root/branches/dmdfe-2.0/aggregate.h

Revision 914, 7.9 kB (checked in by Gregor, 3 months ago)

MERGE: DMD 2.019

Line 
1 // Compiler implementation of the D programming language
2 // Copyright (c) 1999-2008 by Digital Mars
3 // All Rights Reserved
4 // written by Walter Bright
5 // http://www.digitalmars.com
6 // License for redistribution is by either the Artistic License
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
8 // See the included readme.txt for details.
9
10 #ifndef DMD_AGGREGATE_H
11 #define DMD_AGGREGATE_H
12
13 #ifdef __DMC__
14 #pragma once
15 #endif /* __DMC__ */
16
17 #include "root.h"
18 #include "dsymbol.h"
19
20 struct Identifier;
21 struct Type;
22 struct TypeFunction;
23 struct Expression;
24 struct FuncDeclaration;
25 struct CtorDeclaration;
26 struct DtorDeclaration;
27 struct InvariantDeclaration;
28 struct NewDeclaration;
29 struct DeleteDeclaration;
30 struct InterfaceDeclaration;
31 struct ClassInfoDeclaration;
32 struct VarDeclaration;
33 struct dt_t;
34
35
36 struct AggregateDeclaration : ScopeDsymbol
37 {
38     Type *type;
39     unsigned storage_class;
40     enum PROT protection;
41     Type *handle;       // 'this' type
42     unsigned structsize;    // size of struct
43     unsigned alignsize;     // size of struct for alignment purposes
44     unsigned structalign;   // struct member alignment in effect
45     int hasUnions;      // set if aggregate has overlapping fields
46     Array fields;       // VarDeclaration fields
47     unsigned sizeok;        // set when structsize contains valid data
48                 // 0: no size
49                 // 1: size is correct
50                 // 2: cannot determine size; fwd referenced
51     int isdeprecated;       // !=0 if deprecated
52     Scope *scope;       // !=NULL means context to use
53
54     // Special member functions
55     InvariantDeclaration *inv;      // invariant
56     NewDeclaration *aggNew;     // allocator
57     DeleteDeclaration *aggDelete;   // deallocator
58
59 #if V2
60     CtorDeclaration *ctor;
61     CtorDeclaration *defaultCtor;   // default constructor
62 #endif
63
64     FuncDeclarations dtors; // Array of destructors
65     FuncDeclaration *dtor;  // aggregate destructor
66
67 #ifdef IN_GCC
68     Array methods;              // flat list of all methods for debug information
69 #endif
70
71     AggregateDeclaration(Loc loc, Identifier *id);
72     void semantic2(Scope *sc);
73     void semantic3(Scope *sc);
74     void inlineScan();
75     unsigned size(Loc loc);
76     static void alignmember(unsigned salign, unsigned size, unsigned *poffset);
77     Type *getType();
78     void addField(Scope *sc, VarDeclaration *v);
79     int isDeprecated();     // is aggregate deprecated?
80     FuncDeclaration *buildDtor(Scope *sc);
81
82     void emitComment(Scope *sc);
83     void toDocBuffer(OutBuffer *buf);
84
85     // For access checking
86     virtual PROT getAccess(Dsymbol *smember);   // determine access to smember
87     int isFriendOf(AggregateDeclaration *cd);
88     int hasPrivateAccess(Dsymbol *smember); // does smember have private access to members of this class?
89     void accessCheck(Loc loc, Scope *sc, Dsymbol *smember);
90
91     enum PROT prot();
92
93     // Back end
94     Symbol *stag;       // tag symbol for debug data
95     Symbol *sinit;
96
97     AggregateDeclaration *isAggregateDeclaration() { return this; }
98 };
99
100 struct AnonymousAggregateDeclaration : AggregateDeclaration
101 {
102     AnonymousAggregateDeclaration()
103     : AggregateDeclaration(0, NULL)
104     {
105     }
106
107     AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; }
108 };
109
110 struct StructDeclaration : AggregateDeclaration
111 {
112     int zeroInit;       // !=0 if initialize with 0 fill
113 #if V2
114     int hasIdentityAssign;  // !=0 if has identity opAssign
115     FuncDeclaration *cpctor;    // generated copy-constructor, if any
116
117     FuncDeclarations postblits; // Array of postblit functions
118     FuncDeclaration *postblit;  // aggregate postblit
119 #endif
120
121     StructDeclaration(Loc loc, Identifier *id);
122     Dsymbol *syntaxCopy(Dsymbol *s);
123     void semantic(Scope *sc);
124     void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
125     char *mangle();
126     const char *kind();
127     int needOpAssign();
128     FuncDeclaration *buildOpAssign(Scope *sc);
129     FuncDeclaration *buildPostBlit(Scope *sc);
130     FuncDeclaration *buildCpCtor(Scope *sc);
131     void toDocBuffer(OutBuffer *buf);
132
133     PROT getAccess(Dsymbol *smember);   // determine access to smember
134
135     void toDebug();         // to symbolic debug info
136
137     StructDeclaration *isStructDeclaration() { return this; }
138 };
139
140 struct UnionDeclaration : StructDeclaration
141 {
142     UnionDeclaration(Loc loc, Identifier *id);
143     Dsymbol *syntaxCopy(Dsymbol *s);
144     const char *kind();
145
146     UnionDeclaration *isUnionDeclaration() { return this; }
147 };
148
149 struct BaseClass
150 {
151     Type *type;             // (before semantic processing)
152     enum PROT protection;       // protection for the base interface
153
154     ClassDeclaration *base;
155     int offset;             // 'this' pointer offset
156     Array vtbl;             // for interfaces: Array of FuncDeclaration's
157                     // making up the vtbl[]
158
159     int baseInterfaces_dim;
160     BaseClass *baseInterfaces;      // if BaseClass is an interface, these
161                     // are a copy of the InterfaceDeclaration::interfaces
162
163     BaseClass();
164     BaseClass(Type *type, enum PROT protection);
165
166     int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance);
167     void copyBaseInterfaces(BaseClasses *);
168 };
169
170 #if V2
171 #define CLASSINFO_SIZE  (0x3C+16)   // value of ClassInfo.size
172 #else
173 #define CLASSINFO_SIZE  (0x3C+12)   // value of ClassInfo.size
174 #endif
175
176 struct ClassDeclaration : AggregateDeclaration
177 {
178     static ClassDeclaration *object;
179     static ClassDeclaration *classinfo;
180
181     ClassDeclaration *baseClass;    // NULL only if this is Object
182     FuncDeclaration *staticCtor;
183     FuncDeclaration *staticDtor;
184     Array vtbl;             // Array of FuncDeclaration's making up the vtbl[]
185     Array vtblFinal;            // More FuncDeclaration's that aren't in vtbl[]
186
187     BaseClasses baseclasses;        // Array of BaseClass's; first is super,
188                     // rest are Interface's
189
190     int interfaces_dim;
191     BaseClass **interfaces;     // interfaces[interfaces_dim] for this class
192                     // (does not include baseClass)
193
194     BaseClasses *vtblInterfaces;    // array of base interfaces that have
195                     // their own vtbl[]
196
197     ClassInfoDeclaration *vclassinfo;   // the ClassInfo object for this ClassDeclaration
198     int com;                // !=0 if this is a COM class (meaning
199                     // it derives from IUnknown)
200     int isauto;             // !=0 if this is an auto class
201     int isabstract;         // !=0 if abstract class
202
203     int isnested;           // !=0 if is nested
204     VarDeclaration *vthis;      // 'this' parameter if this class is nested
205
206     int inuse;              // to prevent recursive attempts
207
208     ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
209     Dsymbol *syntaxCopy(Dsymbol *s);
210     void semantic(Scope *sc);
211     void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
212     int isBaseOf2(ClassDeclaration *cd);
213
214     #define OFFSET_RUNTIME 0x76543210
215     virtual int isBaseOf(ClassDeclaration *cd, int *poffset);
216
217     Dsymbol *search(Loc, Identifier *ident, int flags);
218 #if V2
219     int isFuncHidden(FuncDeclaration *fd);
220 #endif
221     FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf);
222     void interfaceSemantic(Scope *sc);
223     int isNested();
224     int isCOMclass();
225     virtual int isCOMinterface();
226 #if V2
227     virtual int isCPPinterface();
228 #endif
229     int isAbstract();
230     virtual int vtblOffset();
231     const char *kind();
232     char *mangle();
233     void toDocBuffer(OutBuffer *buf);
234
235     PROT getAccess(Dsymbol *smember);   // determine access to smember
236
237     void addLocalClass(ClassDeclarations *);
238
239     // Back end
240     void toDebug();
241     unsigned baseVtblOffset(BaseClass *bc);
242     Symbol *toVtblSymbol();
243     void toDt2(dt_t **pdt, ClassDeclaration *cd);
244
245     Symbol *vtblsym;
246
247     ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; }
248 };
249
250 struct InterfaceDeclaration : ClassDeclaration
251 {
252 #if V2
253     int cpp;                // !=0 if this is a C++ interface
254 #endif
255     InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
256     Dsymbol *syntaxCopy(Dsymbol *s);
257     void semantic(Scope *sc);
258     int isBaseOf(ClassDeclaration *cd, int *poffset);
259     int isBaseOf(BaseClass *bc, int *poffset);
260     const char *kind();
261     int vtblOffset();
262 #if V2
263     int isCPPinterface();
264 #endif
265     virtual int isCOMinterface();
266
267     InterfaceDeclaration *isInterfaceDeclaration() { return this; }
268 };
269
270 #endif /* DMD_AGGREGATE_H */
Note: See TracBrowser for help on using the browser.