Mercurial > projects > ddmd
diff dmd/ArrayLengthExp.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | e28b18c23469 |
children | 438eaa11eed4 |
line wrap: on
line diff
--- a/dmd/ArrayLengthExp.d Sun Sep 05 15:32:22 2010 +0400 +++ b/dmd/ArrayLengthExp.d Thu Sep 09 22:51:44 2010 +0100 @@ -2,6 +2,7 @@ import dmd.common; import dmd.Expression; +import dmd.BinExp; import dmd.backend.elem; import dmd.UnaExp; import dmd.InterState; @@ -13,6 +14,16 @@ import dmd.TOK; import dmd.Type; import dmd.WANT; +import dmd.VarExp; +import dmd.VarDeclaration; +import dmd.PtrExp; +import dmd.Lexer; +import dmd.Identifier; +import dmd.ExpInitializer; +import dmd.DeclarationExp; +import dmd.CommaExp; +import dmd.AssignExp; +import dmd.AddrExp; import dmd.expression.ArrayLength; @@ -28,8 +39,6 @@ override Expression semantic(Scope sc) { - Expression e; - version (LOGSEMANTIC) { printf("ArrayLengthExp::semantic('%s')\n", toChars()); } @@ -43,6 +52,35 @@ return this; } + static Expression rewriteOpAssign(BinExp exp) + { + Expression e; + + assert(exp.e1.op == TOKarraylength); + auto ale = cast(ArrayLengthExp)exp.e1; + if (ale.e1.op == TOK.TOKvar) + { + e = opAssignToOp(exp.loc, exp.op, ale, exp.e2); + e = new AssignExp(exp.loc, ale.syntaxCopy(), e); + } + else + { + /* auto tmp = &array; + * (*tmp).length = (*tmp).length op e2 + */ + Identifier id = Lexer.uniqueId("__arraylength"); + ExpInitializer ei = new ExpInitializer(ale.loc, new AddrExp(ale.loc, ale.e1)); + VarDeclaration tmp = new VarDeclaration(ale.loc, ale.e1.type.pointerTo(), id, ei); + + Expression e1 = new ArrayLengthExp(ale.loc, new PtrExp(ale.loc, new VarExp(ale.loc, tmp))); + Expression elvalue = e1.syntaxCopy(); + e = opAssignToOp(exp.loc, exp.op, e1, exp.e2); + e = new AssignExp(exp.loc, elvalue, e); + e = new CommaExp(exp.loc, new DeclarationExp(ale.loc, tmp), e); + } + return e; + } + override Expression optimize(int result) { //printf("ArrayLengthExp::optimize(result = %d) %s\n", result, toChars());