Mercurial > projects > ldc
annotate dmd/aggregate.h @ 1611:3f728445fc42
Merge DMD r277: bugzilla 3495 Segfault(typinf.c) instantiating D variadic...
bugzilla 3495 Segfault(typinf.c) instantiating D variadic function with
too few arguments.
---
dmd/expression.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:21 -0300 |
parents | a413ae7329bf |
children | ae8a94d87ca9 |
rev | line source |
---|---|
159 | 1 |
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. | |
10 | |
11 #ifndef DMD_AGGREGATE_H | |
12 #define DMD_AGGREGATE_H | |
13 | |
14 #ifdef __DMC__ | |
15 #pragma once | |
16 #endif /* __DMC__ */ | |
17 | |
18 #include "root.h" | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
19 |
159 | 20 #include "dsymbol.h" |
21 | |
22 #include <vector> | |
23 #include <set> | |
24 #include <map> | |
25 | |
26 struct Identifier; | |
27 struct Type; | |
28 struct TypeFunction; | |
29 struct Expression; | |
30 struct FuncDeclaration; | |
31 struct CtorDeclaration; | |
32 struct DtorDeclaration; | |
33 struct InvariantDeclaration; | |
34 struct NewDeclaration; | |
35 struct DeleteDeclaration; | |
36 struct InterfaceDeclaration; | |
37 struct ClassInfoDeclaration; | |
38 struct VarDeclaration; | |
39 struct dt_t; | |
40 | |
41 namespace llvm | |
42 { | |
43 class Type; | |
44 class Value; | |
45 class Constant; | |
46 class ConstantStruct; | |
47 class GlobalVariable; | |
48 } | |
49 | |
50 struct AggregateDeclaration : ScopeDsymbol | |
51 { | |
52 Type *type; | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
53 StorageClass storage_class; |
159 | 54 enum PROT protection; |
55 Type *handle; // 'this' type | |
56 unsigned structsize; // size of struct | |
57 unsigned alignsize; // size of struct for alignment purposes | |
58 unsigned structalign; // struct member alignment in effect | |
59 int hasUnions; // set if aggregate has overlapping fields | |
60 Array fields; // VarDeclaration fields | |
61 unsigned sizeok; // set when structsize contains valid data | |
62 // 0: no size | |
63 // 1: size is correct | |
64 // 2: cannot determine size; fwd referenced | |
65 int isdeprecated; // !=0 if deprecated | |
66 | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
67 #if DMDV2 |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
68 int isnested; // !=0 if is nested |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
69 VarDeclaration *vthis; // 'this' parameter if this aggregate is nested |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
70 #endif |
159 | 71 // Special member functions |
72 InvariantDeclaration *inv; // invariant | |
73 NewDeclaration *aggNew; // allocator | |
74 DeleteDeclaration *aggDelete; // deallocator | |
75 | |
1587 | 76 #if DMDV2 |
77 //CtorDeclaration *ctor; | |
78 Dsymbol *ctor; // CtorDeclaration or TemplateDeclaration | |
79 CtorDeclaration *defaultCtor; // default constructor | |
80 Dsymbol *aliasthis; // forward unresolved lookups to aliasthis | |
81 #endif | |
82 | |
336 | 83 FuncDeclarations dtors; // Array of destructors |
84 FuncDeclaration *dtor; // aggregate destructor | |
85 | |
159 | 86 #ifdef IN_GCC |
87 Array methods; // flat list of all methods for debug information | |
88 #endif | |
89 | |
90 AggregateDeclaration(Loc loc, Identifier *id); | |
91 void semantic2(Scope *sc); | |
92 void semantic3(Scope *sc); | |
93 void inlineScan(); | |
94 unsigned size(Loc loc); | |
95 static void alignmember(unsigned salign, unsigned size, unsigned *poffset); | |
96 Type *getType(); | |
97 void addField(Scope *sc, VarDeclaration *v); | |
98 int isDeprecated(); // is aggregate deprecated? | |
99 FuncDeclaration *buildDtor(Scope *sc); | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
100 int isNested(); |
159 | 101 |
102 void emitComment(Scope *sc); | |
1587 | 103 void toJsonBuffer(OutBuffer *buf); |
159 | 104 void toDocBuffer(OutBuffer *buf); |
105 | |
106 // For access checking | |
107 virtual PROT getAccess(Dsymbol *smember); // determine access to smember | |
108 int isFriendOf(AggregateDeclaration *cd); | |
109 int hasPrivateAccess(Dsymbol *smember); // does smember have private access to members of this class? | |
110 void accessCheck(Loc loc, Scope *sc, Dsymbol *smember); | |
111 | |
112 enum PROT prot(); | |
113 | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
806
diff
changeset
|
114 #if IN_DMD |
159 | 115 // Back end |
116 Symbol *stag; // tag symbol for debug data | |
117 Symbol *sinit; | |
118 Symbol *toInitializer(); | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
806
diff
changeset
|
119 #endif |
159 | 120 |
121 AggregateDeclaration *isAggregateDeclaration() { return this; } | |
1482
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
122 |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
123 #if IN_LLVM |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
124 // Aggregates that wouldn't have gotten semantic3'ed if we weren't inlining set this flag. |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
125 bool availableExternally; |
d9c5f5a43403
Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
126 #endif |
159 | 127 }; |
128 | |
129 struct AnonymousAggregateDeclaration : AggregateDeclaration | |
130 { | |
131 AnonymousAggregateDeclaration() | |
132 : AggregateDeclaration(0, NULL) | |
133 { | |
134 } | |
135 | |
136 AnonymousAggregateDeclaration *isAnonymousAggregateDeclaration() { return this; } | |
137 }; | |
138 | |
139 struct StructDeclaration : AggregateDeclaration | |
140 { | |
141 int zeroInit; // !=0 if initialize with 0 fill | |
336 | 142 #if DMDV2 |
143 int hasIdentityAssign; // !=0 if has identity opAssign | |
144 FuncDeclaration *cpctor; // generated copy-constructor, if any | |
145 | |
146 FuncDeclarations postblits; // Array of postblit functions | |
147 FuncDeclaration *postblit; // aggregate postblit | |
148 #endif | |
159 | 149 |
150 StructDeclaration(Loc loc, Identifier *id); | |
151 Dsymbol *syntaxCopy(Dsymbol *s); | |
152 void semantic(Scope *sc); | |
153 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
154 char *mangle(); | |
336 | 155 const char *kind(); |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
156 #if DMDV1 |
159 | 157 Expression *cloneMembers(); |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
158 #endif |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
159 #if DMDV2 |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
160 int needOpAssign(); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
161 FuncDeclaration *buildOpAssign(Scope *sc); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
162 FuncDeclaration *buildPostBlit(Scope *sc); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
163 FuncDeclaration *buildCpCtor(Scope *sc); |
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
164 #endif |
159 | 165 void toDocBuffer(OutBuffer *buf); |
166 | |
167 PROT getAccess(Dsymbol *smember); // determine access to smember | |
168 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
169 #if IN_DMD |
336 | 170 void toObjFile(int multiobj); // compile to .obj file |
159 | 171 void toDt(dt_t **pdt); |
172 void toDebug(); // to symbolic debug info | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
173 #endif |
159 | 174 |
175 StructDeclaration *isStructDeclaration() { return this; } | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
176 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
177 #if IN_LLVM |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
178 void codegen(Ir*); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
179 #endif |
159 | 180 }; |
181 | |
182 struct UnionDeclaration : StructDeclaration | |
183 { | |
184 UnionDeclaration(Loc loc, Identifier *id); | |
185 Dsymbol *syntaxCopy(Dsymbol *s); | |
336 | 186 const char *kind(); |
159 | 187 |
188 UnionDeclaration *isUnionDeclaration() { return this; } | |
189 }; | |
190 | |
806
96b404ba7eb0
Move storage of final vtbl from BaseClass to IrInterface: BaseClass instances are shared!
Christian Kamm <kamm incasoftware de>
parents:
797
diff
changeset
|
191 // warning: two classes with the same base class share the same |
96b404ba7eb0
Move storage of final vtbl from BaseClass to IrInterface: BaseClass instances are shared!
Christian Kamm <kamm incasoftware de>
parents:
797
diff
changeset
|
192 // BaseClass instance. |
159 | 193 struct BaseClass |
194 { | |
195 Type *type; // (before semantic processing) | |
196 enum PROT protection; // protection for the base interface | |
197 | |
198 ClassDeclaration *base; | |
199 int offset; // 'this' pointer offset | |
200 Array vtbl; // for interfaces: Array of FuncDeclaration's | |
201 // making up the vtbl[] | |
202 | |
203 int baseInterfaces_dim; | |
204 BaseClass *baseInterfaces; // if BaseClass is an interface, these | |
205 // are a copy of the InterfaceDeclaration::interfaces | |
206 | |
207 BaseClass(); | |
208 BaseClass(Type *type, enum PROT protection); | |
209 | |
210 int fillVtbl(ClassDeclaration *cd, Array *vtbl, int newinstance); | |
211 void copyBaseInterfaces(BaseClasses *); | |
212 }; | |
213 | |
336 | 214 #if DMDV2 |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1147
diff
changeset
|
215 #define CLASSINFO_SIZE (0x3C+16+4) // value of ClassInfo.size |
159 | 216 #else |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1147
diff
changeset
|
217 #define CLASSINFO_SIZE (0x3C+12+4) // value of ClassInfo.size |
159 | 218 #endif |
219 | |
220 struct ClassDeclaration : AggregateDeclaration | |
221 { | |
222 static ClassDeclaration *object; | |
223 static ClassDeclaration *classinfo; | |
224 | |
225 ClassDeclaration *baseClass; // NULL only if this is Object | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
226 #if DMDV1 |
159 | 227 CtorDeclaration *ctor; |
228 CtorDeclaration *defaultCtor; // default constructor | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
229 #endif |
159 | 230 FuncDeclaration *staticCtor; |
231 FuncDeclaration *staticDtor; | |
232 Array vtbl; // Array of FuncDeclaration's making up the vtbl[] | |
233 Array vtblFinal; // More FuncDeclaration's that aren't in vtbl[] | |
234 | |
235 BaseClasses baseclasses; // Array of BaseClass's; first is super, | |
236 // rest are Interface's | |
237 | |
238 int interfaces_dim; | |
239 BaseClass **interfaces; // interfaces[interfaces_dim] for this class | |
240 // (does not include baseClass) | |
241 | |
242 BaseClasses *vtblInterfaces; // array of base interfaces that have | |
243 // their own vtbl[] | |
244 | |
245 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration | |
246 int com; // !=0 if this is a COM class (meaning | |
247 // it derives from IUnknown) | |
1530
05c235309d6f
Make the auto storage class never have the same meaning as scope.
Christian Kamm <kamm incasoftware de>
parents:
1482
diff
changeset
|
248 int isscope; // !=0 if this is a scope class |
159 | 249 int isabstract; // !=0 if abstract class |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
250 #if DMDV1 |
159 | 251 int isnested; // !=0 if is nested |
252 VarDeclaration *vthis; // 'this' parameter if this class is nested | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
253 #endif |
159 | 254 int inuse; // to prevent recursive attempts |
255 | |
256 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
257 Dsymbol *syntaxCopy(Dsymbol *s); | |
258 void semantic(Scope *sc); | |
259 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
260 int isBaseOf2(ClassDeclaration *cd); | |
261 | |
262 #define OFFSET_RUNTIME 0x76543210 | |
263 virtual int isBaseOf(ClassDeclaration *cd, int *poffset); | |
264 | |
265 Dsymbol *search(Loc, Identifier *ident, int flags); | |
336 | 266 #if DMDV2 |
159 | 267 int isFuncHidden(FuncDeclaration *fd); |
268 #endif | |
269 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); | |
270 void interfaceSemantic(Scope *sc); | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
271 #if DMDV1 |
159 | 272 int isNested(); |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
273 #endif |
159 | 274 int isCOMclass(); |
275 virtual int isCOMinterface(); | |
336 | 276 #if DMDV2 |
159 | 277 virtual int isCPPinterface(); |
278 #endif | |
279 int isAbstract(); | |
280 virtual int vtblOffset(); | |
336 | 281 const char *kind(); |
159 | 282 char *mangle(); |
283 void toDocBuffer(OutBuffer *buf); | |
284 | |
285 PROT getAccess(Dsymbol *smember); // determine access to smember | |
286 | |
287 void addLocalClass(ClassDeclarations *); | |
288 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
289 #if IN_DMD |
159 | 290 // Back end |
336 | 291 void toObjFile(int multiobj); // compile to .obj file |
159 | 292 void toDebug(); |
293 unsigned baseVtblOffset(BaseClass *bc); | |
294 Symbol *toSymbol(); | |
295 Symbol *toVtblSymbol(); | |
296 void toDt(dt_t **pdt); | |
297 void toDt2(dt_t **pdt, ClassDeclaration *cd); | |
298 | |
299 Symbol *vtblsym; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
806
diff
changeset
|
300 #endif |
159 | 301 |
302 ClassDeclaration *isClassDeclaration() { return (ClassDeclaration *)this; } | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
303 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
304 #if IN_LLVM |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
305 virtual void codegen(Ir*); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
306 #endif |
159 | 307 }; |
308 | |
309 struct InterfaceDeclaration : ClassDeclaration | |
310 { | |
336 | 311 #if DMDV2 |
159 | 312 int cpp; // !=0 if this is a C++ interface |
313 #endif | |
314 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); | |
315 Dsymbol *syntaxCopy(Dsymbol *s); | |
316 void semantic(Scope *sc); | |
317 int isBaseOf(ClassDeclaration *cd, int *poffset); | |
318 int isBaseOf(BaseClass *bc, int *poffset); | |
336 | 319 const char *kind(); |
159 | 320 int vtblOffset(); |
336 | 321 #if DMDV2 |
159 | 322 int isCPPinterface(); |
323 #endif | |
324 virtual int isCOMinterface(); | |
325 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
326 #if IN_DMD |
336 | 327 void toObjFile(int multiobj); // compile to .obj file |
159 | 328 Symbol *toSymbol(); |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
806
diff
changeset
|
329 #endif |
159 | 330 |
331 InterfaceDeclaration *isInterfaceDeclaration() { return this; } | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
332 |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
333 #if IN_LLVM |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
334 void codegen(Ir*); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
335 #endif |
159 | 336 }; |
337 | |
338 #endif /* DMD_AGGREGATE_H */ |