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

/ray/src/vm/input/nspcinfo.h

Go to the documentation of this file.
00001 /*
00002  * vm/input/nspcinfo.h
00003  * 
00004  * VM namespace information node. 
00005  * 
00006  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #ifndef _VM_INPUT_NSPCINFO_H_
00018 #define _VM_INPUT_NSPCINFO_H_ 1
00019 
00027 #include <vm/vmconfig.h>    /* MUST be first */
00028 #include <vm/vartype.h>
00029 #include <vm/functype.h>
00030 #include <lib/tl/tlstring.h>
00031 #include <lib/tl/linkedlist.h>
00032 #include <lib/tl/tllinearqueue.h>
00033 #include <lib/tl/tlbtree.h>
00034 #include <vm/nrarray.h>
00035 #include <lib/lex/location.h>
00036 
00037 
00038 // See lib/lex/strtreedump.h. 
00039 class StringTreeDump;
00040 
00041 namespace VM
00042 {
00043 
00061 class NamespaceInfo : public LinkedListBase<NamespaceInfo>
00062 {
00063     // Friends used for parsing. 
00064     friend class AssemblerFile;
00065     friend class AssemblerFile_Plaintext;
00066     // Friend for linking. 
00067     friend class VMLinker;
00068     
00069     public:
00075         template<typename T>struct PtrListOperators : 
00076             TLDefaultOperators_Construct_PDT<T*>,
00077             TLDefaultOperators_Allocation
00078         {
00079             static const bool pdt=1;
00080             
00081             static inline bool lt(T const *a,T const *b)
00082                 {  return(a->name<b->name);   }
00083             static inline bool gt(T const *a,T const *b)
00084                 {  return(a->name>b->name);   }
00085             
00086             static inline bool le(T const *a,T const *b)
00087                 {  return(a==b || a->name<=b->name);  }
00088             static inline bool eq(T const *a,T const *b)
00089                 {  return(a==b || a->name==b->name);  }
00090             
00091             static inline bool lt(T const *a,TLString const &b)
00092                 {  return(a->name<b);   }
00093             static inline bool gt(T const *a,TLString const &b)
00094                 {  return(a->name>b);   }
00095             static inline bool eq(T const *a,TLString const &b)
00096                 {  return(a->name==b);  }
00097             
00098             template<typename I>static inline T* &idx(
00099                 T **array,I i)
00100                 {  return(array[i]);  }
00101         };
00102         
00103     public:
00105         enum NSType
00106         {
00107             NSNamespace,
00108             NSClass
00109         };
00110         
00112         static const char *NSType2String(NSType t);
00113         
00114         // See below. 
00115         struct SymbolEntryE;
00116         
00122         struct SymbolEntryB
00123         {
00125             SymRef symref;
00126             
00128             inline SymbolEntryB() : symref(0) {}
00129             inline ~SymbolEntryB() {}
00130             
00135 
00136             inline SymbolEntryE *ep();
00137             inline const SymbolEntryE *ep() const;
00139             
00143             TLString CompleteName() const;
00144             
00151             bool CompareTo(const SymbolEntryB &e) const;
00152             
00153             public:
00155                 inline SymbolEntryB(const SymbolEntryB &b) : symref(b.symref) {}
00156             private:
00158                 void operator=(const SymbolEntryB &);
00159         };
00162         struct SymbolEntryE : SymbolEntryB
00163         {
00165             enum ExtID
00166             {
00167                 ExtUnknown=0,   
00168                 ExtFunction,    
00169                 ExtVariable,    
00170             };
00171             
00173             static const char *ExtID2String(ExtID e);
00174             
00175             ExtID extid;     
00176             // Should use a union for these but cannot because they are 
00177             // "C++-safe" classes. Oh well, they are 2 bytes each...
00178             FuncType ftype;  
00179             VarType vtype;   
00180             TLString name;   
00181             NamespaceInfo *nspc; 
00182 
00183 
00184             SymbolEntryE *linked;
00185             
00187             SymbolEntryE(NamespaceInfo *_nspc=NULL);
00189             inline ~SymbolEntryE()  { nspc=NULL; linked=NULL; }
00190             
00192             SymbolEntryE(const SymbolEntryE &se);
00194             SymbolEntryE &operator=(const SymbolEntryE &se);
00195         };
00196         
00197     protected:
00198         NamespaceInfo *parent;           
00199         LinkedList<NamespaceInfo> down;  
00200         TLString name;                   
00201         NSType nstype;                   
00202         
00204         SCLocation asm_loc;
00205         
00208         NamespaceInfo *linked;
00212         uint16 link_info_set : 1;
00214         uint16 recursion_flag : 1;
00215         
00216         typedef TLLinearQueue<SymbolEntryE,TLDefaultOperators_CDT<SymbolEntryE> > 
00217             SymbolList;
00224         SymbolList symbol;
00225         
00227         TLBTree<NamespaceInfo*,PtrListOperators<NamespaceInfo> > map_name2child;
00228         
00230         TLBTree< SymbolEntryE*,PtrListOperators<SymbolEntryE> > map_name2symbol;
00231         
00233         struct _Operators
00234         {
00236             static inline bool le(NamespaceInfo const &a,
00237                 NamespaceInfo const &b)
00238                 {  return(a.name<=b.name);  }
00239         };
00240         
00242         void _AddChild(NamespaceInfo *child);
00244         void _DelChild(NamespaceInfo *child);
00245         
00246     private:
00248         NamespaceInfo(const NamespaceInfo &);
00250         void operator=(const NamespaceInfo &);
00251     public:
00261         NamespaceInfo(const TLString &name,NamespaceInfo *parent=NULL,
00262             NSType nstype=NSNamespace);
00264         virtual ~NamespaceInfo();
00265         
00272         void SortNamespaceTree();
00273         
00280         void AddChild(NamespaceInfo *child);
00281         
00288         virtual TLString CompleteName() const;
00289         
00301         virtual void DumpTree(StringTreeDump &dump,bool IDs_resolved,
00302             bool recurse=1) const;
00303 };
00304 
00305 // Must be placed here below SymbolEntryE definition. 
00306 inline NamespaceInfo::SymbolEntryE *NamespaceInfo::SymbolEntryB::ep()
00307     {  return(symref<0 ? NULL : static_cast<SymbolEntryE*>(this));  }
00308 inline const NamespaceInfo::SymbolEntryE *NamespaceInfo::SymbolEntryB::ep() 
00309     const
00310     {  return(symref<0 ? NULL : static_cast<const SymbolEntryE*>(this));  }
00311 
00312 // See classinfo.h: 
00313 struct ClassInfo;
00314 
00315 }  // end of namespace VM
00316 
00317 #endif  /* _VM_INPUT_NSPCINFO_H_ */

Generated on Sat Feb 19 22:33:47 2005 for Ray by doxygen 1.3.5