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