Changeset 837

Show
Ignore:
Timestamp:
11/17/07 17:25:07 (1 year ago)
Author:
Gregor
Message:

MERGE: DMD 2.006

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmdfe-2.0/cast.c

    r835 r837  
    484484    { 
    485485    // Look for pointers to functions where the functions are overloaded. 
    486     VarExp *ve; 
    487     FuncDeclaration *f; 
    488486 
    489487    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 
    490510    if (type->ty == Tpointer && type->nextOf()->ty == Tfunction && 
    491511        t->ty == Tpointer && t->nextOf()->ty == Tfunction && 
     
    497517         */ 
    498518        assert(0); 
    499         ve = (VarExp *)e1; 
    500         f = ve->var->isFuncDeclaration(); 
     519        VarExp *ve = (VarExp *)e1; 
     520        FuncDeclaration *f = ve->var->isFuncDeclaration(); 
    501521        if (f && f->overloadExactMatch(t->nextOf())) 
    502522        result = MATCHexact; 
     
    929949    { 
    930950    // 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 
    933978 
    934979    if (type->ty == Tpointer && type->nextOf()->ty == Tfunction && 
     
    936981        e1->op == TOKvar) 
    937982    { 
    938         ve = (VarExp *)e1; 
    939         f = ve->var->isFuncDeclaration(); 
     983        VarExp *ve = (VarExp *)e1; 
     984        FuncDeclaration *f = ve->var->isFuncDeclaration(); 
    940985        if (f) 
    941986        { 
     987        assert(0);  // should be SymOffExp instead 
    942988        f = f->overloadExactMatch(tb->nextOf()); 
    943989        if (f) 
     
    12721318    if ((t1->ty == Tsarray || t1->ty == Tarray) && 
    12731319        (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       ) 
    12751323    { 
    12761324        t1 = t1->constOf(); 
  • branches/dmdfe-2.0/class.c

    r836 r837  
    817817    return 0; 
    818818    } 
    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    } 
    822837} 
    823838#endif 
  • branches/dmdfe-2.0/declaration.c

    r836 r837  
    446446    { 
    447447    // Try to convert Expression to Dsymbol 
    448         if (e->op == TOKvar) 
    449     {   s = ((VarExp *)e)->var; 
     448    s = getDsymbol(e); 
     449    if (s) 
    450450        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; 
    460454    } 
    461455    else if (t) 
     
    651645    //printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars()); 
    652646    //printf(" type = %s\n", type->toChars()); 
     647    //printf("stc = x%x\n", sc->stc); 
    653648    //printf("linkage = %d\n", sc->linkage); 
    654649    //if (strcmp(toChars(), "mul") == 0) halt(); 
     
    748743    } 
    749744 
     745Lagain: 
    750746    if (isConst()) 
    751747    { 
     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    } 
    752758    type = type->constOf(); 
    753759    if (isParameter()) 
  • branches/dmdfe-2.0/declaration.h

    r836 r837  
    461461    int overloadInsert(Dsymbol *s); 
    462462    FuncDeclaration *overloadExactMatch(Type *t); 
    463     FuncDeclaration *overloadResolve(Loc loc, Expressions *arguments); 
     463    FuncDeclaration *overloadResolve(Loc loc, Expressions *arguments, int flags = 0); 
    464464    LabelDsymbol *searchLabel(Identifier *ident); 
    465465    AggregateDeclaration *isThis(); 
     
    476476    int isAbstract(); 
    477477    int isCodeseg(); 
     478    int isOverloadable(); 
    478479    virtual int isNested(); 
    479480    int needThis(); 
  • branches/dmdfe-2.0/dsymbol.c

    r835 r837  
    383383} 
    384384 
     385int Dsymbol::isOverloadable() 
     386{ 
     387    return 0; 
     388} 
     389 
    385390LabelDsymbol *Dsymbol::isLabel()        // is this a LabelDsymbol()? 
    386391{ 
     
    581586    } 
    582587#endif 
     588} 
     589 
     590/********************************* OverloadSet ****************************/ 
     591 
     592OverloadSet::OverloadSet() 
     593    : Dsymbol() 
     594{ 
     595} 
     596 
     597void OverloadSet::push(Dsymbol *s) 
     598{ 
     599    a.push(s); 
     600} 
     601 
     602char *OverloadSet::kind() 
     603{ 
     604    return "overloadset"; 
    583605} 
    584606 
     
    618640 
    619641Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags) 
    620 {   Dsymbol *s; 
    621     int i; 
    622  
     642
    623643    //printf("%s->ScopeDsymbol::search(ident='%s', flags=x%x)\n", toChars(), ident->toChars(), flags); 
     644 
    624645    // Look in symbols declared in this module 
    625     s = symtab ? symtab->lookup(ident) : NULL; 
     646    Dsymbol *s = symtab ? symtab->lookup(ident) : NULL; 
    626647    if (s) 
    627648    { 
     
    630651    else if (imports) 
    631652    { 
     653    OverloadSet *a = NULL; 
     654 
    632655    // Look in imported modules 
    633     for (i = 0; i < imports->dim; i++) 
     656    for (int i = 0; i < imports->dim; i++) 
    634657    {   ScopeDsymbol *ss = (ScopeDsymbol *)imports->data[i]; 
    635658        Dsymbol *s2; 
     
    640663 
    641664        //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         */ 
    642667        s2 = ss->search(loc, ident, ss->isModule() ? 1 : 0); 
    643668        if (!s) 
     
    647672        if (s->toAlias() == s2->toAlias()) 
    648673        { 
     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             */ 
    649678            if (s->isDeprecated()) 
    650679            s = s2; 
     
    665694               ) 
    666695            { 
    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 
    668718                return NULL; 
    669719            if (!(flags & 2)) 
     
    674724        } 
    675725    } 
     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 
    676735    if (s) 
    677736    { 
    678737        Declaration *d = s->isDeclaration(); 
    679         if (d && d->protection == PROTprivate && !d->parent->isTemplateMixin() && 
     738        if (d && d->protection == PROTprivate && 
     739        !d->parent->isTemplateMixin() && 
    680740        !(flags & 2)) 
    681741        error("%s is private", d->toPrettyChars()); 
     
    832892/****************************** ArrayScopeSymbol ******************************/ 
    833893 
    834 ArrayScopeSymbol::ArrayScopeSymbol(Expression *e) 
     894ArrayScopeSymbol::ArrayScopeSymbol(Scope *sc, Expression *e) 
    835895    : ScopeDsymbol() 
    836896{ 
     
    839899    type = NULL; 
    840900    td = NULL; 
    841 
    842  
    843 ArrayScopeSymbol::ArrayScopeSymbol(TypeTuple *t) 
     901    this->sc = sc; 
     902
     903 
     904ArrayScopeSymbol::ArrayScopeSymbol(Scope *sc, TypeTuple *t) 
    844905    : ScopeDsymbol() 
    845906{ 
     
    847908    type = t; 
    848909    td = NULL; 
    849 
    850  
    851 ArrayScopeSymbol::ArrayScopeSymbol(TupleDeclaration *s) 
     910    this->sc = sc; 
     911
     912 
     913ArrayScopeSymbol::ArrayScopeSymbol(Scope *sc, TupleDeclaration *s) 
    852914    : ScopeDsymbol() 
    853915{ 
     
    855917    type = NULL; 
    856918    td = s; 
     919    this->sc = sc; 
    857920} 
    858921 
     
    872935        v->init = new ExpInitializer(0, e); 
    873936        v->storage_class |= STCconst; 
     937        v->semantic(sc); 
    874938        return v; 
    875939    } 
     
    881945        v->init = new ExpInitializer(0, e); 
    882946        v->storage_class |= STCconst; 
     947        v->semantic(sc); 
    883948        return v; 
    884949    } 
     
    9451010        *pvar = v; 
    9461011    } 
     1012    (*pvar)->semantic(sc); 
    9471013    return (*pvar); 
    9481014    } 
  • branches/dmdfe-2.0/dsymbol.h

    r836 r837  
    6767struct DeleteDeclaration; 
    6868struct HdrGenState; 
     69struct OverloadSet; 
    6970 
    7071#if IN_GCC 
     
    141142    virtual ClassDeclaration *isClassMember();  // are we a member of a class? 
    142143    virtual int isExport();         // is Dsymbol exported? 
    143     virtual int isImportedSymbol();        // is Dsymbol imported? 
     144    virtual int isImportedSymbol();     // is Dsymbol imported? 
    144145    virtual int isDeprecated();         // is Dsymbol deprecated? 
     146    virtual int isOverloadable(); 
    145147    virtual LabelDsymbol *isLabel();        // is this a LabelDsymbol? 
    146148    virtual AggregateDeclaration *isMember();   // is this symbol a member of an AggregateDeclaration? 
     
    204206    virtual SymbolDeclaration *isSymbolDeclaration() { return NULL; } 
    205207    virtual AttribDeclaration *isAttribDeclaration() { return NULL; } 
     208    virtual OverloadSet *isOverloadSet() { return NULL; } 
    206209}; 
    207210 
     
    256259    TypeTuple *type;    // for tuple[length] 
    257260    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); 
    262266    Dsymbol *search(Loc loc, Identifier *ident, int flags); 
    263267 
    264268    ArrayScopeSymbol *isArrayScopeSymbol() { return this; } 
     269}; 
     270 
     271// Overload Sets 
     272 
     273struct 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(); 
    265281}; 
    266282 
  • branches/dmdfe-2.0/expression.c

    r836 r837  
    254254    Type *t = e->type->toBasetype(); 
    255255 
    256     if (t->ty == Tfunction
     256    if (t->ty == Tfunction || e->op == TOKoverloadset
    257257    { 
    258258        e = new CallExp(e->loc, e); 
     
    276276        e->error("expression has no value"); 
    277277    } 
     278     
    278279    } 
    279280    return e; 
     
    711712{ 
    712713#if LOGSEMANTIC 
    713     printf("Expression::semantic()\n"); 
     714    printf("Expression::semantic() %s\n", toChars()); 
    714715#endif 
    715716    if (type) 
     
    10261027    if (type && !type->isscalar()) 
    10271028    { 
    1028     //printf("test1: %s, loc = %d\n", toChars(), loc.linnum); 
     1029    //printf("%s, loc = %d\n", toChars(), loc.linnum); 
    10291030    error("integral constant must be scalar type, not %s", type->toChars()); 
    10301031    type = Type::terror; 
     
    16301631    WithScopeSymbol *withsym; 
    16311632 
    1632     // See if it was a with class 
     1633    /* See if the symbol was a member of an enclosing 'with' 
     1634     */ 
    16331635    withsym = scopesym->isWithScopeSymbol(); 
    16341636    if (withsym) 
     
    16511653    else 
    16521654    { 
    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         */ 
    16601658        FuncDeclaration *f = s->isFuncDeclaration(); 
    16611659        if (f && f->parent) 
     
    16771675        } 
    16781676        } 
    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); 
    16881679    } 
    16891680    return e->semantic(sc); 
     
    17281719/******************************** DsymbolExp **************************/ 
    17291720 
    1730 DsymbolExp::DsymbolExp(Loc loc, Dsymbol *s
     1721DsymbolExp::DsymbolExp(Loc loc, Dsymbol *s, int hasOverloads
    17311722    : Expression(loc, TOKdsymbol, sizeof(DsymbolExp)) 
    17321723{ 
    17331724    this->s = s; 
     1725    this->hasOverloads = hasOverloads; 
    17341726} 
    17351727 
     
    17461738    FuncDeclaration *f; 
    17471739    FuncLiteralDeclaration *fld; 
     1740    OverloadSet *o; 
    17481741    Declaration *d; 
    17491742    ClassDeclaration *cd; 
     
    18001793        } 
    18011794    } 
    1802 #if 0 
    1803     if ((v->isConst() || v->isInvariant()) && type->toBasetype()->ty != Tsarray) 
    1804     {   // Replace v with its initializer 
    1805         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 loc 
    1817             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         else 
    1825         { 
    1826         e = type->defaultInit(); 
    1827         e->loc = loc; 
    1828         return e; 
    1829         } 
    1830     } 
    1831 #endif 
    18321795    e = new VarExp(loc, v); 
    18331796    e->type = type; 
     
    18441807    if (f) 
    18451808    {   //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); 
    18471815    } 
    18481816    cd = s->isClassDeclaration(); 
     
    36463614 
    36473615 
     3616/******************************** OverExp **************************/ 
     3617 
     3618OverExp::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 
     3626Expression *OverExp::toLvalue(Scope *sc, Expression *e) 
     3627{ 
     3628    return this; 
     3629} 
     3630 
     3631 
    36483632/******************************** TupleExp **************************/ 
    36493633 
     
    58235807    } 
    58245808    } 
     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    } 
    58255844    else if (!t1) 
    58265845    { 
     
    58785897    f = ve->var->isFuncDeclaration(); 
    58795898    assert(f); 
    5880  
    5881     // Look to see if f is really a function template 
    5882     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 enclosing 
    5892          * template, even if it has the same name as a member 
    5893          * 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's 
    5897             tempdecl = tempdecl->overroot; // then get the start 
    5898         e1 = new TemplateExp(loc, tempdecl); 
    5899         istemp = 1; 
    5900         goto Lagain; 
    5901         } 
    5902     } 
    59035899 
    59045900    if (ve->hasOverloads) 
     
    65576553    if (t->ty == Tsarray || t->ty == Tarray || t->ty == Ttuple) 
    65586554    { 
    6559     sym = new ArrayScopeSymbol(this); 
     6555    sym = new ArrayScopeSymbol(sc, this); 
    65606556    sym->loc = loc; 
    65616557    sym->parent = sc->scopesym; 
     
    66316627    } 
    66326628 
    6633     type = ((TypeNext *)t)->next->arrayOf(); 
     6629    type = t->nextOf()->arrayOf(); 
    66346630    return e; 
    66356631 
     
    68976893    if (t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Ttuple) 
    68986894    {   // Create scope for 'length' variable 
    6899     sym = new ArrayScopeSymbol(this); 
     6895    sym = new ArrayScopeSymbol(sc, this); 
    69006896    sym->loc = loc; 
    69016897    sym->parent = sc->scopesym; 
     
    70827078 
    70837079#if LOGSEMANTIC 
    7084     printf("AssignExp::semantic('%s')\n", toChars()); 
     7080    //printf("AssignExp::semantic('%s')\n", toChars()); 
    70857081#endif 
    70867082    //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)); 
    70877084 
    70887085    /* Look for operator overloading of a[i]=value. 
     
    71787175    e2 = resolveProperties(sc, e2); 
    71797176    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    } 
    71807202 
    71817203    t1 = e1->type->toBasetype(); 
     
    79247946 
    79257947    typeCombine(sc); 
     7948//type->print(); 
    79267949    type = type->mutableOf(); 
     7950//printf("test1\n"); 
     7951//type->print(); 
    79277952 
    79287953    Type *tb = type->toBasetype(); 
    79297954    if (tb->ty == Tsarray) 
    79307955        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) 
    79327959        type = type->nextOf()->toCanonConst()->arrayOf(); 
     7960//printf("test3\n"); 
     7961//type->print(); 
    79337962#if 0 
    79347963    e1->type->print(); 
  • branches/dmdfe-2.0/expression.h

    r836 r837  
    4444struct InterState; 
    4545struct Symbol;      // back end symbol 
     46struct OverloadSet; 
    4647 
    4748enum TOK; 
     
    231232{ 
    232233    Dsymbol *s; 
    233  
    234     DsymbolExp(Loc loc, Dsymbol *s); 
     234    int hasOverloads; 
     235 
     236    DsymbolExp(Loc loc, Dsymbol *s, int hasOverloads = 0); 
    235237    Expression *semantic(Scope *sc); 
    236238    char *toChars(); 
     
    326328    Expression *interpret(InterState *istate); 
    327329    Expression *castTo(Scope *sc, Type *t); 
     330    elem *toElem(IRState *irs); 
    328331 
    329332    int inlineCost(InlineCostState *ics); 
     
    537540    //Expression *inlineScan(InlineScanState *iss); 
    538541}; 
     542 
     543// Overload Set 
     544 
     545struct OverExp : Expression 
     546{ 
     547    OverloadSet *vars; 
     548 
     549    OverExp(OverloadSet *s); 
     550    Expression *toLvalue(Scope *sc, Expression *e); 
     551}; 
     552 
    539553 
    540554// Function/Delegate literal 
  • branches/dmdfe-2.0/func.c

    r836 r837  
    15041504 
    15051505 
    1506 FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expressions *arguments
     1506FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expressions *arguments, int flags
    15071507{ 
    15081508    TypeFunction *tf; 
     
    15461546    if (m.last == MATCHnomatch) 
    15471547    { 
     1548        if (flags & 1)      // if do not print error messages 
     1549        return NULL;        // no match 
     1550 
    15481551        tf = (TypeFunction *)type; 
    15491552 
     
    17741777} 
    17751778 
     1779int FuncDeclaration::isOverloadable() 
     1780{ 
     1781    return 1;           // functions can be overloaded 
     1782} 
     1783 
    17761784// Determine if function needs 
    17771785// a static frame pointer to its lexically enclosing function 
  • branches/dmdfe-2.0/lexer.c

    r835 r837  
    28872887#if V2 
    28882888    {   "__traits", TOKtraits   }, 
     2889    {   "__overloadset", TOKoverloadset }, 
    28892890#endif 
    28902891}; 
  • branches/dmdfe-2.0/lexer.h

    r835 r837  
    153153#if V2 
    154154    TOKtraits, 
     155    TOKoverloadset, 
    155156#endif 
    156157 
  • branches/dmdfe-2.0/mars.c

    r836 r837  
    5656    copyright = "Copyright (c) 1999-2007 by Digital Mars"; 
    5757    written = "written by Walter Bright"; 
    58     version = "v2.005"; 
     58    version = "v2.006"; 
    5959    global.structalign = 8; 
    6060 
     
    110110    fprintf(stdmsg, "\n"); 
    111111    fflush(stdmsg); 
    112 //halt(); 
     112halt(); 
    113113    } 
    114114    global.errors++; 
  • branches/dmdfe-2.0/mtype.c

    r836 r837  
    370370    if (ty == Tsarray) 
    371371    {   TypeSArray *ta = (TypeSArray *)t; 
    372         ta->next = ta->next->mutableOf(); 
     372        //ta->next = ta->next->mutableOf(); 
    373373    } 
    374374    t = t->merge(); 
     
    18581858{ 
    18591859    if (t->ty == Ttuple) 
    1860     {   ScopeDsymbol *sym = new ArrayScopeSymbol((TypeTuple *)t); 
     1860    {   ScopeDsymbol *sym = new ArrayScopeSymbol(sc, (TypeTuple *)t); 
    18611861    sym->parent = sc->scopesym; 
    18621862    sc = sc->push(sym); 
     
    18731873Expression *semanticLength(Scope *sc, TupleDeclaration *s, Expression *exp) 
    18741874{ 
    1875     ScopeDsymbol *sym = new ArrayScopeSymbol(s); 
     1875    ScopeDsymbol *sym = new ArrayScopeSymbol(sc, s); 
    18761876    sym->parent = sc->scopesym; 
    18771877    sc = sc->push(sym); 
     
    18991899    if (td) 
    19001900    { 
    1901         ScopeDsymbol *sym = new ArrayScopeSymbol(td); 
     1901        ScopeDsymbol *sym = new ArrayScopeSymbol(sc, td); 
    19021902        sym->parent = sc->scopesym; 
    19031903        sc = sc->push(sym); 
     
    24412441    index = index->semantic(loc,sc); 
    24422442 
    2443     index = index->constOf()->mutableOf(); 
     2443    if (index->nextOf() && !index->nextOf()->isInvariant()) 
     2444    { 
     2445    index = index->constOf()->mutableOf(); 
     2446    } 
    24442447 
    24452448    switch (index->toBasetype()->ty) 
     
    30523055 
    30533056        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        } 
    30553062        else if (arg->storageClass & STCinvariant) 
    30563063        arg->type = arg->type->invariantOf(); 
     
    44664473    return; 
    44674474    } 
    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()); 
    44694480} 
    44704481 
     
    53215332        /* It's a slice of a TupleDeclaration 
    53225333         */ 
    5323         ScopeDsymbol *sym = new ArrayScopeSymbol(td); 
     5334        ScopeDsymbol *sym = new ArrayScopeSymbol(sc, td); 
    53245335        sym->parent = sc->scopesym; 
    53255336        sc = sc->push(sym); 
     
    54685479        buf->writestring((global.params.Dversion == 1) 
    54695480            ? (char *)"inout " : (char *)"ref "); 
     5481        else if (arg->storageClass & STCin) 
     5482        buf->writestring("in "); 
    54705483        else if (arg->storageClass & STClazy) 
    54715484        buf->writestring("lazy "); 
     5485        if (arg->storageClass & STCconst) 
     5486        buf->writestring("const "); 
     5487        if (arg->storageClass & STCinvariant) 
     5488        buf->writestring("invariant "); 
    54725489        argbuf.reset(); 
    54735490        arg->type->toCBuffer(&argbuf, arg->ident, hgs); 
  • branches/dmdfe-2.0/template.c

    r836 r837  
    204204void ObjectToCBuffer(OutBuffer *buf, HdrGenState *hgs, Object *oarg) 
    205205{ 
     206    //printf("ObjectToCBuffer()\n"); 
    206207    Type *t = isType(oarg); 
    207208    Expression *e = isExpression(oarg); 
     
    209210    Tuple *v = isTuple(oarg); 
    210211    if (t) 
     212    {   //printf("\tt: %s ty = %d\n", t->toChars(), t->ty); 
    211213    t->toCBuffer(buf, NULL, hgs); 
     214    } 
    212215    else if (e) 
    213216    e->toCBuffer(buf, hgs); 
     
    474477    //printf("\targument [%d]\n", i); 
    475478#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"); 
    477480    TemplateTypeParameter *ttp = tp->isTemplateTypeParameter(); 
    478481    if (ttp) 
     
    950953} 
    951954 
     955/*********************************** 
     956 * We can overload templates. 
     957 */ 
     958 
     959int TemplateDeclaration::isOverloadable() 
     960{ 
     961    return 1; 
     962} 
     963 
    952964/************************************************* 
    953965 * Given function arguments, figure out which template function 
     
    957969 *  targsi      initial list of template arguments 
    958970 *  fargs       arguments to function 
     971 *  flags       1: do not issue error message on no match, just return NULL 
    959972 */ 
    960973 
    961974FuncDeclaration *TemplateDeclaration::deduce(Scope *sc, Loc loc, 
    962     Objects *targsi, Expressions *fargs
     975    Objects *targsi, Expressions *fargs, int flags
    963976{ 
    964977    MATCH m_best = MATCHnomatch; 
     
    10451058    if (!td_best) 
    10461059    { 
    1047     error(loc, "does not match any template declaration"); 
     1060    if (!(flags & 1)) 
    &