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