Changeset 268

Show
Ignore:
Timestamp:
11/28/09 15:18:23 (2 years ago)
Author:
walter
Message:

implemented opDispatch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/idgen.c

    r257 r268  
    192192    { "orass",   "opOrAssign" }, 
    193193    { "xorass",  "opXorAssign" }, 
    194194    { "shlass",  "opShlAssign" }, 
    195195    { "shrass",  "opShrAssign" }, 
    196196    { "ushrass", "opUShrAssign" }, 
    197197    { "catass",  "opCatAssign" }, 
    198198    { "postinc", "opPostInc" }, 
    199199    { "postdec", "opPostDec" }, 
    200200    { "index",   "opIndex" }, 
    201201    { "indexass", "opIndexAssign" }, 
    202202    { "slice",   "opSlice" }, 
    203203    { "sliceass", "opSliceAssign" }, 
    204204    { "call",    "opCall" }, 
    205205    { "cast",    "opCast" }, 
    206206    { "match",   "opMatch" }, 
    207207    { "next",    "opNext" }, 
    208208    { "opIn" }, 
    209209    { "opIn_r" }, 
    210210    { "opStar" }, 
    211211    { "opDot" }, 
     212    { "opDispatch" }, 
    212213    { "opImplicitCast" }, 
    213214 
    214215    { "classNew", "new" }, 
    215216    { "classDelete", "delete" }, 
    216217 
    217218    // For foreach 
    218219    { "apply", "opApply" }, 
    219220    { "applyReverse", "opApplyReverse" }, 
    220221 
    221222#if 1 
    222223    { "Fempty", "empty" }, 
    223224    { "Fhead", "front" }, 
    224225    { "Ftoe", "back" }, 
    225226    { "Fnext", "popFront" }, 
    226227    { "Fretreat", "popBack" }, 
    227228#else 
    228229    { "Fempty", "empty" }, 
    229230    { "Fhead", "head" }, 
    230231    { "Ftoe", "toe" }, 
    231232    { "Fnext", "next" }, 
  • trunk/src/mtype.c

    r264 r268  
    59645964        ident != Id::stringof && 
    59655965        ident != Id::offsetof) 
    59665966    { 
    59675967        /* See if we should forward to the alias this. 
    59685968         */ 
    59695969        if (sym->aliasthis) 
    59705970        {   /* Rewrite e.ident as: 
    59715971         *  e.aliasthis.ident 
    59725972         */ 
    59735973        e = new DotIdExp(e->loc, e, sym->aliasthis->ident); 
    59745974        e = new DotIdExp(e->loc, e, ident); 
    59755975        return e->semantic(sc); 
    59765976        } 
    59775977 
    59785978        /* Look for overloaded opDot() to see if we should forward request 
    59795979         * to it. 
    59805980         */ 
    59815981        Dsymbol *fd = search_function(sym, Id::opDot); 
    59825982        if (fd) 
    59835983        {   /* Rewrite e.ident as: 
    5984          *  e.opId().ident 
     5984         *  e.opDot().ident 
    59855985         */ 
    59865986        e = build_overload(e->loc, sc, e, NULL, fd->ident); 
    59875987        e = new DotIdExp(e->loc, e, ident); 
     5988        return e->semantic(sc); 
     5989        } 
     5990 
     5991        /* Look for overloaded opDispatch to see if we should forward request 
     5992         * to it. 
     5993         */ 
     5994        fd = search_function(sym, Id::opDispatch); 
     5995        if (fd) 
     5996        { 
     5997        /* Rewrite e.ident as: 
     5998         *  e.opDispatch!("ident") 
     5999         */ 
     6000        TemplateDeclaration *td = fd->isTemplateDeclaration(); 
     6001        if (!td) 
     6002        { 
     6003            fd->error("must be a template opDispatch(string s), not a %s", fd->kind()); 
     6004            return new ErrorExp(); 
     6005        } 
     6006        StringExp *se = new StringExp(e->loc, ident->toChars()); 
     6007        TemplateInstance *ti = new TemplateInstance(e->loc, td->ident); 
     6008        Objects *tiargs = new Objects(); 
     6009        tiargs->push(se); 
     6010        ti->tiargs = tiargs; 
     6011        e = new DotTemplateInstanceExp(e->loc, e, ti); 
    59886012        return e->semantic(sc); 
    59896013        } 
    59906014    } 
    59916015    return Type::dotExp(sc, e, ident); 
    59926016    } 
    59936017    if (!s->isFuncDeclaration())    // because of overloading 
    59946018    s->checkDeprecated(e->loc, sc); 
    59956019    s = s->toAlias(); 
    59966020 
    59976021    v = s->isVarDeclaration(); 
    59986022    if (v && !v->isDataseg()) 
    59996023    { 
    60006024    Expression *ei = v->getConstInitializer(); 
    60016025    if (ei) 
    60026026    {   e = ei->copy(); // need to copy it if it's a StringExp 
    60036027        e = e->semantic(sc); 
    60046028        return e; 
    60056029    } 
    60066030    } 
    60076031 
     
    64556479        ident != Id::stringof && 
    64566480        ident != Id::offsetof) 
    64576481        { 
    64586482        /* See if we should forward to the alias this. 
    64596483         */ 
    64606484        if (sym->aliasthis) 
    64616485        {   /* Rewrite e.ident as: 
    64626486             *  e.aliasthis.ident 
    64636487             */ 
    64646488            e = new DotIdExp(e->loc, e, sym->aliasthis->ident); 
    64656489            e = new DotIdExp(e->loc, e, ident); 
    64666490            return e->semantic(sc); 
    64676491        } 
    64686492 
    64696493        /* Look for overloaded opDot() to see if we should forward request 
    64706494         * to it. 
    64716495         */ 
    64726496        Dsymbol *fd = search_function(sym, Id::opDot); 
    64736497        if (fd) 
    64746498        {   /* Rewrite e.ident as: 
    6475              *  e.opId().ident 
     6499             *  e.opDot().ident 
    64766500             */ 
    64776501            e = build_overload(e->loc, sc, e, NULL, fd->ident); 
    64786502            e = new DotIdExp(e->loc, e, ident); 
     6503            return e->semantic(sc); 
     6504        } 
     6505 
     6506        /* Look for overloaded opDispatch to see if we should forward request 
     6507         * to it. 
     6508         */ 
     6509        fd = search_function(sym, Id::opDispatch); 
     6510        if (fd) 
     6511        { 
     6512            /* Rewrite e.ident as: 
     6513             *  e.opDispatch!("ident") 
     6514             */ 
     6515            TemplateDeclaration *td = fd->isTemplateDeclaration(); 
     6516            if (!td) 
     6517            { 
     6518            fd->error("must be a template opDispatch(string s), not a %s", fd->kind()); 
     6519            return new ErrorExp(); 
     6520            } 
     6521            StringExp *se = new StringExp(e->loc, ident->toChars()); 
     6522            TemplateInstance *ti = new TemplateInstance(e->loc, td->ident); 
     6523            Objects *tiargs = new Objects(); 
     6524            tiargs->push(se); 
     6525            ti->tiargs = tiargs; 
     6526            e = new DotTemplateInstanceExp(e->loc, e, ti); 
    64796527            return e->semantic(sc); 
    64806528        } 
    64816529        } 
    64826530 
    64836531        return Type::dotExp(sc, e, ident); 
    64846532    } 
    64856533    } 
    64866534    if (!s->isFuncDeclaration())    // because of overloading 
    64876535    s->checkDeprecated(e->loc, sc); 
    64886536    s = s->toAlias(); 
    64896537    v = s->isVarDeclaration(); 
    64906538    if (v && !v->isDataseg()) 
    64916539    {   Expression *ei = v->getConstInitializer(); 
    64926540 
    64936541    if (ei) 
    64946542    {   e = ei->copy(); // need to copy it if it's a StringExp 
    64956543        e = e->semantic(sc); 
    64966544        return e; 
    64976545    } 
    64986546    }