diff options
author | brendandouglas <brendandouglas@google.com> | 2018-06-26 08:53:10 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-26 08:54:41 -0700 |
commit | 01683d3b079d3115b3a34d5af57c31f113fce5fa (patch) | |
tree | bb8804c5249ac02f45c7d9577417931b576fe325 /src/main/java/com/google/devtools/build/lib/syntax | |
parent | d82b8ab5a2da6949a8d87e28367dc789a6785291 (diff) |
Handle evaluation of statements, not just expressions.
Also handle statements in conditional breakpoints.
This is more consistent with other common debuggers (e.g. java, python).
Calls Parser#parseStatement with local parsing level, so some statement types aren't handled (e.g. load statements), which is broadly consistent with other debuggers.
Assignment, augmented assignment, and return statements return a non-None value,
and simple expression statements still return the result of evaluating the expression.
TAG_CHANGE_OK=This proto has never yet been used
TYPE_CHANGE_OK=This proto has never yet been used
PiperOrigin-RevId: 202135678
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/Debuggable.java | 4 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/Environment.java | 29 |
2 files changed, 25 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Debuggable.java b/src/main/java/com/google/devtools/build/lib/syntax/Debuggable.java index 4540f55dfb..ee871e6a05 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Debuggable.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Debuggable.java @@ -22,8 +22,8 @@ import javax.annotation.Nullable; /** A context in which debugging can occur. Implemented by Skylark environments. */ public interface Debuggable { - /** Evaluates a Skylark expression in the adapter's environment. */ - Object evaluate(String expression) throws EvalException, InterruptedException; + /** Evaluates a Skylark statement in the adapter's environment. */ + Object evaluate(String statement) throws EvalException, InterruptedException; /** * Returns the stack frames corresponding of the context's current (paused) state. diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java index 5b22906d71..d5b0d6c6f2 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java @@ -29,6 +29,7 @@ import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; import com.google.devtools.build.lib.syntax.Mutability.Freezable; import com.google.devtools.build.lib.syntax.Mutability.MutabilityException; +import com.google.devtools.build.lib.syntax.Parser.ParsingLevel; import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.SpellChecker; @@ -1169,15 +1170,31 @@ public final class Environment implements Freezable, Debuggable { } @Override - public Object evaluate(String expression) throws EvalException, InterruptedException { - ParserInputSource inputSource = - ParserInputSource.create(expression, PathFragment.create("<debug eval>")); + public Object evaluate(String contents) throws EvalException, InterruptedException { + ParserInputSource input = + ParserInputSource.create(contents, PathFragment.create("<debug eval>")); EvalEventHandler eventHandler = new EvalEventHandler(); - Expression expr = Parser.parseExpression(inputSource, eventHandler); + Statement statement = Parser.parseStatement(input, eventHandler, ParsingLevel.LOCAL_LEVEL); if (!eventHandler.messages.isEmpty()) { - throw new EvalException(expr.getLocation(), eventHandler.messages.get(0)); + throw new EvalException(statement.getLocation(), eventHandler.messages.get(0)); + } + // TODO(bazel-team): move statement handling code to Eval + // deal with the most common case first + if (statement.kind() == Statement.Kind.EXPRESSION) { + return ((ExpressionStatement) statement).getExpression().doEval(this); + } + // all other statement types are executed directly + Eval.fromEnvironment(this).exec(statement); + switch (statement.kind()) { + case ASSIGNMENT: + case AUGMENTED_ASSIGNMENT: + return ((AssignmentStatement) statement).getLValue().getExpression().doEval(this); + case RETURN: + Expression expr = ((ReturnStatement) statement).getReturnExpression(); + return expr != null ? expr.doEval(this) : Runtime.NONE; + default: + return Runtime.NONE; } - return expr.eval(this); } @Override |