Mercurial > projects > ldc
annotate dmd/aggregate.h @ 86:fd32135dca3e trunk
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
Lots of bugfixes.
Added support for special foreach on strings.
Added std.array, std.utf, std.ctype and std.uni to phobos.
Changed all the .c files in the gen dir to .cpp (it *is* C++ after all)
author | lindquist |
---|---|
date | Sat, 03 Nov 2007 14:44:58 +0100 |
parents | 714057ff2dbb |
children | 058d3925950e |
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; |
1 | 107 |
108 AggregateDeclaration *isAggregateDeclaration() { return this; } | |
109 }; | |
110 | |
111 struct AnonymousAggregateDeclaration : AggregateDeclaration | |
112 { | |
113 AnonymousAggregateDeclaration() | |
114 : AggregateDeclaration(0, NULL) | |
115 { | |
116 } | |
117 | |
118 AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; } | |
119 }; | |
120 | |
121 struct StructDeclaration : AggregateDeclaration | |
122 { | |
123 int zeroInit; // !=0 if initialize with 0 fill | |
124 | |
125 StructDeclaration(Loc loc, Identifier *id); | |
126 Dsymbol *syntaxCopy(Dsymbol *s); | |
127 void semantic(Scope *sc); | |
128 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
129 char *mangle(); | |
130 char *kind(); | |
131 void toDocBuffer(OutBuffer *buf); | |
132 | |
133 PROT getAccess(Dsymbol *smember); // determine access to smember | |
134 | |
135 void toObjFile(); // compile to .obj file | |
136 void toDt(dt_t **pdt); | |
137 void toDebug(); // to symbolic debug info | |
138 | |
139 StructDeclaration *isStructDeclaration() { return this; } | |
140 }; | |
141 | |
142 struct UnionDeclaration : StructDeclaration | |
143 { | |
144 UnionDeclaration(Loc loc, Identifier *id); | |
145 Dsymbol *syntaxCopy(Dsymbol *s); | |
146 char *kind(); | |
147 | |
148 UnionDeclaration *isUnionDeclaration() { return this; } | |
149 }; | |
150 | |
151 struct BaseClass | |
152 { | |
153 Type *type; // (before semantic processing) | |
154 enum PROT protection; // protection for the base interface | |
155 | |
156 ClassDeclaration *base; | |
157 int offset; // 'this' pointer offset | |
158 Array vtbl; // for interfaces: Array of FuncDeclaration's | |
159 // making up the vtbl[] | |
160 | |
161 int baseInterfaces_dim; | |
162 BaseClass *baseInterfaces; // if BaseClass is an interface, these | |
163 // are a copy of the InterfaceDeclaration::interfaces | |
164 | |
165 BaseClass(); | |
166 BaseClass(Type *type, enum PROT protection); | |
167 | |
168 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance); | |
169 void copyBaseInterfaces(BaseClasses *); | |
170 }; | |
171 | |
172 #define CLASSINFO_SIZE (0x3C+12) // value of ClassInfo.size | |
173 | |
174 struct ClassDeclaration : AggregateDeclaration | |
175 { | |
176 static ClassDeclaration *object; | |
177 static ClassDeclaration *classinfo; | |
178 | |
179 ClassDeclaration *baseClass; // NULL only if this is Object | |
180 CtorDeclaration *ctor; | |
181 CtorDeclaration *defaultCtor; // default constructor | |
182 FuncDeclarations dtors; // Array of destructors | |
183 FuncDeclaration *staticCtor; | |
184 FuncDeclaration *staticDtor; | |
185 Array vtbl; // Array of FuncDeclaration's making up the vtbl[] | |
186 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] | |
187 | |
188 BaseClasses baseclasses; // Array of BaseClass's; first is super, | |
189 // rest are Interface's | |
190 | |
191 int interfaces_dim; | |
192 BaseClass **interfaces; // interfaces[interfaces_dim] for this class | |
193 // (does not include baseClass) | |
194 | |
195 BaseClasses *vtblInterfaces; // array of base interfaces that have | |
196 // their own vtbl[] | |
197 | |
198 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration | |
199 int com; // !=0 if this is a COM class | |
200 int isauto; // !=0 if this is an auto class | |
201 int isabstract; // !=0 if abstract class | |
202 | |
203 int isnested; // !=0 if is nested | |
204 VarDeclaration *vthis; // 'this' parameter if this class is nested | |
205 | |
206 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
207 Dsymbol *syntaxCopy(Dsymbol *s); | |
208 void semantic(Scope *sc); | |
209 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
210 int isBaseOf2(ClassDeclaration *cd); | |
211 | |
212 #define OFFSET_RUNTIME 0x76543210 | |
213 virtual int isBaseOf(ClassDeclaration *cd, int *poffset); | |
214 | |
215 Dsymbol *search(Loc, Identifier *ident, int flags); | |
216 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); | |
217 void interfaceSemantic(Scope *sc); | |
218 int isNested(); | |
219 int isCOMclass(); | |
35
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
24
diff
changeset
|
220 virtual int isCOMinterface(); |
1 | 221 int isAbstract(); |
222 virtual int vtblOffset(); | |
223 char *kind(); | |
224 char *mangle(); | |
225 void toDocBuffer(OutBuffer *buf); | |
226 | |
227 PROT getAccess(Dsymbol *smember); // determine access to smember | |
228 | |
229 void addLocalClass(ClassDeclarations *); | |
230 | |
231 // Back end | |
232 void toObjFile(); // compile to .obj file | |
233 void toDebug(); | |
234 unsigned baseVtblOffset(BaseClass *bc); | |
235 Symbol *toSymbol(); | |
236 Symbol *toVtblSymbol(); | |
237 void toDt(dt_t **pdt); | |
238 void toDt2(dt_t **pdt, ClassDeclaration *cd); | |
239 | |
240 Symbol *vtblsym; | |
241 | |
77
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
73
diff
changeset
|
242 void offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result); |
1 | 243 |
244 ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; } | |
245 }; | |
246 | |
247 struct InterfaceDeclaration : ClassDeclaration | |
248 { | |
249 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
250 Dsymbol *syntaxCopy(Dsymbol *s); | |
251 void semantic(Scope *sc); | |
252 int isBaseOf(ClassDeclaration *cd, int *poffset); | |
253 int isBaseOf(BaseClass *bc, int *poffset); | |
254 char *kind(); | |
255 int vtblOffset(); | |
35
3cfcb944304e
[svn r39] * Updated to DMD 1.022 with the exception of:
lindquist
parents:
24
diff
changeset
|
256 virtual int isCOMinterface(); |
1 | 257 |
258 void toObjFile(); // compile to .obj file | |
259 Symbol *toSymbol(); | |
260 | |
261 InterfaceDeclaration *isInterfaceDeclaration() { return this; } | |
262 }; | |
263 | |
264 #endif /* DMD_AGGREGATE_H */ |