comparison dmd/dsymbol.h @ 1:c53b6e3fe49a trunk

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