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