root/branches/dmdfe-2.0/dsymbol.h

Revision 905, 9.7 kB (checked in by Gregor, 3 months ago)

MERGE: DMD 2.016

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