Fixed some lexing problems with DOS line-endings
[delight/core.git] / dmd / aggregate.h
blob79c6162b0a01d1e5cdba90a32c445c81a8cfbfd7
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 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);
147 char *kind();
149 UnionDeclaration *isUnionDeclaration() { return this; }
152 struct BaseClass
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
166 BaseClass();
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
191 int interfaces_dim;
192 BaseClass **interfaces; // interfaces[interfaces_dim] for this class
193 // (does not include baseClass)
195 BaseClasses *vtblInterfaces; // array of base interfaces that have
196 // their own vtbl[]
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);
219 #if V2
220 int isFuncHidden(FuncDeclaration *fd);
221 #endif
222 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf);
223 void interfaceSemantic(Scope *sc);
224 int isNested();
225 int isCOMclass();
226 virtual int isCOMinterface();
227 #if V2
228 virtual int isCPPinterface();
229 #endif
230 int isAbstract();
231 virtual int vtblOffset();
232 char *kind();
233 char *mangle();
234 void toDocBuffer(OutBuffer *buf);
236 PROT getAccess(Dsymbol *smember); // determine access to smember
238 void addLocalClass(ClassDeclarations *);
240 // Back end
241 void toObjFile(int multiobj); // compile to .obj file
242 void toDebug();
243 unsigned baseVtblOffset(BaseClass *bc);
244 Symbol *toSymbol();
245 Symbol *toVtblSymbol();
246 void toDt(dt_t **pdt);
247 void toDt2(dt_t **pdt, ClassDeclaration *cd);
249 Symbol *vtblsym;
251 ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; }
254 struct InterfaceDeclaration : ClassDeclaration
256 #if V2
257 int cpp; // !=0 if this is a C++ interface
258 #endif
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);
264 char *kind();
265 int vtblOffset();
266 #if V2
267 int isCPPinterface();
268 #endif
269 virtual int isCOMinterface();
271 void toObjFile(int multiobj); // compile to .obj file
272 Symbol *toSymbol();
274 InterfaceDeclaration *isInterfaceDeclaration() { return this; }
277 #endif /* DMD_AGGREGATE_H */