Accept "in" instance variables
[delight/core.git] / dmd / dsymbol.h
blobed358b5b128dcd5018eca7fa701bdebdbba7d182
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.
11 #ifndef DMD_DSYMBOL_H
12 #define DMD_DSYMBOL_H
14 #ifdef __DMC__
15 #pragma once
16 #endif /* __DMC__ */
18 #include "root.h"
19 #include "stringtable.h"
21 #include "mars.h"
22 #include "arraytypes.h"
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;
70 #if IN_GCC
71 union tree_node;
72 typedef union tree_node TYPE;
73 #else
74 struct TYPE;
75 #endif
77 enum PROT
79 PROTundefined,
80 PROTnone, // no access
81 PROTprivate,
82 PROTpackage,
83 PROTprotected,
84 PROTpublic,
85 PROTexport,
89 struct Dsymbol : Object
91 Identifier *ident;
92 Identifier *c_ident;
93 Dsymbol *parent;
94 Symbol *csym; // symbol for code generator
95 Symbol *isym; // import version of csym
96 unsigned char *comment; // documentation comment for this Dsymbol
97 Loc loc; // where defined
99 Dsymbol();
100 Dsymbol(Identifier *);
101 char *toChars();
102 char *toPrettyChars();
103 char *locToChars();
104 int equals(Object *o);
105 int isAnonymous();
106 void error(Loc loc, const char *format, ...);
107 void error(const char *format, ...);
108 void checkDeprecated(Loc loc, Scope *sc);
109 Module *getModule();
110 Dsymbol *pastMixin();
111 Dsymbol *toParent();
112 Dsymbol *toParent2();
114 int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol()
116 static Array *arraySyntaxCopy(Array *a);
118 virtual char *kind();
119 virtual Dsymbol *toAlias(); // resolve real symbol
120 virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum);
121 virtual void semantic(Scope *sc);
122 virtual void semantic2(Scope *sc);
123 virtual void semantic3(Scope *sc);
124 virtual void inlineScan();
125 virtual Dsymbol *search(Loc loc, Identifier *ident, int flags);
126 Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id);
127 virtual int overloadInsert(Dsymbol *s);
128 #ifdef _DH
129 char *toHChars();
130 virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs);
131 #endif
132 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
133 virtual void toDocBuffer(OutBuffer *buf);
134 virtual target_size_t size(Loc loc);
135 virtual int isforwardRef();
136 virtual void defineRef(Dsymbol *s);
137 virtual AggregateDeclaration *isThis(); // is a 'this' required to access the member
138 virtual ClassDeclaration *isClassMember(); // are we a member of a class?
139 virtual int isExport(); // is Dsymbol exported?
140 virtual int isImportedSymbol(); // is Dsymbol imported?
141 virtual int isDeprecated(); // is Dsymbol deprecated?
142 virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol?
143 virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration?
144 virtual Type *getType(); // is this a type?
145 virtual char *mangle();
146 virtual int needThis(); // need a 'this' pointer?
147 virtual enum PROT prot();
148 virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
149 virtual int oneMember(Dsymbol **ps);
150 static int oneMembers(Array *members, Dsymbol **ps);
151 virtual int hasPointers();
152 virtual void addLocalClass(ClassDeclarations *) { }
153 virtual void checkCtorConstInit() { }
155 virtual void addComment(unsigned char *comment);
156 virtual void emitComment(Scope *sc);
157 void emitDitto(Scope *sc);
159 // Backend
161 virtual Symbol *toSymbol(); // to backend symbol
162 virtual void toObjFile(int multiobj); // compile to .obj file
163 virtual int cvMember(unsigned char *p); // emit cv debug info for member
165 Symbol *toImport(); // to backend import symbol
166 static Symbol *toImport(Symbol *s); // to backend import symbol
168 Symbol *toSymbolX(const char *prefix, int sclass, TYPE *t, const char *suffix); // helper
170 // Eliminate need for dynamic_cast
171 virtual Package *isPackage() { return NULL; }
172 virtual Module *isModule() { return NULL; }
173 virtual EnumMember *isEnumMember() { return NULL; }
174 virtual TemplateDeclaration *isTemplateDeclaration() { return NULL; }
175 virtual TemplateInstance *isTemplateInstance() { return NULL; }
176 virtual TemplateMixin *isTemplateMixin() { return NULL; }
177 virtual Declaration *isDeclaration() { return NULL; }
178 virtual TupleDeclaration *isTupleDeclaration() { return NULL; }
179 virtual TypedefDeclaration *isTypedefDeclaration() { return NULL; }
180 virtual AliasDeclaration *isAliasDeclaration() { return NULL; }
181 virtual AggregateDeclaration *isAggregateDeclaration() { return NULL; }
182 virtual FuncDeclaration *isFuncDeclaration() { return NULL; }
183 virtual FuncAliasDeclaration *isFuncAliasDeclaration() { return NULL; }
184 virtual FuncLiteralDeclaration *isFuncLiteralDeclaration() { return NULL; }
185 virtual CtorDeclaration *isCtorDeclaration() { return NULL; }
186 virtual DtorDeclaration *isDtorDeclaration() { return NULL; }
187 virtual StaticCtorDeclaration *isStaticCtorDeclaration() { return NULL; }
188 virtual StaticDtorDeclaration *isStaticDtorDeclaration() { return NULL; }
189 virtual InvariantDeclaration *isInvariantDeclaration() { return NULL; }
190 virtual UnitTestDeclaration *isUnitTestDeclaration() { return NULL; }
191 virtual NewDeclaration *isNewDeclaration() { return NULL; }
192 virtual VarDeclaration *isVarDeclaration() { return NULL; }
193 virtual ClassDeclaration *isClassDeclaration() { return NULL; }
194 virtual StructDeclaration *isStructDeclaration() { return NULL; }
195 virtual UnionDeclaration *isUnionDeclaration() { return NULL; }
196 virtual InterfaceDeclaration *isInterfaceDeclaration() { return NULL; }
197 virtual ScopeDsymbol *isScopeDsymbol() { return NULL; }
198 virtual WithScopeSymbol *isWithScopeSymbol() { return NULL; }
199 virtual ArrayScopeSymbol *isArrayScopeSymbol() { return NULL; }
200 virtual Import *isImport() { return NULL; }
201 virtual EnumDeclaration *isEnumDeclaration() { return NULL; }
202 #ifdef _DH
203 virtual DeleteDeclaration *isDeleteDeclaration() { return NULL; }
204 #endif
205 virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; }
206 virtual AttribDeclaration *isAttribDeclaration() { return NULL; }
209 // Dsymbol that generates a scope
211 struct ScopeDsymbol : Dsymbol
213 Array *members; // all Dsymbol's in this scope
214 DsymbolTable *symtab; // members[] sorted into table
216 Array *imports; // imported ScopeDsymbol's
217 unsigned char *prots; // PROT for each import
219 ScopeDsymbol();
220 ScopeDsymbol(Identifier *id);
221 Dsymbol *syntaxCopy(Dsymbol *s);
222 Dsymbol *search(Loc loc, Identifier *ident, int flags);
223 void importScope(ScopeDsymbol *s, enum PROT protection);
224 int isforwardRef();
225 void defineRef(Dsymbol *s);
226 static void multiplyDefined(Loc loc, Dsymbol *s1, Dsymbol *s2);
227 Dsymbol *nameCollision(Dsymbol *s);
228 char *kind();
230 void emitMemberComments(Scope *sc);
232 ScopeDsymbol *isScopeDsymbol() { return this; }
235 // With statement scope
237 struct WithScopeSymbol : ScopeDsymbol
239 WithStatement *withstate;
241 WithScopeSymbol(WithStatement *withstate);
242 Dsymbol *search(Loc loc, Identifier *ident, int flags);
244 WithScopeSymbol *isWithScopeSymbol() { return this; }
247 // Array Index/Slice scope
249 struct ArrayScopeSymbol : ScopeDsymbol
251 Expression *exp; // IndexExp or SliceExp
252 TypeTuple *type; // for tuple[length]
253 TupleDeclaration *td; // for tuples of objects
255 ArrayScopeSymbol(Expression *e);
256 ArrayScopeSymbol(TypeTuple *t);
257 ArrayScopeSymbol(TupleDeclaration *td);
258 Dsymbol *search(Loc loc, Identifier *ident, int flags);
260 ArrayScopeSymbol *isArrayScopeSymbol() { return this; }
263 // Table of Dsymbol's
265 struct DsymbolTable : Object
267 StringTable *tab;
269 DsymbolTable();
270 ~DsymbolTable();
272 // Look up Identifier. Return Dsymbol if found, NULL if not.
273 Dsymbol *lookup(Identifier *ident);
275 // Insert Dsymbol in table. Return NULL if already there.
276 Dsymbol *insert(Dsymbol *s);
278 // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
279 Dsymbol *update(Dsymbol *s);
280 Dsymbol *insert(Identifier *ident, Dsymbol *s); // when ident and s are not the same
283 #endif /* DMD_DSYMBOL_H */