Mercurial > projects > ldc
diff dmd/opover.c @ 1587:def7a1d494fd
Merge DMD 1.051
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Fri, 06 Nov 2009 23:58:01 +0100 |
parents | 78038e540342 |
children | 207a8a438dea |
line wrap: on
line diff
--- a/dmd/opover.c Fri Nov 06 21:51:41 2009 +0100 +++ b/dmd/opover.c Fri Nov 06 23:58:01 2009 +0100 @@ -1,6 +1,6 @@ // Compiler implementation of the D programming language -// Copyright (c) 1999-2007 by Digital Mars +// Copyright (c) 1999-2009 by Digital Mars // All Rights Reserved // written by Walter Bright // http://www.digitalmars.com @@ -33,7 +33,7 @@ static Expression *build_overload(Loc loc, Scope *sc, Expression *ethis, Expression *earg, Identifier *id); static void inferApplyArgTypesX(Module* from, FuncDeclaration *fstart, Arguments *arguments); static int inferApplyArgTypesY(TypeFunction *tf, Arguments *arguments); -static void templateResolve(Match *m, TemplateDeclaration *td, Scope *sc, Loc loc, Objects *targsi, Expressions *arguments); +static void templateResolve(Match *m, TemplateDeclaration *td, Scope *sc, Loc loc, Objects *targsi, Expression *ethis, Expressions *arguments); /******************************** Expression **************************/ @@ -158,6 +158,7 @@ Expression *UnaExp::op_overload(Scope *sc) { + //printf("UnaExp::op_overload() (%s)\n", toChars()); AggregateDeclaration *ad; Dsymbol *fd; Type *t1 = e1->type->toBasetype(); @@ -177,10 +178,11 @@ { if (op == TOKarray) { - Expression *e; + /* Rewrite op e1[arguments] as: + * e1.fd(arguments) + */ + Expression *e = new DotIdExp(loc, e1, fd->ident); ArrayExp *ae = (ArrayExp *)this; - - e = new DotIdExp(loc, e1, fd->ident); e = new CallExp(loc, e, ae->arguments); e = e->semantic(sc); return e; @@ -191,6 +193,21 @@ return build_overload(loc, sc, e1, NULL, fd->ident); } } + +#if DMDV2 + // Didn't find it. Forward to aliasthis + if (ad->aliasthis) + { + /* Rewrite op(e1) as: + * op(e1.aliasthis) + */ + Expression *e1 = new DotIdExp(loc, this->e1, ad->aliasthis->ident); + Expression *e = copy(); + ((UnaExp *)e)->e1 = e1; + e = e->semantic(sc); + return e; + } +#endif } return NULL; } @@ -264,11 +281,11 @@ fd = s->isFuncDeclaration(); if (fd) { - overloadResolveX(&m, fd, &args2, sc->module); + overloadResolveX(&m, fd, NULL, &args2, sc->module); } else { td = s->isTemplateDeclaration(); - templateResolve(&m, td, sc, loc, NULL, &args2); + templateResolve(&m, td, sc, loc, NULL, NULL, &args2); } } @@ -279,11 +296,11 @@ fd = s_r->isFuncDeclaration(); if (fd) { - overloadResolveX(&m, fd, &args1, sc->module); + overloadResolveX(&m, fd, NULL, &args1, sc->module); } else { td = s_r->isTemplateDeclaration(); - templateResolve(&m, td, sc, loc, NULL, &args1); + templateResolve(&m, td, sc, loc, NULL, NULL, &args1); } } @@ -335,7 +352,6 @@ * b.opfunc(a) * and see which is better. */ - Expression *e; FuncDeclaration *lastf; if (!argsset) @@ -353,11 +369,11 @@ fd = s_r->isFuncDeclaration(); if (fd) { - overloadResolveX(&m, fd, &args2, sc->module); + overloadResolveX(&m, fd, NULL, &args2, sc->module); } else { td = s_r->isTemplateDeclaration(); - templateResolve(&m, td, sc, loc, NULL, &args2); + templateResolve(&m, td, sc, loc, NULL, NULL, &args2); } } lastf = m.lastf; @@ -367,11 +383,11 @@ fd = s->isFuncDeclaration(); if (fd) { - overloadResolveX(&m, fd, &args1, sc->module); + overloadResolveX(&m, fd, NULL, &args1, sc->module); } else { td = s->isTemplateDeclaration(); - templateResolve(&m, td, sc, loc, NULL, &args1); + templateResolve(&m, td, sc, loc, NULL, NULL, &args1); } } @@ -388,6 +404,7 @@ m.lastf = m.anyf; } + Expression *e; if (lastf && m.lastf == lastf || id_r && m.last == MATCHnomatch) // Rewrite (e1 op e2) as e1.opfunc_r(e2) @@ -423,6 +440,33 @@ } } +#if DMDV2 + // Try alias this on first operand + if (ad1 && ad1->aliasthis) + { + /* Rewrite (e1 op e2) as: + * (e1.aliasthis op e2) + */ + Expression *e1 = new DotIdExp(loc, this->e1, ad1->aliasthis->ident); + Expression *e = copy(); + ((BinExp *)e)->e1 = e1; + e = e->semantic(sc); + return e; + } + + // Try alias this on second operand + if (ad2 && ad2->aliasthis) + { + /* Rewrite (e1 op e2) as: + * (e1 op e2.aliasthis) + */ + Expression *e2 = new DotIdExp(loc, this->e2, ad2->aliasthis->ident); + Expression *e = copy(); + ((BinExp *)e)->e2 = e2; + e = e->semantic(sc); + return e; + } +#endif return NULL; } @@ -430,7 +474,7 @@ * Utility to build a function call out of this reference and argument. */ -static Expression *build_overload(Loc loc, Scope *sc, Expression *ethis, Expression *earg, Identifier *id) +Expression *build_overload(Loc loc, Scope *sc, Expression *ethis, Expression *earg, Identifier *id) { Expression *e; @@ -499,7 +543,6 @@ } AggregateDeclaration *ad; - FuncDeclaration *fd; Argument *arg = (Argument *)arguments->data[0]; Type *taggr = aggr->type; @@ -570,7 +613,7 @@ : Id::apply); if (s) { - fd = s->isFuncDeclaration(); + FuncDeclaration *fd = s->isFuncDeclaration(); if (fd) inferApplyArgTypesX(from, fd, arguments); } @@ -582,7 +625,7 @@ if (0 && aggr->op == TOKdelegate) { DelegateExp *de = (DelegateExp *)aggr; - fd = de->func->isFuncDeclaration(); + FuncDeclaration *fd = de->func->isFuncDeclaration(); if (fd) inferApplyArgTypesX(from, fd, arguments); } @@ -719,7 +762,7 @@ /************************************** */ -static void templateResolve(Match *m, TemplateDeclaration *td, Scope *sc, Loc loc, Objects *targsi, Expressions *arguments) +static void templateResolve(Match *m, TemplateDeclaration *td, Scope *sc, Loc loc, Objects *targsi, Expression *ethis, Expressions *arguments) { FuncDeclaration *fd;