Mercurial > projects > ldc
annotate dmd/dsymbol.h @ 1256:6af2359b433a
Change needed for mingw
author | Kelly Wilson <wilsonk cpsc.ucalgary.ca> |
---|---|
date | Wed, 22 Apr 2009 14:40:56 -0600 |
parents | dbe4af57b240 |
children | 46f6365a50d7 |
rev | line source |
---|---|
159 | 1 |
2 // Compiler implementation of the D programming language | |
336 | 3 // Copyright (c) 1999-2008 by Digital Mars |
159 | 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 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
159
diff
changeset
|
24 // llvm |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
25 #include "../ir/irdsymbol.h" |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
159
diff
changeset
|
26 |
159 | 27 struct Identifier; |
28 struct Scope; | |
29 struct DsymbolTable; | |
30 struct Declaration; | |
31 struct TupleDeclaration; | |
32 struct TypedefDeclaration; | |
33 struct AliasDeclaration; | |
34 struct AggregateDeclaration; | |
35 struct EnumDeclaration; | |
36 struct ClassDeclaration; | |
37 struct InterfaceDeclaration; | |
38 struct StructDeclaration; | |
39 struct UnionDeclaration; | |
40 struct FuncDeclaration; | |
41 struct FuncAliasDeclaration; | |
42 struct FuncLiteralDeclaration; | |
43 struct CtorDeclaration; | |
44 struct DtorDeclaration; | |
45 struct StaticCtorDeclaration; | |
46 struct StaticDtorDeclaration; | |
47 struct InvariantDeclaration; | |
48 struct UnitTestDeclaration; | |
49 struct NewDeclaration; | |
50 struct VarDeclaration; | |
51 struct AttribDeclaration; | |
52 struct Package; | |
53 struct Module; | |
54 struct Import; | |
55 struct Type; | |
56 struct TypeTuple; | |
57 struct WithStatement; | |
58 struct LabelDsymbol; | |
59 struct ScopeDsymbol; | |
60 struct TemplateDeclaration; | |
61 struct TemplateInstance; | |
62 struct TemplateMixin; | |
63 struct EnumMember; | |
64 struct ScopeDsymbol; | |
65 struct WithScopeSymbol; | |
66 struct ArrayScopeSymbol; | |
913
29c0d1194033
Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents:
443
diff
changeset
|
67 struct StaticStructInitDeclaration; |
159 | 68 struct Expression; |
69 struct DeleteDeclaration; | |
70 struct HdrGenState; | |
71 struct TypeInfoDeclaration; | |
72 struct ClassInfoDeclaration; | |
73 | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
74 #if IN_DMD |
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
75 struct Symbol; |
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
76 #endif |
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
77 |
159 | 78 #if IN_GCC |
79 union tree_node; | |
80 typedef union tree_node TYPE; | |
81 #else | |
82 struct TYPE; | |
83 #endif | |
84 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
159
diff
changeset
|
85 // llvm |
159 | 86 #if IN_LLVM |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
87 struct Ir; |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
88 struct IrSymbol; |
159 | 89 namespace llvm |
90 { | |
91 class Value; | |
92 } | |
93 #endif | |
94 | |
95 enum PROT | |
96 { | |
97 PROTundefined, | |
98 PROTnone, // no access | |
99 PROTprivate, | |
100 PROTpackage, | |
101 PROTprotected, | |
102 PROTpublic, | |
103 PROTexport, | |
104 }; | |
105 | |
106 | |
107 struct Dsymbol : Object | |
108 { | |
109 Identifier *ident; | |
110 Identifier *c_ident; | |
111 Dsymbol *parent; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
112 #if IN_DMD |
159 | 113 Symbol *csym; // symbol for code generator |
114 Symbol *isym; // import version of csym | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
115 #endif |
159 | 116 unsigned char *comment; // documentation comment for this Dsymbol |
117 Loc loc; // where defined | |
118 | |
119 Dsymbol(); | |
120 Dsymbol(Identifier *); | |
121 char *toChars(); | |
122 char *toPrettyChars(); | |
123 char *locToChars(); | |
124 int equals(Object *o); | |
125 int isAnonymous(); | |
126 void error(Loc loc, const char *format, ...); | |
127 void error(const char *format, ...); | |
128 void checkDeprecated(Loc loc, Scope *sc); | |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
913
diff
changeset
|
129 Module *getModule(); // module where declared |
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
913
diff
changeset
|
130 Module *getCompilationModule(); // possibly different for templates |
159 | 131 Dsymbol *pastMixin(); |
132 Dsymbol *toParent(); | |
133 Dsymbol *toParent2(); | |
336 | 134 TemplateInstance *inTemplateInstance(); |
159 | 135 |
136 int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol() | |
137 | |
138 static Array *arraySyntaxCopy(Array *a); | |
139 | |
336 | 140 virtual const char *kind(); |
159 | 141 virtual Dsymbol *toAlias(); // resolve real symbol |
142 virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); | |
143 virtual void semantic(Scope *sc); | |
144 virtual void semantic2(Scope *sc); | |
145 virtual void semantic3(Scope *sc); | |
146 virtual void inlineScan(); | |
147 virtual Dsymbol *search(Loc loc, Identifier *ident, int flags); | |
148 Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id); | |
149 virtual int overloadInsert(Dsymbol *s); | |
150 #ifdef _DH | |
151 char *toHChars(); | |
152 virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); | |
153 #endif | |
154 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
155 virtual void toDocBuffer(OutBuffer *buf); | |
156 virtual unsigned size(Loc loc); | |
157 virtual int isforwardRef(); | |
158 virtual void defineRef(Dsymbol *s); | |
159 virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member | |
160 virtual ClassDeclaration *isClassMember(); // are we a member of a class? | |
161 virtual int isExport(); // is Dsymbol exported? | |
336 | 162 virtual int isImportedSymbol(); // is Dsymbol imported? |
159 | 163 virtual int isDeprecated(); // is Dsymbol deprecated? |
164 virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol? | |
165 virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration? | |
166 virtual Type *getType(); // is this a type? | |
167 virtual char *mangle(); | |
168 virtual int needThis(); // need a 'this' pointer? | |
169 virtual enum PROT prot(); | |
170 virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees | |
171 virtual int oneMember(Dsymbol **ps); | |
172 static int oneMembers(Array *members, Dsymbol **ps); | |
173 virtual int hasPointers(); | |
174 virtual void addLocalClass(ClassDeclarations *) { } | |
175 virtual void checkCtorConstInit() { } | |
176 | |
177 virtual void addComment(unsigned char *comment); | |
178 virtual void emitComment(Scope *sc); | |
179 void emitDitto(Scope *sc); | |
180 | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
181 #if IN_DMD |
159 | 182 // Backend |
183 | |
184 virtual Symbol *toSymbol(); // to backend symbol | |
336 | 185 virtual void toObjFile(int multiobj); // compile to .obj file |
159 | 186 virtual int cvMember(unsigned char *p); // emit cv debug info for member |
187 | |
188 Symbol *toImport(); // to backend import symbol | |
189 static Symbol *toImport(Symbol *s); // to backend import symbol | |
190 | |
191 Symbol *toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix); // helper | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
192 #endif |
159 | 193 |
194 // Eliminate need for dynamic_cast | |
195 virtual Package *isPackage() { return NULL; } | |
196 virtual Module *isModule() { return NULL; } | |
197 virtual EnumMember *isEnumMember() { return NULL; } | |
198 virtual TemplateDeclaration *isTemplateDeclaration() { return NULL; } | |
199 virtual TemplateInstance *isTemplateInstance() { return NULL; } | |
200 virtual TemplateMixin *isTemplateMixin() { return NULL; } | |
201 virtual Declaration *isDeclaration() { return NULL; } | |
202 virtual TupleDeclaration *isTupleDeclaration() { return NULL; } | |
203 virtual TypedefDeclaration *isTypedefDeclaration() { return NULL; } | |
204 virtual AliasDeclaration *isAliasDeclaration() { return NULL; } | |
205 virtual AggregateDeclaration *isAggregateDeclaration() { return NULL; } | |
206 virtual FuncDeclaration *isFuncDeclaration() { return NULL; } | |
207 virtual FuncAliasDeclaration *isFuncAliasDeclaration() { return NULL; } | |
208 virtual FuncLiteralDeclaration *isFuncLiteralDeclaration() { return NULL; } | |
209 virtual CtorDeclaration *isCtorDeclaration() { return NULL; } | |
210 virtual DtorDeclaration *isDtorDeclaration() { return NULL; } | |
211 virtual StaticCtorDeclaration *isStaticCtorDeclaration() { return NULL; } | |
212 virtual StaticDtorDeclaration *isStaticDtorDeclaration() { return NULL; } | |
213 virtual InvariantDeclaration *isInvariantDeclaration() { return NULL; } | |
214 virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; } | |
215 virtual NewDeclaration *isNewDeclaration() { return NULL; } | |
216 virtual VarDeclaration *isVarDeclaration() { return NULL; } | |
217 virtual ClassDeclaration *isClassDeclaration() { return NULL; } | |
218 virtual StructDeclaration *isStructDeclaration() { return NULL; } | |
219 virtual UnionDeclaration *isUnionDeclaration() { return NULL; } | |
220 virtual InterfaceDeclaration *isInterfaceDeclaration() { return NULL; } | |
221 virtual ScopeDsymbol *isScopeDsymbol() { return NULL; } | |
222 virtual WithScopeSymbol *isWithScopeSymbol() { return NULL; } | |
223 virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; } | |
224 virtual Import *isImport() { return NULL; } | |
225 virtual EnumDeclaration *isEnumDeclaration() { return NULL; } | |
226 #ifdef _DH | |
227 virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; } | |
228 #endif | |
913
29c0d1194033
Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents:
443
diff
changeset
|
229 virtual StaticStructInitDeclaration *isStaticStructInitDeclaration() { return NULL; } |
159 | 230 virtual AttribDeclaration *isAttribDeclaration() { return NULL; } |
231 virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; } | |
232 virtual ClassInfoDeclaration* isClassInfoDeclaration() { return NULL; } | |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
233 |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
234 #if IN_LLVM |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
235 /// Codegen traversal |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
236 virtual void codegen(Ir* ir); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
237 |
159 | 238 // llvm stuff |
239 int llvmInternal; | |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
240 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
159
diff
changeset
|
241 IrDsymbol ir; |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
242 IrSymbol* irsym; |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
243 #endif |
159 | 244 }; |
245 | |
246 // Dsymbol that generates a scope | |
247 | |
248 struct ScopeDsymbol : Dsymbol | |
249 { | |
250 Array *members; // all Dsymbol's in this scope | |
251 DsymbolTable *symtab; // members[] sorted into table | |
252 | |
253 Array *imports; // imported ScopeDsymbol's | |
254 unsigned char *prots; // PROT for each import | |
255 | |
256 ScopeDsymbol(); | |
257 ScopeDsymbol(Identifier *id); | |
258 Dsymbol *syntaxCopy(Dsymbol *s); | |
259 Dsymbol *search(Loc loc, Identifier *ident, int flags); | |
260 void importScope(ScopeDsymbol *s, enum PROT protection); | |
261 int isforwardRef(); | |
262 void defineRef(Dsymbol *s); | |
263 static void multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2); | |
264 Dsymbol *nameCollision(Dsymbol *s); | |
336 | 265 const char *kind(); |
159 | 266 |
267 void emitMemberComments(Scope *sc); | |
268 | |
269 ScopeDsymbol *isScopeDsymbol() { return this; } | |
270 }; | |
271 | |
272 // With statement scope | |
273 | |
274 struct WithScopeSymbol : ScopeDsymbol | |
275 { | |
276 WithStatement *withstate; | |
277 | |
278 WithScopeSymbol(WithStatement *withstate); | |
279 Dsymbol *search(Loc loc, Identifier *ident, int flags); | |
280 | |
281 WithScopeSymbol *isWithScopeSymbol() { return this; } | |
282 }; | |
283 | |
284 // Array Index/Slice scope | |
285 | |
286 struct ArrayScopeSymbol : ScopeDsymbol | |
287 { | |
288 Expression *exp; // IndexExp or SliceExp | |
289 TypeTuple *type; // for tuple[length] | |
290 TupleDeclaration *td; // for tuples of objects | |
291 | |
292 ArrayScopeSymbol(Expression *e); | |
293 ArrayScopeSymbol(TypeTuple *t); | |
294 ArrayScopeSymbol(TupleDeclaration *td); | |
295 Dsymbol *search(Loc loc, Identifier *ident, int flags); | |
296 | |
297 ArrayScopeSymbol *isArrayScopeSymbol() { return this; } | |
298 }; | |
299 | |
300 // Table of Dsymbol's | |
301 | |
302 struct DsymbolTable : Object | |
303 { | |
304 StringTable *tab; | |
305 | |
306 DsymbolTable(); | |
307 ~DsymbolTable(); | |
308 | |
309 // Look up Identifier. Return Dsymbol if found, NULL if not. | |
310 Dsymbol *lookup(Identifier *ident); | |
311 | |
312 // Insert Dsymbol in table. Return NULL if already there. | |
313 Dsymbol *insert(Dsymbol *s); | |
314 | |
315 // Look for Dsymbol in table. If there, return it. If not, insert s and return that. | |
316 Dsymbol *update(Dsymbol *s); | |
317 Dsymbol *insert(Identifier *ident, Dsymbol *s); // when ident and s are not the same | |
318 }; | |
319 | |
320 #endif /* DMD_DSYMBOL_H */ |