Mercurial > projects > ddmd
diff dmd/CommaExp.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | 51605de93870 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmd/CommaExp.d Sat Oct 24 08:42:06 2009 +0400 @@ -0,0 +1,123 @@ +module dmd.CommaExp; + +import dmd.Loc; +import dmd.BinExp; +import dmd.IRState; +import dmd.Scope; +import dmd.IntRange; +import dmd.Expression; +import dmd.MATCH; +import dmd.WANT; +import dmd.TOK; +import dmd.Type; +import dmd.InterState; + +import dmd.backend.elem; +import dmd.backend.Util; + +class CommaExp : BinExp +{ + this(Loc loc, Expression e1, Expression e2) + { + super(loc, TOK.TOKcomma, CommaExp.sizeof, e1, e2); + } + + Expression semantic(Scope sc) + { + if (!type) + { + BinExp.semanticp(sc); + type = e2.type; + } + return this; + } + + void checkEscape() + { + e2.checkEscape(); + } + + IntRange getIntRange() + { + assert(false); + } + +version (DMDV2) { + int isLvalue() + { + return e2.isLvalue(); + } +} + Expression toLvalue(Scope sc, Expression e) + { + e2 = e2.toLvalue(sc, null); + return this; + } + + Expression modifiableLvalue(Scope sc, Expression e) + { + e2 = e2.modifiableLvalue(sc, e); + return this; + } + + bool isBool(bool result) + { + return e2.isBool(result); + } + + bool checkSideEffect(int flag) + { + if (flag == 2) + return e1.checkSideEffect(2) || e2.checkSideEffect(2); + else + { + // Don't check e1 until we cast(void) the a,b code generation + return e2.checkSideEffect(flag); + } + } + + MATCH implicitConvTo(Type t) + { + assert(false); + } + + Expression castTo(Scope sc, Type t) + { + assert(false); + } + + Expression optimize(int result) + { + Expression e; + + //printf("CommaExp.optimize(result = %d) %s\n", result, toChars()); + e1 = e1.optimize(result & WANTinterpret); + e2 = e2.optimize(result); + if (!e1 || e1.op == TOKint64 || e1.op == TOKfloat64 || !e1.checkSideEffect(2)) + { + e = e2; + if (e) + e.type = type; + } + else + e = this; + //printf("-CommaExp.optimize(result = %d) %s\n", result, e.toChars()); + return e; + } + + Expression interpret(InterState* istate) + { + assert(false); + } + + elem* toElem(IRState* irs) + { + assert(e1 && e2); + elem* eleft = e1.toElem(irs); + elem* eright = e2.toElem(irs); + elem* e = el_combine(eleft, eright); + if (e) + el_setLoc(e, loc); + return e; + } +} \ No newline at end of file