comparison dmd2/declaration.h @ 1452:638d16625da2

LDC 2 compiles again.
author Robert Clipsham <robert@octarineparrot.com>
date Sat, 30 May 2009 17:23:32 +0100
parents 03d7c4aac654
children f62347c22d81
comparison
equal deleted inserted replaced
1423:42bd767ec5a4 1452:638d16625da2
13 13
14 #ifdef __DMC__ 14 #ifdef __DMC__
15 #pragma once 15 #pragma once
16 #endif /* __DMC__ */ 16 #endif /* __DMC__ */
17 17
18 #if IN_LLVM
18 #include <set> 19 #include <set>
19 #include <map> 20 #include <map>
20 #include <string> 21 #include <string>
22 #endif
21 23
22 #include "dsymbol.h" 24 #include "dsymbol.h"
23 #include "lexer.h" 25 #include "lexer.h"
24 #include "mtype.h" 26 #include "mtype.h"
25 27
26 struct Expression; 28 struct Expression;
27 struct Statement; 29 struct Statement;
28 struct LabelDsymbol; 30 struct LabelDsymbol;
31 #if IN_LLVM
29 struct LabelStatement; 32 struct LabelStatement;
33 #endif
30 struct Initializer; 34 struct Initializer;
31 struct Module; 35 struct Module;
32 struct InlineScanState; 36 struct InlineScanState;
33 struct ForeachStatement; 37 struct ForeachStatement;
34 struct FuncDeclaration; 38 struct FuncDeclaration;
35 struct ExpInitializer; 39 struct ExpInitializer;
36 struct StructDeclaration; 40 struct StructDeclaration;
37 struct TupleType; 41 struct TupleType;
38 struct InterState; 42 struct InterState;
39 struct IRState; 43 struct IRState;
44 #if IN_LLVM
40 struct AnonDeclaration; 45 struct AnonDeclaration;
46 #endif
41 47
42 enum PROT; 48 enum PROT;
43 enum LINK; 49 enum LINK;
44 enum TOK; 50 enum TOK;
45 enum MATCH; 51 enum MATCH;
66 STCvariadic = 0x10000, // variadic function argument 72 STCvariadic = 0x10000, // variadic function argument
67 STCctorinit = 0x20000, // can only be set inside constructor 73 STCctorinit = 0x20000, // can only be set inside constructor
68 STCtemplateparameter = 0x40000, // template parameter 74 STCtemplateparameter = 0x40000, // template parameter
69 STCscope = 0x80000, // template parameter 75 STCscope = 0x80000, // template parameter
70 STCinvariant = 0x100000, 76 STCinvariant = 0x100000,
77 STCimmutable = 0x100000,
71 STCref = 0x200000, 78 STCref = 0x200000,
72 STCinit = 0x400000, // has explicit initializer 79 STCinit = 0x400000, // has explicit initializer
73 STCmanifest = 0x800000, // manifest constant 80 STCmanifest = 0x800000, // manifest constant
74 STCnodtor = 0x1000000, // don't run destructor 81 STCnodtor = 0x1000000, // don't run destructor
75 STCnothrow = 0x2000000, // never throws exceptions 82 STCnothrow = 0x2000000, // never throws exceptions
76 STCpure = 0x4000000, // pure function 83 STCpure = 0x4000000, // pure function
77 STCtls = 0x8000000, // thread local 84 STCtls = 0x8000000, // thread local
78 STCalias = 0x10000000, // alias parameter 85 STCalias = 0x10000000, // alias parameter
79 STCshared = 0x20000000, // accessible from multiple threads 86 STCshared = 0x20000000, // accessible from multiple threads
87 STCgshared = 0x40000000, // accessible from multiple threads
88 // but not typed as "shared"
89 STC_TYPECTOR = (STCconst | STCimmutable | STCshared),
80 }; 90 };
81 91
82 struct Match 92 struct Match
83 { 93 {
84 int count; // number of matches found 94 int count; // number of matches found
87 FuncDeclaration *nextf; // current matching function 97 FuncDeclaration *nextf; // current matching function
88 FuncDeclaration *anyf; // pick a func, any func, to use for error recovery 98 FuncDeclaration *anyf; // pick a func, any func, to use for error recovery
89 }; 99 };
90 100
91 void overloadResolveX(Match *m, FuncDeclaration *f, 101 void overloadResolveX(Match *m, FuncDeclaration *f,
92 Expression *ethis, Expressions *arguments); 102 Expression *ethis, Expressions *arguments, Module* from);
93 int overloadApply(FuncDeclaration *fstart, 103 int overloadApply(Module* from, FuncDeclaration *fstart,
94 int (*fp)(void *, FuncDeclaration *), 104 int (*fp)(void *, FuncDeclaration *),
95 void *param); 105 void *param);
96 106
97 /**************************************************************/ 107 /**************************************************************/
98 108
101 Type *type; 111 Type *type;
102 Type *originalType; // before semantic analysis 112 Type *originalType; // before semantic analysis
103 unsigned storage_class; 113 unsigned storage_class;
104 enum PROT protection; 114 enum PROT protection;
105 enum LINK linkage; 115 enum LINK linkage;
116 int inuse; // used to detect cycles
106 117
107 Declaration(Identifier *id); 118 Declaration(Identifier *id);
108 void semantic(Scope *sc); 119 void semantic(Scope *sc);
109 const char *kind(); 120 const char *kind();
110 unsigned size(Loc loc); 121 unsigned size(Loc loc);
117 int isStatic() { return storage_class & STCstatic; } 128 int isStatic() { return storage_class & STCstatic; }
118 virtual int isStaticConstructor(); 129 virtual int isStaticConstructor();
119 virtual int isStaticDestructor(); 130 virtual int isStaticDestructor();
120 virtual int isDelete(); 131 virtual int isDelete();
121 virtual int isDataseg(); 132 virtual int isDataseg();
133 virtual int isThreadlocal();
122 virtual int isCodeseg(); 134 virtual int isCodeseg();
123 int isCtorinit() { return storage_class & STCctorinit; } 135 int isCtorinit() { return storage_class & STCctorinit; }
124 int isFinal() { return storage_class & STCfinal; } 136 int isFinal() { return storage_class & STCfinal; }
125 int isAbstract() { return storage_class & STCabstract; } 137 int isAbstract() { return storage_class & STCabstract; }
126 int isConst() { return storage_class & STCconst; } 138 int isConst() { return storage_class & STCconst; }
138 150
139 enum PROT prot(); 151 enum PROT prot();
140 152
141 Declaration *isDeclaration() { return this; } 153 Declaration *isDeclaration() { return this; }
142 154
143 // llvm 155 #if IN_LLVM
144 virtual void toObjFile(int unused = 0); // compile to .obj file 156 /// Codegen traversal
157 virtual void codegen(Ir* ir);
158 #endif
145 }; 159 };
146 160
147 /**************************************************************/ 161 /**************************************************************/
148 162
149 struct TupleDeclaration : Declaration 163 struct TupleDeclaration : Declaration
159 Type *getType(); 173 Type *getType();
160 int needThis(); 174 int needThis();
161 175
162 TupleDeclaration *isTupleDeclaration() { return this; } 176 TupleDeclaration *isTupleDeclaration() { return this; }
163 177
164 // LDC we need this 178 #if IN_LLVM
165 void toObjFile(int multiobj); // compile to .obj file 179 /// Codegen traversal
180 void codegen(Ir* ir);
181 #endif
166 }; 182 };
167 183
168 /**************************************************************/ 184 /**************************************************************/
169 185
170 struct TypedefDeclaration : Declaration 186 struct TypedefDeclaration : Declaration
173 Initializer *init; 189 Initializer *init;
174 int sem; // 0: semantic() has not been run 190 int sem; // 0: semantic() has not been run
175 // 1: semantic() is in progress 191 // 1: semantic() is in progress
176 // 2: semantic() has been run 192 // 2: semantic() has been run
177 // 3: semantic2() has been run 193 // 3: semantic2() has been run
178 int inuse; // used to detect typedef cycles
179 194
180 TypedefDeclaration(Loc loc, Identifier *ident, Type *basetype, Initializer *init); 195 TypedefDeclaration(Loc loc, Identifier *ident, Type *basetype, Initializer *init);
181 Dsymbol *syntaxCopy(Dsymbol *); 196 Dsymbol *syntaxCopy(Dsymbol *);
182 void semantic(Scope *sc); 197 void semantic(Scope *sc);
183 void semantic2(Scope *sc); 198 void semantic2(Scope *sc);
190 Type *hbasetype; 205 Type *hbasetype;
191 #endif 206 #endif
192 207
193 void toDocBuffer(OutBuffer *buf); 208 void toDocBuffer(OutBuffer *buf);
194 209
210 #if IN_DMD
195 void toObjFile(int multiobj); // compile to .obj file 211 void toObjFile(int multiobj); // compile to .obj file
196 void toDebug(); 212 void toDebug();
197 int cvMember(unsigned char *p); 213 int cvMember(unsigned char *p);
214 #endif
198 215
199 TypedefDeclaration *isTypedefDeclaration() { return this; } 216 TypedefDeclaration *isTypedefDeclaration() { return this; }
200 217
218 #if IN_DMD
201 Symbol *sinit; 219 Symbol *sinit;
202 Symbol *toInitializer(); 220 Symbol *toInitializer();
221 #endif
222
223 #if IN_LLVM
224 /// Codegen traversal
225 void codegen(Ir* ir);
226 #endif
203 }; 227 };
204 228
205 /**************************************************************/ 229 /**************************************************************/
206 230
207 struct AliasDeclaration : Declaration 231 struct AliasDeclaration : Declaration
208 { 232 {
209 Dsymbol *aliassym; 233 Dsymbol *aliassym;
210 Dsymbol *overnext; // next in overload list 234 Dsymbol *overnext; // next in overload list
211 int inSemantic; 235 int inSemantic;
236 PROT importprot; // if generated by import, store its protection
212 237
213 AliasDeclaration(Loc loc, Identifier *ident, Type *type); 238 AliasDeclaration(Loc loc, Identifier *ident, Type *type);
214 AliasDeclaration(Loc loc, Identifier *ident, Dsymbol *s); 239 AliasDeclaration(Loc loc, Identifier *ident, Dsymbol *s);
215 Dsymbol *syntaxCopy(Dsymbol *); 240 Dsymbol *syntaxCopy(Dsymbol *);
216 void semantic(Scope *sc); 241 void semantic(Scope *sc);
235 { 260 {
236 Initializer *init; 261 Initializer *init;
237 unsigned offset; 262 unsigned offset;
238 int noauto; // no auto semantics 263 int noauto; // no auto semantics
239 FuncDeclarations nestedrefs; // referenced by these lexically nested functions 264 FuncDeclarations nestedrefs; // referenced by these lexically nested functions
240 int inuse;
241 int ctorinit; // it has been initialized in a ctor 265 int ctorinit; // it has been initialized in a ctor
242 int onstack; // 1: it has been allocated on the stack 266 int onstack; // 1: it has been allocated on the stack
243 // 2: on stack, run destructor anyway 267 // 2: on stack, run destructor anyway
244 int canassign; // it can be assigned to 268 int canassign; // it can be assigned to
245 Dsymbol *aliassym; // if redone as alias to another symbol 269 Dsymbol *aliassym; // if redone as alias to another symbol
258 Initializer *hinit; 282 Initializer *hinit;
259 #endif 283 #endif
260 int needThis(); 284 int needThis();
261 int isImportedSymbol(); 285 int isImportedSymbol();
262 int isDataseg(); 286 int isDataseg();
287 int isThreadlocal();
263 int hasPointers(); 288 int hasPointers();
264 int canTakeAddressOf(); 289 int canTakeAddressOf();
265 int needsAutoDtor(); 290 int needsAutoDtor();
266 Expression *callAutoDtor(Scope *sc); 291 Expression *callAutoDtor(Scope *sc);
267 ExpInitializer *getExpInitializer(); 292 ExpInitializer *getExpInitializer();
268 Expression *getConstInitializer(); 293 Expression *getConstInitializer();
269 void checkCtorConstInit(); 294 void checkCtorConstInit();
270 void checkNestedReference(Scope *sc, Loc loc); 295 void checkNestedReference(Scope *sc, Loc loc);
271 Dsymbol *toAlias(); 296 Dsymbol *toAlias();
272 297
298 #if IN_DMD
299 void toObjFile(int multiobj); // compile to .obj file
273 Symbol *toSymbol(); 300 Symbol *toSymbol();
274 void toObjFile(int multiobj); // compile to .obj file
275 int cvMember(unsigned char *p); 301 int cvMember(unsigned char *p);
302 #endif
276 303
277 // Eliminate need for dynamic_cast 304 // Eliminate need for dynamic_cast
278 VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; } 305 VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; }
279 306
280 // LDC 307 #if IN_LLVM
308 /// Codegen traversal
309 virtual void codegen(Ir* ir);
310
311 /// Index into parent aggregate.
312 /// Set during type generation.
313 unsigned aggrIndex;
314
315 // FIXME: we're not using these anymore!
281 AnonDeclaration* anonDecl; 316 AnonDeclaration* anonDecl;
282 unsigned offset2; 317 unsigned offset2;
318
319 /// This var is used by a naked function.
283 bool nakedUse; 320 bool nakedUse;
321 #endif
284 }; 322 };
285 323
286 /**************************************************************/ 324 /**************************************************************/
287 325
288 // LDC uses this to denote static struct initializers 326 // LDC uses this to denote static struct initializers
291 { 329 {
292 StructDeclaration *dsym; 330 StructDeclaration *dsym;
293 331
294 StaticStructInitDeclaration(Loc loc, StructDeclaration *dsym); 332 StaticStructInitDeclaration(Loc loc, StructDeclaration *dsym);
295 333
334 #if IN_DMD
296 Symbol *toSymbol(); 335 Symbol *toSymbol();
336 #endif
297 337
298 // Eliminate need for dynamic_cast 338 // Eliminate need for dynamic_cast
299 StaticStructInitDeclaration *isStaticStructInitDeclaration() { return (StaticStructInitDeclaration *)this; } 339 StaticStructInitDeclaration *isStaticStructInitDeclaration() { return (StaticStructInitDeclaration *)this; }
300 }; 340 };
301 341
307 Dsymbol *syntaxCopy(Dsymbol *); 347 Dsymbol *syntaxCopy(Dsymbol *);
308 void semantic(Scope *sc); 348 void semantic(Scope *sc);
309 349
310 void emitComment(Scope *sc); 350 void emitComment(Scope *sc);
311 351
352 #if IN_DMD
312 Symbol *toSymbol(); 353 Symbol *toSymbol();
354 #endif
313 355
314 ClassInfoDeclaration* isClassInfoDeclaration() { return this; } 356 ClassInfoDeclaration* isClassInfoDeclaration() { return this; }
315 }; 357 };
316 358
317 struct ModuleInfoDeclaration : VarDeclaration 359 struct ModuleInfoDeclaration : VarDeclaration
322 Dsymbol *syntaxCopy(Dsymbol *); 364 Dsymbol *syntaxCopy(Dsymbol *);
323 void semantic(Scope *sc); 365 void semantic(Scope *sc);
324 366
325 void emitComment(Scope *sc); 367 void emitComment(Scope *sc);
326 368
369 #if IN_DMD
327 Symbol *toSymbol(); 370 Symbol *toSymbol();
371 #endif
328 }; 372 };
329 373
330 struct TypeInfoDeclaration : VarDeclaration 374 struct TypeInfoDeclaration : VarDeclaration
331 { 375 {
332 Type *tinfo; 376 Type *tinfo;
335 Dsymbol *syntaxCopy(Dsymbol *); 379 Dsymbol *syntaxCopy(Dsymbol *);
336 void semantic(Scope *sc); 380 void semantic(Scope *sc);
337 381
338 void emitComment(Scope *sc); 382 void emitComment(Scope *sc);
339 383
384 #if IN_DMD
385 void toObjFile(int multiobj); // compile to .obj file
340 Symbol *toSymbol(); 386 Symbol *toSymbol();
341 void toObjFile(int multiobj); // compile to .obj file
342 virtual void toDt(dt_t **pdt); 387 virtual void toDt(dt_t **pdt);
388 #endif
343 389
344 virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return this; } 390 virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return this; }
345 391
346 // LDC 392 #if IN_LLVM
347 virtual void llvmDeclare(); 393 /// Codegen traversal
394 void codegen(Ir* ir);
348 virtual void llvmDefine(); 395 virtual void llvmDefine();
396 #endif
349 }; 397 };
350 398
351 struct TypeInfoStructDeclaration : TypeInfoDeclaration 399 struct TypeInfoStructDeclaration : TypeInfoDeclaration
352 { 400 {
353 TypeInfoStructDeclaration(Type *tinfo); 401 TypeInfoStructDeclaration(Type *tinfo);
354 402
355 void toDt(dt_t **pdt); 403 #if IN_DMD
356 404 void toDt(dt_t **pdt);
357 // LDC 405 #endif
358 void llvmDeclare(); 406
359 void llvmDefine(); 407 #if IN_LLVM
408 void llvmDefine();
409 #endif
360 }; 410 };
361 411
362 struct TypeInfoClassDeclaration : TypeInfoDeclaration 412 struct TypeInfoClassDeclaration : TypeInfoDeclaration
363 { 413 {
364 TypeInfoClassDeclaration(Type *tinfo); 414 TypeInfoClassDeclaration(Type *tinfo);
365 415
366 void toDt(dt_t **pdt); 416 #if IN_DMD
367 417 void toDt(dt_t **pdt);
368 // LDC 418 #endif
369 void llvmDeclare(); 419
370 void llvmDefine(); 420 #if IN_LLVM
421 void llvmDefine();
422 #endif
371 }; 423 };
372 424
373 struct TypeInfoInterfaceDeclaration : TypeInfoDeclaration 425 struct TypeInfoInterfaceDeclaration : TypeInfoDeclaration
374 { 426 {
375 TypeInfoInterfaceDeclaration(Type *tinfo); 427 TypeInfoInterfaceDeclaration(Type *tinfo);
376 428
377 void toDt(dt_t **pdt); 429 #if IN_DMD
378 430 void toDt(dt_t **pdt);
379 // LDC 431 #endif
380 void llvmDeclare(); 432
381 void llvmDefine(); 433 #if IN_LLVM
434 void llvmDefine();
435 #endif
382 }; 436 };
383 437
384 struct TypeInfoTypedefDeclaration : TypeInfoDeclaration 438 struct TypeInfoTypedefDeclaration : TypeInfoDeclaration
385 { 439 {
386 TypeInfoTypedefDeclaration(Type *tinfo); 440 TypeInfoTypedefDeclaration(Type *tinfo);
387 441
388 void toDt(dt_t **pdt); 442 #if IN_DMD
389 443 void toDt(dt_t **pdt);
390 // LDC 444 #endif
391 void llvmDeclare(); 445
392 void llvmDefine(); 446 #if IN_LLVM
447 void llvmDefine();
448 #endif
393 }; 449 };
394 450
395 struct TypeInfoPointerDeclaration : TypeInfoDeclaration 451 struct TypeInfoPointerDeclaration : TypeInfoDeclaration
396 { 452 {
397 TypeInfoPointerDeclaration(Type *tinfo); 453 TypeInfoPointerDeclaration(Type *tinfo);
398 454
399 void toDt(dt_t **pdt); 455 #if IN_DMD
400 456 void toDt(dt_t **pdt);
401 // LDC 457 #endif
402 void llvmDeclare(); 458
403 void llvmDefine(); 459 #if IN_LLVM
460 void llvmDefine();
461 #endif
404 }; 462 };
405 463
406 struct TypeInfoArrayDeclaration : TypeInfoDeclaration 464 struct TypeInfoArrayDeclaration : TypeInfoDeclaration
407 { 465 {
408 TypeInfoArrayDeclaration(Type *tinfo); 466 TypeInfoArrayDeclaration(Type *tinfo);
409 467
410 void toDt(dt_t **pdt); 468 #if IN_DMD
411 469 void toDt(dt_t **pdt);
412 // LDC 470 #endif
413 void llvmDeclare(); 471
414 void llvmDefine(); 472 #if IN_LLVM
473 void llvmDefine();
474 #endif
415 }; 475 };
416 476
417 struct TypeInfoStaticArrayDeclaration : TypeInfoDeclaration 477 struct TypeInfoStaticArrayDeclaration : TypeInfoDeclaration
418 { 478 {
419 TypeInfoStaticArrayDeclaration(Type *tinfo); 479 TypeInfoStaticArrayDeclaration(Type *tinfo);
420 480
421 void toDt(dt_t **pdt); 481 #if IN_DMD
422 482 void toDt(dt_t **pdt);
423 // LDC 483 #endif
424 void llvmDeclare(); 484
425 void llvmDefine(); 485 #if IN_LLVM
486 void llvmDefine();
487 #endif
426 }; 488 };
427 489
428 struct TypeInfoAssociativeArrayDeclaration : TypeInfoDeclaration 490 struct TypeInfoAssociativeArrayDeclaration : TypeInfoDeclaration
429 { 491 {
430 TypeInfoAssociativeArrayDeclaration(Type *tinfo); 492 TypeInfoAssociativeArrayDeclaration(Type *tinfo);
431 493
432 void toDt(dt_t **pdt); 494 #if IN_DMD
433 495 void toDt(dt_t **pdt);
434 // LDC 496 #endif
435 void llvmDeclare(); 497
436 void llvmDefine(); 498 #if IN_LLVM
499 void llvmDefine();
500 #endif
437 }; 501 };
438 502
439 struct TypeInfoEnumDeclaration : TypeInfoDeclaration 503 struct TypeInfoEnumDeclaration : TypeInfoDeclaration
440 { 504 {
441 TypeInfoEnumDeclaration(Type *tinfo); 505 TypeInfoEnumDeclaration(Type *tinfo);
442 506
443 void toDt(dt_t **pdt); 507 #if IN_DMD
444 508 void toDt(dt_t **pdt);
445 // LDC 509 #endif
446 void llvmDeclare(); 510
447 void llvmDefine(); 511 #if IN_LLVM
512 void llvmDefine();
513 #endif
448 }; 514 };
449 515
450 struct TypeInfoFunctionDeclaration : TypeInfoDeclaration 516 struct TypeInfoFunctionDeclaration : TypeInfoDeclaration
451 { 517 {
452 TypeInfoFunctionDeclaration(Type *tinfo); 518 TypeInfoFunctionDeclaration(Type *tinfo);
453 519
454 void toDt(dt_t **pdt); 520 #if IN_DMD
455 521 void toDt(dt_t **pdt);
456 // LDC 522 #endif
457 void llvmDeclare(); 523
458 void llvmDefine(); 524 #if IN_LLVM
525 void llvmDefine();
526 #endif
459 }; 527 };
460 528
461 struct TypeInfoDelegateDeclaration : TypeInfoDeclaration 529 struct TypeInfoDelegateDeclaration : TypeInfoDeclaration
462 { 530 {
463 TypeInfoDelegateDeclaration(Type *tinfo); 531 TypeInfoDelegateDeclaration(Type *tinfo);
464 532
465 void toDt(dt_t **pdt); 533 #if IN_DMD
466 534 void toDt(dt_t **pdt);
467 // LDC 535 #endif
468 void llvmDeclare(); 536
469 void llvmDefine(); 537 #if IN_LLVM
538 void llvmDefine();
539 #endif
470 }; 540 };
471 541
472 struct TypeInfoTupleDeclaration : TypeInfoDeclaration 542 struct TypeInfoTupleDeclaration : TypeInfoDeclaration
473 { 543 {
474 TypeInfoTupleDeclaration(Type *tinfo); 544 TypeInfoTupleDeclaration(Type *tinfo);
475 545
476 void toDt(dt_t **pdt); 546 #if IN_DMD
477 547 void toDt(dt_t **pdt);
478 // LDC 548 #endif
479 void llvmDeclare(); 549
480 void llvmDefine(); 550 #if IN_LLVM
551 void llvmDefine();
552 #endif
481 }; 553 };
482 554
483 #if DMDV2 555 #if DMDV2
484 struct TypeInfoConstDeclaration : TypeInfoDeclaration 556 struct TypeInfoConstDeclaration : TypeInfoDeclaration
485 { 557 {
486 TypeInfoConstDeclaration(Type *tinfo); 558 TypeInfoConstDeclaration(Type *tinfo);
487 559
488 void toDt(dt_t **pdt); 560 #if IN_DMD
489 561 void toDt(dt_t **pdt);
490 // LDC 562 #endif
491 void llvmDeclare(); 563
492 void llvmDefine(); 564 #if IN_LLVM
565 void llvmDefine();
566 #endif
493 }; 567 };
494 568
495 struct TypeInfoInvariantDeclaration : TypeInfoDeclaration 569 struct TypeInfoInvariantDeclaration : TypeInfoDeclaration
496 { 570 {
497 TypeInfoInvariantDeclaration(Type *tinfo); 571 TypeInfoInvariantDeclaration(Type *tinfo);
498 572
499 void toDt(dt_t **pdt); 573 #if IN_DMD
500 574 void toDt(dt_t **pdt);
501 // LDC 575 #endif
502 void llvmDeclare(); 576
503 void llvmDefine(); 577 #if IN_LLVM
578 void llvmDefine();
579 #endif
580 };
581
582 struct TypeInfoSharedDeclaration : TypeInfoDeclaration
583 {
584 TypeInfoSharedDeclaration(Type *tinfo);
585
586 #if IN_DMD
587 void toDt(dt_t **pdt);
588 #endif
504 }; 589 };
505 #endif 590 #endif
506 591
507 /**************************************************************/ 592 /**************************************************************/
508 593
509 struct ThisDeclaration : VarDeclaration 594 struct ThisDeclaration : VarDeclaration
510 { 595 {
511 ThisDeclaration(Type *t); 596 ThisDeclaration(Loc loc, Type *t);
512 Dsymbol *syntaxCopy(Dsymbol *); 597 Dsymbol *syntaxCopy(Dsymbol *);
598 ThisDeclaration *isThisDeclaration() { return this; }
513 }; 599 };
514 600
515 enum ILS 601 enum ILS
516 { 602 {
517 ILSuninitialized, // not computed yet 603 ILSuninitialized, // not computed yet
563 int naked; // !=0 if naked 649 int naked; // !=0 if naked
564 int inlineAsm; // !=0 if has inline assembler 650 int inlineAsm; // !=0 if has inline assembler
565 ILS inlineStatus; 651 ILS inlineStatus;
566 int inlineNest; // !=0 if nested inline 652 int inlineNest; // !=0 if nested inline
567 int cantInterpret; // !=0 if cannot interpret function 653 int cantInterpret; // !=0 if cannot interpret function
568 int semanticRun; // !=0 if semantic3() had been run 654 int semanticRun; // 1 semantic() run
655 // 2 semantic2() run
656 // 3 semantic3() started
657 // 4 semantic3() done
658 // 5 toObjFile() run
569 // this function's frame ptr 659 // this function's frame ptr
570 ForeachStatement *fes; // if foreach body, this is the foreach 660 ForeachStatement *fes; // if foreach body, this is the foreach
571 int introducing; // !=0 if 'introducing' function 661 int introducing; // !=0 if 'introducing' function
572 Type *tintro; // if !=NULL, then this is the type 662 Type *tintro; // if !=NULL, then this is the type
573 // of the 'introducing' function 663 // of the 'introducing' function
582 // 8 if there's inline asm 672 // 8 if there's inline asm
583 673
584 // Support for NRVO (named return value optimization) 674 // Support for NRVO (named return value optimization)
585 int nrvo_can; // !=0 means we can do it 675 int nrvo_can; // !=0 means we can do it
586 VarDeclaration *nrvo_var; // variable to replace with shidden 676 VarDeclaration *nrvo_var; // variable to replace with shidden
677 #if IN_DMD
587 Symbol *shidden; // hidden pointer passed to function 678 Symbol *shidden; // hidden pointer passed to function
679 #endif
588 680
589 #if DMDV2 681 #if DMDV2
590 enum BUILTIN builtin; // set if this is a known, builtin 682 enum BUILTIN builtin; // set if this is a known, builtin
591 // function we can evaluate at compile 683 // function we can evaluate at compile
592 // time 684 // time
603 FuncDeclaration(Loc loc, Loc endloc, Identifier *id, enum STC storage_class, Type *type); 695 FuncDeclaration(Loc loc, Loc endloc, Identifier *id, enum STC storage_class, Type *type);
604 Dsymbol *syntaxCopy(Dsymbol *); 696 Dsymbol *syntaxCopy(Dsymbol *);
605 void semantic(Scope *sc); 697 void semantic(Scope *sc);
606 void semantic2(Scope *sc); 698 void semantic2(Scope *sc);
607 void semantic3(Scope *sc); 699 void semantic3(Scope *sc);
700 // called from semantic3
701 void varArgs(Scope *sc, TypeFunction*, VarDeclaration *&, VarDeclaration *&);
702
608 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 703 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
609 void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs); 704 void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs);
610 int overrides(FuncDeclaration *fd); 705 int overrides(FuncDeclaration *fd);
611 int findVtblIndex(Array *vtbl, int dim); 706 int findVtblIndex(Array *vtbl, int dim);
612 int overloadInsert(Dsymbol *s); 707 int overloadInsert(Dsymbol *s);
613 FuncDeclaration *overloadExactMatch(Type *t); 708 FuncDeclaration *overloadExactMatch(Type *t, Module* from);
614 FuncDeclaration *overloadResolve(Loc loc, Expression *ethis, Expressions *arguments, int flags = 0); 709 FuncDeclaration *overloadResolve(Loc loc, Expression *ethis, Expressions *arguments, int flags = 0, Module* from=NULL);
615 MATCH leastAsSpecialized(FuncDeclaration *g); 710 MATCH leastAsSpecialized(FuncDeclaration *g);
616 LabelDsymbol *searchLabel(Identifier *ident); 711 LabelDsymbol *searchLabel(Identifier *ident);
617 AggregateDeclaration *isThis(); 712 AggregateDeclaration *isThis();
618 AggregateDeclaration *isMember2(); 713 AggregateDeclaration *isMember2();
619 int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference 714 int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference
627 int isExport(); 722 int isExport();
628 int isImportedSymbol(); 723 int isImportedSymbol();
629 int isAbstract(); 724 int isAbstract();
630 int isCodeseg(); 725 int isCodeseg();
631 int isOverloadable(); 726 int isOverloadable();
727 int isPure();
632 virtual int isNested(); 728 virtual int isNested();
633 int needThis(); 729 int needThis();
634 virtual int isVirtual(); 730 virtual int isVirtual();
635 virtual int isFinal(); 731 virtual int isFinal();
636 virtual int addPreInvariant(); 732 virtual int addPreInvariant();
646 742
647 // LDC: give argument types to runtime functions 743 // LDC: give argument types to runtime functions
648 static FuncDeclaration *genCfunc(Arguments *args, Type *treturn, const char *name); 744 static FuncDeclaration *genCfunc(Arguments *args, Type *treturn, const char *name);
649 static FuncDeclaration *genCfunc(Arguments *args, Type *treturn, Identifier *id); 745 static FuncDeclaration *genCfunc(Arguments *args, Type *treturn, Identifier *id);
650 746
747 #if IN_DMD
651 Symbol *toSymbol(); 748 Symbol *toSymbol();
652 Symbol *toThunkSymbol(int offset); // thunk version 749 Symbol *toThunkSymbol(int offset); // thunk version
653 void toObjFile(int multiobj); // compile to .obj file 750 void toObjFile(int multiobj); // compile to .obj file
654 int cvMember(unsigned char *p); 751 int cvMember(unsigned char *p);
655 void buildClosure(IRState *irs); 752 void buildClosure(IRState *irs); // Should this be inside or outside the #if IN_DMD?
656 753 #endif
657 FuncDeclaration *isFuncDeclaration() { return this; } 754 FuncDeclaration *isFuncDeclaration() { return this; }
658 755
756 #if IN_LLVM
659 // LDC stuff 757 // LDC stuff
758
759 /// Codegen traversal
760 void codegen(Ir* ir);
660 761
661 // vars declared in this function that nested funcs reference 762 // vars declared in this function that nested funcs reference
662 // is this is not empty, nestedFrameRef is set and these VarDecls 763 // is this is not empty, nestedFrameRef is set and these VarDecls
663 // probably have nestedref set too, see VarDeclaration::checkNestedReference 764 // probably have nestedref set too, see VarDeclaration::checkNestedReference
664 std::set<VarDeclaration*> nestedVars; 765 std::set<VarDeclaration*> nestedVars;
676 // if this is an array operation it gets a little special attention 777 // if this is an array operation it gets a little special attention
677 bool isArrayOp; 778 bool isArrayOp;
678 779
679 // true if overridden with the pragma(allow_inline); stmt 780 // true if overridden with the pragma(allow_inline); stmt
680 bool allowInlining; 781 bool allowInlining;
681 }; 782 #endif
783 };
784
785 FuncDeclaration *resolveFuncCall(Scope *sc, Loc loc, Dsymbol *s,
786 Objects *tiargs,
787 Expression *ethis,
788 Expressions *arguments,
789 int flags);
790
682 791
683 struct FuncAliasDeclaration : FuncDeclaration 792 struct FuncAliasDeclaration : FuncDeclaration
684 { 793 {
685 FuncDeclaration *funcalias; 794 FuncDeclaration *funcalias;
686 795 PROT importprot; // if generated by import, store its protection
796
687 FuncAliasDeclaration(FuncDeclaration *funcalias); 797 FuncAliasDeclaration(FuncDeclaration *funcalias);
688 798
689 FuncAliasDeclaration *isFuncAliasDeclaration() { return this; } 799 FuncAliasDeclaration *isFuncAliasDeclaration() { return this; }
690 const char *kind(); 800 const char *kind();
801 #if IN_DMD
691 Symbol *toSymbol(); 802 Symbol *toSymbol();
803 #endif
692 }; 804 };
693 805
694 struct FuncLiteralDeclaration : FuncDeclaration 806 struct FuncLiteralDeclaration : FuncDeclaration
695 { 807 {
696 enum TOK tok; // TOKfunction or TOKdelegate 808 enum TOK tok; // TOKfunction or TOKdelegate
747 DtorDeclaration(Loc loc, Loc endloc); 859 DtorDeclaration(Loc loc, Loc endloc);
748 DtorDeclaration(Loc loc, Loc endloc, Identifier *id); 860 DtorDeclaration(Loc loc, Loc endloc, Identifier *id);
749 Dsymbol *syntaxCopy(Dsymbol *); 861 Dsymbol *syntaxCopy(Dsymbol *);
750 void semantic(Scope *sc); 862 void semantic(Scope *sc);
751 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 863 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
864 const char *kind();
865 char *toChars();
752 int isVirtual(); 866 int isVirtual();
753 int addPreInvariant(); 867 int addPreInvariant();
754 int addPostInvariant(); 868 int addPostInvariant();
755 int overloadInsert(Dsymbol *s); 869 int overloadInsert(Dsymbol *s);
756 void emitComment(Scope *sc); 870 void emitComment(Scope *sc);