00001
00027
00028
00029
00030
00031
00032 #ifndef __Atom__
00033 #define __Atom__
00034
00035 class AtomList;
00036
00037 #include "Term.hpp"
00038
00039
00040
00041
00042
00043 class Atom {
00044 private:
00045 class Data;
00046
00047 public:
00048
00049 Atom ();
00050 Atom (Signature::Pred* p, const TermList& args);
00051 Atom (Signature::Pred* p);
00052 Atom (const Term& l, const Term& r);
00053 Atom (const Atom& a);
00054 ~Atom ();
00055 void operator = (const Atom& rhs);
00056
00057
00058 Signature::Pred* functor () const;
00059 const TermList& args () const;
00060 bool operator == (const Atom& rhs) const;
00061 bool isEquality () const;
00062
00063
00064 void* operator new (size_t);
00065
00066
00067 bool occurs ( const Signature::Pred* ) const;
00068 bool occurs ( Var v ) const;
00069 bool equal (Atom t) const;
00070 Compare compare (Atom l) const;
00071
00072 void apply (const Substitution& subst);
00073 void rectify (Substitution&, Var& last, VarList& freeVars);
00074 bool hasVarsNotIn (VarListList) const;
00075 bool isDefinition ( Term& lhs, Term& rhs ) const;
00076 void normalize ();
00077 bool isFlat () const;
00078
00079
00080 bool isTautology () const;
00081 static bool transitivity (Atom a1, Atom a2, Atom a3);
00082 static bool functionMonotonicity (Atom a1, Atom a2);
00083 static bool predicateMonotonicity (Atom a1, Atom a2, Atom a3);
00084 bool swap (Atom a) const;
00085 bool isRenamingOf (Atom a, Substitution& sbst) const;
00086 void occurring (bool* occurrences, Var max) const;
00087
00088 private:
00089
00090 Data* _data;
00091 };
00092
00093
00094 class AtomList
00095 : public Lst<Atom>
00096 {
00097 public:
00098
00099 AtomList ();
00100 AtomList (const AtomList&);
00101 explicit AtomList (const Atom& t);
00102 AtomList (const Atom& head, const AtomList& tail);
00103 explicit AtomList (LstData<Atom>*);
00104
00105
00106 const AtomList& tail () const
00107 { return static_cast<const AtomList&>(Lst<Atom>::tail()); }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 };
00121
00122
00123 class Atom::Data
00124 # if DEBUG_PREPRO
00125
00126 # endif
00127 {
00128 public:
00129 Data ();
00130 ~Data ();
00131 Data (Signature::Pred* f, const TermList& args);
00132 explicit Data (Signature::Pred* f);
00133 Data (const Term& l, const Term& r);
00134 void ref ();
00135 void deref ();
00136
00137 Signature::Pred* functor () const;
00138 const TermList& args () const;
00139
00140 protected:
00141
00142 int _counter;
00143 Signature::Pred* _functor;
00144 TermList _args;
00145 };
00146
00147
00148
00149
00150 inline
00151 Atom::Atom ()
00152 :
00153 _data (0)
00154 {
00155 }
00156
00157
00158 inline
00159 Atom::~Atom ()
00160 {
00161 if (_data) {
00162 _data->deref ();
00163 }
00164 }
00165
00166
00167
00168 inline
00169 Atom::Atom (const Atom& t)
00170 :
00171 _data (t._data)
00172 {
00173 if (_data) {
00174 _data->ref ();
00175 }
00176 }
00177
00178
00179
00180
00181 inline
00182 Atom::Atom (Signature::Pred* p, const TermList& args)
00183 :
00184 _data (new Data (p,args))
00185 {
00186 }
00187
00188
00189
00190
00191 inline
00192 Atom::Atom (const Term& lhs, const Term& rhs)
00193 :
00194 _data (new Data (lhs,rhs))
00195 {
00196 }
00197
00198
00199
00200
00201 inline
00202 Atom::Atom (Signature::Pred* p)
00203 :
00204 _data (new Data (p))
00205 {
00206 }
00207
00208
00209 inline
00210 bool Atom::operator == (const Atom& rhs) const
00211 {
00212 ASS (_data && rhs._data);
00213
00214 return _data == rhs._data;
00215 }
00216
00217
00218 inline
00219 Signature::Pred* Atom::functor () const
00220 {
00221 return _data->functor ();
00222 }
00223
00224
00225 inline
00226 const TermList& Atom::args () const
00227 {
00228 return _data->args ();
00229 }
00230
00231
00232 inline
00233 bool Atom::isEquality () const
00234 {
00235 return functor()->isEquality ();
00236 }
00237
00238
00239
00240
00241 inline
00242 bool Atom::hasVarsNotIn (VarListList vs) const
00243 {
00244 return args().hasVarsNotIn (vs);
00245 }
00246
00247
00248
00249 inline
00250 bool Atom::isFlat () const
00251 {
00252 return args().varsOnly();
00253 }
00254
00255
00256
00257
00258 inline
00259 Atom::Data::~Data ()
00260 {
00261 TRACER( "Atom::Data::~Data" );
00262
00263 ASS (_counter == 0);
00264 }
00265
00266
00267 inline
00268 void Atom::Data::ref ()
00269 {
00270 ASS (this);
00271
00272 _counter++;
00273 }
00274
00275
00276 inline
00277 void Atom::Data::deref ()
00278 {
00279 ASS (this);
00280 ASS (_counter > 0);
00281 _counter--;
00282
00283 if (_counter == 0) {
00284 delete this;
00285 }
00286 }
00287
00288
00289 inline
00290 Atom::Data::Data (Signature::Pred* f, const TermList& args)
00291 :
00292 _counter (1),
00293 _functor (f),
00294 _args (args)
00295 {
00296 }
00297
00298
00299 inline
00300 Atom::Data::Data (Signature::Pred* f)
00301 :
00302 _counter (1),
00303 _functor (f)
00304 {
00305 }
00306
00307
00308 inline
00309 Signature::Pred* Atom::Data::functor () const
00310 {
00311 ASS (this);
00312
00313 return _functor;
00314 }
00315
00316
00317 inline
00318 const TermList& Atom::Data::args () const
00319 {
00320 ASS (this);
00321
00322 return _args;
00323 }
00324
00325
00326
00327
00328 inline
00329 AtomList::AtomList ()
00330 :
00331 Lst<Atom> ()
00332 {
00333 }
00334
00335
00336
00337
00338 inline
00339 AtomList::AtomList (const AtomList& ts)
00340 :
00341 Lst<Atom> (ts)
00342 {
00343 }
00344
00345
00346
00347
00348 inline
00349 AtomList::AtomList (LstData<Atom>* d)
00350 :
00351 Lst<Atom> (d)
00352 {
00353 }
00354
00355
00356
00357
00358 inline
00359 AtomList::AtomList (const Atom &hd, const AtomList& tl)
00360 :
00361 Lst<Atom> (hd,tl)
00362 {
00363 }
00364
00365
00366
00367
00368 inline
00369 AtomList::AtomList (const Atom &hd)
00370 :
00371 Lst<Atom> (hd)
00372 {
00373 }
00374
00375
00376 ostream& operator << (ostream& str, Atom);
00377
00378
00379 #endif // __atom__