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