Mercurial > projects > ldc
annotate dmd/aggregate.h @ 1181:204197eb9eb5
Fix up some naked asm output for mingw32
author | Kelly Wilson <wilsonk cpsc.ucalgary.ca> |
---|---|
date | Mon, 30 Mar 2009 18:18:23 -0600 |
parents | dbe4af57b240 |
children | 8026319762be |
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 | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
806
diff
changeset
|
101 #if IN_DMD |
159 | 102 // Back end |
103 Symbol *stag; // tag symbol for debug data | |
104 Symbol *sinit; | |
105 Symbol *toInitializer(); | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
806
diff
changeset
|
106 #endif |
159 | 107 |
108 AggregateDeclaration *isAggregateDeclaration() { return this; } | |
109 }; | |
110 | |
111 struct AnonymousAggregateDeclaration : AggregateDeclaration | |
112 { | |
113 AnonymousAggregateDeclaration() | |
114 : AggregateDeclaration(0, NULL) | |
115 { | |
116 } | |
117 | |
118 AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; } | |
119 }; | |
120 | |
121 struct StructDeclaration : AggregateDeclaration | |
122 { | |
123 int zeroInit; // !=0 if initialize with 0 fill | |
336 | 124 #if DMDV2 |
125 int hasIdentityAssign; // !=0 if has identity opAssign | |
126 FuncDeclaration *cpctor; // generated copy-constructor, if any | |
127 | |
128 FuncDeclarations postblits; // Array of postblit functions | |
129 FuncDeclaration *postblit; // aggregate postblit | |
130 #endif | |
159 | 131 |
132 StructDeclaration(Loc loc, Identifier *id); | |
133 Dsymbol *syntaxCopy(Dsymbol *s); | |
134 void semantic(Scope *sc); | |
135 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
136 char *mangle(); | |
336 | 137 const char *kind(); |
159 | 138 Expression *cloneMembers(); |
139 void toDocBuffer(OutBuffer *buf); | |
140 | |
141 PROT getAccess(Dsymbol *smember); // determine access to smember | |
142 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
143 #if IN_DMD |
336 | 144 void toObjFile(int multiobj); // compile to .obj file |
159 | 145 void toDt(dt_t **pdt); |
146 void toDebug(); // to symbolic debug info | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
147 #endif |
159 | 148 |
149 StructDeclaration *isStructDeclaration() { return this; } | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
150 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
151 #if IN_LLVM |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
152 void codegen(Ir*); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
153 #endif |
159 | 154 }; |
155 | |
156 struct UnionDeclaration : StructDeclaration | |
157 { | |
158 UnionDeclaration(Loc loc, Identifier *id); | |
159 Dsymbol *syntaxCopy(Dsymbol *s); | |
336 | 160 const char *kind(); |
159 | 161 |
162 UnionDeclaration *isUnionDeclaration() { return this; } | |
163 }; | |
164 | |
806
96b404ba7eb0
Move storage of final vtbl from BaseClass to IrInterface: BaseClass instances are shared!
Christian Kamm <kamm incasoftware de>
parents:
797
diff
changeset
|
165 // 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
|
166 // BaseClass instance. |
159 | 167 struct BaseClass |
168 { | |
169 Type *type; // (before semantic processing) | |
170 enum PROT protection; // protection for the base interface | |
171 | |
172 ClassDeclaration *base; | |
173 int offset; // 'this' pointer offset | |
174 Array vtbl; // for interfaces: Array of FuncDeclaration's | |
175 // making up the vtbl[] | |
176 | |
177 int baseInterfaces_dim; | |
178 BaseClass *baseInterfaces; // if BaseClass is an interface, these | |
179 // are a copy of the InterfaceDeclaration::interfaces | |
180 | |
181 BaseClass(); | |
182 BaseClass(Type *type, enum PROT protection); | |
183 | |
184 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance); | |
185 void copyBaseInterfaces(BaseClasses *); | |
186 }; | |
187 | |
336 | 188 #if DMDV2 |
159 | 189 #define CLASSINFO_SIZE (0x3C+16) // value of ClassInfo.size |
190 #else | |
191 #define CLASSINFO_SIZE (0x3C+12) // value of ClassInfo.size | |
192 #endif | |
193 | |
194 struct ClassDeclaration : AggregateDeclaration | |
195 { | |
196 static ClassDeclaration *object; | |
197 static ClassDeclaration *classinfo; | |
198 | |
199 ClassDeclaration *baseClass; // NULL only if this is Object | |
200 CtorDeclaration *ctor; | |
201 CtorDeclaration *defaultCtor; // default constructor | |
202 FuncDeclaration *staticCtor; | |
203 FuncDeclaration *staticDtor; | |
204 Array vtbl; // Array of FuncDeclaration's making up the vtbl[] | |
205 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] | |
206 | |
207 BaseClasses baseclasses; // Array of BaseClass's; first is super, | |
208 // rest are Interface's | |
209 | |
210 int interfaces_dim; | |
211 BaseClass **interfaces; // interfaces[interfaces_dim] for this class | |
212 // (does not include baseClass) | |
213 | |
214 BaseClasses *vtblInterfaces; // array of base interfaces that have | |
215 // their own vtbl[] | |
216 | |
217 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration | |
218 int com; // !=0 if this is a COM class (meaning | |
219 // it derives from IUnknown) | |
220 int isauto; // !=0 if this is an auto class | |
221 int isabstract; // !=0 if abstract class | |
222 | |
223 int isnested; // !=0 if is nested | |
224 VarDeclaration *vthis; // 'this' parameter if this class is nested | |
225 | |
226 int inuse; // to prevent recursive attempts | |
227 | |
228 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
229 Dsymbol *syntaxCopy(Dsymbol *s); | |
230 void semantic(Scope *sc); | |
231 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
232 int isBaseOf2(ClassDeclaration *cd); | |
233 | |
234 #define OFFSET_RUNTIME 0x76543210 | |
235 virtual int isBaseOf(ClassDeclaration *cd, int *poffset); | |
236 | |
237 Dsymbol *search(Loc, Identifier *ident, int flags); | |
336 | 238 #if DMDV2 |
159 | 239 int isFuncHidden(FuncDeclaration *fd); |
240 #endif | |
241 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); | |
242 void interfaceSemantic(Scope *sc); | |
243 int isNested(); | |
244 int isCOMclass(); | |
245 virtual int isCOMinterface(); | |
336 | 246 #if DMDV2 |
159 | 247 virtual int isCPPinterface(); |
248 #endif | |
249 int isAbstract(); | |
250 virtual int vtblOffset(); | |
336 | 251 const char *kind(); |
159 | 252 char *mangle(); |
253 void toDocBuffer(OutBuffer *buf); | |
254 | |
255 PROT getAccess(Dsymbol *smember); // determine access to smember | |
256 | |
257 void addLocalClass(ClassDeclarations *); | |
258 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
259 #if IN_DMD |
159 | 260 // Back end |
336 | 261 void toObjFile(int multiobj); // compile to .obj file |
159 | 262 void toDebug(); |
263 unsigned baseVtblOffset(BaseClass *bc); | |
264 Symbol *toSymbol(); | |
265 Symbol *toVtblSymbol(); | |
266 void toDt(dt_t **pdt); | |
267 void toDt2(dt_t **pdt, ClassDeclaration *cd); | |
268 | |
269 Symbol *vtblsym; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
806
diff
changeset
|
270 #endif |
159 | 271 |
272 ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; } | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
273 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
274 #if IN_LLVM |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
275 virtual void codegen(Ir*); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
276 #endif |
159 | 277 }; |
278 | |
279 struct InterfaceDeclaration : ClassDeclaration | |
280 { | |
336 | 281 #if DMDV2 |
159 | 282 int cpp; // !=0 if this is a C++ interface |
283 #endif | |
284 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
285 Dsymbol *syntaxCopy(Dsymbol *s); | |
286 void semantic(Scope *sc); | |
287 int isBaseOf(ClassDeclaration *cd, int *poffset); | |
288 int isBaseOf(BaseClass *bc, int *poffset); | |
336 | 289 const char *kind(); |
159 | 290 int vtblOffset(); |
336 | 291 #if DMDV2 |
159 | 292 int isCPPinterface(); |
293 #endif | |
294 virtual int isCOMinterface(); | |
295 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
296 #if IN_DMD |
336 | 297 void toObjFile(int multiobj); // compile to .obj file |
159 | 298 Symbol *toSymbol(); |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
806
diff
changeset
|
299 #endif |
159 | 300 |
301 InterfaceDeclaration *isInterfaceDeclaration() { return this; } | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
302 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
303 #if IN_LLVM |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
304 void codegen(Ir*); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
305 #endif |
159 | 306 }; |
307 | |
308 #endif /* DMD_AGGREGATE_H */ |