Mercurial > projects > ldc
annotate dmd/aggregate.h @ 100:5071469303d4 trunk
[svn r104] TONS OF FIXES.
Split up declaration, constant initializer gen and definition for globals, structs, classes and functions.
Improved ClassInfo support (not complete), not in vtable yet.
Fixed a bunch of forward reference problems.
Much more. Major commit! :)
author | lindquist |
---|---|
date | Fri, 16 Nov 2007 08:21:47 +0100 |
parents | ce7ed8f59b99 |
children | 027b8d8b71ec |
rev | line source |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | |
3 // Copyright (c) 1999-2006 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 | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
1
diff
changeset
|
21 #include <vector> |
73 | 22 #include <set> |
23 #include <map> | |
8
5e69b77a5c51
[svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents:
1
diff
changeset
|
24 |
1 | 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; | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
35
diff
changeset
|
45 class ConstantStruct; |
100 | 46 class GlobalVariable; |
1 | 47 } |
100 | 48 struct IRStruct; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
77
diff
changeset
|
49 struct DUnion; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
77
diff
changeset
|
50 |
1 | 51 struct AggregateDeclaration : ScopeDsymbol |
52 { | |
53 Type *type; | |
54 unsigned storage_class; | |
55 enum PROT protection; | |
56 Type *handle; // 'this' type | |
57 unsigned structsize; // size of struct | |
58 unsigned alignsize; // size of struct for alignment purposes | |
59 unsigned structalign; // struct member alignment in effect | |
60 int hasUnions; // set if aggregate has overlapping fields | |
61 Array fields; // VarDeclaration fields | |
62 unsigned sizeok; // set when structsize contains valid data | |
63 // 0: no size | |
64 // 1: size is correct | |
65 // 2: cannot determine size; fwd referenced | |
66 int isdeprecated; // !=0 if deprecated | |
67 Scope *scope; // !=NULL means context to use | |
68 | |
69 // Special member functions | |
70 InvariantDeclaration *inv; // invariant | |
71 NewDeclaration *aggNew; // allocator | |
72 DeleteDeclaration *aggDelete; // deallocator | |
73 | |
74 #ifdef IN_GCC | |
75 Array methods; // flat list of all methods for debug information | |
76 #endif | |
77 | |
78 AggregateDeclaration(Loc loc, Identifier *id); | |
79 void semantic2(Scope *sc); | |
80 void semantic3(Scope *sc); | |
81 void inlineScan(); | |
82 unsigned size(Loc loc); | |
83 static void alignmember(unsigned salign, unsigned size, unsigned *poffset); | |
84 Type *getType(); | |
85 void addField(Scope *sc, VarDeclaration *v); | |
86 int isDeprecated(); // is aggregate deprecated? | |
87 | |
88 void emitComment(Scope *sc); | |
89 void toDocBuffer(OutBuffer *buf); | |
90 | |
91 // For access checking | |
92 virtual PROT getAccess(Dsymbol *smember); // determine access to smember | |
93 int isFriendOf(AggregateDeclaration *cd); | |
94 int hasPrivateAccess(Dsymbol *smember); // does smember have private access to members of this class? | |
95 void accessCheck(Loc loc, Scope *sc, Dsymbol *smember); | |
96 | |
97 enum PROT prot(); | |
98 | |
99 // Back end | |
100 Symbol *stag; // tag symbol for debug data | |
101 Symbol *sinit; | |
102 Symbol *toInitializer(); | |
103 | |
104 bool llvmInProgress; | |
100 | 105 llvm::GlobalVariable* llvmVtbl; |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
35
diff
changeset
|
106 llvm::ConstantStruct* llvmConstVtbl; |
1 | 107 llvm::Constant* llvmInitZ; |
100 | 108 llvm::GlobalVariable* llvmClass; |
109 llvm::Constant* llvmClassZ; | |
73 | 110 bool llvmHasUnions; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
77
diff
changeset
|
111 DUnion* llvmUnion; |
100 | 112 IRStruct* llvmIRStruct; |
1 | 113 |
114 AggregateDeclaration *isAggregateDeclaration() { return this; } | |
115 }; | |
116 | |
117 struct AnonymousAggregateDeclaration : AggregateDeclaration | |
118 { | |
119 AnonymousAggregateDeclaration() | |
120 : AggregateDeclaration(0, NULL) | |
121 { | |
122 } | |
123 | |
124 AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; } | |
125 }; | |
126 | |
127 struct StructDeclaration : AggregateDeclaration | |
128 { | |
129 int zeroInit; // !=0 if initialize with 0 fill | |
130 | |
131 StructDeclaration(Loc loc, Identifier *id); | |
132 Dsymbol *syntaxCopy(Dsymbol *s); | |
133 void semantic(Scope *sc); | |
134 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
135 char *mangle(); | |
136 char *kind(); | |
137 void toDocBuffer(OutBuffer *buf); | |
138 | |
139 PROT getAccess(Dsymbol *smember); // determine access to smember | |
140 | |
141 void toObjFile(); // compile to .obj file | |
142 void toDt(dt_t **pdt); | |
143 void toDebug(); // to symbolic debug info | |
144 | |
145 StructDeclaration *isStructDeclaration() { return this; } | |
146 }; | |
147 | |
148 struct UnionDeclaration : StructDeclaration | |
149 { | |
150 UnionDeclaration(Loc loc, Identifier *id); | |
151 Dsymbol *syntaxCopy(Dsymbol *s); | |
152 char *kind(); | |
153 | |
154 UnionDeclaration *isUnionDeclaration() { return this; } | |
155 }; | |
156 | |
157 struct BaseClass | |
158 { | |
159 Type *type; // (before semantic processing) | |
160 enum PROT protection; // protection for the base interface | |
161 | |
162 ClassDeclaration *base; | |
163 int offset; // 'this' pointer offset | |
164 Array vtbl; // for interfaces: Array of FuncDeclaration's | |
165 // making up the vtbl[] | |
166 | |
167 int baseInterfaces_dim; | |
168 BaseClass *baseInterfaces; // if BaseClass is an interface, these | |
169 // are a copy of the InterfaceDeclaration::interfaces | |
170 | |
171 BaseClass(); | |
172 BaseClass(Type *type, enum PROT protection); | |
173 | |
174 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance); | |
175 void copyBaseInterfaces(BaseClasses *); | |
176 }; | |
177 | |
178 #define CLASSINFO_SIZE (0x3C+12) // value of ClassInfo.size | |
179 | |
180 struct ClassDeclaration : AggregateDeclaration | |
181 { | |
182 static ClassDeclaration *object; | |
183 static ClassDeclaration *classinfo; | |
184 | |
185 ClassDeclaration *baseClass; // NULL only if this is Object | |
186 CtorDeclaration *ctor; | |
187 CtorDeclaration *defaultCtor; // default constructor | |
188 FuncDeclarations dtors; // Array of destructors | |
189 FuncDeclaration *staticCtor; | |
190 FuncDeclaration *staticDtor; | |
191 Array vtbl; // Array of FuncDeclaration's making up the vtbl[] | |
192 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] | |
193 | |
194 BaseClasses baseclasses; // Array of BaseClass's; first is super, | |
195 // rest are Interface's | |
196 | |
197 int interfaces_dim; | |
198 BaseClass **interfaces; // interfaces[interfaces_dim] for this class | |
199 // (does not include baseClass) | |
200 | |
201 BaseClasses *vtblInterfaces; // array of base interfaces that have | |
202 // their own vtbl[] | |
203 | |
204 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration | |
205 int com; // !=0 if this is a COM class | |
206 int isauto; // !=0 if this is an auto class | |
207 int isabstract; // !=0 if abstract class | |
208 | |
209 int isnested; // !=0 if is nested | |
210 VarDeclaration *vthis; // 'this' parameter if this class is nested | |
211 | |
212 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
213 Dsymbol *syntaxCopy(Dsymbol *s); | |
214 void semantic(Scope *sc); | |
215 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
216 int isBaseOf2(ClassDeclaration *cd); | |
217 | |
218 #define OFFSET_RUNTIME 0x76543210 | |
219 virtual int isBaseOf(ClassDeclaration *cd, int *poffset); | |
220 | |
221 Dsymbol *search(Loc, Identifier *ident, int flags); | |
222 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); | |
223 void interfaceSemantic(Scope *sc); | |
224 int isNested(); | |
225 int isCOMclass(); | |
35
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
24
diff
changeset
|
226 virtual int isCOMinterface(); |
1 | 227 int isAbstract(); |
228 virtual int vtblOffset(); | |
229 char *kind(); | |
230 char *mangle(); | |
231 void toDocBuffer(OutBuffer *buf); | |
232 | |
233 PROT getAccess(Dsymbol *smember); // determine access to smember | |
234 | |
235 void addLocalClass(ClassDeclarations *); | |
236 | |
237 // Back end | |
238 void toObjFile(); // compile to .obj file | |
239 void toDebug(); | |
240 unsigned baseVtblOffset(BaseClass *bc); | |
241 Symbol *toSymbol(); | |
242 Symbol *toVtblSymbol(); | |
243 void toDt(dt_t **pdt); | |
244 void toDt2(dt_t **pdt, ClassDeclaration *cd); | |
245 | |
246 Symbol *vtblsym; | |
247 | |
77
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
73
diff
changeset
|
248 void offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result); |
1 | 249 |
250 ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; } | |
251 }; | |
252 | |
253 struct InterfaceDeclaration : ClassDeclaration | |
254 { | |
255 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
256 Dsymbol *syntaxCopy(Dsymbol *s); | |
257 void semantic(Scope *sc); | |
258 int isBaseOf(ClassDeclaration *cd, int *poffset); | |
259 int isBaseOf(BaseClass *bc, int *poffset); | |
260 char *kind(); | |
261 int vtblOffset(); | |
35
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
24
diff
changeset
|
262 virtual int isCOMinterface(); |
1 | 263 |
264 void toObjFile(); // compile to .obj file | |
265 Symbol *toSymbol(); | |
266 | |
267 InterfaceDeclaration *isInterfaceDeclaration() { return this; } | |
268 }; | |
269 | |
270 #endif /* DMD_AGGREGATE_H */ |