diff options
author | 2011-06-16 16:43:52 -0700 | |
---|---|---|
committer | 2011-06-16 16:43:52 -0700 | |
commit | 5dfae3f62aebd04677e65fc35ca702d0a37bb249 (patch) | |
tree | fae5b1663616be243a869170c899c3b99b077d50 /BCT | |
parent | 379c6a37b7b74656d335235220fef676fdd15c38 (diff) |
removed division hadling from CLRsemantics
fixed unarynegation issue
Diffstat (limited to 'BCT')
-rw-r--r-- | BCT/BytecodeTranslator/CLRSemantics.cs | 8 | ||||
-rw-r--r-- | BCT/BytecodeTranslator/ExpressionTraverser.cs | 19 |
2 files changed, 23 insertions, 4 deletions
diff --git a/BCT/BytecodeTranslator/CLRSemantics.cs b/BCT/BytecodeTranslator/CLRSemantics.cs index b0749e6c..e08da536 100644 --- a/BCT/BytecodeTranslator/CLRSemantics.cs +++ b/BCT/BytecodeTranslator/CLRSemantics.cs @@ -24,11 +24,13 @@ namespace BytecodeTranslator { return new CLRExpressionSemantics(sink, statementTraverser, contractContext);
}
+
public class CLRExpressionSemantics : ExpressionTraverser {
public CLRExpressionSemantics(Sink sink, StatementTraverser/*?*/ statementTraverser, bool contractContext)
: base(sink, statementTraverser, contractContext) { }
+ /*
public override void Visit(IDivision division) {
this.Visit(division.LeftOperand);
this.Visit(division.RightOperand);
@@ -42,11 +44,13 @@ namespace BytecodeTranslator { var storeLocal = Bpl.Cmd.SimpleAssign(tok, locExpr, rexp);
this.StmtTraverser.StmtBuilder.Add(storeLocal);
- var a = new Bpl.AssertCmd(tok, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, locExpr, Bpl.Expr.Literal(0)));
- this.StmtTraverser.StmtBuilder.Add(a);
+// Assertion fails if denominator is Real or something else than int
+// var a = new Bpl.AssertCmd(tok, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, locExpr, Bpl.Expr.Literal(0)));
+// this.StmtTraverser.StmtBuilder.Add(a);
TranslatedExpressions.Push(Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Div, lexp, locExpr));
}
+ * */
}
}
}
\ No newline at end of file diff --git a/BCT/BytecodeTranslator/ExpressionTraverser.cs b/BCT/BytecodeTranslator/ExpressionTraverser.cs index 410b9eb3..a0487567 100644 --- a/BCT/BytecodeTranslator/ExpressionTraverser.cs +++ b/BCT/BytecodeTranslator/ExpressionTraverser.cs @@ -1403,8 +1403,23 @@ namespace BytecodeTranslator {
base.Visit(unaryNegation);
Bpl.Expr exp = TranslatedExpressions.Pop();
- Bpl.Expr zero = Bpl.Expr.Literal(0); // TODO: (mschaef) will this work in any case?
- TranslatedExpressions.Push(Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Sub, zero, exp));
+ Bpl.Expr e, zero, realZero;
+ zero = Bpl.Expr.Literal(0);
+ realZero = new Bpl.NAryExpr(Bpl.Token.NoToken, new Bpl.FunctionCall(this.sink.Heap.Int2Real), new Bpl.ExprSeq(zero));
+ switch (unaryNegation.Type.TypeCode) {
+ case PrimitiveTypeCode.Float32:
+ case PrimitiveTypeCode.Float64:
+ e = new Bpl.NAryExpr(
+ unaryNegation.Token(),
+ new Bpl.FunctionCall(this.sink.Heap.RealMinus),
+ new Bpl.ExprSeq(realZero, exp)
+ );
+ break;
+ default:
+ e = Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Sub, Bpl.Expr.Literal(0), exp);
+ break;
+ }
+ TranslatedExpressions.Push(e);
}
public override void Visit(ILogicalNot logicalNot)
|