Mercurial > projects > ldc
annotate dmd/declaration.h @ 1607:207a8a438dea
Merge DMD r253: refactor: Argument => Parameter
---
dmd/arrayop.c | 30 ++++----
dmd/arraytypes.h | 2 +-
dmd/class.c | 8 +-
dmd/declaration.c | 10 ++--
dmd/declaration.h | 16 ++--
dmd/doc.c | 12 ++--
dmd/dsymbol.c | 4 +-
dmd/expression.c | 48 +++++++-------
dmd/expression.h | 32 +++++-----
dmd/func.c | 78 +++++++++++-----------
dmd/init.c | 2 +-
dmd/interpret.c | 8 +-
dmd/mtype.c | 190 ++++++++++++++++++++++++++--------------------------
dmd/mtype.h | 32 +++++-----
dmd/opover.c | 34 +++++-----
dmd/parse.c | 40 ++++++------
dmd/parse.h | 2 +-
dmd/statement.c | 90 +++++++++++++-------------
dmd/statement.h | 14 ++--
dmd/struct.c | 8 +-
dmd/template.c | 30 ++++----
gen/functions.cpp | 10 ++--
gen/functions.h | 2 +-
gen/tocall.cpp | 10 ++--
gen/typinf.cpp | 6 +-
25 files changed, 359 insertions(+), 359 deletions(-)
author | Leandro Lucarella <llucax@gmail.com> |
---|---|
date | Wed, 06 Jan 2010 15:18:20 -0300 |
parents | a413ae7329bf |
children | 6820110de311 |
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 STCinvariant = 0x100000, | |
71 STCimmutable = 0x100000, | |
72 STCref = 0x200000, | |
73 STCinit = 0x400000, // has explicit initializer | |
74 STCmanifest = 0x800000, // manifest constant | |
75 STCnodtor = 0x1000000, // don't run destructor | |
76 STCnothrow = 0x2000000, // never throws exceptions | |
77 STCpure = 0x4000000, // pure function | |
78 STCtls = 0x8000000, // thread local | |
79 STCalias = 0x10000000, // alias parameter | |
80 STCshared = 0x20000000, // accessible from multiple threads | |
81 STCgshared = 0x40000000, // accessible from multiple threads | |
82 // but not typed as "shared" | |
83 STC_TYPECTOR = (STCconst | STCimmutable | STCshared), | |
84 }; | |
85 | |
86 struct Match | |
87 { | |
88 int count; // number of matches found | |
89 MATCH last; // match level of lastf | |
90 FuncDeclaration *lastf; // last matching function we found | |
91 FuncDeclaration *nextf; // current matching function | |
92 FuncDeclaration *anyf; // pick a func, any func, to use for error recovery | |
93 }; | |
94 | |
95 void overloadResolveX(Match *m, FuncDeclaration *f, | |
96 Expression *ethis, Expressions *arguments, Module *from); | |
97 int overloadApply(Module* from, FuncDeclaration *fstart, | |
98 int (*fp)(void *, FuncDeclaration *), | |
99 void *param); | |
100 | |
101 /**************************************************************/ | |
102 | |
103 struct Declaration : Dsymbol | |
104 { | |
105 Type *type; | |
106 Type *originalType; // before semantic analysis | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
107 StorageClass storage_class; |
1587 | 108 enum PROT protection; |
109 enum LINK linkage; | |
110 int inuse; // used to detect cycles | |
111 | |
112 Declaration(Identifier *id); | |
113 void semantic(Scope *sc); | |
114 const char *kind(); | |
115 unsigned size(Loc loc); | |
116 void checkModify(Loc loc, Scope *sc, Type *t); | |
117 | |
118 void emitComment(Scope *sc); | |
119 void toJsonBuffer(OutBuffer *buf); | |
120 void toDocBuffer(OutBuffer *buf); | |
121 | |
122 char *mangle(); | |
123 int isStatic() { return storage_class & STCstatic; } | |
124 virtual int isStaticConstructor(); | |
125 virtual int isStaticDestructor(); | |
126 virtual int isDelete(); | |
127 virtual int isDataseg(); | |
128 virtual int isThreadlocal(); | |
129 virtual int isCodeseg(); | |
130 int isCtorinit() { return storage_class & STCctorinit; } | |
131 int isFinal() { return storage_class & STCfinal; } | |
132 int isAbstract() { return storage_class & STCabstract; } | |
133 int isConst() { return storage_class & STCconst; } | |
134 int isInvariant() { return storage_class & STCinvariant; } | |
135 int isAuto() { return storage_class & STCauto; } | |
136 int isScope() { return storage_class & STCscope; } | |
137 int isSynchronized() { return storage_class & STCsynchronized; } | |
138 int isParameter() { return storage_class & STCparameter; } | |
139 int isDeprecated() { return storage_class & STCdeprecated; } | |
140 int isOverride() { return storage_class & STCoverride; } | |
141 | |
142 virtual int isSameAsInitializer() { return isConst(); }; | |
143 | |
144 int isIn() { return storage_class & STCin; } | |
145 int isOut() { return storage_class & STCout; } | |
146 int isRef() { return storage_class & STCref; } | |
147 | |
148 enum PROT prot(); | |
149 | |
150 Declaration *isDeclaration() { return this; } | |
151 | |
152 #if IN_LLVM | |
153 /// Codegen traversal | |
154 virtual void codegen(Ir* ir); | |
155 #endif | |
156 }; | |
157 | |
158 /**************************************************************/ | |
159 | |
160 struct TupleDeclaration : Declaration | |
161 { | |
162 Objects *objects; | |
163 int isexp; // 1: expression tuple | |
164 | |
165 TypeTuple *tupletype; // !=NULL if this is a type tuple | |
166 | |
167 TupleDeclaration(Loc loc, Identifier *ident, Objects *objects); | |
168 Dsymbol *syntaxCopy(Dsymbol *); | |
169 const char *kind(); | |
170 Type *getType(); | |
171 int needThis(); | |
172 | |
173 TupleDeclaration *isTupleDeclaration() { return this; } | |
174 | |
175 #if IN_LLVM | |
176 /// Codegen traversal | |
177 void codegen(Ir* ir); | |
178 #endif | |
179 }; | |
180 | |
181 /**************************************************************/ | |
182 | |
183 struct TypedefDeclaration : Declaration | |
184 { | |
185 Type *basetype; | |
186 Initializer *init; | |
187 int sem; // 0: semantic() has not been run | |
188 // 1: semantic() is in progress | |
189 // 2: semantic() has been run | |
190 // 3: semantic2() has been run | |
191 | |
192 TypedefDeclaration(Loc loc, Identifier *ident, Type *basetype, Initializer *init); | |
193 Dsymbol *syntaxCopy(Dsymbol *); | |
194 void semantic(Scope *sc); | |
195 void semantic2(Scope *sc); | |
196 char *mangle(); | |
197 const char *kind(); | |
198 Type *getType(); | |
199 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
200 #ifdef _DH | |
201 Type *htype; | |
202 Type *hbasetype; | |
203 #endif | |
204 | |
205 void toDocBuffer(OutBuffer *buf); | |
206 | |
207 #if IN_DMD | |
208 void toObjFile(int multiobj); // compile to .obj file | |
209 void toDebug(); | |
210 int cvMember(unsigned char *p); | |
211 #endif | |
212 | |
213 TypedefDeclaration *isTypedefDeclaration() { return this; } | |
214 | |
215 #if IN_DMD | |
216 Symbol *sinit; | |
217 Symbol *toInitializer(); | |
218 #endif | |
219 | |
220 #if IN_LLVM | |
221 /// Codegen traversal | |
222 void codegen(Ir* ir); | |
223 #endif | |
224 }; | |
225 | |
226 /**************************************************************/ | |
227 | |
228 struct AliasDeclaration : Declaration | |
229 { | |
230 Dsymbol *aliassym; | |
231 Dsymbol *overnext; // next in overload list | |
232 int inSemantic; | |
233 PROT importprot; // if generated by import, store its protection | |
234 | |
235 AliasDeclaration(Loc loc, Identifier *ident, Type *type); | |
236 AliasDeclaration(Loc loc, Identifier *ident, Dsymbol *s); | |
237 Dsymbol *syntaxCopy(Dsymbol *); | |
238 void semantic(Scope *sc); | |
239 int overloadInsert(Dsymbol *s); | |
240 const char *kind(); | |
241 Type *getType(); | |
242 Dsymbol *toAlias(); | |
243 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
244 #ifdef _DH | |
245 Type *htype; | |
246 Dsymbol *haliassym; | |
247 #endif | |
248 | |
249 void toDocBuffer(OutBuffer *buf); | |
250 | |
251 AliasDeclaration *isAliasDeclaration() { return this; } | |
252 }; | |
253 | |
254 /**************************************************************/ | |
255 | |
256 struct VarDeclaration : Declaration | |
257 { | |
258 Initializer *init; | |
259 unsigned offset; | |
260 int noscope; // no scope semantics | |
261 #if DMDV2 | |
262 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
|
263 bool isargptr; // if parameter that _argptr points to |
1587 | 264 #else |
265 int nestedref; // referenced by a lexically nested function | |
266 #endif | |
267 int ctorinit; // it has been initialized in a ctor | |
268 int onstack; // 1: it has been allocated on the stack | |
269 // 2: on stack, run destructor anyway | |
270 int canassign; // it can be assigned to | |
271 Dsymbol *aliassym; // if redone as alias to another symbol | |
272 Expression *value; // when interpreting, this is the value | |
273 // (NULL if value not determinable) | |
274 #if DMDV2 | |
275 VarDeclaration *rundtor; // if !NULL, rundtor is tested at runtime to see | |
276 // if the destructor should be run. Used to prevent | |
277 // dtor calls on postblitted vars | |
278 #endif | |
279 | |
280 VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init); | |
281 Dsymbol *syntaxCopy(Dsymbol *); | |
282 void semantic(Scope *sc); | |
283 void semantic2(Scope *sc); | |
284 const char *kind(); | |
285 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
286 #ifdef _DH | |
287 Type *htype; | |
288 Initializer *hinit; | |
289 #endif | |
290 int needThis(); | |
291 int isImportedSymbol(); | |
292 int isDataseg(); | |
293 int isThreadlocal(); | |
294 int hasPointers(); | |
295 #if DMDV2 | |
296 int canTakeAddressOf(); | |
297 int needsAutoDtor(); | |
298 #endif | |
299 Expression *callScopeDtor(Scope *sc); | |
300 ExpInitializer *getExpInitializer(); | |
301 Expression *getConstInitializer(); | |
302 void checkCtorConstInit(); | |
303 void checkNestedReference(Scope *sc, Loc loc); | |
304 Dsymbol *toAlias(); | |
305 | |
306 virtual int isSameAsInitializer(); | |
307 | |
308 #if IN_DMD | |
309 void toObjFile(int multiobj); // compile to .obj file | |
310 Symbol *toSymbol(); | |
311 int cvMember(unsigned char *p); | |
312 #endif | |
313 | |
314 // Eliminate need for dynamic_cast | |
315 VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; } | |
316 | |
317 #if IN_LLVM | |
318 /// Codegen traversal | |
319 virtual void codegen(Ir* ir); | |
320 | |
321 /// Index into parent aggregate. | |
322 /// Set during type generation. | |
323 unsigned aggrIndex; | |
324 | |
325 /// Variables that wouldn't have gotten semantic3'ed if we weren't inlining set this flag. | |
326 bool availableExternally; | |
327 /// Override added to set above flag. | |
328 void semantic3(Scope *sc); | |
329 | |
330 // FIXME: we're not using these anymore! | |
331 AnonDeclaration* anonDecl; | |
332 unsigned offset2; | |
333 | |
334 /// This var is used by a naked function. | |
335 bool nakedUse; | |
336 #endif | |
337 }; | |
338 | |
339 /**************************************************************/ | |
340 | |
341 // LDC uses this to denote static struct initializers | |
342 | |
343 struct StaticStructInitDeclaration : Declaration | |
344 { | |
345 StructDeclaration *dsym; | |
346 | |
347 StaticStructInitDeclaration(Loc loc, StructDeclaration *dsym); | |
348 | |
349 #if IN_DMD | |
350 Symbol *toSymbol(); | |
351 #endif | |
352 | |
353 // Eliminate need for dynamic_cast | |
354 StaticStructInitDeclaration *isStaticStructInitDeclaration() { return (StaticStructInitDeclaration *)this; } | |
355 }; | |
356 | |
357 struct ClassInfoDeclaration : VarDeclaration | |
358 { | |
359 ClassDeclaration *cd; | |
360 | |
361 ClassInfoDeclaration(ClassDeclaration *cd); | |
362 Dsymbol *syntaxCopy(Dsymbol *); | |
363 void semantic(Scope *sc); | |
364 | |
365 void emitComment(Scope *sc); | |
366 void toJsonBuffer(OutBuffer *buf); | |
367 | |
368 #if IN_DMD | |
369 Symbol *toSymbol(); | |
370 #endif | |
371 | |
372 ClassInfoDeclaration* isClassInfoDeclaration() { return this; } | |
373 }; | |
374 | |
375 struct ModuleInfoDeclaration : VarDeclaration | |
376 { | |
377 Module *mod; | |
378 | |
379 ModuleInfoDeclaration(Module *mod); | |
380 Dsymbol *syntaxCopy(Dsymbol *); | |
381 void semantic(Scope *sc); | |
382 | |
383 void emitComment(Scope *sc); | |
384 void toJsonBuffer(OutBuffer *buf); | |
385 | |
386 #if IN_DMD | |
387 Symbol *toSymbol(); | |
388 #endif | |
389 }; | |
390 | |
391 struct TypeInfoDeclaration : VarDeclaration | |
392 { | |
393 Type *tinfo; | |
394 | |
395 TypeInfoDeclaration(Type *tinfo, int internal); | |
396 Dsymbol *syntaxCopy(Dsymbol *); | |
397 void semantic(Scope *sc); | |
398 | |
399 void emitComment(Scope *sc); | |
400 void toJsonBuffer(OutBuffer *buf); | |
401 | |
402 #if IN_DMD | |
403 void toObjFile(int multiobj); // compile to .obj file | |
404 Symbol *toSymbol(); | |
405 virtual void toDt(dt_t **pdt); | |
406 #endif | |
407 | |
408 virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return this; } | |
409 | |
410 #if IN_LLVM | |
411 /// Codegen traversal | |
412 void codegen(Ir* ir); | |
413 virtual void llvmDefine(); | |
414 #endif | |
415 }; | |
416 | |
417 struct TypeInfoStructDeclaration : TypeInfoDeclaration | |
418 { | |
419 TypeInfoStructDeclaration(Type *tinfo); | |
420 | |
421 #if IN_DMD | |
422 void toDt(dt_t **pdt); | |
423 #endif | |
424 | |
425 #if IN_LLVM | |
426 void llvmDefine(); | |
427 #endif | |
428 }; | |
429 | |
430 struct TypeInfoClassDeclaration : TypeInfoDeclaration | |
431 { | |
432 TypeInfoClassDeclaration(Type *tinfo); | |
433 | |
434 #if IN_DMD | |
435 void toDt(dt_t **pdt); | |
436 #endif | |
437 | |
438 #if IN_LLVM | |
439 void llvmDefine(); | |
440 #endif | |
441 }; | |
442 | |
443 struct TypeInfoInterfaceDeclaration : TypeInfoDeclaration | |
444 { | |
445 TypeInfoInterfaceDeclaration(Type *tinfo); | |
446 | |
447 #if IN_DMD | |
448 void toDt(dt_t **pdt); | |
449 #endif | |
450 | |
451 #if IN_LLVM | |
452 void llvmDefine(); | |
453 #endif | |
454 }; | |
455 | |
456 struct TypeInfoTypedefDeclaration : TypeInfoDeclaration | |
457 { | |
458 TypeInfoTypedefDeclaration(Type *tinfo); | |
459 | |
460 #if IN_DMD | |
461 void toDt(dt_t **pdt); | |
462 #endif | |
463 | |
464 #if IN_LLVM | |
465 void llvmDefine(); | |
466 #endif | |
467 }; | |
468 | |
469 struct TypeInfoPointerDeclaration : TypeInfoDeclaration | |
470 { | |
471 TypeInfoPointerDeclaration(Type *tinfo); | |
472 | |
473 #if IN_DMD | |
474 void toDt(dt_t **pdt); | |
475 #endif | |
476 | |
477 #if IN_LLVM | |
478 void llvmDefine(); | |
479 #endif | |
480 }; | |
481 | |
482 struct TypeInfoArrayDeclaration : TypeInfoDeclaration | |
483 { | |
484 TypeInfoArrayDeclaration(Type *tinfo); | |
485 | |
486 #if IN_DMD | |
487 void toDt(dt_t **pdt); | |
488 #endif | |
489 | |
490 #if IN_LLVM | |
491 void llvmDefine(); | |
492 #endif | |
493 }; | |
494 | |
495 struct TypeInfoStaticArrayDeclaration : TypeInfoDeclaration | |
496 { | |
497 TypeInfoStaticArrayDeclaration(Type *tinfo); | |
498 | |
499 #if IN_DMD | |
500 void toDt(dt_t **pdt); | |
501 #endif | |
502 | |
503 #if IN_LLVM | |
504 void llvmDefine(); | |
505 #endif | |
506 }; | |
507 | |
508 struct TypeInfoAssociativeArrayDeclaration : TypeInfoDeclaration | |
509 { | |
510 TypeInfoAssociativeArrayDeclaration(Type *tinfo); | |
511 | |
512 #if IN_DMD | |
513 void toDt(dt_t **pdt); | |
514 #endif | |
515 | |
516 #if IN_LLVM | |
517 void llvmDefine(); | |
518 #endif | |
519 }; | |
520 | |
521 struct TypeInfoEnumDeclaration : TypeInfoDeclaration | |
522 { | |
523 TypeInfoEnumDeclaration(Type *tinfo); | |
524 | |
525 #if IN_DMD | |
526 void toDt(dt_t **pdt); | |
527 #endif | |
528 | |
529 #if IN_LLVM | |
530 void llvmDefine(); | |
531 #endif | |
532 }; | |
533 | |
534 struct TypeInfoFunctionDeclaration : TypeInfoDeclaration | |
535 { | |
536 TypeInfoFunctionDeclaration(Type *tinfo); | |
537 | |
538 #if IN_DMD | |
539 void toDt(dt_t **pdt); | |
540 #endif | |
541 | |
542 #if IN_LLVM | |
543 void llvmDefine(); | |
544 #endif | |
545 }; | |
546 | |
547 struct TypeInfoDelegateDeclaration : TypeInfoDeclaration | |
548 { | |
549 TypeInfoDelegateDeclaration(Type *tinfo); | |
550 | |
551 #if IN_DMD | |
552 void toDt(dt_t **pdt); | |
553 #endif | |
554 | |
555 #if IN_LLVM | |
556 void llvmDefine(); | |
557 #endif | |
558 }; | |
559 | |
560 struct TypeInfoTupleDeclaration : TypeInfoDeclaration | |
561 { | |
562 TypeInfoTupleDeclaration(Type *tinfo); | |
563 | |
564 #if IN_DMD | |
565 void toDt(dt_t **pdt); | |
566 #endif | |
567 | |
568 #if IN_LLVM | |
569 void llvmDefine(); | |
570 #endif | |
571 }; | |
572 | |
573 #if DMDV2 | |
574 struct TypeInfoConstDeclaration : TypeInfoDeclaration | |
575 { | |
576 TypeInfoConstDeclaration(Type *tinfo); | |
577 | |
578 #if IN_DMD | |
579 void toDt(dt_t **pdt); | |
580 #endif | |
581 | |
582 #if IN_LLVM | |
583 void llvmDefine(); | |
584 #endif | |
585 }; | |
586 | |
587 struct TypeInfoInvariantDeclaration : TypeInfoDeclaration | |
588 { | |
589 TypeInfoInvariantDeclaration(Type *tinfo); | |
590 | |
591 #if IN_DMD | |
592 void toDt(dt_t **pdt); | |
593 #endif | |
594 | |
595 #if IN_LLVM | |
596 void llvmDefine(); | |
597 #endif | |
598 }; | |
599 | |
600 struct TypeInfoSharedDeclaration : TypeInfoDeclaration | |
601 { | |
602 TypeInfoSharedDeclaration(Type *tinfo); | |
603 | |
604 void toDt(dt_t **pdt); | |
605 }; | |
606 #endif | |
607 | |
608 /**************************************************************/ | |
609 | |
610 struct ThisDeclaration : VarDeclaration | |
611 { | |
612 ThisDeclaration(Loc loc, Type *t); | |
613 Dsymbol *syntaxCopy(Dsymbol *); | |
614 ThisDeclaration *isThisDeclaration() { return this; } | |
615 }; | |
616 | |
617 enum ILS | |
618 { | |
619 ILSuninitialized, // not computed yet | |
620 ILSno, // cannot inline | |
621 ILSyes, // can inline | |
622 }; | |
623 | |
624 /**************************************************************/ | |
625 #if DMDV2 | |
626 | |
627 enum BUILTIN | |
628 { | |
629 BUILTINunknown = -1, // not known if this is a builtin | |
630 BUILTINnot, // this is not a builtin | |
631 BUILTINsin, // std.math.sin | |
632 BUILTINcos, // std.math.cos | |
633 BUILTINtan, // std.math.tan | |
634 BUILTINsqrt, // std.math.sqrt | |
635 BUILTINfabs, // std.math.fabs | |
636 }; | |
637 | |
638 Expression *eval_builtin(enum BUILTIN builtin, Expressions *arguments); | |
639 | |
640 #else | |
641 enum BUILTIN { }; | |
642 #endif | |
643 | |
644 struct FuncDeclaration : Declaration | |
645 { | |
646 Array *fthrows; // Array of Type's of exceptions (not used) | |
647 Statement *frequire; | |
648 Statement *fensure; | |
649 Statement *fbody; | |
650 | |
651 FuncDeclarations foverrides; // functions this function overrides | |
652 FuncDeclaration *fdrequire; // function that does the in contract | |
653 FuncDeclaration *fdensure; // function that does the out contract | |
654 | |
655 Identifier *outId; // identifier for out statement | |
656 VarDeclaration *vresult; // variable corresponding to outId | |
657 LabelDsymbol *returnLabel; // where the return goes | |
658 | |
659 DsymbolTable *localsymtab; // used to prevent symbols in different | |
660 // scopes from having the same name | |
661 VarDeclaration *vthis; // 'this' parameter (member and nested) | |
662 VarDeclaration *v_arguments; // '_arguments' parameter | |
663 #if IN_GCC | |
664 VarDeclaration *v_argptr; // '_argptr' variable | |
665 #endif | |
666 Dsymbols *parameters; // Array of VarDeclaration's for parameters | |
667 DsymbolTable *labtab; // statement label symbol table | |
668 Declaration *overnext; // next in overload list | |
669 Loc endloc; // location of closing curly bracket | |
670 int vtblIndex; // for member functions, index into vtbl[] | |
671 int naked; // !=0 if naked | |
672 int inlineAsm; // !=0 if has inline assembler | |
673 ILS inlineStatus; | |
674 int inlineNest; // !=0 if nested inline | |
675 int cantInterpret; // !=0 if cannot interpret function | |
676 int semanticRun; // 1 semantic() run | |
677 // 2 semantic2() run | |
678 // 3 semantic3() started | |
679 // 4 semantic3() done | |
680 // 5 toObjFile() run | |
681 // this function's frame ptr | |
682 ForeachStatement *fes; // if foreach body, this is the foreach | |
683 int introducing; // !=0 if 'introducing' function | |
684 Type *tintro; // if !=NULL, then this is the type | |
685 // of the 'introducing' function | |
686 // this one is overriding | |
687 int inferRetType; // !=0 if return type is to be inferred | |
688 | |
689 // Things that should really go into Scope | |
690 int hasReturnExp; // 1 if there's a return exp; statement | |
691 // 2 if there's a throw statement | |
692 // 4 if there's an assert(0) | |
693 // 8 if there's inline asm | |
694 | |
695 // Support for NRVO (named return value optimization) | |
696 int nrvo_can; // !=0 means we can do it | |
697 VarDeclaration *nrvo_var; // variable to replace with shidden | |
698 #if IN_DMD | |
699 Symbol *shidden; // hidden pointer passed to function | |
700 #endif | |
701 | |
702 #if DMDV2 | |
703 enum BUILTIN builtin; // set if this is a known, builtin | |
704 // function we can evaluate at compile | |
705 // time | |
706 | |
707 int tookAddressOf; // set if someone took the address of | |
708 // this function | |
709 Dsymbols closureVars; // local variables in this function | |
710 // which are referenced by nested | |
711 // functions | |
712 #else | |
713 int nestedFrameRef; // !=0 if nested variables referenced | |
714 #endif | |
715 | |
1602
a413ae7329bf
Merge DMD r243: some harmonization with D2 dmd
Leandro Lucarella <llucax@gmail.com>
parents:
1587
diff
changeset
|
716 FuncDeclaration(Loc loc, Loc endloc, Identifier *id, StorageClass storage_class, Type *type); |
1587 | 717 Dsymbol *syntaxCopy(Dsymbol *); |
718 void semantic(Scope *sc); | |
719 void semantic2(Scope *sc); | |
720 void semantic3(Scope *sc); | |
721 // called from semantic3 | |
722 void varArgs(Scope *sc, TypeFunction*, VarDeclaration *&, VarDeclaration *&); | |
723 | |
724 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
725 void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs); | |
726 int overrides(FuncDeclaration *fd); | |
727 int findVtblIndex(Array *vtbl, int dim); | |
728 int overloadInsert(Dsymbol *s); | |
729 FuncDeclaration *overloadExactMatch(Type *t, Module* from); | |
730 FuncDeclaration *overloadResolve(Loc loc, Expression *ethis, Expressions *arguments, Module *from, int flags = 0); | |
731 MATCH leastAsSpecialized(FuncDeclaration *g); | |
732 LabelDsymbol *searchLabel(Identifier *ident); | |
733 AggregateDeclaration *isThis(); | |
734 AggregateDeclaration *isMember2(); | |
735 int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference | |
736 void appendExp(Expression *e); | |
737 void appendState(Statement *s); | |
738 char *mangle(); | |
739 const char *toPrettyChars(); | |
740 int isMain(); | |
741 int isWinMain(); | |
742 int isDllMain(); | |
743 enum BUILTIN isBuiltin(); | |
744 int isExport(); | |
745 int isImportedSymbol(); | |
746 int isAbstract(); | |
747 int isCodeseg(); | |
748 int isOverloadable(); | |
749 int isPure(); | |
750 virtual int isNested(); | |
751 int needThis(); | |
752 virtual int isVirtual(); | |
753 virtual int isFinal(); | |
754 virtual int addPreInvariant(); | |
755 virtual int addPostInvariant(); | |
756 Expression *interpret(InterState *istate, Expressions *arguments, Expression *thisexp = NULL); | |
757 void inlineScan(); | |
758 int canInline(int hasthis, int hdrscan = 0); | |
759 Expression *doInline(InlineScanState *iss, Expression *ethis, Array *arguments); | |
760 const char *kind(); | |
761 void toDocBuffer(OutBuffer *buf); | |
762 FuncDeclaration *isUnique(); | |
763 int needsClosure(); | |
764 Statement *mergeFrequire(Statement *); | |
765 Statement *mergeFensure(Statement *); | |
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 */ |