2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2008 by Digital Mars
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.
19 #include "stringtable.h"
22 #include "arraytypes.h"
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
;
58 struct TemplateDeclaration
;
59 struct TemplateInstance
;
63 struct WithScopeSymbol
;
64 struct ArrayScopeSymbol
;
65 struct SymbolDeclaration
;
67 struct DeleteDeclaration
;
72 typedef union tree_node TYPE
;
80 PROTnone
, // no access
89 struct Dsymbol
: Object
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
100 Dsymbol(Identifier
*);
102 char *toPrettyChars();
104 int equals(Object
*o
);
106 void error(Loc loc
, const char *format
, ...);
107 void error(const char *format
, ...);
108 void checkDeprecated(Loc loc
, Scope
*sc
);
110 Dsymbol
*pastMixin();
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
);
130 virtual void toHBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
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
);
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
; }
203 virtual DeleteDeclaration
*isDeleteDeclaration() { return NULL
; }
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
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
);
225 void defineRef(Dsymbol
*s
);
226 static void multiplyDefined(Loc loc
, Dsymbol
*s1
, Dsymbol
*s2
);
227 Dsymbol
*nameCollision(Dsymbol
*s
);
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
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 */