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