Browse Source

Fixed bug in NRefactoryToBooConverter: NullReferenceException when first section in switch-statement was the default section.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@626 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
154dfeee9a
  1. 4
      src/AddIns/BackendBindings/Boo/BooBinding.sln
  2. 18
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorStatements.cs
  3. 51
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Test/StatementTests.cs
  4. 6
      src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.cs

4
src/AddIns/BackendBindings/Boo/BooBinding.sln

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# SharpDevelop 2.0.0.618
# SharpDevelop 2.0.0.622
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryToBooConverter", "NRefactoryToBooConverter\Project\NRefactoryToBooConverter.csproj", "{DBCF20A1-BA13-4582-BFA9-74DE4D987B73}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryToBooConverter.Tests", "NRefactoryToBooConverter\Test\NRefactoryToBooConverter.Tests.csproj", "{C9DE556D-325C-4544-B29F-16A9EB7C9830}"
@ -12,5 +12,7 @@ Project("{A33008B1-5DAC-44D5-9060-242E3B6E38F2}") = "Boo.Microsoft.Build.Tasks", @@ -12,5 +12,7 @@ Project("{A33008B1-5DAC-44D5-9060-242E3B6E38F2}") = "Boo.Microsoft.Build.Tasks",
EndProject
Project("{A33008B1-5DAC-44D5-9060-242E3B6E38F2}") = "Boo.InterpreterAddIn", "Boo.InterpreterAddIn\Project\Boo.InterpreterAddIn.booproj", "{928E34B2-5E46-4A4D-8E4D-2CA2CCDB905A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "..\..\..\Libraries\NRefactory\Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}"
EndProject
Global
EndGlobal

18
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorStatements.cs

@ -557,8 +557,9 @@ namespace NRefactoryToBooConverter @@ -557,8 +557,9 @@ namespace NRefactoryToBooConverter
new B.ReferenceExpression(currentSwitchTempName),
ConvertExpression(switchStatement.SwitchExpression));
l.Add(new B.ExpressionStatement(init));
B.IfStatement dummyStatement = new B.IfStatement(GetLexicalInfo(switchStatement));
B.IfStatement first = null;
B.IfStatement current = null;
B.IfStatement current = dummyStatement;
B.BreakStatement bs;
for (int i = 0; i < switchStatement.SwitchSections.Count; i++) {
current = (B.IfStatement)((INode)switchStatement.SwitchSections[i]).AcceptVisitor(this, current);
@ -573,20 +574,25 @@ namespace NRefactoryToBooConverter @@ -573,20 +574,25 @@ namespace NRefactoryToBooConverter
if (bs != null)
bs.ReplaceBy(null);
l.Add(first);
string endSwitchName = currentSwitchTempName + "_end";
first.Accept(new ReplaceBreakStatementsVisitor(endSwitchName));
FindUnneededLabelsVisitor fulv = new FindUnneededLabelsVisitor(currentSwitchTempName + "_", nameComparer);
first.Accept(fulv);
if (fulv.NeededLabels.Contains(endSwitchName)) {
l.Add(MakeLabel(endSwitchName));
}
bool needsEndLabel = fulv.NeededLabels.Contains(endSwitchName);
fulv.RemoveLabels(); // remove "goto case" labels that aren't needed
currentSwitchTempName = oldSwitchTempName;
if (first == dummyStatement) {
l.AddRange(dummyStatement.FalseBlock.Statements);
} else {
l.Add(first);
}
if (needsEndLabel)
l.Add(MakeLabel(endSwitchName));
return l;
}

51
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Test/StatementTests.cs

@ -159,6 +159,57 @@ namespace NRefactoryToBooConverter.Tests @@ -159,6 +159,57 @@ namespace NRefactoryToBooConverter.Tests
"\t\tA3()");
}
[Test]
public void SwitchWithDefaultAtStart()
{
TestStatement("switch (var) { default: A3(); break; case 1: A1(); break; case 2: case 3: A2(); break; }",
"??1 = var\n" +
"if (??1 == 1):\n" +
"\tA1()\n" +
"else:\n" +
"\tif ((??1 == 2) or (??1 == 3)):\n" +
"\t\tA2()\n" +
"\telse:\n" +
"\t\tA3()");
}
[Test]
public void SwitchWithOneCase()
{
TestStatement("switch (var) { case 1: A1(); break; }",
"??1 = var\n" +
"if (??1 == 1):\n" +
"\tA1()");
}
[Test]
public void SwitchWithOneCaseWithMultipleLabels()
{
TestStatement("switch (var) { case 1: case 2: A1(); break; }",
"??1 = var\n" +
"if ((??1 == 1) or (??1 == 2)):\n" +
"\tA1()");
}
[Test]
public void SwitchWithOnlyDefaultSection()
{
TestStatement("switch (var) { default: A1(); break; }",
"??1 = var\n" +
"A1()");
}
[Test]
public void SwitchWithOnlyDefaultSectionAndEarlyBreak()
{
TestStatement("switch (var) { default: if (a) break; A1(); break; }",
"??1 = var\n" +
"if a:\n" +
"\tgoto ??1_end\n" +
"A1()\n" +
":??1_end");
}
[Test]
public void SwitchWithEarlyBreak()
{

6
src/Main/Base/Project/Src/TextEditor/Gui/Dialogs/GotoDialog.cs

@ -151,7 +151,9 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -151,7 +151,9 @@ namespace ICSharpCode.SharpDevelop.Gui
listView.Items.Clear();
visibleEntries.Clear();
bestItem = null;
if (text.Length < 2)
if (text.Length == 0)
return;
if (text.Length == 1 && !char.IsDigit(text, 0))
return;
listView.BeginUpdate();
int dotPos = text.IndexOf('.');
@ -250,7 +252,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -250,7 +252,7 @@ namespace ICSharpCode.SharpDevelop.Gui
TextEditorControl editor = GetEditor();
if (editor != null) {
num = Math.Min(editor.Document.TotalNumberOfLines, Math.Max(1, num));
AddItem("Go to line " + num, ClassBrowserIconService.GotoArrowIndex, num, 0);
AddItem(StringParser.Parse("${res:Dialog.Goto.GotoLine} ") + num, ClassBrowserIconService.GotoArrowIndex, num, 0);
}
}
}

Loading…
Cancel
Save