Mercurial > projects > ldc
annotate dmd/aggregate.h @ 1642:f49cb50c6064
Revert 1637 because it breaks HelloWorld with Tangos Stdout. There may be another way to fix this so that Deewiants case works, as well as Tango.
author | Kelly Wilson <wilsonk cpsc.ucalgary.ca> |
---|---|
date | Mon, 08 Mar 2010 23:10:26 -0700 |
parents | 44b145be2ef5 |
children |
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" | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
19 |
159 | 20 #include "dsymbol.h" |
21 | |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1624
diff
changeset
|
22 #if IN_LLVM |
159 | 23 #include <vector> |
24 #include <set> | |
25 #include <map> | |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1624
diff
changeset
|
26 #endif |
159 | 27 |
28 struct Identifier; | |
29 struct Type; | |
30 struct TypeFunction; | |
31 struct Expression; | |
32 struct FuncDeclaration; | |
33 struct CtorDeclaration; | |
34 struct DtorDeclaration; | |
35 struct InvariantDeclaration; | |
36 struct NewDeclaration; | |
37 struct DeleteDeclaration; | |
38 struct InterfaceDeclaration; | |
39 struct ClassInfoDeclaration; | |
40 struct VarDeclaration; | |
41 struct dt_t; | |
42 | |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1624
diff
changeset
|
43 #if IN_LLVM |
159 | 44 namespace llvm |
45 { | |
46 class Type; | |
47 class Value; | |
48 class Constant; | |
49 class ConstantStruct; | |
50 class GlobalVariable; | |
51 } | |
1630
44b145be2ef5
Merge dmd 1.056.
Robert Clipsham <robert@octarineparrot.com>
parents:
1624
diff
changeset
|
52 #endif |
159 | 53 |
54 struct AggregateDeclaration : ScopeDsymbol | |
55 { | |
56 Type *type; | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
57 StorageClass storage_class; |
159 | 58 enum PROT protection; |
59 Type *handle; // 'this' type | |
60 unsigned structsize; // size of struct | |
61 unsigned alignsize; // size of struct for alignment purposes | |
62 unsigned structalign; // struct member alignment in effect | |
63 int hasUnions; // set if aggregate has overlapping fields | |
64 Array fields; // VarDeclaration fields | |
65 unsigned sizeok; // set when structsize contains valid data | |
66 // 0: no size | |
67 // 1: size is correct | |
68 // 2: cannot determine size; fwd referenced | |
69 int isdeprecated; // !=0 if deprecated | |
70 | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
71 #if DMDV2 |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
72 int isnested; // !=0 if is nested |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
73 VarDeclaration *vthis; // 'this' parameter if this aggregate is nested |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
74 #endif |
159 | 75 // Special member functions |
76 InvariantDeclaration *inv; // invariant | |
77 NewDeclaration *aggNew; // allocator | |
78 DeleteDeclaration *aggDelete; // deallocator | |
79 | |
1587 | 80 #if DMDV2 |
81 //CtorDeclaration *ctor; | |
82 Dsymbol *ctor; // CtorDeclaration or TemplateDeclaration | |
83 CtorDeclaration *defaultCtor; // default constructor | |
84 Dsymbol *aliasthis; // forward unresolved lookups to aliasthis | |
85 #endif | |
86 | |
336 | 87 FuncDeclarations dtors; // Array of destructors |
88 FuncDeclaration *dtor; // aggregate destructor | |
89 | |
159 | 90 #ifdef IN_GCC |
91 Array methods; // flat list of all methods for debug information | |
92 #endif | |
93 | |
94 AggregateDeclaration(Loc loc, Identifier *id); | |
95 void semantic2(Scope *sc); | |
96 void semantic3(Scope *sc); | |
97 void inlineScan(); | |
98 unsigned size(Loc loc); | |
99 static void alignmember(unsigned salign, unsigned size, unsigned *poffset); | |
100 Type *getType(); | |
101 void addField(Scope *sc, VarDeclaration *v); | |
102 int isDeprecated(); // is aggregate deprecated? | |
103 FuncDeclaration *buildDtor(Scope *sc); | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
104 int isNested(); |
159 | 105 |
106 void emitComment(Scope *sc); | |
1587 | 107 void toJsonBuffer(OutBuffer *buf); |
159 | 108 void toDocBuffer(OutBuffer *buf); |
109 | |
110 // For access checking | |
111 virtual PROT getAccess(Dsymbol *smember); // determine access to smember | |
112 int isFriendOf(AggregateDeclaration *cd); | |
113 int hasPrivateAccess(Dsymbol *smember); // does smember have private access to members of this class? | |
114 void accessCheck(Loc loc, Scope *sc, Dsymbol *smember); | |
115 | |
116 enum PROT prot(); | |
117 | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
806
diff
changeset
|
118 #if IN_DMD |
159 | 119 // Back end |
120 Symbol *stag; // tag symbol for debug data | |
121 Symbol *sinit; | |
122 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
|
123 #endif |
159 | 124 |
125 AggregateDeclaration *isAggregateDeclaration() { return this; } | |
1482
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
126 |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
127 #if IN_LLVM |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
128 // Aggregates that wouldn't have gotten semantic3'ed if we weren't inlining set this flag. |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
129 bool availableExternally; |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
130 #endif |
159 | 131 }; |
132 | |
133 struct AnonymousAggregateDeclaration : AggregateDeclaration | |
134 { | |
135 AnonymousAggregateDeclaration() | |
136 : AggregateDeclaration(0, NULL) | |
137 { | |
138 } | |
139 | |
140 AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; } | |
141 }; | |
142 | |
143 struct StructDeclaration : AggregateDeclaration | |
144 { | |
145 int zeroInit; // !=0 if initialize with 0 fill | |
336 | 146 #if DMDV2 |
147 int hasIdentityAssign; // !=0 if has identity opAssign | |
148 FuncDeclaration *cpctor; // generated copy-constructor, if any | |
149 | |
150 FuncDeclarations postblits; // Array of postblit functions | |
151 FuncDeclaration *postblit; // aggregate postblit | |
152 #endif | |
159 | 153 |
154 StructDeclaration(Loc loc, Identifier *id); | |
155 Dsymbol *syntaxCopy(Dsymbol *s); | |
156 void semantic(Scope *sc); | |
1624
ae8a94d87ca9
Merge DMD r318: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1602
diff
changeset
|
157 Dsymbol *search(Loc, Identifier *ident, int flags); |
159 | 158 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
159 char *mangle(); | |
336 | 160 const char *kind(); |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
161 #if DMDV1 |
159 | 162 Expression *cloneMembers(); |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
163 #endif |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
164 #if DMDV2 |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
165 int needOpAssign(); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
166 FuncDeclaration *buildOpAssign(Scope *sc); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
167 FuncDeclaration *buildPostBlit(Scope *sc); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
168 FuncDeclaration *buildCpCtor(Scope *sc); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
169 #endif |
159 | 170 void toDocBuffer(OutBuffer *buf); |
171 | |
172 PROT getAccess(Dsymbol *smember); // determine access to smember | |
173 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
174 #if IN_DMD |
336 | 175 void toObjFile(int multiobj); // compile to .obj file |
159 | 176 void toDt(dt_t **pdt); |
177 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
|
178 #endif |
159 | 179 |
180 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
|
181 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
182 #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
|
183 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
|
184 #endif |
159 | 185 }; |
186 | |
187 struct UnionDeclaration : StructDeclaration | |
188 { | |
189 UnionDeclaration(Loc loc, Identifier *id); | |
190 Dsymbol *syntaxCopy(Dsymbol *s); | |
336 | 191 const char *kind(); |
159 | 192 |
193 UnionDeclaration *isUnionDeclaration() { return this; } | |
194 }; | |
195 | |
806
96b404ba7eb0
Move storage of final vtbl from BaseClass to IrInterface: BaseClass instances are shared!
Christian Kamm <kamm incasoftware de>
parents:
797
diff
changeset
|
196 // 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
|
197 // BaseClass instance. |
159 | 198 struct BaseClass |
199 { | |
200 Type *type; // (before semantic processing) | |
201 enum PROT protection; // protection for the base interface | |
202 | |
203 ClassDeclaration *base; | |
204 int offset; // 'this' pointer offset | |
205 Array vtbl; // for interfaces: Array of FuncDeclaration's | |
206 // making up the vtbl[] | |
207 | |
208 int baseInterfaces_dim; | |
209 BaseClass *baseInterfaces; // if BaseClass is an interface, these | |
210 // are a copy of the InterfaceDeclaration::interfaces | |
211 | |
212 BaseClass(); | |
213 BaseClass(Type *type, enum PROT protection); | |
214 | |
215 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance); | |
216 void copyBaseInterfaces(BaseClasses *); | |
217 }; | |
218 | |
336 | 219 #if DMDV2 |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1147
diff
changeset
|
220 #define CLASSINFO_SIZE (0x3C+16+4) // value of ClassInfo.size |
159 | 221 #else |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1147
diff
changeset
|
222 #define CLASSINFO_SIZE (0x3C+12+4) // value of ClassInfo.size |
159 | 223 #endif |
224 | |
225 struct ClassDeclaration : AggregateDeclaration | |
226 { | |
227 static ClassDeclaration *object; | |
228 static ClassDeclaration *classinfo; | |
229 | |
230 ClassDeclaration *baseClass; // NULL only if this is Object | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
231 #if DMDV1 |
159 | 232 CtorDeclaration *ctor; |
233 CtorDeclaration *defaultCtor; // default constructor | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
234 #endif |
159 | 235 FuncDeclaration *staticCtor; |
236 FuncDeclaration *staticDtor; | |
237 Array vtbl; // Array of FuncDeclaration's making up the vtbl[] | |
238 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] | |
239 | |
240 BaseClasses baseclasses; // Array of BaseClass's; first is super, | |
241 // rest are Interface's | |
242 | |
243 int interfaces_dim; | |
244 BaseClass **interfaces; // interfaces[interfaces_dim] for this class | |
245 // (does not include baseClass) | |
246 | |
247 BaseClasses *vtblInterfaces; // array of base interfaces that have | |
248 // their own vtbl[] | |
249 | |
250 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration | |
251 int com; // !=0 if this is a COM class (meaning | |
252 // it derives from IUnknown) | |
1530
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1482
diff
changeset
|
253 int isscope; // !=0 if this is a scope class |
159 | 254 int isabstract; // !=0 if abstract class |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
255 #if DMDV1 |
159 | 256 int isnested; // !=0 if is nested |
257 VarDeclaration *vthis; // 'this' parameter if this class is nested | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
258 #endif |
159 | 259 int inuse; // to prevent recursive attempts |
260 | |
261 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
262 Dsymbol *syntaxCopy(Dsymbol *s); | |
263 void semantic(Scope *sc); | |
264 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
265 int isBaseOf2(ClassDeclaration *cd); | |
266 | |
267 #define OFFSET_RUNTIME 0x76543210 | |
268 virtual int isBaseOf(ClassDeclaration *cd, int *poffset); | |
269 | |
270 Dsymbol *search(Loc, Identifier *ident, int flags); | |
336 | 271 #if DMDV2 |
159 | 272 int isFuncHidden(FuncDeclaration *fd); |
273 #endif | |
274 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); | |
275 void interfaceSemantic(Scope *sc); | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
276 #if DMDV1 |
159 | 277 int isNested(); |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
278 #endif |
159 | 279 int isCOMclass(); |
280 virtual int isCOMinterface(); | |
336 | 281 #if DMDV2 |
159 | 282 virtual int isCPPinterface(); |
283 #endif | |
284 int isAbstract(); | |
285 virtual int vtblOffset(); | |
336 | 286 const char *kind(); |
159 | 287 char *mangle(); |
288 void toDocBuffer(OutBuffer *buf); | |
289 | |
290 PROT getAccess(Dsymbol *smember); // determine access to smember | |
291 | |
292 void addLocalClass(ClassDeclarations *); | |
293 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
294 #if IN_DMD |
159 | 295 // Back end |
336 | 296 void toObjFile(int multiobj); // compile to .obj file |
159 | 297 void toDebug(); |
298 unsigned baseVtblOffset(BaseClass *bc); | |
299 Symbol *toSymbol(); | |
300 Symbol *toVtblSymbol(); | |
301 void toDt(dt_t **pdt); | |
302 void toDt2(dt_t **pdt, ClassDeclaration *cd); | |
303 | |
304 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
|
305 #endif |
159 | 306 |
307 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
|
308 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
309 #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
|
310 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
|
311 #endif |
159 | 312 }; |
313 | |
314 struct InterfaceDeclaration : ClassDeclaration | |
315 { | |
336 | 316 #if DMDV2 |
159 | 317 int cpp; // !=0 if this is a C++ interface |
318 #endif | |
319 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
320 Dsymbol *syntaxCopy(Dsymbol *s); | |
321 void semantic(Scope *sc); | |
322 int isBaseOf(ClassDeclaration *cd, int *poffset); | |
323 int isBaseOf(BaseClass *bc, int *poffset); | |
336 | 324 const char *kind(); |
159 | 325 int vtblOffset(); |
336 | 326 #if DMDV2 |
159 | 327 int isCPPinterface(); |
328 #endif | |
329 virtual int isCOMinterface(); | |
330 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
331 #if IN_DMD |
336 | 332 void toObjFile(int multiobj); // compile to .obj file |
159 | 333 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
|
334 #endif |
159 | 335 |
336 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
|
337 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
338 #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
|
339 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
|
340 #endif |
159 | 341 }; |
342 | |
343 #endif /* DMD_AGGREGATE_H */ |