Browse Source

Fixed forum-7193: CSharpOutputVisitor bugs

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2799 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
a17c67bf38
  1. 6
      src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs
  2. 30
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs
  3. 14
      src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs
  4. 3
      src/Libraries/NRefactory/Test/Lexer/CSharp/NumberLexerTest.cs
  5. 24
      src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs

6
src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs

@ -286,10 +286,10 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
islong = true; islong = true;
if (!isunsigned && (peek == 'u' || peek == 'U')) { if (!isunsigned && (peek == 'u' || peek == 'U')) {
ReaderRead(); ReaderRead();
suffix = "lu"; suffix = "Lu";
isunsigned = true; isunsigned = true;
} else { } else {
suffix = isunsigned ? "ul" : "l"; suffix = isunsigned ? "uL" : "L";
} }
} }
} }
@ -344,7 +344,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
isunsigned = true; isunsigned = true;
} else if (result > uint.MaxValue) { } else if (result > uint.MaxValue) {
islong = true; islong = true;
} else if (result > int.MaxValue) { } else if (islong == false && result > int.MaxValue) {
isunsigned = true; isunsigned = true;
} }

30
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -1087,6 +1087,22 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
public override object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) public override object TrackedVisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data)
{
TypeReference type = localVariableDeclaration.GetTypeForVariable(0);
for (int i = 1; i < localVariableDeclaration.Variables.Count; ++i) {
if (localVariableDeclaration.GetTypeForVariable(i) != type)
return TrackedVisitLocalVariableDeclarationSeparateTypes(localVariableDeclaration, data);
}
// all variables have the same type
OutputModifier(localVariableDeclaration.Modifier);
TrackVisit(type ?? new TypeReference("object"), data);
outputFormatter.Space();
AppendCommaSeparatedList(localVariableDeclaration.Variables);
outputFormatter.PrintToken(Tokens.Semicolon);
return null;
}
object TrackedVisitLocalVariableDeclarationSeparateTypes(LocalVariableDeclaration localVariableDeclaration, object data)
{ {
for (int i = 0; i < localVariableDeclaration.Variables.Count; ++i) { for (int i = 0; i < localVariableDeclaration.Variables.Count; ++i) {
VariableDeclaration v = (VariableDeclaration)localVariableDeclaration.Variables[i]; VariableDeclaration v = (VariableDeclaration)localVariableDeclaration.Variables[i];
@ -1307,18 +1323,6 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
TrackVisit(stmt, data); TrackVisit(stmt, data);
outputFormatter.NewLine(); outputFormatter.NewLine();
} }
// Check if a 'break' should be auto inserted.
if (switchSection.Children.Count == 0 ||
!(switchSection.Children[switchSection.Children.Count - 1] is BreakStatement ||
switchSection.Children[switchSection.Children.Count - 1] is ContinueStatement ||
switchSection.Children[switchSection.Children.Count - 1] is ReturnStatement)) {
outputFormatter.Indent();
outputFormatter.PrintToken(Tokens.Break);
outputFormatter.PrintToken(Tokens.Semicolon);
outputFormatter.NewLine();
}
--outputFormatter.IndentationLevel; --outputFormatter.IndentationLevel;
return null; return null;
} }
@ -1780,7 +1784,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintText("u"); outputFormatter.PrintText("u");
} }
if (val is long || val is ulong) { if (val is long || val is ulong) {
outputFormatter.PrintText("l"); outputFormatter.PrintText("L");
} }
} else { } else {
outputFormatter.PrintText(val.ToString()); outputFormatter.PrintText(val.ToString());

14
src/Libraries/NRefactory/Project/Src/Visitors/ToCSharpConvertVisitor.cs

@ -211,5 +211,19 @@ namespace ICSharpCode.NRefactory.Visitors
else else
throw new ArgumentException(); throw new ArgumentException();
} }
public override object VisitSwitchSection(SwitchSection switchSection, object data)
{
// Check if a 'break' should be auto inserted.
if (switchSection.Children.Count == 0 ||
!(switchSection.Children[switchSection.Children.Count - 1] is BreakStatement ||
switchSection.Children[switchSection.Children.Count - 1] is ContinueStatement ||
switchSection.Children[switchSection.Children.Count - 1] is ThrowStatement ||
switchSection.Children[switchSection.Children.Count - 1] is ReturnStatement))
{
switchSection.Children.Add(new BreakStatement());
}
return base.VisitSwitchSection(switchSection, data);
}
} }
} }

3
src/Libraries/NRefactory/Test/Lexer/CSharp/NumberLexerTest.cs

@ -74,6 +74,9 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
{ {
CheckToken("0x99F", 0x99F); CheckToken("0x99F", 0x99F);
CheckToken("0xAB1f", 0xAB1f); CheckToken("0xAB1f", 0xAB1f);
CheckToken("0xffffffff", 0xffffffff);
CheckToken("0xffffffffL", 0xffffffffL);
CheckToken("0xffffffffuL", 0xffffffffuL);
} }
[Test] [Test]

24
src/Libraries/NRefactory/Test/Output/CSharp/CSharpOutputTest.cs

@ -185,6 +185,26 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
TestStatement("do { } while (true);"); TestStatement("do { } while (true);");
} }
[Test]
public void Switch()
{
TestStatement("switch (a) {" +
" case 0:" +
" case 1:" +
" break;" +
" case 2:" +
" return;" +
" default:" +
" throw new Exception(); " +
"}");
}
[Test]
public void MultipleVariableForLoop()
{
TestStatement("for (int a = 0, b = 0; b < 100; ++b,a--) { }");
}
[Test] [Test]
public void SizeOf() public void SizeOf()
{ {
@ -225,13 +245,13 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter
[Test] [Test]
public void LongInteger() public void LongInteger()
{ {
TestExpression("12l"); TestExpression("12L");
} }
[Test] [Test]
public void LongUnsignedInteger() public void LongUnsignedInteger()
{ {
TestExpression("12ul"); TestExpression("12uL");
} }
[Test] [Test]

Loading…
Cancel
Save