159
|
1
|
|
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.
|
|
10
|
|
11 #ifndef DMD_AGGREGATE_H
|
|
12 #define DMD_AGGREGATE_H
|
|
13
|
|
14 #ifdef __DMC__
|
|
15 #pragma once
|
|
16 #endif /* __DMC__ */
|
|
17
|
|
18 #include "root.h"
|
|
19 #include "dsymbol.h"
|
|
20
|
|
21 #include <vector>
|
|
22 #include <set>
|
|
23 #include <map>
|
|
24
|
|
25 struct Identifier;
|
|
26 struct Type;
|
|
27 struct TypeFunction;
|
|
28 struct Expression;
|
|
29 struct FuncDeclaration;
|
|
30 struct CtorDeclaration;
|
|
31 struct DtorDeclaration;
|
|
32 struct InvariantDeclaration;
|
|
33 struct NewDeclaration;
|
|
34 struct DeleteDeclaration;
|
|
35 struct InterfaceDeclaration;
|
|
36 struct ClassInfoDeclaration;
|
|
37 struct VarDeclaration;
|
|
38 struct dt_t;
|
|
39
|
|
40 namespace llvm
|
|
41 {
|
|
42 class Type;
|
|
43 class Value;
|
|
44 class Constant;
|
|
45 class ConstantStruct;
|
|
46 class GlobalVariable;
|
|
47 }
|
|
48
|
|
49 struct AggregateDeclaration : ScopeDsymbol
|
|
50 {
|
|
51 Type *type;
|
|
52 unsigned storage_class;
|
|
53 enum PROT protection;
|
|
54 Type *handle; // 'this' type
|
|
55 unsigned structsize; // size of struct
|
|
56 unsigned alignsize; // size of struct for alignment purposes
|
|
57 unsigned structalign; // struct member alignment in effect
|
|
58 int hasUnions; // set if aggregate has overlapping fields
|
|
59 Array fields; // VarDeclaration fields
|
|
60 unsigned sizeok; // set when structsize contains valid data
|
|
61 // 0: no size
|
|
62 // 1: size is correct
|
|
63 // 2: cannot determine size; fwd referenced
|
|
64 int isdeprecated; // !=0 if deprecated
|
|
65 Scope *scope; // !=NULL means context to use
|
|
66
|
|
67 // Special member functions
|
|
68 InvariantDeclaration *inv; // invariant
|
|
69 NewDeclaration *aggNew; // allocator
|
|
70 DeleteDeclaration *aggDelete; // deallocator
|
|
71
|
336
|
72 FuncDeclarations dtors; // Array of destructors
|
|
73 FuncDeclaration *dtor; // aggregate destructor
|
|
74
|
159
|
75 #ifdef IN_GCC
|
|
76 Array methods; // flat list of all methods for debug information
|
|
77 #endif
|
|
78
|
|
79 AggregateDeclaration(Loc loc, Identifier *id);
|
|
80 void semantic2(Scope *sc);
|
|
81 void semantic3(Scope *sc);
|
|
82 void inlineScan();
|
|
83 unsigned size(Loc loc);
|
|
84 static void alignmember(unsigned salign, unsigned size, unsigned *poffset);
|
|
85 Type *getType();
|
|
86 void addField(Scope *sc, VarDeclaration *v);
|
|
87 int isDeprecated(); // is aggregate deprecated?
|
|
88 FuncDeclaration *buildDtor(Scope *sc);
|
|
89
|
|
90 void emitComment(Scope *sc);
|
|
91 void toDocBuffer(OutBuffer *buf);
|
|
92
|
|
93 // For access checking
|
|
94 virtual PROT getAccess(Dsymbol *smember); // determine access to smember
|
|
95 int isFriendOf(AggregateDeclaration *cd);
|
|
96 int hasPrivateAccess(Dsymbol *smember); // does smember have private access to members of this class?
|
|
97 void accessCheck(Loc loc, Scope *sc, Dsymbol *smember);
|
|
98
|
|
99 enum PROT prot();
|
|
100
|
|
101 // Back end
|
|
102 Symbol *stag; // tag symbol for debug data
|
|
103 Symbol *sinit;
|
|
104 Symbol *toInitializer();
|
|
105
|
|
106 AggregateDeclaration *isAggregateDeclaration() { return this; }
|
|
107 };
|
|
108
|
|
109 struct AnonymousAggregateDeclaration : AggregateDeclaration
|
|
110 {
|
|
111 AnonymousAggregateDeclaration()
|
|
112 : AggregateDeclaration(0, NULL)
|
|
113 {
|
|
114 }
|
|
115
|
|
116 AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; }
|
|
117 };
|
|
118
|
|
119 struct StructDeclaration : AggregateDeclaration
|
|
120 {
|
|
121 int zeroInit; // !=0 if initialize with 0 fill
|
336
|
122 #if DMDV2
|
|
123 int hasIdentityAssign; // !=0 if has identity opAssign
|
|
124 FuncDeclaration *cpctor; // generated copy-constructor, if any
|
|
125
|
|
126 FuncDeclarations postblits; // Array of postblit functions
|
|
127 FuncDeclaration *postblit; // aggregate postblit
|
|
128 #endif
|
159
|
129
|
|
130 StructDeclaration(Loc loc, Identifier *id);
|
|
131 Dsymbol *syntaxCopy(Dsymbol *s);
|
|
132 void semantic(Scope *sc);
|
|
133 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
134 char *mangle();
|
336
|
135 const char *kind();
|
159
|
136 Expression *cloneMembers();
|
|
137 void toDocBuffer(OutBuffer *buf);
|
|
138
|
|
139 PROT getAccess(Dsymbol *smember); // determine access to smember
|
|
140
|
336
|
141 void toObjFile(int multiobj); // compile to .obj file
|
159
|
142 void toDt(dt_t **pdt);
|
|
143 void toDebug(); // to symbolic debug info
|
|
144
|
|
145 StructDeclaration *isStructDeclaration() { return this; }
|
|
146 };
|
|
147
|
|
148 struct UnionDeclaration : StructDeclaration
|
|
149 {
|
|
150 UnionDeclaration(Loc loc, Identifier *id);
|
|
151 Dsymbol *syntaxCopy(Dsymbol *s);
|
336
|
152 const char *kind();
|
159
|
153
|
|
154 UnionDeclaration *isUnionDeclaration() { return this; }
|
|
155 };
|
|
156
|
|
157 struct BaseClass
|
|
158 {
|
|
159 Type *type; // (before semantic processing)
|
|
160 enum PROT protection; // protection for the base interface
|
|
161
|
|
162 ClassDeclaration *base;
|
|
163 int offset; // 'this' pointer offset
|
|
164 Array vtbl; // for interfaces: Array of FuncDeclaration's
|
|
165 // making up the vtbl[]
|
|
166
|
|
167 int baseInterfaces_dim;
|
|
168 BaseClass *baseInterfaces; // if BaseClass is an interface, these
|
|
169 // are a copy of the InterfaceDeclaration::interfaces
|
|
170
|
|
171 BaseClass();
|
|
172 BaseClass(Type *type, enum PROT protection);
|
|
173
|
|
174 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance);
|
|
175 void copyBaseInterfaces(BaseClasses *);
|
|
176 };
|
|
177
|
336
|
178 #if DMDV2
|
159
|
179 #define CLASSINFO_SIZE (0x3C+16) // value of ClassInfo.size
|
|
180 #else
|
|
181 #define CLASSINFO_SIZE (0x3C+12) // value of ClassInfo.size
|
|
182 #endif
|
|
183
|
|
184 struct ClassDeclaration : AggregateDeclaration
|
|
185 {
|
|
186 static ClassDeclaration *object;
|
|
187 static ClassDeclaration *classinfo;
|
|
188
|
|
189 ClassDeclaration *baseClass; // NULL only if this is Object
|
|
190 CtorDeclaration *ctor;
|
|
191 CtorDeclaration *defaultCtor; // default constructor
|
|
192 FuncDeclaration *staticCtor;
|
|
193 FuncDeclaration *staticDtor;
|
|
194 Array vtbl; // Array of FuncDeclaration's making up the vtbl[]
|
|
195 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[]
|
|
196
|
|
197 BaseClasses baseclasses; // Array of BaseClass's; first is super,
|
|
198 // rest are Interface's
|
|
199
|
|
200 int interfaces_dim;
|
|
201 BaseClass **interfaces; // interfaces[interfaces_dim] for this class
|
|
202 // (does not include baseClass)
|
|
203
|
|
204 BaseClasses *vtblInterfaces; // array of base interfaces that have
|
|
205 // their own vtbl[]
|
|
206
|
|
207 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration
|
|
208 int com; // !=0 if this is a COM class (meaning
|
|
209 // it derives from IUnknown)
|
|
210 int isauto; // !=0 if this is an auto class
|
|
211 int isabstract; // !=0 if abstract class
|
|
212
|
|
213 int isnested; // !=0 if is nested
|
|
214 VarDeclaration *vthis; // 'this' parameter if this class is nested
|
|
215
|
|
216 int inuse; // to prevent recursive attempts
|
|
217
|
|
218 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
|
|
219 Dsymbol *syntaxCopy(Dsymbol *s);
|
|
220 void semantic(Scope *sc);
|
|
221 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
222 int isBaseOf2(ClassDeclaration *cd);
|
|
223
|
|
224 #define OFFSET_RUNTIME 0x76543210
|
|
225 virtual int isBaseOf(ClassDeclaration *cd, int *poffset);
|
|
226
|
|
227 Dsymbol *search(Loc, Identifier *ident, int flags);
|
336
|
228 #if DMDV2
|
159
|
229 int isFuncHidden(FuncDeclaration *fd);
|
|
230 #endif
|
|
231 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf);
|
|
232 void interfaceSemantic(Scope *sc);
|
|
233 int isNested();
|
|
234 int isCOMclass();
|
|
235 virtual int isCOMinterface();
|
336
|
236 #if DMDV2
|
159
|
237 virtual int isCPPinterface();
|
|
238 #endif
|
|
239 int isAbstract();
|
|
240 virtual int vtblOffset();
|
336
|
241 const char *kind();
|
159
|
242 char *mangle();
|
|
243 void toDocBuffer(OutBuffer *buf);
|
|
244
|
|
245 PROT getAccess(Dsymbol *smember); // determine access to smember
|
|
246
|
|
247 void addLocalClass(ClassDeclarations *);
|
|
248
|
|
249 // Back end
|
336
|
250 void toObjFile(int multiobj); // compile to .obj file
|
159
|
251 void toDebug();
|
|
252 unsigned baseVtblOffset(BaseClass *bc);
|
|
253 Symbol *toSymbol();
|
|
254 Symbol *toVtblSymbol();
|
|
255 void toDt(dt_t **pdt);
|
|
256 void toDt2(dt_t **pdt, ClassDeclaration *cd);
|
|
257
|
|
258 Symbol *vtblsym;
|
|
259
|
|
260 ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; }
|
|
261 };
|
|
262
|
|
263 struct InterfaceDeclaration : ClassDeclaration
|
|
264 {
|
336
|
265 #if DMDV2
|
159
|
266 int cpp; // !=0 if this is a C++ interface
|
|
267 #endif
|
|
268 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
|
|
269 Dsymbol *syntaxCopy(Dsymbol *s);
|
|
270 void semantic(Scope *sc);
|
|
271 int isBaseOf(ClassDeclaration *cd, int *poffset);
|
|
272 int isBaseOf(BaseClass *bc, int *poffset);
|
336
|
273 const char *kind();
|
159
|
274 int vtblOffset();
|
336
|
275 #if DMDV2
|
159
|
276 int isCPPinterface();
|
|
277 #endif
|
|
278 virtual int isCOMinterface();
|
|
279
|
336
|
280 void toObjFile(int multiobj); // compile to .obj file
|
159
|
281 Symbol *toSymbol();
|
|
282
|
|
283 InterfaceDeclaration *isInterfaceDeclaration() { return this; }
|
|
284 };
|
|
285
|
|
286 #endif /* DMD_AGGREGATE_H */
|