Skip to content

Commit

Permalink
Bazel/syntax: Delete/inline Statement.exec
Browse files Browse the repository at this point in the history
RELNOTES: None.
PiperOrigin-RevId: 167300232
  • Loading branch information
laurentlb authored and meteorcloudy committed Sep 4, 2017
1 parent a6d3f52 commit 919d1b7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/com/google/devtools/build/lib/syntax/Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 919d1b7

Please sign in to comment.