root/trunk/src/dsymbol.h

Revision 583, 11.4 kB (checked in by walter, 2 years ago)

workaround for another fwd reference anonymous enum bug

  • Property svn:eol-style set to native
Line 
1 // Compiler implementation of the D programming language
2 // Copyright (c) 1999-2010 by Digital Mars
3 // All Rights Reserved
4 // written by Walter Bright
5 // http://www.digitalmars.com
6 // License for redistribution is by either the Artistic License
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
8 // See the included readme.txt for details.
9
10 #ifndef DMD_DSYMBOL_H
11 #define DMD_DSYMBOL_H
12
13 #ifdef __DMC__
14 #pragma once
15 #endif /* __DMC__ */
16
17 #include "root.h"
18 #include "stringtable.h"
19
20 #include "mars.h"
21 #include "arraytypes.h"
22
23 struct Identifier;
24 struct Scope;
25 struct DsymbolTable;
26 struct Declaration;
27 struct ThisDeclaration;
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 PostBlitDeclaration;
42 struct DtorDeclaration;
43 struct StaticCtorDeclaration;
44 struct StaticDtorDeclaration;
45 struct SharedStaticCtorDeclaration;
46 struct SharedStaticDtorDeclaration;
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 OverloadSet;
73 struct AA;
74 #if TARGET_NET
75 struct PragmaScope;
76 #endif
77 #if IN_GCC
78 union tree_node;
79 typedef union tree_node TYPE;
80 #else
81 struct TYPE;
82 #endif
83
84 // Back end
85 struct Classsym;
86
87 enum PROT
88 {
89     PROTundefined,
90     PROTnone,           // no access
91     PROTprivate,
92     PROTpackage,
93     PROTprotected,
94     PROTpublic,
95     PROTexport,
96 };
97
98 /* State of symbol in winding its way through the passes of the compiler
99  */
100 enum PASS
101 {
102     PASSinit,           // initial state
103     PASSsemantic,       // semantic() started
104     PASSsemanticdone,   // semantic() done
105     PASSsemantic2,      // semantic2() run
106     PASSsemantic3,      // semantic3() started
107     PASSsemantic3done,  // semantic3() done
108     PASSobj,            // toObjFile() run
109 };
110
111 struct Dsymbol : Object
112 {
113     Identifier *ident;
114     Identifier *c_ident;
115     Dsymbol *parent;
116     Symbol *csym;               // symbol for code generator
117     Symbol *isym;               // import version of csym
118     unsigned char *comment;     // documentation comment for this Dsymbol
119     Loc loc;                    // where defined
120     Scope *scope;               // !=NULL means context to use for semantic()
121
122     Dsymbol();
123     Dsymbol(Identifier *);
124     char *toChars();
125     char *locToChars();
126     int equals(Object *o);
127     int isAnonymous();
128     void error(Loc loc, const char *format, ...);
129     void error(const char *format, ...);
130     void checkDeprecated(Loc loc, Scope *sc);
131     Module *getModule();
132     Dsymbol *pastMixin();
133     Dsymbol *toParent();
134     Dsymbol *toParent2();
135     TemplateInstance *inTemplateInstance();
136
137     int dyncast() { return DYNCAST_DSYMBOL; }   // kludge for template.isSymbol()
138
139     static Dsymbols *arraySyntaxCopy(Dsymbols *a);
140
141     virtual const char *toPrettyChars();
142     virtual const char *kind();
143     virtual Dsymbol *toAlias();                 // resolve real symbol
144     virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum);
145     virtual void setScope(Scope *sc);
146     virtual void importAll(Scope *sc);
147     virtual void semantic0(Scope *sc);
148     virtual void semantic(Scope *sc);
149     virtual void semantic2(Scope *sc);
150     virtual void semantic3(Scope *sc);
151     virtual void inlineScan();
152     virtual Dsymbol *search(Loc loc, Identifier *ident, int flags);
153     Dsymbol *search_correct(Identifier *id);
154     Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id);
155     virtual int overloadInsert(Dsymbol *s);
156 #ifdef _DH
157     char *toHChars();
158     virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs);
159 #endif
160     virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
161     virtual void toDocBuffer(OutBuffer *buf);
162     virtual void toJsonBuffer(OutBuffer *buf);
163     virtual unsigned size(Loc loc);
164     virtual int isforwardRef();
165     virtual void defineRef(Dsymbol *s);
166     virtual AggregateDeclaration *isThis();     // is a 'this' required to access the member
167     virtual ClassDeclaration *isClassMember();  // are we a member of a class?
168     virtual int isExport();                     // is Dsymbol exported?
169     virtual int isImportedSymbol();             // is Dsymbol imported?
170     virtual int isDeprecated();                 // is Dsymbol deprecated?
171 #if DMDV2
172     virtual int isOverloadable();
173 #endif
174     virtual LabelDsymbol *isLabel();            // is this a LabelDsymbol?
175     virtual AggregateDeclaration *isMember();   // is this symbol a member of an AggregateDeclaration?
176     virtual Type *getType();                    // is this a type?
177     virtual char *mangle();
178     virtual int needThis();                     // need a 'this' pointer?
179     virtual enum PROT prot();
180     virtual Dsymbol *syntaxCopy(Dsymbol *s);    // copy only syntax trees
181     virtual int oneMember(Dsymbol **ps);
182     static int oneMembers(Array *members, Dsymbol **ps);
183     virtual int hasPointers();
184     virtual void addLocalClass(ClassDeclarations *) { }
185     virtual void checkCtorConstInit() { }
186
187     virtual void addComment(unsigned char *comment);
188     virtual void emitComment(Scope *sc);
189     void emitDitto(Scope *sc);
190
191     // Backend
192
193     virtual Symbol *toSymbol();                 // to backend symbol
194     virtual void toObjFile(int multiobj);                       // compile to .obj file
195     virtual int cvMember(unsigned char *p);     // emit cv debug info for member
196
197     Symbol *toImport();                         // to backend import symbol
198     static Symbol *toImport(Symbol *s);         // to backend import symbol
199
200     Symbol *toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix);     // helper
201
202     // Eliminate need for dynamic_cast
203     virtual Package *isPackage() { return NULL; }
204     virtual Module *isModule() { return NULL; }
205     virtual EnumMember *isEnumMember() { return NULL; }
206     virtual TemplateDeclaration *isTemplateDeclaration() { return NULL; }
207     virtual TemplateInstance *isTemplateInstance() { return NULL; }
208     virtual TemplateMixin *isTemplateMixin() { return NULL; }
209     virtual Declaration *isDeclaration() { return NULL; }
210     virtual ThisDeclaration *isThisDeclaration() { return NULL; }
211     virtual TupleDeclaration *isTupleDeclaration() { return NULL; }
212     virtual TypedefDeclaration *isTypedefDeclaration() { return NULL; }
213     virtual AliasDeclaration *isAliasDeclaration() { return NULL; }
214     virtual AggregateDeclaration *isAggregateDeclaration() { return NULL; }
215     virtual FuncDeclaration *isFuncDeclaration() { return NULL; }
216     virtual FuncAliasDeclaration *isFuncAliasDeclaration() { return NULL; }
217     virtual FuncLiteralDeclaration *isFuncLiteralDeclaration() { return NULL; }
218     virtual CtorDeclaration *isCtorDeclaration() { return NULL; }
219     virtual PostBlitDeclaration *isPostBlitDeclaration() { return NULL; }
220     virtual DtorDeclaration *isDtorDeclaration() { return NULL; }
221     virtual StaticCtorDeclaration *isStaticCtorDeclaration() { return NULL; }
222     virtual StaticDtorDeclaration *isStaticDtorDeclaration() { return NULL; }
223     virtual SharedStaticCtorDeclaration *isSharedStaticCtorDeclaration() { return NULL; }
224     virtual SharedStaticDtorDeclaration *isSharedStaticDtorDeclaration() { return NULL; }
225     virtual InvariantDeclaration *isInvariantDeclaration() { return NULL; }
226     virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; }
227     virtual NewDeclaration *isNewDeclaration() { return NULL; }
228     virtual VarDeclaration *isVarDeclaration() { return NULL; }
229     virtual ClassDeclaration *isClassDeclaration() { return NULL; }
230     virtual StructDeclaration *isStructDeclaration() { return NULL; }
231     virtual UnionDeclaration *isUnionDeclaration() { return NULL; }
232     virtual InterfaceDeclaration *isInterfaceDeclaration() { return NULL; }
233     virtual ScopeDsymbol *isScopeDsymbol() { return NULL; }
234     virtual WithScopeSymbol *isWithScopeSymbol() { return NULL; }
235     virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; }
236     virtual Import *isImport() { return NULL; }
237     virtual EnumDeclaration *isEnumDeclaration() { return NULL; }
238 #ifdef _DH
239     virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; }
240 #endif
241     virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; }
242     virtual AttribDeclaration *isAttribDeclaration() { return NULL; }
243     virtual OverloadSet *isOverloadSet() { return NULL; }
244 #if TARGET_NET
245     virtual PragmaScope* isPragmaScope() { return NULL; }
246 #endif
247 };
248
249 // Dsymbol that generates a scope
250
251 struct ScopeDsymbol : Dsymbol
252 {
253     Dsymbols *members;          // all Dsymbol's in this scope
254     DsymbolTable *symtab;       // members[] sorted into table
255
256     Array *imports;             // imported ScopeDsymbol's
257     unsigned char *prots;       // array of PROT, one for each import
258
259     ScopeDsymbol();
260     ScopeDsymbol(Identifier *id);
261     Dsymbol *syntaxCopy(Dsymbol *s);
262     Dsymbol *search(Loc loc, Identifier *ident, int flags);
263     void importScope(ScopeDsymbol *s, enum PROT protection);
264     int isforwardRef();
265     void defineRef(Dsymbol *s);
266     static void multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2);
267     Dsymbol *nameCollision(Dsymbol *s);
268     const char *kind();
269     FuncDeclaration *findGetMembers();
270     virtual Dsymbol *symtabInsert(Dsymbol *s);
271
272     void emitMemberComments(Scope *sc);
273
274     static size_t dim(Array *members);
275     static Dsymbol *getNth(Array *members, size_t nth, size_t *pn = NULL);
276
277     ScopeDsymbol *isScopeDsymbol() { return this; }
278 };
279
280 // With statement scope
281
282 struct WithScopeSymbol : ScopeDsymbol
283 {
284     WithStatement *withstate;
285
286     WithScopeSymbol(WithStatement *withstate);
287     Dsymbol *search(Loc loc, Identifier *ident, int flags);
288
289     WithScopeSymbol *isWithScopeSymbol() { return this; }
290 };
291
292 // Array Index/Slice scope
293
294 struct ArrayScopeSymbol : ScopeDsymbol
295 {
296     Expression *exp;    // IndexExp or SliceExp
297     TypeTuple *type;    // for tuple[length]
298     TupleDeclaration *td;       // for tuples of objects
299     Scope *sc;
300
301     ArrayScopeSymbol(Scope *sc, Expression *e);
302     ArrayScopeSymbol(Scope *sc, TypeTuple *t);
303     ArrayScopeSymbol(Scope *sc, TupleDeclaration *td);
304     Dsymbol *search(Loc loc, Identifier *ident, int flags);
305
306     ArrayScopeSymbol *isArrayScopeSymbol() { return this; }
307 };
308
309 // Overload Sets
310
311 #if DMDV2
312 struct OverloadSet : Dsymbol
313 {
314     Dsymbols a;         // array of Dsymbols
315
316     OverloadSet();
317     void push(Dsymbol *s);
318     OverloadSet *isOverloadSet() { return this; }
319     const char *kind();
320 };
321 #endif
322
323 // Table of Dsymbol's
324
325 struct DsymbolTable : Object
326 {
327 #if STRINGTABLE
328     StringTable *tab;
329 #else
330     AA *tab;
331 #endif
332
333     DsymbolTable();
334     ~DsymbolTable();
335
336     // Look up Identifier. Return Dsymbol if found, NULL if not.
337     Dsymbol *lookup(Identifier *ident);
338
339     // Insert Dsymbol in table. Return NULL if already there.
340     Dsymbol *insert(Dsymbol *s);
341
342     // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
343     Dsymbol *update(Dsymbol *s);
344     Dsymbol *insert(Identifier *ident, Dsymbol *s);     // when ident and s are not the same
345 };
346
347 #endif /* DMD_DSYMBOL_H */
Note: See TracBrowser for help on using the browser.