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