Warn about "assert X,Y"
[delight/core.git] / dmd2 / aggregate.h
blob684fb971443a4948fb34bf55ce712220603fb4db
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.
11 /* NOTE: This file has been patched from the original DMD distribution to
12 work with the GDC compiler.
14 Modified by David Friedman, December 2006
17 #ifndef DMD_AGGREGATE_H
18 #define DMD_AGGREGATE_H
20 #ifdef __DMC__
21 #pragma once
22 #endif /* __DMC__ */
24 #include "root.h"
25 #include "dsymbol.h"
27 struct Identifier;
28 struct Type;
29 struct TypeFunction;
30 struct Expression;
31 struct FuncDeclaration;
32 struct CtorDeclaration;
33 struct DtorDeclaration;
34 struct InvariantDeclaration;
35 struct NewDeclaration;
36 struct DeleteDeclaration;
37 struct InterfaceDeclaration;
38 struct ClassInfoDeclaration;
39 struct VarDeclaration;
40 struct dt_t;
43 struct AggregateDeclaration : ScopeDsymbol
45 Type *type;
46 unsigned storage_class;
47 enum PROT protection;
48 Type *handle; // 'this' type
49 target_size_t structsize; // size of struct
50 target_size_t alignsize; // size of struct for alignment purposes
51 target_size_t structalign; // struct member alignment in effect
52 int hasUnions; // set if aggregate has overlapping fields
53 Array fields; // VarDeclaration fields
54 unsigned sizeok; // set when structsize contains valid data
55 // 0: no size
56 // 1: size is correct
57 // 2: cannot determine size; fwd referenced
58 int isdeprecated; // !=0 if deprecated
59 Scope *scope; // !=NULL means context to use
61 // Special member functions
62 InvariantDeclaration *inv; // invariant
63 NewDeclaration *aggNew; // allocator
64 DeleteDeclaration *aggDelete; // deallocator
66 FuncDeclarations dtors; // Array of destructors
67 FuncDeclaration *dtor; // aggregate destructor
69 Expressions * attributes; // GCC decl/type attributes
70 #ifdef IN_GCC
71 Array methods; // flat list of all methods for debug information
72 #endif
74 AggregateDeclaration(Loc loc, Identifier *id);
75 void semantic2(Scope *sc);
76 void semantic3(Scope *sc);
77 void inlineScan();
78 target_size_t size(Loc loc);
79 static void alignmember(target_size_t salign, target_size_t size, target_size_t *poffset);
80 Type *getType();
81 void addField(Scope *sc, VarDeclaration *v);
82 int isDeprecated(); // is aggregate deprecated?
83 FuncDeclaration *buildDtor(Scope *sc);
85 void emitComment(Scope *sc);
86 void toDocBuffer(OutBuffer *buf);
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);
94 enum PROT prot();
96 // Back end
97 Symbol *stag; // tag symbol for debug data
98 Symbol *sinit;
99 Symbol *toInitializer();
101 AggregateDeclaration *isAggregateDeclaration() { return this; }
104 struct AnonymousAggregateDeclaration : AggregateDeclaration
106 AnonymousAggregateDeclaration()
107 : AggregateDeclaration(0, NULL)
111 AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; }
114 struct StructDeclaration : AggregateDeclaration
116 int zeroInit; // !=0 if initialize with 0 fill
117 #if V2
118 int hasIdentityAssign; // !=0 if has identity opAssign
119 FuncDeclaration *cpctor; // generated copy-constructor, if any
121 FuncDeclarations postblits; // Array of postblit functions
122 FuncDeclaration *postblit; // aggregate postblit
123 #endif
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 int needOpAssign();
132 FuncDeclaration *buildOpAssign(Scope *sc);
133 FuncDeclaration *buildPostBlit(Scope *sc);
134 FuncDeclaration *buildCpCtor(Scope *sc);
135 void toDocBuffer(OutBuffer *buf);
137 PROT getAccess(Dsymbol *smember); // determine access to smember
139 void toObjFile(int multiobj); // compile to .obj file
140 void toDt(dt_t **pdt);
141 void toDebug(); // to symbolic debug info
143 StructDeclaration *isStructDeclaration() { return this; }
146 struct UnionDeclaration : StructDeclaration
148 UnionDeclaration(Loc loc, Identifier *id);
149 Dsymbol *syntaxCopy(Dsymbol *s);
150 char *kind();
152 UnionDeclaration *isUnionDeclaration() { return this; }
155 struct BaseClass
157 Type *type; // (before semantic processing)
158 enum PROT protection; // protection for the base interface
160 ClassDeclaration *base;
161 target_ptrdiff_t offset; // 'this' pointer offset
162 Array vtbl; // for interfaces: Array of FuncDeclaration's
163 // making up the vtbl[]
165 int baseInterfaces_dim;
166 BaseClass *baseInterfaces; // if BaseClass is an interface, these
167 // are a copy of the InterfaceDeclaration::interfaces
169 BaseClass();
170 BaseClass(Type *type, enum PROT protection);
172 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance);
173 void copyBaseInterfaces(BaseClasses *);
176 extern int CLASSINFO_SIZE; // value of ClassInfo.size
178 struct ClassDeclaration : AggregateDeclaration
180 static ClassDeclaration *object;
181 static ClassDeclaration *classinfo;
183 ClassDeclaration *baseClass; // NULL only if this is Object
184 CtorDeclaration *ctor;
185 CtorDeclaration *defaultCtor; // default constructor
186 FuncDeclaration *staticCtor;
187 FuncDeclaration *staticDtor;
188 Array vtbl; // Array of FuncDeclaration's making up the vtbl[]
189 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[]
191 BaseClasses baseclasses; // Array of BaseClass's; first is super,
192 // rest are Interface's
194 int interfaces_dim;
195 BaseClass **interfaces; // interfaces[interfaces_dim] for this class
196 // (does not include baseClass)
198 BaseClasses *vtblInterfaces; // array of base interfaces that have
199 // their own vtbl[]
201 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration
202 int com; // !=0 if this is a COM class (meaning
203 // it derives from IUnknown)
204 int isauto; // !=0 if this is an auto class
205 int isabstract; // !=0 if abstract class
207 int isnested; // !=0 if is nested
208 VarDeclaration *vthis; // 'this' parameter if this class is nested
210 int inuse; // to prevent recursive attempts
212 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
213 Dsymbol *syntaxCopy(Dsymbol *s);
214 void semantic(Scope *sc);
215 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
216 int isBaseOf2(ClassDeclaration *cd);
218 #define OFFSET_RUNTIME 0x76543210
219 virtual int isBaseOf(ClassDeclaration *cd, target_ptrdiff_t *poffset);
221 Dsymbol *search(Loc, Identifier *ident, int flags);
222 #if V2
223 int isFuncHidden(FuncDeclaration *fd);
224 #endif
225 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf);
226 void interfaceSemantic(Scope *sc);
227 int isNested();
228 int isCOMclass();
229 virtual int isCOMinterface();
230 #if V2
231 virtual int isCPPinterface();
232 #endif
233 int isAbstract();
234 virtual int vtblOffset();
235 char *kind();
236 char *mangle();
237 void toDocBuffer(OutBuffer *buf);
239 PROT getAccess(Dsymbol *smember); // determine access to smember
241 void addLocalClass(ClassDeclarations *);
243 // Back end
244 void toObjFile(int multiobj); // compile to .obj file
245 void toDebug();
246 unsigned baseVtblOffset(BaseClass *bc);
247 Symbol *toSymbol();
248 Symbol *toVtblSymbol();
249 void toDt(dt_t **pdt);
250 void toDt2(dt_t **pdt, ClassDeclaration *cd);
252 Symbol *vtblsym;
254 ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; }
257 struct InterfaceDeclaration : ClassDeclaration
259 #if V2
260 int cpp; // !=0 if this is a C++ interface
261 #endif
262 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
263 Dsymbol *syntaxCopy(Dsymbol *s);
264 void semantic(Scope *sc);
265 int isBaseOf(ClassDeclaration *cd, target_ptrdiff_t *poffset);
266 int isBaseOf(BaseClass *bc, target_ptrdiff_t *poffset);
267 char *kind();
268 int vtblOffset();
269 #if V2
270 int isCPPinterface();
271 #endif
272 virtual int isCOMinterface();
274 void toObjFile(int multiobj); // compile to .obj file
275 Symbol *toSymbol();
277 InterfaceDeclaration *isInterfaceDeclaration() { return this; }
280 #endif /* DMD_AGGREGATE_H */