Mercurial > projects > ldc
annotate dmd/declaration.h @ 1621:fb2e6707ad17
Merge DMD r314+r315: bugzilla 2029 Typesafe variadic functions don't...
Both DMD revisions are for fixing bugzilla 2029 (Typesafe variadic
functions don't work in CTFE).
The DMD r314 commit message is:
bugzilla 2029 (Typesafe variadic functions don't work in CTFE
The DMD r315 commit message is:
bugzilla 2029 - try again
---
dmd/constfold.c | 11 ++++-
dmd/declaration.c | 21 +++++++++-
dmd/declaration.h | 10 ++++-
dmd/expression.c | 1 +
dmd/interpret.c | 111 +++++++++++++++++++++++++++++++++++++++++++++--------
dmd/mars.h | 2 +-
dmd/mtype.c | 2 +-
7 files changed, 135 insertions(+), 23 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:22 -0300 |
parents | c61782a76dff |
children | 44b145be2ef5 |
rev | line source |
---|---|
1587 | 1 |
2 // Compiler implementation of the D programming language | |
3 // Copyright (c) 1999-2009 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_DECLARATION_H | |
12 #define DMD_DECLARATION_H | |
13 | |
14 #ifdef __DMC__ | |
15 #pragma once | |
16 #endif /* __DMC__ */ | |
17 | |
18 #include <set> | |
19 #include <map> | |
20 #include <string> | |
21 | |
22 #include "dsymbol.h" | |
23 #include "lexer.h" | |
24 #include "mtype.h" | |
25 | |
26 struct Expression; | |
27 struct Statement; | |
28 struct LabelDsymbol; | |
29 struct LabelStatement; | |
30 struct Initializer; | |
31 struct Module; | |
32 struct InlineScanState; | |
33 struct ForeachStatement; | |
34 struct FuncDeclaration; | |
35 struct ExpInitializer; | |
36 struct StructDeclaration; | |
37 struct TupleType; | |
38 struct InterState; | |
39 struct IRState; | |
40 struct AnonDeclaration; | |
41 | |
42 enum PROT; | |
43 enum LINK; | |
44 enum TOK; | |
45 enum MATCH; | |
46 | |
47 enum STC | |
48 { | |
49 STCundefined = 0, | |
50 STCstatic = 1, | |
51 STCextern = 2, | |
52 STCconst = 4, | |
53 STCfinal = 8, | |
54 STCabstract = 0x10, | |
55 STCparameter = 0x20, | |
56 STCfield = 0x40, | |
57 STCoverride = 0x80, | |
58 STCauto = 0x100, | |
59 STCsynchronized = 0x200, | |
60 STCdeprecated = 0x400, | |
61 STCin = 0x800, // in parameter | |
62 STCout = 0x1000, // out parameter | |
63 STClazy = 0x2000, // lazy parameter | |
64 STCforeach = 0x4000, // variable for foreach loop | |
65 STCcomdat = 0x8000, // should go into COMDAT record | |
66 STCvariadic = 0x10000, // variadic function argument | |
67 STCctorinit = 0x20000, // can only be set inside constructor | |
68 STCtemplateparameter = 0x40000, // template parameter | |
69 STCscope = 0x80000, // template parameter | |
70 STCimmutable = 0x100000, | |
71 STCref = 0x200000, | |
72 STCinit = 0x400000, // has explicit initializer | |
73 STCmanifest = 0x800000, // manifest constant | |
74 STCnodtor = 0x1000000, // don't run destructor | |
75 STCnothrow = 0x2000000, // never throws exceptions | |
76 STCpure = 0x4000000, // pure function | |
77 STCtls = 0x8000000, // thread local | |
78 STCalias = 0x10000000, // alias parameter | |
79 STCshared = 0x20000000, // accessible from multiple threads | |
80 STCgshared = 0x40000000, // accessible from multiple threads | |
81 // but not typed as "shared" | |
1621
fb2e6707ad17
Merge DMD r314+r315: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
82 STCwild = 0x80000000, // for "wild" type constructor |
fb2e6707ad17
Merge DMD r314+r315: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
83 STC_TYPECTOR = (STCconst | STCimmutable | STCshared | STCwild), |
1587 | 84 }; |
85 | |
1621
fb2e6707ad17
Merge DMD r314+r315: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
86 #define STCproperty 0x100000000LL |
fb2e6707ad17
Merge DMD r314+r315: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
87 #define STCsafe 0x200000000LL |
fb2e6707ad17
Merge DMD r314+r315: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
88 #define STCtrusted 0x400000000LL |
fb2e6707ad17
Merge DMD r314+r315: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
89 #define STCsystem 0x800000000LL |
fb2e6707ad17
Merge DMD r314+r315: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
90 #define STCctfe 0x1000000000LL // can be used in CTFE, even if it is static |
fb2e6707ad17
Merge DMD r314+r315: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
91 |
1587 | 92 struct Match |
93 { | |
94 int count; // number of matches found | |
95 MATCH last; // match level of lastf | |
96 FuncDeclaration *lastf; // last matching function we found | |
97 FuncDeclaration *nextf; // current matching function | |
98 FuncDeclaration *anyf; // pick a func, any func, to use for error recovery | |
99 }; | |
100 | |
101 void overloadResolveX(Match *m, FuncDeclaration *f, | |
102 Expression *ethis, Expressions *arguments, Module *from); | |
103 int overloadApply(Module* from, FuncDeclaration *fstart, | |
104 int (*fp)(void *, FuncDeclaration *), | |
105 void *param); | |
106 | |
107 /**************************************************************/ | |
108 | |
109 struct Declaration : Dsymbol | |
110 { | |
111 Type *type; | |
112 Type *originalType; // before semantic analysis | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
113 StorageClass storage_class; |
1587 | 114 enum PROT protection; |
115 enum LINK linkage; | |
116 int inuse; // used to detect cycles | |
117 | |
118 Declaration(Identifier *id); | |
119 void semantic(Scope *sc); | |
120 const char *kind(); | |
121 unsigned size(Loc loc); | |
122 void checkModify(Loc loc, Scope *sc, Type *t); | |
123 | |
124 void emitComment(Scope *sc); | |
125 void toJsonBuffer(OutBuffer *buf); | |
126 void toDocBuffer(OutBuffer *buf); | |
127 | |
128 char *mangle(); | |
129 int isStatic() { return storage_class & STCstatic; } | |
130 virtual int isStaticConstructor(); | |
131 virtual int isStaticDestructor(); | |
132 virtual int isDelete(); | |
133 virtual int isDataseg(); | |
134 virtual int isThreadlocal(); | |
135 virtual int isCodeseg(); | |
136 int isCtorinit() { return storage_class & STCctorinit; } | |
137 int isFinal() { return storage_class & STCfinal; } | |
138 int isAbstract() { return storage_class & STCabstract; } | |
139 int isConst() { return storage_class & STCconst; } | |
1619
c61782a76dff
Merge DMD r304: refactor invariant => immutable
Leandro Lucarella <llucax@gmail.com>
parents:
1617
diff
changeset
|
140 int isImmutable() { return storage_class & STCimmutable; } |
1587 | 141 int isAuto() { return storage_class & STCauto; } |
142 int isScope() { return storage_class & STCscope; } | |
143 int isSynchronized() { return storage_class & STCsynchronized; } | |
144 int isParameter() { return storage_class & STCparameter; } | |
145 int isDeprecated() { return storage_class & STCdeprecated; } | |
146 int isOverride() { return storage_class & STCoverride; } | |
147 | |
148 virtual int isSameAsInitializer() { return isConst(); }; | |
149 | |
150 int isIn() { return storage_class & STCin; } | |
151 int isOut() { return storage_class & STCout; } | |
152 int isRef() { return storage_class & STCref; } | |
153 | |
154 enum PROT prot(); | |
155 | |
156 Declaration *isDeclaration() { return this; } | |
157 | |
158 #if IN_LLVM | |
159 /// Codegen traversal | |
160 virtual void codegen(Ir* ir); | |
161 #endif | |
162 }; | |
163 | |
164 /**************************************************************/ | |
165 | |
166 struct TupleDeclaration : Declaration | |
167 { | |
168 Objects *objects; | |
169 int isexp; // 1: expression tuple | |
170 | |
171 TypeTuple *tupletype; // !=NULL if this is a type tuple | |
172 | |
173 TupleDeclaration(Loc loc, Identifier *ident, Objects *objects); | |
174 Dsymbol *syntaxCopy(Dsymbol *); | |
175 const char *kind(); | |
176 Type *getType(); | |
177 int needThis(); | |
178 | |
179 TupleDeclaration *isTupleDeclaration() { return this; } | |
180 | |
181 #if IN_LLVM | |
182 /// Codegen traversal | |
183 void codegen(Ir* ir); | |
184 #endif | |
185 }; | |
186 | |
187 /**************************************************************/ | |
188 | |
189 struct TypedefDeclaration : Declaration | |
190 { | |
191 Type *basetype; | |
192 Initializer *init; | |
193 int sem; // 0: semantic() has not been run | |
194 // 1: semantic() is in progress | |
195 // 2: semantic() has been run | |
196 // 3: semantic2() has been run | |
197 | |
198 TypedefDeclaration(Loc loc, Identifier *ident, Type *basetype, Initializer *init); | |
199 Dsymbol *syntaxCopy(Dsymbol *); | |
200 void semantic(Scope *sc); | |
201 void semantic2(Scope *sc); | |
202 char *mangle(); | |
203 const char *kind(); | |
204 Type *getType(); | |
205 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
206 #ifdef _DH | |
207 Type *htype; | |
208 Type *hbasetype; | |
209 #endif | |
210 | |
211 void toDocBuffer(OutBuffer *buf); | |
212 | |
213 #if IN_DMD | |
214 void toObjFile(int multiobj); // compile to .obj file | |
215 void toDebug(); | |
216 int cvMember(unsigned char *p); | |
217 #endif | |
218 | |
219 TypedefDeclaration *isTypedefDeclaration() { return this; } | |
220 | |
221 #if IN_DMD | |
222 Symbol *sinit; | |
223 Symbol *toInitializer(); | |
224 #endif | |
225 | |
226 #if IN_LLVM | |
227 /// Codegen traversal | |
228 void codegen(Ir* ir); | |
229 #endif | |
230 }; | |
231 | |
232 /**************************************************************/ | |
233 | |
234 struct AliasDeclaration : Declaration | |
235 { | |
236 Dsymbol *aliassym; | |
237 Dsymbol *overnext; // next in overload list | |
238 int inSemantic; | |
239 PROT importprot; // if generated by import, store its protection | |
240 | |
241 AliasDeclaration(Loc loc, Identifier *ident, Type *type); | |
242 AliasDeclaration(Loc loc, Identifier *ident, Dsymbol *s); | |
243 Dsymbol *syntaxCopy(Dsymbol *); | |
244 void semantic(Scope *sc); | |
245 int overloadInsert(Dsymbol *s); | |
246 const char *kind(); | |
247 Type *getType(); | |
248 Dsymbol *toAlias(); | |
249 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
250 #ifdef _DH | |
251 Type *htype; | |
252 Dsymbol *haliassym; | |
253 #endif | |
254 | |
255 void toDocBuffer(OutBuffer *buf); | |
256 | |
257 AliasDeclaration *isAliasDeclaration() { return this; } | |
258 }; | |
259 | |
260 /**************************************************************/ | |
261 | |
262 struct VarDeclaration : Declaration | |
263 { | |
264 Initializer *init; | |
265 unsigned offset; | |
266 int noscope; // no scope semantics | |
267 #if DMDV2 | |
268 FuncDeclarations nestedrefs; // referenced by these lexically nested functions | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
269 bool isargptr; // if parameter that _argptr points to |
1587 | 270 #else |
271 int nestedref; // referenced by a lexically nested function | |
272 #endif | |
273 int ctorinit; // it has been initialized in a ctor | |
274 int onstack; // 1: it has been allocated on the stack | |
275 // 2: on stack, run destructor anyway | |
276 int canassign; // it can be assigned to | |
277 Dsymbol *aliassym; // if redone as alias to another symbol | |
278 Expression *value; // when interpreting, this is the value | |
279 // (NULL if value not determinable) | |
280 #if DMDV2 | |
281 VarDeclaration *rundtor; // if !NULL, rundtor is tested at runtime to see | |
282 // if the destructor should be run. Used to prevent | |
283 // dtor calls on postblitted vars | |
284 #endif | |
285 | |
286 VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init); | |
287 Dsymbol *syntaxCopy(Dsymbol *); | |
288 void semantic(Scope *sc); | |
289 void semantic2(Scope *sc); | |
290 const char *kind(); | |
291 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
292 #ifdef _DH | |
293 Type *htype; | |
294 Initializer *hinit; | |
295 #endif | |
296 int needThis(); | |
297 int isImportedSymbol(); | |
298 int isDataseg(); | |
299 int isThreadlocal(); | |
1621
fb2e6707ad17
Merge DMD r314+r315: bugzilla 2029 Typesafe variadic functions don't...
Leandro Lucarella <llucax@gmail.com>
parents:
1619
diff
changeset
|
300 int isCTFE(); |
1587 | 301 int hasPointers(); |
302 #if DMDV2 | |
303 int canTakeAddressOf(); | |
304 int needsAutoDtor(); | |
305 #endif | |
306 Expression *callScopeDtor(Scope *sc); | |
307 ExpInitializer *getExpInitializer(); | |
308 Expression *getConstInitializer(); | |
309 void checkCtorConstInit(); | |
310 void checkNestedReference(Scope *sc, Loc loc); | |
311 Dsymbol *toAlias(); | |
312 | |
313 virtual int isSameAsInitializer(); | |
314 | |
315 #if IN_DMD | |
316 void toObjFile(int multiobj); // compile to .obj file | |
317 Symbol *toSymbol(); | |
318 int cvMember(unsigned char *p); | |
319 #endif | |
320 | |
321 // Eliminate need for dynamic_cast | |
322 VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; } | |
323 | |
324 #if IN_LLVM | |
325 /// Codegen traversal | |
326 virtual void codegen(Ir* ir); | |
327 | |
328 /// Index into parent aggregate. | |
329 /// Set during type generation. | |
330 unsigned aggrIndex; | |
331 | |
332 /// Variables that wouldn't have gotten semantic3'ed if we weren't inlining set this flag. | |
333 bool availableExternally; | |
334 /// Override added to set above flag. | |
335 void semantic3(Scope *sc); | |
336 | |
337 // FIXME: we're not using these anymore! | |
338 AnonDeclaration* anonDecl; | |
339 unsigned offset2; | |
340 | |
341 /// This var is used by a naked function. | |
342 bool nakedUse; | |
343 #endif | |
344 }; | |
345 | |
346 /**************************************************************/ | |
347 | |
348 // LDC uses this to denote static struct initializers | |
349 | |
350 struct StaticStructInitDeclaration : Declaration | |
351 { | |
352 StructDeclaration *dsym; | |
353 | |
354 StaticStructInitDeclaration(Loc loc, StructDeclaration *dsym); | |
355 | |
356 #if IN_DMD | |
357 Symbol *toSymbol(); | |
358 #endif | |
359 | |
360 // Eliminate need for dynamic_cast | |
361 StaticStructInitDeclaration *isStaticStructInitDeclaration() { return (StaticStructInitDeclaration *)this; } | |
362 }; | |
363 | |
364 struct ClassInfoDeclaration : VarDeclaration | |
365 { | |
366 ClassDeclaration *cd; | |
367 | |
368 ClassInfoDeclaration(ClassDeclaration *cd); | |
369 Dsymbol *syntaxCopy(Dsymbol *); | |
370 void semantic(Scope *sc); | |
371 | |
372 void emitComment(Scope *sc); | |
373 void toJsonBuffer(OutBuffer *buf); | |
374 | |
375 #if IN_DMD | |
376 Symbol *toSymbol(); | |
377 #endif | |
378 | |
379 ClassInfoDeclaration* isClassInfoDeclaration() { return this; } | |
380 }; | |
381 | |
382 struct ModuleInfoDeclaration : VarDeclaration | |
383 { | |
384 Module *mod; | |
385 | |
386 ModuleInfoDeclaration(Module *mod); | |
387 Dsymbol *syntaxCopy(Dsymbol *); | |
388 void semantic(Scope *sc); | |
389 | |
390 void emitComment(Scope *sc); | |
391 void toJsonBuffer(OutBuffer *buf); | |
392 | |
393 #if IN_DMD | |
394 Symbol *toSymbol(); | |
395 #endif | |
396 }; | |
397 | |
398 struct TypeInfoDeclaration : VarDeclaration | |
399 { | |
400 Type *tinfo; | |
401 | |
402 TypeInfoDeclaration(Type *tinfo, int internal); | |
403 Dsymbol *syntaxCopy(Dsymbol *); | |
404 void semantic(Scope *sc); | |
405 | |
406 void emitComment(Scope *sc); | |
407 void toJsonBuffer(OutBuffer *buf); | |
408 | |
409 #if IN_DMD | |
410 void toObjFile(int multiobj); // compile to .obj file | |
411 Symbol *toSymbol(); | |
412 virtual void toDt(dt_t **pdt); | |
413 #endif | |
414 | |
415 virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return this; } | |
416 | |
417 #if IN_LLVM | |
418 /// Codegen traversal | |
419 void codegen(Ir* ir); | |
420 virtual void llvmDefine(); | |
421 #endif | |
422 }; | |
423 | |
424 struct TypeInfoStructDeclaration : TypeInfoDeclaration | |
425 { | |
426 TypeInfoStructDeclaration(Type *tinfo); | |
427 | |
428 #if IN_DMD | |
429 void toDt(dt_t **pdt); | |
430 #endif | |
431 | |
432 #if IN_LLVM | |
433 void llvmDefine(); | |
434 #endif | |
435 }; | |
436 | |
437 struct TypeInfoClassDeclaration : TypeInfoDeclaration | |
438 { | |
439 TypeInfoClassDeclaration(Type *tinfo); | |
440 | |
441 #if IN_DMD | |
442 void toDt(dt_t **pdt); | |
443 #endif | |
444 | |
445 #if IN_LLVM | |
446 void llvmDefine(); | |
447 #endif | |
448 }; | |
449 | |
450 struct TypeInfoInterfaceDeclaration : TypeInfoDeclaration | |
451 { | |
452 TypeInfoInterfaceDeclaration(Type *tinfo); | |
453 | |
454 #if IN_DMD | |
455 void toDt(dt_t **pdt); | |
456 #endif | |
457 | |
458 #if IN_LLVM | |
459 void llvmDefine(); | |
460 #endif | |
461 }; | |
462 | |
463 struct TypeInfoTypedefDeclaration : TypeInfoDeclaration | |
464 { | |
465 TypeInfoTypedefDeclaration(Type *tinfo); | |
466 | |
467 #if IN_DMD | |
468 void toDt(dt_t **pdt); | |
469 #endif | |
470 | |
471 #if IN_LLVM | |
472 void llvmDefine(); | |
473 #endif | |
474 }; | |
475 | |
476 struct TypeInfoPointerDeclaration : TypeInfoDeclaration | |
477 { | |
478 TypeInfoPointerDeclaration(Type *tinfo); | |
479 | |
480 #if IN_DMD | |
481 void toDt(dt_t **pdt); | |
482 #endif | |
483 | |
484 #if IN_LLVM | |
485 void llvmDefine(); | |
486 #endif | |
487 }; | |
488 | |
489 struct TypeInfoArrayDeclaration : TypeInfoDeclaration | |
490 { | |
491 TypeInfoArrayDeclaration(Type *tinfo); | |
492 | |
493 #if IN_DMD | |
494 void toDt(dt_t **pdt); | |
495 #endif | |
496 | |
497 #if IN_LLVM | |
498 void llvmDefine(); | |
499 #endif | |
500 }; | |
501 | |
502 struct TypeInfoStaticArrayDeclaration : TypeInfoDeclaration | |
503 { | |
504 TypeInfoStaticArrayDeclaration(Type *tinfo); | |
505 | |
506 #if IN_DMD | |
507 void toDt(dt_t **pdt); | |
508 #endif | |
509 | |
510 #if IN_LLVM | |
511 void llvmDefine(); | |
512 #endif | |
513 }; | |
514 | |
515 struct TypeInfoAssociativeArrayDeclaration : TypeInfoDeclaration | |
516 { | |
517 TypeInfoAssociativeArrayDeclaration(Type *tinfo); | |
518 | |
519 #if IN_DMD | |
520 void toDt(dt_t **pdt); | |
521 #endif | |
522 | |
523 #if IN_LLVM | |
524 void llvmDefine(); | |
525 #endif | |
526 }; | |
527 | |
528 struct TypeInfoEnumDeclaration : TypeInfoDeclaration | |
529 { | |
530 TypeInfoEnumDeclaration(Type *tinfo); | |
531 | |
532 #if IN_DMD | |
533 void toDt(dt_t **pdt); | |
534 #endif | |
535 | |
536 #if IN_LLVM | |
537 void llvmDefine(); | |
538 #endif | |
539 }; | |
540 | |
541 struct TypeInfoFunctionDeclaration : TypeInfoDeclaration | |
542 { | |
543 TypeInfoFunctionDeclaration(Type *tinfo); | |
544 | |
545 #if IN_DMD | |
546 void toDt(dt_t **pdt); | |
547 #endif | |
548 | |
549 #if IN_LLVM | |
550 void llvmDefine(); | |
551 #endif | |
552 }; | |
553 | |
554 struct TypeInfoDelegateDeclaration : TypeInfoDeclaration | |
555 { | |
556 TypeInfoDelegateDeclaration(Type *tinfo); | |
557 | |
558 #if IN_DMD | |
559 void toDt(dt_t **pdt); | |
560 #endif | |
561 | |
562 #if IN_LLVM | |
563 void llvmDefine(); | |
564 #endif | |
565 }; | |
566 | |
567 struct TypeInfoTupleDeclaration : TypeInfoDeclaration | |
568 { | |
569 TypeInfoTupleDeclaration(Type *tinfo); | |
570 | |
571 #if IN_DMD | |
572 void toDt(dt_t **pdt); | |
573 #endif | |
574 | |
575 #if IN_LLVM | |
576 void llvmDefine(); | |
577 #endif | |
578 }; | |
579 | |
580 #if DMDV2 | |
581 struct TypeInfoConstDeclaration : TypeInfoDeclaration | |
582 { | |
583 TypeInfoConstDeclaration(Type *tinfo); | |
584 | |
585 #if IN_DMD | |
586 void toDt(dt_t **pdt); | |
587 #endif | |
588 | |
589 #if IN_LLVM | |
590 void llvmDefine(); | |
591 #endif | |
592 }; | |
593 | |
594 struct TypeInfoInvariantDeclaration : TypeInfoDeclaration | |
595 { | |
596 TypeInfoInvariantDeclaration(Type *tinfo); | |
597 | |
598 #if IN_DMD | |
599 void toDt(dt_t **pdt); | |
600 #endif | |
601 | |
602 #if IN_LLVM | |
603 void llvmDefine(); | |
604 #endif | |
605 }; | |
606 | |
607 struct TypeInfoSharedDeclaration : TypeInfoDeclaration | |
608 { | |
609 TypeInfoSharedDeclaration(Type *tinfo); | |
610 | |
611 void toDt(dt_t **pdt); | |
612 }; | |
613 #endif | |
614 | |
615 /**************************************************************/ | |
616 | |
617 struct ThisDeclaration : VarDeclaration | |
618 { | |
619 ThisDeclaration(Loc loc, Type *t); | |
620 Dsymbol *syntaxCopy(Dsymbol *); | |
621 ThisDeclaration *isThisDeclaration() { return this; } | |
622 }; | |
623 | |
624 enum ILS | |
625 { | |
626 ILSuninitialized, // not computed yet | |
627 ILSno, // cannot inline | |
628 ILSyes, // can inline | |
629 }; | |
630 | |
631 /**************************************************************/ | |
632 #if DMDV2 | |
633 | |
634 enum BUILTIN | |
635 { | |
636 BUILTINunknown = -1, // not known if this is a builtin | |
637 BUILTINnot, // this is not a builtin | |
638 BUILTINsin, // std.math.sin | |
639 BUILTINcos, // std.math.cos | |
640 BUILTINtan, // std.math.tan | |
641 BUILTINsqrt, // std.math.sqrt | |
642 BUILTINfabs, // std.math.fabs | |
643 }; | |
644 | |
645 Expression *eval_builtin(enum BUILTIN builtin, Expressions *arguments); | |
646 | |
647 #else | |
648 enum BUILTIN { }; | |
649 #endif | |
650 | |
651 struct FuncDeclaration : Declaration | |
652 { | |
653 Array *fthrows; // Array of Type's of exceptions (not used) | |
654 Statement *frequire; | |
655 Statement *fensure; | |
656 Statement *fbody; | |
657 | |
658 FuncDeclarations foverrides; // functions this function overrides | |
659 FuncDeclaration *fdrequire; // function that does the in contract | |
660 FuncDeclaration *fdensure; // function that does the out contract | |
661 | |
662 Identifier *outId; // identifier for out statement | |
663 VarDeclaration *vresult; // variable corresponding to outId | |
664 LabelDsymbol *returnLabel; // where the return goes | |
665 | |
666 DsymbolTable *localsymtab; // used to prevent symbols in different | |
667 // scopes from having the same name | |
668 VarDeclaration *vthis; // 'this' parameter (member and nested) | |
669 VarDeclaration *v_arguments; // '_arguments' parameter | |
670 #if IN_GCC | |
671 VarDeclaration *v_argptr; // '_argptr' variable | |
672 #endif | |
673 Dsymbols *parameters; // Array of VarDeclaration's for parameters | |
674 DsymbolTable *labtab; // statement label symbol table | |
675 Declaration *overnext; // next in overload list | |
676 Loc endloc; // location of closing curly bracket | |
677 int vtblIndex; // for member functions, index into vtbl[] | |
678 int naked; // !=0 if naked | |
679 int inlineAsm; // !=0 if has inline assembler | |
680 ILS inlineStatus; | |
681 int inlineNest; // !=0 if nested inline | |
682 int cantInterpret; // !=0 if cannot interpret function | |
683 int semanticRun; // 1 semantic() run | |
684 // 2 semantic2() run | |
685 // 3 semantic3() started | |
686 // 4 semantic3() done | |
687 // 5 toObjFile() run | |
688 // this function's frame ptr | |
689 ForeachStatement *fes; // if foreach body, this is the foreach | |
690 int introducing; // !=0 if 'introducing' function | |
691 Type *tintro; // if !=NULL, then this is the type | |
692 // of the 'introducing' function | |
693 // this one is overriding | |
694 int inferRetType; // !=0 if return type is to be inferred | |
695 | |
696 // Things that should really go into Scope | |
697 int hasReturnExp; // 1 if there's a return exp; statement | |
698 // 2 if there's a throw statement | |
699 // 4 if there's an assert(0) | |
700 // 8 if there's inline asm | |
701 | |
702 // Support for NRVO (named return value optimization) | |
703 int nrvo_can; // !=0 means we can do it | |
704 VarDeclaration *nrvo_var; // variable to replace with shidden | |
705 #if IN_DMD | |
706 Symbol *shidden; // hidden pointer passed to function | |
707 #endif | |
708 | |
709 #if DMDV2 | |
710 enum BUILTIN builtin; // set if this is a known, builtin | |
711 // function we can evaluate at compile | |
712 // time | |
713 | |
714 int tookAddressOf; // set if someone took the address of | |
715 // this function | |
716 Dsymbols closureVars; // local variables in this function | |
717 // which are referenced by nested | |
718 // functions | |
719 #else | |
720 int nestedFrameRef; // !=0 if nested variables referenced | |
721 #endif | |
722 | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
723 FuncDeclaration(Loc loc, Loc endloc, Identifier *id, StorageClass storage_class, Type *type); |
1587 | 724 Dsymbol *syntaxCopy(Dsymbol *); |
725 void semantic(Scope *sc); | |
726 void semantic2(Scope *sc); | |
727 void semantic3(Scope *sc); | |
728 // called from semantic3 | |
729 void varArgs(Scope *sc, TypeFunction*, VarDeclaration *&, VarDeclaration *&); | |
730 | |
731 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
732 void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
733 int overrides(FuncDeclaration *fd); | |
734 int findVtblIndex(Array *vtbl, int dim); | |
735 int overloadInsert(Dsymbol *s); | |
736 FuncDeclaration *overloadExactMatch(Type *t, Module* from); | |
737 FuncDeclaration *overloadResolve(Loc loc, Expression *ethis, Expressions *arguments, Module *from, int flags = 0); | |
738 MATCH leastAsSpecialized(FuncDeclaration *g); | |
739 LabelDsymbol *searchLabel(Identifier *ident); | |
740 AggregateDeclaration *isThis(); | |
741 AggregateDeclaration *isMember2(); | |
742 int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference | |
743 void appendExp(Expression *e); | |
744 void appendState(Statement *s); | |
745 char *mangle(); | |
746 const char *toPrettyChars(); | |
747 int isMain(); | |
748 int isWinMain(); | |
749 int isDllMain(); | |
750 enum BUILTIN isBuiltin(); | |
751 int isExport(); | |
752 int isImportedSymbol(); | |
753 int isAbstract(); | |
754 int isCodeseg(); | |
755 int isOverloadable(); | |
756 int isPure(); | |
757 virtual int isNested(); | |
758 int needThis(); | |
759 virtual int isVirtual(); | |
760 virtual int isFinal(); | |
761 virtual int addPreInvariant(); | |
762 virtual int addPostInvariant(); | |
763 Expression *interpret(InterState *istate, Expressions *arguments, Expression *thisexp = NULL); | |
764 void inlineScan(); | |
765 int canInline(int hasthis, int hdrscan = 0); | |
766 Expression *doInline(InlineScanState *iss, Expression *ethis, Array *arguments); | |
767 const char *kind(); | |
768 void toDocBuffer(OutBuffer *buf); | |
769 FuncDeclaration *isUnique(); | |
770 int needsClosure(); | |
771 Statement *mergeFrequire(Statement *); | |
772 Statement *mergeFensure(Statement *); | |
1617
6820110de311
Merge DMD r301: a little refactor and harmonize
Leandro Lucarella <llucax@gmail.com>
parents:
1607
diff
changeset
|
773 Parameters *getParameters(int *pvarargs); |
1587 | 774 |
775 // LDC: give argument types to runtime functions | |
1607
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1602
diff
changeset
|
776 static FuncDeclaration *genCfunc(Parameters *args, Type *treturn, const char *name); |
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1602
diff
changeset
|
777 static FuncDeclaration *genCfunc(Parameters *args, Type *treturn, Identifier *id); |
1587 | 778 |
779 #if IN_DMD | |
780 Symbol *toSymbol(); | |
781 Symbol *toThunkSymbol(int offset); // thunk version | |
782 void toObjFile(int multiobj); // compile to .obj file | |
783 int cvMember(unsigned char *p); | |
784 void buildClosure(IRState *irs); | |
785 #endif | |
786 | |
787 FuncDeclaration *isFuncDeclaration() { return this; } | |
788 | |
789 #if IN_LLVM | |
790 // LDC stuff | |
791 | |
792 /// Codegen traversal | |
793 void codegen(Ir* ir); | |
794 | |
795 // vars declared in this function that nested funcs reference | |
796 // is this is not empty, nestedFrameRef is set and these VarDecls | |
797 // probably have nestedref set too, see VarDeclaration::checkNestedReference | |
798 std::set<VarDeclaration*> nestedVars; | |
799 | |
800 std::string intrinsicName; | |
801 | |
802 bool isIntrinsic(); | |
803 bool isVaIntrinsic(); | |
804 | |
805 // we keep our own table of label statements as LabelDsymbolS | |
806 // don't always carry their corresponding statement along ... | |
807 typedef std::map<const char*, LabelStatement*> LabelMap; | |
808 LabelMap labmap; | |
809 | |
810 // if this is an array operation it gets a little special attention | |
811 bool isArrayOp; | |
812 | |
813 // Functions that wouldn't have gotten semantic3'ed if we weren't inlining set this flag. | |
814 bool availableExternally; | |
815 | |
816 // true if overridden with the pragma(allow_inline); stmt | |
817 bool allowInlining; | |
818 #endif | |
819 }; | |
820 | |
821 #if DMDV2 | |
822 FuncDeclaration *resolveFuncCall(Scope *sc, Loc loc, Dsymbol *s, | |
823 Objects *tiargs, | |
824 Expression *ethis, | |
825 Expressions *arguments, | |
826 int flags); | |
827 #endif | |
828 | |
829 struct FuncAliasDeclaration : FuncDeclaration | |
830 { | |
831 FuncDeclaration *funcalias; | |
832 PROT importprot; // if generated by import, store its protection | |
833 | |
834 FuncAliasDeclaration(FuncDeclaration *funcalias); | |
835 | |
836 FuncAliasDeclaration *isFuncAliasDeclaration() { return this; } | |
837 const char *kind(); | |
838 #if IN_DMD | |
839 Symbol *toSymbol(); | |
840 #endif | |
841 }; | |
842 | |
843 struct FuncLiteralDeclaration : FuncDeclaration | |
844 { | |
845 enum TOK tok; // TOKfunction or TOKdelegate | |
846 | |
847 FuncLiteralDeclaration(Loc loc, Loc endloc, Type *type, enum TOK tok, | |
848 ForeachStatement *fes); | |
849 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
850 Dsymbol *syntaxCopy(Dsymbol *); | |
851 int isNested(); | |
852 int isVirtual(); | |
853 | |
854 FuncLiteralDeclaration *isFuncLiteralDeclaration() { return this; } | |
855 const char *kind(); | |
856 }; | |
857 | |
858 struct CtorDeclaration : FuncDeclaration | |
1607
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1602
diff
changeset
|
859 { Parameters *arguments; |
1587 | 860 int varargs; |
861 | |
1607
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1602
diff
changeset
|
862 CtorDeclaration(Loc loc, Loc endloc, Parameters *arguments, int varargs); |
1587 | 863 Dsymbol *syntaxCopy(Dsymbol *); |
864 void semantic(Scope *sc); | |
865 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
866 const char *kind(); | |
867 char *toChars(); | |
868 int isVirtual(); | |
869 int addPreInvariant(); | |
870 int addPostInvariant(); | |
871 void toDocBuffer(OutBuffer *buf); | |
872 | |
873 CtorDeclaration *isCtorDeclaration() { return this; } | |
874 }; | |
875 | |
876 #if DMDV2 | |
877 struct PostBlitDeclaration : FuncDeclaration | |
878 { | |
879 PostBlitDeclaration(Loc loc, Loc endloc); | |
880 PostBlitDeclaration(Loc loc, Loc endloc, Identifier *id); | |
881 Dsymbol *syntaxCopy(Dsymbol *); | |
882 void semantic(Scope *sc); | |
883 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
884 int isVirtual(); | |
885 int addPreInvariant(); | |
886 int addPostInvariant(); | |
887 int overloadInsert(Dsymbol *s); | |
888 void emitComment(Scope *sc); | |
889 void toJsonBuffer(OutBuffer *buf); | |
890 | |
891 PostBlitDeclaration *isPostBlitDeclaration() { return this; } | |
892 }; | |
893 #endif | |
894 | |
895 struct DtorDeclaration : FuncDeclaration | |
896 { | |
897 DtorDeclaration(Loc loc, Loc endloc); | |
898 DtorDeclaration(Loc loc, Loc endloc, Identifier *id); | |
899 Dsymbol *syntaxCopy(Dsymbol *); | |
900 void semantic(Scope *sc); | |
901 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
902 const char *kind(); | |
903 char *toChars(); | |
904 int isVirtual(); | |
905 int addPreInvariant(); | |
906 int addPostInvariant(); | |
907 int overloadInsert(Dsymbol *s); | |
908 void emitComment(Scope *sc); | |
909 void toJsonBuffer(OutBuffer *buf); | |
910 | |
911 DtorDeclaration *isDtorDeclaration() { return this; } | |
912 }; | |
913 | |
914 struct StaticCtorDeclaration : FuncDeclaration | |
915 { | |
916 StaticCtorDeclaration(Loc loc, Loc endloc); | |
917 Dsymbol *syntaxCopy(Dsymbol *); | |
918 void semantic(Scope *sc); | |
919 AggregateDeclaration *isThis(); | |
920 int isStaticConstructor(); | |
921 int isVirtual(); | |
922 int addPreInvariant(); | |
923 int addPostInvariant(); | |
924 void emitComment(Scope *sc); | |
925 void toJsonBuffer(OutBuffer *buf); | |
926 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
927 | |
928 StaticCtorDeclaration *isStaticCtorDeclaration() { return this; } | |
929 }; | |
930 | |
931 struct StaticDtorDeclaration : FuncDeclaration | |
932 { VarDeclaration *vgate; // 'gate' variable | |
933 | |
934 StaticDtorDeclaration(Loc loc, Loc endloc); | |
935 Dsymbol *syntaxCopy(Dsymbol *); | |
936 void semantic(Scope *sc); | |
937 AggregateDeclaration *isThis(); | |
938 int isStaticDestructor(); | |
939 int isVirtual(); | |
940 int addPreInvariant(); | |
941 int addPostInvariant(); | |
942 void emitComment(Scope *sc); | |
943 void toJsonBuffer(OutBuffer *buf); | |
944 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
945 | |
946 StaticDtorDeclaration *isStaticDtorDeclaration() { return this; } | |
947 }; | |
948 | |
949 struct InvariantDeclaration : FuncDeclaration | |
950 { | |
951 InvariantDeclaration(Loc loc, Loc endloc); | |
952 Dsymbol *syntaxCopy(Dsymbol *); | |
953 void semantic(Scope *sc); | |
954 int isVirtual(); | |
955 int addPreInvariant(); | |
956 int addPostInvariant(); | |
957 void emitComment(Scope *sc); | |
958 void toJsonBuffer(OutBuffer *buf); | |
959 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
960 | |
961 InvariantDeclaration *isInvariantDeclaration() { return this; } | |
962 }; | |
963 | |
964 | |
965 struct UnitTestDeclaration : FuncDeclaration | |
966 { | |
967 UnitTestDeclaration(Loc loc, Loc endloc); | |
968 Dsymbol *syntaxCopy(Dsymbol *); | |
969 void semantic(Scope *sc); | |
970 AggregateDeclaration *isThis(); | |
971 int isVirtual(); | |
972 int addPreInvariant(); | |
973 int addPostInvariant(); | |
974 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
975 | |
976 UnitTestDeclaration *isUnitTestDeclaration() { return this; } | |
977 }; | |
978 | |
979 struct NewDeclaration : FuncDeclaration | |
1607
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1602
diff
changeset
|
980 { Parameters *arguments; |
1587 | 981 int varargs; |
982 | |
1607
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1602
diff
changeset
|
983 NewDeclaration(Loc loc, Loc endloc, Parameters *arguments, int varargs); |
1587 | 984 Dsymbol *syntaxCopy(Dsymbol *); |
985 void semantic(Scope *sc); | |
986 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
987 const char *kind(); | |
988 int isVirtual(); | |
989 int addPreInvariant(); | |
990 int addPostInvariant(); | |
991 | |
992 NewDeclaration *isNewDeclaration() { return this; } | |
993 }; | |
994 | |
995 | |
996 struct DeleteDeclaration : FuncDeclaration | |
1607
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1602
diff
changeset
|
997 { Parameters *arguments; |
1587 | 998 |
1607
207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
Leandro Lucarella <llucax@gmail.com>
parents:
1602
diff
changeset
|
999 DeleteDeclaration(Loc loc, Loc endloc, Parameters *arguments); |
1587 | 1000 Dsymbol *syntaxCopy(Dsymbol *); |
1001 void semantic(Scope *sc); | |
1002 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
1003 const char *kind(); | |
1004 int isDelete(); | |
1005 int isVirtual(); | |
1006 int addPreInvariant(); | |
1007 int addPostInvariant(); | |
1008 #ifdef _DH | |
1009 DeleteDeclaration *isDeleteDeclaration() { return this; } | |
1010 #endif | |
1011 }; | |
1012 | |
1013 #endif /* DMD_DECLARATION_H */ |