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

Signature.hpp

Go to the documentation of this file.
00001 
00027 //
00028 //  file signature.h 
00029 //  defines class Signature consisting of predicate and function symbols
00030 //
00031 //  28/04/2002, Manchester, made by merging PSymbol and FSymbol
00032 //  01/05/2002, Manchester, implementation of equality changed, Iterator added
00033 //
00034 
00035 #ifndef __signature__
00036 #define __signature__
00037 
00038 #define NO_OF_BUCKETS 2039
00039 
00040 
00041 // ***************** class Signature, definition ****************************
00042 
00043 
00044 // class ostream;
00045 class TermList;
00046 
00047 
00048 #include "Int.hpp"
00049 #include "List.hpp"
00050 
00051 
00052 class Atom;
00053 
00054 class Signature {
00055  
00056  public:
00057 
00058   class Symbol;
00059   typedef List <Symbol*,CID_PSYM_LIST> List;
00060 
00061   class Symbol 
00062 #   if DEBUG_PREPRO
00063     : public Memory <CID_SYMBOL>
00064 #   endif
00065   {
00066    public:
00067     // query structure
00068     int arity () const { return _arity; }
00069     const char* name () const { return _name;}
00070     const int number () const { return _number; }
00071     void arity ( int ar ) { _arity = ar; };
00072     void kernelNumber (unsigned long n) { _kernelNumber = n; }
00073     unsigned long kernelNumber () const { return _kernelNumber; }
00074 
00075    protected:
00076     Symbol (const char* name, int arity, int& number) :
00077       _name (name),
00078       _arity (arity),
00079       _number (number++)
00080       {}
00081     // structure
00082     const char* _name;
00083     int _arity;
00084     int _number;
00085     unsigned long _kernelNumber;
00086   }; // class Signature::Symbol
00087 
00088   class Fun :
00089     public Symbol
00090   {
00091    public:
00092     Fun (const char* name, int arity, int& count) :
00093       Symbol (name,arity,count)
00094       {}
00095     Compare compare (const Fun*) const; // comparison, needed to normalize
00096   };
00097 
00098   class Pred :
00099     public Symbol
00100   {
00101    public:
00102     Pred (const char* name, int arity, int& count) :
00103       Symbol (name,arity,count)
00104       {}
00105     bool isEquality () const
00106       { return number() == 0; }
00107 
00108     Compare compare (const Pred*) const; // comparison, needed to normalize
00109   };
00110 
00111   // iterator, iterate over all function or predicate symbols
00112   class Iterator {
00113    public:
00114     explicit Iterator (List** buckets);
00115     bool more ();
00116     Symbol* next ();
00117    private:
00118     List** _firstBucket;
00119     List** _currentBucket;
00120     List* _currentList;
00121   }; // Iterator
00122 
00123   // iterator over all function symbols
00124   class FunIterator 
00125     : public Iterator {
00126    public:
00127     explicit FunIterator (Signature* s) :
00128       Iterator (s->_fbuckets)
00129       {}
00130   };
00131 
00132   // iterator over all predicate symbols
00133   class PredIterator 
00134     : public Iterator {
00135    public:
00136     explicit PredIterator (Signature* s) :
00137       Iterator (s->_pbuckets)
00138       {}
00139   };
00140 
00141   Signature ();
00142   ~Signature ();
00143 
00144   Fun* createFun ( const char* name, int arity )
00145     { return static_cast<Fun*>(create (name, arity, _fbuckets, false)); }
00146   Pred* createPred ( const char* name, int arity )
00147     { return static_cast<Pred*>(create (name, arity, _pbuckets, true)); }
00148 
00149   // structure
00150   Pred* equality () { return _equality; }
00151   int noOfPreds () const { return _noOfPreds; }
00152   int noOfFuns () const { return _noOfFuns; }
00153   bool arityCheck () const; // true if every symbol has only one arity
00154 
00155   // miscellaneous
00156   Fun* newSkolemFunction (int arity);
00157   void createAnswerAtom (TermList args, Atom& answer); // create answer atom predicate
00158   void addArithmetic ();         // add functions and relations of arithmetic
00159   bool isAnswer (const Pred* p) const
00160     { return p == _answer; }
00161 
00162  private:  
00163   List * _fbuckets [NO_OF_BUCKETS];
00164   List * _pbuckets [NO_OF_BUCKETS];
00165   int _noOfPreds;
00166   int _noOfFuns;
00167   int _lastSkolem;
00168   Pred* _answer;
00169  
00170   static int hash ( const char* );  // hashing function
00171   Symbol* create ( const char* str, int arity, List** buckets, bool isPred );
00172   Pred* _equality;
00173 
00174   // miscellaneous
00175   bool existsFun ( const char* name ) const;
00176 
00177  friend class SymCounter;
00178  friend class FunIterator;
00179  friend class PredIterator;
00180 }; // class Signature
00181 
00182 
00183 ostream& operator << ( ostream& str, const Signature::Symbol* p );
00184 
00185 
00186 // the global signature
00187 extern Signature* sig;
00188 
00189 #endif // __signature__

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