private void CloseSwitch(Node switchBlock) { if (switchBlock.GetType() != Token.BLOCK) { throw Kit.CodeBug(); } Jump switchNode = (Jump)switchBlock.GetFirstChild(); if (switchNode.GetType() != Token.SWITCH) { throw Kit.CodeBug(); } Node switchBreakTarget = Node.NewTarget(); // switchNode.target is only used by NodeTransformer // to detect switch end switchNode.target = switchBreakTarget; Node defaultTarget = switchNode.GetDefault(); if (defaultTarget == null) { defaultTarget = switchBreakTarget; } switchBlock.AddChildAfter(MakeJump(Token.GOTO, defaultTarget), switchNode); switchBlock.AddChildToBack(switchBreakTarget); }
private static Node AddBeforeCurrent(Node parent, Node previous, Node current, Node toAdd) { if (previous == null) { if (!(current == parent.GetFirstChild())) { Kit.CodeBug(); } parent.AddChildToFront(toAdd); } else { if (!(current == previous.GetNext())) { Kit.CodeBug(); } parent.AddChildAfter(toAdd, previous); } return toAdd; }