static BlockStatement ReplaceJump(JumpStatement jump, BlockStatement block) { if (jump.StartOffset < block.StartOffset) { throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block"); } if (jump.JumpOffset > block.EndOffset) { throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block"); } var newBlock = new BlockStatement(); var doWhileStatement = new DoWhileStatement(jump.Condition, new BlockStatement()) { StartOffset = jump.StartOffset, EndOffset = jump.JumpOffset }; var inside = false; foreach (var statement in block) { if (statement.StartOffset == jump.JumpOffset) { ((BlockStatement)doWhileStatement.Statement).AddStatement(statement); inside = true; } else if (statement.StartOffset == jump.StartOffset) { if (doWhileStatement == null) { throw new InvalidOperationException("DoWhileStatement can't be null"); } newBlock.AddStatement(doWhileStatement); doWhileStatement = null; inside = false; } else if (inside) { ((BlockStatement)doWhileStatement.Statement).AddStatement(statement); } else { var lastStatement = newBlock.LastOrDefault(); if (lastStatement != null && lastStatement.EndOffset > statement.StartOffset) { throw new NotSupportedException("invalid Statement"); } newBlock.AddStatement(statement); } } return(newBlock); }
public override IAstNode Visit(JumpStatement node) { var newNode = base.Visit(node); if (CurrentContext.EndOffset == node.EndOffset) { contexts.Pop(); } else if (node.JumpOffset > node.EndOffset) { contexts.Push(new Context(CurrentContext.Reverse(), node.JumpOffset)); } return(newNode); }
public override IAstNode Visit(JumpStatement node) { IAstNode n; if (AcceptJump(node)) { n = new GoToStatement(CreateLabel(node)) { StartOffset = node.StartOffset, EndOffset = node.EndOffset }; } else { n = node; } return(n); }
public override string Visit(JumpStatement node) { return(Indentation(node, string.Format("jump {0} if {1}{2}", node.JumpOffset, node.Condition.Accept(this), Environment.NewLine))); }
public override void Visit(JumpStatement node) { Jumps.Add(node); }
static BlockStatement ReplaceJump(JumpStatement jump, BlockStatement block) { if (jump.StartOffset < block.StartOffset) { throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block"); } if (jump.JumpOffset > block.EndOffset) { throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block"); } var newBlock = new BlockStatement(); var ifStatement = new IfStatement(Not(jump.Condition), new BlockStatement()) { StartOffset = jump.StartOffset, EndOffset = jump.JumpOffset }; var inside = false; foreach (var statement in block) { if (statement is IfStatement && statement.Contains(jump.StartOffset.Value) && statement.EndOffset >= jump.JumpOffset) { var ifStatement2 = (IfStatement)statement; var b2 = ReplaceJump(jump, (BlockStatement)ifStatement2.TrueStatement); var newIfStatement2 = new IfStatement(ifStatement2.Condition, new BlockStatement()) { StartOffset = ifStatement2.StartOffset, EndOffset = ifStatement2.EndOffset }; ((BlockStatement)newIfStatement2.TrueStatement).AddStatements((IEnumerable <Statement>)b2); newBlock.AddStatement(newIfStatement2); } else if (statement.StartOffset == jump.StartOffset) { inside = true; } else if (statement.StartOffset == jump.JumpOffset) { if (ifStatement == null) { throw new InvalidOperationException("ifStatement can't be null"); } newBlock.AddStatement(ifStatement); newBlock.AddStatement(statement); ifStatement = null; inside = false; } else if (inside) { ((BlockStatement)ifStatement.TrueStatement).AddStatement(statement); } else { var lastStatement = newBlock.LastOrDefault(); if (lastStatement != null && lastStatement.EndOffset > statement.StartOffset) { throw new NotSupportedException("invalid Statement"); } newBlock.AddStatement(statement); } } return(newBlock); }
public override IAstNode Visit(JumpStatement node) { return(new JumpStatement((Expression)node.Condition.Accept(this), node.JumpOffset, node.StartOffset, node.EndOffset)); }
static string CreateLabel(JumpStatement node) { return(string.Format("label_{0}", node.JumpOffset)); }
static bool AcceptJump(JumpStatement node) { var condition = node.Condition as BooleanLiteralExpression; return(condition != null && condition.Value); }