diff options
author | 2017-09-01 20:22:11 +0200 | |
---|---|---|
committer | 2017-09-04 12:17:58 +0200 | |
commit | 919d1b762fc94a98725e70a405bd4a3fb33b9877 (patch) | |
tree | 9dc4648852ca6f1124dad39b64434f7d045de93e /src/main/java/com/google/devtools/build/lib | |
parent | a6d3f52fef62955b6b25a3832440f041a93bc5e2 (diff) |
Bazel/syntax: Delete/inline Statement.exec
RELNOTES: None.
PiperOrigin-RevId: 167300232
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
4 files changed, 8 insertions, 35 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java index 2f8b36b7eb..fcd3da0085 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/BuildFileAST.java @@ -181,7 +181,7 @@ public class BuildFileAST extends ASTNode { * Executes this build file in a given Environment. * * <p>If, for any reason, execution of a statement cannot be completed, an {@link EvalException} - * is thrown by {@link Statement#exec(Environment)}. This exception is caught here and reported + * is thrown by {@link Eval#exec(Statement)}. This exception is caught here and reported * through reporter and execution continues on the next statement. In effect, there is a * "try/except" block around every top level statement. Such exceptions are not ignored, though: * they are visible via the return value. Rules declared in a package containing any error @@ -207,7 +207,7 @@ public class BuildFileAST extends ASTNode { * Executes tol-level statement of this build file in a given Environment. * * <p>If, for any reason, execution of a statement cannot be completed, an {@link EvalException} - * is thrown by {@link Statement#exec(Environment)}. This exception is caught here and reported + * is thrown by {@link Eval#exec(Statement)}. This exception is caught here and reported * through reporter. In effect, there is a * "try/except" block around every top level statement. Such exceptions are not ignored, though: * they are visible via the return value. Rules declared in a package containing any error @@ -223,7 +223,7 @@ public class BuildFileAST extends ASTNode { public boolean execTopLevelStatement(Statement stmt, Environment env, EventHandler eventHandler) throws InterruptedException { try { - stmt.exec(env); + new Eval(env).exec(stmt); return true; } catch (EvalException e) { // Do not report errors caused by a previous parsing error, as it has already been @@ -378,11 +378,12 @@ public class BuildFileAST extends ASTNode { */ @Nullable public Object eval(Environment env) throws EvalException, InterruptedException { Object last = null; + Eval evaluator = new Eval(env); for (Statement statement : statements) { if (statement instanceof ExpressionStatement) { last = ((ExpressionStatement) statement).getExpression().eval(env); } else { - statement.exec(env); + evaluator.exec(statement); last = null; } } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Eval.java b/src/main/java/com/google/devtools/build/lib/syntax/Eval.java index d4c6edb0da..2fc54df17c 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Eval.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Eval.java @@ -73,7 +73,7 @@ public class Eval { try { for (Statement stmt : node.getBlock()) { - stmt.exec(env); + exec(stmt); } } catch (FlowException ex) { if (ex == breakException) { diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Statement.java b/src/main/java/com/google/devtools/build/lib/syntax/Statement.java index b8505c3aee..1f08bbb030 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Statement.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Statement.java @@ -37,35 +37,6 @@ public abstract class Statement extends ASTNode { } /** - * Executes the statement in the specified build environment, which may be modified. - * - * @throws EvalException if execution of the statement could not be completed. - * @throws InterruptedException may be thrown in a sub class. - */ - @Deprecated // use Eval class instead - final void exec(Environment env) throws EvalException, InterruptedException { - try { - doExec(env); - } catch (EvalException ex) { - throw maybeTransformException(ex); - } - } - - /** - * Executes the statement. - * - * <p>This method is only invoked by the super class {@link Statement} when calling {@link - * #exec(Environment)}. - * - * @throws EvalException if execution of the statement could not be completed. - * @throws InterruptedException may be thrown in a sub class. - */ - @Deprecated - final void doExec(Environment env) throws EvalException, InterruptedException { - new Eval(env).exec(this); - } - - /** * Kind of the statement. This is similar to using instanceof, except that it's more efficient and * can be used in a switch/case. */ diff --git a/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java index 0740416826..2b64d7c14b 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/UserDefinedFunction.java @@ -75,6 +75,7 @@ public class UserDefinedFunction extends BaseFunction { env.update(name, arguments[i++]); } + Eval eval = new Eval(env); try { for (Statement stmt : statements) { if (stmt instanceof ReturnStatement) { @@ -86,7 +87,7 @@ public class UserDefinedFunction extends BaseFunction { } return returnExpr.eval(env); } else { - stmt.exec(env); + eval.exec(stmt); } } } catch (ReturnStatement.ReturnException e) { |