Changeset 837
- Timestamp:
- 11/17/07 17:25:07 (1 year ago)
- Files:
-
- branches/dmdfe-2.0/cast.c (modified) (5 diffs)
- branches/dmdfe-2.0/class.c (modified) (1 diff)
- branches/dmdfe-2.0/declaration.c (modified) (3 diffs)
- branches/dmdfe-2.0/declaration.h (modified) (2 diffs)
- branches/dmdfe-2.0/dsymbol.c (modified) (15 diffs)
- branches/dmdfe-2.0/dsymbol.h (modified) (4 diffs)
- branches/dmdfe-2.0/expression.c (modified) (20 diffs)
- branches/dmdfe-2.0/expression.h (modified) (4 diffs)
- branches/dmdfe-2.0/func.c (modified) (3 diffs)
- branches/dmdfe-2.0/lexer.c (modified) (1 diff)
- branches/dmdfe-2.0/lexer.h (modified) (1 diff)
- branches/dmdfe-2.0/mars.c (modified) (2 diffs)
- branches/dmdfe-2.0/mtype.c (modified) (9 diffs)
- branches/dmdfe-2.0/template.c (modified) (12 diffs)
- branches/dmdfe-2.0/template.h (modified) (2 diffs)
- branches/dmdfe-2.0/typinf.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmdfe-2.0/cast.c
r835 r837 484 484 { 485 485 // Look for pointers to functions where the functions are overloaded. 486 VarExp *ve;487 FuncDeclaration *f;488 486 489 487 t = t->toBasetype(); 488 489 if (e1->op == TOKoverloadset && 490 (t->ty == Tpointer || t->ty == Tdelegate) && t->nextOf()->ty == Tfunction) 491 { OverExp *eo = (OverExp *)e1; 492 FuncDeclaration *f = NULL; 493 for (int i = 0; i < eo->vars->a.dim; i++) 494 { Dsymbol *s = (Dsymbol *)eo->vars->a.data[i]; 495 FuncDeclaration *f2 = s->isFuncDeclaration(); 496 assert(f2); 497 if (f2->overloadExactMatch(t->nextOf())) 498 { if (f) 499 /* Error if match in more than one overload set, 500 * even if one is a 'better' match than the other. 501 */ 502 ScopeDsymbol::multiplyDefined(loc, f, f2); 503 else 504 f = f2; 505 result = MATCHexact; 506 } 507 } 508 } 509 490 510 if (type->ty == Tpointer && type->nextOf()->ty == Tfunction && 491 511 t->ty == Tpointer && t->nextOf()->ty == Tfunction && … … 497 517 */ 498 518 assert(0); 499 ve = (VarExp *)e1;500 f = ve->var->isFuncDeclaration();519 VarExp *ve = (VarExp *)e1; 520 FuncDeclaration *f = ve->var->isFuncDeclaration(); 501 521 if (f && f->overloadExactMatch(t->nextOf())) 502 522 result = MATCHexact; … … 929 949 { 930 950 // Look for pointers to functions where the functions are overloaded. 931 VarExp *ve; 932 FuncDeclaration *f; 951 952 if (e1->op == TOKoverloadset && 953 (t->ty == Tpointer || t->ty == Tdelegate) && t->nextOf()->ty == Tfunction) 954 { OverExp *eo = (OverExp *)e1; 955 FuncDeclaration *f = NULL; 956 for (int i = 0; i < eo->vars->a.dim; i++) 957 { Dsymbol *s = (Dsymbol *)eo->vars->a.data[i]; 958 FuncDeclaration *f2 = s->isFuncDeclaration(); 959 assert(f2); 960 if (f2->overloadExactMatch(t->nextOf())) 961 { if (f) 962 /* Error if match in more than one overload set, 963 * even if one is a 'better' match than the other. 964 */ 965 ScopeDsymbol::multiplyDefined(loc, f, f2); 966 else 967 f = f2; 968 } 969 } 970 if (f) 971 { SymOffExp *se = new SymOffExp(loc, f, 0, 0); 972 se->semantic(sc); 973 // Let SymOffExp::castTo() do the heavy lifting 974 return se->castTo(sc, t); 975 } 976 } 977 933 978 934 979 if (type->ty == Tpointer && type->nextOf()->ty == Tfunction && … … 936 981 e1->op == TOKvar) 937 982 { 938 ve = (VarExp *)e1;939 f = ve->var->isFuncDeclaration();983 VarExp *ve = (VarExp *)e1; 984 FuncDeclaration *f = ve->var->isFuncDeclaration(); 940 985 if (f) 941 986 { 987 assert(0); // should be SymOffExp instead 942 988 f = f->overloadExactMatch(tb->nextOf()); 943 989 if (f) … … 1272 1318 if ((t1->ty == Tsarray || t1->ty == Tarray) && 1273 1319 (t2->ty == Tsarray || t2->ty == Tarray) && 1274 (t1->nextOf()->mod || t2->nextOf()->mod)) 1320 (t1->nextOf()->mod || t2->nextOf()->mod) && 1321 (t1->nextOf()->mod != t2->nextOf()->mod) 1322 ) 1275 1323 { 1276 1324 t1 = t1->constOf(); branches/dmdfe-2.0/class.c
r836 r837 817 817 return 0; 818 818 } 819 FuncDeclaration *fdstart = s->toAlias()->isFuncDeclaration(); 820 //printf("%s fdstart = %p\n", s->kind(), fdstart); 821 return !overloadApply(fdstart, &isf, fd); 819 s = s->toAlias(); 820 OverloadSet *os = s->isOverloadSet(); 821 if (os) 822 { 823 for (int i = 0; i < os->a.dim; i++) 824 { Dsymbol *s = (Dsymbol *)os->a.data[i]; 825 FuncDeclaration *f2 = s->isFuncDeclaration(); 826 if (f2 && overloadApply(f2, &isf, fd)) 827 return 0; 828 } 829 return 1; 830 } 831 else 832 { 833 FuncDeclaration *fdstart = s->isFuncDeclaration(); 834 //printf("%s fdstart = %p\n", s->kind(), fdstart); 835 return !overloadApply(fdstart, &isf, fd); 836 } 822 837 } 823 838 #endif branches/dmdfe-2.0/declaration.c
r836 r837 446 446 { 447 447 // Try to convert Expression to Dsymbol 448 if (e->op == TOKvar) 449 { s = ((VarExp *)e)->var;448 s = getDsymbol(e); 449 if (s) 450 450 goto L2; 451 } 452 else if (e->op == TOKfunction) 453 { s = ((FuncExp *)e)->fd; 454 goto L2; 455 } 456 else 457 { error("cannot alias an expression %s", e->toChars()); 458 t = e->type; 459 } 451 452 error("cannot alias an expression %s", e->toChars()); 453 t = e->type; 460 454 } 461 455 else if (t) … … 651 645 //printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars()); 652 646 //printf(" type = %s\n", type->toChars()); 647 //printf("stc = x%x\n", sc->stc); 653 648 //printf("linkage = %d\n", sc->linkage); 654 649 //if (strcmp(toChars(), "mul") == 0) halt(); … … 748 743 } 749 744 745 Lagain: 750 746 if (isConst()) 751 747 { 748 /* Rewrite things like: 749 * const string s; 750 * to: 751 * invariant string s; 752 */ 753 if (type->nextOf() && type->nextOf()->isInvariant()) 754 { storage_class |= STCinvariant; 755 storage_class &= ~STCconst; 756 goto Lagain; 757 } 752 758 type = type->constOf(); 753 759 if (isParameter()) branches/dmdfe-2.0/declaration.h
r836 r837 461 461 int overloadInsert(Dsymbol *s); 462 462 FuncDeclaration *overloadExactMatch(Type *t); 463 FuncDeclaration *overloadResolve(Loc loc, Expressions *arguments );463 FuncDeclaration *overloadResolve(Loc loc, Expressions *arguments, int flags = 0); 464 464 LabelDsymbol *searchLabel(Identifier *ident); 465 465 AggregateDeclaration *isThis(); … … 476 476 int isAbstract(); 477 477 int isCodeseg(); 478 int isOverloadable(); 478 479 virtual int isNested(); 479 480 int needThis(); branches/dmdfe-2.0/dsymbol.c
r835 r837 383 383 } 384 384 385 int Dsymbol::isOverloadable() 386 { 387 return 0; 388 } 389 385 390 LabelDsymbol *Dsymbol::isLabel() // is this a LabelDsymbol()? 386 391 { … … 581 586 } 582 587 #endif 588 } 589 590 /********************************* OverloadSet ****************************/ 591 592 OverloadSet::OverloadSet() 593 : Dsymbol() 594 { 595 } 596 597 void OverloadSet::push(Dsymbol *s) 598 { 599 a.push(s); 600 } 601 602 char *OverloadSet::kind() 603 { 604 return "overloadset"; 583 605 } 584 606 … … 618 640 619 641 Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags) 620 { Dsymbol *s; 621 int i; 622 642 { 623 643 //printf("%s->ScopeDsymbol::search(ident='%s', flags=x%x)\n", toChars(), ident->toChars(), flags); 644 624 645 // Look in symbols declared in this module 625 s = symtab ? symtab->lookup(ident) : NULL;646 Dsymbol *s = symtab ? symtab->lookup(ident) : NULL; 626 647 if (s) 627 648 { … … 630 651 else if (imports) 631 652 { 653 OverloadSet *a = NULL; 654 632 655 // Look in imported modules 633 for (i = 0; i < imports->dim; i++)656 for (int i = 0; i < imports->dim; i++) 634 657 { ScopeDsymbol *ss = (ScopeDsymbol *)imports->data[i]; 635 658 Dsymbol *s2; … … 640 663 641 664 //printf("\tscanning import '%s', prots = %d, isModule = %p, isImport = %p\n", ss->toChars(), prots[i], ss->isModule(), ss->isImport()); 665 /* Don't find private members if ss is a module 666 */ 642 667 s2 = ss->search(loc, ident, ss->isModule() ? 1 : 0); 643 668 if (!s) … … 647 672 if (s->toAlias() == s2->toAlias()) 648 673 { 674 /* After following aliases, we found the same symbol, 675 * so it's not an ambiguity. 676 * But if one alias is deprecated, prefer the other. 677 */ 649 678 if (s->isDeprecated()) 650 679 s = s2; … … 665 694 ) 666 695 { 667 if (flags & 4) 696 /* If both s2 and s are overloadable (though we only 697 * need to check s once) 698 */ 699 if (s2->isOverloadable() && (a || s->isOverloadable())) 700 { if (!a) 701 a = new OverloadSet(); 702 /* Don't add to a[] if s2 is alias of previous sym 703 */ 704 for (int j = 0; j < a->a.dim; j++) 705 { Dsymbol *s3 = (Dsymbol *)a->a.data[j]; 706 if (s2->toAlias() == s3->toAlias()) 707 { 708 if (s3->isDeprecated()) 709 a->a.data[j] = (void *)s2; 710 goto Lcontinue; 711 } 712 } 713 a->push(s2); 714 Lcontinue: 715 continue; 716 } 717 if (flags & 4) // if return NULL on ambiguity 668 718 return NULL; 669 719 if (!(flags & 2)) … … 674 724 } 675 725 } 726 727 /* Build special symbol if we had multiple finds 728 */ 729 if (a) 730 { assert(s); 731 a->push(s); 732 s = a; 733 } 734 676 735 if (s) 677 736 { 678 737 Declaration *d = s->isDeclaration(); 679 if (d && d->protection == PROTprivate && !d->parent->isTemplateMixin() && 738 if (d && d->protection == PROTprivate && 739 !d->parent->isTemplateMixin() && 680 740 !(flags & 2)) 681 741 error("%s is private", d->toPrettyChars()); … … 832 892 /****************************** ArrayScopeSymbol ******************************/ 833 893 834 ArrayScopeSymbol::ArrayScopeSymbol( Expression *e)894 ArrayScopeSymbol::ArrayScopeSymbol(Scope *sc, Expression *e) 835 895 : ScopeDsymbol() 836 896 { … … 839 899 type = NULL; 840 900 td = NULL; 841 } 842 843 ArrayScopeSymbol::ArrayScopeSymbol(TypeTuple *t) 901 this->sc = sc; 902 } 903 904 ArrayScopeSymbol::ArrayScopeSymbol(Scope *sc, TypeTuple *t) 844 905 : ScopeDsymbol() 845 906 { … … 847 908 type = t; 848 909 td = NULL; 849 } 850 851 ArrayScopeSymbol::ArrayScopeSymbol(TupleDeclaration *s) 910 this->sc = sc; 911 } 912 913 ArrayScopeSymbol::ArrayScopeSymbol(Scope *sc, TupleDeclaration *s) 852 914 : ScopeDsymbol() 853 915 { … … 855 917 type = NULL; 856 918 td = s; 919 this->sc = sc; 857 920 } 858 921 … … 872 935 v->init = new ExpInitializer(0, e); 873 936 v->storage_class |= STCconst; 937 v->semantic(sc); 874 938 return v; 875 939 } … … 881 945 v->init = new ExpInitializer(0, e); 882 946 v->storage_class |= STCconst; 947 v->semantic(sc); 883 948 return v; 884 949 } … … 945 1010 *pvar = v; 946 1011 } 1012 (*pvar)->semantic(sc); 947 1013 return (*pvar); 948 1014 } branches/dmdfe-2.0/dsymbol.h
r836 r837 67 67 struct DeleteDeclaration; 68 68 struct HdrGenState; 69 struct OverloadSet; 69 70 70 71 #if IN_GCC … … 141 142 virtual ClassDeclaration *isClassMember(); // are we a member of a class? 142 143 virtual int isExport(); // is Dsymbol exported? 143 virtual int isImportedSymbol(); // is Dsymbol imported?144 virtual int isImportedSymbol(); // is Dsymbol imported? 144 145 virtual int isDeprecated(); // is Dsymbol deprecated? 146 virtual int isOverloadable(); 145 147 virtual LabelDsymbol *isLabel(); // is this a LabelDsymbol? 146 148 virtual AggregateDeclaration *isMember(); // is this symbol a member of an AggregateDeclaration? … … 204 206 virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; } 205 207 virtual AttribDeclaration *isAttribDeclaration() { return NULL; } 208 virtual OverloadSet *isOverloadSet() { return NULL; } 206 209 }; 207 210 … … 256 259 TypeTuple *type; // for tuple[length] 257 260 TupleDeclaration *td; // for tuples of objects 258 259 ArrayScopeSymbol(Expression *e); 260 ArrayScopeSymbol(TypeTuple *t); 261 ArrayScopeSymbol(TupleDeclaration *td); 261 Scope *sc; 262 263 ArrayScopeSymbol(Scope *sc, Expression *e); 264 ArrayScopeSymbol(Scope *sc, TypeTuple *t); 265 ArrayScopeSymbol(Scope *sc, TupleDeclaration *td); 262 266 Dsymbol *search(Loc loc, Identifier *ident, int flags); 263 267 264 268 ArrayScopeSymbol *isArrayScopeSymbol() { return this; } 269 }; 270 271 // Overload Sets 272 273 struct OverloadSet : Dsymbol 274 { 275 Dsymbols a; // array of Dsymbols 276 277 OverloadSet(); 278 void push(Dsymbol *s); 279 OverloadSet *isOverloadSet() { return this; } 280 char *kind(); 265 281 }; 266 282 branches/dmdfe-2.0/expression.c
r836 r837 254 254 Type *t = e->type->toBasetype(); 255 255 256 if (t->ty == Tfunction )256 if (t->ty == Tfunction || e->op == TOKoverloadset) 257 257 { 258 258 e = new CallExp(e->loc, e); … … 276 276 e->error("expression has no value"); 277 277 } 278 278 279 } 279 280 return e; … … 711 712 { 712 713 #if LOGSEMANTIC 713 printf("Expression::semantic() \n");714 printf("Expression::semantic() %s\n", toChars()); 714 715 #endif 715 716 if (type) … … 1026 1027 if (type && !type->isscalar()) 1027 1028 { 1028 //printf(" test1:%s, loc = %d\n", toChars(), loc.linnum);1029 //printf("%s, loc = %d\n", toChars(), loc.linnum); 1029 1030 error("integral constant must be scalar type, not %s", type->toChars()); 1030 1031 type = Type::terror; … … 1630 1631 WithScopeSymbol *withsym; 1631 1632 1632 // See if it was a with class 1633 /* See if the symbol was a member of an enclosing 'with' 1634 */ 1633 1635 withsym = scopesym->isWithScopeSymbol(); 1634 1636 if (withsym) … … 1651 1653 else 1652 1654 { 1653 if (!s->parent && scopesym->isArrayScopeSymbol()) 1654 { // Kludge to run semantic() here because 1655 // ArrayScopeSymbol::search() doesn't have access to sc. 1656 s->semantic(sc); 1657 } 1658 // Look to see if f is really a function template 1659 //FuncDeclaration *f = s->toAlias()->isFuncDeclaration(); 1655 /* If f is really a function template, 1656 * then replace f with the function template declaration. 1657 */ 1660 1658 FuncDeclaration *f = s->isFuncDeclaration(); 1661 1659 if (f && f->parent) … … 1677 1675 } 1678 1676 } 1679 f = s->toAlias()->isFuncDeclaration(); 1680 if (f && !f->isFuncLiteralDeclaration()) 1681 { 1682 e = new VarExp(loc, f, 1); 1683 } 1684 else 1685 { 1686 e = new DsymbolExp(loc, s); 1687 } 1677 // Haven't done overload resolution yet, so pass 1 1678 e = new DsymbolExp(loc, s, 1); 1688 1679 } 1689 1680 return e->semantic(sc); … … 1728 1719 /******************************** DsymbolExp **************************/ 1729 1720 1730 DsymbolExp::DsymbolExp(Loc loc, Dsymbol *s )1721 DsymbolExp::DsymbolExp(Loc loc, Dsymbol *s, int hasOverloads) 1731 1722 : Expression(loc, TOKdsymbol, sizeof(DsymbolExp)) 1732 1723 { 1733 1724 this->s = s; 1725 this->hasOverloads = hasOverloads; 1734 1726 } 1735 1727 … … 1746 1738 FuncDeclaration *f; 1747 1739 FuncLiteralDeclaration *fld; 1740 OverloadSet *o; 1748 1741 Declaration *d; 1749 1742 ClassDeclaration *cd; … … 1800 1793 } 1801 1794 } 1802 #if 01803 if ((v->isConst() || v->isInvariant()) && type->toBasetype()->ty != Tsarray)1804 { // Replace v with its initializer1805 if (v->init)1806 {1807 if (v->inuse)1808 {1809 error("circular reference to '%s'", v->toChars());1810 type = Type::tint32;1811 return this;1812 }1813 ExpInitializer *ei = v->init->isExpInitializer();1814 if (ei)1815 {1816 e = ei->exp->copy(); // make copy so we can change loc1817 if (e->op == TOKstring || !e->type)1818 e = e->semantic(sc);1819 e = e->implicitCastTo(sc, type);1820 e->loc = loc;1821 return e;1822 }1823 }1824 else1825 {1826 e = type->defaultInit();1827 e->loc = loc;1828 return e;1829 }1830 }1831 #endif1832 1795 e = new VarExp(loc, v); 1833 1796 e->type = type; … … 1844 1807 if (f) 1845 1808 { //printf("'%s' is a function\n", f->toChars()); 1846 return new VarExp(loc, f); 1809 return new VarExp(loc, f, hasOverloads); 1810 } 1811 o = s->isOverloadSet(); 1812 if (o) 1813 { //printf("'%s' is an overload set\n", o->toChars()); 1814 return new OverExp(o); 1847 1815 } 1848 1816 cd = s->isClassDeclaration(); … … 3646 3614 3647 3615 3616 /******************************** OverExp **************************/ 3617 3618 OverExp::OverExp(OverloadSet *s) 3619 : Expression(loc, TOKoverloadset, sizeof(OverExp)) 3620 { 3621 //printf("OverExp(this = %p, '%s')\n", this, var->toChars()); 3622 vars = s; 3623 type = Type::tvoid; 3624 } 3625 3626 Expression *OverExp::toLvalue(Scope *sc, Expression *e) 3627 { 3628 return this; 3629 } 3630 3631 3648 3632 /******************************** TupleExp **************************/ 3649 3633 … … 5823 5807 } 5824 5808 } 5809 else if (e1->op == TOKoverloadset) 5810 { 5811 OverExp *eo = (OverExp *)e1; 5812 FuncDeclaration *f = NULL; 5813 for (int i = 0; i < eo->vars->a.dim; i++) 5814 { Dsymbol *s = (Dsymbol *)eo->vars->a.data[i]; 5815 FuncDeclaration *f2 = s->isFuncDeclaration(); 5816 if (f2) 5817 { 5818 f2 = f2->overloadResolve(loc, arguments, 1); 5819 } 5820 else 5821 { TemplateDeclaration *td = s->isTemplateDeclaration(); 5822 assert(td); 5823 f2 = td->deduce(sc, loc, NULL, arguments, 1); 5824 } 5825 if (f2) 5826 { if (f) 5827 /* Error if match in more than one overload set, 5828 * even if one is a 'better' match than the other. 5829 */ 5830 ScopeDsymbol::multiplyDefined(loc, f, f2); 5831 else 5832 f = f2; 5833 } 5834 } 5835 if (!f) 5836 { /* No overload matches, just set f and rely on error 5837 * message being generated later. 5838 */ 5839 f = (FuncDeclaration *)eo->vars->a.data[0]; 5840 } 5841 e1 = new VarExp(loc, f); 5842 goto Lagain; 5843 } 5825 5844 else if (!t1) 5826 5845 { … … 5878 5897 f = ve->var->isFuncDeclaration(); 5879 5898 assert(f); 5880 5881 // Look to see if f is really a function template5882 if (0 && !istemp && f->parent)5883 { TemplateInstance *ti = f->parent->isTemplateInstance();5884 5885 if (ti &&5886 (ti->name == f->ident ||5887 ti->toAlias()->ident == f->ident)5888 &&5889 ti->tempdecl)5890 {5891 /* This is so that one can refer to the enclosing5892 * template, even if it has the same name as a member5893 * of the template, if it has a !(arguments)5894 */5895 TemplateDeclaration *tempdecl = ti->tempdecl;5896 if (tempdecl->overroot) // if not start of overloaded list of TemplateDeclaration's5897 tempdecl = tempdecl->overroot; // then get the start5898 e1 = new TemplateExp(loc, tempdecl);5899 istemp = 1;5900 goto Lagain;5901 }5902 }5903 5899 5904 5900 if (ve->hasOverloads) … … 6557 6553 if (t->ty == Tsarray || t->ty == Tarray || t->ty == Ttuple) 6558 6554 { 6559 sym = new ArrayScopeSymbol( this);6555 sym = new ArrayScopeSymbol(sc, this); 6560 6556 sym->loc = loc; 6561 6557 sym->parent = sc->scopesym; … … 6631 6627 } 6632 6628 6633 type = ((TypeNext *)t)->next->arrayOf();6629 type = t->nextOf()->arrayOf(); 6634 6630 return e; 6635 6631 … … 6897 6893 if (t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Ttuple) 6898 6894 { // Create scope for 'length' variable 6899 sym = new ArrayScopeSymbol( this);6895 sym = new ArrayScopeSymbol(sc, this); 6900 6896 sym->loc = loc; 6901 6897 sym->parent = sc->scopesym; … … 7082 7078 7083 7079 #if LOGSEMANTIC 7084 printf("AssignExp::semantic('%s')\n", toChars());7080 //printf("AssignExp::semantic('%s')\n", toChars()); 7085 7081 #endif 7086 7082 //printf("e1->op = %d, '%s'\n", e1->op, Token::toChars(e1->op)); 7083 //printf("e2->op = %d, '%s'\n", e2->op, Token::toChars(e2->op)); 7087 7084 7088 7085 /* Look for operator overloading of a[i]=value. … … 7178 7175 e2 = resolveProperties(sc, e2); 7179 7176 assert(e1->type); 7177 7178 /* Rewrite tuple assignment as a tuple of assignments. 7179 */ 7180 if (e1->op == TOKtuple && e2->op == TOKtuple) 7181 { TupleExp *tup1 = (TupleExp *)e1; 7182 TupleExp *tup2 = (TupleExp *)e2; 7183 size_t dim = tup1->exps->dim; 7184 if (dim != tup2->exps->dim) 7185 { 7186 error("mismatched tuple lengths, %d and %d", (int)dim, (int)tup2->exps->dim); 7187 } 7188 else 7189 { Expressions *exps = new Expressions; 7190 exps->setDim(dim); 7191 7192 for (int i = 0; i < dim; i++) 7193 { Expression *ex1 = (Expression *)tup1->exps->data[i]; 7194 Expression *ex2 = (Expression *)tup2->exps->data[i]; 7195 exps->data[i] = (void *) new AssignExp(loc, ex1, ex2); 7196 } 7197 Expression *e = new TupleExp(loc, exps); 7198 e = e->semantic(sc); 7199 return e; 7200 } 7201 } 7180 7202 7181 7203 t1 = e1->type->toBasetype(); … … 7924 7946 7925 7947 typeCombine(sc); 7948 //type->print(); 7926 7949 type = type->mutableOf(); 7950 //printf("test1\n"); 7951 //type->print(); 7927 7952 7928 7953 Type *tb = type->toBasetype(); 7929 7954 if (tb->ty == Tsarray) 7930 7955 type = tb->nextOf()->arrayOf(); 7931 if (type->ty == Tarray) 7956 //printf("test2\n"); 7957 //type->print(); 7958 if (type->ty == Tarray && tb1->nextOf()->mod != tb2->nextOf()->mod) 7932 7959 type = type->nextOf()->toCanonConst()->arrayOf(); 7960 //printf("test3\n"); 7961 //type->print(); 7933 7962 #if 0 7934 7963 e1->type->print(); branches/dmdfe-2.0/expression.h
r836 r837 44 44 struct InterState; 45 45 struct Symbol; // back end symbol 46 struct OverloadSet; 46 47 47 48 enum TOK; … … 231 232 { 232 233 Dsymbol *s; 233 234 DsymbolExp(Loc loc, Dsymbol *s); 234 int hasOverloads; 235 236 DsymbolExp(Loc loc, Dsymbol *s, int hasOverloads = 0); 235 237 Expression *semantic(Scope *sc); 236 238 char *toChars(); … … 326 328 Expression *interpret(InterState *istate); 327 329 Expression *castTo(Scope *sc, Type *t); 330 elem *toElem(IRState *irs); 328 331 329 332 int inlineCost(InlineCostState *ics); … … 537 540 //Expression *inlineScan(InlineScanState *iss); 538 541 }; 542 543 // Overload Set 544 545 struct OverExp : Expression 546 { 547 OverloadSet *vars; 548 549 OverExp(OverloadSet *s); 550 Expression *toLvalue(Scope *sc, Expression *e); 551 }; 552 539 553 540 554 // Function/Delegate literal branches/dmdfe-2.0/func.c
r836 r837 1504 1504 1505 1505 1506 FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expressions *arguments )1506 FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expressions *arguments, int flags) 1507 1507 { 1508 1508 TypeFunction *tf; … … 1546 1546 if (m.last == MATCHnomatch) 1547 1547 { 1548 if (flags & 1) // if do not print error messages 1549 return NULL; // no match 1550 1548 1551 tf = (TypeFunction *)type; 1549 1552 … … 1774 1777 } 1775 1778 1779 int FuncDeclaration::isOverloadable() 1780 { 1781 return 1; // functions can be overloaded 1782 } 1783 1776 1784 // Determine if function needs 1777 1785 // a static frame pointer to its lexically enclosing function branches/dmdfe-2.0/lexer.c
r835 r837 2887 2887 #if V2 2888 2888 { "__traits", TOKtraits }, 2889 { "__overloadset", TOKoverloadset }, 2889 2890 #endif 2890 2891 }; branches/dmdfe-2.0/lexer.h
r835 r837 153 153 #if V2 154 154 TOKtraits, 155 TOKoverloadset, 155 156 #endif 156 157 branches/dmdfe-2.0/mars.c
r836 r837 56 56 copyright = "Copyright (c) 1999-2007 by Digital Mars"; 57 57 written = "written by Walter Bright"; 58 version = "v2.00 5";58 version = "v2.006"; 59 59 global.structalign = 8; 60 60 … … 110 110 fprintf(stdmsg, "\n"); 111 111 fflush(stdmsg); 112 //halt();112 halt(); 113 113 } 114 114 global.errors++; branches/dmdfe-2.0/mtype.c
r836 r837 370 370 if (ty == Tsarray) 371 371 { TypeSArray *ta = (TypeSArray *)t; 372 ta->next = ta->next->mutableOf();372 //ta->next = ta->next->mutableOf(); 373 373 } 374 374 t = t->merge(); … … 1858 1858 { 1859 1859 if (t->ty == Ttuple) 1860 { ScopeDsymbol *sym = new ArrayScopeSymbol( (TypeTuple *)t);1860 { ScopeDsymbol *sym = new ArrayScopeSymbol(sc, (TypeTuple *)t); 1861 1861 sym->parent = sc->scopesym; 1862 1862 sc = sc->push(sym); … … 1873 1873 Expression *semanticLength(Scope *sc, TupleDeclaration *s, Expression *exp) 1874 1874 { 1875 ScopeDsymbol *sym = new ArrayScopeSymbol(s );1875 ScopeDsymbol *sym = new ArrayScopeSymbol(sc, s); 1876 1876 sym->parent = sc->scopesym; 1877 1877 sc = sc->push(sym); … … 1899 1899 if (td) 1900 1900 { 1901 ScopeDsymbol *sym = new ArrayScopeSymbol( td);1901 ScopeDsymbol *sym = new ArrayScopeSymbol(sc, td); 1902 1902 sym->parent = sc->scopesym; 1903 1903 sc = sc->push(sym); … … 2441 2441 index = index->semantic(loc,sc); 2442 2442 2443 index = index->constOf()->mutableOf(); 2443 if (index->nextOf() && !index->nextOf()->isInvariant()) 2444 { 2445 index = index->constOf()->mutableOf(); 2446 } 2444 2447 2445 2448 switch (index->toBasetype()->ty) … … 3052 3055 3053 3056 if (arg->storageClass & STCconst) 3054 arg->type = arg->type->constOf(); 3057 { if (arg->type->nextOf() && arg->type->nextOf()->isInvariant()) 3058 arg->storageClass &= ~STCconst; 3059 else 3060 arg->type = arg->type->constOf(); 3061 } 3055 3062 else if (arg->storageClass & STCinvariant) 3056 3063 arg->type = arg->type->invariantOf(); … … 4466 4473 return; 4467 4474 } 4468 buf->writestring(sym->toChars()); 4475 TemplateInstance *ti = sym->parent->isTemplateInstance(); 4476 if (ti && ti->toAlias() == sym) 4477 buf->writestring(ti->toChars()); 4478 else 4479 buf->writestring(sym->toChars()); 4469 4480 } 4470 4481 … … 5321 5332 /* It's a slice of a TupleDeclaration 5322 5333 */ 5323 ScopeDsymbol *sym = new ArrayScopeSymbol( td);5334 ScopeDsymbol *sym = new ArrayScopeSymbol(sc, td); 5324 5335 sym->parent = sc->scopesym; 5325 5336 sc = sc->push(sym); … … 5468 5479 buf->writestring((global.params.Dversion == 1) 5469 5480 ? (char *)"inout " : (char *)"ref "); 5481 else if (arg->storageClass & STCin) 5482 buf->writestring("in "); 5470 5483 else if (arg->storageClass & STClazy) 5471 5484 buf->writestring("lazy "); 5485 if (arg->storageClass & STCconst) 5486 buf->writestring("const "); 5487 if (arg->storageClass & STCinvariant) 5488 buf->writestring("invariant "); 5472 5489 argbuf.reset(); 5473 5490 arg->type->toCBuffer(&argbuf, arg->ident, hgs); branches/dmdfe-2.0/template.c
r836 r837 204 204 void ObjectToCBuffer(OutBuffer *buf, HdrGenState *hgs, Object *oarg) 205 205 { 206 //printf("ObjectToCBuffer()\n"); 206 207 Type *t = isType(oarg); 207 208 Expression *e = isExpression(oarg); … … 209 210 Tuple *v = isTuple(oarg); 210 211 if (t) 212 { //printf("\tt: %s ty = %d\n", t->toChars(), t->ty); 211 213 t->toCBuffer(buf, NULL, hgs); 214 } 212 215 else if (e) 213 216 e->toCBuffer(buf, hgs); … … 474 477 //printf("\targument [%d]\n", i); 475 478 #if 0 476 printf("\targument [%d] is %s\n", i, oarg ? oarg->toChars() : "null");479 //printf("\targument [%d] is %s\n", i, oarg ? oarg->toChars() : "null"); 477 480 TemplateTypeParameter *ttp = tp->isTemplateTypeParameter(); 478 481 if (ttp) … … 950 953 } 951 954 955 /*********************************** 956 * We can overload templates. 957 */ 958 959 int TemplateDeclaration::isOverloadable() 960 { 961 return 1; 962 } 963 952 964 /************************************************* 953 965 * Given function arguments, figure out which template function … … 957 969 * targsi initial list of template arguments 958 970 * fargs arguments to function 971 * flags 1: do not issue error message on no match, just return NULL 959 972 */ 960 973 961 974 FuncDeclaration *TemplateDeclaration::deduce(Scope *sc, Loc loc, 962 Objects *targsi, Expressions *fargs )975 Objects *targsi, Expressions *fargs, int flags) 963 976 { 964 977 MATCH m_best = MATCHnomatch; … … 1045 1058 if (!td_best) 1046 1059 { 1047 error(loc, "does not match any template declaration"); 1060 if (!(flags & 1)) &
