Mercurial > projects > ldc
annotate dmd/dsymbol.h @ 1146:1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
* Added #if IN_DMD versioning around DMD backend specific code in the D1 frontend, D2 is currently broken.
* All part of a greater cleanup scheme.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail.com> |
---|---|
date | Thu, 26 Mar 2009 20:45:53 +0100 |
parents | 1714836f2c0b |
children | dbe4af57b240 |
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 |
87 namespace llvm | |
88 { | |
89 class Value; | |
90 } | |
91 #endif | |
92 | |
93 enum PROT | |
94 { | |
95 PROTundefined, | |
96 PROTnone, // no access | |
97 PROTprivate, | |
98 PROTpackage, | |
99 PROTprotected, | |
100 PROTpublic, | |
101 PROTexport, | |
102 }; | |
103 | |
104 | |
105 struct Dsymbol : Object | |
106 { | |
107 Identifier *ident; | |
108 Identifier *c_ident; | |
109 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
|
110 #if IN_DMD |
159 | 111 Symbol *csym; // symbol for code generator |
112 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
|
113 #endif |
159 | 114 unsigned char *comment; // documentation comment for this Dsymbol |
115 Loc loc; // where defined | |
116 | |
117 Dsymbol(); | |
118 Dsymbol(Identifier *); | |
119 char *toChars(); | |
120 char *toPrettyChars(); | |
121 char *locToChars(); | |
122 int equals(Object *o); | |
123 int isAnonymous(); | |
124 void error(Loc loc, const char *format, ...); | |
125 void error(const char *format, ...); | |
126 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
|
127 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
|
128 Module *getCompilationModule(); // possibly different for templates |
159 | 129 Dsymbol *pastMixin(); |
130 Dsymbol *toParent(); | |
131 Dsymbol *toParent2(); | |
336 | 132 TemplateInstance *inTemplateInstance(); |
159 | 133 |
134 int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol() | |
135 | |
136 static Array *arraySyntaxCopy(Array *a); | |
137 | |
336 | 138 virtual const char *kind(); |
159 | 139 virtual Dsymbol *toAlias(); // resolve real symbol |
140 virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); | |
141 virtual void semantic(Scope *sc); | |
142 virtual void semantic2(Scope *sc); | |
143 virtual void semantic3(Scope *sc); | |
144 virtual void inlineScan(); | |
145 virtual Dsymbol *search(Loc loc, Identifier *ident, int flags); | |
146 Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id); | |
147 virtual int overloadInsert(Dsymbol *s); | |
148 #ifdef _DH | |
149 char *toHChars(); | |
150 virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); | |
151 #endif | |
152 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
153 virtual void toDocBuffer(OutBuffer *buf); | |
154 virtual unsigned size(Loc loc); | |
155 virtual int isforwardRef(); | |
156 virtual void defineRef(Dsymbol *s); | |
157 virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member | |
158 virtual ClassDeclaration *isClassMember(); // are we a member of a class? | |
159 virtual int isExport(); // is Dsymbol exported? | |
336 | 160 virtual int isImportedSymbol(); // is Dsymbol imported? |
159 | 161 virtual int isDeprecated(); // is Dsymbol deprecated? |
162 virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol? | |
163 virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration? | |
164 virtual Type *getType(); // is this a type? | |
165 virtual char *mangle(); | |
166 virtual int needThis(); // need a 'this' pointer? | |
167 virtual enum PROT prot(); | |
168 virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees | |
169 virtual int oneMember(Dsymbol **ps); | |
170 static int oneMembers(Array *members, Dsymbol **ps); | |
171 virtual int hasPointers(); | |
172 virtual void addLocalClass(ClassDeclarations *) { } | |
173 virtual void checkCtorConstInit() { } | |
174 | |
175 virtual void addComment(unsigned char *comment); | |
176 virtual void emitComment(Scope *sc); | |
177 void emitDitto(Scope *sc); | |
178 | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
179 #if IN_DMD |
159 | 180 // Backend |
181 | |
182 virtual Symbol *toSymbol(); // to backend symbol | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
183 #endif |
336 | 184 virtual void toObjFile(int multiobj); // compile to .obj file |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
185 #if IN_DMD |
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 |
159 | 235 // llvm stuff |
236 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
|
237 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
159
diff
changeset
|
238 IrDsymbol ir; |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
946
diff
changeset
|
239 #endif |
159 | 240 }; |
241 | |
242 // Dsymbol that generates a scope | |
243 | |
244 struct ScopeDsymbol : Dsymbol | |
245 { | |
246 Array *members; // all Dsymbol's in this scope | |
247 DsymbolTable *symtab; // members[] sorted into table | |
248 | |
249 Array *imports; // imported ScopeDsymbol's | |
250 unsigned char *prots; // PROT for each import | |
251 | |
252 ScopeDsymbol(); | |
253 ScopeDsymbol(Identifier *id); | |
254 Dsymbol *syntaxCopy(Dsymbol *s); | |
255 Dsymbol *search(Loc loc, Identifier *ident, int flags); | |
256 void importScope(ScopeDsymbol *s, enum PROT protection); | |
257 int isforwardRef(); | |
258 void defineRef(Dsymbol *s); | |
259 static void multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2); | |
260 Dsymbol *nameCollision(Dsymbol *s); | |
336 | 261 const char *kind(); |
159 | 262 |
263 void emitMemberComments(Scope *sc); | |
264 | |
265 ScopeDsymbol *isScopeDsymbol() { return this; } | |
266 }; | |
267 | |
268 // With statement scope | |
269 | |
270 struct WithScopeSymbol : ScopeDsymbol | |
271 { | |
272 WithStatement *withstate; | |
273 | |
274 WithScopeSymbol(WithStatement *withstate); | |
275 Dsymbol *search(Loc loc, Identifier *ident, int flags); | |
276 | |
277 WithScopeSymbol *isWithScopeSymbol() { return this; } | |
278 }; | |
279 | |
280 // Array Index/Slice scope | |
281 | |
282 struct ArrayScopeSymbol : ScopeDsymbol | |
283 { | |
284 Expression *exp; // IndexExp or SliceExp | |
285 TypeTuple *type; // for tuple[length] | |
286 TupleDeclaration *td; // for tuples of objects | |
287 | |
288 ArrayScopeSymbol(Expression *e); | |
289 ArrayScopeSymbol(TypeTuple *t); | |
290 ArrayScopeSymbol(TupleDeclaration *td); | |
291 Dsymbol *search(Loc loc, Identifier *ident, int flags); | |
292 | |
293 ArrayScopeSymbol *isArrayScopeSymbol() { return this; } | |
294 }; | |
295 | |
296 // Table of Dsymbol's | |
297 | |
298 struct DsymbolTable : Object | |
299 { | |
300 StringTable *tab; | |
301 | |
302 DsymbolTable(); | |
303 ~DsymbolTable(); | |
304 | |
305 // Look up Identifier. Return Dsymbol if found, NULL if not. | |
306 Dsymbol *lookup(Identifier *ident); | |
307 | |
308 // Insert Dsymbol in table. Return NULL if already there. | |
309 Dsymbol *insert(Dsymbol *s); | |
310 | |
311 // Look for Dsymbol in table. If there, return it. If not, insert s and return that. | |
312 Dsymbol *update(Dsymbol *s); | |
313 Dsymbol *insert(Identifier *ident, Dsymbol *s); // when ident and s are not the same | |
314 }; | |
315 | |
316 #endif /* DMD_DSYMBOL_H */ |