Mercurial > projects > ddmd
diff dmd/SwitchStatement.d @ 162:438eaa11eed4
updated build script to use dmd2.039
some missing methods implemented
author | korDen |
---|---|
date | Tue, 21 Sep 2010 14:59:56 +0400 |
parents | af1bebfd96a4 |
children | af724d3510d7 |
line wrap: on
line diff
--- a/dmd/SwitchStatement.d Mon Sep 20 01:19:36 2010 +0400 +++ b/dmd/SwitchStatement.d Tue Sep 21 14:59:56 2010 +0400 @@ -3,6 +3,7 @@ import dmd.common; import dmd.Statement; import dmd.Expression; +import dmd.GlobalExpressions; import dmd.DefaultStatement; import dmd.TryFinallyStatement; import dmd.Array; @@ -33,6 +34,7 @@ import dmd.TypeTypedef; import dmd.TOK; import dmd.StringExp; +import dmd.expression.Equal; import dmd.backend.Util; import dmd.backend.block; @@ -245,7 +247,60 @@ override Expression interpret(InterState istate) { - assert(false); +version (LOG) { + printf("SwitchStatement.interpret()\n"); +} + if (istate.start == this) + istate.start = null; + Expression e = null; + + if (istate.start) + { + e = body_ ? body_.interpret(istate) : null; + if (istate.start) + return null; + if (e is EXP_CANT_INTERPRET) + return e; + if (e is EXP_BREAK_INTERPRET) + return null; + return e; + } + + + Expression econdition = condition.interpret(istate); + if (econdition is EXP_CANT_INTERPRET) + return EXP_CANT_INTERPRET; + + Statement s = null; + if (cases) + { + for (size_t i = 0; i < cases.dim; i++) + { + CaseStatement cs = cast(CaseStatement)cases.data[i]; + e = Equal(TOKequal, Type.tint32, econdition, cs.exp); + if (e is EXP_CANT_INTERPRET) + return EXP_CANT_INTERPRET; + if (e.isBool(true)) + { + s = cs; + break; + } + } + } + if (!s) + { + if (hasNoDefault) + error("no default or case for %s in switch statement", econdition.toChars()); + s = sdefault; + } + + assert(s); + istate.start = s; + e = body_ ? body_.interpret(istate) : null; + assert(!istate.start); + if (e is EXP_BREAK_INTERPRET) + return null; + return e; } override void toCBuffer(OutBuffer buf, HdrGenState* hgs)