aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
diff options
context:
space:
mode:
authorGravatar Francois-Rene Rideau <tunes@google.com>2015-09-04 19:13:47 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-09-08 09:02:28 +0000
commit5a94e59f02833f9142bad9203acd72626b089535 (patch)
treeddfe00a54a701eff0f74af6e84e5b8cefcef1c93 /src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
parentab1711b026f8a4915ee2ef2556b2a7dbff18fa63 (diff)
Refactor Skylark Environment-s
Make Environment-s freezable: Introduce a class Mutability as a revokable capability to mutate objects in an Environment. For now, only Environment-s carry this capability. Make sure that every Mutability is revoked in the same function that creates it, so no Environment is left open for modification after being created and exported; exceptions for tests, the shell and initialization contexts. Unify Environment, SkylarkEnvironment and EvaluationContext into Environment. Have a notion of Frame for the bindings + parent + mutability. Replace the updateAndPropagate mechanism by a dynamicFrame. Simplify ValidationEnvironment, that is now always deduced from the Environment. -- MOS_MIGRATED_REVID=102363438
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java23
1 files changed, 5 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
index 996ae41bbe..b1ca1f60a0 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/MethodLibrary.java
@@ -776,7 +776,7 @@ public class MethodLibrary {
new BuiltinFunction("append") {
public Runtime.NoneType invoke(List<Object> self, Object item,
Location loc, Environment env) throws EvalException, ConversionException {
- if (env.isSkylark()) {
+ if (env.isCallerSkylark()) {
throw new EvalException(loc,
"function 'append' is not available in Skylark");
}
@@ -806,7 +806,7 @@ public class MethodLibrary {
new BuiltinFunction("extend") {
public Runtime.NoneType invoke(List<Object> self, List<Object> items,
Location loc, Environment env) throws EvalException, ConversionException {
- if (env.isSkylark()) {
+ if (env.isCallerSkylark()) {
throw new EvalException(loc,
"function 'append' is not available in Skylark");
}
@@ -920,7 +920,7 @@ public class MethodLibrary {
List<Object> list = Lists.newArrayListWithCapacity(dict.size());
for (Map.Entry<?, ?> entries : dict.entrySet()) {
List<?> item = ImmutableList.of(entries.getKey(), entries.getValue());
- list.add(env.isSkylark() ? SkylarkList.tuple(item) : item);
+ list.add(env.isCallerSkylark() ? SkylarkList.tuple(item) : item);
}
return convert(list, env, loc);
}
@@ -966,7 +966,7 @@ public class MethodLibrary {
@SuppressWarnings("unchecked")
private static Iterable<Object> convert(Collection<?> list, Environment env, Location loc)
throws EvalException {
- if (env.isSkylark()) {
+ if (env.isCallerSkylark()) {
return SkylarkList.list(list, loc);
} else {
return Lists.newArrayList(list);
@@ -1386,7 +1386,7 @@ public class MethodLibrary {
useLocation = true, useEnvironment = true)
private static final BuiltinFunction print = new BuiltinFunction("print") {
public Runtime.NoneType invoke(String sep, SkylarkList starargs,
- Location loc, SkylarkEnvironment env) throws EvalException {
+ Location loc, Environment env) throws EvalException {
String msg = Joiner.on(sep).join(Iterables.transform(starargs,
new com.google.common.base.Function<Object, String>() {
@Override
@@ -1493,19 +1493,6 @@ public class MethodLibrary {
/**
- * Set up a given environment for supported class methods.
- */
- public static void setupMethodEnvironment(Environment env) {
- setupMethodEnvironment(env, env.isSkylark() ? skylarkGlobalFunctions : buildGlobalFunctions);
- }
-
- private static void setupMethodEnvironment(Environment env, Iterable<BaseFunction> functions) {
- for (BaseFunction function : functions) {
- env.update(function.getName(), function);
- }
- }
-
- /**
* Collect global functions for the validation environment.
*/
public static void setupValidationEnvironment(Set<String> builtIn) {