Mercurial > projects > ldc
annotate dmd/dsymbol.h @ 973:d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
error message.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Tue, 17 Feb 2009 18:25:34 +0100 |
parents | 1714836f2c0b |
children | 1860414bf3b7 |
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 |
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; | |
913
29c0d1194033
Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents:
443
diff
changeset
|
68 struct StaticStructInitDeclaration; |
159 | 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); | |
946
1714836f2c0b
Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents:
913
diff
changeset
|
122 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
|
123 Module *getCompilationModule(); // possibly different for templates |
159 | 124 Dsymbol *pastMixin(); |
125 Dsymbol *toParent(); | |
126 Dsymbol *toParent2(); | |
336 | 127 TemplateInstance *inTemplateInstance(); |
159 | 128 |
129 int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol() | |
130 | |
131 static Array *arraySyntaxCopy(Array *a); | |
132 | |
336 | 133 virtual const char *kind(); |
159 | 134 virtual Dsymbol *toAlias(); // resolve real symbol |
135 virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); | |
136 virtual void semantic(Scope *sc); | |
137 virtual void semantic2(Scope *sc); | |
138 virtual void semantic3(Scope *sc); | |
139 virtual void inlineScan(); | |
140 virtual Dsymbol *search(Loc loc, Identifier *ident, int flags); | |
141 Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id); | |
142 virtual int overloadInsert(Dsymbol *s); | |
143 #ifdef _DH | |
144 char *toHChars(); | |
145 virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs); | |
146 #endif | |
147 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
148 virtual void toDocBuffer(OutBuffer *buf); | |
149 virtual unsigned size(Loc loc); | |
150 virtual int isforwardRef(); | |
151 virtual void defineRef(Dsymbol *s); | |
152 virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member | |
153 virtual ClassDeclaration *isClassMember(); // are we a member of a class? | |
154 virtual int isExport(); // is Dsymbol exported? | |
336 | 155 virtual int isImportedSymbol(); // is Dsymbol imported? |
159 | 156 virtual int isDeprecated(); // is Dsymbol deprecated? |
157 virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol? | |
158 virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration? | |
159 virtual Type *getType(); // is this a type? | |
160 virtual char *mangle(); | |
161 virtual int needThis(); // need a 'this' pointer? | |
162 virtual enum PROT prot(); | |
163 virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees | |
164 virtual int oneMember(Dsymbol **ps); | |
165 static int oneMembers(Array *members, Dsymbol **ps); | |
166 virtual int hasPointers(); | |
167 virtual void addLocalClass(ClassDeclarations *) { } | |
168 virtual void checkCtorConstInit() { } | |
169 | |
170 virtual void addComment(unsigned char *comment); | |
171 virtual void emitComment(Scope *sc); | |
172 void emitDitto(Scope *sc); | |
173 | |
174 // Backend | |
175 | |
176 virtual Symbol *toSymbol(); // to backend symbol | |
336 | 177 virtual void toObjFile(int multiobj); // compile to .obj file |
159 | 178 virtual int cvMember(unsigned char *p); // emit cv debug info for member |
179 | |
180 Symbol *toImport(); // to backend import symbol | |
181 static Symbol *toImport(Symbol *s); // to backend import symbol | |
182 | |
183 Symbol *toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix); // helper | |
184 | |
185 // Eliminate need for dynamic_cast | |
186 virtual Package *isPackage() { return NULL; } | |
187 virtual Module *isModule() { return NULL; } | |
188 virtual EnumMember *isEnumMember() { return NULL; } | |
189 virtual TemplateDeclaration *isTemplateDeclaration() { return NULL; } | |
190 virtual TemplateInstance *isTemplateInstance() { return NULL; } | |
191 virtual TemplateMixin *isTemplateMixin() { return NULL; } | |
192 virtual Declaration *isDeclaration() { return NULL; } | |
193 virtual TupleDeclaration *isTupleDeclaration() { return NULL; } | |
194 virtual TypedefDeclaration *isTypedefDeclaration() { return NULL; } | |
195 virtual AliasDeclaration *isAliasDeclaration() { return NULL; } | |
196 virtual AggregateDeclaration *isAggregateDeclaration() { return NULL; } | |
197 virtual FuncDeclaration *isFuncDeclaration() { return NULL; } | |
198 virtual FuncAliasDeclaration *isFuncAliasDeclaration() { return NULL; } | |
199 virtual FuncLiteralDeclaration *isFuncLiteralDeclaration() { return NULL; } | |
200 virtual CtorDeclaration *isCtorDeclaration() { return NULL; } | |
201 virtual DtorDeclaration *isDtorDeclaration() { return NULL; } | |
202 virtual StaticCtorDeclaration *isStaticCtorDeclaration() { return NULL; } | |
203 virtual StaticDtorDeclaration *isStaticDtorDeclaration() { return NULL; } | |
204 virtual InvariantDeclaration *isInvariantDeclaration() { return NULL; } | |
205 virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; } | |
206 virtual NewDeclaration *isNewDeclaration() { return NULL; } | |
207 virtual VarDeclaration *isVarDeclaration() { return NULL; } | |
208 virtual ClassDeclaration *isClassDeclaration() { return NULL; } | |
209 virtual StructDeclaration *isStructDeclaration() { return NULL; } | |
210 virtual UnionDeclaration *isUnionDeclaration() { return NULL; } | |
211 virtual InterfaceDeclaration *isInterfaceDeclaration() { return NULL; } | |
212 virtual ScopeDsymbol *isScopeDsymbol() { return NULL; } | |
213 virtual WithScopeSymbol *isWithScopeSymbol() { return NULL; } | |
214 virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; } | |
215 virtual Import *isImport() { return NULL; } | |
216 virtual EnumDeclaration *isEnumDeclaration() { return NULL; } | |
217 #ifdef _DH | |
218 virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; } | |
219 #endif | |
913
29c0d1194033
Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents:
443
diff
changeset
|
220 virtual StaticStructInitDeclaration *isStaticStructInitDeclaration() { return NULL; } |
159 | 221 virtual AttribDeclaration *isAttribDeclaration() { return NULL; } |
222 virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; } | |
223 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
|
224 |
159 | 225 // llvm stuff |
226 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
|
227 |
173
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); | |
336 | 250 const char *kind(); |
159 | 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 */ |