comparison dmd2/dsymbol.h @ 758:f04dde6e882c

Added initial D2 support, D2 frontend and changes to codegen to make things compile.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 11 Nov 2008 01:38:48 +0100
parents
children 356e65836fb5
comparison
equal deleted inserted replaced
757:2c730d530c98 758:f04dde6e882c
1
2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2008 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 // llvm
25 #include "../ir/irsymbol.h"
26
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 PostBlitDeclaration;
45 struct DtorDeclaration;
46 struct StaticCtorDeclaration;
47 struct StaticDtorDeclaration;
48 struct InvariantDeclaration;
49 struct UnitTestDeclaration;
50 struct NewDeclaration;
51 struct VarDeclaration;
52 struct AttribDeclaration;
53 struct Symbol;
54 struct Package;
55 struct Module;
56 struct Import;
57 struct Type;
58 struct TypeTuple;
59 struct WithStatement;
60 struct LabelDsymbol;
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 OverloadSet;
73 struct TypeInfoDeclaration;
74 struct ClassInfoDeclaration;
75
76 #if IN_GCC
77 union tree_node;
78 typedef union tree_node TYPE;
79 #else
80 struct TYPE;
81 #endif
82
83 // llvm
84 #if IN_LLVM
85 namespace llvm
86 {
87 class Value;
88 }
89 #endif
90
91 enum PROT
92 {
93 PROTundefined,
94 PROTnone, // no access
95 PROTprivate,
96 PROTpackage,
97 PROTprotected,
98 PROTpublic,
99 PROTexport,
100 };
101
102
103 struct Dsymbol : Object
104 {
105 Identifier *ident;
106 Identifier *c_ident;
107 Dsymbol *parent;
108 Symbol *csym; // symbol for code generator
109 Symbol *isym; // import version of csym
110 unsigned char *comment; // documentation comment for this Dsymbol
111 Loc loc; // where defined
112
113 Dsymbol();
114 Dsymbol(Identifier *);
115 char *toChars();
116 char *toPrettyChars();
117 char *locToChars();
118 int equals(Object *o);
119 int isAnonymous();
120 void error(Loc loc, const char *format, ...);
121 void error(const char *format, ...);
122 void checkDeprecated(Loc loc, Scope *sc);
123 Module *getModule();
124 Dsymbol *pastMixin();
125 Dsymbol *toParent();
126 Dsymbol *toParent2();
127 TemplateInstance *inTemplateInstance();
128
129 int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol()
130
131 static Array *arraySyntaxCopy(Array *a);
132
133 virtual const char *kind();
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?
155 virtual int isImportedSymbol(); // is Dsymbol imported?
156 virtual int isDeprecated(); // is Dsymbol deprecated?
157 virtual int isOverloadable();
158 virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol?
159 virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration?
160 virtual Type *getType(); // is this a type?
161 virtual char *mangle();
162 virtual int needThis(); // need a 'this' pointer?
163 virtual enum PROT prot();
164 virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
165 virtual int oneMember(Dsymbol **ps);
166 static int oneMembers(Array *members, Dsymbol **ps);
167 virtual int hasPointers();
168 virtual void addLocalClass(ClassDeclarations *) { }
169 virtual void checkCtorConstInit() { }
170
171 virtual void addComment(unsigned char *comment);
172 virtual void emitComment(Scope *sc);
173 void emitDitto(Scope *sc);
174
175 // Backend
176
177 virtual Symbol *toSymbol(); // to backend symbol
178 virtual void toObjFile(int multiobj); // compile to .obj file
179 virtual int cvMember(unsigned char *p); // emit cv debug info for member
180
181 Symbol *toImport(); // to backend import symbol
182 static Symbol *toImport(Symbol *s); // to backend import symbol
183
184 Symbol *toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix); // helper
185
186 // Eliminate need for dynamic_cast
187 virtual Package *isPackage() { return NULL; }
188 virtual Module *isModule() { return NULL; }
189 virtual EnumMember *isEnumMember() { return NULL; }
190 virtual TemplateDeclaration *isTemplateDeclaration() { return NULL; }
191 virtual TemplateInstance *isTemplateInstance() { return NULL; }
192 virtual TemplateMixin *isTemplateMixin() { return NULL; }
193 virtual Declaration *isDeclaration() { return NULL; }
194 virtual TupleDeclaration *isTupleDeclaration() { return NULL; }
195 virtual TypedefDeclaration *isTypedefDeclaration() { return NULL; }
196 virtual AliasDeclaration *isAliasDeclaration() { return NULL; }
197 virtual AggregateDeclaration *isAggregateDeclaration() { return NULL; }
198 virtual FuncDeclaration *isFuncDeclaration() { return NULL; }
199 virtual FuncAliasDeclaration *isFuncAliasDeclaration() { return NULL; }
200 virtual FuncLiteralDeclaration *isFuncLiteralDeclaration() { return NULL; }
201 virtual CtorDeclaration *isCtorDeclaration() { return NULL; }
202 virtual PostBlitDeclaration *isPostBlitDeclaration() { return NULL; }
203 virtual DtorDeclaration *isDtorDeclaration() { return NULL; }
204 virtual StaticCtorDeclaration *isStaticCtorDeclaration() { return NULL; }
205 virtual StaticDtorDeclaration *isStaticDtorDeclaration() { return NULL; }
206 virtual InvariantDeclaration *isInvariantDeclaration() { return NULL; }
207 virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; }
208 virtual NewDeclaration *isNewDeclaration() { return NULL; }
209 virtual VarDeclaration *isVarDeclaration() { return NULL; }
210 virtual ClassDeclaration *isClassDeclaration() { return NULL; }
211 virtual StructDeclaration *isStructDeclaration() { return NULL; }
212 virtual UnionDeclaration *isUnionDeclaration() { return NULL; }
213 virtual InterfaceDeclaration *isInterfaceDeclaration() { return NULL; }
214 virtual ScopeDsymbol *isScopeDsymbol() { return NULL; }
215 virtual WithScopeSymbol *isWithScopeSymbol() { return NULL; }
216 virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; }
217 virtual Import *isImport() { return NULL; }
218 virtual EnumDeclaration *isEnumDeclaration() { return NULL; }
219 #ifdef _DH
220 virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; }
221 #endif
222 virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; }
223 virtual AttribDeclaration *isAttribDeclaration() { return NULL; }
224 virtual OverloadSet *isOverloadSet() { return NULL; }
225 virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; }
226 virtual ClassInfoDeclaration* isClassInfoDeclaration() { return NULL; }
227
228 // llvm stuff
229 int llvmInternal;
230
231 IrDsymbol ir;
232 };
233
234 // Dsymbol that generates a scope
235
236 struct ScopeDsymbol : Dsymbol
237 {
238 Array *members; // all Dsymbol's in this scope
239 DsymbolTable *symtab; // members[] sorted into table
240
241 Array *imports; // imported ScopeDsymbol's
242 unsigned char *prots; // PROT for each import
243
244 ScopeDsymbol();
245 ScopeDsymbol(Identifier *id);
246 Dsymbol *syntaxCopy(Dsymbol *s);
247 Dsymbol *search(Loc loc, Identifier *ident, int flags);
248 void importScope(ScopeDsymbol *s, enum PROT protection);
249 int isforwardRef();
250 void defineRef(Dsymbol *s);
251 static void multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2);
252 Dsymbol *nameCollision(Dsymbol *s);
253 const char *kind();
254 FuncDeclaration *findGetMembers();
255
256 void emitMemberComments(Scope *sc);
257
258 static size_t dim(Array *members);
259 static Dsymbol *getNth(Array *members, size_t nth, size_t *pn = NULL);
260
261 ScopeDsymbol *isScopeDsymbol() { return this; }
262 };
263
264 // With statement scope
265
266 struct WithScopeSymbol : ScopeDsymbol
267 {
268 WithStatement *withstate;
269
270 WithScopeSymbol(WithStatement *withstate);
271 Dsymbol *search(Loc loc, Identifier *ident, int flags);
272
273 WithScopeSymbol *isWithScopeSymbol() { return this; }
274 };
275
276 // Array Index/Slice scope
277
278 struct ArrayScopeSymbol : ScopeDsymbol
279 {
280 Expression *exp; // IndexExp or SliceExp
281 TypeTuple *type; // for tuple[length]
282 TupleDeclaration *td; // for tuples of objects
283 Scope *sc;
284
285 ArrayScopeSymbol(Scope *sc, Expression *e);
286 ArrayScopeSymbol(Scope *sc, TypeTuple *t);
287 ArrayScopeSymbol(Scope *sc, TupleDeclaration *td);
288 Dsymbol *search(Loc loc, Identifier *ident, int flags);
289
290 ArrayScopeSymbol *isArrayScopeSymbol() { return this; }
291 };
292
293 // Overload Sets
294
295 struct OverloadSet : Dsymbol
296 {
297 Dsymbols a; // array of Dsymbols
298
299 OverloadSet();
300 void push(Dsymbol *s);
301 OverloadSet *isOverloadSet() { return this; }
302 const char *kind();
303 };
304
305 // Table of Dsymbol's
306
307 struct DsymbolTable : Object
308 {
309 StringTable *tab;
310
311 DsymbolTable();
312 ~DsymbolTable();
313
314 // Look up Identifier. Return Dsymbol if found, NULL if not.
315 Dsymbol *lookup(Identifier *ident);
316
317 // Insert Dsymbol in table. Return NULL if already there.
318 Dsymbol *insert(Dsymbol *s);
319
320 // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
321 Dsymbol *update(Dsymbol *s);
322 Dsymbol *insert(Identifier *ident, Dsymbol *s); // when ident and s are not the same
323 };
324
325 #endif /* DMD_DSYMBOL_H */