annotate dmd/dsymbol.h @ 173:db9890b3fb64 trunk

[svn r189] moving IR data back into DMD frontend nodes
author ChristianK
date Tue, 06 May 2008 07:56:03 +0200
parents 5acec6b2eef8
children aaade6ded589
rev   line source
ChristianK@159 1
ChristianK@159 2 // Compiler implementation of the D programming language
ChristianK@159 3 // Copyright (c) 1999-2007 by Digital Mars
ChristianK@159 4 // All Rights Reserved
ChristianK@159 5 // written by Walter Bright
ChristianK@159 6 // http://www.digitalmars.com
ChristianK@159 7 // License for redistribution is by either the Artistic License
ChristianK@159 8 // in artistic.txt, or the GNU General Public License in gnu.txt.
ChristianK@159 9 // See the included readme.txt for details.
ChristianK@159 10
ChristianK@159 11 #ifndef DMD_DSYMBOL_H
ChristianK@159 12 #define DMD_DSYMBOL_H
ChristianK@159 13
ChristianK@159 14 #ifdef __DMC__
ChristianK@159 15 #pragma once
ChristianK@159 16 #endif /* __DMC__ */
ChristianK@159 17
ChristianK@159 18 #include "root.h"
ChristianK@159 19 #include "stringtable.h"
ChristianK@159 20
ChristianK@159 21 #include "mars.h"
ChristianK@159 22 #include "arraytypes.h"
ChristianK@159 23
ChristianK@173 24 // llvm
ChristianK@173 25 #include "../ir/irsymbol.h"
ChristianK@173 26
ChristianK@159 27 struct Identifier;
ChristianK@159 28 struct Scope;
ChristianK@159 29 struct DsymbolTable;
ChristianK@159 30 struct Declaration;
ChristianK@159 31 struct TupleDeclaration;
ChristianK@159 32 struct TypedefDeclaration;
ChristianK@159 33 struct AliasDeclaration;
ChristianK@159 34 struct AggregateDeclaration;
ChristianK@159 35 struct EnumDeclaration;
ChristianK@159 36 struct ClassDeclaration;
ChristianK@159 37 struct InterfaceDeclaration;
ChristianK@159 38 struct StructDeclaration;
ChristianK@159 39 struct UnionDeclaration;
ChristianK@159 40 struct FuncDeclaration;
ChristianK@159 41 struct FuncAliasDeclaration;
ChristianK@159 42 struct FuncLiteralDeclaration;
ChristianK@159 43 struct CtorDeclaration;
ChristianK@159 44 struct DtorDeclaration;
ChristianK@159 45 struct StaticCtorDeclaration;
ChristianK@159 46 struct StaticDtorDeclaration;
ChristianK@159 47 struct InvariantDeclaration;
ChristianK@159 48 struct UnitTestDeclaration;
ChristianK@159 49 struct NewDeclaration;
ChristianK@159 50 struct VarDeclaration;
ChristianK@159 51 struct AttribDeclaration;
ChristianK@159 52 struct Symbol;
ChristianK@159 53 struct Package;
ChristianK@159 54 struct Module;
ChristianK@159 55 struct Import;
ChristianK@159 56 struct Type;
ChristianK@159 57 struct TypeTuple;
ChristianK@159 58 struct WithStatement;
ChristianK@159 59 struct LabelDsymbol;
ChristianK@159 60 struct ScopeDsymbol;
ChristianK@159 61 struct TemplateDeclaration;
ChristianK@159 62 struct TemplateInstance;
ChristianK@159 63 struct TemplateMixin;
ChristianK@159 64 struct EnumMember;
ChristianK@159 65 struct ScopeDsymbol;
ChristianK@159 66 struct WithScopeSymbol;
ChristianK@159 67 struct ArrayScopeSymbol;
ChristianK@159 68 struct SymbolDeclaration;
ChristianK@159 69 struct Expression;
ChristianK@159 70 struct DeleteDeclaration;
ChristianK@159 71 struct HdrGenState;
ChristianK@159 72 struct TypeInfoDeclaration;
ChristianK@159 73 struct ClassInfoDeclaration;
ChristianK@159 74
ChristianK@159 75 #if IN_GCC
ChristianK@159 76 union tree_node;
ChristianK@159 77 typedef union tree_node TYPE;
ChristianK@159 78 #else
ChristianK@159 79 struct TYPE;
ChristianK@159 80 #endif
ChristianK@159 81
ChristianK@173 82 // llvm
ChristianK@159 83 #if IN_LLVM
ChristianK@159 84 namespace llvm
ChristianK@159 85 {
ChristianK@159 86 class Value;
ChristianK@159 87 }
ChristianK@159 88 #endif
ChristianK@159 89
ChristianK@159 90 enum PROT
ChristianK@159 91 {
ChristianK@159 92 PROTundefined,
ChristianK@159 93 PROTnone, // no access
ChristianK@159 94 PROTprivate,
ChristianK@159 95 PROTpackage,
ChristianK@159 96 PROTprotected,
ChristianK@159 97 PROTpublic,
ChristianK@159 98 PROTexport,
ChristianK@159 99 };
ChristianK@159 100
ChristianK@159 101
ChristianK@159 102 struct Dsymbol : Object
ChristianK@159 103 {
ChristianK@159 104 Identifier *ident;
ChristianK@159 105 Identifier *c_ident;
ChristianK@159 106 Dsymbol *parent;
ChristianK@159 107 Symbol *csym; // symbol for code generator
ChristianK@159 108 Symbol *isym; // import version of csym
ChristianK@159 109 unsigned char *comment; // documentation comment for this Dsymbol
ChristianK@159 110 Loc loc; // where defined
ChristianK@159 111
ChristianK@159 112 Dsymbol();
ChristianK@159 113 Dsymbol(Identifier *);
ChristianK@159 114 char *toChars();
ChristianK@159 115 char *toPrettyChars();
ChristianK@159 116 char *locToChars();
ChristianK@159 117 int equals(Object *o);
ChristianK@159 118 int isAnonymous();
ChristianK@159 119 void error(Loc loc, const char *format, ...);
ChristianK@159 120 void error(const char *format, ...);
ChristianK@159 121 void checkDeprecated(Loc loc, Scope *sc);
ChristianK@159 122 Module *getModule();
ChristianK@159 123 Dsymbol *pastMixin();
ChristianK@159 124 Dsymbol *toParent();
ChristianK@159 125 Dsymbol *toParent2();
ChristianK@159 126
ChristianK@159 127 int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol()
ChristianK@159 128
ChristianK@159 129 static Array *arraySyntaxCopy(Array *a);
ChristianK@159 130
ChristianK@159 131 virtual char *kind();
ChristianK@159 132 virtual Dsymbol *toAlias(); // resolve real symbol
ChristianK@159 133 virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum);
ChristianK@159 134 virtual void semantic(Scope *sc);
ChristianK@159 135 virtual void semantic2(Scope *sc);
ChristianK@159 136 virtual void semantic3(Scope *sc);
ChristianK@159 137 virtual void inlineScan();
ChristianK@159 138 virtual Dsymbol *search(Loc loc, Identifier *ident, int flags);
ChristianK@159 139 Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id);
ChristianK@159 140 virtual int overloadInsert(Dsymbol *s);
ChristianK@159 141 #ifdef _DH
ChristianK@159 142 char *toHChars();
ChristianK@159 143 virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs);
ChristianK@159 144 #endif
ChristianK@159 145 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
ChristianK@159 146 virtual void toDocBuffer(OutBuffer *buf);
ChristianK@159 147 virtual unsigned size(Loc loc);
ChristianK@159 148 virtual int isforwardRef();
ChristianK@159 149 virtual void defineRef(Dsymbol *s);
ChristianK@159 150 virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member
ChristianK@159 151 virtual ClassDeclaration *isClassMember(); // are we a member of a class?
ChristianK@159 152 virtual int isExport(); // is Dsymbol exported?
ChristianK@159 153 virtual int isImportedSymbol(); // is Dsymbol imported?
ChristianK@159 154 virtual int isDeprecated(); // is Dsymbol deprecated?
ChristianK@159 155 virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol?
ChristianK@159 156 virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration?
ChristianK@159 157 virtual Type *getType(); // is this a type?
ChristianK@159 158 virtual char *mangle();
ChristianK@159 159 virtual int needThis(); // need a 'this' pointer?
ChristianK@159 160 virtual enum PROT prot();
ChristianK@159 161 virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
ChristianK@159 162 virtual int oneMember(Dsymbol **ps);
ChristianK@159 163 static int oneMembers(Array *members, Dsymbol **ps);
ChristianK@159 164 virtual int hasPointers();
ChristianK@159 165 virtual void addLocalClass(ClassDeclarations *) { }
ChristianK@159 166 virtual void checkCtorConstInit() { }
ChristianK@159 167
ChristianK@159 168 virtual void addComment(unsigned char *comment);
ChristianK@159 169 virtual void emitComment(Scope *sc);
ChristianK@159 170 void emitDitto(Scope *sc);
ChristianK@159 171
ChristianK@159 172 // Backend
ChristianK@159 173
ChristianK@159 174 virtual Symbol *toSymbol(); // to backend symbol
ChristianK@159 175 virtual void toObjFile(); // compile to .obj file
ChristianK@159 176 virtual int cvMember(unsigned char *p); // emit cv debug info for member
ChristianK@159 177
ChristianK@159 178 Symbol *toImport(); // to backend import symbol
ChristianK@159 179 static Symbol *toImport(Symbol *s); // to backend import symbol
ChristianK@159 180
ChristianK@159 181 Symbol *toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix); // helper
ChristianK@159 182
ChristianK@159 183 // Eliminate need for dynamic_cast
ChristianK@159 184 virtual Package *isPackage() { return NULL; }
ChristianK@159 185 virtual Module *isModule() { return NULL; }
ChristianK@159 186 virtual EnumMember *isEnumMember() { return NULL; }
ChristianK@159 187 virtual TemplateDeclaration *isTemplateDeclaration() { return NULL; }
ChristianK@159 188 virtual TemplateInstance *isTemplateInstance() { return NULL; }
ChristianK@159 189 virtual TemplateMixin *isTemplateMixin() { return NULL; }
ChristianK@159 190 virtual Declaration *isDeclaration() { return NULL; }
ChristianK@159 191 virtual TupleDeclaration *isTupleDeclaration() { return NULL; }
ChristianK@159 192 virtual TypedefDeclaration *isTypedefDeclaration() { return NULL; }
ChristianK@159 193 virtual AliasDeclaration *isAliasDeclaration() { return NULL; }
ChristianK@159 194 virtual AggregateDeclaration *isAggregateDeclaration() { return NULL; }
ChristianK@159 195 virtual FuncDeclaration *isFuncDeclaration() { return NULL; }
ChristianK@159 196 virtual FuncAliasDeclaration *isFuncAliasDeclaration() { return NULL; }
ChristianK@159 197 virtual FuncLiteralDeclaration *isFuncLiteralDeclaration() { return NULL; }
ChristianK@159 198 virtual CtorDeclaration *isCtorDeclaration() { return NULL; }
ChristianK@159 199 virtual DtorDeclaration *isDtorDeclaration() { return NULL; }
ChristianK@159 200 virtual StaticCtorDeclaration *isStaticCtorDeclaration() { return NULL; }
ChristianK@159 201 virtual StaticDtorDeclaration *isStaticDtorDeclaration() { return NULL; }
ChristianK@159 202 virtual InvariantDeclaration *isInvariantDeclaration() { return NULL; }
ChristianK@159 203 virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; }
ChristianK@159 204 virtual NewDeclaration *isNewDeclaration() { return NULL; }
ChristianK@159 205 virtual VarDeclaration *isVarDeclaration() { return NULL; }
ChristianK@159 206 virtual ClassDeclaration *isClassDeclaration() { return NULL; }
ChristianK@159 207 virtual StructDeclaration *isStructDeclaration() { return NULL; }
ChristianK@159 208 virtual UnionDeclaration *isUnionDeclaration() { return NULL; }
ChristianK@159 209 virtual InterfaceDeclaration *isInterfaceDeclaration() { return NULL; }
ChristianK@159 210 virtual ScopeDsymbol *isScopeDsymbol() { return NULL; }
ChristianK@159 211 virtual WithScopeSymbol *isWithScopeSymbol() { return NULL; }
ChristianK@159 212 virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; }
ChristianK@159 213 virtual Import *isImport() { return NULL; }
ChristianK@159 214 virtual EnumDeclaration *isEnumDeclaration() { return NULL; }
ChristianK@159 215 #ifdef _DH
ChristianK@159 216 virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; }
ChristianK@159 217 #endif
ChristianK@159 218 virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; }
ChristianK@159 219 virtual AttribDeclaration *isAttribDeclaration() { return NULL; }
ChristianK@159 220 virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; }
ChristianK@159 221 virtual ClassInfoDeclaration* isClassInfoDeclaration() { return NULL; }
ChristianK@159 222
ChristianK@159 223 // llvm stuff
ChristianK@159 224 int llvmInternal;
ChristianK@159 225 char* llvmInternal1;
ChristianK@159 226 char* llvmInternal2;
ChristianK@173 227
ChristianK@173 228 IrDsymbol ir;
ChristianK@159 229 };
ChristianK@159 230
ChristianK@159 231 // Dsymbol that generates a scope
ChristianK@159 232
ChristianK@159 233 struct ScopeDsymbol : Dsymbol
ChristianK@159 234 {
ChristianK@159 235 Array *members; // all Dsymbol's in this scope
ChristianK@159 236 DsymbolTable *symtab; // members[] sorted into table
ChristianK@159 237
ChristianK@159 238 Array *imports; // imported ScopeDsymbol's
ChristianK@159 239 unsigned char *prots; // PROT for each import
ChristianK@159 240
ChristianK@159 241 ScopeDsymbol();
ChristianK@159 242 ScopeDsymbol(Identifier *id);
ChristianK@159 243 Dsymbol *syntaxCopy(Dsymbol *s);
ChristianK@159 244 Dsymbol *search(Loc loc, Identifier *ident, int flags);
ChristianK@159 245 void importScope(ScopeDsymbol *s, enum PROT protection);
ChristianK@159 246 int isforwardRef();
ChristianK@159 247 void defineRef(Dsymbol *s);
ChristianK@159 248 static void multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2);
ChristianK@159 249 Dsymbol *nameCollision(Dsymbol *s);
ChristianK@159 250 char *kind();
ChristianK@159 251
ChristianK@159 252 void emitMemberComments(Scope *sc);
ChristianK@159 253
ChristianK@159 254 ScopeDsymbol *isScopeDsymbol() { return this; }
ChristianK@159 255 };
ChristianK@159 256
ChristianK@159 257 // With statement scope
ChristianK@159 258
ChristianK@159 259 struct WithScopeSymbol : ScopeDsymbol
ChristianK@159 260 {
ChristianK@159 261 WithStatement *withstate;
ChristianK@159 262
ChristianK@159 263 WithScopeSymbol(WithStatement *withstate);
ChristianK@159 264 Dsymbol *search(Loc loc, Identifier *ident, int flags);
ChristianK@159 265
ChristianK@159 266 WithScopeSymbol *isWithScopeSymbol() { return this; }
ChristianK@159 267 };
ChristianK@159 268
ChristianK@159 269 // Array Index/Slice scope
ChristianK@159 270
ChristianK@159 271 struct ArrayScopeSymbol : ScopeDsymbol
ChristianK@159 272 {
ChristianK@159 273 Expression *exp; // IndexExp or SliceExp
ChristianK@159 274 TypeTuple *type; // for tuple[length]
ChristianK@159 275 TupleDeclaration *td; // for tuples of objects
ChristianK@159 276
ChristianK@159 277 ArrayScopeSymbol(Expression *e);
ChristianK@159 278 ArrayScopeSymbol(TypeTuple *t);
ChristianK@159 279 ArrayScopeSymbol(TupleDeclaration *td);
ChristianK@159 280 Dsymbol *search(Loc loc, Identifier *ident, int flags);
ChristianK@159 281
ChristianK@159 282 ArrayScopeSymbol *isArrayScopeSymbol() { return this; }
ChristianK@159 283 };
ChristianK@159 284
ChristianK@159 285 // Table of Dsymbol's
ChristianK@159 286
ChristianK@159 287 struct DsymbolTable : Object
ChristianK@159 288 {
ChristianK@159 289 StringTable *tab;
ChristianK@159 290
ChristianK@159 291 DsymbolTable();
ChristianK@159 292 ~DsymbolTable();
ChristianK@159 293
ChristianK@159 294 // Look up Identifier. Return Dsymbol if found, NULL if not.
ChristianK@159 295 Dsymbol *lookup(Identifier *ident);
ChristianK@159 296
ChristianK@159 297 // Insert Dsymbol in table. Return NULL if already there.
ChristianK@159 298 Dsymbol *insert(Dsymbol *s);
ChristianK@159 299
ChristianK@159 300 // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
ChristianK@159 301 Dsymbol *update(Dsymbol *s);
ChristianK@159 302 Dsymbol *insert(Identifier *ident, Dsymbol *s); // when ident and s are not the same
ChristianK@159 303 };
ChristianK@159 304
ChristianK@159 305 #endif /* DMD_DSYMBOL_H */