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