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