annotate dmd/dsymbol.h @ 1651:cb960b882ca3 tip

bindings were moved to dsource.org/projects/bindings/
author Moritz Warning <moritzwarning@web.de>
date Thu, 20 May 2010 20:05:03 +0200
parents 9bf06e02070b
children
rev   line source
ChristianK@159 1
ChristianK@159 2 // Compiler implementation of the D programming language
kamm@1640 3 // Copyright (c) 1999-2010 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
robert@1630 24 #if IN_LLVM
tomas@1146 25 #include "../ir/irdsymbol.h"
robert@1630 26 #endif
ChristianK@173 27
ChristianK@159 28 struct Identifier;
ChristianK@159 29 struct Scope;
ChristianK@159 30 struct DsymbolTable;
ChristianK@159 31 struct Declaration;
kamm@1587 32 struct ThisDeclaration;
ChristianK@159 33 struct TupleDeclaration;
ChristianK@159 34 struct TypedefDeclaration;
ChristianK@159 35 struct AliasDeclaration;
ChristianK@159 36 struct AggregateDeclaration;
ChristianK@159 37 struct EnumDeclaration;
ChristianK@159 38 struct ClassDeclaration;
ChristianK@159 39 struct InterfaceDeclaration;
ChristianK@159 40 struct StructDeclaration;
ChristianK@159 41 struct UnionDeclaration;
ChristianK@159 42 struct FuncDeclaration;
ChristianK@159 43 struct FuncAliasDeclaration;
ChristianK@159 44 struct FuncLiteralDeclaration;
ChristianK@159 45 struct CtorDeclaration;
kamm@1587 46 struct PostBlitDeclaration;
ChristianK@159 47 struct DtorDeclaration;
ChristianK@159 48 struct StaticCtorDeclaration;
ChristianK@159 49 struct StaticDtorDeclaration;
ChristianK@159 50 struct InvariantDeclaration;
ChristianK@159 51 struct UnitTestDeclaration;
ChristianK@159 52 struct NewDeclaration;
ChristianK@159 53 struct VarDeclaration;
ChristianK@159 54 struct AttribDeclaration;
robert@1630 55 #if IN_DMD
robert@1630 56 struct Symbol;
robert@1630 57 #endif
ChristianK@159 58 struct Package;
ChristianK@159 59 struct Module;
ChristianK@159 60 struct Import;
ChristianK@159 61 struct Type;
ChristianK@159 62 struct TypeTuple;
ChristianK@159 63 struct WithStatement;
ChristianK@159 64 struct LabelDsymbol;
ChristianK@159 65 struct ScopeDsymbol;
ChristianK@159 66 struct TemplateDeclaration;
ChristianK@159 67 struct TemplateInstance;
ChristianK@159 68 struct TemplateMixin;
ChristianK@159 69 struct EnumMember;
ChristianK@159 70 struct ScopeDsymbol;
ChristianK@159 71 struct WithScopeSymbol;
ChristianK@159 72 struct ArrayScopeSymbol;
kamm@913 73 struct StaticStructInitDeclaration;
ChristianK@159 74 struct Expression;
ChristianK@159 75 struct DeleteDeclaration;
ChristianK@159 76 struct HdrGenState;
ChristianK@159 77 struct TypeInfoDeclaration;
ChristianK@159 78 struct ClassInfoDeclaration;
kamm@1587 79 struct OverloadSet;
kamm@1587 80 #if TARGET_NET
kamm@1587 81 struct PragmaScope;
kamm@1587 82 #endif
ChristianK@159 83 #if IN_GCC
ChristianK@159 84 union tree_node;
ChristianK@159 85 typedef union tree_node TYPE;
ChristianK@159 86 #else
ChristianK@159 87 struct TYPE;
ChristianK@159 88 #endif
ChristianK@159 89
kamm@1587 90 // Back end
kamm@1587 91 struct Classsym;
kamm@1587 92
ChristianK@159 93 #if IN_LLVM
tomas@1364 94 class Ir;
tomas@1364 95 class IrSymbol;
ChristianK@159 96 namespace llvm
ChristianK@159 97 {
ChristianK@159 98 class Value;
ChristianK@159 99 }
ChristianK@159 100 #endif
ChristianK@159 101
ChristianK@159 102 enum PROT
ChristianK@159 103 {
ChristianK@159 104 PROTundefined,
ChristianK@159 105 PROTnone, // no access
ChristianK@159 106 PROTprivate,
ChristianK@159 107 PROTpackage,
ChristianK@159 108 PROTprotected,
ChristianK@159 109 PROTpublic,
ChristianK@159 110 PROTexport,
ChristianK@159 111 };
ChristianK@159 112
robert@1630 113 /* State of symbol in winding its way through the passes of the compiler
robert@1630 114 */
robert@1630 115 enum PASS
robert@1630 116 {
robert@1630 117 PASSinit, // initial state
robert@1630 118 PASSsemantic, // semantic() started
robert@1630 119 PASSsemanticdone, // semantic() done
robert@1630 120 PASSsemantic2, // semantic2() run
robert@1630 121 PASSsemantic3, // semantic3() started
robert@1630 122 PASSsemantic3done, // semantic3() done
robert@1630 123 PASSobj, // toObjFile() run
robert@1630 124 };
ChristianK@159 125
ChristianK@159 126 struct Dsymbol : Object
ChristianK@159 127 {
ChristianK@159 128 Identifier *ident;
ChristianK@159 129 Identifier *c_ident;
ChristianK@159 130 Dsymbol *parent;
tomas@1146 131 #if IN_DMD
ChristianK@159 132 Symbol *csym; // symbol for code generator
ChristianK@159 133 Symbol *isym; // import version of csym
tomas@1146 134 #endif
ChristianK@159 135 unsigned char *comment; // documentation comment for this Dsymbol
ChristianK@159 136 Loc loc; // where defined
kamm@1587 137 Scope *scope; // !=NULL means context to use for semantic()
ChristianK@159 138
ChristianK@159 139 Dsymbol();
ChristianK@159 140 Dsymbol(Identifier *);
ChristianK@159 141 char *toChars();
ChristianK@159 142 char *locToChars();
ChristianK@159 143 int equals(Object *o);
ChristianK@159 144 int isAnonymous();
fvbommel@1372 145 void error(Loc loc, const char *format, ...) IS_PRINTF(3);
fvbommel@1372 146 void error(const char *format, ...) IS_PRINTF(2);
ChristianK@159 147 void checkDeprecated(Loc loc, Scope *sc);
kamm@946 148 Module *getModule(); // module where declared
kamm@946 149 Module *getCompilationModule(); // possibly different for templates
ChristianK@159 150 Dsymbol *pastMixin();
ChristianK@159 151 Dsymbol *toParent();
ChristianK@159 152 Dsymbol *toParent2();
lindquist@336 153 TemplateInstance *inTemplateInstance();
ChristianK@159 154
ChristianK@159 155 int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol()
ChristianK@159 156
ChristianK@159 157 static Array *arraySyntaxCopy(Array *a);
ChristianK@159 158
kamm@1587 159 virtual const char *toPrettyChars();
lindquist@336 160 virtual const char *kind();
ChristianK@159 161 virtual Dsymbol *toAlias(); // resolve real symbol
ChristianK@159 162 virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum);
kamm@1587 163 virtual void setScope(Scope *sc);
kamm@1587 164 virtual void importAll(Scope *sc);
ChristianK@159 165 virtual void semantic(Scope *sc);
ChristianK@159 166 virtual void semantic2(Scope *sc);
ChristianK@159 167 virtual void semantic3(Scope *sc);
ChristianK@159 168 virtual void inlineScan();
ChristianK@159 169 virtual Dsymbol *search(Loc loc, Identifier *ident, int flags);
kamm@1640 170 Dsymbol *search_correct(Identifier *id);
ChristianK@159 171 Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id);
ChristianK@159 172 virtual int overloadInsert(Dsymbol *s);
ChristianK@159 173 #ifdef _DH
ChristianK@159 174 char *toHChars();
ChristianK@159 175 virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs);
ChristianK@159 176 #endif
ChristianK@159 177 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
ChristianK@159 178 virtual void toDocBuffer(OutBuffer *buf);
kamm@1587 179 virtual void toJsonBuffer(OutBuffer *buf);
ChristianK@159 180 virtual unsigned size(Loc loc);
ChristianK@159 181 virtual int isforwardRef();
ChristianK@159 182 virtual void defineRef(Dsymbol *s);
ChristianK@159 183 virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member
ChristianK@159 184 virtual ClassDeclaration *isClassMember(); // are we a member of a class?
ChristianK@159 185 virtual int isExport(); // is Dsymbol exported?
lindquist@336 186 virtual int isImportedSymbol(); // is Dsymbol imported?
ChristianK@159 187 virtual int isDeprecated(); // is Dsymbol deprecated?
kamm@1587 188 #if DMDV2
kamm@1587 189 virtual int isOverloadable();
kamm@1587 190 #endif
ChristianK@159 191 virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol?
ChristianK@159 192 virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration?
ChristianK@159 193 virtual Type *getType(); // is this a type?
ChristianK@159 194 virtual char *mangle();
ChristianK@159 195 virtual int needThis(); // need a 'this' pointer?
ChristianK@159 196 virtual enum PROT prot();
ChristianK@159 197 virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
ChristianK@159 198 virtual int oneMember(Dsymbol **ps);
ChristianK@159 199 static int oneMembers(Array *members, Dsymbol **ps);
ChristianK@159 200 virtual int hasPointers();
ChristianK@159 201 virtual void addLocalClass(ClassDeclarations *) { }
ChristianK@159 202 virtual void checkCtorConstInit() { }
ChristianK@159 203
ChristianK@159 204 virtual void addComment(unsigned char *comment);
ChristianK@159 205 virtual void emitComment(Scope *sc);
ChristianK@159 206 void emitDitto(Scope *sc);
ChristianK@159 207
tomas@1146 208 #if IN_DMD
ChristianK@159 209 // Backend
ChristianK@159 210
ChristianK@159 211 virtual Symbol *toSymbol(); // to backend symbol
lindquist@336 212 virtual void toObjFile(int multiobj); // compile to .obj file
ChristianK@159 213 virtual int cvMember(unsigned char *p); // emit cv debug info for member
ChristianK@159 214
ChristianK@159 215 Symbol *toImport(); // to backend import symbol
ChristianK@159 216 static Symbol *toImport(Symbol *s); // to backend import symbol
ChristianK@159 217
ChristianK@159 218 Symbol *toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix); // helper
tomas@1146 219 #endif
ChristianK@159 220
ChristianK@159 221 // Eliminate need for dynamic_cast
ChristianK@159 222 virtual Package *isPackage() { return NULL; }
ChristianK@159 223 virtual Module *isModule() { return NULL; }
ChristianK@159 224 virtual EnumMember *isEnumMember() { return NULL; }
ChristianK@159 225 virtual TemplateDeclaration *isTemplateDeclaration() { return NULL; }
ChristianK@159 226 virtual TemplateInstance *isTemplateInstance() { return NULL; }
ChristianK@159 227 virtual TemplateMixin *isTemplateMixin() { return NULL; }
ChristianK@159 228 virtual Declaration *isDeclaration() { return NULL; }
kamm@1587 229 virtual ThisDeclaration *isThisDeclaration() { return NULL; }
ChristianK@159 230 virtual TupleDeclaration *isTupleDeclaration() { return NULL; }
ChristianK@159 231 virtual TypedefDeclaration *isTypedefDeclaration() { return NULL; }
ChristianK@159 232 virtual AliasDeclaration *isAliasDeclaration() { return NULL; }
ChristianK@159 233 virtual AggregateDeclaration *isAggregateDeclaration() { return NULL; }
ChristianK@159 234 virtual FuncDeclaration *isFuncDeclaration() { return NULL; }
ChristianK@159 235 virtual FuncAliasDeclaration *isFuncAliasDeclaration() { return NULL; }
ChristianK@159 236 virtual FuncLiteralDeclaration *isFuncLiteralDeclaration() { return NULL; }
ChristianK@159 237 virtual CtorDeclaration *isCtorDeclaration() { return NULL; }
kamm@1587 238 virtual PostBlitDeclaration *isPostBlitDeclaration() { return NULL; }
ChristianK@159 239 virtual DtorDeclaration *isDtorDeclaration() { return NULL; }
ChristianK@159 240 virtual StaticCtorDeclaration *isStaticCtorDeclaration() { return NULL; }
ChristianK@159 241 virtual StaticDtorDeclaration *isStaticDtorDeclaration() { return NULL; }
ChristianK@159 242 virtual InvariantDeclaration *isInvariantDeclaration() { return NULL; }
ChristianK@159 243 virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; }
ChristianK@159 244 virtual NewDeclaration *isNewDeclaration() { return NULL; }
ChristianK@159 245 virtual VarDeclaration *isVarDeclaration() { return NULL; }
ChristianK@159 246 virtual ClassDeclaration *isClassDeclaration() { return NULL; }
ChristianK@159 247 virtual StructDeclaration *isStructDeclaration() { return NULL; }
ChristianK@159 248 virtual UnionDeclaration *isUnionDeclaration() { return NULL; }
ChristianK@159 249 virtual InterfaceDeclaration *isInterfaceDeclaration() { return NULL; }
ChristianK@159 250 virtual ScopeDsymbol *isScopeDsymbol() { return NULL; }
ChristianK@159 251 virtual WithScopeSymbol *isWithScopeSymbol() { return NULL; }
ChristianK@159 252 virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; }
ChristianK@159 253 virtual Import *isImport() { return NULL; }
ChristianK@159 254 virtual EnumDeclaration *isEnumDeclaration() { return NULL; }
ChristianK@159 255 #ifdef _DH
ChristianK@159 256 virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; }
ChristianK@159 257 #endif
kamm@913 258 virtual StaticStructInitDeclaration *isStaticStructInitDeclaration() { return NULL; }
ChristianK@159 259 virtual AttribDeclaration *isAttribDeclaration() { return NULL; }
ChristianK@159 260 virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; }
ChristianK@159 261 virtual ClassInfoDeclaration* isClassInfoDeclaration() { return NULL; }
tomas@443 262
kamm@1587 263 virtual OverloadSet *isOverloadSet() { return NULL; }
kamm@1587 264 #if TARGET_NET
kamm@1587 265 virtual PragmaScope* isPragmaScope() { return NULL; }
kamm@1587 266 #endif
kamm@1587 267
tomas@1146 268 #if IN_LLVM
tomas@1147 269 /// Codegen traversal
tomas@1147 270 virtual void codegen(Ir* ir);
tomas@1147 271
ChristianK@159 272 // llvm stuff
ChristianK@159 273 int llvmInternal;
tomas@443 274
ChristianK@173 275 IrDsymbol ir;
tomas@1147 276 IrSymbol* irsym;
tomas@1146 277 #endif
ChristianK@159 278 };
ChristianK@159 279
ChristianK@159 280 // Dsymbol that generates a scope
ChristianK@159 281
ChristianK@159 282 struct ScopeDsymbol : Dsymbol
ChristianK@159 283 {
ChristianK@159 284 Array *members; // all Dsymbol's in this scope
ChristianK@159 285 DsymbolTable *symtab; // members[] sorted into table
ChristianK@159 286
ChristianK@159 287 Array *imports; // imported ScopeDsymbol's
kamm@1587 288 unsigned char *prots; // array of PROT, one for each import
ChristianK@159 289
ChristianK@159 290 ScopeDsymbol();
ChristianK@159 291 ScopeDsymbol(Identifier *id);
ChristianK@159 292 Dsymbol *syntaxCopy(Dsymbol *s);
ChristianK@159 293 Dsymbol *search(Loc loc, Identifier *ident, int flags);
ChristianK@159 294 void importScope(ScopeDsymbol *s, enum PROT protection);
ChristianK@159 295 int isforwardRef();
ChristianK@159 296 void defineRef(Dsymbol *s);
ChristianK@159 297 static void multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2);
ChristianK@159 298 Dsymbol *nameCollision(Dsymbol *s);
lindquist@336 299 const char *kind();
kamm@1587 300 FuncDeclaration *findGetMembers();
kamm@1587 301 virtual Dsymbol *symtabInsert(Dsymbol *s);
ChristianK@159 302
ChristianK@159 303 void emitMemberComments(Scope *sc);
ChristianK@159 304
kamm@1587 305 static size_t dim(Array *members);
kamm@1587 306 static Dsymbol *getNth(Array *members, size_t nth, size_t *pn = NULL);
kamm@1587 307
ChristianK@159 308 ScopeDsymbol *isScopeDsymbol() { return this; }
ChristianK@159 309 };
ChristianK@159 310
ChristianK@159 311 // With statement scope
ChristianK@159 312
ChristianK@159 313 struct WithScopeSymbol : ScopeDsymbol
ChristianK@159 314 {
ChristianK@159 315 WithStatement *withstate;
ChristianK@159 316
ChristianK@159 317 WithScopeSymbol(WithStatement *withstate);
ChristianK@159 318 Dsymbol *search(Loc loc, Identifier *ident, int flags);
ChristianK@159 319
ChristianK@159 320 WithScopeSymbol *isWithScopeSymbol() { return this; }
ChristianK@159 321 };
ChristianK@159 322
ChristianK@159 323 // Array Index/Slice scope
ChristianK@159 324
ChristianK@159 325 struct ArrayScopeSymbol : ScopeDsymbol
ChristianK@159 326 {
ChristianK@159 327 Expression *exp; // IndexExp or SliceExp
ChristianK@159 328 TypeTuple *type; // for tuple[length]
ChristianK@159 329 TupleDeclaration *td; // for tuples of objects
kamm@1587 330 Scope *sc;
ChristianK@159 331
ChristianK@159 332 ArrayScopeSymbol(Expression *e);
ChristianK@159 333 ArrayScopeSymbol(TypeTuple *t);
ChristianK@159 334 ArrayScopeSymbol(TupleDeclaration *td);
ChristianK@159 335 Dsymbol *search(Loc loc, Identifier *ident, int flags);
ChristianK@159 336
ChristianK@159 337 ArrayScopeSymbol *isArrayScopeSymbol() { return this; }
ChristianK@159 338 };
ChristianK@159 339
kamm@1587 340 // Overload Sets
kamm@1587 341
kamm@1587 342 #if DMDV2
kamm@1587 343 struct OverloadSet : Dsymbol
kamm@1587 344 {
kamm@1587 345 Dsymbols a; // array of Dsymbols
kamm@1587 346
kamm@1587 347 OverloadSet();
kamm@1587 348 void push(Dsymbol *s);
kamm@1587 349 OverloadSet *isOverloadSet() { return this; }
kamm@1587 350 const char *kind();
kamm@1587 351 };
kamm@1587 352 #endif
kamm@1587 353
ChristianK@159 354 // Table of Dsymbol's
ChristianK@159 355
ChristianK@159 356 struct DsymbolTable : Object
ChristianK@159 357 {
ChristianK@159 358 StringTable *tab;
ChristianK@159 359
ChristianK@159 360 DsymbolTable();
ChristianK@159 361 ~DsymbolTable();
ChristianK@159 362
ChristianK@159 363 // Look up Identifier. Return Dsymbol if found, NULL if not.
ChristianK@159 364 Dsymbol *lookup(Identifier *ident);
ChristianK@159 365
ChristianK@159 366 // Insert Dsymbol in table. Return NULL if already there.
ChristianK@159 367 Dsymbol *insert(Dsymbol *s);
ChristianK@159 368
ChristianK@159 369 // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
ChristianK@159 370 Dsymbol *update(Dsymbol *s);
ChristianK@159 371 Dsymbol *insert(Identifier *ident, Dsymbol *s); // when ident and s are not the same
ChristianK@159 372 };
ChristianK@159 373
ChristianK@159 374 #endif /* DMD_DSYMBOL_H */