comparison dmd2/aggregate.h @ 758:f04dde6e882c

Added initial D2 support, D2 frontend and changes to codegen to make things compile.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 11 Nov 2008 01:38:48 +0100
parents
children 340acf1535d0
comparison
equal deleted inserted replaced
757:2c730d530c98 758:f04dde6e882c
1
2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2008 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
21 #include <vector>
22 #include <set>
23 #include <map>
24
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;
45 class ConstantStruct;
46 class GlobalVariable;
47 }
48 struct DUnion;
49
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 #if DMDV2
74 CtorDeclaration *ctor;
75 CtorDeclaration *defaultCtor; // default constructor
76 #endif
77
78 FuncDeclarations dtors; // Array of destructors
79 FuncDeclaration *dtor; // aggregate destructor
80
81 #ifdef IN_GCC
82 Array methods; // flat list of all methods for debug information
83 #endif
84
85 AggregateDeclaration(Loc loc, Identifier *id);
86 void semantic2(Scope *sc);
87 void semantic3(Scope *sc);
88 void inlineScan();
89 unsigned size(Loc loc);
90 static void alignmember(unsigned salign, unsigned size, unsigned *poffset);
91 Type *getType();
92 void addField(Scope *sc, VarDeclaration *v);
93 int isDeprecated(); // is aggregate deprecated?
94 FuncDeclaration *buildDtor(Scope *sc);
95
96 void emitComment(Scope *sc);
97 void toDocBuffer(OutBuffer *buf);
98
99 // For access checking
100 virtual PROT getAccess(Dsymbol *smember); // determine access to smember
101 int isFriendOf(AggregateDeclaration *cd);
102 int hasPrivateAccess(Dsymbol *smember); // does smember have private access to members of this class?
103 void accessCheck(Loc loc, Scope *sc, Dsymbol *smember);
104
105 enum PROT prot();
106
107 // Back end
108 Symbol *stag; // tag symbol for debug data
109 Symbol *sinit;
110 Symbol *toInitializer();
111
112 AggregateDeclaration *isAggregateDeclaration() { return this; }
113 };
114
115 struct AnonymousAggregateDeclaration : AggregateDeclaration
116 {
117 AnonymousAggregateDeclaration()
118 : AggregateDeclaration(0, NULL)
119 {
120 }
121
122 AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; }
123 };
124
125 struct StructDeclaration : AggregateDeclaration
126 {
127 int zeroInit; // !=0 if initialize with 0 fill
128 #if DMDV2
129 int hasIdentityAssign; // !=0 if has identity opAssign
130 FuncDeclaration *cpctor; // generated copy-constructor, if any
131
132 FuncDeclarations postblits; // Array of postblit functions
133 FuncDeclaration *postblit; // aggregate postblit
134 #endif
135
136 StructDeclaration(Loc loc, Identifier *id);
137 Dsymbol *syntaxCopy(Dsymbol *s);
138 void semantic(Scope *sc);
139 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
140 char *mangle();
141 const char *kind();
142 int needOpAssign();
143 FuncDeclaration *buildOpAssign(Scope *sc);
144 FuncDeclaration *buildPostBlit(Scope *sc);
145 FuncDeclaration *buildCpCtor(Scope *sc);
146 void toDocBuffer(OutBuffer *buf);
147
148 PROT getAccess(Dsymbol *smember); // determine access to smember
149
150 void toObjFile(int multiobj); // compile to .obj file
151 void toDt(dt_t **pdt);
152 void toDebug(); // to symbolic debug info
153
154 StructDeclaration *isStructDeclaration() { return this; }
155 };
156
157 struct UnionDeclaration : StructDeclaration
158 {
159 UnionDeclaration(Loc loc, Identifier *id);
160 Dsymbol *syntaxCopy(Dsymbol *s);
161 const char *kind();
162
163 UnionDeclaration *isUnionDeclaration() { return this; }
164 };
165
166 struct BaseClass
167 {
168 Type *type; // (before semantic processing)
169 enum PROT protection; // protection for the base interface
170
171 ClassDeclaration *base;
172 int offset; // 'this' pointer offset
173 Array vtbl; // for interfaces: Array of FuncDeclaration's
174 // making up the vtbl[]
175
176 int baseInterfaces_dim;
177 BaseClass *baseInterfaces; // if BaseClass is an interface, these
178 // are a copy of the InterfaceDeclaration::interfaces
179
180 BaseClass();
181 BaseClass(Type *type, enum PROT protection);
182
183 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance);
184 void copyBaseInterfaces(BaseClasses *);
185 };
186
187 #if DMDV2
188 #define CLASSINFO_SIZE (0x3C+16) // value of ClassInfo.size
189 #else
190 #define CLASSINFO_SIZE (0x3C+12) // value of ClassInfo.size
191 #endif
192
193 struct ClassDeclaration : AggregateDeclaration
194 {
195 static ClassDeclaration *object;
196 static ClassDeclaration *classinfo;
197
198 ClassDeclaration *baseClass; // NULL only if this is Object
199 FuncDeclaration *staticCtor;
200 FuncDeclaration *staticDtor;
201 Array vtbl; // Array of FuncDeclaration's making up the vtbl[]
202 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[]
203
204 BaseClasses baseclasses; // Array of BaseClass's; first is super,
205 // rest are Interface's
206
207 int interfaces_dim;
208 BaseClass **interfaces; // interfaces[interfaces_dim] for this class
209 // (does not include baseClass)
210
211 BaseClasses *vtblInterfaces; // array of base interfaces that have
212 // their own vtbl[]
213
214 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration
215 int com; // !=0 if this is a COM class (meaning
216 // it derives from IUnknown)
217 int isauto; // !=0 if this is an auto class
218 int isabstract; // !=0 if abstract class
219
220 int isnested; // !=0 if is nested
221 VarDeclaration *vthis; // 'this' parameter if this class is nested
222
223 int inuse; // to prevent recursive attempts
224
225 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
226 Dsymbol *syntaxCopy(Dsymbol *s);
227 void semantic(Scope *sc);
228 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
229 int isBaseOf2(ClassDeclaration *cd);
230
231 #define OFFSET_RUNTIME 0x76543210
232 virtual int isBaseOf(ClassDeclaration *cd, int *poffset);
233
234 Dsymbol *search(Loc, Identifier *ident, int flags);
235 #if DMDV2
236 int isFuncHidden(FuncDeclaration *fd);
237 #endif
238 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf);
239 void interfaceSemantic(Scope *sc);
240 int isNested();
241 int isCOMclass();
242 virtual int isCOMinterface();
243 #if DMDV2
244 virtual int isCPPinterface();
245 #endif
246 int isAbstract();
247 virtual int vtblOffset();
248 const char *kind();
249 char *mangle();
250 void toDocBuffer(OutBuffer *buf);
251
252 PROT getAccess(Dsymbol *smember); // determine access to smember
253
254 void addLocalClass(ClassDeclarations *);
255
256 // Back end
257 void toObjFile(int multiobj); // compile to .obj file
258 void toDebug();
259 unsigned baseVtblOffset(BaseClass *bc);
260 Symbol *toSymbol();
261 Symbol *toVtblSymbol();
262 void toDt(dt_t **pdt);
263 void toDt2(dt_t **pdt, ClassDeclaration *cd);
264
265 Symbol *vtblsym;
266
267 // llvm
268 void offsetToIndex(Type* t, unsigned os, std::vector<unsigned>& result);
269
270 ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; }
271 };
272
273 struct InterfaceDeclaration : ClassDeclaration
274 {
275 #if DMDV2
276 int cpp; // !=0 if this is a C++ interface
277 #endif
278 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
279 Dsymbol *syntaxCopy(Dsymbol *s);
280 void semantic(Scope *sc);
281 int isBaseOf(ClassDeclaration *cd, int *poffset);
282 int isBaseOf(BaseClass *bc, int *poffset);
283 const char *kind();
284 int vtblOffset();
285 #if DMDV2
286 int isCPPinterface();
287 #endif
288 virtual int isCOMinterface();
289
290 void toObjFile(int multiobj); // compile to .obj file
291 Symbol *toSymbol();
292
293 InterfaceDeclaration *isInterfaceDeclaration() { return this; }
294 };
295
296 #endif /* DMD_AGGREGATE_H */