Changeset 268

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

implemented opDispatch

Files:

Legend:

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

    r257 r268  
    207207    { "next",    "opNext" }, 
    208208    { "opIn" }, 
    209209    { "opIn_r" }, 
    210210    { "opStar" }, 
    211211    { "opDot" }, 
     212    { "opDispatch" }, 
    212213    { "opImplicitCast" }, 
    213214 
    214215    { "classNew", "new" }, 
    215216    { "classDelete", "delete" }, 
    216217 
  • trunk/src/mtype.c

    r264 r268  
    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    } 
     
    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);