annotate dmd/dsymbol.h @ 884:a166ba5bdf2d

Automated merge with http://hg.dsource.org/projects/ldc
author Christian Kamm <kamm incasoftware de>
date Mon, 12 Jan 2009 07:51:39 +0100
parents 44f08170f4ef
children 29c0d1194033
rev   line source
ChristianK@159 1
ChristianK@159 2 // Compiler implementation of the D programming language
lindquist@336 3 // Copyright (c) 1999-2008 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();
lindquist@336 126 TemplateInstance *inTemplateInstance();
ChristianK@159 127
ChristianK@159 128 int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol()
ChristianK@159 129
ChristianK@159 130 static Array *arraySyntaxCopy(Array *a);
ChristianK@159 131
lindquist@336 132 virtual const char *kind();
ChristianK@159 133 virtual Dsymbol *toAlias(); // resolve real symbol
ChristianK@159 134 virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum);
ChristianK@159 135 virtual void semantic(Scope *sc);
ChristianK@159 136 virtual void semantic2(Scope *sc);
ChristianK@159 137 virtual void semantic3(Scope *sc);
ChristianK@159 138 virtual void inlineScan();
ChristianK@159 139 virtual Dsymbol *search(Loc loc, Identifier *ident, int flags);
ChristianK@159 140 Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id);
ChristianK@159 141 virtual int overloadInsert(Dsymbol *s);
ChristianK@159 142 #ifdef _DH
ChristianK@159 143 char *toHChars();
ChristianK@159 144 virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs);
ChristianK@159 145 #endif
ChristianK@159 146 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
ChristianK@159 147 virtual void toDocBuffer(OutBuffer *buf);
ChristianK@159 148 virtual unsigned size(Loc loc);
ChristianK@159 149 virtual int isforwardRef();
ChristianK@159 150 virtual void defineRef(Dsymbol *s);
ChristianK@159 151 virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member
ChristianK@159 152 virtual ClassDeclaration *isClassMember(); // are we a member of a class?
ChristianK@159 153 virtual int isExport(); // is Dsymbol exported?
lindquist@336 154 virtual int isImportedSymbol(); // is Dsymbol imported?
ChristianK@159 155 virtual int isDeprecated(); // is Dsymbol deprecated?
ChristianK@159 156 virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol?
ChristianK@159 157 virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration?
ChristianK@159 158 virtual Type *getType(); // is this a type?
ChristianK@159 159 virtual char *mangle();
ChristianK@159 160 virtual int needThis(); // need a 'this' pointer?
ChristianK@159 161 virtual enum PROT prot();
ChristianK@159 162 virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
ChristianK@159 163 virtual int oneMember(Dsymbol **ps);
ChristianK@159 164 static int oneMembers(Array *members, Dsymbol **ps);
ChristianK@159 165 virtual int hasPointers();
ChristianK@159 166 virtual void addLocalClass(ClassDeclarations *) { }
ChristianK@159 167 virtual void checkCtorConstInit() { }
ChristianK@159 168
ChristianK@159 169 virtual void addComment(unsigned char *comment);
ChristianK@159 170 virtual void emitComment(Scope *sc);
ChristianK@159 171 void emitDitto(Scope *sc);
ChristianK@159 172
ChristianK@159 173 // Backend
ChristianK@159 174
ChristianK@159 175 virtual Symbol *toSymbol(); // to backend symbol
lindquist@336 176 virtual void toObjFile(int multiobj); // compile to .obj file
ChristianK@159 177 virtual int cvMember(unsigned char *p); // emit cv debug info for member
ChristianK@159 178
ChristianK@159 179 Symbol *toImport(); // to backend import symbol
ChristianK@159 180 static Symbol *toImport(Symbol *s); // to backend import symbol
ChristianK@159 181
ChristianK@159 182 Symbol *toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix); // helper
ChristianK@159 183
ChristianK@159 184 // Eliminate need for dynamic_cast
ChristianK@159 185 virtual Package *isPackage() { return NULL; }
ChristianK@159 186 virtual Module *isModule() { return NULL; }
ChristianK@159 187 virtual EnumMember *isEnumMember() { return NULL; }
ChristianK@159 188 virtual TemplateDeclaration *isTemplateDeclaration() { return NULL; }
ChristianK@159 189 virtual TemplateInstance *isTemplateInstance() { return NULL; }
ChristianK@159 190 virtual TemplateMixin *isTemplateMixin() { return NULL; }
ChristianK@159 191 virtual Declaration *isDeclaration() { return NULL; }
ChristianK@159 192 virtual TupleDeclaration *isTupleDeclaration() { return NULL; }
ChristianK@159 193 virtual TypedefDeclaration *isTypedefDeclaration() { return NULL; }
ChristianK@159 194 virtual AliasDeclaration *isAliasDeclaration() { return NULL; }
ChristianK@159 195 virtual AggregateDeclaration *isAggregateDeclaration() { return NULL; }
ChristianK@159 196 virtual FuncDeclaration *isFuncDeclaration() { return NULL; }
ChristianK@159 197 virtual FuncAliasDeclaration *isFuncAliasDeclaration() { return NULL; }
ChristianK@159 198 virtual FuncLiteralDeclaration *isFuncLiteralDeclaration() { return NULL; }
ChristianK@159 199 virtual CtorDeclaration *isCtorDeclaration() { return NULL; }
ChristianK@159 200 virtual DtorDeclaration *isDtorDeclaration() { return NULL; }
ChristianK@159 201 virtual StaticCtorDeclaration *isStaticCtorDeclaration() { return NULL; }
ChristianK@159 202 virtual StaticDtorDeclaration *isStaticDtorDeclaration() { return NULL; }
ChristianK@159 203 virtual InvariantDeclaration *isInvariantDeclaration() { return NULL; }
ChristianK@159 204 virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; }
ChristianK@159 205 virtual NewDeclaration *isNewDeclaration() { return NULL; }
ChristianK@159 206 virtual VarDeclaration *isVarDeclaration() { return NULL; }
ChristianK@159 207 virtual ClassDeclaration *isClassDeclaration() { return NULL; }
ChristianK@159 208 virtual StructDeclaration *isStructDeclaration() { return NULL; }
ChristianK@159 209 virtual UnionDeclaration *isUnionDeclaration() { return NULL; }
ChristianK@159 210 virtual InterfaceDeclaration *isInterfaceDeclaration() { return NULL; }
ChristianK@159 211 virtual ScopeDsymbol *isScopeDsymbol() { return NULL; }
ChristianK@159 212 virtual WithScopeSymbol *isWithScopeSymbol() { return NULL; }
ChristianK@159 213 virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; }
ChristianK@159 214 virtual Import *isImport() { return NULL; }
ChristianK@159 215 virtual EnumDeclaration *isEnumDeclaration() { return NULL; }
ChristianK@159 216 #ifdef _DH
ChristianK@159 217 virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; }
ChristianK@159 218 #endif
ChristianK@159 219 virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; }
ChristianK@159 220 virtual AttribDeclaration *isAttribDeclaration() { return NULL; }
ChristianK@159 221 virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; }
ChristianK@159 222 virtual ClassInfoDeclaration* isClassInfoDeclaration() { return NULL; }
tomas@443 223
ChristianK@159 224 // llvm stuff
ChristianK@159 225 int llvmInternal;
tomas@443 226
ChristianK@173 227 IrDsymbol ir;
ChristianK@159 228 };
ChristianK@159 229
ChristianK@159 230 // Dsymbol that generates a scope
ChristianK@159 231
ChristianK@159 232 struct ScopeDsymbol : Dsymbol
ChristianK@159 233 {
ChristianK@159 234 Array *members; // all Dsymbol's in this scope
ChristianK@159 235 DsymbolTable *symtab; // members[] sorted into table
ChristianK@159 236
ChristianK@159 237 Array *imports; // imported ScopeDsymbol's
ChristianK@159 238 unsigned char *prots; // PROT for each import
ChristianK@159 239
ChristianK@159 240 ScopeDsymbol();
ChristianK@159 241 ScopeDsymbol(Identifier *id);
ChristianK@159 242 Dsymbol *syntaxCopy(Dsymbol *s);
ChristianK@159 243 Dsymbol *search(Loc loc, Identifier *ident, int flags);
ChristianK@159 244 void importScope(ScopeDsymbol *s, enum PROT protection);
ChristianK@159 245 int isforwardRef();
ChristianK@159 246 void defineRef(Dsymbol *s);
ChristianK@159 247 static void multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2);
ChristianK@159 248 Dsymbol *nameCollision(Dsymbol *s);
lindquist@336 249 const char *kind();
ChristianK@159 250
ChristianK@159 251 void emitMemberComments(Scope *sc);
ChristianK@159 252
ChristianK@159 253 ScopeDsymbol *isScopeDsymbol() { return this; }
ChristianK@159 254 };
ChristianK@159 255
ChristianK@159 256 // With statement scope
ChristianK@159 257
ChristianK@159 258 struct WithScopeSymbol : ScopeDsymbol
ChristianK@159 259 {
ChristianK@159 260 WithStatement *withstate;
ChristianK@159 261
ChristianK@159 262 WithScopeSymbol(WithStatement *withstate);
ChristianK@159 263 Dsymbol *search(Loc loc, Identifier *ident, int flags);
ChristianK@159 264
ChristianK@159 265 WithScopeSymbol *isWithScopeSymbol() { return this; }
ChristianK@159 266 };
ChristianK@159 267
ChristianK@159 268 // Array Index/Slice scope
ChristianK@159 269
ChristianK@159 270 struct ArrayScopeSymbol : ScopeDsymbol
ChristianK@159 271 {
ChristianK@159 272 Expression *exp; // IndexExp or SliceExp
ChristianK@159 273 TypeTuple *type; // for tuple[length]
ChristianK@159 274 TupleDeclaration *td; // for tuples of objects
ChristianK@159 275
ChristianK@159 276 ArrayScopeSymbol(Expression *e);
ChristianK@159 277 ArrayScopeSymbol(TypeTuple *t);
ChristianK@159 278 ArrayScopeSymbol(TupleDeclaration *td);
ChristianK@159 279 Dsymbol *search(Loc loc, Identifier *ident, int flags);
ChristianK@159 280
ChristianK@159 281 ArrayScopeSymbol *isArrayScopeSymbol() { return this; }
ChristianK@159 282 };
ChristianK@159 283
ChristianK@159 284 // Table of Dsymbol's
ChristianK@159 285
ChristianK@159 286 struct DsymbolTable : Object
ChristianK@159 287 {
ChristianK@159 288 StringTable *tab;
ChristianK@159 289
ChristianK@159 290 DsymbolTable();
ChristianK@159 291 ~DsymbolTable();
ChristianK@159 292
ChristianK@159 293 // Look up Identifier. Return Dsymbol if found, NULL if not.
ChristianK@159 294 Dsymbol *lookup(Identifier *ident);
ChristianK@159 295
ChristianK@159 296 // Insert Dsymbol in table. Return NULL if already there.
ChristianK@159 297 Dsymbol *insert(Dsymbol *s);
ChristianK@159 298
ChristianK@159 299 // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
ChristianK@159 300 Dsymbol *update(Dsymbol *s);
ChristianK@159 301 Dsymbol *insert(Identifier *ident, Dsymbol *s); // when ident and s are not the same
ChristianK@159 302 };
ChristianK@159 303
ChristianK@159 304 #endif /* DMD_DSYMBOL_H */