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