2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2008 by Digital Mars
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
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
;
43 struct AggregateDeclaration
: ScopeDsymbol
46 unsigned storage_class
;
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
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
71 Array methods
; // flat list of all methods for debug information
74 AggregateDeclaration(Loc loc
, Identifier
*id
);
75 void semantic2(Scope
*sc
);
76 void semantic3(Scope
*sc
);
78 target_size_t
size(Loc loc
);
79 static void alignmember(target_size_t salign
, target_size_t size
, target_size_t
*poffset
);
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
);
97 Symbol
*stag
; // tag symbol for debug data
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
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
125 StructDeclaration(Loc loc
, Identifier
*id
);
126 Dsymbol
*syntaxCopy(Dsymbol
*s
);
127 void semantic(Scope
*sc
);
128 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
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
);
152 UnionDeclaration
*isUnionDeclaration() { return this; }
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
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
195 BaseClass
**interfaces
; // interfaces[interfaces_dim] for this class
196 // (does not include baseClass)
198 BaseClasses
*vtblInterfaces
; // array of base interfaces that have
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
);
223 int isFuncHidden(FuncDeclaration
*fd
);
225 FuncDeclaration
*findFunc(Identifier
*ident
, TypeFunction
*tf
);
226 void interfaceSemantic(Scope
*sc
);
229 virtual int isCOMinterface();
231 virtual int isCPPinterface();
234 virtual int vtblOffset();
237 void toDocBuffer(OutBuffer
*buf
);
239 PROT
getAccess(Dsymbol
*smember
); // determine access to smember
241 void addLocalClass(ClassDeclarations
*);
244 void toObjFile(int multiobj
); // compile to .obj file
246 unsigned baseVtblOffset(BaseClass
*bc
);
248 Symbol
*toVtblSymbol();
249 void toDt(dt_t
**pdt
);
250 void toDt2(dt_t
**pdt
, ClassDeclaration
*cd
);
254 ClassDeclaration
*isClassDeclaration() { return (ClassDeclaration
*)this; }
257 struct InterfaceDeclaration
: ClassDeclaration
260 int cpp
; // !=0 if this is a C++ interface
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
);
270 int isCPPinterface();
272 virtual int isCOMinterface();
274 void toObjFile(int multiobj
); // compile to .obj file
277 InterfaceDeclaration
*isInterfaceDeclaration() { return this; }
280 #endif /* DMD_AGGREGATE_H */