ChristianK@159: ChristianK@159: // Compiler implementation of the D programming language ChristianK@159: // Copyright (c) 1999-2007 by Digital Mars ChristianK@159: // All Rights Reserved ChristianK@159: // written by Walter Bright ChristianK@159: // http://www.digitalmars.com ChristianK@159: // License for redistribution is by either the Artistic License ChristianK@159: // in artistic.txt, or the GNU General Public License in gnu.txt. ChristianK@159: // See the included readme.txt for details. ChristianK@159: ChristianK@159: #ifndef DMD_DSYMBOL_H ChristianK@159: #define DMD_DSYMBOL_H ChristianK@159: ChristianK@159: #ifdef __DMC__ ChristianK@159: #pragma once ChristianK@159: #endif /* __DMC__ */ ChristianK@159: ChristianK@159: #include "root.h" ChristianK@159: #include "stringtable.h" ChristianK@159: ChristianK@159: #include "mars.h" ChristianK@159: #include "arraytypes.h" ChristianK@159: ChristianK@159: struct Identifier; ChristianK@159: struct Scope; ChristianK@159: struct DsymbolTable; ChristianK@159: struct Declaration; ChristianK@159: struct TupleDeclaration; ChristianK@159: struct TypedefDeclaration; ChristianK@159: struct AliasDeclaration; ChristianK@159: struct AggregateDeclaration; ChristianK@159: struct EnumDeclaration; ChristianK@159: struct ClassDeclaration; ChristianK@159: struct InterfaceDeclaration; ChristianK@159: struct StructDeclaration; ChristianK@159: struct UnionDeclaration; ChristianK@159: struct FuncDeclaration; ChristianK@159: struct FuncAliasDeclaration; ChristianK@159: struct FuncLiteralDeclaration; ChristianK@159: struct CtorDeclaration; ChristianK@159: struct DtorDeclaration; ChristianK@159: struct StaticCtorDeclaration; ChristianK@159: struct StaticDtorDeclaration; ChristianK@159: struct InvariantDeclaration; ChristianK@159: struct UnitTestDeclaration; ChristianK@159: struct NewDeclaration; ChristianK@159: struct VarDeclaration; ChristianK@159: struct AttribDeclaration; ChristianK@159: struct Symbol; ChristianK@159: struct Package; ChristianK@159: struct Module; ChristianK@159: struct Import; ChristianK@159: struct Type; ChristianK@159: struct TypeTuple; ChristianK@159: struct WithStatement; ChristianK@159: struct LabelDsymbol; ChristianK@159: struct ScopeDsymbol; ChristianK@159: struct TemplateDeclaration; ChristianK@159: struct TemplateInstance; ChristianK@159: struct TemplateMixin; ChristianK@159: struct EnumMember; ChristianK@159: struct ScopeDsymbol; ChristianK@159: struct WithScopeSymbol; ChristianK@159: struct ArrayScopeSymbol; ChristianK@159: struct SymbolDeclaration; ChristianK@159: struct Expression; ChristianK@159: struct DeleteDeclaration; ChristianK@159: struct HdrGenState; ChristianK@159: struct TypeInfoDeclaration; ChristianK@159: struct ClassInfoDeclaration; ChristianK@159: ChristianK@159: #if IN_GCC ChristianK@159: union tree_node; ChristianK@159: typedef union tree_node TYPE; ChristianK@159: #else ChristianK@159: struct TYPE; ChristianK@159: #endif ChristianK@159: ChristianK@159: #if IN_LLVM ChristianK@159: namespace llvm ChristianK@159: { ChristianK@159: class Value; ChristianK@159: } ChristianK@159: #endif ChristianK@159: ChristianK@159: enum PROT ChristianK@159: { ChristianK@159: PROTundefined, ChristianK@159: PROTnone, // no access ChristianK@159: PROTprivate, ChristianK@159: PROTpackage, ChristianK@159: PROTprotected, ChristianK@159: PROTpublic, ChristianK@159: PROTexport, ChristianK@159: }; ChristianK@159: ChristianK@159: ChristianK@159: struct Dsymbol : Object ChristianK@159: { ChristianK@159: Identifier *ident; ChristianK@159: Identifier *c_ident; ChristianK@159: Dsymbol *parent; ChristianK@159: Symbol *csym; // symbol for code generator ChristianK@159: Symbol *isym; // import version of csym ChristianK@159: unsigned char *comment; // documentation comment for this Dsymbol ChristianK@159: Loc loc; // where defined ChristianK@159: ChristianK@159: Dsymbol(); ChristianK@159: Dsymbol(Identifier *); ChristianK@159: char *toChars(); ChristianK@159: char *toPrettyChars(); ChristianK@159: char *locToChars(); ChristianK@159: int equals(Object *o); ChristianK@159: int isAnonymous(); ChristianK@159: void error(Loc loc, const char *format, ...); ChristianK@159: void error(const char *format, ...); ChristianK@159: void checkDeprecated(Loc loc, Scope *sc); ChristianK@159: Module *getModule(); ChristianK@159: Dsymbol *pastMixin(); ChristianK@159: Dsymbol *toParent(); ChristianK@159: Dsymbol *toParent2(); ChristianK@159: ChristianK@159: int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol() ChristianK@159: ChristianK@159: static Array *arraySyntaxCopy(Array *a); ChristianK@159: ChristianK@159: virtual char *kind(); ChristianK@159: virtual Dsymbol *toAlias(); // resolve real symbol ChristianK@159: virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); ChristianK@159: virtual void semantic(Scope *sc); ChristianK@159: virtual void semantic2(Scope *sc); ChristianK@159: virtual void semantic3(Scope *sc); ChristianK@159: virtual void inlineScan(); ChristianK@159: virtual Dsymbol *search(Loc loc, Identifier *ident, int flags); ChristianK@159: Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id); ChristianK@159: virtual int overloadInsert(Dsymbol *s); ChristianK@159: #ifdef _DH ChristianK@159: char *toHChars(); ChristianK@159: virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); ChristianK@159: #endif ChristianK@159: virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs); ChristianK@159: virtual void toDocBuffer(OutBuffer *buf); ChristianK@159: virtual unsigned size(Loc loc); ChristianK@159: virtual int isforwardRef(); ChristianK@159: virtual void defineRef(Dsymbol *s); ChristianK@159: virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member ChristianK@159: virtual ClassDeclaration *isClassMember(); // are we a member of a class? ChristianK@159: virtual int isExport(); // is Dsymbol exported? ChristianK@159: virtual int isImportedSymbol(); // is Dsymbol imported? ChristianK@159: virtual int isDeprecated(); // is Dsymbol deprecated? ChristianK@159: virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol? ChristianK@159: virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration? ChristianK@159: virtual Type *getType(); // is this a type? ChristianK@159: virtual char *mangle(); ChristianK@159: virtual int needThis(); // need a 'this' pointer? ChristianK@159: virtual enum PROT prot(); ChristianK@159: virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees ChristianK@159: virtual int oneMember(Dsymbol **ps); ChristianK@159: static int oneMembers(Array *members, Dsymbol **ps); ChristianK@159: virtual int hasPointers(); ChristianK@159: virtual void addLocalClass(ClassDeclarations *) { } ChristianK@159: virtual void checkCtorConstInit() { } ChristianK@159: ChristianK@159: virtual void addComment(unsigned char *comment); ChristianK@159: virtual void emitComment(Scope *sc); ChristianK@159: void emitDitto(Scope *sc); ChristianK@159: ChristianK@159: // Backend ChristianK@159: ChristianK@159: virtual Symbol *toSymbol(); // to backend symbol ChristianK@159: virtual void toObjFile(); // compile to .obj file ChristianK@159: virtual int cvMember(unsigned char *p); // emit cv debug info for member ChristianK@159: ChristianK@159: Symbol *toImport(); // to backend import symbol ChristianK@159: static Symbol *toImport(Symbol *s); // to backend import symbol ChristianK@159: ChristianK@159: Symbol *toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix); // helper ChristianK@159: ChristianK@159: // Eliminate need for dynamic_cast ChristianK@159: virtual Package *isPackage() { return NULL; } ChristianK@159: virtual Module *isModule() { return NULL; } ChristianK@159: virtual EnumMember *isEnumMember() { return NULL; } ChristianK@159: virtual TemplateDeclaration *isTemplateDeclaration() { return NULL; } ChristianK@159: virtual TemplateInstance *isTemplateInstance() { return NULL; } ChristianK@159: virtual TemplateMixin *isTemplateMixin() { return NULL; } ChristianK@159: virtual Declaration *isDeclaration() { return NULL; } ChristianK@159: virtual TupleDeclaration *isTupleDeclaration() { return NULL; } ChristianK@159: virtual TypedefDeclaration *isTypedefDeclaration() { return NULL; } ChristianK@159: virtual AliasDeclaration *isAliasDeclaration() { return NULL; } ChristianK@159: virtual AggregateDeclaration *isAggregateDeclaration() { return NULL; } ChristianK@159: virtual FuncDeclaration *isFuncDeclaration() { return NULL; } ChristianK@159: virtual FuncAliasDeclaration *isFuncAliasDeclaration() { return NULL; } ChristianK@159: virtual FuncLiteralDeclaration *isFuncLiteralDeclaration() { return NULL; } ChristianK@159: virtual CtorDeclaration *isCtorDeclaration() { return NULL; } ChristianK@159: virtual DtorDeclaration *isDtorDeclaration() { return NULL; } ChristianK@159: virtual StaticCtorDeclaration *isStaticCtorDeclaration() { return NULL; } ChristianK@159: virtual StaticDtorDeclaration *isStaticDtorDeclaration() { return NULL; } ChristianK@159: virtual InvariantDeclaration *isInvariantDeclaration() { return NULL; } ChristianK@159: virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; } ChristianK@159: virtual NewDeclaration *isNewDeclaration() { return NULL; } ChristianK@159: virtual VarDeclaration *isVarDeclaration() { return NULL; } ChristianK@159: virtual ClassDeclaration *isClassDeclaration() { return NULL; } ChristianK@159: virtual StructDeclaration *isStructDeclaration() { return NULL; } ChristianK@159: virtual UnionDeclaration *isUnionDeclaration() { return NULL; } ChristianK@159: virtual InterfaceDeclaration *isInterfaceDeclaration() { return NULL; } ChristianK@159: virtual ScopeDsymbol *isScopeDsymbol() { return NULL; } ChristianK@159: virtual WithScopeSymbol *isWithScopeSymbol() { return NULL; } ChristianK@159: virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; } ChristianK@159: virtual Import *isImport() { return NULL; } ChristianK@159: virtual EnumDeclaration *isEnumDeclaration() { return NULL; } ChristianK@159: #ifdef _DH ChristianK@159: virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; } ChristianK@159: #endif ChristianK@159: virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; } ChristianK@159: virtual AttribDeclaration *isAttribDeclaration() { return NULL; } ChristianK@159: virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; } ChristianK@159: virtual ClassInfoDeclaration* isClassInfoDeclaration() { return NULL; } ChristianK@159: ChristianK@159: // llvm stuff ChristianK@159: int llvmInternal; ChristianK@159: char* llvmInternal1; ChristianK@159: char* llvmInternal2; ChristianK@159: }; ChristianK@159: ChristianK@159: // Dsymbol that generates a scope ChristianK@159: ChristianK@159: struct ScopeDsymbol : Dsymbol ChristianK@159: { ChristianK@159: Array *members; // all Dsymbol's in this scope ChristianK@159: DsymbolTable *symtab; // members[] sorted into table ChristianK@159: ChristianK@159: Array *imports; // imported ScopeDsymbol's ChristianK@159: unsigned char *prots; // PROT for each import ChristianK@159: ChristianK@159: ScopeDsymbol(); ChristianK@159: ScopeDsymbol(Identifier *id); ChristianK@159: Dsymbol *syntaxCopy(Dsymbol *s); ChristianK@159: Dsymbol *search(Loc loc, Identifier *ident, int flags); ChristianK@159: void importScope(ScopeDsymbol *s, enum PROT protection); ChristianK@159: int isforwardRef(); ChristianK@159: void defineRef(Dsymbol *s); ChristianK@159: static void multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2); ChristianK@159: Dsymbol *nameCollision(Dsymbol *s); ChristianK@159: char *kind(); ChristianK@159: ChristianK@159: void emitMemberComments(Scope *sc); ChristianK@159: ChristianK@159: ScopeDsymbol *isScopeDsymbol() { return this; } ChristianK@159: }; ChristianK@159: ChristianK@159: // With statement scope ChristianK@159: ChristianK@159: struct WithScopeSymbol : ScopeDsymbol ChristianK@159: { ChristianK@159: WithStatement *withstate; ChristianK@159: ChristianK@159: WithScopeSymbol(WithStatement *withstate); ChristianK@159: Dsymbol *search(Loc loc, Identifier *ident, int flags); ChristianK@159: ChristianK@159: WithScopeSymbol *isWithScopeSymbol() { return this; } ChristianK@159: }; ChristianK@159: ChristianK@159: // Array Index/Slice scope ChristianK@159: ChristianK@159: struct ArrayScopeSymbol : ScopeDsymbol ChristianK@159: { ChristianK@159: Expression *exp; // IndexExp or SliceExp ChristianK@159: TypeTuple *type; // for tuple[length] ChristianK@159: TupleDeclaration *td; // for tuples of objects ChristianK@159: ChristianK@159: ArrayScopeSymbol(Expression *e); ChristianK@159: ArrayScopeSymbol(TypeTuple *t); ChristianK@159: ArrayScopeSymbol(TupleDeclaration *td); ChristianK@159: Dsymbol *search(Loc loc, Identifier *ident, int flags); ChristianK@159: ChristianK@159: ArrayScopeSymbol *isArrayScopeSymbol() { return this; } ChristianK@159: }; ChristianK@159: ChristianK@159: // Table of Dsymbol's ChristianK@159: ChristianK@159: struct DsymbolTable : Object ChristianK@159: { ChristianK@159: StringTable *tab; ChristianK@159: ChristianK@159: DsymbolTable(); ChristianK@159: ~DsymbolTable(); ChristianK@159: ChristianK@159: // Look up Identifier. Return Dsymbol if found, NULL if not. ChristianK@159: Dsymbol *lookup(Identifier *ident); ChristianK@159: ChristianK@159: // Insert Dsymbol in table. Return NULL if already there. ChristianK@159: Dsymbol *insert(Dsymbol *s); ChristianK@159: ChristianK@159: // Look for Dsymbol in table. If there, return it. If not, insert s and return that. ChristianK@159: Dsymbol *update(Dsymbol *s); ChristianK@159: Dsymbol *insert(Identifier *ident, Dsymbol *s); // when ident and s are not the same ChristianK@159: }; ChristianK@159: ChristianK@159: #endif /* DMD_DSYMBOL_H */