root/trunk/src/aggregate.h

Revision 873, 10.0 kB (checked in by walter, 1 year ago)

bugzilla 5447 Should be illegal to throw a non-Throwable

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