/** * Creates a block statement from the given list of statements. * @param stmts Initial statements for the block * @param introducesNewScope Determines whether the block introduces a new lexical scope. This * should be false in the case of a function body, as this has the same * lexical scope as the function parameters. */ public BlockStmt(List<Stmt> stmts, boolean introducesNewScope) { setStmts(stmts); this.introducesNewScope = introducesNewScope; }
@Override public void replaceChild(IAstNode child, IAstNode newChild) { assert child == getExpr(); assert newChild instanceof Expr; expr = (Expr) newChild; }
/** * Determines whether the loop's body contains any break or continue statements * that are not nested in inner loops. */ public boolean containsDirectBreakOrContinueStmt() { return new ContainsDirectBreakOrContinueStmt().check(); }
public OutlinedStatementReductionOpportunity(ExprStmt stmt, FunctionDefinition outlined, VisitationDepth depth) { super(depth); assert stmt.getExpr() instanceof BinaryExpr; assert outlined.getBody().getNumStmts() == 1; assert outlined.getBody().getStmt(0) instanceof ReturnStmt; this.stmt = stmt; this.outlined = outlined; }
@Override public void inject(Stmt stmt) { if (nextStmt == null) { blockStmt.insertStmt(blockStmt.getNumStmts(), stmt); } else { blockStmt.insertBefore(nextStmt, stmt); } }
@Override public Stmt getNextStmt() { return chooseThen ? ifStmt.getThenStmt() : ifStmt.getElseStmt(); }
@Override public DoStmt clone() { return new DoStmt(getBody().clone(), getCondition().clone()); }
@Override public WhileStmt clone() { return new WhileStmt(getCondition().clone(), getBody().clone()); }
@Override public void replaceNext(Stmt stmt) { if (chooseThen) { ifStmt.setThenStmt(stmt); } else { ifStmt.setElseStmt(stmt); } }
@Override public Stmt getNextStmt() { return loopStmt.getBody(); }
@Override public void replaceNext(Stmt stmt) { loopStmt.setBody(stmt); }
@Override public void visitBreakStmt(BreakStmt breakStmt) { if (nestingDepth == 0) { throw new FoundBreakOrContinueStmtException(); } }
@Override public void replaceChild(IAstNode child, IAstNode newChild) { if (child == init) { init = (Stmt) newChild; } else if (child == increment) { increment = (Expr) newChild; } else { super.replaceChild(child, newChild); } }
@Override public ExtensionStatement clone() { return new ExtensionStatement(extensionName, extensionStatus); } }
@Override public boolean hasChild(IAstNode candidateChild) { return candidateChild == init || candidateChild == increment || super.hasChild(candidateChild); }
public boolean check() { try { visit(body); return false; } catch (FoundBreakOrContinueStmtException exception) { return true; } }
@Override public void visitContinueStmt(ContinueStmt continueStmt) { if (nestingDepth == 0) { throw new FoundBreakOrContinueStmtException(); } }