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
);
131 Expression
*cloneMembers();
132 void toDocBuffer(OutBuffer
*buf
);
134 PROT
getAccess(Dsymbol
*smember
); // determine access to smember
136 void toObjFile(int multiobj
); // compile to .obj file
137 void toDt(dt_t
**pdt
);
138 void toDebug(); // to symbolic debug info
140 StructDeclaration
*isStructDeclaration() { return this; }
143 struct UnionDeclaration
: StructDeclaration
145 UnionDeclaration(Loc loc
, Identifier
*id
);
146 Dsymbol
*syntaxCopy(Dsymbol
*s
);
149 UnionDeclaration
*isUnionDeclaration() { return this; }
154 Type
*type
; // (before semantic processing)
155 enum PROT protection
; // protection for the base interface
157 ClassDeclaration
*base
;
158 target_ptrdiff_t offset
; // 'this' pointer offset
159 Array vtbl
; // for interfaces: Array of FuncDeclaration's
160 // making up the vtbl[]
162 int baseInterfaces_dim
;
163 BaseClass
*baseInterfaces
; // if BaseClass is an interface, these
164 // are a copy of the InterfaceDeclaration::interfaces
167 BaseClass(Type
*type
, enum PROT protection
);
169 int fillVtbl(ClassDeclaration
*cd
, Array
*vtbl
, int newinstance
);
170 void copyBaseInterfaces(BaseClasses
*);
173 extern int CLASSINFO_SIZE
; // value of ClassInfo.size
175 struct ClassDeclaration
: AggregateDeclaration
177 static ClassDeclaration
*object
;
178 static ClassDeclaration
*classinfo
;
180 ClassDeclaration
*baseClass
; // NULL only if this is Object
181 CtorDeclaration
*ctor
;
182 CtorDeclaration
*defaultCtor
; // default constructor
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[]
188 BaseClasses baseclasses
; // Array of BaseClass's; first is super,
189 // rest are Interface's
192 BaseClass
**interfaces
; // interfaces[interfaces_dim] for this class
193 // (does not include baseClass)
195 BaseClasses
*vtblInterfaces
; // array of base interfaces that have
198 ClassInfoDeclaration
*vclassinfo
; // the ClassInfo object for this ClassDeclaration
199 int com
; // !=0 if this is a COM class (meaning
200 // it derives from IUnknown)
201 int isauto
; // !=0 if this is an auto class
202 int isabstract
; // !=0 if abstract class
204 int isnested
; // !=0 if is nested
205 VarDeclaration
*vthis
; // 'this' parameter if this class is nested
207 int inuse
; // to prevent recursive attempts
209 ClassDeclaration(Loc loc
, Identifier
*id
, BaseClasses
*baseclasses
);
210 Dsymbol
*syntaxCopy(Dsymbol
*s
);
211 void semantic(Scope
*sc
);
212 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
213 int isBaseOf2(ClassDeclaration
*cd
);
215 #define OFFSET_RUNTIME 0x76543210
216 virtual int isBaseOf(ClassDeclaration
*cd
, target_ptrdiff_t
*poffset
);
218 Dsymbol
*search(Loc
, Identifier
*ident
, int flags
);
220 int isFuncHidden(FuncDeclaration
*fd
);
222 FuncDeclaration
*findFunc(Identifier
*ident
, TypeFunction
*tf
);
223 void interfaceSemantic(Scope
*sc
);
226 virtual int isCOMinterface();
228 virtual int isCPPinterface();
231 virtual int vtblOffset();
234 void toDocBuffer(OutBuffer
*buf
);
236 PROT
getAccess(Dsymbol
*smember
); // determine access to smember
238 void addLocalClass(ClassDeclarations
*);
241 void toObjFile(int multiobj
); // compile to .obj file
243 unsigned baseVtblOffset(BaseClass
*bc
);
245 Symbol
*toVtblSymbol();
246 void toDt(dt_t
**pdt
);
247 void toDt2(dt_t
**pdt
, ClassDeclaration
*cd
);
251 ClassDeclaration
*isClassDeclaration() { return (ClassDeclaration
*)this; }
254 struct InterfaceDeclaration
: ClassDeclaration
257 int cpp
; // !=0 if this is a C++ interface
259 InterfaceDeclaration(Loc loc
, Identifier
*id
, BaseClasses
*baseclasses
);
260 Dsymbol
*syntaxCopy(Dsymbol
*s
);
261 void semantic(Scope
*sc
);
262 int isBaseOf(ClassDeclaration
*cd
, target_ptrdiff_t
*poffset
);
263 int isBaseOf(BaseClass
*bc
, target_ptrdiff_t
*poffset
);
267 int isCPPinterface();
269 virtual int isCOMinterface();
271 void toObjFile(int multiobj
); // compile to .obj file
274 InterfaceDeclaration
*isInterfaceDeclaration() { return this; }
277 #endif /* DMD_AGGREGATE_H */