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