Changeset 1526:54b3c1394d62
- Timestamp:
- 07/06/09 21:26:11 (3 years ago)
- Files:
-
- dmd2/arrayop.c (modified) (2 diffs)
- dmd2/attrib.c (modified) (14 diffs)
- dmd2/attrib.h (modified) (4 diffs)
- dmd2/cast.c (modified) (10 diffs)
- dmd2/class.c (modified) (6 diffs)
- dmd2/cond.c (modified) (1 diff)
- dmd2/constfold.c (modified) (1 diff)
- dmd2/declaration.c (modified) (21 diffs)
- dmd2/declaration.h (modified) (3 diffs)
- dmd2/dsymbol.c (modified) (9 diffs)
- dmd2/dsymbol.h (modified) (5 diffs)
- dmd2/enum.c (modified) (1 diff)
- dmd2/enum.h (modified) (1 diff)
- dmd2/expression.c (modified) (28 diffs)
- dmd2/expression.h (modified) (14 diffs)
- dmd2/func.c (modified) (15 diffs)
- dmd2/import.c (modified) (7 diffs)
- dmd2/import.h (modified) (2 diffs)
- dmd2/inifile.c (modified) (2 diffs)
- dmd2/init.c (modified) (4 diffs)
- dmd2/interpret.c (modified) (2 diffs)
- dmd2/lexer.c (modified) (1 diff)
- dmd2/mangle.c (modified) (1 diff)
- dmd2/mars.c (modified) (1 diff)
- dmd2/mars.h (modified) (2 diffs)
- dmd2/module.c (modified) (8 diffs)
- dmd2/module.h (modified) (1 diff)
- dmd2/mtype.c (modified) (23 diffs)
- dmd2/mtype.h (modified) (2 diffs)
- dmd2/opover.c (modified) (4 diffs)
- dmd2/optimize.c (modified) (2 diffs)
- dmd2/parse.c (modified) (14 diffs)
- dmd2/root/async.c (modified) (2 diffs)
- dmd2/scope.c (modified) (2 diffs)
- dmd2/scope.h (modified) (1 diff)
- dmd2/statement.c (modified) (18 diffs)
- dmd2/statement.h (modified) (17 diffs)
- dmd2/struct.c (modified) (4 diffs)
- dmd2/template.c (modified) (30 diffs)
- dmd2/template.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dmd2/arrayop.c
r1452 r1526 1 1 2 // Copyright (c) 1999-200 8by Digital Mars2 // Copyright (c) 1999-2009 by Digital Mars 3 3 // All Rights Reserved 4 4 // written by Walter Bright … … 436 436 */ 437 437 Expression *ex2 = e2->buildArrayLoop(fparams); 438 /* Need the cast because: 439 * b = c + p[i]; 440 * where b is a byte fails because (c + p[i]) is an int 441 * which cannot be implicitly cast to byte. 442 */ 443 ex2 = new CastExp(0, ex2, e1->type->nextOf()); 438 444 Expression *ex1 = e1->buildArrayLoop(fparams); 439 445 Argument *param = (Argument *)fparams->data[0]; dmd2/attrib.c
r1452 r1526 27 27 #include "parse.h" 28 28 #include "template.h" 29 #if TARGET_NET 30 #include "frontend.net/pragma.h" 31 #endif 29 32 30 33 #if IN_LLVM … … 73 76 } 74 77 return m; 78 } 79 80 void AttribDeclaration::semanticNewSc(Scope *sc, 81 unsigned stc, enum LINK linkage, enum PROT protection, int explicitProtection, 82 unsigned structalign) 83 { 84 if (decl) 85 { 86 Scope *newsc = sc; 87 if (stc != sc->stc || 88 linkage != sc->linkage || 89 protection != sc->protection || 90 explicitProtection != sc->explicitProtection || 91 structalign != sc->structalign) 92 { 93 // create new one for changes 94 newsc = new Scope(*sc); 95 newsc->flags &= ~SCOPEfree; 96 newsc->stc = stc; 97 newsc->linkage = linkage; 98 newsc->protection = protection; 99 newsc->explicitProtection = explicitProtection; 100 newsc->structalign = structalign; 101 } 102 for (unsigned i = 0; i < decl->dim; i++) 103 { Dsymbol *s = (Dsymbol *)decl->data[i]; 104 105 s->semantic(newsc); 106 } 107 if (newsc != sc) 108 { 109 sc->offset = newsc->offset; 110 newsc->pop(); 111 } 112 } 75 113 } 76 114 … … 306 344 { 307 345 if (decl) 308 { unsigned stc_save = sc->stc; 309 310 if (stc & (STCauto | STCscope | STCstatic | STCextern)) 311 sc->stc &= ~(STCauto | STCscope | STCstatic | STCextern); 346 { 347 #if 1 348 unsigned scstc = sc->stc; 349 350 /* These sets of storage classes are mutually exclusive, 351 * so choose the innermost or most recent one. 352 */ 353 if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest)) 354 scstc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest); 355 if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared)) 356 scstc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared); 357 if (stc & (STCconst | STCimmutable | STCmanifest)) 358 scstc &= ~(STCconst | STCimmutable | STCmanifest); 359 if (stc & (STCgshared | STCshared | STCtls)) 360 scstc &= ~(STCgshared | STCshared | STCtls); 361 scstc |= stc; 362 363 semanticNewSc(sc, scstc, sc->linkage, sc->protection, sc->explicitProtection, sc->structalign); 364 #else 365 unsigned stc_save = sc->stc; 366 367 /* These sets of storage classes are mutually exclusive, 368 * so choose the innermost or most recent one. 369 */ 370 if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest)) 371 sc->stc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest); 372 if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared)) 373 sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared); 374 if (stc & (STCconst | STCimmutable | STCmanifest)) 375 sc->stc &= ~(STCconst | STCimmutable | STCmanifest); 376 if (stc & (STCgshared | STCshared | STCtls)) 377 sc->stc &= ~(STCgshared | STCshared | STCtls); 312 378 sc->stc |= stc; 313 379 for (unsigned i = 0; i < decl->dim; i++) … … 318 384 } 319 385 sc->stc = stc_save; 320 } 321 else 322 sc->stc = stc; 386 #endif 387 } 323 388 } 324 389 … … 394 459 //printf("LinkDeclaration::semantic(linkage = %d, decl = %p)\n", linkage, decl); 395 460 if (decl) 396 { enum LINK linkage_save = sc->linkage; 461 { 462 #if 1 463 semanticNewSc(sc, sc->stc, linkage, sc->protection, sc->explicitProtection, sc->structalign); 464 #else 465 enum LINK linkage_save = sc->linkage; 397 466 398 467 sc->linkage = linkage; … … 404 473 } 405 474 sc->linkage = linkage_save; 406 } 407 else 408 { 409 sc->linkage = linkage; 475 #endif 410 476 } 411 477 } … … 482 548 { 483 549 if (decl) 484 { enum PROT protection_save = sc->protection; 550 { 551 #if 1 552 semanticNewSc(sc, sc->stc, sc->linkage, protection, 1, sc->structalign); 553 #else 554 enum PROT protection_save = sc->protection; 485 555 int explicitProtection_save = sc->explicitProtection; 486 556 … … 495 565 sc->protection = protection_save; 496 566 sc->explicitProtection = explicitProtection_save; 497 } 498 else 499 { sc->protection = protection; 500 sc->explicitProtection = 1; 501 } 502 } 503 504 void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 505 { const char *p; 567 #endif 568 } 569 } 570 571 void ProtDeclaration::protectionToCBuffer(OutBuffer *buf, enum PROT protection) 572 { 573 const char *p; 506 574 507 575 switch (protection) … … 517 585 } 518 586 buf->writestring(p); 587 buf->writeByte(' '); 588 } 589 590 void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 591 { 592 protectionToCBuffer(buf, protection); 519 593 AttribDeclaration::toCBuffer(buf, hgs); 520 594 } … … 546 620 //printf("\tAlignDeclaration::semantic '%s'\n",toChars()); 547 621 if (decl) 548 { unsigned salign_save = sc->structalign; 622 { 623 #if 1 624 semanticNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign); 625 #else 626 unsigned salign_save = sc->structalign; 627 549 628 #if IN_DMD 550 629 sc->structalign = salign; … … 554 633 Dsymbol *s = (Dsymbol *)decl->data[i]; 555 634 635 #if IN_LLVM 556 636 if (s->isStructDeclaration() && salign == 1) 557 637 { … … 562 642 else 563 643 { 644 #endif 564 645 s->semantic(sc); 565 } 646 #if IN_LLVM 647 } 648 #endif 566 649 } 567 650 sc->structalign = salign_save; 651 #endif 568 652 } 569 653 else … … 585 669 this->loc = loc; 586 670 this->isunion = isunion; 587 this->scope = NULL;588 671 this->sem = 0; 589 672 } … … 896 979 goto Lnodecl; 897 980 } 898 981 #if TARGET_NET 982 else if (ident == Lexer::idPool("assembly")) 983 { 984 if (!args || args->dim != 1) 985 error("pragma has invalid number of arguments"); 986 else 987 { 988 Expression *e = (Expression *)args->data[0]; 989 e = e->semantic(sc); 990 e = e->optimize(WANTvalue | WANTinterpret); 991 args->data[0] = (void *)e; 992 if (e->op != TOKstring) 993 { 994 error("string expected, not '%s'", e->toChars()); 995 } 996 PragmaScope* pragma = new PragmaScope(this, sc->parent, static_cast<StringExp*>(e)); 997 decl = new Array; 998 decl->push(pragma); 999 } 1000 } 1001 #endif // TARGET_NET 899 1002 // LDC 900 1003 #if IN_LLVM dmd2/attrib.h
r1452 r1526 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-200 7by Digital Mars3 // Copyright (c) 1999-2009 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright … … 37 37 virtual Array *include(Scope *sc, ScopeDsymbol *s); 38 38 int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 39 void semanticNewSc(Scope *sc, 40 unsigned newstc, enum LINK linkage, enum PROT protection, int explictProtection, 41 unsigned structalign); 39 42 void semantic(Scope *sc); 40 43 void semantic2(Scope *sc); … … 93 96 void semantic(Scope *sc); 94 97 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 98 99 static void protectionToCBuffer(OutBuffer *buf, enum PROT protection); 95 100 }; 96 101 … … 108 113 { 109 114 int isunion; 110 Scope *scope; // !=NULL means context to use111 115 int sem; // 1 if successful semantic() 112 116 dmd2/cast.c
r1452 r1526 34 34 { TY tyfrom = type->toBasetype()->ty; 35 35 TY tyto = t->toBasetype()->ty; 36 #if DMDV1 36 37 if (global.params.warnings && 37 38 Type::impcnvWarn[tyfrom][tyto] && … … 42 43 if (e->op == TOKint64) 43 44 return e->implicitCastTo(sc, t); 44 45 45 if (tyfrom == Tint32 && 46 46 (op == TOKadd || op == TOKmin || … … 62 62 } 63 63 } 64 #endif 64 65 #if DMDV2 65 66 if (match == MATCHconst && t == type->constOf()) … … 145 146 if (match != MATCHnomatch) 146 147 return match; 148 149 /* See if we can do integral narrowing conversions 150 */ 151 if (type->isintegral() && t->isintegral() && 152 type->isTypeBasic() && t->isTypeBasic()) 153 { IntRange ir = getIntRange(); 154 if (ir.imax <= t->sizemask()) 155 return MATCHconvert; 156 } 157 147 158 #if 0 148 159 Type *tb = t->toBasetype(); … … 677 688 } 678 689 690 MATCH OrExp::implicitConvTo(Type *t) 691 { 692 MATCH result = Expression::implicitConvTo(t); 693 694 if (result == MATCHnomatch) 695 { 696 MATCH m1 = e1->implicitConvTo(t); 697 MATCH m2 = e2->implicitConvTo(t); 698 699 // Pick the worst match 700 result = (m1 < m2) ? m1 : m2; 701 } 702 return result; 703 } 704 705 MATCH XorExp::implicitConvTo(Type *t) 706 { 707 MATCH result = Expression::implicitConvTo(t); 708 709 if (result == MATCHnomatch) 710 { 711 MATCH m1 = e1->implicitConvTo(t); 712 MATCH m2 = e2->implicitConvTo(t); 713 714 // Pick the worst match 715 result = (m1 < m2) ? m1 : m2; 716 } 717 return result; 718 } 719 679 720 MATCH CondExp::implicitConvTo(Type *t) 680 721 { 681 MATCH m1; 682 MATCH m2; 683 684 m1 = e1->implicitConvTo(t); 685 m2 = e2->implicitConvTo(t); 722 MATCH m1 = e1->implicitConvTo(t); 723 MATCH m2 = e2->implicitConvTo(t); 724 //printf("CondExp: m1 %d m2 %d\n", m1, m2); 686 725 687 726 // Pick the worst match … … 689 728 } 690 729 730 MATCH CommaExp::implicitConvTo(Type *t) 731 { 732 return e2->implicitConvTo(t); 733 } 734 735 MATCH CastExp::implicitConvTo(Type *t) 736 { 737 #if 0 738 printf("CastExp::implicitConvTo(this=%s, type=%s, t=%s)\n", 739 toChars(), type->toChars(), t->toChars()); 740 #endif 741 MATCH result; 742 743 result = type->implicitConvTo(t); 744 745 if (result == MATCHnomatch) 746 { 747 if (t->isintegral() && 748 e1->type->isintegral() && 749 e1->implicitConvTo(t) != MATCHnomatch) 750 result = MATCHconvert; 751 else 752 result = Expression::implicitConvTo(t); 753 } 754 return result; 755 } 691 756 692 757 /* ==================== castTo ====================== */ … … 1259 1324 if (f) 1260 1325 { 1261 if (tb->ty == Tdelegate && f->needThis() && hasThis(sc))1326 if (tb->ty == Tdelegate) 1262 1327 { 1263 e = new DelegateExp(loc, new ThisExp(loc), f); 1264 e = e->semantic(sc); 1265 } 1266 else if (tb->ty == Tdelegate && f->isNested()) 1267 { 1268 e = new DelegateExp(loc, new IntegerExp(0), f); 1269 e = e->semantic(sc); 1328 if (f->needThis() && hasThis(sc)) 1329 { 1330 e = new DelegateExp(loc, new ThisExp(loc), f); 1331 e = e->semantic(sc); 1332 } 1333 else if (f->isNested()) 1334 { 1335 e = new DelegateExp(loc, new IntegerExp(0), f); 1336 e = e->semantic(sc); 1337 } 1338 else if (f->needThis()) 1339 { error("no 'this' to create delegate for %s", f->toChars()); 1340 e = new ErrorExp(); 1341 } 1342 else 1343 { error("cannot cast from function pointer to delegate"); 1344 e = new ErrorExp(); 1345 } 1270 1346 } 1271 1347 else … … 1274 1350 e->type = t; 1275 1351 } 1352 #if DMDV2 1276 1353 f->tookAddressOf++; 1354 #endif 1277 1355 return e; 1278 1356 } … … 1354 1432 } 1355 1433 1434 Expression *CommaExp::castTo(Scope *sc, Type *t) 1435 { 1436 Expression *e2c = e2->castTo(sc, t); 1437 Expression *e; 1438 1439 if (e2c != e2) 1440 { 1441 e = new CommaExp(loc, e1, e2c); 1442 e->type = e2c->type; 1443 } 1444 else 1445 { e = this; 1446 e->type = e2->type; 1447 } 1448 return e; 1449 } 1450 1356 1451 /* ==================== ====================== */ 1357 1452 … … 1778 1873 return 0; 1779 1874 } 1875 1876 /******************************************************************/ 1877 1878 /* Determine the integral ranges of an expression. 1879 * This is used to determine if implicit narrowing conversions will 1880 * be allowed. 1881 */ 1882 1883 uinteger_t getMask(uinteger_t v) 1884 { 1885 uinteger_t u = 0; 1886 if (v >= 0x80) 1887 u = 0xFF; 1888 while (u < v) 1889 u = (u << 1) | 1; 1890 return u; 1891 } 1892 1893 IntRange Expression::getIntRange() 1894 { 1895 IntRange ir; 1896 ir.imin = 0; 1897 ir.imax = type->sizemask(); 1898 return ir; 1899 } 1900 1901 IntRange IntegerExp::getIntRange() 1902 { 1903 IntRange ir; 1904 ir.imin = value & type->sizemask(); 1905 ir.imax = ir.imin; 1906 return ir; 1907 } 1908 1909 IntRange CastExp::getIntRange() 1910 { 1911 IntRange ir; 1912 ir = e1->getIntRange(); 1913 // Do sign extension 1914 switch (e1->type->toBasetype()->ty) 1915 { 1916 case Tint8: 1917 if (ir.imax & 0x80) 1918 ir.imax |= 0xFFFFFFFFFFFFFF00ULL; 1919 break; 1920 case Tint16: 1921 if (ir.imax & 0x8000) 1922 ir.imax |= 0xFFFFFFFFFFFF0000ULL; 1923 break; 1924 case Tint32: 1925 if (ir.imax & 0x80000000) 1926 ir.imax |= 0xFFFFFFFF00000000ULL; 1927 break; 1928 } 1929 ir.imin &= type->sizemask(); 1930 ir.imax &= type->sizemask(); 1931 //printf("CastExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 1932 return ir; 1933 } 1934 1935 IntRange DivExp::getIntRange() 1936 { 1937 if (!e1->type->isunsigned() && !e2->type->isunsigned()) 1938 return Expression::getIntRange(); 1939 1940 IntRange ir; 1941 IntRange ir1 = e1->getIntRange(); 1942 IntRange ir2 = e2->getIntRange(); 1943 1944 ir.imin = ir1.imin / ir2.imax; 1945 ir.imax = ir1.imax / ir2.imin; 1946 1947 ir.imin &= type->sizemask(); 1948 ir.imax &= type->sizemask(); 1949 1950 //printf("DivExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 1951 //e1->dump(0); 1952 1953 return ir; 1954 } 1955 1956 IntRange AndExp::getIntRange() 1957 { 1958 IntRange ir; 1959 IntRange ir1 = e1->getIntRange(); 1960 IntRange ir2 = e2->getIntRange(); 1961 1962 ir.imin = ir1.imin; 1963 if (ir2.imin < ir.imin) 1964 ir.imin = ir2.imin; 1965 1966 ir.imax = ir1.imax; 1967 if (ir2.imax > ir.imax) 1968 ir.imax = ir2.imax; 1969 1970 uinteger_t u; 1971 1972 u = getMask(ir1.imax); 1973 ir.imin &= u; 1974 ir.imax &= u; 1975 1976 u = getMask(ir2.imax); 1977 ir.imin &= u; 1978 ir.imax &= u; 1979 1980 ir.imin &= type->sizemask(); 1981 ir.imax &= type->sizemask(); 1982 1983 //printf("AndExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 1984 //e1->dump(0); 1985 1986 return ir; 1987 } 1988 1989 IntRange OrExp::getIntRange() 1990 { 1991 IntRange ir; 1992 IntRange ir1 = e1->getIntRange(); 1993 IntRange ir2 = e2->getIntRange(); 1994 1995 ir.imin = ir1.imin; 1996 if (ir2.imin < ir.imin) 1997 ir.imin = ir2.imin; 1998 1999 ir.imax = ir1.imax; 2000 if (ir2.imax > ir.imax) 2001 ir.imax = ir2.imax; 2002 2003 ir.imin &= type->sizemask(); 2004 ir.imax &= type->sizemask(); 2005 2006 //printf("OrExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 2007 //e1->dump(0); 2008 2009 return ir; 2010 } 2011 2012 IntRange XorExp::getIntRange() 2013 { 2014 IntRange ir; 2015 IntRange ir1 = e1->getIntRange(); 2016 IntRange ir2 = e2->getIntRange(); 2017 2018 ir.imin = ir1.imin; 2019 if (ir2.imin < ir.imin) 2020 ir.imin = ir2.imin; 2021 2022 ir.imax = ir1.imax; 2023 if (ir2.imax > ir.imax) 2024 ir.imax = ir2.imax; 2025 2026 ir.imin &= type->sizemask(); 2027 ir.imax &= type->sizemask(); 2028 2029 //printf("XorExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 2030 //e1->dump(0); 2031 2032 return ir; 2033 } 2034 2035 IntRange ShlExp::getIntRange() 2036 { 2037 IntRange ir; 2038 IntRange ir1 = e1->getIntRange(); 2039 IntRange ir2 = e2->getIntRange(); 2040 2041 ir.imin = getMask(ir1.imin) << ir2.imin; 2042 ir.imax = getMask(ir1.imax) << ir2.imax; 2043 2044 ir.imin &= type->sizemask(); 2045 ir.imax &= type->sizemask(); 2046 2047 //printf("ShlExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 2048 //e1->dump(0); 2049 2050 return ir; 2051 } 2052 2053 IntRange ShrExp::getIntRange() 2054 { 2055 if (!e1->type->isunsigned()) 2056 return Expression::getIntRange(); 2057 2058 IntRange ir; 2059 IntRange ir1 = e1->getIntRange(); 2060 IntRange ir2 = e2->getIntRange(); 2061 2062 ir.imin = ir1.imin >> ir2.imax; 2063 ir.imax = ir1.imax >> ir2.imin; 2064 2065 ir.imin &= type->sizemask(); 2066 ir.imax &= type->sizemask(); 2067 2068 //printf("ShrExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 2069 //e1->dump(0); 2070 2071 return ir; 2072 } 2073 2074 IntRange UshrExp::getIntRange() 2075 { 2076 IntRange ir; 2077 IntRange ir1 = e1->getIntRange(); 2078 IntRange ir2 = e2->getIntRange(); 2079 2080 ir.imin = ir1.imin >> ir2.imax; 2081 ir.imax = ir1.imax >> ir2.imin; 2082 2083 ir.imin &= type->sizemask(); 2084 ir.imax &= type->sizemask(); 2085 2086 //printf("UshrExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); 2087 //e1->dump(0); 2088 2089 return ir; 2090 } 2091 2092 IntRange CommaExp::getIntRange() 2093 { 2094 return e2->getIntRange(); 2095 } 2096 2097 dmd2/class.c
r1452 r1526 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-200 8by Digital Mars3 // Copyright (c) 1999-2009 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright … … 234 234 } 235 235 236 if (!sc ope)237 { 238 if (!parent && sc->parent && !sc->parent->isModule())239 parent = sc->parent;240 241 type = type->semantic(loc, sc);242 handle = handle->semantic(loc, sc);243 } 236 if (!sc) 237 sc = scope; 238 if (!parent && sc->parent && !sc->parent->isModule()) 239 parent = sc->parent; 240 241 type = type->semantic(loc, sc); 242 handle = type; 243 244 244 if (!members) // if forward reference 245 245 { //printf("\tclass '%s' is forward referenced\n", toChars()); … … 276 276 for (i = 0; i < baseclasses.dim; ) 277 277 { BaseClass *b = (BaseClass *)baseclasses.data[i]; 278 //printf("test1 %s %s\n", toChars(), b->type->toChars()); 278 279 b->type = b->type->semantic(loc, sc); 280 //printf("test2\n"); 279 281 Type *tb = b->type->toBasetype(); 280 282 … … 335 337 } 336 338 } 339 if (!tc->sym->symtab || tc->sym->sizeok == 0) 340 { // Try to resolve forward reference 341 if (sc->mustsemantic && tc->sym->scope) 342 tc->sym->semantic(NULL); 343 } 337 344 if (!tc->sym->symtab || tc->sym->scope || tc->sym->sizeok == 0) 338 345 { 346 //printf("%s: forward reference of base class %s\n", toChars(), tc->sym->toChars()); 339 347 //error("forward reference of base class %s", baseClass->toChars()); 340 348 // Forward reference of base class, try again later … … 794 802 //printf("%s.ClassDeclaration::search('%s')\n", toChars(), ident->toChars()); 795 803 if (scope) 796 semantic(scope); 804 { Scope *sc = scope; 805 sc->mustsemantic++; 806 semantic(sc); 807 sc->mustsemantic--; 808 } 797 809 798 810 if (!members || !symtab || scope) 799 { error("is forward referenced when looking for '%s'", ident->toChars()); 811 { 812 error("is forward referenced when looking for '%s'", ident->toChars()); 800 813 //*(char*)0=0; 801 814 return NULL; … … 1038 1051 if (inuse) 1039 1052 return; 1040 if (!scope) 1041 { type = type->semantic(loc, sc); 1042 handle = handle->semantic(loc, sc); 1043 } 1053 1054 if (!sc) 1055 sc = scope; 1056 if (!parent && sc->parent && !sc->parent->isModule()) 1057 parent = sc->parent; 1058 1059 type = type->semantic(loc, sc); 1060 handle = type; 1061 1044 1062 if (!members) // if forward reference 1045 1063 { //printf("\tinterface '%s' is forward referenced\n", toChars()); dmd2/cond.c
r1452 r1526 144 144 "none", 145 145 146 // LDC 146 #if IN_LLVM 147 147 "LLVM", "LDC", "LLVM64", 148 148 "PPC", "PPC64", 149 149 "darwin","solaris","freebsd" 150 #endif 150 151 }; 151 152 dmd2/constfold.c
r1452 r1526 854 854 int cmp; 855 855 856 if (e1->op == TOKnull && e2->op == TOKnull) 857 { 858 cmp = 1; 856 if (e1->op == TOKnull) 857 { 858 cmp = (e2->op == TOKnull); 859 } 860 else if (e2->op == TOKnull) 861 { 862 cmp = 0; 859 863 } 860 864 else if (e1->op == TOKsymoff && e2->op == TOKsymoff) dmd2/declaration.c
r1487 r1526 464 464 goto L2; // it's a symbolic alias 465 465 466 #if DMDV2 466 467 if (storage_class & STCref) 467 468 { // For 'ref' to be attached to function types, and picked … … 473 474 } 474 475 else 476 #endif 475 477 type->resolve(loc, sc, &e, &t, &s); 476 478 if (s) … … 489 491 } 490 492 else if (t) 493 { 491 494 type = t; 495 } 492 496 if (overnext) 493 497 ScopeDsymbol::multiplyDefined(0, this, overnext); … … 512 516 { 513 517 FuncAliasDeclaration *fa = new FuncAliasDeclaration(f); 518 #if IN_LLVM 514 519 fa->importprot = importprot; 520 #endif 515 521 if (!fa->overloadInsert(overnext)) 516 522 ScopeDsymbol::multiplyDefined(0, f, overnext); … … 528 534 } 529 535 } 536 //printf("setting aliassym %p to %p\n", this, s); 530 537 aliassym = s; 531 538 this->inSemantic = 0; … … 625 632 offset = 0; 626 633 noauto = 0; 634 #if DMDV1 635 nestedref = 0; 636 #endif 627 637 ctorinit = 0; 628 638 aliassym = NULL; … … 630 640 canassign = 0; 631 641 value = NULL; 632 scope = NULL;633 642 #if IN_LLVM 634 643 aggrIndex = 0; … … 731 740 //printf("storage_class = x%x\n", storage_class); 732 741 742 #if DMDV2 733 743 if (storage_class & STCgshared && global.params.safe && !sc->module->safe) 734 744 { 735 745 error("__gshared not allowed in safe mode; use shared"); 736 746 } 747 #endif 737 748 738 749 Dsymbol *parent = toParent(); … … 852 863 aad = parent->isAggregateDeclaration(); 853 864 if (aad) 854 { assert(!(storage_class & (STCextern | STCstatic | STCtls | STCgshared))); 865 { 866 #if DMDV2 867 assert(!(storage_class & (STCextern | STCstatic | STCtls | STCgshared))); 855 868 856 869 if (storage_class & (STCconst | STCimmutable) && init) … … 860 873 } 861 874 else 875 #endif 862 876 aad->addField(sc, this); 863 877 } … … 892 906 } 893 907 908 #if DMDV2 894 909 if ((storage_class & (STCref | STCparameter | STCforeach)) == STCref && 895 910 ident != Id::This) … … 897 912 error("only parameters or foreach declarations can be ref"); 898 913 } 914 #endif 899 915 900 916 if (type->isauto() && !noauto) … … 941 957 e1 = new VarExp(loc, this); 942 958 e = new AssignExp(loc, e1, e); 959 #if DMDV2 943 960 e->op = TOKconstruct; 961 #endif 944 962 e->type = e1->type; // don't type check this, it would fail 945 963 init = new ExpInitializer(loc, e); … … 962 980 init = getExpInitializer(); 963 981 } 982 #if DMDV2 964 983 // Default initializer is always a blit 965 984 op = TOKblit; 985 #endif 966 986 } 967 987 … … 1041 1061 { 1042 1062 ei->exp = ei->exp->semantic(sc); 1043 1063 #if DMDV2 1044 1064 /* Look to see if initializer is a call to the constructor 1045 1065 */ … … 1079 1099 } 1080 1100 } 1081 1101 #endif 1082 1102 if (!ei->exp->implicitConvTo(type)) 1083 1103 { Type *ti = ei->exp->type->toBasetype(); … … 1133 1153 if (global.gag == 0) 1134 1154 global.errors = errors; // act as if nothing happened 1135 1155 #if DMDV2 1136 1156 /* Save scope for later use, to try again 1137 1157 */ 1138 1158 scope = new Scope(*sc); 1139 1159 scope->setNoFree(); 1160 #endif 1140 1161 } 1141 1162 else if (ei) … … 1151 1172 ei->exp = e; // no errors, keep result 1152 1173 } 1174 #if DMDV2 1153 1175 else 1154 1176 { … … 1158 1180 scope->setNoFree(); 1159 1181 } 1182 #endif 1160 1183 } 1161 1184 else … … 1221 1244 if (init) 1222 1245 { buf->writestring(" = "); 1246 #if DMDV2 1223 1247 ExpInitializer *ie = init->isExpInitializer(); 1224 1248 if (ie && (ie->exp->op == TOKconstruct || ie->exp->op == TOKblit)) 1225 1249 ((AssignExp *)ie->exp)->e2->toCBuffer(buf, hgs); 1226 1250 else 1251 #endif 1227 1252 init->toCBuffer(buf, hgs); 1228 1253 } … … 1589 1614 { 1590 1615 assert(linkage == LINKc); 1591 // LDC 1616 #if IN_LLVM 1592 1617 if (!global.params.useAvailableExternally) 1593 1618 availableExternally = false; 1619 #endif 1594 1620 } 1595 1621 dmd2/declaration.h
r1487 r1526 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-200 8by Digital Mars3 // Copyright (c) 1999-2009 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright … … 270 270 Expression *value; // when interpreting, this is the value 271 271 // (NULL if value not determinable) 272 Scope *scope; // !=NULL means context to use273 272 274 273 VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init); … … 669 668 // this one is overriding 670 669 int inferRetType; // !=0 if return type is to be inferred 671 Scope *scope; // !=NULL means context to use672 670 673 671 // Things that should really go into Scope dmd2/dsymbol.c
r1452 r1526 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-200 8by Digital Mars3 // Copyright (c) 1999-2009 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright … … 49 49 this->loc = 0; 50 50 this->comment = NULL; 51 this->scope = NULL; 51 52 52 53 #if IN_LLVM … … 68 69 this->loc = 0; 69 70 this->comment = NULL; 71 this->scope = NULL; 70 72 71 73 #if IN_LLVM … … 194 196 break; 195 197 q--; 198 #if TARGET_NET 199 if (AggregateDeclaration* ad = p->isAggregateDeclaration()) 200 { 201 if (ad->isNested() && p->parent && p->parent->isAggregateDeclaration()) 202 { 203 *q = '/'; 204 continue; 205 } 206 } 207 #endif 196 208 *q = '.'; 197 209 } … … 270 282 } 271 283 284 /************************************* 285 * Set scope for future semantic analysis so we can 286 * deal better with forward references. 287 */ 288 289 void Dsymbol::setScope(Scope *sc) 290 { 291 //printf("Dsymbol::setScope() %p %s\n", this, toChars()); 292 if (!sc->nofree) 293 sc->setNoFree(); // may need it even after semantic() finishes 294 scope = sc; 295 } 296 297 /************************************* 298 * Does semantic analysis on the public face of declarations. 299 */ 300 272 301 void Dsymbol::semantic(Scope *sc) 273 302 { … … 275 304 } 276 305 306 /************************************* 307 * Does semantic analysis on initializers and members of aggregates. 308 */ 309 277 310 void Dsymbol::semantic2(Scope *sc) 278 311 { … … 280 313 } 281 314 315 /************************************* 316 * Does semantic analysis on function bodies. 317 */ 318 282 319 void Dsymbol::semantic3(Scope *sc) 283 320 { … … 285 322 } 286 323 324 /************************************* 325 * Look for function inlining possibilities. 326 */ 327 287 328 void Dsymbol::inlineScan() 288 329 { 289 // Most Dsymbols have no further semantic analysis needed330 // Most Dsymbols aren't functions 290 331 } 291 332 … … 345 386 } 346 387 ti->tempdecl = td; 347 if (!ti->semantic done)388 if (!ti->semanticRun) 348 389 ti->semantic(sc); 349 390 sm = ti->toAlias(); dmd2/dsymbol.h
r1452 r1526 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-200 8by Digital Mars3 // Copyright (c) 1999-2009 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright … … 75 75 struct HdrGenState; 76 76 struct OverloadSet; 77 #if TARGET_NET 78 struct PragmaScope; 79 #endif 77 80 #if IN_LLVM 78 81 struct TypeInfoDeclaration; 79 82 struct ClassInfoDeclaration; 80 #endif81 82 #if IN_DMD83 struct Symbol;84 83 #endif 85 84 … … 127 126 unsigned char *comment; // documentation comment for this Dsymbol 128 127 Loc loc; // where defined 128 Scope *scope; // !=NULL means context to use for semantic() 129 129 130 130 Dsymbol(); … … 152 152 virtual Dsymbol *toAlias(); // resolve real symbol 153 153 virtual int addMember(Scope *sc, ScopeDsymbol *s, int memnum); 154 virtual void setScope(Scope *sc); 154 155 virtual void semantic(Scope *sc); 155 156 virtual void semantic2(Scope *sc); … … 246 247 virtual TypeInfoDeclaration* isTypeInfoDeclaration() { return NULL; } 247 248 virtual ClassInfoDeclaration* isClassInfoDeclaration() { return NULL; } 248 249 #if TARGET_NET 250 virtual PragmaScope* isPragmaScope() { return NULL; } 251 #endif 249 252 #if IN_LLVM 250 253 /// Codegen traversal dmd2/enum.c
r1452 r1526 34 34 sinit = NULL; 35 35 #endif 36 scope = NULL;37 36 isdeprecated = 0; 38 37 } dmd2/enum.h
r1452 r1526 41 41 Expression *minval; 42 42 Expression *defaultval; // default initializer 43 44 Scope *scope; // !=NULL means context to use45 43 #endif 46 44 int isdeprecated; dmd2/expression.c
r1523 r1526 380 380 } 381 381 382 } 383 else if (e->op == TOKdottd) 384 { 385 e = new CallExp(e->loc, e); 386 e = e->semantic(sc); 382 387 } 383 388 return e; … … 1003 1008 halt(); 1004 1009 #endif 1005 type = Type::t int32;1010 type = Type::terror; 1006 1011 } 1007 1012 } … … 1065 1070 { 1066 1071 error("expression %s is not a valid template value argument", toChars()); 1072 #ifdef DEBUG 1073 dump(0); 1074 #endif 1067 1075 } 1068 1076 … … 1117 1125 if (!type->isscalar()) 1118 1126 error("'%s' is not a scalar, it is a %s", toChars(), type->toChars()); 1127 rvalue(); 1119 1128 } 1120 1129 … … 1131 1140 return new ErrorExp(); 1132 1141 } 1142 rvalue(); 1133 1143 return this; 1134 1144 } … … 1140 1150 return new ErrorExp(); 1141 1151 } 1152 rvalue(); 1142 1153 return this; 1143 1154 } … … 1997 2008 if (withsym) 1998 2009 { 2010 #if DMDV2 2011 /* Disallow shadowing 2012 */ 2013 // First find the scope of the with 2014 Scope *scwith = sc; 2015 while (scwith->scopesym != scopesym) 2016 { scwith = scwith->enclosing; 2017 assert(scwith); 2018 } 2019 // Look at enclosing scopes for symbols with the same name, 2020 // in the same function 2021 for (Scope *scx = scwith; scx && scx->func == scwith->func; scx = scx->enclosing) 2022 { Dsymbol *s2; 2023 2024 if (scx->scopesym && scx->scopesym->symtab && 2025 (s2 = scx->scopesym->symtab->lookup(s->ident)) != NULL && 2026 s != s2) 2027 { 2028 error("with symbol %s is shadowing local symbol %s", s->toPrettyChars(), s2->toPrettyChars()); 2029 } 2030 } 2031 #endif 1999 2032 s = s->toAlias(); 2000 2033 … … 2161 2194 { type = v->type; 2162 2195 if (!v->type) 2163 { error("forward reference of %s ", v->toChars());2196 { error("forward reference of %s %s", v->kind(), v->toChars()); 2164 2197 type = Type::terror; 2165 2198 } … … 2179 2212 if (f) 2180 2213 { //printf("'%s' is a function\n", f->toChars()); 2214 2215 if (!f->type->deco) 2216 { 2217 error("forward reference to %s", toChars()); 2218 } 2181 2219 return new VarExp(loc, f, hasOverloads); 2182 2220 } … … 2238 2276 TemplateInstance *ti = s->isTemplateInstance(); 2239 2277 if (ti && !global.errors) 2240 { if (!ti->semantic done)2278 { if (!ti->semanticRun) 2241 2279 ti->semantic(sc); 2242 2280 s = ti->inst->toAlias(); … … 2927 2965 { e = (Expression *)elements->data[i]; 2928 2966 e = e->semantic(sc); 2967 assert(e->type); 2929 2968 elements->data[i] = (void *)e; 2930 2969 } … … 3406 3445 } 3407 3446 3447 void TypeExp::rvalue() 3448 { 3449 error("type %s has no value", toChars()); 3450 } 3451 3408 3452 void TypeExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 3409 3453 { … … 3441 3485 if (ti && !global.errors) 3442 3486 { Dsymbol *s; 3443 if (!ti->semantic done)3487 if (!ti->semanticRun) 3444 3488 ti->semantic(sc); 3445 3489 s = ti->inst->toAlias(); … … 3656 3700 #endif 3657 3701 } 3658 else if (fdn) // Possible problems here, no obvious solution when merging 3702 #if 1 3703 else if (thisexp) 3704 error("e.new is only for allocating nested classes"); 3705 else if (fdn) 3706 { 3707 // make sure the parent context fdn of cd is reachable from sc 3708 for (Dsymbol *sp = sc->parent; 1; sp = sp->parent) 3709 { 3710 if (fdn == sp) 3711 break; 3712 FuncDeclaration *fsp = sp ? sp->isFuncDeclaration() : NULL; 3713 if (!sp || (fsp && fsp->isStatic())) 3714 { 3715 error("outer function context of %s is needed to 'new' nested class %s", fdn->toPrettyChars(), cd->toPrettyChars()); 3716 break; 3717 } 3718 } 3719 } 3720 #else 3721 else if (fdn) 3659 3722 { /* The nested class cd is nested inside a function, 3660 3723 * we'll let getEthis() look for errors. … … 3665 3728 error("e.new is only for allocating nested classes"); 3666 3729 } 3730 #endif 3667 3731 else 3668 3732 assert(0); … … 4029 4093 #endif 4030 4094 } 4095 4031 4096 /* Fix for 1161 doesn't work because it causes protection 4032 4097 * problems when instantiating imported templates passing private … … 4110 4175 } 4111 4176 #endif 4177 4112 4178 return this; 4113 4179 } … … 4296 4362 } 4297 4363 type = new TypeTuple(exps); 4364 type = type->semantic(loc, sc); 4298 4365 //printf("-TupleExp::semantic(%s)\n", toChars()); 4299 4366 return this; … … 6160 6227 { ScopeExp *se = (ScopeExp *)e1; 6161 6228 TemplateInstance *ti = se->sds->isTemplateInstance(); 6162 if (ti && !ti->semantic done)6229 if (ti && !ti->semanticRun) 6163 6230 { 6164 6231 /* Attempt to instantiate ti. If that works, go with it. … … 6188 6255 { DotTemplateInstanceExp *se = (DotTemplateInstanceExp *)e1; 6189 6256 TemplateInstance *ti = se->ti; 6190 if (!ti->semantic done)6257 if (!ti->semanticRun) 6191 6258 { 6192 6259 /* Attempt to instantiate ti. If that works, go with it. … … 6796 6863 : UnaExp(loc, TOKaddress, sizeof(AddrExp), e) 6797 6864 { 6865 #if IN_LLVM 6798 6866 m = NULL; 6867 #endif 6799 6868 } 6800 6869 … … 6806 6875 if (!type) 6807 6876 { 6877 #if IN_LLVM 6808 6878 m = sc->module; 6879 #endif 6809 6880 UnaExp::semantic(sc); 6810 6881 e1 = e1->toLvalue(sc, NULL); … … 6812 6883 { 6813 6884 error("cannot take address of %s", e1->toChars()); 6814 type = Type::tint32; 6815 return this; 6816 } 6885 return new ErrorExp(); 6886 } 6887 if (!e1->type->deco) 6888 { 6889 /* No deco means semantic() was not run on the type. 6890 * We have to run semantic() on the symbol to get the right type: 6891 * auto x = &bar; 6892 * pure: int bar() { return 1;} 6893 * otherwise the 'pure' is missing from the type assigned to x. 6894 */ 6895 6896 error("forward reference to %s", e1->toChars()); 6897 return new ErrorExp(); 6898 } 6899 6900 //printf("test3 deco = %p\n", e1->type->deco); 6817 6901 type = e1->type->pointerTo(); 6818 6902 … … 6879 6963 : UnaExp(loc, TOKstar, sizeof(PtrExp), e) 6880 6964 { 6881 if (e->type)6882 type = ((TypePointer *)e->type)->next;6965 // if (e->type) 6966 // type = ((TypePointer *)e->type)->next; 6883 6967 } 6884 6968 … … 6890 6974 6891 6975 Expression *PtrExp::semantic(Scope *sc) 6892 { Type *tb; 6893 6976 { 6894 6977 #if LOGSEMANTIC 6895 6978 printf("PtrExp::semantic('%s')\n", toChars()); … … 6904 6987 if (e) 6905 6988 return e; 6906 tb = e1->type->toBasetype();6989 Type *tb = e1->type->toBasetype(); 6907 6990 switch (tb->ty) 6908 6991 { … … 6919 7002 default: 6920 7003 error("can only * a pointer, not a '%s'", e1->type->toChars()); 6921 type = Type::tint32; 6922 break; 7004 return new ErrorExp(); 6923 7005 } 6924 7006 rvalue(); … … 9745 9827 #endif 9746 9828 else 9829 { e1->rvalue(); 9830 e2->rvalue(); 9747 9831 e = this; 9748 //printf("CmpExp: %s\n", e->toChars()); 9832 } 9833 //printf("CmpExp: %s, type = %s\n", e->toChars(), e->type->toChars()); 9749 9834 return e; 9750 9835 } dmd2/expression.h
r1452 r1526 86 86 int arrayExpressionCanThrow(Expressions *exps); 87 87 88 struct IntRange 89 { uinteger_t imin; 90 uinteger_t imax; 91 }; 92 88 93 struct Expression : Object 89 94 { … … 123 128 virtual Expression *implicitCastTo(Scope *sc, Type *t); 124 129 virtual MATCH implicitConvTo(Type *t); 130 virtual IntRange getIntRange(); 125 131 virtual Expression *castTo(Scope *sc, Type *t); 126 132 virtual void checkEscape(); … … 192 198 char *toChars(); 193 199 void dump(int indent); 200 IntRange getIntRange(); 194 201 dinteger_t toInteger(); 195 202 real_t toReal(); … … 559 566 Expression *syntaxCopy(); 560 567 Expression *semantic(Scope *sc); 568 void rvalue(); 561 569 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 562 570 Expression *optimize(int result); … … 1231 1239 Expression *syntaxCopy(); 1232 1240 Expression *semantic(Scope *sc); 1241 MATCH implicitConvTo(Type *t); 1242 IntRange getIntRange(); 1233 1243 Expression *optimize(int result); 1234 1244 Expression *interpret(InterState *istate); … … 1335 1345 Expression *semantic(Scope *sc); 1336 1346 void checkEscape(); 1347 IntRange getIntRange(); 1337 1348 int isLvalue(); 1338 1349 Expression *toLvalue(Scope *sc, Expression *e); … … 1340 1351 int isBool(int result); 1341 1352 int checkSideEffect(int flag); 1353 MATCH implicitConvTo(Type *t); 1354 Expression *castTo(Scope *sc, Type *t); 1342 1355 Expression *optimize(int result); 1343 1356 Expression *interpret(InterState *istate); … … 1553 1566 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); 1554 1567 Expression *buildArrayLoop(Arguments *fparams); 1568 IntRange getIntRange(); 1555 1569 1556 1570 // For operator overloading … … 1595 1609 Expression *optimize(int result); 1596 1610 Expression *interpret(InterState *istate); 1611 IntRange getIntRange(); 1597 1612 1598 1613 // For operator overloading … … 1615 1630 Expression *optimize(int result); 1616 1631 Expression *interpret(InterState *istate); 1632 IntRange getIntRange(); 1617 1633 1618 1634 // For operator overloading … … 1635 1651 Expression *optimize(int result); 1636 1652 Expression *interpret(InterState *istate); 1653 IntRange getIntRange(); 1637 1654 1638 1655 // For operator overloading … … 1657 1674 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); 1658 1675 Expression *buildArrayLoop(Arguments *fparams); 1676 IntRange getIntRange(); 1659 1677 1660 1678 // For operator overloading … … 1680 1698 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); 1681 1699 Expression *buildArrayLoop(Arguments *fparams); 1700 MATCH implicitConvTo(Type *t); 1701 IntRange getIntRange(); 1682 1702 1683 1703 // For operator overloading … … 1703 1723 void buildArrayIdent(OutBuffer *buf, Expressions *arguments); 1704 1724 Expression *buildArrayLoop(Arguments *fparams); 1725 MATCH implicitConvTo(Type *t); 1726 IntRange getIntRange(); 1705 1727 1706 1728 // For operator overloading dmd2/func.c
r1487 r1526 1 1 // Compiler implementation of the D programming language 2 // Copyright (c) 1999-200 8by Digital Mars2 // Copyright (c) 1999-2009 by Digital Mars 3 3 // All Rights Reserved 4 4 // written by Walter Bright … … 65 65 cantInterpret = 0; 66 66 semanticRun = 0; 67 #if DMDV1 68 nestedFrameRef = 0; 69 #endif 67 70 fes = NULL; 68 71 introducing = 0; … … 72 75 */ 73 76 inferRetType = (type && type->nextOf() == NULL); 74 scope = NULL;75 77 hasReturnExp = 0; 76 78 nrvo_can = 1; … … 79 81 shidden = NULL; 80 82 #endif 81 83 #if DMDV2 82 84 builtin = BUILTINunknown; 83 85 tookAddressOf = 0; 84 86 #endif 85 87 #if IN_LLVM 86 88 // LDC … … 126 128 assert(!fthrows); // deprecated 127 129 128 // LDC 130 #if IN_LLVM 129 131 f->intrinsicName = intrinsicName; 132 #endif 130 133 131 134 return f; … … 167 170 if (!originalType) 168 171 originalType = type; 169 if (!type->deco && type->nextOf())172 if (!type->deco) 170 173 { 171 174 /* Apply const and invariant storage class … … 305 308 306 309 if (isCtorDeclaration() || 310 #if DMDV2 307 311 isPostBlitDeclaration() || 312 #endif 308 313 isDtorDeclaration() || 309 314 isInvariantDeclaration() || … … 879 884 { Argument *arg = (Argument *)f->parameters->data[i]; 880 885 886 //printf("[%d] arg->type->ty = %d %s\n", i, arg->type->ty, arg->type->toChars()); 881 887 if (arg->type->ty == Ttuple) 882 888 { TypeTuple *t = (TypeTuple *)arg->type; … … 1009 1015 v = new VarDeclaration(loc, type->nextOf(), outId, NULL); 1010 1016 v->noauto = 1; 1017 #if DMDV2 1018 if (f->isref) 1019 { 1020 v->storage_class |= STCref | STCforeach; 1021 } 1022 #endif 1011 1023 sc2->incontract--; 1012 1024 v->semantic(sc2); … … 1109 1121 1110 1122 fbody = fbody->semantic(sc2); 1123 if (!fbody) 1124 fbody = new CompoundStatement(0, new Statements()); 1111 1125 1112 1126 if (inferRetType) … … 1186 1200 else if (!inlineAsm) 1187 1201 { 1188 int blockexit = fbody ? fbody->blockExit() : 0;1202 int blockexit = fbody ? fbody->blockExit() : BEfallthru; 1189 1203 if (f->isnothrow && blockexit & BEthrow) 1190 1204 error("'%s' is nothrow yet may throw", toChars()); … … 1205 1219 { Expression *e; 1206 1220 1207 warning(loc, "no return at end of function"); 1221 //warning(loc, "no return exp; or assert(0); at end of function"); 1222 error("no return exp; or assert(0); at end of function"); 1208 1223 1209 1224 if (global.params.useAssert && … … 2170 2185 2171 2186 void FuncDeclaration::appendState(Statement *s) 2172 { CompoundStatement *cs; 2173 2187 { 2174 2188 if (!fbody) 2175 { Statements *a; 2176 2177 a = new Statements(); 2178 fbody = new CompoundStatement(0, a); 2179 } 2180 cs = fbody->isCompoundStatement(); 2181 cs->statements->push(s); 2189 fbody = s; 2190 else 2191 { 2192 CompoundStatement *cs = fbody->isCompoundStatement(); 2193 if (cs) 2194 { 2195 if (!cs->statements) 2196 fbody = s; 2197 else 2198 cs->statements->push(s); 2199 } 2200 else 2201 fbody = new CompoundStatement(0, fbody, s); 2202 } 2182 2203 } 2183 2204 … … 2636 2657 /********************************* PostBlitDeclaration ****************************/ 2637 2658 2659 #if DMDV2 2638 2660 PostBlitDeclaration::PostBlitDeclaration(Loc loc, Loc endloc) 2639 2661 : FuncDeclaration(loc, endloc, Id::_postblit, STCundefined, NULL) … … 2705 2727 bodyToCBuffer(buf, hgs); 2706 2728 } 2729 #endif 2707 2730 2708 2731 /********************************* DtorDeclaration ****************************/ dmd2/import.c
r1452 r1526 22 22 #include "declaration.h" 23 23 #include "id.h" 24 #include "attrib.h" 24 25 25 26 /********************************* Import ****************************/ … … 101 102 if (s) 102 103 { 104 #if TARGET_NET 105 mod = (Module *)s; 106 #else 103 107 if (s->isModule()) 104 108 mod = (Module *)s; 105 109 else 106 110 error("package and module have the same name"); 111 #endif 107 112 } 108 113 … … 122 127 } 123 128 124 #if IN_LLVM 125 char* escapePath(char* fname, char* buffer, int bufLen) { 126 char* res = buffer; 127 bufLen -= 2; // for \0 and an occasional escape char 128 int dst = 0; 129 for (; dst < bufLen && *fname; ++dst, ++fname) { 130 switch (*fname) { 129 void escapePath(OutBuffer *buf, const char *fname) 130 { 131 while (1) 132 { 133 switch (*fname) 134 { 135 case 0: 136 return; 131 137 case '(': 132 138 case ')': 133 139 case '\\': 134 buffer[dst++] = '\\'; 135 // fall through 136 140 buf->writebyte('\\'); 137 141 default: 138 buffer[dst] = *fname; 139 } 140 } 141 buffer[dst] = '\0'; 142 return buffer; 143 } 144 #endif 142 buf->writebyte(*fname); 143 break; 144 } 145 fname++; 146 } 147 } 145 148 146 149 void Import::semantic(Scope *sc) … … 165 168 //printf("%s imports %s\n", sc->module->toChars(), mod->toChars()); 166 169 sc->module->aimports.push(mod); 167 168 mod->semantic();169 170 170 171 if (!isstatic && !aliasId && !names.dim) … … 178 179 } 179 180 181 mod->semantic(); 182 180 183 if (mod->needmoduleinfo) 181 184 sc->module->needmoduleinfo = 1; … … 194 197 sc = sc->pop(); 195 198 } 196 //printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg); 197 198 199 if (global.params.moduleDeps != NULL) { 200 char fnameBuf[262]; // MAX_PATH+2 201 202 OutBuffer *const ob = global.params.moduleDeps; 203 ob->printf("%s (%s) : ", 204 sc->module->toPrettyChars(), 205 escapePath(sc->module->srcfile->toChars(), fnameBuf, sizeof(fnameBuf) / sizeof(*fnameBuf)) 206 ); 207 208 char* protStr = ""; 209 switch (sc->protection) { 210 case PROTpublic: protStr = "public"; break; 211 case PROTprivate: protStr = "private"; break; 212 case PROTpackage: protStr = "package"; break; 213 default: break; 214 } 215 ob->writestring(protStr); 216 if (isstatic) { 217 ob->writestring(" static"); 218 } 219 ob->writestring(" : "); 220 221 if (this->packages) { 222 for (size_t i = 0; i < this->packages->dim; i++) { 223 Identifier *pid = (Identifier *)this->packages->data[i]; 199 200 if (global.params.moduleDeps != NULL) 201 { 202 /* The grammar of the file is: 203 * ImportDeclaration 204 * ::= BasicImportDeclaration [ " : " ImportBindList ] [ " -> " 205 * ModuleAliasIdentifier ] "\n" 206 * 207 * BasicImportDeclaration 208 * ::= ModuleFullyQualifiedName " (" FilePath ") : " Protection 209 * " [ " static" ] : " ModuleFullyQualifiedName " (" FilePath ")" 210 * 211 * FilePath 212 * - any string with '(', ')' and '\' escaped with the '\' character 213 */ 214 215 OutBuffer *ob = global.params.moduleDeps; 216 217 ob->writestring(sc->module->toPrettyChars()); 218 ob->writestring(" ("); 219 escapePath(ob, sc->module->srcfile->toChars()); 220 ob->writestring(") : "); 221 222 ProtDeclaration::protectionToCBuffer(ob, sc->protection); 223 if (isstatic) 224 StorageClassDeclaration::stcToCBuffer(ob, STCstatic); 225 ob->writestring(": "); 226 227 if (packages) 228 { 229 for (size_t i = 0; i < packages->dim; i++) 230 { 231 Identifier *pid = (Identifier *)packages->data[i]; 224 232 ob->printf("%s.", pid->toChars()); 225 233 } 226 234 } 227 235 228 ob->printf("%s (%s)", 229 this->id->toChars(), 230 mod ? escapePath(mod->srcfile->toChars(), fnameBuf, sizeof(fnameBuf) / sizeof(*fnameBuf)) : "???" 231 ); 232 233 if (aliasId) { 234 ob->printf(" -> %s", aliasId->toChars()); 235 } else { 236 if (names.dim > 0) { 237 ob->writestring(" : "); 238 for (size_t i = 0; i < names.dim; i++) 239 { 240 if (i > 0) { 241 ob->writebyte(','); 242 } 243 244 Identifier *name = (Identifier *)names.data[i]; 245 Identifier *alias = (Identifier *)aliases.data[i]; 246 247 if (!alias) { 248 ob->printf("%s", name->toChars()); 249 alias = name; 250 } else { 251 ob->printf("%s=%s", alias->toChars(), name->toChars()); 252 } 253 } 236 ob->writestring(id->toChars()); 237 ob->writestring(" ("); 238 if (mod) 239 escapePath(ob, mod->srcfile->toChars()); 240 else 241 ob->writestring("???"); 242 ob->writebyte(')'); 243 244 for (size_t i = 0; i < names.dim; i++) 245 { 246 if (i == 0) 247 ob->writebyte(':'); 248 else 249 ob->writebyte(','); 250 251 Identifier *name = (Identifier *)names.data[i]; 252 Identifier *alias = (Identifier *)aliases.data[i]; 253 254 if (!alias) 255 { 256 ob->printf("%s", name->toChars()); 257 alias = name; 254 258 } 255 } 259 else 260 ob->printf("%s=%s", alias->toChars(), name->toChars()); 261 } 262 263 if (aliasId) 264 ob->printf(" -> %s", aliasId->toChars()); 256 265 257 266 ob->writenl(); 258 267 } 268 269 //printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg); 259 270 } 260 271 … … 348 359 } 349 360 } 350 buf->printf("%s", id->toChars()); 351 if (names.dim > 0) { 352 buf->writebyte(':'); 353 for (size_t i = 0; i < names.dim; i++) 354 { 355 if (i > 0) { 356 buf->writebyte(','); 357 } 358 359 Identifier *name = (Identifier *)names.data[i]; 360 Identifier *alias = (Identifier *)aliases.data[i]; 361 362 if (!alias) { 363 buf->printf("%s", name->toChars()); 364 alias = name; 365 } else { 366 buf->printf("%s=%s", alias->toChars(), name->toChars()); 367 } 368 } 369 } 370 buf->writebyte(';'); 361 buf->printf("%s;", id->toChars()); 371 362 buf->writenl(); 372 363 } dmd2/import.h
r758 r1526 35 35 Identifier *aliasId; 36 36 int isstatic; // !=0 if static import 37 #if IN_LLVM 37 38 enum PROT protection; 39 #endif 38 40 39 41 // Pairs of alias=name to bind into current namespace … … 51 53 52 54 const char *kind(); 55 #if IN_LLVM 53 56 enum PROT prot(); 57 #endif 54 58 Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees 55 59 void load(Scope *sc); dmd2/inifile.c
r1452 r1526 15 15 #include <stdlib.h> 16 16 #include <ctype.h> 17 18 #if _WIN32 19 #include <windows.h> 20 #endif 17 21 18 22 #if __APPLE__ … … 92 96 if (!FileName::exists(filename)) 93 97 { 98 #if _WIN32 // This fix by Tim Matthews 99 char resolved_name[MAX_PATH + 1]; 100 if(GetModuleFileName(NULL, resolved_name, MAX_PATH + 1) && FileName::exists(resolved_name)) 101 { 102 filename = (char *)FileName::replaceName(resolved_name, inifile); 103 if(FileName::exists(filename)) 104 goto Ldone; 105 } 106 #endif 94 107 filename = (char *)FileName::replaceName(argv0, inifile); 95 108 if (!FileName::exists(filename)) dmd2/init.c
r1452 r1526 397 397 Expression *e; 398 398 399 //printf("ArrayInitializer::toExpression() \n");399 //printf("ArrayInitializer::toExpression(), dim = %d\n", dim); 400 400 //static int i; if (++i == 2) halt(); 401 402 size_t edim; 403 Type *t = NULL; 404 if (type) 405 { 406 t = type->toBasetype(); 407 switch (t->ty) 408 { 409 case Tsarray: 410 edim = ((TypeSArray *)t)->dim->toInteger(); 411 break; 412 413 case Tpointer: 414 case Tarray: 415 edim = dim; 416 break; 417 418 default: 419 assert(0); 420 } 421 } 422 else 423 edim = value.dim; 424 401 425 elements = new Expressions(); 402 for (size_t i = 0; i < value.dim; i++) 426 elements->setDim(edim); 427 for (size_t i = 0, j = 0; i < value.dim; i++, j++) 403 428 { 404 429 if (index.data[i]) 405 goto Lno; 430 j = ((Expression *)index.data[i])->toInteger(); 431 assert(j < edim); 406 432 Initializer *iz = (Initializer *)value.data[i]; 407 433 if (!iz) … … 409 435 Expression *ex = iz->toExpression(); 410 436 if (!ex) 411 goto Lno; 412 elements->push(ex); 413 } 414 e = new ArrayLiteralExp(loc, elements); 437 { 438 goto Lno; 439 } 440 elements->data[j] = ex; 441 } 442 443 /* Fill in any missing elements with the default initializer 444 */ 445 { 446 Expression *init = NULL; 447 for (size_t i = 0; i < edim; i++) 448 { 449 if (!elements->data[i]) 450 { 451 if (!type) 452 goto Lno; 453 if (!init) 454 init = ((TypeNext *)t)->next->defaultInit(); 455 elements->data[i] = init; 456 } 457 } 458 459 Expression *e = new ArrayLiteralExp(loc, elements); 415 460 e->type = type; 416 461 return e; 462 } 417 463 418 464 Lno: … … 467 513 Type *ArrayInitializer::inferType(Scope *sc) 468 514 { 515 //printf("ArrayInitializer::inferType() %s\n", toChars()); 516 type = Type::terror; 469 517 for (size_t i = 0; i < value.dim; i++) 470 518 { … … 472 520 goto Lno; 473 521 } 474 if (value.dim)475 { 476 Initializer *iz = (Initializer *)value.data[ 0];522 for (size_t i = 0; i < value.dim; i++) 523 { 524 Initializer *iz = (Initializer *)value.data[i]; 477 525 if (iz) 478 526 { Type *t = iz->inferType(sc); 479 t = new TypeSArray(t, new IntegerExp(value.dim)); 480 t = t->semantic(loc, sc); 481 return t; 482 } 483 } 527 if (i == 0) 528 { t = new TypeSArray(t, new IntegerExp(value.dim)); 529 t = t->semantic(loc, sc); 530 type = t; 531 } 532 } 533 } 534 return type; 484 535 485 536 Lno: dmd2/interpret.c
r1452 r1526 2294 2294 AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg; 2295 2295 Expression *e = new ArrayLiteralExp(aae->loc, aae->keys); 2296 Type *elemType = ((TypeAArray *)aae->type)->index; 2297 e->type = new TypeSArray(elemType, new IntegerExp(arguments ? arguments->dim : 0)); 2296 2298 return e; 2297 2299 } … … 2310 2312 AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg; 2311 2313 Expression *e = new ArrayLiteralExp(aae->loc, aae->values); 2314 Type *elemType = ((TypeAArray *)aae->type)->next; 2315 e->type = new TypeSArray(elemType, new IntegerExp(arguments ? arguments->dim : 0)); 2312 2316 //printf("result is %s\n", e->toChars()); 2313 2317 return e; dmd2/lexer.c
r1460 r1526 1279 1279 } 1280 1280 if (ndigits != 2 && !utf_isValidDchar(v)) 1281 error("invalid UTF character \\U%08x", v); 1281 { error("invalid UTF character \\U%08x", v); 1282 v = '?'; // recover with valid UTF character 1283 } 1282 1284 c = v; 1283 1285 } dmd2/mangle.c
r1452 r1526 114 114 break; 115 115 116 // LDC 116 #if IN_LLVM 117 117 case LINKintrinsic: 118 118 #endif 119 119 case LINKc: 120 120 case LINKwindows: dmd2/mars.c
r1452 r1526 99 99 #endif 100 100 ; 101 version = "v2.03 0";101 version = "v2.031"; 102 102 #if IN_LLVM 103 103 ldc_version = LDC_REV; dmd2/mars.h
r1487 r1526 210 210 211 211 const char *xmlname; // filename for XML output 212 213 OutBuffer *moduleDeps; // buffer and filename for emitting module deps214 char *moduleDepsFile;215 212 213 char *moduleDepsFile; // filename for deps output 214 OutBuffer *moduleDeps; // contents to be written to deps file 215 216 216 // Hidden debug switches 217 217 bool debuga; … … 444 444 #define stdmsg stderr 445 445 #else 446 #define stdmsg std out446 #define stdmsg stderr 447 447 #endif 448 448 dmd2/module.c
r1452 r1526 100 100 searchCacheFlags = 0; 101 101 semanticstarted = 0; 102 semantic done= 0;102 semanticRun = 0; 103 103 decldefs = NULL; 104 104 vmoduleinfo = NULL; … … 771 771 symtab = new DsymbolTable(); 772 772 for (i = 0; i < members->dim; i++) 773 { Dsymbol *s; 774 775 s = (Dsymbol *)members->data[i]; 773 { Dsymbol *s = (Dsymbol *)members->data[i]; 776 774 s->addMember(NULL, sc->scopesym, 1); 775 } 776 777 /* Set scope for the symbols so that if we forward reference 778 * a symbol, it can possibly be resolved on the spot. 779 * If this works out well, it can be extended to all modules 780 * before any semantic() on any of them. 781 */ 782 for (i = 0; i < members->dim; i++) 783 { Dsymbol *s = (Dsymbol *)members->data[i]; 784 s->setScope(sc); 777 785 } 778 786 779 787 // Pass 1 semantic routines: do public side of the definition 780 788 for (i = 0; i < members->dim; i++) 781 { Dsymbol *s; 782 783 s = (Dsymbol *)members->data[i]; 789 { Dsymbol *s = (Dsymbol *)members->data[i]; 790 784 791 //printf("\tModule('%s'): '%s'.semantic()\n", toChars(), s->toChars()); 785 792 s->semantic(sc); … … 788 795 789 796 sc = sc->pop(); 790 sc->pop(); 791 semantic done= semanticstarted;797 sc->pop(); // 2 pops because Scope::createGlobal() created 2 798 semanticRun = semanticstarted; 792 799 //printf("-Module::semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); 793 800 } … … 828 835 sc = sc->pop(); 829 836 sc->pop(); 830 semantic done= semanticstarted;837 semanticRun = semanticstarted; 831 838 //printf("-Module::semantic2('%s'): parent = %p\n", toChars(), parent); 832 839 } … … 858 865 sc = sc->pop(); 859 866 sc->pop(); 860 semantic done= semanticstarted;867 semanticRun = semanticstarted; 861 868 } 862 869 … … 883 890 s->inlineScan(); 884 891 } 885 semantic done= semanticstarted;892 semanticRun = semanticstarted; 886 893 } 887 894 … … 1144 1151 { 1145 1152 assert(p->isPackage()); 1153 #if TARGET_NET //dot net needs modules and packages with same name 1154 #else 1146 1155 if (p->isModule()) 1147 1156 { p->error("module and package have the same name"); … … 1149 1158 break; 1150 1159 } 1160 #endif 1151 1161 } 1152 1162 parent = p; dmd2/module.h
r1452 r1526 92 92 93 93 int semanticstarted; // has semantic() been started? 94 int semantic done; // has semantic() been done?94 int semanticRun; // has semantic() been done? 95 95 int root; // != 0 if this is a 'root' module, 96 96 // i.e. a module that will be taken all the dmd2/mtype.c
r1463 r1526 1172 1172 if (sv->ptrvalue) 1173 1173 { t = (Type *) sv->ptrvalue; 1174 #ifdef DEBUG 1175 if (!t->deco) 1176 printf("t = %s\n", t->toChars()); 1177 #endif 1174 1178 assert(t->deco); 1175 1179 //printf("old value, deco = '%s' %p\n", t->deco, t->deco); … … 1325 1329 * to type 'to'. 1326 1330 * Returns: 1327 * 0 can't convert 1328 * 1 can convert using implicit conversions 1329 * 2 this and to are the same type 1331 * MATCHnomatch, MATCHconvert, MATCHconst, MATCHexact 1330 1332 */ 1331 1333 … … 1333 1335 { 1334 1336 //printf("Type::implicitConvTo(this=%p, to=%p)\n", this, to); 1337 //printf("from: %s\n", toChars()); 1338 //printf("to : %s\n", to->toChars()); 1335 1339 if (this == to) 1336 1340 return MATCHexact; … … 1592 1596 } 1593 1597 1598 /**************************************** 1599 * Return the mask that an integral type will 1600 * fit into. 1601 */ 1602 uinteger_t Type::sizemask() 1603 { uinteger_t m; 1604 1605 switch (toBasetype()->ty) 1606 { 1607 case Tbool: m = 1; break; 1608 case Tchar: 1609 case Tint8: 1610 case Tuns8: m = 0xFF; break; 1611 case Twchar: 1612 case Tint16: 1613 case Tuns16: m = 0xFFFFUL; break; 1614 case Tdchar: 1615 case Tint32: 1616 case Tuns32: m = 0xFFFFFFFFUL; break; 1617 case Tint64: 1618 case Tuns64: m = 0xFFFFFFFFFFFFFFFFULL; break; 1619 default: 1620 assert(0); 1621 } 1622 return m; 1623 } 1624 1594 1625 /* ============================= TypeNext =========================== */ 1595 1626 … … 1611 1642 { 1612 1643 Type::checkDeprecated(loc, sc); 1613 next->checkDeprecated(loc, sc); 1644 if (next) // next can be NULL if TypeFunction and auto return type 1645 next->checkDeprecated(loc, sc); 1614 1646 } 1615 1647 … … 1633 1665 } 1634 1666 TypeNext *t = (TypeNext *)Type::makeConst(); 1635 if (ty != Tfunction && ty != Tdelegate && next->deco && 1667 if (ty != Tfunction && ty != Tdelegate && 1668 (next->deco || next->ty == Tfunction) && 1636 1669 !next->isInvariant() && !next->isConst()) 1637 1670 { if (next->isShared()) … … 1652 1685 } 1653 1686 TypeNext *t = (TypeNext *)Type::makeInvariant(); 1654 if (ty != Tfunction && ty != Tdelegate && next->deco && 1687 if (ty != Tfunction && ty != Tdelegate && 1688 (next->deco || next->ty == Tfunction) && 1655 1689 !next->isInvariant()) 1656 1690 { t->next = next->invariantOf(); … … 1667 1701 } 1668 1702 TypeNext *t = (TypeNext *)Type::makeShared(); 1669 if (ty != Tfunction && ty != Tdelegate && next->deco && 1703 if (ty != Tfunction && ty != Tdelegate && 1704 (next->deco || next->ty == Tfunction) && 1670 1705 !next->isInvariant() && !next->isShared()) 1671 1706 { … … 1687 1722 } 1688 1723 TypeNext *t = (TypeNext *)Type::makeSharedConst(); 1689 if (ty != Tfunction && ty != Tdelegate && next->deco && 1724 if (ty != Tfunction && ty != Tdelegate && 1725 (next->deco || next->ty == Tfunction) && 1690 1726 !next->isInvariant() && !next->isSharedConst()) 1691 1727 { … … 2362 2398 return MATCHexact; 2363 2399 2400 #if DMDV2 2364 2401 if (ty == to->ty) 2365 2402 { 2366 2403 return (mod == to->mod) ? MATCHexact : MATCHconst; 2367 2404 } 2405 #endif 2368 2406 2369 2407 if (ty == Tvoid || to->ty == Tvoid) 2370 2408 return MATCHnomatch; 2371 if (1 || global.params.Dversion == 1) 2372 { 2373 if (to->ty == Tbool) 2374 return MATCHnomatch; 2375 } 2376 else 2377 { 2378 if (ty == Tbool || to->ty == Tbool) 2379 return MATCHnomatch; 2380 } 2409 if (to->ty == Tbool) 2410 return MATCHnomatch; 2381 2411 if (!to->isTypeBasic()) 2382 2412 return MATCHnomatch; … … 2389 2419 return MATCHnomatch; 2390 2420 2391 // If converting to integral 2392 if (0 && global.params.Dversion > 1 && tob->flags & TFLAGSintegral) 2421 #if DMDV2 2422 // If converting from integral to integral 2423 if (1 && tob->flags & TFLAGSintegral) 2393 2424 { d_uns64 sz = size(0); 2394 2425 d_uns64 tosz = tob->size(0); 2395 2426 2396 /* Can't convert to smaller size or, if same size, change sign2427 /* Can't convert to smaller size 2397 2428 */ 2398 2429 if (sz > tosz) 2399 2430 return MATCHnomatch; 2400 2431 2432 /* Can't change sign if same size 2433 */ 2401 2434 /*if (sz == tosz && (flags ^ tob->flags) & TFLAGSunsigned) 2402 2435 return MATCHnomatch;*/ 2403 2436 } 2437 #endif 2404 2438 } 2405 2439 else if (flags & TFLAGSfloating) … … 3553 3587 { 3554 3588 //printf("TypePointer::semantic()\n"); 3589 if (deco) 3590 return this; 3555 3591 Type *n = next->semantic(loc, sc); 3556 3592 switch (n->toBasetype()->ty) … … 3562 3598 } 3563 3599 if (n != next) 3600 { 3564 3601 deco = NULL; 3602 } 3565 3603 next = n; 3566 3604 transitive(); … … 3802 3840 3803 3841 if (!arg1->type->equals(arg2->type)) 3804 goto Ldistinct; 3842 { 3843 #if 0 // turn on this for contravariant argument types, see bugzilla 3075 3844 // We can add const, but not subtract it 3845 if (arg2->type->implicitConvTo(arg1->type) < MATCHconst) 3846 #endif 3847 goto Ldistinct; 3848 } 3805 3849 if ((arg1->storageClass & ~STCscope) != (arg2->storageClass & ~STCscope)) 3806 3850 inoutmismatch = 1; … … 4058 4102 buf->writestring(" const"); 4059 4103 if (mod & MODinvariant) 4060 buf->writestring(" i nvariant");4104 buf->writestring(" immutable"); 4061 4105 if (mod & MODshared) 4062 4106 buf->writestring(" shared"); … … 4082 4126 //printf("TypeFunction::semantic() %s, sc->stc = %x\n", toChars(), sc->stc); 4083 4127 4128 /* Copy in order to not mess up original. 4129 * This can produce redundant copies if inferring return type, 4130 * as semantic() will get called again on this. 4131 */ 4084 4132 TypeFunction *tf = (TypeFunction *)mem.malloc(sizeof(TypeFunction)); 4085 4133 memcpy(tf, this, sizeof(TypeFunction)); … … 4102 4150 4103 4151 tf->linkage = sc->linkage; 4104 if (!tf->next) 4105 { 4106 assert(global.errors); 4107 tf->next = tvoid; 4108 } 4109 tf->next = tf->next->semantic(loc,sc); 4110 if (tf->next->toBasetype()->ty == Tsarray) 4111 { error(loc, "functions cannot return static array %s", tf->next->toChars()); 4112 tf->next = Type::terror; 4113 } 4114 if (tf->next->toBasetype()->ty == Tfunction) 4115 { error(loc, "functions cannot return a function"); 4116 tf->next = Type::terror; 4117 } 4118 if (tf->next->toBasetype()->ty == Ttuple) 4119 { error(loc, "functions cannot return a tuple"); 4120 tf->next = Type::terror; 4121 } 4122 if (tf->next->isauto() && !(sc->flags & SCOPEctor)) 4123 error(loc, "functions cannot return scope %s", tf->next->toChars()); 4152 if (tf->next) 4153 { 4154 tf->next = tf->next->semantic(loc,sc); 4155 if (tf->next->toBasetype()->ty == Tsarray) 4156 { error(loc, "functions cannot return static array %s", tf->next->toChars()); 4157 tf->next = Type::terror; 4158 } 4159 if (tf->next->toBasetype()->ty == Tfunction) 4160 { error(loc, "functions cannot return a function"); 4161 tf->next = Type::terror; 4162 } 4163 if (tf->next->toBasetype()->ty == Ttuple) 4164 { error(loc, "functions cannot return a tuple"); 4165 tf->next = Type::terror; 4166 } 4167 if (tf->next->isauto() && !(sc->flags & SCOPEctor)) 4168 error(loc, "functions cannot return scope %s", tf->next->toChars()); 4169 } 4124 4170 4125 4171 if (tf->parameters) … … 4169 4215 } 4170 4216 } 4171 tf->deco = tf->merge()->deco; 4217 if (tf->next) 4218 tf->deco = tf->merge()->deco; 4172 4219 4173 4220 if (tf->inuse) … … 4771 4818 4772 4819 void TypeIdentifier::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) 4773 { Dsymbol *s;4820 { 4774 4821 Dsymbol *scopesym; 4775 4822 4776 4823 //printf("TypeIdentifier::resolve(sc = %p, idents = '%s')\n", sc, toChars()); 4777 s = sc->search(loc, ident, &scopesym);4824 Dsymbol *s = sc->search(loc, ident, &scopesym); 4778 4825 resolveHelper(loc, sc, s, scopesym, pe, pt, ps); 4779 4826 if (*pt) … … 5242 5289 { 5243 5290 //printf("TypeEnum::semantic() %s\n", toChars()); 5244 sym->semantic(sc);5291 //sym->semantic(sc); 5245 5292 return merge(); 5246 5293 } … … 5896 5943 TemplateInstance *ti = s->isTemplateInstance(); 5897 5944 if (ti) 5898 { if (!ti->semantic done)5945 { if (!ti->semanticRun) 5899 5946 ti->semantic(sc); 5900 5947 s = ti->inst->toAlias(); … … 6135 6182 { 6136 6183 //printf("TypeClass::semantic(%s)\n", sym->toChars()); 6137 if (sym->scope) 6138 sym->semantic(sym->scope); 6184 if (deco) 6185 return this; 6186 //printf("\t%s\n", merge()->deco); 6139 6187 return merge(); 6140 6188 } … … 6427 6475 TemplateInstance *ti = s->isTemplateInstance(); 6428 6476 if (ti) 6429 { if (!ti->semantic done)6477 { if (!ti->semanticRun) 6430 6478 ti->semantic(sc); 6431 6479 s = ti->inst->toAlias(); dmd2/mtype.h
r1452 r1526 307 307 //Type *next; 308 308 virtual Type *nextOf(); 309 uinteger_t sizemask(); 310 309 311 310 312 static void error(Loc loc, const char *format, ...) IS_PRINTF(2); … … 715 717 716 718 TypeEnum(EnumDeclaration *sym); 719 Type *syntaxCopy(); 717 720 d_uns64 size(Loc loc); 718 721 unsigned alignsize(); 719 722 char *toChars(); 720 Type *syntaxCopy();721 723 Type *semantic(Loc loc, Scope *sc); 722 724 Dsymbol *toDsymbol(Scope *sc); dmd2/opover.c
r1452 r1526 199 199 } 200 200 201 #if DMDV2 201 202 // Didn't find it. Forward to aliasthis 202 203 if (ad->aliasthis) … … 211 212 return e; 212 213 } 214 #endif 213 215 } 214 216 return NULL; … … 442 444 } 443 445 446 #if DMDV2 444 447 // Try alias this on first operand 445 448 if (ad1 && ad1->aliasthis) … … 467 470 return e; 468 471 } 469 472 #endif 470 473 return NULL; 471 474 } dmd2/optimize.c
r1452 r1526 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-200 7by Digital Mars3 // Copyright (c) 1999-2009 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright … … 806 806 Expression *e1 = this->e1->optimize(WANTvalue | (result & WANTinterpret)); 807 807 e1 = fromConstInitializer(result, e1); 808 if (this->e1->op == TOKvar) 809 { VarExp *ve = (VarExp *)this->e1; 810 if (ve->var->storage_class & STCmanifest) 811 { /* We generally don't want to have more than one copy of an 812 * array literal, but if it's an enum we have to because the 813 * enum isn't stored elsewhere. See Bugzilla 2559 814 */ 815 this->e1 = e1; 816 } 817 } 808 818 e2 = e2->optimize(WANTvalue | (result & WANTinterpret)); 809 819 e = Index(type, e1, e2); dmd2/parse.c
r1452 r1526 3145 3145 Statement *ifbody; 3146 3146 Statement *elsebody; 3147 bool isfinal; 3147 3148 Loc loc = this->loc; 3148 3149 … … 3246 3247 } 3247 3248 3249 case TOKfinal: 3250 if (peekNext() == TOKswitch) 3251 { 3252 nextToken(); 3253 isfinal = TRUE; 3254 goto Lswitch; 3255 } 3256 goto Ldeclaration; 3257 3248 3258 CASE_BASIC_TYPES: 3249 3259 case TOKtypedef: … … 3252 3262 case TOKauto: 3253 3263 case TOKextern: 3254 case TOKfinal:3255 3264 case TOKinvariant: 3256 3265 #if DMDV2 … … 3652 3661 3653 3662 case TOKswitch: 3654 { Expression *condition; 3655 Statement *body; 3656 3663 isfinal = FALSE; 3664 goto Lswitch; 3665 3666 Lswitch: 3667 { 3657 3668 nextToken(); 3658 3669 check(TOKlparen); 3659 condition = parseExpression();3670 Expression *condition = parseExpression(); 3660 3671 check(TOKrparen); 3661 body = parseStatement(PSscope);3662 s = new SwitchStatement(loc, condition, body );3672 Statement *body = parseStatement(PSscope); 3673 s = new SwitchStatement(loc, condition, body, isfinal); 3663 3674 break; 3664 3675 } … … 3668 3679 Statements *statements; 3669 3680 Array cases; // array of Expression's 3681 Expression *last = NULL; 3670 3682 3671 3683 while (1) … … 3679 3691 check(TOKcolon); 3680 3692 3693 #if DMDV2 3694 /* case exp: .. case last: 3695 */ 3696 if (token.value == TOKslice) 3697 { 3698 if (cases.dim > 1) 3699 error("only one case allowed for start of case range"); 3700 nextToken(); 3701 check(TOKcase); 3702 last = parseAssignExp(); 3703 check(TOKcolon); 3704 } 3705 #endif 3706 3681 3707 statements = new Statements(); 3682 3708 while (token.value != TOKcase && … … 3689 3715 s = new ScopeStatement(loc, s); 3690 3716 3691 // Keep cases in order by building the case statements backwards 3692 for (int i = cases.dim; i; i--) 3693 { 3694 exp = (Expression *)cases.data[i - 1]; 3695 s = new CaseStatement(loc, exp, s); 3717 #if DMDV2 3718 if (last) 3719 { 3720 s = new CaseRangeStatement(loc, exp, last, s); 3721 } 3722 else 3723 #endif 3724 { 3725 // Keep cases in order by building the case statements backwards 3726 for (int i = cases.dim; i; i--) 3727 { 3728 exp = (Expression *)cases.data[i - 1]; 3729 s = new CaseStatement(loc, exp, s); 3730 } 3696 3731 } 3697 3732 break; … … 4025 4060 * 1 identifier optional 4026 4061 * 2 must have identifier 4062 * Output: 4063 * if *pt is not NULL, it is set to the ending token, which would be endtok 4027 4064 */ 4028 4065 … … 4063 4100 4064 4101 Lis: 4065 //printf("\tis declaration \n");4102 //printf("\tis declaration, t = %s\n", t->toChars()); 4066 4103 return TRUE; 4067 4104 … … 4358 4395 { // This code parallels parseParameters() 4359 4396 Token *t = *pt; 4360 int tmp;4361 4397 4362 4398 //printf("isParameters()\n"); … … 4367 4403 for (;1; t = peek(t)) 4368 4404 { 4405 L1: 4369 4406 switch (t->value) 4370 4407 { … … 4381 4418 case TOKref: 4382 4419 case TOKlazy: 4420 case TOKfinal: 4421 continue; 4422 4383 4423 case TOKconst: 4384 4424 case TOKinvariant: 4385 4425 case TOKimmutable: 4386 4426 case TOKshared: 4387 case TOKfinal: 4388 continue; 4427 t = peek(t); 4428 if (t->value == TOKlparen) 4429 { 4430 t = peek(t); 4431 if (!isDeclaration(t, 0, TOKrparen, &t)) 4432 return FALSE; 4433 t = peek(t); // skip past closing ')' 4434 goto L2; 4435 } 4436 goto L1; 4389 4437 4390 4438 #if 0 … … 4405 4453 4406 4454 default: 4407 if (!isBasicType(&t))4455 { if (!isBasicType(&t)) 4408 4456 return FALSE; 4409 tmp = FALSE; 4457 L2: 4458 int tmp = FALSE; 4410 4459 if (t->value != TOKdotdotdot && 4411 4460 !isDeclarator(&t, &tmp, TOKreserved)) … … 4421 4470 break; 4422 4471 } 4472 } 4423 4473 L3: 4424 4474 if (t->value == TOKcomma) dmd2/root/async.c
r1452 r1526 62 62 void AsyncRead::start() 63 63 { 64 unsigned threadaddr; 65 hThread = (HANDLE) _beginthreadex(NULL, 66 0, 67 &startthread, 68 this, 69 0, 70 (unsigned *)&threadaddr); 64 //printf("aw->filesdim = %p %d\n", this, filesdim); 65 if (filesdim) 66 { 67 unsigned threadaddr; 68 hThread = (HANDLE) _beginthreadex(NULL, 69 0, 70 &startthread, 71 this, 72 0, 73 (unsigned *)&threadaddr); 71 74 72 if (hThread) 73 { 74 SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST); 75 } 76 else 77 { 78 assert(0); 75 if (hThread) 76 { 77 SetThreadPriority(hThread, THREAD_PRIORITY_HIGHEST); 78 } 79 else 80 { 81 assert(0); 82 } 79 83 } 80 84 } … … 99 103 AsyncRead *aw = (AsyncRead *)p; 100 104 105 //printf("aw->filesdim = %p %d\n", aw, aw->filesdim); 101 106 for (size_t i = 0; i < aw->filesdim; i++) 102 107 { FileData *f = &aw->files[i]; dmd2/scope.c
r1452 r1526 72 72 this->noctor = 0; 73 73 this->noaccesscheck = 0; 74 this->mustsemantic = 0; 74 75 this->intypeof = 0; 75 76 this->parameterSpecialization = 0; … … 120 121 this->noctor = enclosing->noctor; 121 122 this->noaccesscheck = enclosing->noaccesscheck; 123 this->mustsemantic = enclosing->mustsemantic; 122 124 this->intypeof = enclosing->intypeof; 123 125 this->parameterSpecialization = enclosing->parameterSpecialization; dmd2/scope.h
r1452 r1526 72 72 int parameterSpecialization; // if in template parameter specialization 73 73 int noaccesscheck; // don't do access checks 74 int mustsemantic; // cannot defer semantic() 74 75 75 76 unsigned callSuper; // primitive flow analysis for constructors dmd2/statement.c
r1452 r1526 142 142 { 143 143 //printf("Statement::comeFrom()\n"); 144 return FALSE; 145 } 146 147 // Return TRUE if statement has no code in it 148 int Statement::isEmpty() 149 { 150 //printf("Statement::isEmpty()\n"); 144 151 return FALSE; 145 152 } … … 581 588 } 582 589 590 int CompoundStatement::isEmpty() 591 { 592 for (int i = 0; i < statements->dim; i++) 593 { Statement *s = (Statement *) statements->data[i]; 594 if (s && !s->isEmpty()) 595 return FALSE; 596 } 597 return TRUE; 598 } 599 583 600 584 601 /******************************** CompoundDeclarationStatement ***************************/ … … 857 874 } 858 875 876 int ScopeStatement::isEmpty() 877 { 878 //printf("ScopeStatement::isEmpty() %d\n", statement ? statement->isEmpty() : TRUE); 879 return statement ? statement->isEmpty() : TRUE; 880 } 881 859 882 void ScopeStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 860 883 { … … 1537 1560 */ 1538 1561 Identifier *id = Identifier::generateId("__r"); 1539 aggr = aggr->semantic(sc);1540 1562 Expression *rinit = new SliceExp(loc, aggr, NULL, NULL); 1541 1563 rinit = rinit->trySemantic(sc); … … 1871 1893 1872 1894 s = new CompoundStatement(loc, a); 1873 s = new SwitchStatement(loc, e, s );1895 s = new SwitchStatement(loc, e, s, FALSE); 1874 1896 s = s->semantic(sc); 1875 1897 } … … 2547 2569 /******************************** SwitchStatement ***************************/ 2548 2570 2549 SwitchStatement::SwitchStatement(Loc loc, Expression *c, Statement *b )2571 SwitchStatement::SwitchStatement(Loc loc, Expression *c, Statement *b, bool isFinal) 2550 2572 : Statement(loc) 2551 2573 { 2552 condition = c; 2553 body = b; 2574 this->condition = c; 2575 this->body = b; 2576 this->isFinal = isFinal; 2554 2577 sdefault = NULL; 2555 2578 cases = NULL; 2556 2579 hasNoDefault = 0; 2557 2580 hasVars = 0; 2558 // LDC 2581 #if IN_LLVM 2559 2582 enclosingScopeExit = NULL; 2583 #endif 2560 2584 } 2561 2585 … … 2563 2587 { 2564 2588 SwitchStatement *s = new SwitchStatement(loc, 2565 condition->syntaxCopy(), body->syntaxCopy() );2589 condition->syntaxCopy(), body->syntaxCopy(), isFinal); 2566 2590 return s; 2567 2591 } … … 2572 2596 assert(!cases); // ensure semantic() is only run once 2573 2597 2574 // LDC 2598 #if IN_LLVM 2575 2599 enclosingScopeExit = sc->enclosingScopeExit; 2600 #endif 2576 2601 2577 2602 condition = condition->semantic(sc); … … 2663 2688 body = cs; 2664 2689 } 2690 2691 #if DMDV2 2692 if (isFinal) 2693 { Type *t = condition->type; 2694 while (t->ty == Ttypedef) 2695 { // Don't use toBasetype() because that will skip past enums 2696 t = ((TypeTypedef *)t)->sym->basetype; 2697 } 2698 if (condition->type->ty == Tenum) 2699 { TypeEnum *te = (TypeEnum *)condition->type; 2700 EnumDeclaration *ed = te->toDsymbol(sc)->isEnumDeclaration(); 2701 assert(ed); 2702 size_t dim = ed->members->dim; 2703 for (size_t i = 0; i < dim; i++) 2704 { 2705 EnumMember *em = ((Dsymbol *)ed->members->data[i])->isEnumMember(); 2706 if (em) 2707 { 2708 for (size_t j = 0; j < cases->dim; j++) 2709 { CaseStatement *cs = (CaseStatement *)cases->data[j]; 2710 if (cs->exp->equals(em->value)) 2711 goto L1; 2712 } 2713 error("enum member %s not represented in final switch", em->toChars()); 2714 } 2715 L1: 2716 ; 2717 } 2718 } 2719 } 2720 #endif 2665 2721 2666 2722 sc->pop(); … … 2747 2803 if (sw) 2748 2804 { 2749 // LDC 2805 #if IN_LLVM 2750 2806 enclosingScopeExit = sc->enclosingScopeExit; 2751 2807 if (enclosingScopeExit != sw->enclosingScopeExit) … … 2753 2809 error("case must be inside the same try, synchronized or volatile level as switch"); 2754 2810 } 2755 2811 #endif 2756 2812 exp = exp->implicitCastTo(sc, sw->condition->type); 2757 2813 exp = exp->optimize(WANTvalue | WANTinterpret); … … 2768 2824 */ 2769 2825 sw->hasVars = 1; 2826 if (sw->isFinal) 2827 error("case variables not allowed in final switch statements"); 2770 2828 goto L1; 2771 2829 } … … 2846 2904 statement->toCBuffer(buf, hgs); 2847 2905 } 2906 2907 /******************************** CaseRangeStatement ***************************/ 2908 2909 #if DMDV2 2910 2911 CaseRangeStatement::CaseRangeStatement(Loc loc, Expression *first, 2912 Expression *last, Statement *s) 2913 : Statement(loc) 2914 { 2915 this->first = first; 2916 this->last = last; 2917 this->statement = s; 2918 } 2919 2920 Statement *CaseRangeStatement::syntaxCopy() 2921 { 2922 CaseRangeStatement *s = new CaseRangeStatement(loc, 2923 first->syntaxCopy(), last->syntaxCopy(), statement->syntaxCopy()); 2924 return s; 2925 } 2926 2927 Statement *CaseRangeStatement::semantic(Scope *sc) 2928 { SwitchStatement *sw = sc->sw; 2929 2930 //printf("CaseRangeStatement::semantic() %s\n", toChars()); 2931 if (sw->isFinal) 2932 error("case ranges not allowed in final switch"); 2933 2934 first = first->semantic(sc); 2935 first = first->implicitCastTo(sc, sw->condition->type); 2936 first = first->optimize(WANTvalue | WANTinterpret); 2937 dinteger_t fval = first->toInteger(); 2938 2939 last = last->semantic(sc); 2940 last = last->implicitCastTo(sc, sw->condition->type); 2941 last = last->optimize(WANTvalue | WANTinterpret); 2942 dinteger_t lval = last->toInteger(); 2943 2944 if (lval - fval > 256) 2945 { error("more than 256 cases in case range"); 2946 lval = fval + 256; 2947 } 2948 2949 /* This works by replacing the CaseRange with an array of Case's. 2950 * 2951 * case a: .. case b: s; 2952 * => 2953 * case a: 2954 * [...] 2955 * case b: 2956 * s; 2957 */ 2958 2959 Statements *statements = new Statements(); 2960 for (dinteger_t i = fval; i <= lval; i++) 2961 { 2962 Statement *s = statement; 2963 if (i != lval) 2964 s = new ExpStatement(loc, NULL); 2965 Expression *e = new IntegerExp(loc, i, first->type); 2966 Statement *cs = new CaseStatement(loc, e, s); 2967 statements->push(cs); 2968 } 2969 Statement *s = new CompoundStatement(loc, statements); 2970 s = s->semantic(sc); 2971 return s; 2972 } 2973 2974 void CaseRangeStatement::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 2975 { 2976 buf->writestring("case "); 2977 first->toCBuffer(buf, hgs); 2978 buf->writestring(": .. case "); 2979 last->toCBuffer(buf, hgs); 2980 buf->writenl(); 2981 statement->toCBuffer(buf, hgs); 2982 } 2983 2984 #endif 2848 2985 2849 2986 /******************************** DefaultStatement ***************************/ … … 2878 3015 sc->sw->sdefault = this; 2879 3016 2880 // LDC 3017 #if IN_LLVM 2881 3018 enclosingScopeExit = sc->enclosingScopeExit; 2882 3019 if (enclosingScopeExit != sc->sw->enclosingScopeExit) … … 2884 3021 error("default must be inside the same try, synchronized or volatile level as switch"); 2885 3022 } 3023 3024 if (sc->sw->isFinal) 3025 { 3026 error("default statement not allowed in final switch statement"); 3027 } 3028 #endif 2886 3029 } 2887 3030 else … … 3218 3361 // Construct: { vresult = exp; return cases.dim + 1; } 3219 3362 exp = new AssignExp(loc, new VarExp(0, fd->vresult), exp); 3363 exp->op = TOKconstruct; 3220 3364 exp = exp->semantic(sc); 3221 3365 Statement *s1 = new ExpStatement(loc, exp); … … 3234 3378 3235 3379 exp = new AssignExp(loc, v, exp); 3380 exp->op = TOKconstruct; 3236 3381 exp = exp->semantic(sc); 3237 3382 } … … 3758 3903 } 3759 3904 3760 if (!body) 3905 if (!body || body->isEmpty()) 3906 { 3761 3907 return NULL; 3762 3908 } 3763 3909 return this; 3764 3910 } dmd2/statement.h
r1452 r1526 129 129 virtual int blockExit(); 130 130 virtual int comeFrom(); 131 virtual int isEmpty(); 131 132 virtual void scopeCode(Scope *sc, Statement **sentry, Statement **sexit, Statement **sfinally); 132 133 virtual Statements *flatten(Scope *sc); … … 147 148 virtual CaseStatement* isCaseStatement() { return NULL; } 148 149 149 // LDC 150 #if IN_LLVM 150 151 virtual void toNakedIR(IRState *irs); 151 152 virtual AsmBlockStatement* endsWithAsm(); 153 #endif 152 154 }; 153 155 … … 169 171 void toIR(IRState *irs); 170 172 171 // LDC 173 #if IN_LLVM 172 174 void toNakedIR(IRState *irs); 175 #endif 173 176 }; 174 177 … … 210 213 int blockExit(); 211 214 int comeFrom(); 215 int isEmpty(); 212 216 virtual Statements *flatten(Scope *sc); 213 217 ReturnStatement *isReturnStatement(); … … 220 224 virtual void toIR(IRState *irs); 221 225 222 // LDC 226 #if IN_LLVM 223 227 virtual void toNakedIR(IRState *irs); 224 228 virtual AsmBlockStatement* endsWithAsm(); 229 #endif 225 230 226 231 virtual CompoundStatement *isCompoundStatement() { return this; } … … 273 278 int blockExit(); 274 279 int comeFrom(); 280 int isEmpty(); 275 281 Expression *interpret(InterState *istate); 276 282 … … 480 486 Expression *condition; 481 487 Statement *body; 488 bool isFinal; 482 489 483 490 DefaultStatement *sdefault; … … 488 495 int hasVars; // !=0 if has variable case values 489 496 490 // LDC 497 #if IN_LLVM 491 498 Statement *enclosingScopeExit; 492 493 SwitchStatement(Loc loc, Expression *c, Statement *b); 499 #endif 500 501 SwitchStatement(Loc loc, Expression *c, Statement *b, bool isFinal); 494 502 Statement *syntaxCopy(); 495 503 Statement *semantic(Scope *sc); … … 509 517 Expression *exp; 510 518 Statement *statement; 519 511 520 int index; // which case it is (since we sort this) 512 521 block *cblock; // back end: label for the block 513 522 514 // LDC 523 #if IN_LLVM 515 524 Statement *enclosingScopeExit; 525 #endif 516 526 517 527 CaseStatement(Loc loc, Expression *exp, Statement *s); … … 531 541 CaseStatement* isCaseStatement() { return this; } 532 542 533 // LDC 543 #if IN_LLVM 534 544 llvm::BasicBlock* bodyBB; 535 545 llvm::ConstantInt* llvmIdx; 536 }; 546 #endif 547 }; 548 549 #if DMDV2 550 551 struct CaseRangeStatement : Statement 552 { 553 Expression *first; 554 Expression *last; 555 Statement *statement; 556 557 CaseRangeStatement(Loc loc, Expression *first, Expression *last, Statement *s); 558 Statement *syntaxCopy(); 559 Statement *semantic(Scope *sc); 560 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 561 }; 562 563 #endif 537 564 538 565 struct DefaultStatement : Statement … … 543 570 #endif 544 571 545 // LDC 572 #if IN_LLVM 546 573 Statement *enclosingScopeExit; 574 #endif 547 575 548 576 DefaultStatement(Loc loc, Statement *s); … … 559 587 void toIR(IRState *irs); 560 588 561 // LDC 589 #if IN_LLVM 562 590 llvm::BasicBlock* bodyBB; 591 #endif 563 592 }; 564 593 … … 635 664 void toIR(IRState *irs); 636 665 666 #if IN_LLVM 637 667 // LDC: only set if ident is set: label statement to jump to 638 668 LabelStatement *target; 669 #endif 639 670 }; 640 671 … … 652 683 void toIR(IRState *irs); 653 684 685 #if IN_LLVM 654 686 // LDC: only set if ident is set: label statement to jump to 655 687 LabelStatement *target; 688 #endif 656 689 }; 657 690 … … 676 709 SynchronizedStatement(Loc loc, elem *esync, Statement *body); 677 710 void toIR(IRState *irs); 711 #if IN_LLVM 678 712 llvm::Value* llsync; 713 #endif 679 714 }; 680 715 … … 838 873 void toIR(IRState *irs); 839 874 840 // LDC 875 #if IN_LLVM 841 876 bool asmLabel; // for labels inside inline assembler 842 877 void toNakedIR(IRState *irs); 878 #endif 843 879 }; 844 880 … … 874 910 void toIR(IRState *irs); 875 911 876 // LDC 912 #if IN_LLVM 877 913 // non-zero if this is a branch, contains the target labels identifier 878 914 Identifier* isBranchToLabel; 879 915 880 916 void toNakedIR(IRState *irs); 917 #endif 881 918 }; 882 919 dmd2/struct.c
r1487 r1526 47 47 sinit = NULL; 48 48 #endif 49 scope = NULL;50 49 isnested = 0; 51 50 vthis = NULL; … … 71 70 { 72 71 //printf("AggregateDeclaration::semantic2(%s)\n", toChars()); 73 if (scope )72 if (scope && members) 74 73 { error("has forward references"); 75 74 return; … … 90 89 { int i; 91 90 92 // LDC 91 #if IN_LLVM 93 92 if (!global.params.useAvailableExternally) 94 93 availableExternally = false; 94 #endif 95 95 96 96 //printf("AggregateDeclaration::semantic3(%s)\n", toChars()); … … 289 289 290 290 parent = sc->parent; 291 type = type->semantic(loc, sc); 291 292 #if STRUCTTHISREF 292 293 handle = type; dmd2/template.c
r1452 r1526 309 309 this->overnext = NULL; 310 310 this->overroot = NULL; 311 this->s cope = NULL;311 this->semanticRun = 0; 312 312 this->onemember = NULL; 313 313 this->literal = 0; … … 338 338 339 339 #if IN_LLVM 340 // LDC341 340 td->intrinsicName = intrinsicName; 342 341 #endif … … 350 349 printf("TemplateDeclaration::semantic(this = %p, id = '%s')\n", this, ident->toChars()); 351 350 #endif 352 if (s cope)351 if (semanticRun) 353 352 return; // semantic() already run 353 semanticRun = 1; 354 354 355 355 if (sc->func) … … 879 879 } 880 880 881 nfparams = Argument::dim(fparameters); // number of function parameters882 nfargs = fargs ->dim; // number of function arguments881 nfparams = Argument::dim(fparameters); // number of function parameters 882 nfargs = fargs ? fargs->dim : 0; // number of function arguments 883 883 884 884 /* Check for match of function arguments with variadic template … … 1330 1330 for (TemplateDeclaration *td = this; td; td = td->overnext) 1331 1331 { 1332 if (!td->s cope)1332 if (!td->semanticRun) 1333 1333 { 1334 1334 error("forward reference to template %s", td->toChars()); … … 3216 3216 this->argsym = NULL; 3217 3217 this->aliasdecl = NULL; 3218 this->semantic done= 0;3218 this->semanticRun = 0; 3219 3219 this->semantictiargsdone = 0; 3220 3220 this->withsym = NULL; … … 3250 3250 this->argsym = NULL; 3251 3251 this->aliasdecl = NULL; 3252 this->semantic done= 0;3252 this->semanticRun = 0; 3253 3253 this->semantictiargsdone = 1; 3254 3254 this->withsym = NULL; … … 3325 3325 tinst = sc->tinst; 3326 3326 3327 if (semantic done!= 0)3327 if (semanticRun != 0) 3328 3328 { 3329 3329 error(loc, "recursive template expansion"); … … 3331 3331 return; 3332 3332 } 3333 semantic done= 1;3333 semanticRun = 1; 3334 3334 #if IN_LLVM 3335 3335 // get the enclosing template instance from the scope tinst … … 3475 3475 //printf("\t2: adding to module %s instead of module %s\n", m->toChars(), sc->module->toChars()); 3476 3476 a = m->members; 3477 if (m->semantic done>= 3)3477 if (m->semanticRun >= 3) 3478 3478 dosemantic3 = 1; 3479 3479 } … … 3496 3496 // Create our own scope for the template parameters 3497 3497 Scope *scope = tempdecl->scope; 3498 if (! scope)3499 { 3500 error(" forward reference to template declaration %s\n", tempdecl->toChars());3498 if (!tempdecl->semanticRun) 3499 { 3500 error("template instantiation %s forward references template declaration %s\n", toChars(), tempdecl->toChars()); 3501 3501 return; 3502 3502 } … … 3718 3718 else if (ta) 3719 3719 { 3720 Ltype: 3720 3721 if (ta->ty == Ttuple) 3721 3722 { // Expand tuple … … 3753 3754 tiargs->data[j] = ea; 3754 3755 if (ea->op == TOKtype) 3755 tiargs->data[j] = ea->type; 3756 { ta = ea->type; 3757 goto Ltype; 3758 } 3759 if (ea->op == TOKtuple) 3760 { // Expand tuple 3761 TupleExp *te = (TupleExp *)ea; 3762 size_t dim = te->exps->dim; 3763 tiargs->remove(j); 3764 if (dim) 3765 { tiargs->reserve(dim); 3766 for (size_t i = 0; i < dim; i++) 3767 tiargs->insert(j + i, te->exps->data[i]); 3768 } 3769 j--; 3770 } 3756 3771 } 3757 3772 else if (sa) 3758 3773 { 3759 3774 TemplateDeclaration *td = sa->isTemplateDeclaration(); 3760 if (td && !td->s cope&& td->literal)3775 if (td && !td->semanticRun && td->literal) 3761 3776 td->semantic(sc); 3762 3777 } … … 3899 3914 printf("TemplateInstance::findBestMatch()\n"); 3900 3915 #endif 3916 // First look for forward references 3917 for (TemplateDeclaration *td = tempdecl; td; td = td->overnext) 3918 { 3919 if (!td->semanticRun) 3920 { 3921 if (td->scope) 3922 { // Try to fix forward reference 3923 td->semantic(td->scope); 3924 } 3925 if (!td->semanticRun) 3926 { 3927 error("%s forward references template declaration %s\n", toChars(), td->toChars()); 3928 return NULL; 3929 } 3930 } 3931 } 3932 3901 3933 for (TemplateDeclaration *td = tempdecl; td; td = td->overnext) 3902 3934 { … … 3915 3947 dedtypes.setDim(td->parameters->dim); 3916 3948 dedtypes.zero(); 3917 if (!td->scope) 3918 { 3919 error("forward reference to template declaration %s", td->toChars()); 3920 return NULL; 3921 } 3949 assert(td->semanticRun); 3922 3950 m = td->matchWithInstance(this, &dedtypes, 0); 3923 3951 //printf("matchWithInstance = %d\n", m); … … 4213 4241 */ 4214 4242 4215 void TemplateInstance::declareParameters(Scope *sc ope)4243 void TemplateInstance::declareParameters(Scope *sc) 4216 4244 { 4217 4245 //printf("TemplateInstance::declareParameters()\n"); … … 4223 4251 4224 4252 //printf("\ttdtypes[%d] = %p\n", i, o); 4225 tempdecl->declareParameter(sc ope, tp, o);4253 tempdecl->declareParameter(sc, tp, o); 4226 4254 } 4227 4255 } … … 4231 4259 { int i; 4232 4260 4233 if (semantic done>= 2)4261 if (semanticRun >= 2) 4234 4262 return; 4235 semantic done= 2;4263 semanticRun = 2; 4236 4264 #if LOG 4237 4265 printf("+TemplateInstance::semantic2('%s')\n", toChars()); … … 4263 4291 { 4264 4292 #if LOG 4265 printf("TemplateInstance::semantic3('%s'), semantic done = %d\n", toChars(), semanticdone);4293 printf("TemplateInstance::semantic3('%s'), semanticRun = %d\n", toChars(), semanticRun); 4266 4294 #endif 4267 4295 //if (toChars()[0] == 'D') *(char*)0=0; 4268 if (semantic done>= 3)4296 if (semanticRun >= 3) 4269 4297 return; 4270 semantic done= 3;4298 semanticRun = 3; 4271 4299 if (!errors && members) 4272 4300 { … … 4458 4486 this->idents = idents; 4459 4487 this->tiargs = tiargs ? tiargs : new Objects(); 4460 this->scope = NULL;4461 4488 } 4462 4489 … … 4492 4519 fflush(stdout); 4493 4520 #endif 4494 if (semantic done&&4521 if (semanticRun && 4495 4522 // This for when a class/struct contains mixin members, and 4496 4523 // is done over because of forward references … … 4502 4529 return; 4503 4530 } 4504 if (!semantic done)4505 semantic done= 1;4531 if (!semanticRun) 4532 semanticRun = 1; 4506 4533 #if LOG 4507 4534 printf("\tdo semantic\n"); … … 4578 4605 for (TemplateDeclaration *td = tempdecl; td; td = td->overnext) 4579 4606 { 4580 if (!td->s cope)4607 if (!td->semanticRun) 4581 4608 { 4582 4609 /* Cannot handle forward references if mixin is a struct member, … … 4586 4613 * semantic. 4587 4614 */ 4588 semantic done= 0;4615 semanticRun = 0; 4589 4616 AggregateDeclaration *ad = toParent()->isAggregateDeclaration(); 4590 4617 if (ad) … … 4692 4719 argsym = new ScopeDsymbol(); 4693 4720 argsym->parent = scy->parent; 4694 Scope * scope = scy->push(argsym);4721 Scope *argscope = scy->push(argsym); 4695 4722 4696 4723 unsigned errorsave = global.errors; 4697 4724 4698 4725 // Declare each template parameter as an alias for the argument type 4699 declareParameters( scope);4726 declareParameters(argscope); 4700 4727 4701 4728 // Add members to enclosing scope, as well as this scope … … 4704 4731 4705 4732 s = (Dsymbol *)members->data[i]; 4706 s->addMember( scope, this, i);4733 s->addMember(argscope, this, i); 4707 4734 //sc->insert(s); 4708 4735 //printf("sc->parent = %p, sc->scopesym = %p\n", sc->parent, sc->scopesym); … … 4715 4742 #endif 4716 4743 Scope *sc2; 4717 sc2 = scope->push(this);4744 sc2 = argscope->push(this); 4718 4745 sc2->offset = sc->offset; 4719 4746 … … 4758 4785 sc2->pop(); 4759 4786 4760 scope->pop();4787 argscope->pop(); 4761 4788 4762 4789 // if (!isAnonymous()) … … 4772 4799 { int i; 4773 4800 4774 if (semantic done>= 2)4801 if (semanticRun >= 2) 4775 4802 return; 4776 semantic done= 2;4803 semanticRun = 2; 4777 4804 #if LOG 4778 4805 printf("+TemplateMixin::semantic2('%s')\n", toChars()); … … 4802 4829 { int i; 4803 4830 4804 if (semantic done>= 3)4831 if (semanticRun >= 3) 4805 4832 return; 4806 semantic done= 3;4833 semanticRun = 3; 4807 4834 #if LOG 4808 4835 printf("TemplateMixin::semantic3('%s')\n", toChars()); dmd2/template.h
r1452 r1526 62 62 TemplateDeclaration *overroot; // first in overnext list 63 63 64 Scope *scope; 64 int semanticRun; // 1 semantic() run 65 65 66 Dsymbol *onemember; // if !=NULL then one member of this template 66 67 … … 285 286 // sole member 286 287 WithScopeSymbol *withsym; // if a member of a with statement 287 int semantic done; // has semantic() been done?288 int semanticRun; // has semantic() been done? 288 289 int semantictiargsdone; // has semanticTiargs() been done? 289 290 int nest; // for recursion detection … … 343 344 Array *idents; 344 345 Type *tqual; 345 346 Scope *scope; // for forward referencing347 346 348 347 TemplateMixin(Loc loc, Identifier *ident, Type *tqual, Array *idents, Objects *tiargs);

