diff options
author | 2016-02-01 18:39:42 +0000 | |
---|---|---|
committer | 2016-02-02 14:57:35 +0000 | |
commit | d5ef2b4956619c44c9d17ac097857508e4d53b40 (patch) | |
tree | e51de7e9541fa1eb346fe5a9876ca5b61ccd7cdf /src/main/java/com/google/devtools/build/lib/syntax/DictionaryLiteral.java | |
parent | dccd81fe23111818d63a61d882f65a8b412de4e2 (diff) |
Rollback of commit f941d56acfad5f8c819c81b494f806ea74ea7fd8.
*** Reason for rollback ***
Breaks many targets, see []
*** Original change description ***
Reinstate mutable SkylarkDict
Add <String, Object> annotation to optionMap invocation in SkylarkAttr,
to make JDK 1.7 happy.
Give the visible name "aspect" to class SkylarkAspect.
--
MOS_MIGRATED_REVID=113543873
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/DictionaryLiteral.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/DictionaryLiteral.java | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/DictionaryLiteral.java b/src/main/java/com/google/devtools/build/lib/syntax/DictionaryLiteral.java index 3ab31263f1..8a223ed582 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/DictionaryLiteral.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/DictionaryLiteral.java @@ -16,7 +16,7 @@ package com.google.devtools.build.lib.syntax; import static com.google.devtools.build.lib.syntax.compiler.ByteCodeUtils.append; import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.events.Location; +import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.syntax.compiler.ByteCodeMethodCalls; import com.google.devtools.build.lib.syntax.compiler.ByteCodeUtils; import com.google.devtools.build.lib.syntax.compiler.DebugInfo; @@ -26,7 +26,9 @@ import net.bytebuddy.implementation.bytecode.ByteCodeAppender; import net.bytebuddy.implementation.bytecode.Duplication; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; /** * Syntax node for dictionary literals. @@ -79,17 +81,18 @@ public class DictionaryLiteral extends Expression { @Override Object doEval(Environment env) throws EvalException, InterruptedException { - SkylarkDict<Object, Object> dict = SkylarkDict.<Object, Object>of(env); - Location loc = getLocation(); + // We need LinkedHashMap to maintain the order during iteration (e.g. for loops) + Map<Object, Object> map = new LinkedHashMap<>(); for (DictionaryEntryLiteral entry : entries) { if (entry == null) { - throw new EvalException(loc, "null expression in " + this); + throw new EvalException(getLocation(), "null expression in " + this); } Object key = entry.key.eval(env); + EvalUtils.checkValidDictKey(key); Object val = entry.value.eval(env); - dict.put(key, val, loc, env); + map.put(key, val); } - return dict; + return ImmutableMap.copyOf(map); } @Override @@ -126,18 +129,16 @@ public class DictionaryLiteral extends Expression { @Override ByteCodeAppender compile(VariableScope scope, DebugInfo debugInfo) throws EvalException { List<ByteCodeAppender> code = new ArrayList<>(); - append(code, scope.loadEnvironment()); - append(code, ByteCodeMethodCalls.BCSkylarkDict.of); + append(code, ByteCodeMethodCalls.BCImmutableMap.builder); + for (DictionaryEntryLiteral entry : entries) { - append(code, Duplication.SINGLE); // duplicate the dict code.add(entry.key.compile(scope, debugInfo)); append(code, Duplication.SINGLE, EvalUtils.checkValidDictKey); code.add(entry.value.compile(scope, debugInfo)); - append(code, - debugInfo.add(this).loadLocation, - scope.loadEnvironment(), - ByteCodeMethodCalls.BCSkylarkDict.put); + // add it to the builder which is already on the stack and returns itself + append(code, ByteCodeMethodCalls.BCImmutableMap.Builder.put); } + append(code, ByteCodeMethodCalls.BCImmutableMap.Builder.build); return ByteCodeUtils.compoundAppender(code); } } |