Browse Source

Suppress break statements while generating switch/case

pull/334/head
figment 12 years ago
parent
commit
4d178855bb
  1. 12
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs

12
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs

@ -56,6 +56,9 @@ namespace ICSharpCode.PythonBinding @@ -56,6 +56,9 @@ namespace ICSharpCode.PythonBinding
// flag during yield statement to suppress child return statements
private bool suppressReturn = false;
// flag during case statement to suppress child break statements
private bool suppressBreak = false;
static readonly string Docstring = "\"\"\"";
public NRefactoryToPythonConverter(SupportedLanguage language)
@ -441,7 +444,10 @@ namespace ICSharpCode.PythonBinding @@ -441,7 +444,10 @@ namespace ICSharpCode.PythonBinding
public override object TrackedVisitBreakStatement(BreakStatement breakStatement, object data)
{
AppendIndentedLine("break");
if (suppressBreak)
AppendIndentedLine("pass #break"); // use pass as noop
else
AppendIndentedLine("break");
return null;
}
@ -1497,6 +1503,8 @@ namespace ICSharpCode.PythonBinding @@ -1497,6 +1503,8 @@ namespace ICSharpCode.PythonBinding
public override object TrackedVisitSwitchStatement(SwitchStatement switchStatement, object data)
{
var oldSuppressBreak = suppressBreak;
this.suppressBreak = true;
bool firstSection = true;
foreach (SwitchSection section in switchStatement.SwitchSections) {
// Create if/elif/else condition.
@ -1509,6 +1517,8 @@ namespace ICSharpCode.PythonBinding @@ -1509,6 +1517,8 @@ namespace ICSharpCode.PythonBinding
firstSection = false;
}
suppressBreak = oldSuppressBreak;
return null;
}

Loading…
Cancel
Save