root/branches/dmdfe/dsymbol.h

Revision 458, 9.0 kB (checked in by Gregor, 2 years ago)

MERGE: DMD 1.011

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