Mercurial > projects > ldc
annotate dmd/aggregate.h @ 120:5ce8ab11e75a trunk
[svn r124] Fixed another D vararg + return in ptr bug.
Fixed some nested function calls failed to resolve the context ptr.
author | lindquist |
---|---|
date | Mon, 26 Nov 2007 07:26:21 +0100 |
parents | 027b8d8b71ec |
children | 9c79b61fb638 |
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; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
113 bool llvmClassDeclared; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
114 bool llvmClassDefined; |
1 | 115 |
116 AggregateDeclaration *isAggregateDeclaration() { return this; } | |
117 }; | |
118 | |
119 struct AnonymousAggregateDeclaration : AggregateDeclaration | |
120 { | |
121 AnonymousAggregateDeclaration() | |
122 : AggregateDeclaration(0, NULL) | |
123 { | |
124 } | |
125 | |
126 AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; } | |
127 }; | |
128 | |
129 struct StructDeclaration : AggregateDeclaration | |
130 { | |
131 int zeroInit; // !=0 if initialize with 0 fill | |
132 | |
133 StructDeclaration(Loc loc, Identifier *id); | |
134 Dsymbol *syntaxCopy(Dsymbol *s); | |
135 void semantic(Scope *sc); | |
136 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
137 char *mangle(); | |
138 char *kind(); | |
139 void toDocBuffer(OutBuffer *buf); | |
140 | |
141 PROT getAccess(Dsymbol *smember); // determine access to smember | |
142 | |
143 void toObjFile(); // compile to .obj file | |
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); | |
154 char *kind(); | |
155 | |
156 UnionDeclaration *isUnionDeclaration() { return this; } | |
157 }; | |
158 | |
159 struct BaseClass | |
160 { | |
161 Type *type; // (before semantic processing) | |
162 enum PROT protection; // protection for the base interface | |
163 | |
164 ClassDeclaration *base; | |
165 int offset; // 'this' pointer offset | |
166 Array vtbl; // for interfaces: Array of FuncDeclaration's | |
167 // making up the vtbl[] | |
168 | |
169 int baseInterfaces_dim; | |
170 BaseClass *baseInterfaces; // if BaseClass is an interface, these | |
171 // are a copy of the InterfaceDeclaration::interfaces | |
172 | |
173 BaseClass(); | |
174 BaseClass(Type *type, enum PROT protection); | |
175 | |
176 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance); | |
177 void copyBaseInterfaces(BaseClasses *); | |
178 }; | |
179 | |
180 #define CLASSINFO_SIZE (0x3C+12) // value of ClassInfo.size | |
181 | |
182 struct ClassDeclaration : AggregateDeclaration | |
183 { | |
184 static ClassDeclaration *object; | |
185 static ClassDeclaration *classinfo; | |
186 | |
187 ClassDeclaration *baseClass; // NULL only if this is Object | |
188 CtorDeclaration *ctor; | |
189 CtorDeclaration *defaultCtor; // default constructor | |
190 FuncDeclarations dtors; // Array of destructors | |
191 FuncDeclaration *staticCtor; | |
192 FuncDeclaration *staticDtor; | |
193 Array vtbl; // Array of FuncDeclaration's making up the vtbl[] | |
194 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] | |
195 | |
196 BaseClasses baseclasses; // Array of BaseClass's; first is super, | |
197 // rest are Interface's | |
198 | |
199 int interfaces_dim; | |
200 BaseClass **interfaces; // interfaces[interfaces_dim] for this class | |
201 // (does not include baseClass) | |
202 | |
203 BaseClasses *vtblInterfaces; // array of base interfaces that have | |
204 // their own vtbl[] | |
205 | |
206 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration | |
207 int com; // !=0 if this is a COM class | |
208 int isauto; // !=0 if this is an auto class | |
209 int isabstract; // !=0 if abstract class | |
210 | |
211 int isnested; // !=0 if is nested | |
212 VarDeclaration *vthis; // 'this' parameter if this class is nested | |
213 | |
214 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
215 Dsymbol *syntaxCopy(Dsymbol *s); | |
216 void semantic(Scope *sc); | |
217 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
218 int isBaseOf2(ClassDeclaration *cd); | |
219 | |
220 #define OFFSET_RUNTIME 0x76543210 | |
221 virtual int isBaseOf(ClassDeclaration *cd, int *poffset); | |
222 | |
223 Dsymbol *search(Loc, Identifier *ident, int flags); | |
224 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); | |
225 void interfaceSemantic(Scope *sc); | |
226 int isNested(); | |
227 int isCOMclass(); | |
35
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
24
diff
changeset
|
228 virtual int isCOMinterface(); |
1 | 229 int isAbstract(); |
230 virtual int vtblOffset(); | |
231 char *kind(); | |
232 char *mangle(); | |
233 void toDocBuffer(OutBuffer *buf); | |
234 | |
235 PROT getAccess(Dsymbol *smember); // determine access to smember | |
236 | |
237 void addLocalClass(ClassDeclarations *); | |
238 | |
239 // Back end | |
240 void toObjFile(); // compile to .obj file | |
241 void toDebug(); | |
242 unsigned baseVtblOffset(BaseClass *bc); | |
243 Symbol *toSymbol(); | |
244 Symbol *toVtblSymbol(); | |
245 void toDt(dt_t **pdt); | |
246 void toDt2(dt_t **pdt, ClassDeclaration *cd); | |
247 | |
248 Symbol *vtblsym; | |
249 | |
77
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
73
diff
changeset
|
250 void offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result); |
1 | 251 |
252 ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; } | |
253 }; | |
254 | |
255 struct InterfaceDeclaration : ClassDeclaration | |
256 { | |
257 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
258 Dsymbol *syntaxCopy(Dsymbol *s); | |
259 void semantic(Scope *sc); | |
260 int isBaseOf(ClassDeclaration *cd, int *poffset); | |
261 int isBaseOf(BaseClass *bc, int *poffset); | |
262 char *kind(); | |
263 int vtblOffset(); | |
35
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
24
diff
changeset
|
264 virtual int isCOMinterface(); |
1 | 265 |
266 void toObjFile(); // compile to .obj file | |
267 Symbol *toSymbol(); | |
268 | |
269 InterfaceDeclaration *isInterfaceDeclaration() { return this; } | |
270 }; | |
271 | |
272 #endif /* DMD_AGGREGATE_H */ |