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