summaryrefslogtreecommitdiff
path: root/BCT
diff options
context:
space:
mode:
authorGravatar Unknown <mbarnett@MBARNETT-LAP2.redmond.corp.microsoft.com>2011-04-26 11:42:27 -0700
committerGravatar Unknown <mbarnett@MBARNETT-LAP2.redmond.corp.microsoft.com>2011-04-26 11:42:27 -0700
commite45880eaaae633b0d4627503d873433af9cb125b (patch)
treebdb7a08b012b3bf2a475c84aa65d46f469299e18 /BCT
parent85f5689fde9df72ea51c28e3c38e6eb4a462f2b6 (diff)
Add translation for conversion expressions, at least between bool and int.
Diffstat (limited to 'BCT')
-rw-r--r--BCT/BytecodeTranslator/ExpressionTraverser.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/BCT/BytecodeTranslator/ExpressionTraverser.cs b/BCT/BytecodeTranslator/ExpressionTraverser.cs
index a19bbedc..b077d66c 100644
--- a/BCT/BytecodeTranslator/ExpressionTraverser.cs
+++ b/BCT/BytecodeTranslator/ExpressionTraverser.cs
@@ -934,6 +934,42 @@ namespace BytecodeTranslator
return;
}
+ public override void Visit(IConversion conversion)
+ {
+ var tok = conversion.ValueToConvert.Token();
+ Visit(conversion.ValueToConvert);
+ var exp = TranslatedExpressions.Pop();
+ switch (conversion.TypeAfterConversion.TypeCode) {
+ case PrimitiveTypeCode.Int16:
+ case PrimitiveTypeCode.Int32:
+ case PrimitiveTypeCode.Int64:
+ case PrimitiveTypeCode.Int8:
+ switch (conversion.ValueToConvert.Type.TypeCode) {
+ case PrimitiveTypeCode.Boolean:
+ TranslatedExpressions.Push(
+ new Bpl.NAryExpr(tok, new Bpl.IfThenElse(tok), new Bpl.ExprSeq(exp, Bpl.Expr.Literal(1), Bpl.Expr.Literal(0)))
+ );
+ return;
+ default:
+ throw new NotImplementedException();
+ }
+ case PrimitiveTypeCode.Boolean:
+ switch (conversion.ValueToConvert.Type.TypeCode) {
+ case PrimitiveTypeCode.Int16:
+ case PrimitiveTypeCode.Int32:
+ case PrimitiveTypeCode.Int64:
+ case PrimitiveTypeCode.Int8:
+ TranslatedExpressions.Push(Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, exp, Bpl.Expr.Literal(0)));
+ return;
+ default:
+ throw new NotImplementedException();
+
+ }
+ default:
+ throw new NotImplementedException();
+ }
+ }
+
public override void Visit(IUnaryNegation unaryNegation)
{
base.Visit(unaryNegation);