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