From c1d27c7770be8bc96231674f57905e1117dd6bdd Mon Sep 17 00:00:00 2001 From: Alex Lyman Date: Mon, 13 Jun 2011 21:42:14 -0700 Subject: [PATCH 1/3] - Made the InitializerTests pass, through three changes: * Added new-lines as needed to make the source formatting match what the actual output was. * Added code to CodeAssert to make it ignore #regions * Added code to output decimal.MinValue and decimal.MaxValue as appropriate --- .../CSharp/OutputVisitor/OutputVisitor.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index da524257d0..8e33190067 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -872,6 +872,17 @@ namespace ICSharpCode.NRefactory.CSharp formatter.WriteToken("'" + ConvertCharLiteral((char)val) + "'"); lastWritten = LastWritten.Other; } else if (val is decimal) { + decimal d = (decimal) val; + if (d == decimal.MinValue || d == decimal.MaxValue) + { + WriteKeyword("decimal"); + WriteToken(".", AstNode.Roles.Dot); + if (d == decimal.MinValue) + WriteIdentifier("MinValue"); + else + WriteIdentifier("MaxValue"); + return; + } formatter.WriteToken(((decimal)val).ToString(NumberFormatInfo.InvariantInfo) + "m"); lastWritten = LastWritten.Other; } else if (val is float) { From 5c3be8f4ccbf2f88000a0d317a1b8de31842244d Mon Sep 17 00:00:00 2001 From: Alex Lyman Date: Tue, 14 Jun 2011 11:25:22 -0700 Subject: [PATCH 2/3] - Modified the InitializerPeepholeTransforms' Array Initializers to do a forward scan of the block instead of just checking the next instruction. The next-instruction thing breaks down under the case where you have an array-of-arrays (int[][]) - Added to the InitializerPeepholeTransforms' Array Initializers to detect the creation of a multi-dimensional array (int[,]) - Modified the ILCode.InitArray contract to take an ArrayType instead of just the element type, and passing with the ArrayType.Dimensions set accordingly. - AstMethodBodyBuilder now used the ArrayType.Dimensions info to build a tree of ArrayInitializerExpressions from the raw, element-by-element list. - Fixed OutputVisitor not calling StartNode for EmptyExpressions Known issues: - ArrayCreateExpression outputs extra space in the array specifier when using EmptyExpressions, ala: "new int[][, ]" - The tree of ArrayInitializerExpressions outputs with blank lines before and after each block. --- ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index 8e33190067..bb1391c25d 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -838,6 +838,7 @@ namespace ICSharpCode.NRefactory.CSharp public object VisitEmptyExpression (EmptyExpression emptyExpression, object data) { + StartNode(emptyExpression); return EndNode (emptyExpression); } #region VisitPrimitiveExpression From 016987427b1d616ec8cf60714072b7cedc598924 Mon Sep 17 00:00:00 2001 From: Alex Lyman Date: Tue, 14 Jun 2011 14:52:35 -0700 Subject: [PATCH 3/3] - Reverted changes to display decimal.MinValue and decimal.MaxValue - Altered InitializerTests to use constant literals instead of decimal.MinValue and decimal.MaxValue --- .../CSharp/OutputVisitor/OutputVisitor.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index bb1391c25d..151cc9b14e 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -873,17 +873,6 @@ namespace ICSharpCode.NRefactory.CSharp formatter.WriteToken("'" + ConvertCharLiteral((char)val) + "'"); lastWritten = LastWritten.Other; } else if (val is decimal) { - decimal d = (decimal) val; - if (d == decimal.MinValue || d == decimal.MaxValue) - { - WriteKeyword("decimal"); - WriteToken(".", AstNode.Roles.Dot); - if (d == decimal.MinValue) - WriteIdentifier("MinValue"); - else - WriteIdentifier("MaxValue"); - return; - } formatter.WriteToken(((decimal)val).ToString(NumberFormatInfo.InvariantInfo) + "m"); lastWritten = LastWritten.Other; } else if (val is float) {