Ticket #125: forwardref-1434-noexception.diff
| File forwardref-1434-noexception.diff, 177.6 kB (added by ChristianK, 3 years ago) |
|---|
-
a/dmd/aggregate.h
old new 62 62 // 1: size is correct 63 63 // 2: cannot determine size; fwd referenced 64 64 int isdeprecated; // !=0 if deprecated 65 Scope *scope; // !=NULL means context to use66 65 67 66 // Special member functions 68 67 InvariantDeclaration *inv; // invariant … … 77 76 #endif 78 77 79 78 AggregateDeclaration(Loc loc, Identifier *id); 80 voidsemantic2(Scope *sc);81 voidsemantic3(Scope *sc);79 DeferStatus<void> semantic2(Scope *sc); 80 DeferStatus<void> semantic3(Scope *sc); 82 81 void inlineScan(); 83 82 unsigned size(Loc loc); 84 83 static void alignmember(unsigned salign, unsigned size, unsigned *poffset); 85 84 Type *getType(); 86 voidaddField(Scope *sc, VarDeclaration *v);85 DeferStatus<void> addField(Scope *sc, VarDeclaration *v); 87 86 int isDeprecated(); // is aggregate deprecated? 88 87 FuncDeclaration *buildDtor(Scope *sc); 89 88 … … 106 105 #endif 107 106 108 107 AggregateDeclaration *isAggregateDeclaration() { return this; } 108 109 // LDC 110 int sc_offset; // saved next offset in aggregate 109 111 }; 110 112 111 113 struct AnonymousAggregateDeclaration : AggregateDeclaration … … 131 133 132 134 StructDeclaration(Loc loc, Identifier *id); 133 135 Dsymbol *syntaxCopy(Dsymbol *s); 134 voidsemantic(Scope *sc);136 DeferStatus<void> semantic(Scope *sc); 135 137 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 138 139 //LDC, override to allow searching in partially semantic'ed structs 140 DeferStatus<Dsymbol*> search(Loc, Identifier *ident, int flags); 141 142 //LDC, for deferring 143 int deferState; 144 virtual bool isMemberReorderable(Dsymbol* s); 145 136 146 char *mangle(); 137 147 const char *kind(); 138 148 Expression *cloneMembers(); … … 160 170 const char *kind(); 161 171 162 172 UnionDeclaration *isUnionDeclaration() { return this; } 173 174 // LDC, overload to reset offset to zero after each member 175 virtual void postMemberSemantic(Scope* sc); 163 176 }; 164 177 165 178 // warning: two classes with the same base class share the same … … 225 238 226 239 int inuse; // to prevent recursive attempts 227 240 241 //LDC, for deferring 242 int deferState; 243 228 244 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); 229 245 Dsymbol *syntaxCopy(Dsymbol *s); 230 voidsemantic(Scope *sc);246 DeferStatus<void> semantic(Scope *sc); 231 247 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 232 248 int isBaseOf2(ClassDeclaration *cd); 233 249 234 250 #define OFFSET_RUNTIME 0x76543210 235 251 virtual int isBaseOf(ClassDeclaration *cd, int *poffset); 236 252 237 D symbol *search(Loc, Identifier *ident, int flags);253 DeferStatus<Dsymbol*> search(Loc, Identifier *ident, int flags); 238 254 #if DMDV2 239 255 int isFuncHidden(FuncDeclaration *fd); 240 256 #endif … … 283 299 #endif 284 300 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); 285 301 Dsymbol *syntaxCopy(Dsymbol *s); 286 voidsemantic(Scope *sc);302 DeferStatus<void> semantic(Scope *sc); 287 303 int isBaseOf(ClassDeclaration *cd, int *poffset); 288 304 int isBaseOf(BaseClass *bc, int *poffset); 289 305 const char *kind(); -
a/dmd/attrib.c
old new 52 52 : Dsymbol() 53 53 { 54 54 this->decl = decl; 55 member_semantic_started = false; 56 included_decls = NULL; 55 57 } 56 58 57 59 Array *AttribDeclaration::include(Scope *sc, ScopeDsymbol *sd) … … 74 76 return m; 75 77 } 76 78 77 void AttribDeclaration::semantic(Scope *sc) 79 // shares code with ScopeDsymbol::callSemanticOnMembers 80 DeferStatus<void> AttribDeclaration::callSemanticOnMembers(Scope* sc, Array* members) 78 81 { 79 Array *d = include(sc, NULL); 82 if (!members) 83 return nodefer(); 84 85 // first add everything to remaining_semantic 86 if (!member_semantic_started) { 87 for (int i = 0; i < members->dim; i++) 88 remaining_semantic.push_back( (Dsymbol*)members->data[i] ); 89 member_semantic_started = true; 90 } 91 92 int failed = 0; 93 94 DeferStatus<void> lastdefer; 95 96 // if we deferred an order dependent member, save it here 97 // we will then skip all order dependent members until this is reached again 98 Dsymbol *deferredOrderDependent = NULL; 99 100 while (!remaining_semantic.empty() && failed != remaining_semantic.size()) 101 { Dsymbol *s; 102 s = remaining_semantic[0]; 103 remaining_semantic.pop_front(); 104 105 // if we deferred something order dependent, skip other 106 // order dependent ones for one iteration 107 if (deferredOrderDependent == s) 108 deferredOrderDependent = NULL; 109 if (deferredOrderDependent && !isMemberReorderable(s)) { 110 ++failed; 111 remaining_semantic.push_back(s); 112 continue; 113 } 114 115 DeferStatus<void> result = runSemantic(s, sc); 116 if (result.defer()) { 117 lastdefer = result; 118 ++failed; 119 remaining_semantic.push_back(s); 120 if (!isMemberReorderable(s)) 121 deferredOrderDependent = s; 122 continue; 123 } 124 125 failed = 0; 126 postMemberSemantic(sc); 127 } 128 129 if (!remaining_semantic.empty()) 130 { 131 assert(lastdefer.defer()); 132 133 // reorder members into a valid state if necessary 134 if (deferredOrderDependent) 135 while (remaining_semantic[0] != deferredOrderDependent) { 136 Dsymbol* s = remaining_semantic[0]; 137 remaining_semantic.pop_front(); 138 remaining_semantic.push_back(s); 139 } 140 return lastdefer; 141 } 142 143 lastdefer.handled = true; 144 return nodefer(); 145 } 146 147 DeferStatus<void> AttribDeclaration::semantic(Scope *sc) 148 { 149 if (!included_decls) 150 included_decls = include(sc, NULL); 80 151 81 152 //printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d); 82 if (d) 83 { 84 for (unsigned i = 0; i < d->dim; i++) 85 { 86 Dsymbol *s = (Dsymbol *)d->data[i]; 87 88 s->semantic(sc); 89 } 90 } 153 return callSemanticOnMembers(sc, included_decls); 91 154 } 92 155 93 voidAttribDeclaration::semantic2(Scope *sc)156 DeferStatus<void> AttribDeclaration::semantic2(Scope *sc) 94 157 { 95 158 Array *d = include(sc, NULL); 96 159 … … 101 164 s->semantic2(sc); 102 165 } 103 166 } 167 return nodefer(); 104 168 } 105 169 106 voidAttribDeclaration::semantic3(Scope *sc)170 DeferStatus<void> AttribDeclaration::semantic3(Scope *sc) 107 171 { 108 172 Array *d = include(sc, NULL); 109 173 … … 114 178 s->semantic3(sc); 115 179 } 116 180 } 181 return nodefer(); 117 182 } 118 183 119 184 void AttribDeclaration::inlineScan() … … 302 367 return scd; 303 368 } 304 369 305 voidStorageClassDeclaration::semantic(Scope *sc)370 DeferStatus<void> StorageClassDeclaration::semantic(Scope *sc) 306 371 { 307 372 if (decl) 308 373 { unsigned stc_save = sc->stc; … … 310 375 if (stc & (STCauto | STCscope | STCstatic | STCextern)) 311 376 sc->stc &= ~(STCauto | STCscope | STCstatic | STCextern); 312 377 sc->stc |= stc; 313 for (unsigned i = 0; i < decl->dim; i++) 314 { 315 Dsymbol *s = (Dsymbol *)decl->data[i]; 316 317 s->semantic(sc); 318 } 378 callSemanticOnMembers(sc, decl); 319 379 sc->stc = stc_save; 320 380 } 321 381 else 322 382 sc->stc = stc; 383 return nodefer(); 323 384 } 324 385 325 386 void StorageClassDeclaration::stcToCBuffer(OutBuffer *buf, int stc) … … 384 445 return ld; 385 446 } 386 447 387 voidLinkDeclaration::semantic(Scope *sc)448 DeferStatus<void> LinkDeclaration::semantic(Scope *sc) 388 449 { 389 450 //printf("LinkDeclaration::semantic(linkage = %d, decl = %p)\n", linkage, decl); 390 451 if (decl) 391 452 { enum LINK linkage_save = sc->linkage; 392 453 393 454 sc->linkage = linkage; 394 for (unsigned i = 0; i < decl->dim; i++) 395 { 396 Dsymbol *s = (Dsymbol *)decl->data[i]; 397 398 s->semantic(sc); 399 } 455 callSemanticOnMembers(sc, decl); 400 456 sc->linkage = linkage_save; 401 457 } 402 458 else 403 459 { 404 460 sc->linkage = linkage; 405 461 } 462 return nodefer(); 406 463 } 407 464 408 voidLinkDeclaration::semantic3(Scope *sc)465 DeferStatus<void> LinkDeclaration::semantic3(Scope *sc) 409 466 { 410 467 //printf("LinkDeclaration::semantic3(linkage = %d, decl = %p)\n", linkage, decl); 411 468 if (decl) … … 424 481 { 425 482 sc->linkage = linkage; 426 483 } 484 return nodefer(); 427 485 } 428 486 429 487 void LinkDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) … … 473 531 return pd; 474 532 } 475 533 476 voidProtDeclaration::semantic(Scope *sc)534 DeferStatus<void> ProtDeclaration::semantic(Scope *sc) 477 535 { 478 536 if (decl) 479 537 { enum PROT protection_save = sc->protection; … … 481 539 482 540 sc->protection = protection; 483 541 sc->explicitProtection = 1; 484 for (unsigned i = 0; i < decl->dim; i++) 485 { 486 Dsymbol *s = (Dsymbol *)decl->data[i]; 487 488 s->semantic(sc); 489 } 542 callSemanticOnMembers(sc, decl); 490 543 sc->protection = protection_save; 491 544 sc->explicitProtection = explicitProtection_save; 492 545 } … … 494 547 { sc->protection = protection; 495 548 sc->explicitProtection = 1; 496 549 } 550 return nodefer(); 497 551 } 498 552 499 553 void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) … … 532 586 return ad; 533 587 } 534 588 535 voidAlignDeclaration::semantic(Scope *sc)589 DeferStatus<void> AlignDeclaration::semantic(Scope *sc) 536 590 { 537 591 // LDC 538 592 // we only support packed structs, as from the spec: align(1) struct Packed { ... } … … 540 594 541 595 //printf("\tAlignDeclaration::semantic '%s'\n",toChars()); 542 596 if (decl) 543 { unsigned salign_save = sc->structalign; 597 { 598 callSemanticOnMembers(sc, decl); 599 } 600 else 601 assert(0 && "what kind of align use triggers this?"); 602 return nodefer(); 603 } 544 604 545 for (unsigned i = 0; i < decl->dim; i++) 546 { 547 Dsymbol *s = (Dsymbol *)decl->data[i]; 605 DeferStatus<void> AlignDeclaration::runSemantic(Dsymbol* s, Scope* sc) 606 { 607 unsigned salign_save = sc->structalign; 608 DeferStatus<void> ret; 548 609 549 if (s->isStructDeclaration() && salign == 1) 550 { 551 sc->structalign = salign; 552 s->semantic(sc); 553 sc->structalign = salign_save; 554 } 555 else 556 { 557 s->semantic(sc); 558 } 559 } 610 if (s->isStructDeclaration() && salign == 1) 611 { 612 sc->structalign = salign; 613 ret = s->semantic(sc); 560 614 sc->structalign = salign_save; 561 615 } 562 616 else 563 assert(0 && "what kind of align use triggers this?"); 617 { 618 ret = s->semantic(sc); 619 } 620 return ret; 564 621 } 565 622 566 567 623 void AlignDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 568 624 { 569 625 buf->printf("align (%d)", salign); … … 577 633 { 578 634 this->loc = loc; 579 635 this->isunion = isunion; 580 this->scope = NULL;581 636 this->sem = 0; 637 638 sc_offset = -1; 582 639 } 583 640 584 641 Dsymbol *AnonDeclaration::syntaxCopy(Dsymbol *s) … … 590 647 return ad; 591 648 } 592 649 593 void AnonDeclaration::semantic(Scope *sc) 650 // copied from StructDeclaration::isMemberReorderable 651 bool AnonDeclaration::isMemberReorderable(Dsymbol* s) 652 { 653 if ( 654 s->isVarDeclaration() || 655 s->isAttribDeclaration() 656 ) 657 return false; 658 return true; 659 } 660 661 void AnonDeclaration::postMemberSemantic(Scope* sc) 662 { 663 if (isunion) 664 sc->offset = 0; 665 } 666 667 DeferStatus<void> AnonDeclaration::semantic(Scope *sc) 594 668 { 595 669 //printf("\tAnonDeclaration::semantic %s %p\n", isunion ? "union" : "struct", this); 596 670 597 Scope *scx = NULL;598 if (scope)599 { sc = scope;600 scx = scope;601 scope = NULL;602 }603 604 671 assert(sc->parent); 605 672 606 673 Dsymbol *parent = sc->parent->pastMixin(); … … 609 676 if (!ad || (!ad->isStructDeclaration() && !ad->isClassDeclaration())) 610 677 { 611 678 error("can only be a part of an aggregate"); 612 return ;679 return nodefer(); 613 680 } 614 681 615 682 if (decl) 616 683 { 617 AnonymousAggregateDeclaration aad;618 684 int adisunion; 619 685 620 686 if (sc->anonAgg) … … 633 699 sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls); 634 700 sc->inunion = isunion; 635 701 sc->offset = 0; 702 if (sc_offset >= 0) 703 sc->offset = sc_offset; 704 636 705 sc->flags = 0; 637 706 aad.structalign = sc->structalign; 638 707 aad.parent = ad; 639 708 640 for (unsigned i = 0; i < decl->dim; i++) 641 { 642 Dsymbol *s = (Dsymbol *)decl->data[i]; 643 644 s->semantic(sc); 645 if (isunion) 646 sc->offset = 0; 647 if (aad.sizeok == 2) 648 { 649 break; 650 } 709 DeferStatus<void> res = callSemanticOnMembers(sc, decl); 710 if (res.defer()) { 711 sc_offset = sc->offset; 712 sc->pop(); 713 return res; 651 714 } 715 652 716 sc = sc->pop(); 653 717 654 // If failed due to forward references, unwind and try again later655 if (aad.sizeok == 2)656 {657 ad->sizeok = 2;658 //printf("\tsetting ad->sizeok %p to 2\n", ad);659 if (!sc->anonAgg)660 {661 scope = scx ? scx : new Scope(*sc);662 scope->setNoFree();663 scope->module->addDeferredSemantic(this);664 }665 //printf("\tforward reference %p\n", this);666 return;667 }668 718 if (sem == 0) 669 719 { Module::dprogress++; 670 720 sem = 1; … … 720 770 if (ad->alignsize < aad.alignsize) 721 771 ad->alignsize = aad.alignsize; 722 772 } 773 return nodefer(); 723 774 } 724 775 725 776 … … 780 831 return pd; 781 832 } 782 833 783 voidPragmaDeclaration::semantic(Scope *sc)834 DeferStatus<void> PragmaDeclaration::semantic(Scope *sc) 784 835 { // Should be merged with PragmaStatement 785 836 786 837 #if IN_LLVM … … 1166 1217 1167 1218 } 1168 1219 } 1169 return ;1220 return nodefer(); 1170 1221 1171 1222 Lnodecl: 1172 1223 if (decl) 1173 1224 error("pragma is missing closing ';'"); 1225 return nodefer(); 1174 1226 } 1175 1227 1176 1228 int PragmaDeclaration::oneMember(Dsymbol **ps) … … 1418 1470 } 1419 1471 1420 1472 1421 voidStaticIfDeclaration::semantic(Scope *sc)1473 DeferStatus<void> StaticIfDeclaration::semantic(Scope *sc) 1422 1474 { 1423 Array *d = include(sc, sd); 1475 if (!included_decls) 1476 included_decls = include(sc, sd); 1424 1477 1425 1478 //printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d); 1426 if ( d)1479 if (included_decls) 1427 1480 { 1428 1481 if (!addisdone) 1429 1482 { AttribDeclaration::addMember(sc, sd, 1); 1430 1483 addisdone = 1; 1431 1484 } 1432 1485 1433 for (unsigned i = 0; i < d->dim; i++) 1434 { 1435 Dsymbol *s = (Dsymbol *)d->data[i]; 1436 1437 s->semantic(sc); 1438 } 1486 callSemanticOnMembers(sc, included_decls); 1439 1487 } 1488 return nodefer(); 1440 1489 } 1441 1490 1442 1491 const char *StaticIfDeclaration::kind() … … 1500 1549 } 1501 1550 } 1502 1551 1503 voidCompileDeclaration::semantic(Scope *sc)1552 DeferStatus<void> CompileDeclaration::semantic(Scope *sc) 1504 1553 { 1505 1554 //printf("CompileDeclaration::semantic()\n"); 1506 1555 … … 1511 1560 compiled = 1; 1512 1561 } 1513 1562 AttribDeclaration::semantic(sc); 1563 return nodefer(); 1514 1564 } 1515 1565 1516 1566 void CompileDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) -
a/dmd/attrib.h
old new 16 16 #endif /* __DMC__ */ 17 17 18 18 #include "dsymbol.h" 19 #include "aggregate.h" 19 20 20 21 struct Expression; 21 22 struct Statement; … … 36 37 AttribDeclaration(Array *decl); 37 38 virtual Array *include(Scope *sc, ScopeDsymbol *s); 38 39 int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 39 voidsemantic(Scope *sc);40 voidsemantic2(Scope *sc);41 voidsemantic3(Scope *sc);40 DeferStatus<void> semantic(Scope *sc); 41 DeferStatus<void> semantic2(Scope *sc); 42 DeferStatus<void> semantic3(Scope *sc); 42 43 void inlineScan(); 43 44 void addComment(unsigned char *comment); 44 45 void emitComment(Scope *sc); … … 58 59 #if IN_LLVM 59 60 virtual void codegen(Ir*); 60 61 #endif 62 63 // LDC 64 Array *included_decls; 65 std::deque<Dsymbol*> remaining_semantic; 66 bool member_semantic_started; 67 68 DeferStatus<void> callSemanticOnMembers(Scope* sc, Array* members); 69 virtual DeferStatus<void> runSemantic(Dsymbol* s, Scope* sc) { return s->semantic(sc); } 70 virtual void postMemberSemantic(Scope* sc) {}; 71 virtual bool isMemberReorderable(Dsymbol* sym) { return true; } 61 72 }; 62 73 63 74 struct StorageClassDeclaration: AttribDeclaration … … 66 77 67 78 StorageClassDeclaration(unsigned stc, Array *decl); 68 79 Dsymbol *syntaxCopy(Dsymbol *s); 69 voidsemantic(Scope *sc);80 DeferStatus<void> semantic(Scope *sc); 70 81 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 71 82 72 83 static void stcToCBuffer(OutBuffer *buf, int stc); … … 78 89 79 90 LinkDeclaration(enum LINK p, Array *decl); 80 91 Dsymbol *syntaxCopy(Dsymbol *s); 81 voidsemantic(Scope *sc);82 voidsemantic3(Scope *sc);92 DeferStatus<void> semantic(Scope *sc); 93 DeferStatus<void> semantic3(Scope *sc); 83 94 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 84 95 char *toChars(); 85 96 }; … … 90 101 91 102 ProtDeclaration(enum PROT p, Array *decl); 92 103 Dsymbol *syntaxCopy(Dsymbol *s); 93 voidsemantic(Scope *sc);104 DeferStatus<void> semantic(Scope *sc); 94 105 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 95 106 }; 96 107 … … 100 111 101 112 AlignDeclaration(Loc loc, unsigned sa, Array *decl); 102 113 Dsymbol *syntaxCopy(Dsymbol *s); 103 voidsemantic(Scope *sc);114 DeferStatus<void> semantic(Scope *sc); 104 115 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 116 117 DeferStatus<void> runSemantic(Dsymbol* s, Scope* sc); 105 118 }; 106 119 107 120 struct AnonDeclaration : AttribDeclaration 108 121 { 109 122 int isunion; 110 Scope *scope; // !=NULL means context to use111 123 int sem; // 1 if successful semantic() 112 124 113 125 AnonDeclaration(Loc loc, int isunion, Array *decl); 114 126 Dsymbol *syntaxCopy(Dsymbol *s); 115 voidsemantic(Scope *sc);127 DeferStatus<void> semantic(Scope *sc); 116 128 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 117 129 const char *kind(); 130 131 void postMemberSemantic(Scope* sc); 132 bool isMemberReorderable(Dsymbol* sym); 133 int sc_offset; // saved next offset in aggregate 134 AnonymousAggregateDeclaration aad; 118 135 }; 119 136 120 137 struct PragmaDeclaration : AttribDeclaration … … 123 140 124 141 PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Array *decl); 125 142 Dsymbol *syntaxCopy(Dsymbol *s); 126 voidsemantic(Scope *sc);143 DeferStatus<void> semantic(Scope *sc); 127 144 int oneMember(Dsymbol **ps); 128 145 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 129 146 const char *kind(); … … 159 176 StaticIfDeclaration(Condition *condition, Array *decl, Array *elsedecl); 160 177 Dsymbol *syntaxCopy(Dsymbol *s); 161 178 int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 162 voidsemantic(Scope *sc);179 DeferStatus<void> semantic(Scope *sc); 163 180 const char *kind(); 164 181 }; 165 182 … … 176 193 Dsymbol *syntaxCopy(Dsymbol *s); 177 194 int addMember(Scope *sc, ScopeDsymbol *sd, int memnum); 178 195 void compileIt(Scope *sc); 179 voidsemantic(Scope *sc);196 DeferStatus<void> semantic(Scope *sc); 180 197 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 181 198 }; 182 199 -
a/dmd/class.c
old new 41 41 this->baseclasses = *baseclasses; 42 42 baseClass = NULL; 43 43 44 deferState = 0; 45 44 46 interfaces_dim = 0; 45 47 interfaces = NULL; 46 48 … … 215 217 return cd; 216 218 } 217 219 218 voidClassDeclaration::semantic(Scope *sc)220 DeferStatus<void> ClassDeclaration::semantic(Scope *sc) 219 221 { int i; 220 222 unsigned offset; 223 Scope scsave; 224 Scope *scx = NULL; 225 DeferStatus<void> defers; 221 226 222 227 //printf("ClassDeclaration::semantic(%s), type = %p, sizeok = %d, this = %p\n", toChars(), type, sizeok, this); 223 228 //printf("\tparent = %p, '%s'\n", sc->parent, sc->parent ? sc->parent->toChars() : ""); … … 225 230 226 231 //{ static int n; if (++n == 20) *(char*)0=0; } 227 232 233 int continueAt = deferState; 234 if (deferState > 0) 235 deferState = 0; 236 switch (continueAt) { 237 case 0: 238 228 239 if (!ident) // if anonymous class 229 240 { char *id = "__anonclass"; 230 241 231 242 ident = Identifier::generateId(id); 232 243 } 233 244 234 if (!scope) 235 { 236 if (!parent && sc->parent && !sc->parent->isModule()) 237 parent = sc->parent; 245 if (!parent && sc->parent && !sc->parent->isModule()) 246 parent = sc->parent; 238 247 239 type = type->semantic(loc, sc);240 handle = handle->semantic(loc, sc);241 } 248 type = type->semantic(loc, sc); 249 handle = handle->semantic(loc, sc); 250 242 251 if (!members) // if forward reference 243 252 { //printf("\tclass '%s' is forward referenced\n", toChars()); 244 return ;253 return nodefer(); 245 254 } 246 255 if (symtab) 247 { if (!scope) 248 { //printf("\tsemantic for '%s' is already completed\n", toChars()); 249 return; // semantic() already completed 250 } 256 { 257 return nodefer(); // semantic() already completed 251 258 } 252 259 else 253 260 symtab = new DsymbolTable(); 254 261 255 Scope *scx = NULL;256 if (scope)257 { sc = scope;258 scx = scope; // save so we don't make redundant copies259 scope = NULL;260 }261 262 #ifdef IN_GCC 262 263 methods.setDim(0); 263 264 #endif … … 288 289 i++; 289 290 } 290 291 292 case 1: 291 293 // See if there's a base class as first in baseclasses[] 292 294 if (baseclasses.dim) 293 295 { TypeClass *tc; … … 329 331 goto L7; 330 332 } 331 333 } 332 if (!tc->sym->symtab || tc->sym-> scope|| tc->sym->sizeok == 0)334 if (!tc->sym->symtab || tc->sym->deferState > 0 || tc->sym->sizeok == 0) 333 335 { 334 336 //error("forward reference of base class %s", baseClass->toChars()); 335 337 // Forward reference of base class, try again later 336 338 //printf("\ttry later, forward reference of base class %s\n", tc->sym->toChars()); 337 scope = scx ? scx : new Scope(*sc);338 sc ope->setNoFree();339 scope->module->addDeferredSemantic(this);340 return;339 deferState = 1; 340 sc->module->addDeferredSemantic(this, sc); 341 return nodefer(); 342 //throw new DeferException(loc, "forward reference of base class %s", tc->sym->toChars()); 341 343 } 342 344 else 343 345 { baseClass = tc->sym; … … 348 350 } 349 351 } 350 352 353 case 2: 351 354 // Treat the remaining entries in baseclasses as interfaces 352 355 // Check for errors, handle forward references 353 356 for (i = (baseClass ? 1 : 0); i < baseclasses.dim; ) … … 390 393 } 391 394 392 395 b->base = tc->sym; 393 if (!b->base->symtab || b->base-> scope)396 if (!b->base->symtab || b->base->deferState > 0) 394 397 { 395 398 //error("forward reference of base class %s", baseClass->toChars()); 396 399 // Forward reference of base, try again later 397 400 //printf("\ttry later, forward reference of base %s\n", baseClass->toChars()); 398 scope = scx ? scx : new Scope(*sc);399 sc ope->setNoFree();400 scope->module->addDeferredSemantic(this);401 return;401 deferState = 2; 402 sc->module->addDeferredSemantic(this, sc); 403 return nodefer(); 404 //throw new DeferException(loc, "forward reference of interface %s", baseClass->toChars()); 402 405 } 403 406 } 404 407 i++; … … 534 537 if (storage_class & STCabstract) 535 538 isabstract = 1; 536 539 540 structalign = 8; 541 if (baseClass) 542 { sc_offset = baseClass->structsize; 543 alignsize = baseClass->alignsize; 544 // if (isnested) 545 // sc->offset += PTRSIZE; // room for uplevel context pointer 546 } 547 else 548 { sc_offset = PTRSIZE * 2; // allow room for vptr[] and monitor 549 alignsize = PTRSIZE; 550 } 551 structsize = sc_offset; 552 sizeok = 0; 553 554 case 3: 537 555 sc = sc->push(this); 538 556 sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | 539 557 STCabstract | STCdeprecated); … … 554 572 sc->protection = PROTpublic; 555 573 sc->explicitProtection = 0; 556 574 sc->structalign = 8; 557 structalign = sc->structalign; 558 if (baseClass) 559 { sc->offset = baseClass->structsize; 560 alignsize = baseClass->alignsize; 561 // if (isnested) 562 // sc->offset += PTRSIZE; // room for uplevel context pointer 563 } 564 else 565 { sc->offset = PTRSIZE * 2; // allow room for vptr[] and monitor 566 alignsize = PTRSIZE; 567 } 568 structsize = sc->offset; 569 Scope scsave = *sc; 570 int members_dim = members->dim; 571 sizeok = 0; 572 for (i = 0; i < members_dim; i++) 573 { 574 Dsymbol *s = (Dsymbol *)members->data[i]; 575 s->semantic(sc); 576 } 577 578 if (sizeok == 2) 579 { // semantic() failed because of forward references. 580 // Unwind what we did, and defer it for later 581 fields.setDim(0); 582 structsize = 0; 583 alignsize = 0; 584 structalign = 0; 585 575 576 if (sc_offset >= 0) 577 sc->offset = sc_offset; 578 579 scsave = *sc; 580 581 defers = callSemanticOnMembers(sc); 582 if (defers.defer()) { 583 sc_offset = sc->offset; 584 deferState = 3; 586 585 sc = sc->pop(); 587 588 scope = scx ? scx : new Scope(*sc); 589 scope->setNoFree(); 590 scope->module->addDeferredSemantic(this); 591 592 //printf("\tsemantic('%s') failed due to forward references\n", toChars()); 593 return; 586 return defers; 594 587 } 595 588 596 589 //printf("\tsemantic('%s') successful\n", toChars()); … … 601 594 /* Look for special member functions. 602 595 * They must be in this class, not in a base class. 603 596 */ 604 ctor = (CtorDeclaration *) search(0, Id::ctor, 0);597 ctor = (CtorDeclaration *)(Dsymbol *)search(0, Id::ctor, 0); 605 598 if (ctor && (ctor->toParent() != this || !ctor->isCtorDeclaration())) 606 599 ctor = NULL; 607 600 … … 614 607 // inv = NULL; 615 608 616 609 // Can be in base class 617 aggNew = (NewDeclaration *) search(0, Id::classNew, 0);618 aggDelete = (DeleteDeclaration *) search(0, Id::classDelete, 0);610 aggNew = (NewDeclaration *)(Dsymbol *)search(0, Id::classNew, 0); 611 aggDelete = (DeleteDeclaration *)(Dsymbol *)search(0, Id::classDelete, 0); 619 612 620 613 // If this class has no constructor, but base class does, create 621 614 // a constructor: … … 681 674 } 682 675 #endif 683 676 //printf("-ClassDeclaration::semantic(%s), type = %p\n", toChars(), type); 677 678 deferState = -1; 679 case -1: 680 break; 681 default: 682 assert(0 && "deferState for classes must be between -1 and 3"); 683 } // switch for deferred calling 684 return nodefer(); 684 685 } 685 686 686 687 void ClassDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) … … 772 773 return 0; 773 774 } 774 775 775 D symbol *ClassDeclaration::search(Loc loc, Identifier *ident, int flags)776 DeferStatus<Dsymbol*> ClassDeclaration::search(Loc loc, Identifier *ident, int flags) 776 777 { 777 778 Dsymbol *s; 778 779 779 780 //printf("%s.ClassDeclaration::search('%s')\n", toChars(), ident->toChars()); 780 if (scope) 781 semantic(scope); 781 s = ScopeDsymbol::search(loc, ident, flags); 782 782 783 if (!members || !symtab || scope) 784 { error("is forward referenced when looking for '%s'", ident->toChars()); 785 //*(char*)0=0; 786 return NULL; 783 if (!s && (!members || !symtab || deferState > 0)) 784 { 785 return defer<Dsymbol*>(loc, "%s is forward referenced when looking for '%s'", toChars(), ident->toChars()); 787 786 } 788 787 789 s = ScopeDsymbol::search(loc, ident, flags);790 788 if (!s) 791 789 { 792 790 // Search bases classes in depth-first, left to right order … … 998 996 return id; 999 997 } 1000 998 1001 voidInterfaceDeclaration::semantic(Scope *sc)999 DeferStatus<void> InterfaceDeclaration::semantic(Scope *sc) 1002 1000 { int i; 1001 Scope *scx = NULL; 1002 DeferStatus<void> defers; 1003 1003 1004 int continueAt = deferState; 1005 if (deferState > 0) 1006 deferState = 0; 1007 switch (continueAt) { 1008 case 0: 1004 1009 //printf("InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type); 1005 1010 if (inuse) 1006 return ;1007 if (!scope) 1008 {type = type->semantic(loc, sc);1009 handle = handle->semantic(loc, sc);1010 } 1011 return nodefer(); 1012 1013 type = type->semantic(loc, sc); 1014 handle = handle->semantic(loc, sc); 1015 1011 1016 if (!members) // if forward reference 1012 1017 { //printf("\tinterface '%s' is forward referenced\n", toChars()); 1013 return ;1018 return nodefer(); 1014 1019 } 1015 1020 if (symtab) // if already done 1016 { if (!scope)1017 return;1021 { 1022 return nodefer(); 1018 1023 } 1019 1024 else 1020 1025 symtab = new DsymbolTable(); 1021 1026 1022 Scope *scx = NULL;1023 if (scope)1024 { sc = scope;1025 scx = scope; // save so we don't make redundant copies1026 scope = NULL;1027 }1028 1029 1027 if (sc->stc & STCdeprecated) 1030 1028 { 1031 1029 isdeprecated = 1; … … 1052 1050 i++; 1053 1051 } 1054 1052 1053 case 1: 1055 1054 // Check for errors, handle forward references 1056 1055 for (i = 0; i < baseclasses.dim; ) 1057 1056 { TypeClass *tc; … … 1088 1087 baseclasses.remove(i); 1089 1088 continue; 1090 1089 } 1091 if (!b->base->symtab || b->base-> scope|| b->base->inuse)1090 if (!b->base->symtab || b->base->deferState > 0 || b->base->inuse) 1092 1091 { 1093 1092 //error("forward reference of base class %s", baseClass->toChars()); 1094 1093 // Forward reference of base, try again later 1095 1094 //printf("\ttry later, forward reference of base %s\n", b->base->toChars()); 1096 scope = scx ? scx : new Scope(*sc);1097 sc ope->setNoFree();1098 scope->module->addDeferredSemantic(this);1099 return;1095 deferState = 1; 1096 sc->module->addDeferredSemantic(this, sc); 1097 return nodefer(); 1098 //throw new DeferException(loc, "forward reference of interface %s", baseClass->toChars()); 1100 1099 } 1101 1100 } 1102 1101 i++; … … 1146 1145 s->addMember(sc, this, 1); 1147 1146 } 1148 1147 1148 case 2: 1149 1149 sc = sc->push(this); 1150 1150 sc->parent = this; 1151 1151 if (isCOMinterface()) … … 1153 1153 sc->structalign = 8; 1154 1154 structalign = sc->structalign; 1155 1155 sc->offset = PTRSIZE * 2; 1156 if (sc_offset >= 0) 1157 sc->offset = sc_offset; 1158 1156 1159 inuse++; 1157 for (i = 0; i < members->dim; i++) 1158 { 1159 Dsymbol *s = (Dsymbol *)members->data[i]; 1160 s->semantic(sc); 1160 1161 defers = callSemanticOnMembers(sc); 1162 if (defers.defer()) { 1163 sc_offset = sc->offset; 1164 deferState = 2; 1165 sc = sc->pop(); 1166 inuse--; 1167 return defers; 1161 1168 } 1162 1169 inuse--; 1163 1170 //members->print(); 1164 1171 sc->pop(); 1165 1172 //printf("-InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type); 1173 1174 deferState = -1; 1175 case -1: 1176 break; 1177 default: 1178 assert(0 && "deferState for interfaces must be between -1 and 2"); 1179 } // switch for deferStatus 1180 return nodefer(); 1166 1181 } 1167 1182 1168 1183 -
a/dmd/declaration.c
old new 36 36 inuse = 0; 37 37 } 38 38 39 voidDeclaration::semantic(Scope *sc)39 DeferStatus<void> Declaration::semantic(Scope *sc) 40 40 { 41 return nodefer(); 41 42 } 42 43 43 44 const char *Declaration::kind() … … 293 294 return st; 294 295 } 295 296 296 voidTypedefDeclaration::semantic(Scope *sc)297 DeferStatus<void> TypedefDeclaration::semantic(Scope *sc) 297 298 { 298 299 //printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem); 299 300 if (sem == 0) … … 309 310 { 310 311 error("circular definition"); 311 312 } 313 return nodefer(); 312 314 } 313 315 314 voidTypedefDeclaration::semantic2(Scope *sc)316 DeferStatus<void> TypedefDeclaration::semantic2(Scope *sc) 315 317 { 316 318 //printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem); 317 319 if (sem == 2) … … 328 330 } 329 331 } 330 332 } 333 return nodefer(); 331 334 } 332 335 333 336 const char *TypedefDeclaration::kind() … … 421 424 return sa; 422 425 } 423 426 424 voidAliasDeclaration::semantic(Scope *sc)427 DeferStatus<void> AliasDeclaration::semantic(Scope *sc) 425 428 { 426 429 //printf("AliasDeclaration::semantic() %s\n", toChars()); 427 430 if (aliassym) 428 431 { 429 432 if (aliassym->isTemplateInstance()) 430 433 aliassym->semantic(sc); 431 return ;434 return nodefer(); 432 435 } 433 436 this->inSemantic = 1; 434 437 … … 488 491 if (overnext) 489 492 ScopeDsymbol::multiplyDefined(0, this, overnext); 490 493 this->inSemantic = 0; 491 return ;494 return nodefer(); 492 495 493 496 L2: 494 497 //printf("alias is a symbol %s %s\n", s->kind(), s->toChars()); … … 525 528 } 526 529 aliassym = s; 527 530 this->inSemantic = 0; 531 return nodefer(); 528 532 } 529 533 530 534 int AliasDeclaration::overloadInsert(Dsymbol *s) … … 680 684 return sv; 681 685 } 682 686 683 voidVarDeclaration::semantic(Scope *sc)687 DeferStatus<void> VarDeclaration::semantic(Scope *sc) 684 688 { 685 689 //printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars()); 686 690 //printf(" type = %s\n", type ? type->toChars() : "null"); … … 698 702 int inferred = 0; 699 703 if (!type) 700 704 { inuse++; 701 type = init->inferType(sc); 705 DeferStatus<Type*> res = init->inferType(sc); 706 if (res.defer()) { 707 inuse--; 708 return res; 709 } 710 type = res; 702 711 inuse--; 703 712 inferred = 1; 704 713 … … 711 720 else 712 721 { if (!originalType) 713 722 originalType = type; 714 type = type->semantic(loc, sc); 723 DeferStatus<Type*> ret = type->semantic(loc, sc); 724 if (ret.defer()) 725 return ret; 726 type = ret; 715 727 } 716 728 //printf(" semantic type = %s\n", type ? type->toChars() : "null"); 717 729 … … 793 805 TupleDeclaration *v2 = new TupleDeclaration(loc, ident, exps); 794 806 v2->isexp = 1; 795 807 aliassym = v2; 796 return ;808 return nodefer(); 797 809 } 798 810 799 811 if (storage_class & STCconst && !init && !fd) … … 828 840 aad = parent->isAggregateDeclaration(); 829 841 if (aad) 830 842 { 831 aad->addField(sc, this); 843 DeferStatus<void> ret = aad->addField(sc, this); 844 if (ret.defer()) 845 return ret; 832 846 } 833 847 834 848 InterfaceDeclaration *id = parent->isInterfaceDeclaration(); … … 894 908 e = new AssignExp(loc, e1, e); 895 909 e->type = e1->type; 896 910 init = new ExpInitializer(loc, e/*->type->defaultInit()*/); 897 return ;911 return nodefer(); 898 912 } 899 913 else if (type->ty == Ttypedef) 900 914 { TypeTypedef *td = (TypeTypedef *)type; … … 956 970 e = init->toExpression(); 957 971 if (!e) 958 972 { error("is not a static and cannot have static initializer"); 959 return ;973 return nodefer(); 960 974 } 961 975 } 962 976 ei = new ExpInitializer(init->loc, e); … … 1025 1039 if (ei) 1026 1040 { 1027 1041 e = ei->exp->syntaxCopy(); 1028 e = e->semantic(sc); 1042 DeferStatus<Expression*> res = e->semantic(sc); 1043 if (res.defer()) { 1044 inuse--; 1045 global.gag--; 1046 return res; 1047 } 1048 e = res; 1029 1049 e = e->implicitCastTo(sc, type); 1030 1050 } 1031 1051 else if (si || ai) … … 1054 1074 } 1055 1075 sc = sc->pop(); 1056 1076 } 1077 return nodefer(); 1057 1078 } 1058 1079 1059 1080 ExpInitializer *VarDeclaration::getExpInitializer() … … 1073 1094 return ei; 1074 1095 } 1075 1096 1076 voidVarDeclaration::semantic2(Scope *sc)1097 DeferStatus<void> VarDeclaration::semantic2(Scope *sc) 1077 1098 { 1078 1099 //printf("VarDeclaration::semantic2('%s')\n", toChars()); 1079 1100 if (init && !toParent()->isFuncDeclaration()) … … 1089 1110 init = init->semantic(sc, type); 1090 1111 inuse--; 1091 1112 } 1113 return nodefer(); 1092 1114 } 1093 1115 1094 1116 const char *VarDeclaration::kind() … … 1249 1271 return NULL; 1250 1272 } 1251 1273 1252 voidClassInfoDeclaration::semantic(Scope *sc)1274 DeferStatus<void> ClassInfoDeclaration::semantic(Scope *sc) 1253 1275 { 1276 return nodefer(); 1254 1277 } 1255 1278 1256 1279 /********************************* ModuleInfoDeclaration ****************************/ … … 1268 1291 return NULL; 1269 1292 } 1270 1293 1271 voidModuleInfoDeclaration::semantic(Scope *sc)1294 DeferStatus<void> ModuleInfoDeclaration::semantic(Scope *sc) 1272 1295 { 1296 return nodefer(); 1273 1297 } 1274 1298 1275 1299 /********************************* TypeInfoDeclaration ****************************/ … … 1289 1313 return NULL; 1290 1314 } 1291 1315 1292 voidTypeInfoDeclaration::semantic(Scope *sc)1316 DeferStatus<void> TypeInfoDeclaration::semantic(Scope *sc) 1293 1317 { 1294 1318 assert(linkage == LINKc); 1319 return nodefer(); 1295 1320 } 1296 1321 1297 1322 /***************************** TypeInfoConstDeclaration **********************/ -
a/dmd/declaration.h
old new 109 109 int inuse; // used to detect cycles 110 110 111 111 Declaration(Identifier *id); 112 voidsemantic(Scope *sc);112 DeferStatus<void> semantic(Scope *sc); 113 113 const char *kind(); 114 114 unsigned size(Loc loc); 115 115 void checkModify(Loc loc, Scope *sc, Type *t); … … 186 186 187 187 TypedefDeclaration(Loc loc, Identifier *ident, Type *basetype, Initializer *init); 188 188 Dsymbol *syntaxCopy(Dsymbol *); 189 voidsemantic(Scope *sc);190 voidsemantic2(Scope *sc);189 DeferStatus<void> semantic(Scope *sc); 190 DeferStatus<void> semantic2(Scope *sc); 191 191 char *mangle(); 192 192 const char *kind(); 193 193 Type *getType(); … … 230 230 AliasDeclaration(Loc loc, Identifier *ident, Type *type); 231 231 AliasDeclaration(Loc loc, Identifier *ident, Dsymbol *s); 232 232 Dsymbol *syntaxCopy(Dsymbol *); 233 voidsemantic(Scope *sc);233 DeferStatus<void> semantic(Scope *sc); 234 234 int overloadInsert(Dsymbol *s); 235 235 const char *kind(); 236 236 Type *getType(); … … 265 265 266 266 VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init); 267 267 Dsymbol *syntaxCopy(Dsymbol *); 268 voidsemantic(Scope *sc);269 voidsemantic2(Scope *sc);268 DeferStatus<void> semantic(Scope *sc); 269 DeferStatus<void> semantic2(Scope *sc); 270 270 const char *kind(); 271 271 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 272 272 #ifdef _DH … … 333 333 334 334 ClassInfoDeclaration(ClassDeclaration *cd); 335 335 Dsymbol *syntaxCopy(Dsymbol *); 336 voidsemantic(Scope *sc);336 DeferStatus<void> semantic(Scope *sc); 337 337 338 338 void emitComment(Scope *sc); 339 339 … … 350 350 351 351 ModuleInfoDeclaration(Module *mod); 352 352 Dsymbol *syntaxCopy(Dsymbol *); 353 voidsemantic(Scope *sc);353 DeferStatus<void> semantic(Scope *sc); 354 354 355 355 void emitComment(Scope *sc); 356 356 … … 365 365 366 366 TypeInfoDeclaration(Type *tinfo, int internal); 367 367 Dsymbol *syntaxCopy(Dsymbol *); 368 voidsemantic(Scope *sc);368 DeferStatus<void> semantic(Scope *sc); 369 369 370 370 void emitComment(Scope *sc); 371 371 … … 680 680 681 681 FuncDeclaration(Loc loc, Loc endloc, Identifier *id, enum STC storage_class, Type *type); 682 682 Dsymbol *syntaxCopy(Dsymbol *); 683 voidsemantic(Scope *sc);684 voidsemantic2(Scope *sc);685 voidsemantic3(Scope *sc);683 DeferStatus<void> semantic(Scope *sc); 684 DeferStatus<void> semantic2(Scope *sc); 685 DeferStatus<void> semantic3(Scope *sc); 686 686 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 687 687 void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs); 688 688 int overrides(FuncDeclaration *fd); … … 794 794 795 795 CtorDeclaration(Loc loc, Loc endloc, Arguments *arguments, int varargs); 796 796 Dsymbol *syntaxCopy(Dsymbol *); 797 voidsemantic(Scope *sc);797 DeferStatus<void> semantic(Scope *sc); 798 798 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 799 799 const char *kind(); 800 800 char *toChars(); … … 812 812 PostBlitDeclaration(Loc loc, Loc endloc); 813 813 PostBlitDeclaration(Loc loc, Loc endloc, Identifier *id); 814 814 Dsymbol *syntaxCopy(Dsymbol *); 815 voidsemantic(Scope *sc);815 DeferStatus<void> semantic(Scope *sc); 816 816 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 817 817 int isVirtual(); 818 818 int addPreInvariant(); … … 829 829 DtorDeclaration(Loc loc, Loc endloc); 830 830 DtorDeclaration(Loc loc, Loc endloc, Identifier *id); 831 831 Dsymbol *syntaxCopy(Dsymbol *); 832 voidsemantic(Scope *sc);832 DeferStatus<void> semantic(Scope *sc); 833 833 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 834 834 int isVirtual(); 835 835 int addPreInvariant(); … … 844 844 { 845 845 StaticCtorDeclaration(Loc loc, Loc endloc); 846 846 Dsymbol *syntaxCopy(Dsymbol *); 847 voidsemantic(Scope *sc);847 DeferStatus<void> semantic(Scope *sc); 848 848 AggregateDeclaration *isThis(); 849 849 int isStaticConstructor(); 850 850 int isVirtual(); … … 861 861 862 862 StaticDtorDeclaration(Loc loc, Loc endloc); 863 863 Dsymbol *syntaxCopy(Dsymbol *); 864 voidsemantic(Scope *sc);864 DeferStatus<void> semantic(Scope *sc); 865 865 AggregateDeclaration *isThis(); 866 866 int isStaticDestructor(); 867 867 int isVirtual(); … … 877 877 { 878 878 InvariantDeclaration(Loc loc, Loc endloc); 879 879 Dsymbol *syntaxCopy(Dsymbol *); 880 voidsemantic(Scope *sc);880 DeferStatus<void> semantic(Scope *sc); 881 881 int isVirtual(); 882 882 int addPreInvariant(); 883 883 int addPostInvariant(); … … 892 892 { 893 893 UnitTestDeclaration(Loc loc, Loc endloc); 894 894 Dsymbol *syntaxCopy(Dsymbol *); 895 voidsemantic(Scope *sc);895 DeferStatus<void> semantic(Scope *sc); 896 896 AggregateDeclaration *isThis(); 897 897 int isVirtual(); 898 898 int addPreInvariant(); … … 908 908 909 909 NewDeclaration(Loc loc, Loc endloc, Arguments *arguments, int varargs); 910 910 Dsymbol *syntaxCopy(Dsymbol *); 911 voidsemantic(Scope *sc);911 DeferStatus<void> semantic(Scope *sc); 912 912 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 913 913 const char *kind(); 914 914 int isVirtual(); … … 924 924 925 925 DeleteDeclaration(Loc loc, Loc endloc, Arguments *arguments); 926 926 Dsymbol *syntaxCopy(Dsymbol *); 927 voidsemantic(Scope *sc);927 DeferStatus<void> semantic(Scope *sc); 928 928 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 929 929 const char *kind(); 930 930 int isDelete(); -
a/dmd/dsymbol.c
old new 266 266 return ident ? 0 : 1; 267 267 } 268 268 269 voidDsymbol::semantic(Scope *sc)269 DeferStatus<void> Dsymbol::semantic(Scope *sc) 270 270 { 271 271 error("%p has no semantic routine", this); 272 return nodefer(); 272 273 } 273 274 274 voidDsymbol::semantic2(Scope *sc)275 DeferStatus<void> Dsymbol::semantic2(Scope *sc) 275 276 { 276 277 // Most Dsymbols have no further semantic analysis needed 278 return nodefer(); 277 279 } 278 280 279 voidDsymbol::semantic3(Scope *sc)281 DeferStatus<void> Dsymbol::semantic3(Scope *sc) 280 282 { 281 283 // Most Dsymbols have no further semantic analysis needed 284 return nodefer(); 282 285 } 283 286 284 287 void Dsymbol::inlineScan() … … 296 299 * NULL if not found 297 300 */ 298 301 299 D symbol *Dsymbol::search(Loc loc, Identifier *ident, int flags)302 DeferStatus<Dsymbol*> Dsymbol::search(Loc loc, Identifier *ident, int flags) 300 303 { 301 304 //printf("Dsymbol::search(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars()); 302 305 return NULL; … … 309 312 * symbol found, NULL if not 310 313 */ 311 314 312 D symbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id)315 DeferStatus<Dsymbol*> Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id) 313 316 { 314 317 //printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars()); 315 318 Dsymbol *s = toAlias(); … … 318 321 switch (id->dyncast()) 319 322 { 320 323 case DYNCAST_IDENTIFIER: 321 sm = s->search(loc, id, 0); 322 break; 324 return s->search(loc, id, 0); 323 325 324 326 case DYNCAST_DSYMBOL: 325 327 { // It's a template instance … … 654 656 symtab = NULL; 655 657 imports = NULL; 656 658 prots = NULL; 659 member_semantic_started = false; 657 660 } 658 661 659 662 ScopeDsymbol::ScopeDsymbol(Identifier *id) … … 663 666 symtab = NULL; 664 667 imports = NULL; 665 668 prots = NULL; 669 member_semantic_started = false; 666 670 } 667 671 668 672 Dsymbol *ScopeDsymbol::syntaxCopy(Dsymbol *s) … … 678 682 return sd; 679 683 } 680 684 681 D symbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)685 DeferStatus<Dsymbol*> ScopeDsymbol::search(Loc loc, Identifier *ident, int flags) 682 686 { 683 687 //printf("%s->ScopeDsymbol::search(ident='%s', flags=x%x)\n", toChars(), ident->toChars(), flags); 684 688 … … 779 783 } 780 784 } 781 785 } 782 imports->push(s); 783 prots = (unsigned char *)mem.realloc(prots, imports->dim * sizeof(prots[0])); 784 prots[imports->dim - 1] = protection; 786 bool in_imports = false; 787 for (int i = 0; i < imports->dim; ++i) 788 if (imports->data[i] == s) 789 in_imports = true; 790 if (!in_imports) 791 { 792 imports->push(s); 793 prots = (unsigned char *)mem.realloc(prots, imports->dim * sizeof(prots[0])); 794 prots[imports->dim - 1] = protection; 795 } 785 796 } 786 797 } 787 798 … … 849 860 return "ScopeDsymbol"; 850 861 } 851 862 863 // shares code with AttribDeclaration::callSemanticOnMembers 864 DeferStatus<void> ScopeDsymbol::callSemanticOnMembers(Scope* sc) 865 { 866 // first add everything to remaining_semantic 867 if (!member_semantic_started) { 868 for (int i = 0; i < members->dim; i++) 869 remaining_semantic.push_back( (Dsymbol*)members->data[i] ); 870 member_semantic_started = true; 871 } 872 873 int failed = 0; 874 875 // last defer exception that was caught. stored for the error message inside 876 DeferStatus<void> lastdefer; 877 878 // if we deferred an order dependent member, save it here 879 // we will then skip all order dependent members until this is reached again 880 Dsymbol *deferredOrderDependent = NULL; 881 882 while (!remaining_semantic.empty() && failed != remaining_semantic.size()) 883 { Dsymbol *s; 884 s = remaining_semantic[0]; 885 remaining_semantic.pop_front(); 886 887 // if we deferred something order dependent, skip other 888 // order dependent ones for one iteration 889 if (deferredOrderDependent == s) 890 deferredOrderDependent = NULL; 891 if (deferredOrderDependent && !isMemberReorderable(s)) { 892 ++failed; 893 remaining_semantic.push_back(s); 894 continue; 895 } 896 897 DeferStatus<void> res = s->semantic(sc); 898 if (res.defer()) { 899 lastdefer = res; 900 ++failed; 901 remaining_semantic.push_back(s); 902 if (!isMemberReorderable(s)) 903 deferredOrderDependent = s; 904 continue; 905 } 906 907 failed = 0; 908 postMemberSemantic(sc); 909 } 910 911 if (!remaining_semantic.empty()) 912 { 913 assert(lastdefer.defer()); 914 915 // reorder members into a valid state if necessary 916 if (deferredOrderDependent) 917 while (remaining_semantic[0] != deferredOrderDependent) { 918 Dsymbol* s = remaining_semantic[0]; 919 remaining_semantic.pop_front(); 920 remaining_semantic.push_back(s); 921 } 922 return lastdefer; 923 } 924 925 lastdefer.handled = true; 926 return nodefer(); 927 } 928 852 929 853 930 /******************************************* 854 931 * Look for member of the form: … … 895 972 this->withstate = withstate; 896 973 } 897 974 898 D symbol *WithScopeSymbol::search(Loc loc, Identifier *ident, int flags)975 DeferStatus<Dsymbol*> WithScopeSymbol::search(Loc loc, Identifier *ident, int flags) 899 976 { 900 977 // Acts as proxy to the with class declaration 901 978 return withstate->exp->type->toDsymbol(NULL)->search(loc, ident, 0); … … 928 1005 td = s; 929 1006 } 930 1007 931 D symbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags)1008 DeferStatus<Dsymbol*> ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags) 932 1009 { 933 1010 //printf("ArrayScopeSymbol::search('%s', flags = %d)\n", ident->toChars(), flags); 934 1011 if (ident == Id::length || ident == Id::dollar) … … 1016 1093 return NULL; 1017 1094 } 1018 1095 1019 1020 1096 /****************************** DsymbolTable ******************************/ 1021 1097 1022 1098 DsymbolTable::DsymbolTable() -
a/dmd/dsymbol.h
old new 20 20 21 21 #include "mars.h" 22 22 #include "arraytypes.h" 23 #include <deque> 23 24 24 25 // llvm 25 26 #include "../ir/irdsymbol.h" … … 139 140 virtual const char *kind(); 140 141 virtual Dsymbol *toAlias(); // resolve real symbol 141 142 virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 142 virtual voidsemantic(Scope *sc);143 virtual voidsemantic2(Scope *sc);144 virtual voidsemantic3(Scope *sc);143 virtual DeferStatus<void> semantic(Scope *sc); 144 virtual DeferStatus<void> semantic2(Scope *sc); 145 virtual DeferStatus<void> semantic3(Scope *sc); 145 146 virtual void inlineScan(); 146 virtual D symbol *search(Loc loc, Identifier *ident, int flags);147 D symbol *searchX(Loc loc, Scope *sc, Identifier *id);147 virtual DeferStatus<Dsymbol*> search(Loc loc, Identifier *ident, int flags); 148 DeferStatus<Dsymbol*> searchX(Loc loc, Scope *sc, Identifier *id); 148 149 virtual int overloadInsert(Dsymbol *s); 149 150 #ifdef _DH 150 151 char *toHChars(); … … 255 256 ScopeDsymbol(); 256 257 ScopeDsymbol(Identifier *id); 257 258 Dsymbol *syntaxCopy(Dsymbol *s); 258 D symbol *search(Loc loc, Identifier *ident, int flags);259 DeferStatus<Dsymbol*> search(Loc loc, Identifier *ident, int flags); 259 260 void importScope(ScopeDsymbol *s, enum PROT protection); 260 261 int isforwardRef(); 261 262 void defineRef(Dsymbol *s); … … 266 267 void emitMemberComments(Scope *sc); 267 268 268 269 ScopeDsymbol *isScopeDsymbol() { return this; } 270 271 // LDC 272 std::deque<Dsymbol*> remaining_semantic; // Dsymbols where semantic remains to be called 273 bool member_semantic_started; 274 DeferStatus<void> callSemanticOnMembers(Scope* sc); 275 virtual void postMemberSemantic(Scope* sc) {} 276 virtual bool isMemberReorderable(Dsymbol* sym) { return true; } 269 277 }; 270 278 271 279 // With statement scope … … 275 283 WithStatement *withstate; 276 284 277 285 WithScopeSymbol(WithStatement *withstate); 278 D symbol *search(Loc loc, Identifier *ident, int flags);286 DeferStatus<Dsymbol*> search(Loc loc, Identifier *ident, int flags); 279 287 280 288 WithScopeSymbol *isWithScopeSymbol() { return this; } 281 289 }; … … 291 299 ArrayScopeSymbol(Expression *e); 292 300 ArrayScopeSymbol(TypeTuple *t); 293 301 ArrayScopeSymbol(TupleDeclaration *td); 294 D symbol *search(Loc loc, Identifier *ident, int flags);302 DeferStatus<Dsymbol*> search(Loc loc, Identifier *ident, int flags); 295 303 296 304 ArrayScopeSymbol *isArrayScopeSymbol() { return this; } 297 305 }; -
a/dmd/enum.c
old new 24 24 this->loc = loc; 25 25 type = new TypeEnum(this); 26 26 this->memtype = memtype; 27 if (!this->memtype) 28 this->memtype = Type::tint32; 27 29 maxval = 0; 28 30 minval = 0; 29 31 defaultval = 0; … … 50 52 return ed; 51 53 } 52 54 53 voidEnumDeclaration::semantic(Scope *sc)55 DeferStatus<void> EnumDeclaration::semantic(Scope *sc) 54 56 { int i; 55 57 uinteger_t number; 56 58 Type *t; … … 58 60 59 61 //printf("EnumDeclaration::semantic(sd = %p, '%s')\n", sc->scopesym, sc->scopesym->toChars()); 60 62 if (symtab) // if already done 61 return; 62 if (!memtype) 63 memtype = Type::tint32; 63 return nodefer(); 64 64 if (sc->stc & STCdeprecated) 65 65 isdeprecated = 1; 66 66 … … 89 89 sce->parent = this; 90 90 number = 0; 91 91 if (!members) // enum ident; 92 return ;92 return nodefer(); 93 93 if (members->dim == 0) 94 94 error("enum %s must have at least one member", toChars()); 95 95 int first = 1; … … 222 222 223 223 sce->pop(); 224 224 //members->print(); 225 return nodefer(); 225 226 } 226 227 227 228 int EnumDeclaration::oneMember(Dsymbol **ps) -
a/dmd/enum.h
old new 46 46 47 47 EnumDeclaration(Loc loc, Identifier *id, Type *memtype); 48 48 Dsymbol *syntaxCopy(Dsymbol *s); 49 voidsemantic(Scope *sc);49 DeferStatus<void> semantic(Scope *sc); 50 50 int oneMember(Dsymbol **ps); 51 51 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 52 52 Type *getType(); -
a/dmd/expression.c
old new 342 342 * Pull out any properties. 343 343 */ 344 344 345 Expression *resolveProperties(Scope *sc, Expression *e)345 DeferStatus<Expression*> resolveProperties(Scope *sc, Expression *e) 346 346 { 347 347 //printf("resolveProperties(%s)\n", e->toChars()); 348 348 if (e->type) 349 349 { 350 Type *t = e->type->toBasetype(); 350 DeferStatus<Type*> t = e->type->toBasetype(); 351 if (t.defer()) return t; 351 352 352 353 if (t->ty == Tfunction /*|| e->op == TOKoverloadset*/) 353 354 { … … 914 915 * Determine types, fold constants, etc. 915 916 */ 916 917 917 Expression *Expression::semantic(Scope *sc)918 DeferStatus<Expression*> Expression::semantic(Scope *sc) 918 919 { 919 920 #if LOGSEMANTIC 920 921 printf("Expression::semantic() %s\n", toChars()); … … 1407 1408 return result ? value != 0 : value == 0; 1408 1409 } 1409 1410 1410 Expression *IntegerExp::semantic(Scope *sc)1411 DeferStatus<Expression*> IntegerExp::semantic(Scope *sc) 1411 1412 { 1412 1413 if (!type) 1413 1414 { … … 1668 1669 return 0; 1669 1670 } 1670 1671 1671 Expression *RealExp::semantic(Scope *sc)1672 DeferStatus<Expression*> RealExp::semantic(Scope *sc) 1672 1673 { 1673 1674 if (!type) 1674 1675 type = Type::tfloat64; … … 1870 1871 return 0; 1871 1872 } 1872 1873 1873 Expression *ComplexExp::semantic(Scope *sc)1874 DeferStatus<Expression*> ComplexExp::semantic(Scope *sc) 1874 1875 { 1875 1876 if (!type) 1876 1877 type = Type::tcomplex80; … … 1925 1926 this->ident = ident; 1926 1927 } 1927 1928 1928 Expression *IdentifierExp::semantic(Scope *sc)1929 DeferStatus<Expression*> IdentifierExp::semantic(Scope *sc) 1929 1930 { 1930 1931 Dsymbol *s; 1931 1932 Dsymbol *scopesym; … … 2043 2044 this->s = s; 2044 2045 } 2045 2046 2046 Expression *DsymbolExp::semantic(Scope *sc)2047 DeferStatus<Expression*> DsymbolExp::semantic(Scope *sc) 2047 2048 { 2048 2049 #if LOGSEMANTIC 2049 2050 printf("DsymbolExp::semantic('%s')\n", s->toChars()); … … 2270 2271 var = NULL; 2271 2272 } 2272 2273 2273 Expression *ThisExp::semantic(Scope *sc)2274 DeferStatus<Expression*> ThisExp::semantic(Scope *sc) 2274 2275 { FuncDeclaration *fd; 2275 2276 FuncDeclaration *fdthis; 2276 2277 int nested = 0; … … 2372 2373 op = TOKsuper; 2373 2374 } 2374 2375 2375 Expression *SuperExp::semantic(Scope *sc)2376 DeferStatus<Expression*> SuperExp::semantic(Scope *sc) 2376 2377 { FuncDeclaration *fd; 2377 2378 FuncDeclaration *fdthis; 2378 2379 ClassDeclaration *cd; … … 2474 2475 committed = 0; 2475 2476 } 2476 2477 2477 Expression *NullExp::semantic(Scope *sc)2478 DeferStatus<Expression*> NullExp::semantic(Scope *sc) 2478 2479 { 2479 2480 #if LOGSEMANTIC 2480 2481 printf("NullExp::semantic('%s')\n", toChars()); … … 2568 2569 return p; 2569 2570 } 2570 2571 2571 Expression *StringExp::semantic(Scope *sc)2572 DeferStatus<Expression*> StringExp::semantic(Scope *sc) 2572 2573 { 2573 2574 #if LOGSEMANTIC 2574 2575 printf("StringExp::semantic() %s\n", toChars()); … … 2845 2846 return new ArrayLiteralExp(loc, arraySyntaxCopy(elements)); 2846 2847 } 2847 2848 2848 Expression *ArrayLiteralExp::semantic(Scope *sc)2849 DeferStatus<Expression*> ArrayLiteralExp::semantic(Scope *sc) 2849 2850 { Expression *e; 2850 2851 Type *t0 = NULL; 2851 2852 … … 2960 2961 arraySyntaxCopy(keys), arraySyntaxCopy(values)); 2961 2962 } 2962 2963 2963 Expression *AssocArrayLiteralExp::semantic(Scope *sc)2964 DeferStatus<Expression*> AssocArrayLiteralExp::semantic(Scope *sc) 2964 2965 { Expression *e; 2965 2966 Type *tkey = NULL; 2966 2967 Type *tvalue = NULL; … … 3099 3100 return new StructLiteralExp(loc, sd, arraySyntaxCopy(elements)); 3100 3101 } 3101 3102 3102 Expression *StructLiteralExp::semantic(Scope *sc)3103 DeferStatus<Expression*> StructLiteralExp::semantic(Scope *sc) 3103 3104 { Expression *e; 3104 3105 3105 3106 #if LOGSEMANTIC … … 3326 3327 return new TypeExp(loc, type->syntaxCopy()); 3327 3328 } 3328 3329 3329 Expression *TypeExp::semantic(Scope *sc)3330 DeferStatus<Expression*> TypeExp::semantic(Scope *sc) 3330 3331 { 3331 3332 //printf("TypeExp::semantic(%s)\n", type->toChars()); 3332 3333 type = type->semantic(loc, sc); … … 3356 3357 return se; 3357 3358 } 3358 3359 3359 Expression *ScopeExp::semantic(Scope *sc)3360 DeferStatus<Expression*> ScopeExp::semantic(Scope *sc) 3360 3361 { 3361 3362 TemplateInstance *ti; 3362 3363 ScopeDsymbol *sds2; … … 3369 3370 if (ti && !global.errors) 3370 3371 { Dsymbol *s; 3371 3372 if (!ti->semanticdone) 3372 ti->semantic(sc); 3373 { 3374 DeferStatus<void> ret = ti->semantic(sc); 3375 if (ret.defer()) 3376 return ret; 3377 } 3373 3378 s = ti->inst->toAlias(); 3374 3379 sds2 = s->isScopeDsymbol(); 3375 3380 if (!sds2) … … 3467 3472 } 3468 3473 3469 3474 3470 Expression *NewExp::semantic(Scope *sc)3475 DeferStatus<Expression*> NewExp::semantic(Scope *sc) 3471 3476 { int i; 3472 3477 Type *tb; 3473 3478 ClassDeclaration *cdthis = NULL; … … 3781 3786 } 3782 3787 3783 3788 3784 Expression *NewAnonClassExp::semantic(Scope *sc)3789 DeferStatus<Expression*> NewAnonClassExp::semantic(Scope *sc) 3785 3790 { 3786 3791 #if LOGSEMANTIC 3787 3792 printf("NewAnonClassExp::semantic() %s\n", toChars()); … … 3864 3869 error("need 'this' for address of %s", v->toChars()); 3865 3870 } 3866 3871 3867 Expression *SymOffExp::semantic(Scope *sc)3872 DeferStatus<Expression*> SymOffExp::semantic(Scope *sc) 3868 3873 { 3869 3874 #if LOGSEMANTIC 3870 3875 printf("SymOffExp::semantic('%s')\n", toChars()); … … 3923 3928 return 0; 3924 3929 } 3925 3930 3926 Expression *VarExp::semantic(Scope *sc)3931 DeferStatus<Expression*> VarExp::semantic(Scope *sc) 3927 3932 { FuncLiteralDeclaration *fd; 3928 3933 3929 3934 #if LOGSEMANTIC … … 4177 4182 return new TupleExp(loc, arraySyntaxCopy(exps)); 4178 4183 } 4179 4184 4180 Expression *TupleExp::semantic(Scope *sc)4185 DeferStatus<Expression*> TupleExp::semantic(Scope *sc) 4181 4186 { 4182 4187 #if LOGSEMANTIC 4183 4188 printf("+TupleExp::semantic(%s)\n", toChars()); … … 4255 4260 return new FuncExp(loc, (FuncLiteralDeclaration *)fd->syntaxCopy(NULL)); 4256 4261 } 4257 4262 4258 Expression *FuncExp::semantic(Scope *sc)4263 DeferStatus<Expression*> FuncExp::semantic(Scope *sc) 4259 4264 { 4260 4265 #if LOGSEMANTIC 4261 4266 printf("FuncExp::semantic(%s)\n", toChars()); … … 4320 4325 return new DeclarationExp(loc, declaration->syntaxCopy(NULL)); 4321 4326 } 4322 4327 4323 Expression *DeclarationExp::semantic(Scope *sc)4328 DeferStatus<Expression*> DeclarationExp::semantic(Scope *sc) 4324 4329 { 4325 4330 if (type) 4326 4331 return this; … … 4441 4446 } 4442 4447 4443 4448 4444 Expression *TypeidExp::semantic(Scope *sc)4449 DeferStatus<Expression*> TypeidExp::semantic(Scope *sc) 4445 4450 { Expression *e; 4446 4451 4447 4452 #if LOGSEMANTIC … … 4505 4510 { 4506 4511 } 4507 4512 4508 Expression *HaltExp::semantic(Scope *sc)4513 DeferStatus<Expression*> HaltExp::semantic(Scope *sc) 4509 4514 { 4510 4515 #if LOGSEMANTIC 4511 4516 printf("HaltExp::semantic()\n"); … … 4547 4552 tok2); 4548 4553 } 4549 4554 4550 Expression *IsExp::semantic(Scope *sc)4555 DeferStatus<Expression*> IsExp::semantic(Scope *sc) 4551 4556 { Type *tded; 4552 4557 4553 4558 /* is(targ id tok tspec) … … 4815 4820 return e; 4816 4821 } 4817 4822 4818 Expression *UnaExp::semantic(Scope *sc)4823 DeferStatus<Expression*> UnaExp::semantic(Scope *sc) 4819 4824 { 4820 4825 #if LOGSEMANTIC 4821 4826 printf("UnaExp::semantic('%s')\n", toChars()); 4822 4827 #endif 4823 e1 = e1->semantic(sc); 4828 DeferStatus<Expression*> ret = e1->semantic(sc); 4829 if (ret.defer()) 4830 return ret; 4831 e1 = ret; 4824 4832 // if (!e1->type) 4825 4833 // error("%s has no value", e1->toChars()); 4826 4834 return this; … … 4858 4866 return e; 4859 4867 } 4860 4868 4861 Expression *BinExp::semantic(Scope *sc)4869 DeferStatus<Expression*> BinExp::semantic(Scope *sc) 4862 4870 { 4863 4871 #if LOGSEMANTIC 4864 4872 printf("BinExp::semantic('%s')\n", toChars()); 4865 4873 #endif 4866 e1 = e1->semantic(sc); 4874 DeferStatus<Expression*> ret = e1->semantic(sc); 4875 if (ret.defer()) return ret; 4876 e1 = ret; 4867 4877 if (!e1->type && 4868 4878 !(op == TOKassign && e1->op == TOKdottd)) // a.template = e2 4869 4879 { … … 4879 4889 return this; 4880 4890 } 4881 4891 4882 Expression *BinExp::semanticp(Scope *sc) 4883 { 4884 BinExp::semantic(sc); 4892 DeferStatus<Expression*> BinExp::semanticp(Scope *sc) 4893 { 4894 DeferStatus<Expression*> ret = BinExp::semantic(sc); 4895 if (ret.defer()) return ret; 4885 4896 e1 = resolveProperties(sc, e1); 4886 4897 e2 = resolveProperties(sc, e2); 4887 4898 return this; … … 5023 5034 { 5024 5035 } 5025 5036 5026 Expression *CompileExp::semantic(Scope *sc)5037 DeferStatus<Expression*> CompileExp::semantic(Scope *sc) 5027 5038 { 5028 5039 #if LOGSEMANTIC 5029 5040 printf("CompileExp::semantic('%s')\n", toChars()); … … 5062 5073 { 5063 5074 } 5064 5075 5065 Expression *FileExp::semantic(Scope *sc)5076 DeferStatus<Expression*> FileExp::semantic(Scope *sc) 5066 5077 { char *name; 5067 5078 StringExp *se; 5068 5079 … … 5140 5151 return ae; 5141 5152 } 5142 5153 5143 Expression *AssertExp::semantic(Scope *sc)5154 DeferStatus<Expression*> AssertExp::semantic(Scope *sc) 5144 5155 { 5145 5156 #if LOGSEMANTIC 5146 5157 printf("AssertExp::semantic('%s')\n", toChars()); … … 5204 5215 this->ident = ident; 5205 5216 } 5206 5217 5207 Expression *DotIdExp::semantic(Scope *sc)5218 DeferStatus<Expression*> DotIdExp::semantic(Scope *sc) 5208 5219 { Expression *e; 5209 5220 Expression *eleft; 5210 5221 Expression *eright; … … 5269 5280 } 5270 5281 } 5271 5282 5272 UnaExp::semantic(sc); 5283 DeferStatus<Expression*> ret = UnaExp::semantic(sc); 5284 if (ret.defer()) 5285 return ret; 5273 5286 5274 5287 if (e1->op == TOKdotexp) 5275 5288 { … … 5279 5292 } 5280 5293 else 5281 5294 { 5282 e1 = resolveProperties(sc, e1); 5295 DeferStatus<Expression*> ret2 = resolveProperties(sc, e1); 5296 if (ret2.defer()) return ret2; 5297 e1 = ret2; 5283 5298 eleft = NULL; 5284 5299 eright = e1; 5285 5300 } … … 5512 5527 #endif 5513 5528 else 5514 5529 { 5515 e = e1->type->dotExp(sc, e1, ident); 5516 e = e->semantic(sc); 5517 return e; 5530 DeferStatus<Expression*> ret = e1->type->dotExp(sc, e1, ident); 5531 if (ret.defer()) return ret; 5532 ret = ret->semantic(sc); 5533 if (ret.defer()) return ret; 5534 return ret; 5518 5535 } 5519 5536 } 5520 5537 … … 5554 5571 this->var = v; 5555 5572 } 5556 5573 5557 Expression *DotVarExp::semantic(Scope *sc)5574 DeferStatus<Expression*> DotVarExp::semantic(Scope *sc) 5558 5575 { 5559 5576 #if LOGSEMANTIC 5560 5577 printf("DotVarExp::semantic('%s')\n", toChars()); … … 5730 5747 return de; 5731 5748 } 5732 5749 5733 Expression *DotTemplateInstanceExp::semantic(Scope *sc)5750 DeferStatus<Expression*> DotTemplateInstanceExp::semantic(Scope *sc) 5734 5751 { Dsymbol *s; 5735 5752 Dsymbol *s2; 5736 5753 TemplateDeclaration *td; … … 5865 5882 m = NULL; 5866 5883 } 5867 5884 5868 Expression *DelegateExp::semantic(Scope *sc)5885 DeferStatus<Expression*> DelegateExp::semantic(Scope *sc) 5869 5886 { 5870 5887 #if LOGSEMANTIC 5871 5888 printf("DelegateExp::semantic('%s')\n", toChars()); … … 5904 5921 this->type = s->getType(); 5905 5922 } 5906 5923 5907 Expression *DotTypeExp::semantic(Scope *sc)5924 DeferStatus<Expression*> DotTypeExp::semantic(Scope *sc) 5908 5925 { 5909 5926 #if LOGSEMANTIC 5910 5927 printf("DotTypeExp::semantic('%s')\n", toChars()); … … 5961 5978 } 5962 5979 5963 5980 5964 Expression *CallExp::semantic(Scope *sc)5981 DeferStatus<Expression*> CallExp::semantic(Scope *sc) 5965 5982 { 5966 5983 TypeFunction *tf; 5967 5984 FuncDeclaration *f; … … 6590 6607 m = NULL; 6591 6608 } 6592 6609 6593 Expression *AddrExp::semantic(Scope *sc)6610 DeferStatus<Expression*> AddrExp::semantic(Scope *sc) 6594 6611 { 6595 6612 #if LOGSEMANTIC 6596 6613 printf("AddrExp::semantic('%s')\n", toChars()); … … 6666 6683 type = t; 6667 6684 } 6668 6685 6669 Expression *PtrExp::semantic(Scope *sc)6686 DeferStatus<Expression*> PtrExp::semantic(Scope *sc) 6670 6687 { Type *tb; 6671 6688 6672 6689 #if LOGSEMANTIC … … 6754 6771 { 6755 6772 } 6756 6773 6757 Expression *NegExp::semantic(Scope *sc)6774 DeferStatus<Expression*> NegExp::semantic(Scope *sc) 6758 6775 { Expression *e; 6759 6776 6760 6777 #if LOGSEMANTIC … … 6783 6800 { 6784 6801 } 6785 6802 6786 Expression *UAddExp::semantic(Scope *sc)6803 DeferStatus<Expression*> UAddExp::semantic(Scope *sc) 6787 6804 { Expression *e; 6788 6805 6789 6806 #if LOGSEMANTIC … … 6807 6824 { 6808 6825 } 6809 6826 6810 Expression *ComExp::semantic(Scope *sc)6827 DeferStatus<Expression*> ComExp::semantic(Scope *sc) 6811 6828 { Expression *e; 6812 6829 6813 6830 if (!type) … … 6833 6850 { 6834 6851 } 6835 6852 6836 Expression *NotExp::semantic(Scope *sc)6853 DeferStatus<Expression*> NotExp::semantic(Scope *sc) 6837 6854 { 6838 6855 UnaExp::semantic(sc); 6839 6856 e1 = resolveProperties(sc, e1); … … 6857 6874 type = t; 6858 6875 } 6859 6876 6860 Expression *BoolExp::semantic(Scope *sc)6877 DeferStatus<Expression*> BoolExp::semantic(Scope *sc) 6861 6878 { 6862 6879 UnaExp::semantic(sc); 6863 6880 e1 = resolveProperties(sc, e1); … … 6878 6895 { 6879 6896 } 6880 6897 6881 Expression *DeleteExp::semantic(Scope *sc)6898 DeferStatus<Expression*> DeleteExp::semantic(Scope *sc) 6882 6899 { 6883 6900 Type *tb; 6884 6901 … … 6990 7007 } 6991 7008 6992 7009 6993 Expression *CastExp::semantic(Scope *sc)7010 DeferStatus<Expression*> CastExp::semantic(Scope *sc) 6994 7011 { Expression *e; 6995 7012 BinExp *b; 6996 7013 UnaExp *u; … … 7125 7142 return new SliceExp(loc, e1->syntaxCopy(), lwr, upr); 7126 7143 } 7127 7144 7128 Expression *SliceExp::semantic(Scope *sc)7145 DeferStatus<Expression*> SliceExp::semantic(Scope *sc) 7129 7146 { Expression *e; 7130 7147 AggregateDeclaration *ad; 7131 7148 //FuncDeclaration *fd; … … 7337 7354 { 7338 7355 } 7339 7356 7340 Expression *ArrayLengthExp::semantic(Scope *sc)7357 DeferStatus<Expression*> ArrayLengthExp::semantic(Scope *sc) 7341 7358 { Expression *e; 7342 7359 7343 7360 #if LOGSEMANTIC … … 7374 7391 return new ArrayExp(loc, e1->syntaxCopy(), arraySyntaxCopy(arguments)); 7375 7392 } 7376 7393 7377 Expression *ArrayExp::semantic(Scope *sc)7394 DeferStatus<Expression*> ArrayExp::semantic(Scope *sc) 7378 7395 { Expression *e; 7379 7396 Type *t1; 7380 7397 … … 7447 7464 { 7448 7465 } 7449 7466 7450 Expression *DotExp::semantic(Scope *sc)7467 DeferStatus<Expression*> DotExp::semantic(Scope *sc) 7451 7468 { 7452 7469 #if LOGSEMANTIC 7453 7470 printf("DotExp::semantic('%s')\n", toChars()); … … 7478 7495 { 7479 7496 } 7480 7497 7481 Expression *CommaExp::semantic(Scope *sc)7498 DeferStatus<Expression*> CommaExp::semantic(Scope *sc) 7482 7499 { 7483 7500 if (!type) 7484 7501 { BinExp::semanticp(sc); … … 7539 7556 modifiable = 0; // assume it is an rvalue 7540 7557 } 7541 7558 7542 Expression *IndexExp::semantic(Scope *sc)7559 DeferStatus<Expression*> IndexExp::semantic(Scope *sc) 7543 7560 { Expression *e; 7544 7561 BinExp *b; 7545 7562 UnaExp *u; … … 7707 7724 { 7708 7725 } 7709 7726 7710 Expression *PostExp::semantic(Scope *sc)7727 DeferStatus<Expression*> PostExp::semantic(Scope *sc) 7711 7728 { Expression *e = this; 7712 7729 7713 7730 if (!type) … … 7748 7765 ismemset = 0; 7749 7766 } 7750 7767 7751 Expression *AssignExp::semantic(Scope *sc)7768 DeferStatus<Expression*> AssignExp::semantic(Scope *sc) 7752 7769 { Type *t1; 7753 7770 Expression *e1old = e1; 7754 7771 … … 7977 7994 { 7978 7995 } 7979 7996 7980 Expression *AddAssignExp::semantic(Scope *sc)7997 DeferStatus<Expression*> AddAssignExp::semantic(Scope *sc) 7981 7998 { Expression *e; 7982 7999 7983 8000 if (type) … … 8085 8102 { 8086 8103 } 8087 8104 8088 Expression *MinAssignExp::semantic(Scope *sc)8105 DeferStatus<Expression*> MinAssignExp::semantic(Scope *sc) 8089 8106 { Expression *e; 8090 8107 8091 8108 if (type) … … 8136 8153 { 8137 8154 } 8138 8155 8139 Expression *CatAssignExp::semantic(Scope *sc)8156 DeferStatus<Expression*> CatAssignExp::semantic(Scope *sc) 8140 8157 { Expression *e; 8141 8158 8142 8159 BinExp::semantic(sc); … … 8194 8211 { 8195 8212 } 8196 8213 8197 Expression *MulAssignExp::semantic(Scope *sc)8214 DeferStatus<Expression*> MulAssignExp::semantic(Scope *sc) 8198 8215 { Expression *e; 8199 8216 8200 8217 BinExp::semantic(sc); … … 8260 8277 { 8261 8278 } 8262 8279 8263 Expression *DivAssignExp::semantic(Scope *sc)8280 DeferStatus<Expression*> DivAssignExp::semantic(Scope *sc) 8264 8281 { Expression *e; 8265 8282 8266 8283 BinExp::semantic(sc); … … 8329 8346 { 8330 8347 } 8331 8348 8332 Expression *ModAssignExp::semantic(Scope *sc)8349 DeferStatus<Expression*> ModAssignExp::semantic(Scope *sc) 8333 8350 { 8334 8351 return commonSemanticAssign(sc); 8335 8352 } … … 8341 8358 { 8342 8359 } 8343 8360 8344 Expression *ShlAssignExp::semantic(Scope *sc)8361 DeferStatus<Expression*> ShlAssignExp::semantic(Scope *sc) 8345 8362 { Expression *e; 8346 8363 8347 8364 //printf("ShlAssignExp::semantic()\n"); … … 8371 8388 { 8372 8389 } 8373 8390 8374 Expression *ShrAssignExp::semantic(Scope *sc)8391 DeferStatus<Expression*> ShrAssignExp::semantic(Scope *sc) 8375 8392 { Expression *e; 8376 8393 8377 8394 BinExp::semantic(sc); … … 8400 8417 { 8401 8418 } 8402 8419 8403 Expression *UshrAssignExp::semantic(Scope *sc)8420 DeferStatus<Expression*> UshrAssignExp::semantic(Scope *sc) 8404 8421 { Expression *e; 8405 8422 8406 8423 BinExp::semantic(sc); … … 8429 8446 { 8430 8447 } 8431 8448 8432 Expression *AndAssignExp::semantic(Scope *sc)8449 DeferStatus<Expression*> AndAssignExp::semantic(Scope *sc) 8433 8450 { 8434 8451 return commonSemanticAssignIntegral(sc); 8435 8452 } … … 8441 8458 { 8442 8459 } 8443 8460 8444 Expression *OrAssignExp::semantic(Scope *sc)8461 DeferStatus<Expression*> OrAssignExp::semantic(Scope *sc) 8445 8462 { 8446 8463 return commonSemanticAssignIntegral(sc); 8447 8464 } … … 8453 8470 { 8454 8471 } 8455 8472 8456 Expression *XorAssignExp::semantic(Scope *sc)8473 DeferStatus<Expression*> XorAssignExp::semantic(Scope *sc) 8457 8474 { 8458 8475 return commonSemanticAssignIntegral(sc); 8459 8476 } … … 8465 8482 { 8466 8483 } 8467 8484 8468 Expression *AddExp::semantic(Scope *sc)8485 DeferStatus<Expression*> AddExp::semantic(Scope *sc) 8469 8486 { Expression *e; 8470 8487 8471 8488 #if LOGSEMANTIC … … 8473 8490 #endif 8474 8491 if (!type) 8475 8492 { 8476 BinExp::semanticp(sc); 8493 DeferStatus<Expression*> ret = BinExp::semanticp(sc); 8494 if (ret.defer()) return ret; 8477 8495 8478 8496 e = op_overload(sc); 8479 8497 if (e) … … 8540 8558 { 8541 8559 } 8542 8560 8543 Expression *MinExp::semantic(Scope *sc)8561 DeferStatus<Expression*> MinExp::semantic(Scope *sc) 8544 8562 { Expression *e; 8545 8563 Type *t1; 8546 8564 Type *t2; … … 8635 8653 { 8636 8654 } 8637 8655 8638 Expression *CatExp::semantic(Scope *sc)8656 DeferStatus<Expression*> CatExp::semantic(Scope *sc) 8639 8657 { Expression *e; 8640 8658 8641 8659 //printf("CatExp::semantic() %s\n", toChars()); … … 8722 8740 { 8723 8741 } 8724 8742 8725 Expression *MulExp::semantic(Scope *sc)8743 DeferStatus<Expression*> MulExp::semantic(Scope *sc) 8726 8744 { Expression *e; 8727 8745 8728 8746 #if 0 … … 8793 8811 { 8794 8812 } 8795 8813 8796 Expression *DivExp::semantic(Scope *sc)8814 DeferStatus<Expression*> DivExp::semantic(Scope *sc) 8797 8815 { Expression *e; 8798 8816 8799 8817 if (type) … … 8860 8878 { 8861 8879 } 8862 8880 8863 Expression *ModExp::semantic(Scope *sc)8881 DeferStatus<Expression*> ModExp::semantic(Scope *sc) 8864 8882 { Expression *e; 8865 8883 8866 8884 if (type) … … 8893 8911 { 8894 8912 } 8895 8913 8896 Expression *ShlExp::semantic(Scope *sc)8914 DeferStatus<Expression*> ShlExp::semantic(Scope *sc) 8897 8915 { Expression *e; 8898 8916 8899 8917 //printf("ShlExp::semantic(), type = %p\n", type); … … 8919 8937 { 8920 8938 } 8921 8939 8922 Expression *ShrExp::semantic(Scope *sc)8940 DeferStatus<Expression*> ShrExp::semantic(Scope *sc) 8923 8941 { Expression *e; 8924 8942 8925 8943 if (!type) … … 8944 8962 { 8945 8963 } 8946 8964 8947 Expression *UshrExp::semantic(Scope *sc)8965 DeferStatus<Expression*> UshrExp::semantic(Scope *sc) 8948 8966 { Expression *e; 8949 8967 8950 8968 if (!type) … … 8969 8987 { 8970 8988 } 8971 8989 8972 Expression *AndExp::semantic(Scope *sc)8990 DeferStatus<Expression*> AndExp::semantic(Scope *sc) 8973 8991 { Expression *e; 8974 8992 8975 8993 if (!type) … … 9002 9020 { 9003 9021 } 9004 9022 9005 Expression *OrExp::semantic(Scope *sc)9023 DeferStatus<Expression*> OrExp::semantic(Scope *sc) 9006 9024 { Expression *e; 9007 9025 9008 9026 if (!type) … … 9035 9053 { 9036 9054 } 9037 9055 9038 Expression *XorExp::semantic(Scope *sc)9056 DeferStatus<Expression*> XorExp::semantic(Scope *sc) 9039 9057 { Expression *e; 9040 9058 9041 9059 if (!type) … … 9069 9087 { 9070 9088 } 9071 9089 9072 Expression *OrOrExp::semantic(Scope *sc)9090 DeferStatus<Expression*> OrOrExp::semantic(Scope *sc) 9073 9091 { 9074 9092 unsigned cs1; 9075 9093 … … 9134 9152 { 9135 9153 } 9136 9154 9137 Expression *AndAndExp::semantic(Scope *sc)9155 DeferStatus<Expression*> AndAndExp::semantic(Scope *sc) 9138 9156 { 9139 9157 unsigned cs1; 9140 9158 … … 9200 9218 { 9201 9219 } 9202 9220 9203 Expression *InExp::semantic(Scope *sc)9221 DeferStatus<Expression*> InExp::semantic(Scope *sc) 9204 9222 { Expression *e; 9205 9223 9206 9224 if (type) … … 9255 9273 { 9256 9274 } 9257 9275 9258 Expression *CmpExp::semantic(Scope *sc)9276 DeferStatus<Expression*> CmpExp::semantic(Scope *sc) 9259 9277 { Expression *e; 9260 9278 Type *t1; 9261 9279 Type *t2; … … 9338 9356 assert(op == TOKequal || op == TOKnotequal); 9339 9357 } 9340 9358 9341 Expression *EqualExp::semantic(Scope *sc)9359 DeferStatus<Expression*> EqualExp::semantic(Scope *sc) 9342 9360 { Expression *e; 9343 9361 Type *t1; 9344 9362 Type *t2; … … 9430 9448 { 9431 9449 } 9432 9450 9433 Expression *IdentityExp::semantic(Scope *sc)9451 DeferStatus<Expression*> IdentityExp::semantic(Scope *sc) 9434 9452 { 9435 9453 if (type) 9436 9454 return this; … … 9467 9485 } 9468 9486 9469 9487 9470 Expression *CondExp::semantic(Scope *sc)9488 DeferStatus<Expression*> CondExp::semantic(Scope *sc) 9471 9489 { Type *t1; 9472 9490 Type *t2; 9473 9491 unsigned cs0; -
a/dmd/expression.h
old new 70 70 71 71 void initPrecedence(); 72 72 73 Expression *resolveProperties(Scope *sc, Expression *e);73 DeferStatus<Expression*> resolveProperties(Scope *sc, Expression *e); 74 74 void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d); 75 75 Dsymbol *search_function(AggregateDeclaration *ad, Identifier *funcid); 76 76 void inferApplyArgTypes(enum TOK op, Arguments *arguments, Expression *aggr, Module* from); … … 91 91 Expression(Loc loc, enum TOK op, int size); 92 92 Expression *copy(); 93 93 virtual Expression *syntaxCopy(); 94 virtual Expression *semantic(Scope *sc);94 virtual DeferStatus<Expression*> semantic(Scope *sc); 95 95 96 96 int dyncast() { return DYNCAST_EXPRESSION; } // kludge for template.isExpression() 97 97 … … 180 180 IntegerExp(Loc loc, dinteger_t value, Type *type); 181 181 IntegerExp(dinteger_t value); 182 182 int equals(Object *o); 183 Expression *semantic(Scope *sc);183 DeferStatus<Expression*> semantic(Scope *sc); 184 184 Expression *interpret(InterState *istate); 185 185 char *toChars(); 186 186 void dump(int indent); … … 216 216 217 217 RealExp(Loc loc, real_t value, Type *type); 218 218 int equals(Object *o); 219 Expression *semantic(Scope *sc);219 DeferStatus<Expression*> semantic(Scope *sc); 220 220 Expression *interpret(InterState *istate); 221 221 char *toChars(); 222 222 dinteger_t toInteger(); … … 244 244 245 245 ComplexExp(Loc loc, complex_t value, Type *type); 246 246 int equals(Object *o); 247 Expression *semantic(Scope *sc);247 DeferStatus<Expression*> semantic(Scope *sc); 248 248 Expression *interpret(InterState *istate); 249 249 char *toChars(); 250 250 dinteger_t toInteger(); … … 276 276 277 277 IdentifierExp(Loc loc, Identifier *ident); 278 278 IdentifierExp(Loc loc, Declaration *var); 279 Expression *semantic(Scope *sc);279 DeferStatus<Expression*> semantic(Scope *sc); 280 280 char *toChars(); 281 281 void dump(int indent); 282 282 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 293 293 Dsymbol *s; 294 294 295 295 DsymbolExp(Loc loc, Dsymbol *s); 296 Expression *semantic(Scope *sc);296 DeferStatus<Expression*> semantic(Scope *sc); 297 297 char *toChars(); 298 298 void dump(int indent); 299 299 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 305 305 Declaration *var; 306 306 307 307 ThisExp(Loc loc); 308 Expression *semantic(Scope *sc);308 DeferStatus<Expression*> semantic(Scope *sc); 309 309 int isBool(int result); 310 310 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 311 311 Expression *toLvalue(Scope *sc, Expression *e); … … 327 327 struct SuperExp : ThisExp 328 328 { 329 329 SuperExp(Loc loc); 330 Expression *semantic(Scope *sc);330 DeferStatus<Expression*> semantic(Scope *sc); 331 331 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 332 332 void scanForNestedRef(Scope *sc); 333 333 … … 341 341 unsigned char committed; // !=0 if type is committed 342 342 343 343 NullExp(Loc loc); 344 Expression *semantic(Scope *sc);344 DeferStatus<Expression*> semantic(Scope *sc); 345 345 int isBool(int result); 346 346 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 347 347 void toMangleBuffer(OutBuffer *buf); … … 371 371 //Expression *syntaxCopy(); 372 372 int equals(Object *o); 373 373 char *toChars(); 374 Expression *semantic(Scope *sc);374 DeferStatus<Expression*> semantic(Scope *sc); 375 375 Expression *interpret(InterState *istate); 376 376 StringExp *toUTF8(Scope *sc); 377 377 MATCH implicitConvTo(Type *t); … … 400 400 TupleExp(Loc loc, TupleDeclaration *tup); 401 401 Expression *syntaxCopy(); 402 402 int equals(Object *o); 403 Expression *semantic(Scope *sc);403 DeferStatus<Expression*> semantic(Scope *sc); 404 404 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 405 405 void scanForNestedRef(Scope *sc); 406 406 void checkEscape(); … … 429 429 ArrayLiteralExp(Loc loc, Expression *e); 430 430 431 431 Expression *syntaxCopy(); 432 Expression *semantic(Scope *sc);432 DeferStatus<Expression*> semantic(Scope *sc); 433 433 int isBool(int result); 434 434 int checkSideEffect(int flag); 435 435 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 461 461 AssocArrayLiteralExp(Loc loc, Expressions *keys, Expressions *values); 462 462 463 463 Expression *syntaxCopy(); 464 Expression *semantic(Scope *sc);464 DeferStatus<Expression*> semantic(Scope *sc); 465 465 int isBool(int result); 466 466 #if IN_DMD 467 467 elem *toElem(IRState *irs); … … 500 500 StructLiteralExp(Loc loc, StructDeclaration *sd, Expressions *elements); 501 501 502 502 Expression *syntaxCopy(); 503 Expression *semantic(Scope *sc);503 DeferStatus<Expression*> semantic(Scope *sc); 504 504 Expression *getField(Type *type, unsigned offset); 505 505 int getFieldIndex(Type *type, unsigned offset); 506 506 int checkSideEffect(int flag); … … 538 538 { 539 539 TypeExp(Loc loc, Type *type); 540 540 Expression *syntaxCopy(); 541 Expression *semantic(Scope *sc);541 DeferStatus<Expression*> semantic(Scope *sc); 542 542 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 543 543 Expression *optimize(int result); 544 544 #if IN_DMD … … 556 556 557 557 ScopeExp(Loc loc, ScopeDsymbol *sds); 558 558 Expression *syntaxCopy(); 559 Expression *semantic(Scope *sc);559 DeferStatus<Expression*> semantic(Scope *sc); 560 560 #if IN_DMD 561 561 elem *toElem(IRState *irs); 562 562 #endif … … 592 592 NewExp(Loc loc, Expression *thisexp, Expressions *newargs, 593 593 Type *newtype, Expressions *arguments); 594 594 Expression *syntaxCopy(); 595 Expression *semantic(Scope *sc);595 DeferStatus<Expression*> semantic(Scope *sc); 596 596 #if IN_DMD 597 597 elem *toElem(IRState *irs); 598 598 #endif … … 621 621 NewAnonClassExp(Loc loc, Expression *thisexp, Expressions *newargs, 622 622 ClassDeclaration *cd, Expressions *arguments); 623 623 Expression *syntaxCopy(); 624 Expression *semantic(Scope *sc);624 DeferStatus<Expression*> semantic(Scope *sc); 625 625 int checkSideEffect(int flag); 626 626 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 627 627 }; … … 635 635 Module* m; // starting point for overload resolution 636 636 637 637 SymOffExp(Loc loc, Declaration *var, unsigned offset); 638 Expression *semantic(Scope *sc);638 DeferStatus<Expression*> semantic(Scope *sc); 639 639 void checkEscape(); 640 640 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 641 641 int isConst(); … … 663 663 664 664 VarExp(Loc loc, Declaration *var); 665 665 int equals(Object *o); 666 Expression *semantic(Scope *sc);666 DeferStatus<Expression*> semantic(Scope *sc); 667 667 Expression *optimize(int result); 668 668 Expression *interpret(InterState *istate); 669 669 void dump(int indent); … … 710 710 711 711 FuncExp(Loc loc, FuncLiteralDeclaration *fd); 712 712 Expression *syntaxCopy(); 713 Expression *semantic(Scope *sc);713 DeferStatus<Expression*> semantic(Scope *sc); 714 714 void scanForNestedRef(Scope *sc); 715 715 char *toChars(); 716 716 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 736 736 737 737 DeclarationExp(Loc loc, Dsymbol *declaration); 738 738 Expression *syntaxCopy(); 739 Expression *semantic(Scope *sc);739 DeferStatus<Expression*> semantic(Scope *sc); 740 740 Expression *interpret(InterState *istate); 741 741 int checkSideEffect(int flag); 742 742 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 760 760 761 761 TypeidExp(Loc loc, Type *typeidType); 762 762 Expression *syntaxCopy(); 763 Expression *semantic(Scope *sc);763 DeferStatus<Expression*> semantic(Scope *sc); 764 764 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 765 765 }; 766 766 … … 772 772 773 773 TraitsExp(Loc loc, Identifier *ident, Objects *args); 774 774 Expression *syntaxCopy(); 775 Expression *semantic(Scope *sc);775 DeferStatus<Expression*> semantic(Scope *sc); 776 776 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 777 777 }; 778 778 #endif … … 780 780 struct HaltExp : Expression 781 781 { 782 782 HaltExp(Loc loc); 783 Expression *semantic(Scope *sc);783 DeferStatus<Expression*> semantic(Scope *sc); 784 784 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 785 785 int checkSideEffect(int flag); 786 786 … … 806 806 807 807 IsExp(Loc loc, Type *targ, Identifier *id, enum TOK tok, Type *tspec, enum TOK tok2); 808 808 Expression *syntaxCopy(); 809 Expression *semantic(Scope *sc);809 DeferStatus<Expression*> semantic(Scope *sc); 810 810 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 811 811 }; 812 812 … … 818 818 819 819 UnaExp(Loc loc, enum TOK op, int size, Expression *e1); 820 820 Expression *syntaxCopy(); 821 Expression *semantic(Scope *sc);821 DeferStatus<Expression*> semantic(Scope *sc); 822 822 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 823 823 Expression *optimize(int result); 824 824 void dump(int indent); … … 839 839 840 840 BinExp(Loc loc, enum TOK op, int size, Expression *e1, Expression *e2); 841 841 Expression *syntaxCopy(); 842 Expression *semantic(Scope *sc);843 Expression *semanticp(Scope *sc);842 DeferStatus<Expression*> semantic(Scope *sc); 843 DeferStatus<Expression*> semanticp(Scope *sc); 844 844 Expression *commonSemanticAssign(Scope *sc); 845 845 Expression *commonSemanticAssignIntegral(Scope *sc); 846 846 int checkSideEffect(int flag); … … 879 879 struct CompileExp : UnaExp 880 880 { 881 881 CompileExp(Loc loc, Expression *e); 882 Expression *semantic(Scope *sc);882 DeferStatus<Expression*> semantic(Scope *sc); 883 883 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 884 884 }; 885 885 886 886 struct FileExp : UnaExp 887 887 { 888 888 FileExp(Loc loc, Expression *e); 889 Expression *semantic(Scope *sc);889 DeferStatus<Expression*> semantic(Scope *sc); 890 890 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 891 891 }; 892 892 … … 896 896 897 897 AssertExp(Loc loc, Expression *e, Expression *msg = NULL); 898 898 Expression *syntaxCopy(); 899 Expression *semantic(Scope *sc);899 DeferStatus<Expression*> semantic(Scope *sc); 900 900 Expression *interpret(InterState *istate); 901 901 int checkSideEffect(int flag); 902 902 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 919 919 Identifier *ident; 920 920 921 921 DotIdExp(Loc loc, Expression *e, Identifier *ident); 922 Expression *semantic(Scope *sc);922 DeferStatus<Expression*> semantic(Scope *sc); 923 923 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 924 924 void dump(int i); 925 925 }; … … 937 937 Declaration *var; 938 938 939 939 DotVarExp(Loc loc, Expression *e, Declaration *var); 940 Expression *semantic(Scope *sc);940 DeferStatus<Expression*> semantic(Scope *sc); 941 941 Expression *toLvalue(Scope *sc, Expression *e); 942 942 Expression *modifiableLvalue(Scope *sc, Expression *e); 943 943 Expression *optimize(int result); … … 960 960 961 961 DotTemplateInstanceExp(Loc loc, Expression *e, TemplateInstance *ti); 962 962 Expression *syntaxCopy(); 963 Expression *semantic(Scope *sc);963 DeferStatus<Expression*> semantic(Scope *sc); 964 964 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 965 965 void dump(int indent); 966 966 }; … … 971 971 Module* m; // starting point for overload resolution 972 972 973 973 DelegateExp(Loc loc, Expression *e, FuncDeclaration *func); 974 Expression *semantic(Scope *sc);974 DeferStatus<Expression*> semantic(Scope *sc); 975 975 MATCH implicitConvTo(Type *t); 976 976 Expression *castTo(Scope *sc, Type *t); 977 977 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 992 992 Dsymbol *sym; // symbol that represents a type 993 993 994 994 DotTypeExp(Loc loc, Expression *e, Dsymbol *sym); 995 Expression *semantic(Scope *sc);995 DeferStatus<Expression*> semantic(Scope *sc); 996 996 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 997 997 #if IN_DMD 998 998 elem *toElem(IRState *irs); … … 1013 1013 CallExp(Loc loc, Expression *e, Expression *earg1, Expression *earg2); 1014 1014 1015 1015 Expression *syntaxCopy(); 1016 Expression *semantic(Scope *sc);1016 DeferStatus<Expression*> semantic(Scope *sc); 1017 1017 Expression *optimize(int result); 1018 1018 Expression *interpret(InterState *istate); 1019 1019 int checkSideEffect(int flag); … … 1039 1039 Module* m; // starting point for overload resolution 1040 1040 1041 1041 AddrExp(Loc loc, Expression *e); 1042 Expression *semantic(Scope *sc);1042 DeferStatus<Expression*> semantic(Scope *sc); 1043 1043 #if IN_DMD 1044 1044 elem *toElem(IRState *irs); 1045 1045 #endif … … 1057 1057 { 1058 1058 PtrExp(Loc loc, Expression *e); 1059 1059 PtrExp(Loc loc, Expression *e, Type *t); 1060 Expression *semantic(Scope *sc);1060 DeferStatus<Expression*> semantic(Scope *sc); 1061 1061 Expression *toLvalue(Scope *sc, Expression *e); 1062 1062 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 1063 1063 #if IN_DMD … … 1075 1075 struct NegExp : UnaExp 1076 1076 { 1077 1077 NegExp(Loc loc, Expression *e); 1078 Expression *semantic(Scope *sc);1078 DeferStatus<Expression*> semantic(Scope *sc); 1079 1079 Expression *optimize(int result); 1080 1080 Expression *interpret(InterState *istate); 1081 1081 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); … … 1096 1096 struct UAddExp : UnaExp 1097 1097 { 1098 1098 UAddExp(Loc loc, Expression *e); 1099 Expression *semantic(Scope *sc);1099 DeferStatus<Expression*> semantic(Scope *sc); 1100 1100 1101 1101 // For operator overloading 1102 1102 Identifier *opId(); … … 1105 1105 struct ComExp : UnaExp 1106 1106 { 1107 1107 ComExp(Loc loc, Expression *e); 1108 Expression *semantic(Scope *sc);1108 DeferStatus<Expression*> semantic(Scope *sc); 1109 1109 Expression *optimize(int result); 1110 1110 Expression *interpret(InterState *istate); 1111 1111 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); … … 1126 1126 struct NotExp : UnaExp 1127 1127 { 1128 1128 NotExp(Loc loc, Expression *e); 1129 Expression *semantic(Scope *sc);1129 DeferStatus<Expression*> semantic(Scope *sc); 1130 1130 Expression *optimize(int result); 1131 1131 Expression *interpret(InterState *istate); 1132 1132 int isBit(); … … 1142 1142 struct BoolExp : UnaExp 1143 1143 { 1144 1144 BoolExp(Loc loc, Expression *e, Type *type); 1145 Expression *semantic(Scope *sc);1145 DeferStatus<Expression*> semantic(Scope *sc); 1146 1146 Expression *optimize(int result); 1147 1147 Expression *interpret(InterState *istate); 1148 1148 int isBit(); … … 1158 1158 struct DeleteExp : UnaExp 1159 1159 { 1160 1160 DeleteExp(Loc loc, Expression *e); 1161 Expression *semantic(Scope *sc);1161 DeferStatus<Expression*> semantic(Scope *sc); 1162 1162 Expression *checkToBoolean(); 1163 1163 int checkSideEffect(int flag); 1164 1164 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 1178 1178 1179 1179 CastExp(Loc loc, Expression *e, Type *t); 1180 1180 Expression *syntaxCopy(); 1181 Expression *semantic(Scope *sc);1181 DeferStatus<Expression*> semantic(Scope *sc); 1182 1182 Expression *optimize(int result); 1183 1183 Expression *interpret(InterState *istate); 1184 1184 int checkSideEffect(int flag); … … 1206 1206 1207 1207 SliceExp(Loc loc, Expression *e1, Expression *lwr, Expression *upr); 1208 1208 Expression *syntaxCopy(); 1209 Expression *semantic(Scope *sc);1209 DeferStatus<Expression*> semantic(Scope *sc); 1210 1210 void checkEscape(); 1211 1211 Expression *toLvalue(Scope *sc, Expression *e); 1212 1212 Expression *modifiableLvalue(Scope *sc, Expression *e); … … 1234 1234 struct ArrayLengthExp : UnaExp 1235 1235 { 1236 1236 ArrayLengthExp(Loc loc, Expression *e1); 1237 Expression *semantic(Scope *sc);1237 DeferStatus<Expression*> semantic(Scope *sc); 1238 1238 Expression *optimize(int result); 1239 1239 Expression *interpret(InterState *istate); 1240 1240 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 1255 1255 1256 1256 ArrayExp(Loc loc, Expression *e1, Expressions *arguments); 1257 1257 Expression *syntaxCopy(); 1258 Expression *semantic(Scope *sc);1258 DeferStatus<Expression*> semantic(Scope *sc); 1259 1259 Expression *toLvalue(Scope *sc, Expression *e); 1260 1260 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 1261 1261 void scanForNestedRef(Scope *sc); … … 1273 1273 struct DotExp : BinExp 1274 1274 { 1275 1275 DotExp(Loc loc, Expression *e1, Expression *e2); 1276 Expression *semantic(Scope *sc);1276 DeferStatus<Expression*> semantic(Scope *sc); 1277 1277 }; 1278 1278 1279 1279 struct CommaExp : BinExp 1280 1280 { 1281 1281 CommaExp(Loc loc, Expression *e1, Expression *e2); 1282 Expression *semantic(Scope *sc);1282 DeferStatus<Expression*> semantic(Scope *sc); 1283 1283 void checkEscape(); 1284 1284 Expression *toLvalue(Scope *sc, Expression *e); 1285 1285 Expression *modifiableLvalue(Scope *sc, Expression *e); … … 1302 1302 int modifiable; 1303 1303 1304 1304 IndexExp(Loc loc, Expression *e1, Expression *e2); 1305 Expression *semantic(Scope *sc);1305 DeferStatus<Expression*> semantic(Scope *sc); 1306 1306 Expression *toLvalue(Scope *sc, Expression *e); 1307 1307 Expression *modifiableLvalue(Scope *sc, Expression *e); 1308 1308 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 1325 1325 struct PostExp : BinExp 1326 1326 { 1327 1327 PostExp(enum TOK op, Loc loc, Expression *e); 1328 Expression *semantic(Scope *sc);1328 DeferStatus<Expression*> semantic(Scope *sc); 1329 1329 Expression *interpret(InterState *istate); 1330 1330 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 1331 1331 Identifier *opId(); // For operator overloading … … 1342 1342 { int ismemset; // !=0 if setting the contents of an array 1343 1343 1344 1344 AssignExp(Loc loc, Expression *e1, Expression *e2); 1345 Expression *semantic(Scope *sc);1345 DeferStatus<Expression*> semantic(Scope *sc); 1346 1346 Expression *checkToBoolean(); 1347 1347 Expression *interpret(InterState *istate); 1348 1348 Identifier *opId(); // For operator overloading … … 1369 1369 struct op##AssignExp : BinExp \ 1370 1370 { \ 1371 1371 op##AssignExp(Loc loc, Expression *e1, Expression *e2); \ 1372 Expression *semantic(Scope *sc); \1372 DeferStatus<Expression*> semantic(Scope *sc); \ 1373 1373 Expression *interpret(InterState *istate); \ 1374 1374 X(void buildArrayIdent(OutBuffer *buf, Expressions *arguments);) \ 1375 1375 X(Expression *buildArrayLoop(Arguments *fparams);) \ … … 1404 1404 struct AddExp : BinExp 1405 1405 { 1406 1406 AddExp(Loc loc, Expression *e1, Expression *e2); 1407 Expression *semantic(Scope *sc);1407 DeferStatus<Expression*> semantic(Scope *sc); 1408 1408 Expression *optimize(int result); 1409 1409 Expression *interpret(InterState *istate); 1410 1410 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); … … 1427 1427 struct MinExp : BinExp 1428 1428 { 1429 1429 MinExp(Loc loc, Expression *e1, Expression *e2); 1430 Expression *semantic(Scope *sc);1430 DeferStatus<Expression*> semantic(Scope *sc); 1431 1431 Expression *optimize(int result); 1432 1432 Expression *interpret(InterState *istate); 1433 1433 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); … … 1449 1449 struct CatExp : BinExp 1450 1450 { 1451 1451 CatExp(Loc loc, Expression *e1, Expression *e2); 1452 Expression *semantic(Scope *sc);1452 DeferStatus<Expression*> semantic(Scope *sc); 1453 1453 Expression *optimize(int result); 1454 1454 Expression *interpret(InterState *istate); 1455 1455 … … 1469 1469 struct MulExp : BinExp 1470 1470 { 1471 1471 MulExp(Loc loc, Expression *e1, Expression *e2); 1472 Expression *semantic(Scope *sc);1472 DeferStatus<Expression*> semantic(Scope *sc); 1473 1473 Expression *optimize(int result); 1474 1474 Expression *interpret(InterState *istate); 1475 1475 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); … … 1492 1492 struct DivExp : BinExp 1493 1493 { 1494 1494 DivExp(Loc loc, Expression *e1, Expression *e2); 1495 Expression *semantic(Scope *sc);1495 DeferStatus<Expression*> semantic(Scope *sc); 1496 1496 Expression *optimize(int result); 1497 1497 Expression *interpret(InterState *istate); 1498 1498 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); … … 1514 1514 struct ModExp : BinExp 1515 1515 { 1516 1516 ModExp(Loc loc, Expression *e1, Expression *e2); 1517 Expression *semantic(Scope *sc);1517 DeferStatus<Expression*> semantic(Scope *sc); 1518 1518 Expression *optimize(int result); 1519 1519 Expression *interpret(InterState *istate); 1520 1520 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); … … 1536 1536 struct ShlExp : BinExp 1537 1537 { 1538 1538 ShlExp(Loc loc, Expression *e1, Expression *e2); 1539 Expression *semantic(Scope *sc);1539 DeferStatus<Expression*> semantic(Scope *sc); 1540 1540 Expression *optimize(int result); 1541 1541 Expression *interpret(InterState *istate); 1542 1542 … … 1556 1556 struct ShrExp : BinExp 1557 1557 { 1558 1558 ShrExp(Loc loc, Expression *e1, Expression *e2); 1559 Expression *semantic(Scope *sc);1559 DeferStatus<Expression*> semantic(Scope *sc); 1560 1560 Expression *optimize(int result); 1561 1561 Expression *interpret(InterState *istate); 1562 1562 … … 1576 1576 struct UshrExp : BinExp 1577 1577 { 1578 1578 UshrExp(Loc loc, Expression *e1, Expression *e2); 1579 Expression *semantic(Scope *sc);1579 DeferStatus<Expression*> semantic(Scope *sc); 1580 1580 Expression *optimize(int result); 1581 1581 Expression *interpret(InterState *istate); 1582 1582 … … 1596 1596 struct AndExp : BinExp 1597 1597 { 1598 1598 AndExp(Loc loc, Expression *e1, Expression *e2); 1599 Expression *semantic(Scope *sc);1599 DeferStatus<Expression*> semantic(Scope *sc); 1600 1600 Expression *optimize(int result); 1601 1601 Expression *interpret(InterState *istate); 1602 1602 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); … … 1619 1619 struct OrExp : BinExp 1620 1620 { 1621 1621 OrExp(Loc loc, Expression *e1, Expression *e2); 1622 Expression *semantic(Scope *sc);1622 DeferStatus<Expression*> semantic(Scope *sc); 1623 1623 Expression *optimize(int result); 1624 1624 Expression *interpret(InterState *istate); 1625 1625 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); … … 1642 1642 struct XorExp : BinExp 1643 1643 { 1644 1644 XorExp(Loc loc, Expression *e1, Expression *e2); 1645 Expression *semantic(Scope *sc);1645 DeferStatus<Expression*> semantic(Scope *sc); 1646 1646 Expression *optimize(int result); 1647 1647 Expression *interpret(InterState *istate); 1648 1648 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); … … 1665 1665 struct OrOrExp : BinExp 1666 1666 { 1667 1667 OrOrExp(Loc loc, Expression *e1, Expression *e2); 1668 Expression *semantic(Scope *sc);1668 DeferStatus<Expression*> semantic(Scope *sc); 1669 1669 Expression *checkToBoolean(); 1670 1670 int isBit(); 1671 1671 Expression *optimize(int result); … … 1683 1683 struct AndAndExp : BinExp 1684 1684 { 1685 1685 AndAndExp(Loc loc, Expression *e1, Expression *e2); 1686 Expression *semantic(Scope *sc);1686 DeferStatus<Expression*> semantic(Scope *sc); 1687 1687 Expression *checkToBoolean(); 1688 1688 int isBit(); 1689 1689 Expression *optimize(int result); … … 1701 1701 struct CmpExp : BinExp 1702 1702 { 1703 1703 CmpExp(enum TOK op, Loc loc, Expression *e1, Expression *e2); 1704 Expression *semantic(Scope *sc);1704 DeferStatus<Expression*> semantic(Scope *sc); 1705 1705 Expression *optimize(int result); 1706 1706 Expression *interpret(InterState *istate); 1707 1707 int isBit(); … … 1722 1722 struct InExp : BinExp 1723 1723 { 1724 1724 InExp(Loc loc, Expression *e1, Expression *e2); 1725 Expression *semantic(Scope *sc);1725 DeferStatus<Expression*> semantic(Scope *sc); 1726 1726 int isBit(); 1727 1727 1728 1728 // For operator overloading … … 1755 1755 struct EqualExp : BinExp 1756 1756 { 1757 1757 EqualExp(enum TOK op, Loc loc, Expression *e1, Expression *e2); 1758 Expression *semantic(Scope *sc);1758 DeferStatus<Expression*> semantic(Scope *sc); 1759 1759 Expression *optimize(int result); 1760 1760 Expression *interpret(InterState *istate); 1761 1761 int isBit(); … … 1778 1778 struct IdentityExp : BinExp 1779 1779 { 1780 1780 IdentityExp(enum TOK op, Loc loc, Expression *e1, Expression *e2); 1781 Expression *semantic(Scope *sc);1781 DeferStatus<Expression*> semantic(Scope *sc); 1782 1782 int isBit(); 1783 1783 Expression *optimize(int result); 1784 1784 Expression *interpret(InterState *istate); … … 1799 1799 1800 1800 CondExp(Loc loc, Expression *econd, Expression *e1, Expression *e2); 1801 1801 Expression *syntaxCopy(); 1802 Expression *semantic(Scope *sc);1802 DeferStatus<Expression*> semantic(Scope *sc); 1803 1803 Expression *optimize(int result); 1804 1804 Expression *interpret(InterState *istate); 1805 1805 void checkEscape(); … … 1840 1840 struct FileInitExp : DefaultInitExp 1841 1841 { 1842 1842 FileInitExp(Loc loc); 1843 Expression *semantic(Scope *sc);1843 DeferStatus<Expression*> semantic(Scope *sc); 1844 1844 Expression *resolve(Loc loc, Scope *sc); 1845 1845 }; 1846 1846 1847 1847 struct LineInitExp : DefaultInitExp 1848 1848 { 1849 1849 LineInitExp(Loc loc); 1850 Expression *semantic(Scope *sc);1850 DeferStatus<Expression*> semantic(Scope *sc); 1851 1851 Expression *resolve(Loc loc, Scope *sc); 1852 1852 }; 1853 1853 #endif -
a/dmd/func.c
old new 129 129 130 130 // Do the semantic analysis on the external interface to the function. 131 131 132 voidFuncDeclaration::semantic(Scope *sc)132 DeferStatus<void> FuncDeclaration::semantic(Scope *sc) 133 133 { TypeFunction *f; 134 134 StructDeclaration *sd; 135 135 ClassDeclaration *cd; … … 151 151 * once on them. 152 152 * See test\interface2.d, test20 153 153 */ 154 return ;154 return nodefer(); 155 155 } 156 156 assert(semanticRun <= 1); 157 157 semanticRun = 1; 158 158 159 159 if (type->nextOf()) 160 type = type->semantic(loc, sc); 160 { 161 DeferStatus<Type*> ret = type->semantic(loc, sc); 162 if (ret.defer()) { 163 semanticRun = 0; 164 return ret; 165 } 166 type = ret; 167 } 161 168 //type->print(); 162 169 if (type->ty != Tfunction) 163 170 { 164 171 error("%s must be a function", toChars()); 165 return ;172 return nodefer(); 166 173 } 167 174 f = (TypeFunction *)(type); 168 175 size_t nparams = Argument::dim(f->parameters); … … 279 286 // ctor = (CtorDeclaration *)this; 280 287 // if (!cd->ctor) 281 288 // cd->ctor = ctor; 282 return ;289 return nodefer(); 283 290 } 284 291 285 292 #if 0 … … 361 368 break; 362 369 363 370 case -2: // can't determine because of fwd refs 364 cd->sizeok = 2; // can't finish due to forward reference 365 return; 371 return defer<void>(loc, "cannot determine vtbl index of %s because of forward references", toChars()); 366 372 367 373 default: 368 374 { FuncDeclaration *fdv = (FuncDeclaration *)cd->vtbl.data[vi]; … … 435 441 break; 436 442 437 443 case -2: 438 cd->sizeok = 2; // can't finish due to forward reference 439 return; 444 return defer<void>(loc, "cannot determine vtbl index of %s because of forward references", toChars()); 440 445 441 446 default: 442 447 { FuncDeclaration *fdv = (FuncDeclaration *)b->base->vtbl.data[vi]; … … 531 536 } 532 537 if (cov == 3) 533 538 { 534 cd->sizeok = 2; // can't finish due to forward reference 535 return; 539 return defer<void>(loc, "cannot finish due to forward reference"); 536 540 } 537 541 } 538 542 } … … 639 643 */ 640 644 scope = new Scope(*sc); 641 645 scope->setNoFree(); 642 return ;646 return nodefer(); 643 647 644 648 Lassignerr: 645 649 error("identity assignment operator overload is illegal"); 650 return nodefer(); 646 651 } 647 652 648 voidFuncDeclaration::semantic2(Scope *sc)653 DeferStatus<void> FuncDeclaration::semantic2(Scope *sc) 649 654 { 655 return nodefer(); 650 656 } 651 657 652 658 // Do the semantic analysis on the internals of the function. 653 659 654 voidFuncDeclaration::semantic3(Scope *sc)660 DeferStatus<void> FuncDeclaration::semantic3(Scope *sc) 655 661 { TypeFunction *f; 656 662 AggregateDeclaration *ad; 657 663 VarDeclaration *argptr = NULL; … … 660 666 if (!parent) 661 667 { 662 668 if (global.errors) 663 return ;669 return nodefer(); 664 670 //printf("FuncDeclaration::semantic3(%s '%s', sc = %p)\n", kind(), toChars(), sc); 665 671 assert(0); 666 672 } … … 671 677 672 678 //printf(" sc->incontract = %d\n", sc->incontract); 673 679 if (semanticRun >= 3) 674 return ;680 return nodefer(); 675 681 semanticRun = 3; 676 682 677 683 if (!type || type->ty != Tfunction) 678 return ;684 return nodefer(); 679 685 f = (TypeFunction *)(type); 680 686 size_t nparams = Argument::dim(f->parameters); 681 687 … … 728 734 if (isFuncLiteralDeclaration() && isNested()) 729 735 { 730 736 error("literals cannot be class members"); 731 return ;737 return nodefer(); 732 738 } 733 739 else 734 740 { … … 1364 1370 sc2->pop(); 1365 1371 } 1366 1372 semanticRun = 4; 1373 1374 return nodefer(); 1367 1375 } 1368 1376 1369 1377 void FuncDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) … … 2369 2377 } 2370 2378 2371 2379 2372 voidCtorDeclaration::semantic(Scope *sc)2380 DeferStatus<void> CtorDeclaration::semantic(Scope *sc) 2373 2381 { 2374 2382 ClassDeclaration *cd; 2375 2383 Type *tret; 2376 2384 2377 2385 //printf("CtorDeclaration::semantic()\n"); 2378 2386 if (type) 2379 return ;2387 return nodefer(); 2380 2388 2381 2389 sc = sc->push(); 2382 2390 sc->stc &= ~STCstatic; // not a static constructor … … 2412 2420 fbody = new CompoundStatement(0, fbody, s); 2413 2421 } 2414 2422 2415 FuncDeclaration::semantic(sc);2423 DeferStatus<void> ret = FuncDeclaration::semantic(sc); 2416 2424 2417 2425 sc->pop(); 2418 2426 2419 2427 // See if it's the default constructor 2420 2428 if (cd && varargs == 0 && Argument::dim(arguments) == 0) 2421 2429 cd->defaultCtor = this; 2430 2431 return ret; 2422 2432 } 2423 2433 2424 2434 const char *CtorDeclaration::kind() … … 2474 2484 } 2475 2485 2476 2486 2477 voidDtorDeclaration::semantic(Scope *sc)2487 DeferStatus<void> DtorDeclaration::semantic(Scope *sc) 2478 2488 { 2479 2489 ClassDeclaration *cd; 2480 2490 … … 2494 2504 sc->stc &= ~STCstatic; // not a static destructor 2495 2505 sc->linkage = LINKd; 2496 2506 2497 FuncDeclaration::semantic(sc);2507 DeferStatus<void> ret = FuncDeclaration::semantic(sc); 2498 2508 2499 2509 sc->pop(); 2510 return ret; 2500 2511 } 2501 2512 2502 2513 int DtorDeclaration::overloadInsert(Dsymbol *s) … … 2552 2563 } 2553 2564 2554 2565 2555 voidStaticCtorDeclaration::semantic(Scope *sc)2566 DeferStatus<void> StaticCtorDeclaration::semantic(Scope *sc) 2556 2567 { 2557 2568 //printf("StaticCtorDeclaration::semantic()\n"); 2558 2569 … … 2586 2597 fbody = new CompoundStatement(0, sa); 2587 2598 } 2588 2599 2589 FuncDeclaration::semantic(sc);2600 DeferStatus<void> ret = FuncDeclaration::semantic(sc); 2590 2601 2591 2602 // We're going to need ModuleInfo 2592 2603 Module *m = getModule(); … … 2598 2609 m->strictlyneedmoduleinfo = 1; 2599 2610 #endif 2600 2611 } 2612 2613 return ret; 2601 2614 } 2602 2615 2603 2616 AggregateDeclaration *StaticCtorDeclaration::isThis() … … 2654 2667 } 2655 2668 2656 2669 2657 voidStaticDtorDeclaration::semantic(Scope *sc)2670 DeferStatus<void> StaticDtorDeclaration::semantic(Scope *sc) 2658 2671 { 2659 2672 ClassDeclaration *cd; 2660 2673 Type *tret; … … 2695 2708 vgate = v; 2696 2709 } 2697 2710 2698 FuncDeclaration::semantic(sc);2711 DeferStatus<void> ret = FuncDeclaration::semantic(sc); 2699 2712 2700 2713 // We're going to need ModuleInfo 2701 2714 Module *m = getModule(); … … 2707 2720 m->strictlyneedmoduleinfo = 1; 2708 2721 #endif 2709 2722 } 2723 2724 return ret; 2710 2725 } 2711 2726 2712 2727 AggregateDeclaration *StaticDtorDeclaration::isThis() … … 2760 2775 } 2761 2776 2762 2777 2763 voidInvariantDeclaration::semantic(Scope *sc)2778 DeferStatus<void> InvariantDeclaration::semantic(Scope *sc) 2764 2779 { 2765 2780 AggregateDeclaration *ad; 2766 2781 Type *tret; … … 2771 2786 if (!ad) 2772 2787 { 2773 2788 error("invariants are only for struct/union/class definitions"); 2774 return ;2789 return nodefer(); 2775 2790 } 2776 2791 else if (ad->inv && ad->inv != this) 2777 2792 { … … 2785 2800 sc->incontract++; 2786 2801 sc->linkage = LINKd; 2787 2802 2788 FuncDeclaration::semantic(sc);2803 DeferStatus<void> ret = FuncDeclaration::semantic(sc); 2789 2804 2790 2805 sc->pop(); 2806 return ret; 2791 2807 } 2792 2808 2793 2809 int InvariantDeclaration::isVirtual() … … 2841 2857 } 2842 2858 2843 2859 2844 voidUnitTestDeclaration::semantic(Scope *sc)2860 DeferStatus<void> UnitTestDeclaration::semantic(Scope *sc) 2845 2861 { 2846 2862 if (global.params.useUnitTests) 2847 2863 { … … 2860 2876 m = sc->module; 2861 2877 if (m) 2862 2878 m->needmoduleinfo = 1; 2879 2880 return nodefer(); 2863 2881 } 2864 2882 2865 2883 AggregateDeclaration *UnitTestDeclaration::isThis() … … 2913 2931 } 2914 2932 2915 2933 2916 voidNewDeclaration::semantic(Scope *sc)2934 DeferStatus<void> NewDeclaration::semantic(Scope *sc) 2917 2935 { 2918 2936 ClassDeclaration *cd; 2919 2937 Type *tret; … … 2946 2964 error("first argument must be type size_t, not %s", a->type->toChars()); 2947 2965 } 2948 2966 2949 FuncDeclaration::semantic(sc);2967 return FuncDeclaration::semantic(sc); 2950 2968 } 2951 2969 2952 2970 const char *NewDeclaration::kind() … … 2999 3017 } 3000 3018 3001 3019 3002 voidDeleteDeclaration::semantic(Scope *sc)3020 DeferStatus<void> DeleteDeclaration::semantic(Scope *sc) 3003 3021 { 3004 3022 ClassDeclaration *cd; 3005 3023 … … 3030 3048 error("one argument of type void* expected, not %s", a->type->toChars()); 3031 3049 } 3032 3050 3033 FuncDeclaration::semantic(sc);3051 return FuncDeclaration::semantic(sc); 3034 3052 } 3035 3053 3036 3054 const char *DeleteDeclaration::kind() -
a/dmd/import.c
old new 82 82 return si; 83 83 } 84 84 85 voidImport::load(Scope *sc)85 DeferStatus<void> Import::load(Scope *sc) 86 86 { 87 87 DsymbolTable *dst; 88 88 Dsymbol *s; … … 114 114 pkg = mod; 115 115 116 116 //printf("-Import::load('%s'), pkg = %p\n", toChars(), pkg); 117 return nodefer(); 117 118 } 118 119 119 120 char* escapePath(char* fname, char* buffer, int bufLen) { … … 136 137 return buffer; 137 138 } 138 139 139 voidImport::semantic(Scope *sc)140 DeferStatus<void> Import::semantic(Scope *sc) 140 141 { 141 142 //printf("Import::semantic('%s')\n", toChars()); 142 143 143 load(sc);144 DeferStatus<void> defer = load(sc); 144 145 145 146 if (mod) 146 147 { … … 154 155 } 155 156 #endif 156 157 158 DeferStatus<void> ret = mod->semantic(); 159 if (ret.defer()) return ret; 160 157 161 // Modules need a list of each imported module 158 162 //printf("%s imports %s\n", sc->module->toChars(), mod->toChars()); 159 sc->module->aimports.push(mod); 160 161 mod->semantic(); 163 bool in_aimports = false; 164 for (int i = 0; i < sc->module->aimports.dim; ++i) 165 if (sc->module->aimports.data[i] == mod) 166 in_aimports = true; 167 if (!in_aimports) 168 sc->module->aimports.push(mod); 162 169 163 170 /* Default to private importing 164 171 */ … … 187 194 } 188 195 sc = sc->pop(); 189 196 } 197 190 198 //printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg); 191 199 192 200 … … 250 258 251 259 ob->writenl(); 252 260 } 261 262 return defer; 253 263 } 254 264 255 voidImport::semantic2(Scope *sc)265 DeferStatus<void> Import::semantic2(Scope *sc) 256 266 { 257 267 //printf("Import::semantic2('%s')\n", toChars()); 258 268 mod->semantic2(); 259 269 if (mod->needmoduleinfo) 260 270 sc->module->needmoduleinfo = 1; 271 return nodefer(); 261 272 } 262 273 263 274 Dsymbol *Import::toAlias() … … 302 313 return result; 303 314 } 304 315 305 D symbol *Import::search(Loc loc, Identifier *ident, int flags)316 DeferStatus<Dsymbol*> Import::search(Loc loc, Identifier *ident, int flags) 306 317 { 307 318 //printf("%s.Import::search(ident = '%s', flags = x%x)\n", toChars(), ident->toChars(), flags); 308 319 -
a/dmd/import.h
old new 52 52 const char *kind(); 53 53 enum PROT prot(); 54 54 Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees 55 voidload(Scope *sc);56 voidsemantic(Scope *sc);57 voidsemantic2(Scope *sc);55 DeferStatus<void> load(Scope *sc); 56 DeferStatus<void> semantic(Scope *sc); 57 DeferStatus<void> semantic2(Scope *sc); 58 58 Dsymbol *toAlias(); 59 59 int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 60 D symbol *search(Loc loc, Identifier *ident, int flags);60 DeferStatus<Dsymbol*> search(Loc loc, Identifier *ident, int flags); 61 61 int overloadInsert(Dsymbol *s); 62 62 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 63 63 -
a/dmd/init.c
old new 39 39 return this; 40 40 } 41 41 42 Type *Initializer::inferType(Scope *sc)42 DeferStatus<Type*> Initializer::inferType(Scope *sc) 43 43 { 44 44 error(loc, "cannot infer type from initializer"); 45 45 return Type::terror; … … 464 464 } 465 465 466 466 467 Type *ArrayInitializer::inferType(Scope *sc)467 DeferStatus<Type*> ArrayInitializer::inferType(Scope *sc) 468 468 { 469 469 for (size_t i = 0; i < value.dim; i++) 470 470 { … … 563 563 return this; 564 564 } 565 565 566 Type *ExpInitializer::inferType(Scope *sc)566 DeferStatus<Type*> ExpInitializer::inferType(Scope *sc) 567 567 { 568 568 //printf("ExpInitializer::inferType() %s\n", toChars()); 569 exp = exp->semantic(sc); 569 DeferStatus<Expression*> ret = exp->semantic(sc); 570 if (ret.defer()) 571 return ret; 572 exp = ret; 570 573 exp = resolveProperties(sc, exp); 571 574 572 575 #if DMDV2 -
a/dmd/init.h
old new 37 37 Initializer(Loc loc); 38 38 virtual Initializer *syntaxCopy(); 39 39 virtual Initializer *semantic(Scope *sc, Type *t); 40 virtual Type *inferType(Scope *sc);40 virtual DeferStatus<Type*> inferType(Scope *sc); 41 41 virtual Expression *toExpression() = 0; 42 42 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs) = 0; 43 43 char *toChars(); … … 105 105 Initializer *syntaxCopy(); 106 106 void addInit(Expression *index, Initializer *value); 107 107 Initializer *semantic(Scope *sc, Type *t); 108 Type *inferType(Scope *sc);108 DeferStatus<Type*> inferType(Scope *sc); 109 109 Expression *toExpression(); 110 110 Initializer *toAssocArrayInitializer(); 111 111 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 125 125 ExpInitializer(Loc loc, Expression *exp); 126 126 Initializer *syntaxCopy(); 127 127 Initializer *semantic(Scope *sc, Type *t); 128 Type *inferType(Scope *sc);128 DeferStatus<Type*> inferType(Scope *sc); 129 129 Expression *toExpression(); 130 130 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 131 131 -
a/dmd/module.c
old new 63 63 DsymbolTable *Module::modules; 64 64 Array Module::amodules; 65 65 66 ArrayModule::deferred; // deferred Dsymbol's needing semantic() run on them66 std::deque<DeferredDsymbol> Module::deferred; // deferred Dsymbol's needing semantic() run on them 67 67 unsigned Module::dprogress; 68 68 69 69 void Module::init() … … 148 148 llvmForceLogging = false; 149 149 this->doDocComment = doDocComment; 150 150 this->doHdrGen = doHdrGen; 151 sc = NULL; 151 152 } 152 153 153 154 File* Module::buildFilePath(const char* forcename, const char* path, const char* ext) … … 635 636 } 636 637 } 637 638 638 voidModule::semantic(Scope* unused_sc)639 DeferStatus<void> Module::semantic(Scope* unused_sc) 639 640 { int i; 640 641 641 if (semanticstarted) 642 return; 642 // if already done or circular, bail out 643 if (semanticdone || semanticstarted == 1) 644 return nodefer(); 643 645 644 //printf("+Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); 645 semanticstarted = 1; 646 if (semanticstarted == 0) 647 { 648 //printf("+Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); 649 semanticstarted = 1; 646 650 647 // Note that modules get their own scope, from scratch.648 // This is so regardless of where in the syntax a module649 // gets imported, it is unaffected by context.650 Scope *sc = Scope::createGlobal(this); // create root scope651 // Note that modules get their own scope, from scratch. 652 // This is so regardless of where in the syntax a module 653 // gets imported, it is unaffected by context. 654 sc = Scope::createGlobal(this); // create root scope 651 655 652 //printf("Module = %p, linkage = %d\n", sc->scopesym, sc->linkage);656 //printf("Module = %p, linkage = %d\n", sc->scopesym, sc->linkage); 653 657 654 // Add import of "object" if this module isn't "object"655 if (ident != Id::object)656 {657 Import *im = new Import(0, NULL, Id::object, NULL, 0);658 members->shift(im);659 }658 // Add import of "object" if this module isn't "object" 659 if (ident != Id::object) 660 { 661 Import *im = new Import(0, NULL, Id::object, NULL, 0); 662 members->shift(im); 663 } 660 664 661 // Add all symbols into module's symbol table662 symtab = new DsymbolTable();663 for (i = 0; i < members->dim; i++)664 { Dsymbol *s;665 // Add all symbols into module's symbol table 666 symtab = new DsymbolTable(); 667 for (i = 0; i < members->dim; i++) 668 { Dsymbol *s; 665 669 666 s = (Dsymbol *)members->data[i]; 667 s->addMember(NULL, sc->scopesym, 1); 670 s = (Dsymbol *)members->data[i]; 671 s->addMember(NULL, sc->scopesym, 1); 672 } 668 673 } 669 674 670 675 // Pass 1 semantic routines: do public side of the definition 671 for (i = 0; i < members->dim; i++) 672 { Dsymbol *s; 673 674 s = (Dsymbol *)members->data[i]; 675 //printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars()); 676 s->semantic(sc); 677 runDeferredSemantic(); 676 DeferStatus<void> res = callSemanticOnMembers(sc); 677 if (res.defer()) { 678 semanticstarted = -1; 679 return res; 678 680 } 679 681 680 682 sc = sc->pop(); 681 683 sc->pop(); 682 semanticdone = semanticstarted; 684 semanticstarted = 1; 685 semanticdone = 1; 683 686 //printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); 687 return nodefer(); 684 688 } 685 689 686 voidModule::semantic2(Scope* unused_sc)690 DeferStatus<void> Module::semantic2(Scope* unused_sc) 687 691 { int i; 688 692 689 if ( deferred.dim)693 if (!deferred.empty()) 690 694 { 691 for (int i = 0; i < deferred. dim; i++)695 for (int i = 0; i < deferred.size(); i++) 692 696 { 693 Dsymbol *sd = (Dsymbol *)deferred.data[i];697 Dsymbol *sd = deferred[i].sym; 694 698 695 699 sd->error("unable to resolve forward reference in definition"); 696 700 } 697 return ;701 return nodefer(); 698 702 } 699 703 //printf("Module::semantic2('%s'): parent = %p\n", toChars(), parent); 700 704 if (semanticstarted >= 2) 701 return ;705 return nodefer(); 702 706 assert(semanticstarted == 1); 703 707 semanticstarted = 2; 704 708 … … 720 724 sc->pop(); 721 725 semanticdone = semanticstarted; 722 726 //printf("-Module::semantic2('%s'): parent = %p\n", toChars(), parent); 727 return nodefer(); 723 728 } 724 729 725 voidModule::semantic3(Scope* unused_sc)730 DeferStatus<void> Module::semantic3(Scope* unused_sc) 726 731 { int i; 727 732 728 733 //printf("Module::semantic3('%s'): parent = %p\n", toChars(), parent); 729 734 if (semanticstarted >= 3) 730 return ;735 return nodefer(); 731 736 assert(semanticstarted == 2); 732 737 semanticstarted = 3; 733 738 … … 749 754 sc = sc->pop(); 750 755 sc->pop(); 751 756 semanticdone = semanticstarted; 757 return nodefer(); 752 758 } 753 759 754 760 void Module::inlineScan() … … 814 820 return needmoduleinfo; 815 821 } 816 822 817 D symbol *Module::search(Loc loc, Identifier *ident, int flags)823 DeferStatus<Dsymbol*> Module::search(Loc loc, Identifier *ident, int flags) 818 824 { 819 825 /* Since modules can be circularly referenced, 820 826 * need to stop infinite recursive searches. … … 832 838 s = ScopeDsymbol::search(loc, ident, flags); 833 839 insearch = 0; 834 840 841 if (!s && semanticstarted == -1) 842 error("Forward reference!"); 843 835 844 searchCacheIdent = ident; 836 845 searchCacheSymbol = s; 837 846 searchCacheFlags = flags; … … 843 852 * Can't run semantic on s now, try again later. 844 853 */ 845 854 846 void Module::addDeferredSemantic(Dsymbol *s )855 void Module::addDeferredSemantic(Dsymbol *sym, Scope *scope) 847 856 { 848 857 // Don't add it if it is already there 849 for (int i = 0; i < deferred. dim; i++)858 for (int i = 0; i < deferred.size(); i++) 850 859 { 851 Dsymbol *sd = (Dsymbol *)deferred .data[i];860 Dsymbol *sd = (Dsymbol *)deferred[i].sym; 852 861 853 if (sd == s )862 if (sd == sym) 854 863 return; 855 864 } 856 865 866 // copy scope 867 Scope* scx = new Scope(*scope); 868 scx->setNoFree(); 869 857 870 //printf("Module::addDeferredSemantic('%s')\n", s->toChars()); 858 deferred.push (s);871 deferred.push_back(DeferredDsymbol(sym, scx)); 859 872 } 860 873 861 874 … … 865 878 866 879 void Module::runDeferredSemantic() 867 880 { 868 size_t len;881 //if (deferred.dim) printf("+Module::runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim); 869 882 870 883 static int nested; 871 884 if (nested) 872 885 return; 873 //if (deferred.dim) printf("+Module::runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim);874 886 nested++; 875 887 876 do 877 { 878 dprogress = 0; 879 len = deferred.dim; 880 if (!len) 881 break; 888 int failed = 0; 882 889 883 Dsymbol **todo; 884 Dsymbol *tmp; 885 if (len == 1) 890 // last defer exception that was caught. stored for the error message inside 891 DeferStatus<void> lastdefer; 892 893 // if we deferred an order dependent member, save it here 894 // we will then skip all order dependent members until this is reached again 895 Dsymbol *deferredOrderDependent = NULL; 896 897 while (!deferred.empty() && failed != deferred.size()) 898 { Dsymbol *s; 899 Scope *sc; 900 s = deferred[0].sym; 901 sc = deferred[0].scope; 902 deferred.pop_front(); 903 904 // if we deferred something order dependent, skip other 905 // order dependent ones for one iteration 906 if (deferredOrderDependent == s) 907 deferredOrderDependent = NULL; 908 if (deferredOrderDependent && !isMemberReorderable(s)) { 909 ++failed; 910 deferred.push_back(DeferredDsymbol(s, sc)); 911 continue; 912 } 913 914 DeferStatus<void> res = s->semantic(sc); 915 if (!res.defer()) 886 916 { 887 todo = &tmp; 917 if (!deferred.empty() && deferred.rbegin()->sym == s) 918 ++failed; 919 else 920 failed = 0; 888 921 } 889 else 922 else 890 923 { 891 todo = (Dsymbol **)alloca(len * sizeof(Dsymbol *)); 892 assert(todo); 924 lastdefer = res; 925 ++failed; 926 deferred.push_back(DeferredDsymbol(s, sc)); 927 if (!isMemberReorderable(s)) 928 deferredOrderDependent = s; 929 continue; 893 930 } 894 memcpy(todo, deferred.data, len * sizeof(Dsymbol *)); 895 deferred.setDim(0); 931 } 896 932 897 for (int i = 0; i < len; i++)898 {899 Dsymbol *s = todo[i];900 901 s->semantic(NULL);902 //printf("deferred: %s, parent = %s\n", s->toChars(), s->parent->toChars());903 }904 //printf("\tdeferred.dim = %d, len = %d, dprogress = %d\n", deferred.dim, len, dprogress);905 } while (deferred.dim < len || dprogress); // while making progress906 933 nested--; 907 934 //printf("-Module::runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim); 908 935 } -
a/dmd/module.h
old new 17 17 18 18 #include "root.h" 19 19 #include "dsymbol.h" 20 #include <deque> 20 21 21 22 struct ModuleInfoDeclaration; 22 23 struct ClassDeclaration; … … 41 42 #endif 42 43 #endif 43 44 45 // The global list of out-of-order deferred Dsymbols 46 // contains elements of this type. In addition to the 47 // Dsymbol, they hold the scope that's to be used for 48 // the deferred semantic call. 49 struct DeferredDsymbol 50 { 51 DeferredDsymbol(Dsymbol* sym_, Scope* scope_) 52 : sym(sym_), scope(scope_) {} 53 54 Dsymbol* sym; 55 Scope* scope; 56 }; 57 44 58 struct Package : ScopeDsymbol 45 59 { 46 60 Package(Identifier *ident); … … 50 64 51 65 Package *isPackage() { return this; } 52 66 53 virtual void semantic(Scope *sc) {}67 virtual DeferStatus<void> semantic(Scope *sc) { return nodefer(); } 54 68 }; 55 69 56 70 struct Module : Package … … 58 72 static Module *rootModule; 59 73 static DsymbolTable *modules; // symbol table of all modules 60 74 static Array amodules; // array of all modules 61 static Arraydeferred; // deferred Dsymbol's needing semantic() run on them75 static std::deque<DeferredDsymbol> deferred; // deferred Dsymbol's needing semantic() run on them 62 76 static unsigned dprogress; // progress resolving the deferred list 63 77 static void init(); 64 78 … … 132 146 #else 133 147 void parse(); // syntactic parse 134 148 #endif 135 voidsemantic(Scope* unused_sc = NULL); // semantic analysis136 voidsemantic2(Scope* unused_sc = NULL); // pass 2 semantic analysis137 voidsemantic3(Scope* unused_sc = NULL); // pass 3 semantic analysis149 DeferStatus<void> semantic(Scope* unused_sc = NULL); // semantic analysis 150 DeferStatus<void> semantic2(Scope* unused_sc = NULL); // pass 2 semantic analysis 151 DeferStatus<void> semantic3(Scope* unused_sc = NULL); // pass 3 semantic analysis 138 152 void inlineScan(); // scan for functions to inline 139 153 #ifdef _DH 140 154 void genhdrfile(); // generate D import file … … 142 156 // void gensymfile(); 143 157 void gendocfile(); 144 158 int needModuleInfo(); 145 D symbol *search(Loc loc, Identifier *ident, int flags);159 DeferStatus<Dsymbol*> search(Loc loc, Identifier *ident, int flags); 146 160 void deleteObjFile(); 147 void addDeferredSemantic(Dsymbol *s );161 void addDeferredSemantic(Dsymbol *sym, Scope* scope); 148 162 void runDeferredSemantic(); 149 163 int imports(Module *m); 150 164 … … 188 202 // array ops emitted in this module already 189 203 StringTable arrayfuncs; 190 204 #endif 205 206 // LDC 207 virtual void postMemberSemantic(Scope* sc) { runDeferredSemantic(); } 208 Scope* sc; 191 209 }; 192 210 193 211 -
a/dmd/mtype.c
old new 307 307 return size(0); 308 308 } 309 309 310 Type *Type::semantic(Loc loc, Scope *sc)310 DeferStatus<Type*> Type::semantic(Loc loc, Scope *sc) 311 311 { 312 312 if (next) 313 313 next = next->semantic(loc,sc); … … 676 676 return e; 677 677 } 678 678 679 Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)679 DeferStatus<Expression*> Type::dotExp(Scope *sc, Expression *e, Identifier *ident) 680 680 { VarDeclaration *v = NULL; 681 681 682 682 #if LOGDOTEXP … … 820 820 } 821 821 822 822 823 voidType::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps)823 DeferStatus<void> Type::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) 824 824 { 825 825 //printf("Type::resolve() %s, %d\n", toChars(), ty); 826 826 Type *t = semantic(loc, sc); 827 827 *pt = t; 828 828 *pe = NULL; 829 829 *ps = NULL; 830 return nodefer(); 830 831 } 831 832 832 833 /******************************* … … 1339 1340 return e; 1340 1341 } 1341 1342 1342 Expression *TypeBasic::dotExp(Scope *sc, Expression *e, Identifier *ident)1343 DeferStatus<Expression*> TypeBasic::dotExp(Scope *sc, Expression *e, Identifier *ident) 1343 1344 { 1344 1345 #if LOGDOTEXP 1345 1346 printf("TypeBasic::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); … … 1585 1586 { 1586 1587 } 1587 1588 1588 Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident)1589 DeferStatus<Expression*> TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident) 1589 1590 { 1590 1591 Type *n = this->next->toBasetype(); // uncover any typedef's 1591 1592 … … 1804 1805 * This evaluates exp while setting length to be the number 1805 1806 * of elements in the tuple t. 1806 1807 */ 1807 Expression *semanticLength(Scope *sc, Type *t, Expression *exp) 1808 { 1808 DeferStatus<Expression*> semanticLength(Scope *sc, Type *t, Expression *exp) 1809 { 1810 DeferStatus<Expression*> ret; 1809 1811 if (t->ty == Ttuple) 1810 1812 { ScopeDsymbol *sym = new ArrayScopeSymbol((TypeTuple *)t); 1811 1813 sym->parent = sc->scopesym; 1812 1814 sc = sc->push(sym); 1813 1815 1814 exp= exp->semantic(sc);1816 ret = exp->semantic(sc); 1815 1817 1816 1818 sc->pop(); 1817 1819 } 1818 1820 else 1819 exp= exp->semantic(sc);1820 return exp;1821 } 1822 1823 Expression *semanticLength(Scope *sc, TupleDeclaration *s, Expression *exp)1821 ret = exp->semantic(sc); 1822 return ret; 1823 } 1824 1825 DeferStatus<Expression*> semanticLength(Scope *sc, TupleDeclaration *s, Expression *exp) 1824 1826 { 1825 1827 ScopeDsymbol *sym = new ArrayScopeSymbol(s); 1826 1828 sym->parent = sc->scopesym; 1827 1829 sc = sc->push(sym); 1828 1830 1829 exp= exp->semantic(sc);1831 DeferStatus<Expression*> ret = exp->semantic(sc); 1830 1832 1831 1833 sc->pop(); 1832 return exp;1833 } 1834 1835 voidTypeSArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps)1834 return ret; 1835 } 1836 1837 DeferStatus<void> TypeSArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) 1836 1838 { 1837 1839 //printf("TypeSArray::resolve() %s\n", toChars()); 1838 1840 next->resolve(loc, sc, pe, pt, ps); … … 1866 1868 if (o->dyncast() == DYNCAST_DSYMBOL) 1867 1869 { 1868 1870 *ps = (Dsymbol *)o; 1869 return ;1871 return nodefer(); 1870 1872 } 1871 1873 if (o->dyncast() == DYNCAST_EXPRESSION) 1872 1874 { 1873 1875 *ps = NULL; 1874 1876 *pe = (Expression *)o; 1875 return ;1877 return nodefer(); 1876 1878 } 1877 1879 1878 1880 /* Create a new TupleDeclaration which … … 1893 1895 else 1894 1896 { 1895 1897 Ldefault: 1896 Type::resolve(loc, sc, pe, pt, ps); 1897 } 1898 } 1899 1900 Type *TypeSArray::semantic(Loc loc, Scope *sc) 1898 return Type::resolve(loc, sc, pe, pt, ps); 1899 } 1900 return nodefer(); 1901 } 1902 1903 DeferStatus<Type*> TypeSArray::semantic(Loc loc, Scope *sc) 1901 1904 { 1902 1905 //printf("TypeSArray::semantic() %s\n", toChars()); 1903 1906 … … 1908 1911 if (dim && s && s->isTupleDeclaration()) 1909 1912 { TupleDeclaration *sd = s->isTupleDeclaration(); 1910 1913 1911 dim = semanticLength(sc, sd, dim); 1912 dim = dim->optimize(WANTvalue | WANTinterpret); 1914 DeferStatus<Expression*> ret = semanticLength(sc, sd, dim); 1915 if (ret.defer()) return ret; 1916 dim = ret->optimize(WANTvalue | WANTinterpret); 1913 1917 uinteger_t d = dim->toUInteger(); 1914 1918 1915 1919 if (d >= sd->objects->dim) … … 1931 1935 if (dim) 1932 1936 { dinteger_t n, n2; 1933 1937 1934 dim= semanticLength(sc, tbn, dim);1935 1936 dim = dim->optimize(WANTvalue | WANTinterpret);1938 DeferStatus<Expression*> ret = semanticLength(sc, tbn, dim); 1939 if (ret.defer()) return ret; 1940 dim = ret->optimize(WANTvalue | WANTinterpret); 1937 1941 if (sc && sc->parameterSpecialization && dim->op == TOKvar && 1938 1942 ((VarExp *)dim)->var->storage_class & STCtemplateparameter) 1939 1943 { … … 2020 2024 buf->printf("[%s]", dim->toChars()); 2021 2025 } 2022 2026 2023 Expression *TypeSArray::dotExp(Scope *sc, Expression *e, Identifier *ident)2027 DeferStatus<Expression*> TypeSArray::dotExp(Scope *sc, Expression *e, Identifier *ident) 2024 2028 { 2025 2029 #if LOGDOTEXP 2026 2030 printf("TypeSArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); … … 2145 2149 return PTRSIZE; 2146 2150 } 2147 2151 2148 Type *TypeDArray::semantic(Loc loc, Scope *sc)2152 DeferStatus<Type*> TypeDArray::semantic(Loc loc, Scope *sc) 2149 2153 { Type *tn = next; 2150 2154 2151 2155 tn = next->semantic(loc,sc); … … 2184 2188 buf->writestring("[]"); 2185 2189 } 2186 2190 2187 Expression *TypeDArray::dotExp(Scope *sc, Expression *e, Identifier *ident)2191 DeferStatus<Expression*> TypeDArray::dotExp(Scope *sc, Expression *e, Identifier *ident) 2188 2192 { 2189 2193 #if LOGDOTEXP 2190 2194 printf("TypeDArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); … … 2292 2296 } 2293 2297 2294 2298 2295 Type *TypeAArray::semantic(Loc loc, Scope *sc)2299 DeferStatus<Type*> TypeAArray::semantic(Loc loc, Scope *sc) 2296 2300 { 2297 2301 //printf("TypeAArray::semantic() %s index->ty = %d\n", toChars(), index->ty); 2298 2302 … … 2364 2368 return merge(); 2365 2369 } 2366 2370 2367 voidTypeAArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps)2371 DeferStatus<void> TypeAArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) 2368 2372 { 2369 2373 //printf("TypeAArray::resolve() %s\n", toChars()); 2370 2374 … … 2389 2393 else 2390 2394 index->error(loc, "index is not a type or an expression"); 2391 2395 } 2392 Type::resolve(loc, sc, pe, pt, ps);2393 } 2394 2395 2396 Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident)2396 return Type::resolve(loc, sc, pe, pt, ps); 2397 } 2398 2399 2400 DeferStatus<Expression*> TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident) 2397 2401 { 2398 2402 #if LOGDOTEXP 2399 2403 printf("TypeAArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); … … 2555 2559 return t; 2556 2560 } 2557 2561 2558 Type *TypePointer::semantic(Loc loc, Scope *sc)2562 DeferStatus<Type*> TypePointer::semantic(Loc loc, Scope *sc) 2559 2563 { 2560 2564 //printf("TypePointer::semantic()\n"); 2561 2565 Type *n = next->semantic(loc, sc); … … 2682 2686 buf->writeByte('&'); 2683 2687 } 2684 2688 2685 Expression *TypeReference::dotExp(Scope *sc, Expression *e, Identifier *ident)2689 DeferStatus<Expression*> TypeReference::dotExp(Scope *sc, Expression *e, Identifier *ident) 2686 2690 { 2687 2691 #if LOGDOTEXP 2688 2692 printf("TypeReference::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); … … 2956 2960 inuse--; 2957 2961 } 2958 2962 2959 Type *TypeFunction::semantic(Loc loc, Scope *sc)2963 DeferStatus<Type*> TypeFunction::semantic(Loc loc, Scope *sc) 2960 2964 { 2961 2965 if (deco) // if semantic() already run 2962 2966 { … … 3007 3011 Type *t; 3008 3012 3009 3013 tf->inuse++; 3010 arg->type = arg->type->semantic(loc,sc); 3014 DeferStatus<Type*> ret = arg->type->semantic(loc,sc); 3015 if (ret.defer()) return ret; 3016 arg->type = ret; 3011 3017 if (tf->inuse == 1) tf->inuse--; 3012 3018 3013 3019 // each function needs its own copy of a tuple arg, since … … 3217 3223 return t; 3218 3224 } 3219 3225 3220 Type *TypeDelegate::semantic(Loc loc, Scope *sc)3226 DeferStatus<Type*> TypeDelegate::semantic(Loc loc, Scope *sc) 3221 3227 { 3222 3228 if (deco) // if semantic() already run 3223 3229 { … … 3275 3281 return TRUE; 3276 3282 } 3277 3283 3278 Expression *TypeDelegate::dotExp(Scope *sc, Expression *e, Identifier *ident)3284 DeferStatus<Expression*> TypeDelegate::dotExp(Scope *sc, Expression *e, Identifier *ident) 3279 3285 { 3280 3286 #if LOGDOTEXP 3281 3287 printf("TypeDelegate::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); … … 3371 3377 * if type, *pt is set 3372 3378 */ 3373 3379 3374 voidTypeQualified::resolveHelper(Loc loc, Scope *sc,3380 DeferStatus<void> TypeQualified::resolveHelper(Loc loc, Scope *sc, 3375 3381 Dsymbol *s, Dsymbol *scopesym, 3376 3382 Expression **pe, Type **pt, Dsymbol **ps) 3377 3383 { … … 3401 3407 { Dsymbol *sm; 3402 3408 3403 3409
