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 FuncDeclarations dtors; // Array of destructors
|
|
68 FuncDeclaration *dtor; // aggregate destructor
|
|
69
|
|
70 // Special member functions
|
|
71 InvariantDeclaration *inv; // invariant
|
|
72 NewDeclaration *aggNew; // allocator
|
|
73 DeleteDeclaration *aggDelete; // deallocator
|
|
74
|
|
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
|
|
122
|
|
123 StructDeclaration(Loc loc, Identifier *id);
|
|
124 Dsymbol *syntaxCopy(Dsymbol *s);
|
|
125 void semantic(Scope *sc);
|
|
126 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
127 char *mangle();
|
|
128 char *kind();
|
|
129 Expression *cloneMembers();
|
|
130 void toDocBuffer(OutBuffer *buf);
|
|
131
|
|
132 PROT getAccess(Dsymbol *smember); // determine access to smember
|
|
133
|
|
134 void toObjFile(); // compile to .obj file
|
|
135 void toDt(dt_t **pdt);
|
|
136 void toDebug(); // to symbolic debug info
|
|
137
|
|
138 StructDeclaration *isStructDeclaration() { return this; }
|
|
139 };
|
|
140
|
|
141 struct UnionDeclaration : StructDeclaration
|
|
142 {
|
|
143 UnionDeclaration(Loc loc, Identifier *id);
|
|
144 Dsymbol *syntaxCopy(Dsymbol *s);
|
|
145 char *kind();
|
|
146
|
|
147 UnionDeclaration *isUnionDeclaration() { return this; }
|
|
148 };
|
|
149
|
|
150 struct BaseClass
|
|
151 {
|
|
152 Type *type; // (before semantic processing)
|
|
153 enum PROT protection; // protection for the base interface
|
|
154
|
|
155 ClassDeclaration *base;
|
|
156 int offset; // 'this' pointer offset
|
|
157 Array vtbl; // for interfaces: Array of FuncDeclaration's
|
|
158 // making up the vtbl[]
|
|
159
|
|
160 int baseInterfaces_dim;
|
|
161 BaseClass *baseInterfaces; // if BaseClass is an interface, these
|
|
162 // are a copy of the InterfaceDeclaration::interfaces
|
|
163
|
|
164 BaseClass();
|
|
165 BaseClass(Type *type, enum PROT protection);
|
|
166
|
|
167 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance);
|
|
168 void copyBaseInterfaces(BaseClasses *);
|
|
169 };
|
|
170
|
|
171 #if V2
|
|
172 #define CLASSINFO_SIZE (0x3C+16) // value of ClassInfo.size
|
|
173 #else
|
|
174 #define CLASSINFO_SIZE (0x3C+12) // value of ClassInfo.size
|
|
175 #endif
|
|
176
|
|
177 struct ClassDeclaration : AggregateDeclaration
|
|
178 {
|
|
179 static ClassDeclaration *object;
|
|
180 static ClassDeclaration *classinfo;
|
|
181
|
|
182 ClassDeclaration *baseClass; // NULL only if this is Object
|
|
183 CtorDeclaration *ctor;
|
|
184 CtorDeclaration *defaultCtor; // default constructor
|
|
185 FuncDeclaration *staticCtor;
|
|
186 FuncDeclaration *staticDtor;
|
|
187 Array vtbl; // Array of FuncDeclaration's making up the vtbl[]
|
|
188 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[]
|
|
189
|
|
190 BaseClasses baseclasses; // Array of BaseClass's; first is super,
|
|
191 // rest are Interface's
|
|
192
|
|
193 int interfaces_dim;
|
|
194 BaseClass **interfaces; // interfaces[interfaces_dim] for this class
|
|
195 // (does not include baseClass)
|
|
196
|
|
197 BaseClasses *vtblInterfaces; // array of base interfaces that have
|
|
198 // their own vtbl[]
|
|
199
|
|
200 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration
|
|
201 int com; // !=0 if this is a COM class (meaning
|
|
202 // it derives from IUnknown)
|
|
203 int isauto; // !=0 if this is an auto class
|
|
204 int isabstract; // !=0 if abstract class
|
|
205
|
|
206 int isnested; // !=0 if is nested
|
|
207 VarDeclaration *vthis; // 'this' parameter if this class is nested
|
|
208
|
|
209 int inuse; // to prevent recursive attempts
|
|
210
|
|
211 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
|
|
212 Dsymbol *syntaxCopy(Dsymbol *s);
|
|
213 void semantic(Scope *sc);
|
|
214 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
215 int isBaseOf2(ClassDeclaration *cd);
|
|
216
|
|
217 #define OFFSET_RUNTIME 0x76543210
|
|
218 virtual int isBaseOf(ClassDeclaration *cd, int *poffset);
|
|
219
|
|
220 Dsymbol *search(Loc, Identifier *ident, int flags);
|
|
221 #if V2
|
|
222 int isFuncHidden(FuncDeclaration *fd);
|
|
223 #endif
|
|
224 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf);
|
|
225 void interfaceSemantic(Scope *sc);
|
|
226 int isNested();
|
|
227 int isCOMclass();
|
|
228 virtual int isCOMinterface();
|
|
229 #if V2
|
|
230 virtual int isCPPinterface();
|
|
231 #endif
|
|
232 int isAbstract();
|
|
233 virtual int vtblOffset();
|
|
234 char *kind();
|
|
235 char *mangle();
|
|
236 void toDocBuffer(OutBuffer *buf);
|
|
237
|
|
238 PROT getAccess(Dsymbol *smember); // determine access to smember
|
|
239
|
|
240 void addLocalClass(ClassDeclarations *);
|
|
241
|
|
242 // Back end
|
|
243 void toObjFile(); // compile to .obj file
|
|
244 void toDebug();
|
|
245 unsigned baseVtblOffset(BaseClass *bc);
|
|
246 Symbol *toSymbol();
|
|
247 Symbol *toVtblSymbol();
|
|
248 void toDt(dt_t **pdt);
|
|
249 void toDt2(dt_t **pdt, ClassDeclaration *cd);
|
|
250
|
|
251 Symbol *vtblsym;
|
|
252
|
|
253 // llvm
|
|
254 void offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result);
|
|
255
|
|
256 ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; }
|
|
257 };
|
|
258
|
|
259 struct InterfaceDeclaration : ClassDeclaration
|
|
260 {
|
|
261 #if V2
|
|
262 int cpp; // !=0 if this is a C++ interface
|
|
263 #endif
|
|
264 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
|
|
265 Dsymbol *syntaxCopy(Dsymbol *s);
|
|
266 void semantic(Scope *sc);
|
|
267 int isBaseOf(ClassDeclaration *cd, int *poffset);
|
|
268 int isBaseOf(BaseClass *bc, int *poffset);
|
|
269 char *kind();
|
|
270 int vtblOffset();
|
|
271 #if V2
|
|
272 int isCPPinterface();
|
|
273 #endif
|
|
274 virtual int isCOMinterface();
|
|
275
|
|
276 void toObjFile(); // compile to .obj file
|
|
277 Symbol *toSymbol();
|
|
278
|
|
279 InterfaceDeclaration *isInterfaceDeclaration() { return this; }
|
|
280 };
|
|
281
|
|
282 #endif /* DMD_AGGREGATE_H */
|