annotate dmd/dsymbol.h @ 159:5acec6b2eef8 trunk

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