From 919d1b762fc94a98725e70a405bd4a3fb33b9877 Mon Sep 17 00:00:00 2001 From: laurentlb <laurentlb@google.com> Date: Fri, 1 Sep 2017 20:22:11 +0200 Subject: [PATCH] Bazel/syntax: Delete/inline Statement.exec RELNOTES: None. PiperOrigin-RevId: 167300232 --- .../build/lib/syntax/BuildFileAST.java | 9 +++--- .../devtools/build/lib/syntax/Eval.java | 2 +- .../devtools/build/lib/syntax/Statement.java | 29 ------------------- .../build/lib/syntax/UserDefinedFunction.java | 3 +- 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 2f8b36b7eb038a..fcd3da00856617 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 ImmutableList<StringLiteral> getRawImports() { * 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 boolean exec(Environment env, EventHandler eventHandler) throws Interrupt * 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 boolean exec(Environment env, EventHandler eventHandler) throws Interrupt 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 static boolean checkSyntax(ParserInputSource input, EventHandler eventHan */ @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 d4c6edb0dafcc8..2fc54df17cc39c 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 @@ void execFor(ForStatement node) throws EvalException, InterruptedException { 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 b8505c3aeef664..1f08bbb0305d1e 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 @@ -36,35 +36,6 @@ public enum Kind { RETURN, } - /** - * 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 0740416826a8e9..2b64d7c14b2843 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 Object call(Object[] arguments, FuncallExpression ast, Environment env) env.update(name, arguments[i++]); } + Eval eval = new Eval(env); try { for (Statement stmt : statements) { if (stmt instanceof ReturnStatement) { @@ -86,7 +87,7 @@ public Object call(Object[] arguments, FuncallExpression ast, Environment env) } return returnExpr.eval(env); } else { - stmt.exec(env); + eval.exec(stmt); } } } catch (ReturnStatement.ReturnException e) {