Mercurial > projects > ldc
annotate dmd/aggregate.h @ 1587:def7a1d494fd
Merge DMD 1.051
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Fri, 06 Nov 2009 23:58:01 +0100 |
parents | 05c235309d6f |
children | a413ae7329bf |
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 | |
66 // Special member functions | |
67 InvariantDeclaration *inv; // invariant | |
68 NewDeclaration *aggNew; // allocator | |
69 DeleteDeclaration *aggDelete; // deallocator | |
70 | |
1587 | 71 #if DMDV2 |
72 //CtorDeclaration *ctor; | |
73 Dsymbol *ctor; // CtorDeclaration or TemplateDeclaration | |
74 CtorDeclaration *defaultCtor; // default constructor | |
75 Dsymbol *aliasthis; // forward unresolved lookups to aliasthis | |
76 #endif | |
77 | |
336 | 78 FuncDeclarations dtors; // Array of destructors |
79 FuncDeclaration *dtor; // aggregate destructor | |
80 | |
159 | 81 #ifdef IN_GCC |
82 Array methods; // flat list of all methods for debug information | |
83 #endif | |
84 | |
85 AggregateDeclaration(Loc loc, Identifier *id); | |
86 void semantic2(Scope *sc); | |
87 void semantic3(Scope *sc); | |
88 void inlineScan(); | |
89 unsigned size(Loc loc); | |
90 static void alignmember(unsigned salign, unsigned size, unsigned *poffset); | |
91 Type *getType(); | |
92 void addField(Scope *sc, VarDeclaration *v); | |
93 int isDeprecated(); // is aggregate deprecated? | |
94 FuncDeclaration *buildDtor(Scope *sc); | |
95 | |
96 void emitComment(Scope *sc); | |
1587 | 97 void toJsonBuffer(OutBuffer *buf); |
159 | 98 void toDocBuffer(OutBuffer *buf); |
99 | |
100 // For access checking | |
101 virtual PROT getAccess(Dsymbol *smember); // determine access to smember | |
102 int isFriendOf(AggregateDeclaration *cd); | |
103 int hasPrivateAccess(Dsymbol *smember); // does smember have private access to members of this class? | |
104 void accessCheck(Loc loc, Scope *sc, Dsymbol *smember); | |
105 | |
106 enum PROT prot(); | |
107 | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
806
diff
changeset
|
108 #if IN_DMD |
159 | 109 // Back end |
110 Symbol *stag; // tag symbol for debug data | |
111 Symbol *sinit; | |
112 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
|
113 #endif |
159 | 114 |
115 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
|
116 |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
117 #if IN_LLVM |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
118 // 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
|
119 bool availableExternally; |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
120 #endif |
159 | 121 }; |
122 | |
123 struct AnonymousAggregateDeclaration : AggregateDeclaration | |
124 { | |
125 AnonymousAggregateDeclaration() | |
126 : AggregateDeclaration(0, NULL) | |
127 { | |
128 } | |
129 | |
130 AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; } | |
131 }; | |
132 | |
133 struct StructDeclaration : AggregateDeclaration | |
134 { | |
135 int zeroInit; // !=0 if initialize with 0 fill | |
336 | 136 #if DMDV2 |
137 int hasIdentityAssign; // !=0 if has identity opAssign | |
138 FuncDeclaration *cpctor; // generated copy-constructor, if any | |
139 | |
140 FuncDeclarations postblits; // Array of postblit functions | |
141 FuncDeclaration *postblit; // aggregate postblit | |
142 #endif | |
159 | 143 |
144 StructDeclaration(Loc loc, Identifier *id); | |
145 Dsymbol *syntaxCopy(Dsymbol *s); | |
146 void semantic(Scope *sc); | |
147 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
148 char *mangle(); | |
336 | 149 const char *kind(); |
159 | 150 Expression *cloneMembers(); |
151 void toDocBuffer(OutBuffer *buf); | |
152 | |
153 PROT getAccess(Dsymbol *smember); // determine access to smember | |
154 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
155 #if IN_DMD |
336 | 156 void toObjFile(int multiobj); // compile to .obj file |
159 | 157 void toDt(dt_t **pdt); |
158 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
|
159 #endif |
159 | 160 |
161 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
|
162 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
163 #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
|
164 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
|
165 #endif |
159 | 166 }; |
167 | |
168 struct UnionDeclaration : StructDeclaration | |
169 { | |
170 UnionDeclaration(Loc loc, Identifier *id); | |
171 Dsymbol *syntaxCopy(Dsymbol *s); | |
336 | 172 const char *kind(); |
159 | 173 |
174 UnionDeclaration *isUnionDeclaration() { return this; } | |
175 }; | |
176 | |
806
96b404ba7eb0
Move storage of final vtbl from BaseClass to IrInterface: BaseClass instances are shared!
Christian Kamm <kamm incasoftware de>
parents:
797
diff
changeset
|
177 // 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
|
178 // BaseClass instance. |
159 | 179 struct BaseClass |
180 { | |
181 Type *type; // (before semantic processing) | |
182 enum PROT protection; // protection for the base interface | |
183 | |
184 ClassDeclaration *base; | |
185 int offset; // 'this' pointer offset | |
186 Array vtbl; // for interfaces: Array of FuncDeclaration's | |
187 // making up the vtbl[] | |
188 | |
189 int baseInterfaces_dim; | |
190 BaseClass *baseInterfaces; // if BaseClass is an interface, these | |
191 // are a copy of the InterfaceDeclaration::interfaces | |
192 | |
193 BaseClass(); | |
194 BaseClass(Type *type, enum PROT protection); | |
195 | |
196 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance); | |
197 void copyBaseInterfaces(BaseClasses *); | |
198 }; | |
199 | |
336 | 200 #if DMDV2 |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1147
diff
changeset
|
201 #define CLASSINFO_SIZE (0x3C+16+4) // value of ClassInfo.size |
159 | 202 #else |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1147
diff
changeset
|
203 #define CLASSINFO_SIZE (0x3C+12+4) // value of ClassInfo.size |
159 | 204 #endif |
205 | |
206 struct ClassDeclaration : AggregateDeclaration | |
207 { | |
208 static ClassDeclaration *object; | |
209 static ClassDeclaration *classinfo; | |
210 | |
211 ClassDeclaration *baseClass; // NULL only if this is Object | |
212 CtorDeclaration *ctor; | |
213 CtorDeclaration *defaultCtor; // default constructor | |
214 FuncDeclaration *staticCtor; | |
215 FuncDeclaration *staticDtor; | |
216 Array vtbl; // Array of FuncDeclaration's making up the vtbl[] | |
217 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] | |
218 | |
219 BaseClasses baseclasses; // Array of BaseClass's; first is super, | |
220 // rest are Interface's | |
221 | |
222 int interfaces_dim; | |
223 BaseClass **interfaces; // interfaces[interfaces_dim] for this class | |
224 // (does not include baseClass) | |
225 | |
226 BaseClasses *vtblInterfaces; // array of base interfaces that have | |
227 // their own vtbl[] | |
228 | |
229 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration | |
230 int com; // !=0 if this is a COM class (meaning | |
231 // 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
|
232 int isscope; // !=0 if this is a scope class |
159 | 233 int isabstract; // !=0 if abstract class |
234 | |
235 int isnested; // !=0 if is nested | |
236 VarDeclaration *vthis; // 'this' parameter if this class is nested | |
237 | |
238 int inuse; // to prevent recursive attempts | |
239 | |
240 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
241 Dsymbol *syntaxCopy(Dsymbol *s); | |
242 void semantic(Scope *sc); | |
243 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
244 int isBaseOf2(ClassDeclaration *cd); | |
245 | |
246 #define OFFSET_RUNTIME 0x76543210 | |
247 virtual int isBaseOf(ClassDeclaration *cd, int *poffset); | |
248 | |
249 Dsymbol *search(Loc, Identifier *ident, int flags); | |
336 | 250 #if DMDV2 |
159 | 251 int isFuncHidden(FuncDeclaration *fd); |
252 #endif | |
253 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); | |
254 void interfaceSemantic(Scope *sc); | |
255 int isNested(); | |
256 int isCOMclass(); | |
257 virtual int isCOMinterface(); | |
336 | 258 #if DMDV2 |
159 | 259 virtual int isCPPinterface(); |
260 #endif | |
261 int isAbstract(); | |
262 virtual int vtblOffset(); | |
336 | 263 const char *kind(); |
159 | 264 char *mangle(); |
265 void toDocBuffer(OutBuffer *buf); | |
266 | |
267 PROT getAccess(Dsymbol *smember); // determine access to smember | |
268 | |
269 void addLocalClass(ClassDeclarations *); | |
270 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
271 #if IN_DMD |
159 | 272 // Back end |
336 | 273 void toObjFile(int multiobj); // compile to .obj file |
159 | 274 void toDebug(); |
275 unsigned baseVtblOffset(BaseClass *bc); | |
276 Symbol *toSymbol(); | |
277 Symbol *toVtblSymbol(); | |
278 void toDt(dt_t **pdt); | |
279 void toDt2(dt_t **pdt, ClassDeclaration *cd); | |
280 | |
281 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
|
282 #endif |
159 | 283 |
284 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
|
285 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
286 #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
|
287 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
|
288 #endif |
159 | 289 }; |
290 | |
291 struct InterfaceDeclaration : ClassDeclaration | |
292 { | |
336 | 293 #if DMDV2 |
159 | 294 int cpp; // !=0 if this is a C++ interface |
295 #endif | |
296 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
297 Dsymbol *syntaxCopy(Dsymbol *s); | |
298 void semantic(Scope *sc); | |
299 int isBaseOf(ClassDeclaration *cd, int *poffset); | |
300 int isBaseOf(BaseClass *bc, int *poffset); | |
336 | 301 const char *kind(); |
159 | 302 int vtblOffset(); |
336 | 303 #if DMDV2 |
159 | 304 int isCPPinterface(); |
305 #endif | |
306 virtual int isCOMinterface(); | |
307 | |
1147
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_DMD |
336 | 309 void toObjFile(int multiobj); // compile to .obj file |
159 | 310 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
|
311 #endif |
159 | 312 |
313 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
|
314 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
315 #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
|
316 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
|
317 #endif |
159 | 318 }; |
319 | |
320 #endif /* DMD_AGGREGATE_H */ |