aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax
diff options
context:
space:
mode:
authorGravatar Laurent Le Brun <laurentlb@google.com>2015-04-16 14:59:59 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-04-16 18:38:36 +0000
commit352b9da0d738b56112252e97d601297852233fdd (patch)
tree5d3f7bcd1d16329a1d2c6dd15f6ab332fb57be3d /src/main/java/com/google/devtools/build/lib/syntax
parente7963dff0932e3a49a5ffa735f00d16fb5c3cc67 (diff)
Simplify ValidationEnvironment.
We need only a set of symbols, types are not used anymore. -- MOS_MIGRATED_REVID=91299566
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java28
1 files changed, 11 insertions, 17 deletions
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 2bbdbbb584..5d38ccfec8 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
@@ -15,7 +15,7 @@
package com.google.devtools.build.lib.syntax;
import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.events.Location;
import java.util.HashMap;
@@ -34,7 +34,7 @@ public class ValidationEnvironment {
private final ValidationEnvironment parent;
- private Map<String, SkylarkType> variableTypes = new HashMap<>();
+ private Set<String> variables = new HashSet<>();
private Map<String, Location> variableLocations = new HashMap<>();
@@ -47,26 +47,22 @@ public class ValidationEnvironment {
// Whether this validation environment is not modified therefore clonable or not.
private boolean clonable;
- public ValidationEnvironment(Map<String, SkylarkType> builtinVariableTypes) {
+ public ValidationEnvironment(Set<String> builtinVariables) {
parent = null;
- variableTypes = new HashMap<>(builtinVariableTypes);
- readOnlyVariables.addAll(builtinVariableTypes.keySet());
+ variables.addAll(builtinVariables);
+ readOnlyVariables.addAll(builtinVariables);
clonable = true;
}
- private ValidationEnvironment(Map<String, SkylarkType> builtinVariableTypes,
- Set<String> readOnlyVariables) {
+ private ValidationEnvironment(Set<String> builtinVariables, Set<String> readOnlyVariables) {
parent = null;
- this.variableTypes = new HashMap<>(builtinVariableTypes);
+ this.variables = new HashSet<>(builtinVariables);
this.readOnlyVariables = new HashSet<>(readOnlyVariables);
clonable = false;
}
// ValidationEnvironment for a new Environment()
- private static ImmutableMap<String, SkylarkType> globalTypes =
- new ImmutableMap.Builder<String, SkylarkType> ()
- .put("False", SkylarkType.BOOL).put("True", SkylarkType.BOOL)
- .put("None", SkylarkType.TOP).build();
+ private static ImmutableSet<String> globalTypes = ImmutableSet.of("False", "True", "None");
public ValidationEnvironment() {
this(globalTypes);
@@ -75,7 +71,7 @@ public class ValidationEnvironment {
@Override
public ValidationEnvironment clone() {
Preconditions.checkState(clonable);
- return new ValidationEnvironment(variableTypes, readOnlyVariables);
+ return new ValidationEnvironment(variables, readOnlyVariables);
}
/**
@@ -84,7 +80,6 @@ public class ValidationEnvironment {
public ValidationEnvironment(ValidationEnvironment parent) {
// Don't copy readOnlyVariables: Variables may shadow global values.
this.parent = parent;
- this.variableTypes = new HashMap<String, SkylarkType>();
this.clonable = false;
}
@@ -108,7 +103,7 @@ public class ValidationEnvironment {
futureReadOnlyVariables.peek().add(varname);
}
}
- variableTypes.put(varname, SkylarkType.UNKNOWN);
+ variables.add(varname);
variableLocations.put(varname, location);
clonable = false;
}
@@ -123,8 +118,7 @@ public class ValidationEnvironment {
* Returns true if the symbol exists in the validation environment.
*/
public boolean hasSymbolInEnvironment(String varname) {
- return variableTypes.containsKey(varname)
- || topLevel().variableTypes.containsKey(varname);
+ return variables.contains(varname) || topLevel().variables.contains(varname);
}
private ValidationEnvironment topLevel() {