protected override void TranslateSwitchStatementContinuousSafe(List<string> output, SwitchStatementContinuousSafe switchStatement) { foreach (SwitchStatement.Chunk chunks in switchStatement.OriginalSwitchStatement.Chunks) { if (chunks.Cases.Length > 1) throw new Exception("Not a continuous switch statement."); if (chunks.Cases[0] == null) throw new Exception("Not a safe switch statement."); } this.TranslateSwitchStatement(output, switchStatement.OriginalSwitchStatement); }
protected override void TranslateSwitchStatementContinuousSafe(List<string> output, SwitchStatementContinuousSafe switchStatement) { SwitchStatementContinuousSafe.SearchTree tree = switchStatement.GenerateSearchTree(); int switchId = this.GetNextInt(); string varName = "switch_key_" + switchId; output.Add(this.CurrentTabIndention); output.Add(varName); output.Add(" = "); this.TranslateExpression(output, switchStatement.Condition); output.Add("\r\n"); this.GenerateSearchTree(output, tree, varName); }
private void GenerateSearchTree(List<string> output, SwitchStatementContinuousSafe.SearchTree tree, string varName) { if (tree.Code == null) { output.Add(this.CurrentTabIndention); output.Add("if " + varName + " < " + tree.LessThanThis + ":\r\n"); this.CurrentIndention++; this.GenerateSearchTree(output, tree.Left, varName); this.CurrentIndention--; output.Add(this.CurrentTabIndention); output.Add("else:\r\n"); this.CurrentIndention++; this.GenerateSearchTree(output, tree.Right, varName); this.CurrentIndention--; } else { this.Translate(output, tree.Code); } }
public SearchTree GenerateSearchTree() { int[] keys = this.codeByCondition.Keys.ToArray(); int min = keys.First <int>(); int max = keys.First <int>(); foreach (int key in keys) { if (key < min) { min = key; } if (key > max) { max = key; } } return(SwitchStatementContinuousSafe.GenerateSearchTreeCommon(this.codeByCondition, min, max)); }
public SwitchStatementContinuousSafe.SearchTree GenerateSearchTree() { return(SwitchStatementContinuousSafe.GenerateSearchTreeCommon(this.codeMapping, 0, this.max)); }
protected abstract void TranslateSwitchStatementContinuousSafe(List<string> output, SwitchStatementContinuousSafe switchStatement);