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