Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/NRefactory.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiegfried Pammer <siegfriedpammer@gmail.com>2016-07-23 17:08:50 +0300
committerSiegfried Pammer <siegfriedpammer@gmail.com>2016-07-23 17:08:50 +0300
commit19497cfae13c3dcebed7dfeb1cba549e4c2deded (patch)
tree06b59a44ff913d7b8467d2030d02b10b506f810c
parent0254d4899eb45422ecca76fdb41c356976f720d5 (diff)
InsertParenthesesVisitor: Add parentheses to PrimitiveExpression if its value is a negative int/long. -1.ToString() is interpreted as -(1.ToString()) by the parser. We need parentheses in order to fix this.
-rw-r--r--ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertParenthesesVisitor.cs7
1 files changed, 7 insertions, 0 deletions
diff --git a/ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertParenthesesVisitor.cs b/ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertParenthesesVisitor.cs
index 4528a5f9..475ca40b 100644
--- a/ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertParenthesesVisitor.cs
+++ b/ICSharpCode.NRefactory.CSharp/OutputVisitor/InsertParenthesesVisitor.cs
@@ -63,6 +63,13 @@ namespace ICSharpCode.NRefactory.CSharp
}
if (expr is CastExpression)
return Unary;
+ if (expr is PrimitiveExpression) {
+ var value = ((PrimitiveExpression)expr).Value;
+ if (value is int && (int)value < 0)
+ return Unary;
+ if (value is long && (long)value < 0)
+ return Unary;
+ }
BinaryOperatorExpression boe = expr as BinaryOperatorExpression;
if (boe != null) {
switch (boe.Operator) {