Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

env.h

Go to the documentation of this file.
00001 /*
00002   Copyright (C) 1997-2001 Shigeru Chiba, Tokyo Institute of Technology.
00003 
00004   Permission to use, copy, distribute and modify this software and   
00005   its documentation for any purpose is hereby granted without fee,        
00006   provided that the above copyright notice appear in all copies and that 
00007   both that copyright notice and this permission notice appear in 
00008   supporting documentation.
00009 
00010   Shigeru Chiba makes no representations about the suitability of this 
00011   software for any purpose.  It is provided "as is" without express or
00012   implied warranty.
00013 */
00014 
00015 #ifndef _env_h
00016 #define _env_h
00017 
00018 #include "types.h"
00019 #include "ptree-core.h"
00020 
00021 class Class;
00022 class HashTable;
00023 class Bind;
00024 class Encoding;
00025 class TypeInfo;
00026 class Walker;
00027 
00028 // class Environment
00029 
00030 class OCXXMOP Environment : public LightObject {
00031 public:
00032     Environment(Walker* w);
00033     Environment(Environment* e);
00034     Environment(Environment* e, Walker* w);
00035 
00036     bool IsEmpty();
00037     Environment* GetOuterEnvironment() { return next; }
00038     Environment* GetBottom();
00039     void AddBaseclassEnv(Environment* e) { baseclasses_or_using.Append(e); }
00040     Walker* GetWalker() { return walker; }
00041     void SetWalker(Walker* w) { walker = w; }
00042 
00043     Class* LookupClassMetaobject(Ptree* name);
00044     bool LookupType(const char* name, int len, Bind*& t);
00045 
00046     bool Lookup(Ptree* name, bool& is_type_name, TypeInfo& t);
00047     bool Lookup(Ptree* name, TypeInfo& t);
00048     bool Lookup(Ptree*, Bind*&);
00049     bool LookupTop(Ptree*, Bind*&);
00050 
00051     bool LookupTop(const char* name, int len, Bind*& t);
00052     bool LookupAll(const char* name, int len, Bind*& t);
00053 
00054     bool RecordVariable(char* name, Class* c);
00055     bool RecordPointerVariable(char* name, Class* c);
00056 
00057     int AddEntry(char*, int, Bind*);
00058     int AddDupEntry(char*, int, Bind*);
00059 
00060     void RecordNamespace(Environment*, Ptree*);
00061     Environment* LookupNamespace(const char* name, int len);
00062     Environment* LookupNamespace0(Ptree*);
00063     void RecordUsing(Ptree* name);
00064     void RecordUsingNamespace(Ptree* name);
00065 
00066     void RecordTypedefName(Ptree*);
00067     void RecordEnumName(Ptree*);
00068     void RecordClassName(char*, Class*);
00069     void RecordTemplateClass(Ptree*, Class*);
00070     Environment* RecordTemplateFunction(Ptree*, Ptree*);
00071     Environment* RecordDeclarator(Ptree*);
00072     Environment* DontRecordDeclarator(Ptree*);
00073     void RecordMetaclassName(Ptree*);
00074     Ptree* LookupMetaclass(Ptree*);
00075     static bool RecordClasskeyword(char*, char*);
00076     static Ptree* LookupClasskeyword(Ptree*);
00077 
00078     void SetMetaobject(Class* m) { metaobject = m; }
00079     Class* IsClassEnvironment() { return metaobject; }
00080     Ptree* IsNamespace() { return namespace_name; }
00081     Class* LookupThis();
00082     Environment* IsMember(Ptree*);
00083 
00084     void Dump();
00085     void Dump(int);
00086 
00087     Ptree* GetLineNumber(Ptree*, int&);
00088 
00089 private:
00090     static bool SearchBaseOrUsing(Environment* this_env,
00091                         bool (Environment::*func)(const char*, int, Bind*&),
00092                         const char* name, int len, Bind*& t);
00093     Environment* LookupNamespace0(const char*, int);
00094 
00095 public:
00096     class OCXXMOP Array : public LightObject {
00097     public:
00098         Array(int = 2);
00099         uint Number() { return num; }
00100         Environment* Ref(uint index);
00101         void Append(Environment*);
00102     private:
00103         uint num, size;
00104         Environment** array;
00105     };
00106 
00107 private:
00108     Environment*        next;
00109     HashTable*          htable;
00110     Class*              metaobject;
00111     Walker*             walker;
00112     PtreeArray          metaclasses;
00113     static PtreeArray*  classkeywords;
00114     Array               baseclasses_or_using;
00115                         // baseclasses or using_namespaces
00116     Array               namespaces;
00117     Ptree*              namespace_name;  // nil unless this is a namespace
00118 };
00119 
00120 // class Bind and its subclasses
00121 
00122 class Bind : public LightObject {
00123 public:
00124     enum Kind {
00125         isVarName, isTypedefName, isClassName, isEnumName, isTemplateClass,
00126         isTemplateFunction
00127      };
00128     virtual Kind What() = nil;
00129     virtual void GetType(TypeInfo&, Environment*) = nil;
00130     virtual char* GetEncodedType();
00131     virtual bool IsType();
00132     virtual Class* ClassMetaobject();
00133     virtual void SetClassMetaobject(Class*);
00134 };
00135 
00136 class BindVarName : public Bind {
00137 public:
00138     BindVarName(char* t) { type = t; }
00139     Kind What();
00140     void GetType(TypeInfo&, Environment*);
00141     char* GetEncodedType();
00142     bool IsType();
00143 
00144 private:
00145     char* type;
00146 };
00147 
00148 class BindTypedefName : public Bind {
00149 public:
00150     BindTypedefName(char* t) { type = t; }
00151     Kind What();
00152     void GetType(TypeInfo&, Environment*);
00153     char* GetEncodedType();
00154 
00155 private:
00156     char* type;
00157 };
00158 
00159 class BindClassName : public Bind {
00160 public:
00161     BindClassName(Class* c) { metaobject = c; }
00162     Kind What();
00163     void GetType(TypeInfo&, Environment*);
00164     Class* ClassMetaobject();
00165     void SetClassMetaobject(Class*);
00166 
00167 private:
00168     Class* metaobject;
00169 };
00170 
00171 class BindEnumName : public Bind {
00172 public:
00173     BindEnumName(char*, Ptree*);
00174     Kind What();
00175     void GetType(TypeInfo&, Environment*);
00176     Ptree* GetSpecification() { return specification; }
00177 
00178 private:
00179     char* type;
00180     Ptree* specification;
00181 };
00182 
00183 class BindTemplateClass : public Bind {
00184 public:
00185     BindTemplateClass(Class* c) { metaobject = c; }
00186     Kind What();
00187     void GetType(TypeInfo&, Environment*);
00188     Class* ClassMetaobject();
00189     void SetClassMetaobject(Class*);
00190 
00191 private:
00192     Class* metaobject;
00193 };
00194 
00195 class BindTemplateFunction : public Bind {
00196 public:
00197     BindTemplateFunction(Ptree* d) { decl = d; }
00198     Kind What();
00199     void GetType(TypeInfo&, Environment*);
00200     bool IsType();
00201 
00202 private:
00203     Ptree* decl;
00204 };
00205 
00206 #endif /* _env_h */

Generated on Mon Feb 10 17:32:47 2003 for VFiasco Semantics Compiler by doxygen1.2.15