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 PostBlitDeclaration
;
42 struct DtorDeclaration
;
43 struct StaticCtorDeclaration
;
44 struct StaticDtorDeclaration
;
45 struct InvariantDeclaration
;
46 struct UnitTestDeclaration
;
47 struct NewDeclaration
;
48 struct VarDeclaration
;
49 struct AttribDeclaration
;
59 struct TemplateDeclaration
;
60 struct TemplateInstance
;
64 struct WithScopeSymbol
;
65 struct ArrayScopeSymbol
;
66 struct SymbolDeclaration
;
68 struct DeleteDeclaration
;
74 typedef union tree_node TYPE
;
85 PROTnone
, // no access
94 struct Dsymbol
: Object
99 Symbol
*csym
; // symbol for code generator
100 Symbol
*isym
; // import version of csym
101 unsigned char *comment
; // documentation comment for this Dsymbol
102 Loc loc
; // where defined
105 Dsymbol(Identifier
*);
107 char *toPrettyChars();
109 int equals(Object
*o
);
111 void error(Loc loc
, const char *format
, ...);
112 void error(const char *format
, ...);
113 void checkDeprecated(Loc loc
, Scope
*sc
);
115 Dsymbol
*pastMixin();
117 Dsymbol
*toParent2();
119 int dyncast() { return DYNCAST_DSYMBOL
; } // kludge for template.isSymbol()
121 static Array
*arraySyntaxCopy(Array
*a
);
123 virtual char *kind();
124 virtual Dsymbol
*toAlias(); // resolve real symbol
125 virtual int addMember(Scope
*sc
, ScopeDsymbol
*s
, int memnum
);
126 virtual void semantic(Scope
*sc
);
127 virtual void semantic2(Scope
*sc
);
128 virtual void semantic3(Scope
*sc
);
129 virtual void inlineScan();
130 virtual Dsymbol
*search(Loc loc
, Identifier
*ident
, int flags
);
131 Dsymbol
*searchX(Loc loc
, Scope
*sc
, Identifier
*id
);
132 virtual int overloadInsert(Dsymbol
*s
);
135 virtual void toHBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
137 virtual void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
138 virtual void toDocBuffer(OutBuffer
*buf
);
139 virtual target_size_t
size(Loc loc
);
140 virtual int isforwardRef();
141 virtual void defineRef(Dsymbol
*s
);
142 virtual AggregateDeclaration
*isThis(); // is a 'this' required to access the member
143 virtual ClassDeclaration
*isClassMember(); // are we a member of a class?
144 virtual int isExport(); // is Dsymbol exported?
145 virtual int isImportedSymbol(); // is Dsymbol imported?
146 virtual int isDeprecated(); // is Dsymbol deprecated?
147 virtual int isOverloadable();
148 virtual LabelDsymbol
*isLabel(); // is this a LabelDsymbol?
149 virtual AggregateDeclaration
*isMember(); // is this symbol a member of an AggregateDeclaration?
150 virtual Type
*getType(); // is this a type?
151 virtual char *mangle();
152 virtual int needThis(); // need a 'this' pointer?
153 virtual enum PROT
prot();
154 virtual Dsymbol
*syntaxCopy(Dsymbol
*s
); // copy only syntax trees
155 virtual int oneMember(Dsymbol
**ps
);
156 static int oneMembers(Array
*members
, Dsymbol
**ps
);
157 virtual int hasPointers();
158 virtual void addLocalClass(ClassDeclarations
*) { }
159 virtual void checkCtorConstInit() { }
161 virtual void addComment(unsigned char *comment
);
162 virtual void emitComment(Scope
*sc
);
163 void emitDitto(Scope
*sc
);
167 virtual Symbol
*toSymbol(); // to backend symbol
168 virtual void toObjFile(int multiobj
); // compile to .obj file
169 virtual int cvMember(unsigned char *p
); // emit cv debug info for member
171 Symbol
*toImport(); // to backend import symbol
172 static Symbol
*toImport(Symbol
*s
); // to backend import symbol
174 Symbol
*toSymbolX(const char *prefix
, int sclass
, TYPE
*t
, const char *suffix
); // helper
176 // Eliminate need for dynamic_cast
177 virtual Package
*isPackage() { return NULL
; }
178 virtual Module
*isModule() { return NULL
; }
179 virtual EnumMember
*isEnumMember() { return NULL
; }
180 virtual TemplateDeclaration
*isTemplateDeclaration() { return NULL
; }
181 virtual TemplateInstance
*isTemplateInstance() { return NULL
; }
182 virtual TemplateMixin
*isTemplateMixin() { return NULL
; }
183 virtual Declaration
*isDeclaration() { return NULL
; }
184 virtual TupleDeclaration
*isTupleDeclaration() { return NULL
; }
185 virtual TypedefDeclaration
*isTypedefDeclaration() { return NULL
; }
186 virtual AliasDeclaration
*isAliasDeclaration() { return NULL
; }
187 virtual AggregateDeclaration
*isAggregateDeclaration() { return NULL
; }
188 virtual FuncDeclaration
*isFuncDeclaration() { return NULL
; }
189 virtual FuncAliasDeclaration
*isFuncAliasDeclaration() { return NULL
; }
190 virtual FuncLiteralDeclaration
*isFuncLiteralDeclaration() { return NULL
; }
191 virtual CtorDeclaration
*isCtorDeclaration() { return NULL
; }
192 virtual PostBlitDeclaration
*isPostBlitDeclaration() { return NULL
; }
193 virtual DtorDeclaration
*isDtorDeclaration() { return NULL
; }
194 virtual StaticCtorDeclaration
*isStaticCtorDeclaration() { return NULL
; }
195 virtual StaticDtorDeclaration
*isStaticDtorDeclaration() { return NULL
; }
196 virtual InvariantDeclaration
*isInvariantDeclaration() { return NULL
; }
197 virtual UnitTestDeclaration
*isUnitTestDeclaration() { return NULL
; }
198 virtual NewDeclaration
*isNewDeclaration() { return NULL
; }
199 virtual VarDeclaration
*isVarDeclaration() { return NULL
; }
200 virtual ClassDeclaration
*isClassDeclaration() { return NULL
; }
201 virtual StructDeclaration
*isStructDeclaration() { return NULL
; }
202 virtual UnionDeclaration
*isUnionDeclaration() { return NULL
; }
203 virtual InterfaceDeclaration
*isInterfaceDeclaration() { return NULL
; }
204 virtual ScopeDsymbol
*isScopeDsymbol() { return NULL
; }
205 virtual WithScopeSymbol
*isWithScopeSymbol() { return NULL
; }
206 virtual ArrayScopeSymbol
*isArrayScopeSymbol() { return NULL
; }
207 virtual Import
*isImport() { return NULL
; }
208 virtual EnumDeclaration
*isEnumDeclaration() { return NULL
; }
210 virtual DeleteDeclaration
*isDeleteDeclaration() { return NULL
; }
212 virtual SymbolDeclaration
*isSymbolDeclaration() { return NULL
; }
213 virtual AttribDeclaration
*isAttribDeclaration() { return NULL
; }
214 virtual OverloadSet
*isOverloadSet() { return NULL
; }
217 // Dsymbol that generates a scope
219 struct ScopeDsymbol
: Dsymbol
221 Array
*members
; // all Dsymbol's in this scope
222 DsymbolTable
*symtab
; // members[] sorted into table
224 Array
*imports
; // imported ScopeDsymbol's
225 unsigned char *prots
; // PROT for each import
228 ScopeDsymbol(Identifier
*id
);
229 Dsymbol
*syntaxCopy(Dsymbol
*s
);
230 Dsymbol
*search(Loc loc
, Identifier
*ident
, int flags
);
231 void importScope(ScopeDsymbol
*s
, enum PROT protection
);
233 void defineRef(Dsymbol
*s
);
234 static void multiplyDefined(Loc loc
, Dsymbol
*s1
, Dsymbol
*s2
);
235 Dsymbol
*nameCollision(Dsymbol
*s
);
237 FuncDeclaration
*findGetMembers();
239 void emitMemberComments(Scope
*sc
);
241 static size_t dim(Array
*members
);
242 static Dsymbol
*getNth(Array
*members
, size_t nth
, size_t *pn
= NULL
);
244 ScopeDsymbol
*isScopeDsymbol() { return this; }
247 // With statement scope
249 struct WithScopeSymbol
: ScopeDsymbol
251 WithStatement
*withstate
;
253 WithScopeSymbol(WithStatement
*withstate
);
254 Dsymbol
*search(Loc loc
, Identifier
*ident
, int flags
);
256 WithScopeSymbol
*isWithScopeSymbol() { return this; }
259 // Array Index/Slice scope
261 struct ArrayScopeSymbol
: ScopeDsymbol
263 Expression
*exp
; // IndexExp or SliceExp
264 TypeTuple
*type
; // for tuple[length]
265 TupleDeclaration
*td
; // for tuples of objects
268 ArrayScopeSymbol(Scope
*sc
, Expression
*e
);
269 ArrayScopeSymbol(Scope
*sc
, TypeTuple
*t
);
270 ArrayScopeSymbol(Scope
*sc
, TupleDeclaration
*td
);
271 Dsymbol
*search(Loc loc
, Identifier
*ident
, int flags
);
273 ArrayScopeSymbol
*isArrayScopeSymbol() { return this; }
278 struct OverloadSet
: Dsymbol
280 Dsymbols a
; // array of Dsymbols
283 void push(Dsymbol
*s
);
284 OverloadSet
*isOverloadSet() { return this; }
288 // Table of Dsymbol's
290 struct DsymbolTable
: Object
297 // Look up Identifier. Return Dsymbol if found, NULL if not.
298 Dsymbol
*lookup(Identifier
*ident
);
300 // Insert Dsymbol in table. Return NULL if already there.
301 Dsymbol
*insert(Dsymbol
*s
);
303 // Look for Dsymbol in table. If there, return it. If not, insert s and return that.
304 Dsymbol
*update(Dsymbol
*s
);
305 Dsymbol
*insert(Identifier
*ident
, Dsymbol
*s
); // when ident and s are not the same
308 #endif /* DMD_DSYMBOL_H */