diff options
author | 2017-08-16 21:19:48 +0200 | |
---|---|---|
committer | 2017-08-17 09:54:03 +0200 | |
commit | c780f2fe411876e6235069b50635fa2b1e8555f6 (patch) | |
tree | 9c71c9d34d223828e8b3ee0121f82210fa029194 /src/main/java/com/google/devtools/build/lib/syntax | |
parent | bcb0354b2d7c7a8f824e9dab76cb21526a81a045 (diff) |
Simplify validation environment (futureReadOnlyVariables is not needed).
RELNOTES: None.
PiperOrigin-RevId: 165477209
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/IfStatement.java | 14 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java | 36 |
2 files changed, 6 insertions, 44 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/IfStatement.java b/src/main/java/com/google/devtools/build/lib/syntax/IfStatement.java index e6c8c23c16..c96f001c09 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/IfStatement.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/IfStatement.java @@ -73,7 +73,9 @@ public final class IfStatement extends Statement { @Override void validate(ValidationEnvironment env) throws EvalException { condition.validate(env); - validateStmts(env, statements); + for (Statement stmt : statements) { + stmt.validate(env); + } } } @@ -142,19 +144,11 @@ public final class IfStatement extends Statement { @Override void validate(ValidationEnvironment env) throws EvalException { - env.startTemporarilyDisableReadonlyCheckSession(); for (ConditionalStatements stmts : thenBlocks) { stmts.validate(env); } - validateStmts(env, elseBlock); - env.finishTemporarilyDisableReadonlyCheckSession(); - } - - private static void validateStmts(ValidationEnvironment env, List<Statement> stmts) - throws EvalException { - for (Statement stmt : stmts) { + for (Statement stmt : elseBlock) { stmt.validate(env); } - env.finishTemporarilyDisableReadonlyCheckBranch(); } } diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java index 3629449832..68268e0774 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java @@ -21,7 +21,6 @@ import com.google.devtools.build.lib.util.Preconditions; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.Stack; import javax.annotation.Nullable; /** @@ -35,10 +34,6 @@ public final class ValidationEnvironment { private class Scope { private final Set<String> variables = new HashSet<>(); private final Set<String> readOnlyVariables = new HashSet<>(); - // A stack of variable-sets which are read only but can be assigned in different - // branches of if-else statements. - // TODO(laurentlb): Remove it. - private final Stack<Set<String>> futureReadOnlyVariables = new Stack<>(); @Nullable private final Scope parent; Scope(@Nullable Scope parent) { @@ -71,12 +66,8 @@ public final class ValidationEnvironment { /** Declare a variable and add it to the environment. */ void declare(String varname, Location location) throws EvalException { checkReadonly(varname, location); - if (scope.parent == null) { // top-level values are immutable + if (scope.parent == null) { // top-level values are immutable scope.readOnlyVariables.add(varname); - if (!scope.futureReadOnlyVariables.isEmpty()) { - // Currently validating an if-else statement - scope.futureReadOnlyVariables.peek().add(varname); - } } scope.variables.add(varname); } @@ -109,30 +100,7 @@ public final class ValidationEnvironment { return all; } - /** - * Starts a session with temporarily disabled readonly checking for variables between branches. - * This is useful to validate control flows like if-else when we know that certain parts of the - * code cannot both be executed. - */ - void startTemporarilyDisableReadonlyCheckSession() { - scope.futureReadOnlyVariables.add(new HashSet<String>()); - } - - /** Finishes the session with temporarily disabled readonly checking. */ - void finishTemporarilyDisableReadonlyCheckSession() { - Set<String> variables = scope.futureReadOnlyVariables.pop(); - scope.readOnlyVariables.addAll(variables); - if (!scope.futureReadOnlyVariables.isEmpty()) { - scope.futureReadOnlyVariables.peek().addAll(variables); - } - } - - /** Finishes a branch of temporarily disabled readonly checking. */ - void finishTemporarilyDisableReadonlyCheckBranch() { - scope.readOnlyVariables.removeAll(scope.futureReadOnlyVariables.peek()); - } - - /** Throws EvalException if a load() appears after another kind of statement. */ + /** Throws EvalException if a load() appears after another kind of statement. */ private static void checkLoadAfterStatement(List<Statement> statements) throws EvalException { Location firstStatement = null; |