summaryrefslogtreecommitdiff
path: root/Source/Dafny/Printer.cs
diff options
context:
space:
mode:
authorGravatar Rustan Leino <unknown>2014-02-13 21:10:16 -0800
committerGravatar Rustan Leino <unknown>2014-02-13 21:10:16 -0800
commit79610237eba7902e8be127fa54f2572a2c01f6b7 (patch)
tree4c273b46c76e2128cc9e058aebdb96d0c6405bc2 /Source/Dafny/Printer.cs
parent6897d8be8a9c5ebef140398f682021acfea393bb (diff)
Allow unary minus on reals
Diffstat (limited to 'Source/Dafny/Printer.cs')
-rw-r--r--Source/Dafny/Printer.cs14
1 files changed, 14 insertions, 0 deletions
diff --git a/Source/Dafny/Printer.cs b/Source/Dafny/Printer.cs
index 952c8ef6..601c5761 100644
--- a/Source/Dafny/Printer.cs
+++ b/Source/Dafny/Printer.cs
@@ -1566,6 +1566,20 @@ namespace Microsoft.Dafny {
// printing of parentheses is done optimally, not according to the parentheses in the given program
PrintExpr(e.E, contextBindingStrength, fragileContext, isRightmost, isFollowedBySemicolon, indent);
+ } else if (expr is NegationExpression) {
+ var e = (NegationExpression)expr;
+ string op = "-";
+ int opBindingStrength = 0x60;
+ bool parensNeeded = opBindingStrength < contextBindingStrength ||
+ (fragileContext && opBindingStrength == contextBindingStrength);
+
+ bool containsNestedNegation = e.E is ParensExpression && ((ParensExpression)e.E).E is NegationExpression;
+
+ if (parensNeeded) { wr.Write("("); }
+ wr.Write(op);
+ PrintExpr(e.E, opBindingStrength, containsNestedNegation, parensNeeded || isRightmost, !parensNeeded && isFollowedBySemicolon, -1);
+ if (parensNeeded) { wr.Write(")"); }
+
} else if (expr is IdentifierSequence) {
var e = (IdentifierSequence)expr;
string sep = "";