Mercurial > projects > ldc
annotate dmd/aggregate.h @ 1035:4c524d80e6e1
Move more tests to D_InlineAsm
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Tue, 03 Mar 2009 19:03:27 +0100 |
parents | 96b404ba7eb0 |
children | 1860414bf3b7 |
rev | line source |
---|---|
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 | |
806
96b404ba7eb0
Move storage of final vtbl from BaseClass to IrInterface: BaseClass instances are shared!
Christian Kamm <kamm incasoftware de>
parents:
797
diff
changeset
|
157 // warning: two classes with the same base class share the same |
96b404ba7eb0
Move storage of final vtbl from BaseClass to IrInterface: BaseClass instances are shared!
Christian Kamm <kamm incasoftware de>
parents:
797
diff
changeset
|
158 // BaseClass instance. |
159 | 159 struct BaseClass |
160 { | |
161 Type *type; // (before semantic processing) | |
162 enum PROT protection; // protection for the base interface | |
163 | |
164 ClassDeclaration *base; | |
165 int offset; // 'this' pointer offset | |
166 Array vtbl; // for interfaces: Array of FuncDeclaration's | |
167 // making up the vtbl[] | |
168 | |
169 int baseInterfaces_dim; | |
170 BaseClass *baseInterfaces; // if BaseClass is an interface, these | |
171 // are a copy of the InterfaceDeclaration::interfaces | |
172 | |
173 BaseClass(); | |
174 BaseClass(Type *type, enum PROT protection); | |
175 | |
176 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance); | |
177 void copyBaseInterfaces(BaseClasses *); | |
178 }; | |
179 | |
336 | 180 #if DMDV2 |
159 | 181 #define CLASSINFO_SIZE (0x3C+16) // value of ClassInfo.size |
182 #else | |
183 #define CLASSINFO_SIZE (0x3C+12) // value of ClassInfo.size | |
184 #endif | |
185 | |
186 struct ClassDeclaration : AggregateDeclaration | |
187 { | |
188 static ClassDeclaration *object; | |
189 static ClassDeclaration *classinfo; | |
190 | |
191 ClassDeclaration *baseClass; // NULL only if this is Object | |
192 CtorDeclaration *ctor; | |
193 CtorDeclaration *defaultCtor; // default constructor | |
194 FuncDeclaration *staticCtor; | |
195 FuncDeclaration *staticDtor; | |
196 Array vtbl; // Array of FuncDeclaration's making up the vtbl[] | |
197 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] | |
198 | |
199 BaseClasses baseclasses; // Array of BaseClass's; first is super, | |
200 // rest are Interface's | |
201 | |
202 int interfaces_dim; | |
203 BaseClass **interfaces; // interfaces[interfaces_dim] for this class | |
204 // (does not include baseClass) | |
205 | |
206 BaseClasses *vtblInterfaces; // array of base interfaces that have | |
207 // their own vtbl[] | |
208 | |
209 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration | |
210 int com; // !=0 if this is a COM class (meaning | |
211 // it derives from IUnknown) | |
212 int isauto; // !=0 if this is an auto class | |
213 int isabstract; // !=0 if abstract class | |
214 | |
215 int isnested; // !=0 if is nested | |
216 VarDeclaration *vthis; // 'this' parameter if this class is nested | |
217 | |
218 int inuse; // to prevent recursive attempts | |
219 | |
220 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
221 Dsymbol *syntaxCopy(Dsymbol *s); | |
222 void semantic(Scope *sc); | |
223 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
224 int isBaseOf2(ClassDeclaration *cd); | |
225 | |
226 #define OFFSET_RUNTIME 0x76543210 | |
227 virtual int isBaseOf(ClassDeclaration *cd, int *poffset); | |
228 | |
229 Dsymbol *search(Loc, Identifier *ident, int flags); | |
336 | 230 #if DMDV2 |
159 | 231 int isFuncHidden(FuncDeclaration *fd); |
232 #endif | |
233 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); | |
234 void interfaceSemantic(Scope *sc); | |
235 int isNested(); | |
236 int isCOMclass(); | |
237 virtual int isCOMinterface(); | |
336 | 238 #if DMDV2 |
159 | 239 virtual int isCPPinterface(); |
240 #endif | |
241 int isAbstract(); | |
242 virtual int vtblOffset(); | |
336 | 243 const char *kind(); |
159 | 244 char *mangle(); |
245 void toDocBuffer(OutBuffer *buf); | |
246 | |
247 PROT getAccess(Dsymbol *smember); // determine access to smember | |
248 | |
249 void addLocalClass(ClassDeclarations *); | |
250 | |
251 // Back end | |
336 | 252 void toObjFile(int multiobj); // compile to .obj file |
159 | 253 void toDebug(); |
254 unsigned baseVtblOffset(BaseClass *bc); | |
255 Symbol *toSymbol(); | |
256 Symbol *toVtblSymbol(); | |
257 void toDt(dt_t **pdt); | |
258 void toDt2(dt_t **pdt, ClassDeclaration *cd); | |
259 | |
260 Symbol *vtblsym; | |
261 | |
262 ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; } | |
263 }; | |
264 | |
265 struct InterfaceDeclaration : ClassDeclaration | |
266 { | |
336 | 267 #if DMDV2 |
159 | 268 int cpp; // !=0 if this is a C++ interface |
269 #endif | |
270 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
271 Dsymbol *syntaxCopy(Dsymbol *s); | |
272 void semantic(Scope *sc); | |
273 int isBaseOf(ClassDeclaration *cd, int *poffset); | |
274 int isBaseOf(BaseClass *bc, int *poffset); | |
336 | 275 const char *kind(); |
159 | 276 int vtblOffset(); |
336 | 277 #if DMDV2 |
159 | 278 int isCPPinterface(); |
279 #endif | |
280 virtual int isCOMinterface(); | |
281 | |
336 | 282 void toObjFile(int multiobj); // compile to .obj file |
159 | 283 Symbol *toSymbol(); |
284 | |
285 InterfaceDeclaration *isInterfaceDeclaration() { return this; } | |
286 }; | |
287 | |
288 #endif /* DMD_AGGREGATE_H */ |