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