Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

Term.hpp

Go to the documentation of this file.
00001 
00027 //
00028 //  file Term.hpp
00029 //  defines classes Term and TermList
00030 //
00031 // 28/09/2002 Manchester, changed by adding NumericData
00032 //
00033 
00034 #ifndef __Term__
00035 #define __Term__
00036 
00037 
00038 class TermList;
00039 class Substitution;
00040 
00041 
00042 #include <string>
00043 
00044 
00045 #include "Signature.hpp"
00046 #include "Memory.hpp"
00047 #include "Var.hpp"
00048 
00049 #include "VampireKernel.hpp"
00050 
00051 
00052 // ****************** class Term, definition *************************
00053 
00054 
00055 class Term {
00056  private:
00057   class Data;
00058   class VarData;
00059   class CompoundData;
00060   class NumericData;
00061 
00062  public:
00063   enum Tag {
00064     VAR = 0,        // numbers required for normalization
00065     NUMERIC = 1,
00066     COMPOUND = 2 
00067   };
00068 
00069   // constructors/destructors
00070   Term ();
00071   Term (Signature::Fun* f, const TermList& args); // for compound terms
00072   Term (Signature::Fun* f);                       // for constants
00073   Term (const Term& t);
00074   ~Term ();
00075   explicit Term (Var v);
00076   explicit Term (double number);
00077   Term (const VampireKernel::Subterm* term, const VampireKernel& kernel);
00078   void operator= (const Term& rhs);
00079 
00080   // structure
00081   Tag tag () const;
00082   int var () const;
00083   double number () const;
00084   Signature::Fun* functor () const;
00085   const TermList& args () const;
00086   bool operator == (const Term& rhs) const;
00087   bool isvar () const;
00088 
00089   // declared but not defined, to prevent on-heap allocation
00090   void* operator new (size_t);
00091 
00092   // various
00093   bool occurs ( const Signature::Fun* ) const;
00094   bool occurs ( Var v ) const;
00095   bool equal (const Term& t) const;
00096   Compare compare (const Term& l) const; // comparison, used for normalisation
00097   bool equalUpTo (const Term& r, Var x, Var y) const; // this obtained from r by swapping x and y 
00098   bool defines (const Term& lhs) const;  // auxiliary function for atoms
00099   void apply (const Substitution& subst);
00100   void rectify (Substitution&, Var& last, VarList& freeVars);
00101   bool hasVarsNotIn (VarListList) const;
00102   bool isRenamingOf (Term t, Substitution& sbst) const;
00103   void occurring (bool* occurrences, Var max) const; // auxiliary for Formula::occurring
00104 
00105   // other
00106   static const char* Term::varPrefix; // for printing variables
00107  private:
00108   // structure
00109   Data* _data;
00110 }; // class Term
00111 
00112 
00113 class TermList 
00114   : public Lst<Term>
00115 {
00116  public:
00117   // constructors
00118   TermList ();
00119   TermList (const TermList&);
00120   explicit TermList (const Term& t); // one-element list
00121   TermList (const Term& head, const TermList& tail);
00122   explicit TermList (LstData<Term>*);
00123   explicit TermList (const VampireKernel::Subterm* term);
00124   TermList (const VampireKernel::Subterm* term, const VampireKernel& kernel);
00125 
00126   // inherited functions
00127   const TermList& tail () const
00128     { return static_cast<const TermList&>(Lst<Term>::tail()); }
00129 
00130   // various
00131   bool occurs ( const Signature::Fun* ) const;
00132   bool occurs ( Var v ) const;
00133   bool equal (TermList t) const;
00134   Compare compare (TermList l) const; // comparison, used for normalisation
00135   bool equalUpTo (TermList rs, Var x, Var y) const; // this obtained from r by swapping x and y 
00136   bool hasVarsNotIn (VarListList) const;
00137   bool varsOnly () const; // list consists of variables only
00138   void apply (const Substitution& subst);
00139   void rectify (Substitution&, Var& last, VarList& freeVars);
00140   void buildFrom (VarList vs);
00141   bool isRenamingOf (TermList t, Substitution& sbst) const;
00142   void occurring (bool* occurrences, Var max) const; // auxiliary for Formula::occurring
00143 }; // class TermList
00144 
00145 
00146 class Term::Data 
00147 {
00148  public:
00149   Data ();
00150   explicit Data (Tag tag);
00151   ~Data ();
00152 
00153   Term::Tag tag () const;
00154 
00155   void ref ();
00156   void deref ();
00157   void destroy ();
00158 
00159  protected:
00160   // structure
00161   int _counter;
00162   Term::Tag _tag;
00163 }; // classTerm::Data
00164 
00165 
00166 class Term::VarData 
00167 : public Term::Data
00168 #   if DEBUG_PREPRO
00169     , public Memory <CID_VTERM>
00170 #   endif
00171 {
00172  public:
00173   explicit VarData (Var v);
00174   Var var () const;
00175 
00176  private:
00177   // structure
00178   Var _var;
00179 }; // Term::VarData
00180 
00181 
00182 class Term::CompoundData 
00183 : public Term::Data
00184 #   if DEBUG_PREPRO
00185     , public Memory <CID_CTERM>
00186 #   endif
00187 {
00188  public:
00189   CompoundData (Signature::Fun* f, const TermList& args);
00190   explicit CompoundData (Signature::Fun* f);
00191   Signature::Fun* functor () const;
00192   const TermList& args () const;
00193 
00194  private:
00195   // structure
00196   Signature::Fun* _functor;
00197   TermList _args;
00198 }; // Term::CompoundData
00199 
00200 
00201 class Term::NumericData 
00202 : public Term::Data
00203 #   if DEBUG_PREPRO
00204     , public Memory <CID_NTERM>
00205 #   endif
00206 {
00207  public:
00208   explicit NumericData (double f);
00209   double number () const;
00210 
00211  private:
00212   // structure
00213   double _number;
00214 }; // Term::NumericData
00215 
00216 
00217 ostream& operator << ( ostream&, const Term );
00218 
00219 // ******************* Term definitions ************************
00220 
00221 inline
00222 Term::Term () 
00223   : 
00224   _data (0) 
00225 {
00226 } // Term::Term
00227 
00228 
00229 inline
00230 Term::~Term () 
00231 {
00232   if (_data) {
00233     _data->deref ();
00234   }
00235 } // Term::~Term
00236 
00237 
00238 // 25/08/2002 Torrevieja
00239 inline
00240 Term::Term (const Term& t)
00241   :
00242   _data (t._data)
00243 {
00244   if (_data) {
00245     _data->ref ();
00246   }
00247 } // Term::Term
00248 
00249 
00250 // compound term constructor
00251 // 25/08/2002 Torrevieja
00252 inline
00253 Term::Term (Signature::Fun* f, const TermList& args)
00254   :
00255   _data (new CompoundData (f,args))
00256 {
00257 } // Term (Signature::Fun* f, TermList args)
00258 
00259 
00260 // compound term constructor
00261 // 25/08/2002 Torrevieja
00262 inline
00263 Term::Term (Signature::Fun* f)
00264   :
00265   _data (new CompoundData (f))
00266 {
00267 } // Term (Signature::Fun* f, TermList args)
00268 
00269 
00270 // variable term constructor
00271 // 25/08/2002 Torrevieja
00272 inline
00273 Term::Term (Var v)
00274   :
00275   _data (new VarData (v))
00276 {
00277 } // Term (Var v)
00278 
00279 
00280 // numeric term constructor
00281 // 28/09/2002 Manchester
00282 inline
00283 Term::Term (double d)
00284   :
00285   _data (new NumericData (d))
00286 {
00287 } // Term (Var v)
00288 
00289 
00290 inline
00291 Term::Tag Term::tag () const 
00292 { 
00293   return _data->tag(); 
00294 } // Term::tag ()
00295 
00296 
00297 inline
00298 bool Term::isvar () const 
00299 { 
00300   return _data->tag() == VAR; 
00301 } // Term::isvar ()
00302 
00303 
00304 inline
00305 bool Term::operator == (const Term& rhs) const
00306 { 
00307   ASS (_data && rhs._data);
00308 
00309   return _data == rhs._data; 
00310 } // Term::operator ==
00311 
00312 
00313 // Var Term::var () - return the variable number of a variable term
00314 // 25/08/2002 Torrevieja
00315 inline
00316 Var Term::var () const
00317 { 
00318   ASS (this && tag() == VAR);
00319 
00320   return (static_cast<Term::VarData*>(_data))->var();
00321 } // Term::var
00322 
00323 
00324 // return the functor of a compound term
00325 // 25/08/2002 Torrevieja
00326 inline
00327 Signature::Fun* Term::functor () const
00328 { 
00329   ASS (this && tag() == COMPOUND);
00330 
00331   return (static_cast<Term::CompoundData*>(_data))->functor();
00332 } // Term::functor
00333 
00334 
00335 // return the arguments of a compound term
00336 // 25/08/2002 Torrevieja
00337 inline
00338 const TermList& Term::args () const
00339 { 
00340   ASS (this && tag() == COMPOUND);
00341 
00342   return (static_cast<Term::CompoundData*>(_data))->args();
00343 } // Term::args
00344 
00345 
00346 // return the value of a numeric term
00347 // 25/08/2002 Torrevieja
00348 inline
00349 double Term::number () const
00350 { 
00351   ASS (this && tag() == NUMERIC);
00352 
00353   return (static_cast<Term::NumericData*>(_data))->number();
00354 } // Term::number
00355 
00356 
00357 // **************** Term::Data definitions *********************
00358 
00359 inline
00360 Term::Data::Data (Term::Tag tag)
00361   : 
00362   _counter (1),
00363   _tag (tag)
00364 {
00365 } // Term::Data::Data (Tag tag)
00366 
00367 
00368 inline 
00369 Term::Data::~Data ()
00370 {
00371   TRACER( "Term::Data::~Data" );
00372 
00373   ASS (_counter == 0);
00374 } // Term::Data::~Data ()
00375 
00376 
00377 inline
00378 void Term::Data::ref () 
00379 { 
00380   ASS (this);
00381 
00382   _counter++;
00383 } // Term::Data::ref ()
00384 
00385 
00386 inline
00387 Term::Tag Term::Data::tag () const 
00388 { 
00389   ASS (this);
00390 
00391   return _tag; 
00392 } // Term::Data::tag ()
00393 
00394 
00395 inline
00396 void Term::Data::deref () 
00397 { 
00398   ASS (this);
00399   ASS (_counter > 0);
00400   _counter--;
00401 
00402   if (_counter == 0) {
00403     destroy ();
00404   }
00405 } // Term::Data::deref ()
00406 
00407 
00408 // **************** Term::VarData definitions *********************
00409 
00410 inline
00411 Term::VarData::VarData (Var v)
00412   : 
00413   Data (VAR), 
00414   _var (v) 
00415 {
00416 } // Term::VarData::VarData
00417 
00418 
00419 inline
00420 Var Term::VarData::var () const 
00421 { 
00422   ASS(_tag == VAR);
00423 
00424   return _var; 
00425 } // Term::VarData::var ()
00426 
00427 
00428 // **************** Term::NumericData definitions *********************
00429 
00430 inline
00431 Term::NumericData::NumericData (double value)
00432   : 
00433   Data (NUMERIC), 
00434   _number (value) 
00435 {
00436 } // Term::NumericData::NumericData
00437 
00438 
00439 inline
00440 double Term::NumericData::number () const 
00441 { 
00442   ASS(_tag == NUMERIC);
00443 
00444   return _number; 
00445 } // Term::NumericData::number ()
00446 
00447 
00448 // *************** Term::CompoundData definitions *****************
00449 
00450 inline
00451 Term::CompoundData::CompoundData (Signature::Fun* f, const TermList& args) 
00452   : 
00453   Data (COMPOUND), 
00454   _functor (f), 
00455   _args (args) 
00456 {
00457 } // Term::CompoundData::CompoundData
00458 
00459 
00460 inline
00461 Term::CompoundData::CompoundData (Signature::Fun* f) 
00462   : 
00463   Data (COMPOUND), 
00464   _functor (f) 
00465 {
00466 } // Term::CompoundData::CompoundData
00467 
00468 
00469 inline
00470 Signature::Fun* Term::CompoundData::functor () const 
00471 { 
00472   ASS (this && _tag == COMPOUND);
00473 
00474   return _functor; 
00475 } // Term::CompoundData::functor ()
00476 
00477 
00478 inline
00479 const TermList& Term::CompoundData::args () const 
00480 { 
00481   ASS (this && _tag == COMPOUND);
00482 
00483   return _args; 
00484 } // Term::CompoundData::args ()
00485 
00486 
00487 // ******************* TermList definitions ************************
00488 
00489 inline
00490 TermList::TermList () 
00491   : 
00492   Lst<Term> ()
00493 {
00494 } // TermList::TermList
00495 
00496 
00497 // copy constructor
00498 // 25/08/2002 Torrevieja
00499 // 07/09/2002 Manchester, changed
00500 inline
00501 TermList::TermList (const TermList& ts)
00502   :
00503   Lst<Term> (ts)
00504 {
00505 } // TermList::TermList
00506 
00507 
00508 // almost a copy constructor
00509 // 25/08/2002 Torrevieja
00510 inline
00511 TermList::TermList (LstData<Term>* d)
00512   :
00513   Lst<Term> (d)
00514 {
00515 } // TermList::TermList
00516 
00517 
00518 // 'cons' list constructor
00519 // 25/08/2002 Torrevieja
00520 inline
00521 TermList::TermList (const Term &hd, const TermList& tl)
00522   :
00523   Lst<Term> (hd,tl)
00524 {
00525 } // TermList::TermList
00526 
00527 
00528 // 'cons' list constructor
00529 // 25/08/2002 Torrevieja
00530 inline
00531 TermList::TermList (const Term &hd)
00532   :
00533   Lst<Term> (hd)
00534 {
00535 } // TermList::TermList
00536 
00537 
00538 #endif // __Term__
00539 

Generated on Sat Jun 28 15:08:58 2003 for Vampire by doxygen 1.3.2