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