public void VisitNode(JSSwitchStatement ss) { Formatter.ConditionalNewLine(); Comment("switch ({0}) {{", ss.Condition); Formatter.WriteRaw("(i32.switch "); Formatter.Indent(); Visit(ss.Condition); Formatter.ConditionalNewLine(); var defaultCase = ss.Cases.FirstOrDefault(c => c.IsDefault); foreach (var c in ss.Cases) { if (c.IsDefault) { continue; } EmitSwitchCase(c); } if (defaultCase != null) { EmitSwitchCase(defaultCase); } Formatter.Unindent(); Formatter.ConditionalNewLine(); Formatter.WriteRaw(")"); Formatter.NewLine(); }
public void VisitNode(JSSwitchStatement ss) { AbsoluteJumpsSeenStack.Add(0); VisitChildren(ss); AbsoluteJumpsSeenStack.RemoveAt(AbsoluteJumpsSeenStack.Count - 1); }
public void VisitNode(JSSwitchStatement ss) { CheckLabel(ss); PushBlock(ss); try { VisitChildren(ss); } finally { BlockStack.Pop(); } }
public void VisitNode(JSSwitchStatement ss) { var conditionType = ss.Condition.GetActualType(TypeSystem); if ( !TypeUtil.IsIntegral(conditionType) && IsEnumOrNullableEnum(conditionType) ) { var cast = JSInvocationExpression.InvokeStatic( JS.Number(TypeSystem.Int32), new[] { ss.Condition }, true ); ss.ReplaceChild(ss.Condition, cast); } VisitChildren(ss); }
public void VisitNode(JSSwitchStatement swtch) { BlockStack.Push(BlockType.Switch); WriteLabel(swtch); Output.WriteRaw("switch"); Output.Space(); Output.LPar(); Visit(swtch.Condition); Output.RPar(); Output.Space(); Output.OpenBrace(); foreach (var c in swtch.Cases) { if (c.Values != null) { foreach (var value in c.Values) { Output.WriteRaw("case "); Visit(value); Output.WriteRaw(": "); Output.NewLine(); } } else { Output.WriteRaw("default: "); Output.NewLine(); } Output.Indent(); Visit(c.Body); Output.Unindent(); Output.NewLine(); } Output.CloseBrace(); BlockStack.Pop(); }
public void VisitNode(JSSwitchStatement ss) { IndexLookup indexLookup; Initializer initializer; NullCheck nullCheck; // Detect switch statements using a lookup dictionary var switchVar = ss.Condition as JSVariable; if ( (switchVar != null) && IndexLookups.TryGetValue(switchVar, out indexLookup) && Initializers.TryGetValue(indexLookup.Field, out initializer) ) { if (NullChecks.TryGetValue(indexLookup.SwitchVariable, out nullCheck)) { ParentNode.ReplaceChild(nullCheck.Statement, new JSNullStatement()); } Stack.Skip(2).First().ReplaceChildRecursive(initializer.Statement, new JSNullStatement()); if (indexLookup.IsInverted) { ParentNode.ReplaceChild(indexLookup.Statement, new JSNullStatement()); } var switchCases = new List <JSSwitchCase>(); JSExpression[] values; foreach (var cse in ss.Cases) { var body = cse.Body; if (cse.Values == null) { values = null; body = new JSBlockStatement(body.Statements.ToArray()); } else { values = (from v in cse.Values let il = v as JSIntegerLiteral where il != null select initializer.Values[(int)il.Value]).ToArray(); } switchCases.Add(new JSSwitchCase( values, body )); } var newSwitch = new JSSwitchStatement( indexLookup.SwitchVariable, switchCases.ToArray() ); SwitchStatementsDeoptimized += 1; ParentNode.ReplaceChild(ss, newSwitch); var outVar = indexLookup.OutputVariable; foreach (var fn in Stack.OfType <JSFunctionExpression>()) { foreach (var vds in fn.Body.AllChildrenRecursive.OfType <JSVariableDeclarationStatement>().ToArray()) { for (int i = 0, c = vds.Declarations.Count; i < c; i++) { var leftVar = vds.Declarations[i].Left as JSVariable; if ((leftVar != null) && (leftVar.Identifier == outVar.Identifier)) { vds.Declarations.RemoveAt(i); i--; c--; } } } fn.AllVariables.Remove(outVar.Identifier); } VisitReplacement(newSwitch); } VisitChildren(ss); }