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
|
|
107 unsigned storage_class;
|
|
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
|
|
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
|
|
715 FuncDeclaration(Loc loc, Loc endloc, Identifier *id, enum STC storage_class, Type *type);
|
|
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 *);
|
|
765
|
|
766 // LDC: give argument types to runtime functions
|
|
767 static FuncDeclaration *genCfunc(Arguments *args, Type *treturn, const char *name);
|
|
768 static FuncDeclaration *genCfunc(Arguments *args, Type *treturn, Identifier *id);
|
|
769
|
|
770 #if IN_DMD
|
|
771 Symbol *toSymbol();
|
|
772 Symbol *toThunkSymbol(int offset); // thunk version
|
|
773 void toObjFile(int multiobj); // compile to .obj file
|
|
774 int cvMember(unsigned char *p);
|
|
775 void buildClosure(IRState *irs);
|
|
776 #endif
|
|
777
|
|
778 FuncDeclaration *isFuncDeclaration() { return this; }
|
|
779
|
|
780 #if IN_LLVM
|
|
781 // LDC stuff
|
|
782
|
|
783 /// Codegen traversal
|
|
784 void codegen(Ir* ir);
|
|
785
|
|
786 // vars declared in this function that nested funcs reference
|
|
787 // is this is not empty, nestedFrameRef is set and these VarDecls
|
|
788 // probably have nestedref set too, see VarDeclaration::checkNestedReference
|
|
789 std::set<VarDeclaration*> nestedVars;
|
|
790
|
|
791 std::string intrinsicName;
|
|
792
|
|
793 bool isIntrinsic();
|
|
794 bool isVaIntrinsic();
|
|
795
|
|
796 // we keep our own table of label statements as LabelDsymbolS
|
|
797 // don't always carry their corresponding statement along ...
|
|
798 typedef std::map<const char*, LabelStatement*> LabelMap;
|
|
799 LabelMap labmap;
|
|
800
|
|
801 // if this is an array operation it gets a little special attention
|
|
802 bool isArrayOp;
|
|
803
|
|
804 // Functions that wouldn't have gotten semantic3'ed if we weren't inlining set this flag.
|
|
805 bool availableExternally;
|
|
806
|
|
807 // true if overridden with the pragma(allow_inline); stmt
|
|
808 bool allowInlining;
|
|
809 #endif
|
|
810 };
|
|
811
|
|
812 #if DMDV2
|
|
813 FuncDeclaration *resolveFuncCall(Scope *sc, Loc loc, Dsymbol *s,
|
|
814 Objects *tiargs,
|
|
815 Expression *ethis,
|
|
816 Expressions *arguments,
|
|
817 int flags);
|
|
818 #endif
|
|
819
|
|
820 struct FuncAliasDeclaration : FuncDeclaration
|
|
821 {
|
|
822 FuncDeclaration *funcalias;
|
|
823 PROT importprot; // if generated by import, store its protection
|
|
824
|
|
825 FuncAliasDeclaration(FuncDeclaration *funcalias);
|
|
826
|
|
827 FuncAliasDeclaration *isFuncAliasDeclaration() { return this; }
|
|
828 const char *kind();
|
|
829 #if IN_DMD
|
|
830 Symbol *toSymbol();
|
|
831 #endif
|
|
832 };
|
|
833
|
|
834 struct FuncLiteralDeclaration : FuncDeclaration
|
|
835 {
|
|
836 enum TOK tok; // TOKfunction or TOKdelegate
|
|
837
|
|
838 FuncLiteralDeclaration(Loc loc, Loc endloc, Type *type, enum TOK tok,
|
|
839 ForeachStatement *fes);
|
|
840 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
841 Dsymbol *syntaxCopy(Dsymbol *);
|
|
842 int isNested();
|
|
843 int isVirtual();
|
|
844
|
|
845 FuncLiteralDeclaration *isFuncLiteralDeclaration() { return this; }
|
|
846 const char *kind();
|
|
847 };
|
|
848
|
|
849 struct CtorDeclaration : FuncDeclaration
|
|
850 { Arguments *arguments;
|
|
851 int varargs;
|
|
852
|
|
853 CtorDeclaration(Loc loc, Loc endloc, Arguments *arguments, int varargs);
|
|
854 Dsymbol *syntaxCopy(Dsymbol *);
|
|
855 void semantic(Scope *sc);
|
|
856 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
857 const char *kind();
|
|
858 char *toChars();
|
|
859 int isVirtual();
|
|
860 int addPreInvariant();
|
|
861 int addPostInvariant();
|
|
862 void toDocBuffer(OutBuffer *buf);
|
|
863
|
|
864 CtorDeclaration *isCtorDeclaration() { return this; }
|
|
865 };
|
|
866
|
|
867 #if DMDV2
|
|
868 struct PostBlitDeclaration : FuncDeclaration
|
|
869 {
|
|
870 PostBlitDeclaration(Loc loc, Loc endloc);
|
|
871 PostBlitDeclaration(Loc loc, Loc endloc, Identifier *id);
|
|
872 Dsymbol *syntaxCopy(Dsymbol *);
|
|
873 void semantic(Scope *sc);
|
|
874 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
875 int isVirtual();
|
|
876 int addPreInvariant();
|
|
877 int addPostInvariant();
|
|
878 int overloadInsert(Dsymbol *s);
|
|
879 void emitComment(Scope *sc);
|
|
880 void toJsonBuffer(OutBuffer *buf);
|
|
881
|
|
882 PostBlitDeclaration *isPostBlitDeclaration() { return this; }
|
|
883 };
|
|
884 #endif
|
|
885
|
|
886 struct DtorDeclaration : FuncDeclaration
|
|
887 {
|
|
888 DtorDeclaration(Loc loc, Loc endloc);
|
|
889 DtorDeclaration(Loc loc, Loc endloc, Identifier *id);
|
|
890 Dsymbol *syntaxCopy(Dsymbol *);
|
|
891 void semantic(Scope *sc);
|
|
892 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
893 const char *kind();
|
|
894 char *toChars();
|
|
895 int isVirtual();
|
|
896 int addPreInvariant();
|
|
897 int addPostInvariant();
|
|
898 int overloadInsert(Dsymbol *s);
|
|
899 void emitComment(Scope *sc);
|
|
900 void toJsonBuffer(OutBuffer *buf);
|
|
901
|
|
902 DtorDeclaration *isDtorDeclaration() { return this; }
|
|
903 };
|
|
904
|
|
905 struct StaticCtorDeclaration : FuncDeclaration
|
|
906 {
|
|
907 StaticCtorDeclaration(Loc loc, Loc endloc);
|
|
908 Dsymbol *syntaxCopy(Dsymbol *);
|
|
909 void semantic(Scope *sc);
|
|
910 AggregateDeclaration *isThis();
|
|
911 int isStaticConstructor();
|
|
912 int isVirtual();
|
|
913 int addPreInvariant();
|
|
914 int addPostInvariant();
|
|
915 void emitComment(Scope *sc);
|
|
916 void toJsonBuffer(OutBuffer *buf);
|
|
917 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
918
|
|
919 StaticCtorDeclaration *isStaticCtorDeclaration() { return this; }
|
|
920 };
|
|
921
|
|
922 struct StaticDtorDeclaration : FuncDeclaration
|
|
923 { VarDeclaration *vgate; // 'gate' variable
|
|
924
|
|
925 StaticDtorDeclaration(Loc loc, Loc endloc);
|
|
926 Dsymbol *syntaxCopy(Dsymbol *);
|
|
927 void semantic(Scope *sc);
|
|
928 AggregateDeclaration *isThis();
|
|
929 int isStaticDestructor();
|
|
930 int isVirtual();
|
|
931 int addPreInvariant();
|
|
932 int addPostInvariant();
|
|
933 void emitComment(Scope *sc);
|
|
934 void toJsonBuffer(OutBuffer *buf);
|
|
935 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
936
|
|
937 StaticDtorDeclaration *isStaticDtorDeclaration() { return this; }
|
|
938 };
|
|
939
|
|
940 struct InvariantDeclaration : FuncDeclaration
|
|
941 {
|
|
942 InvariantDeclaration(Loc loc, Loc endloc);
|
|
943 Dsymbol *syntaxCopy(Dsymbol *);
|
|
944 void semantic(Scope *sc);
|
|
945 int isVirtual();
|
|
946 int addPreInvariant();
|
|
947 int addPostInvariant();
|
|
948 void emitComment(Scope *sc);
|
|
949 void toJsonBuffer(OutBuffer *buf);
|
|
950 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
951
|
|
952 InvariantDeclaration *isInvariantDeclaration() { return this; }
|
|
953 };
|
|
954
|
|
955
|
|
956 struct UnitTestDeclaration : FuncDeclaration
|
|
957 {
|
|
958 UnitTestDeclaration(Loc loc, Loc endloc);
|
|
959 Dsymbol *syntaxCopy(Dsymbol *);
|
|
960 void semantic(Scope *sc);
|
|
961 AggregateDeclaration *isThis();
|
|
962 int isVirtual();
|
|
963 int addPreInvariant();
|
|
964 int addPostInvariant();
|
|
965 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
966
|
|
967 UnitTestDeclaration *isUnitTestDeclaration() { return this; }
|
|
968 };
|
|
969
|
|
970 struct NewDeclaration : FuncDeclaration
|
|
971 { Arguments *arguments;
|
|
972 int varargs;
|
|
973
|
|
974 NewDeclaration(Loc loc, Loc endloc, Arguments *arguments, int varargs);
|
|
975 Dsymbol *syntaxCopy(Dsymbol *);
|
|
976 void semantic(Scope *sc);
|
|
977 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
978 const char *kind();
|
|
979 int isVirtual();
|
|
980 int addPreInvariant();
|
|
981 int addPostInvariant();
|
|
982
|
|
983 NewDeclaration *isNewDeclaration() { return this; }
|
|
984 };
|
|
985
|
|
986
|
|
987 struct DeleteDeclaration : FuncDeclaration
|
|
988 { Arguments *arguments;
|
|
989
|
|
990 DeleteDeclaration(Loc loc, Loc endloc, Arguments *arguments);
|
|
991 Dsymbol *syntaxCopy(Dsymbol *);
|
|
992 void semantic(Scope *sc);
|
|
993 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
994 const char *kind();
|
|
995 int isDelete();
|
|
996 int isVirtual();
|
|
997 int addPreInvariant();
|
|
998 int addPostInvariant();
|
|
999 #ifdef _DH
|
|
1000 DeleteDeclaration *isDeleteDeclaration() { return this; }
|
|
1001 #endif
|
|
1002 };
|
|
1003
|
|
1004 #endif /* DMD_DECLARATION_H */
|