diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java index 942bf92657..662ac2f259 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.syntax; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Ordering; import com.google.common.collect.Sets; @@ -29,6 +30,7 @@ import com.google.devtools.build.lib.util.Preconditions; import net.bytebuddy.implementation.bytecode.StackManipulation; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -203,7 +205,7 @@ public abstract class BaseFunction implements SkylarkValue { */ public Object[] processArguments(List<Object> args, @Nullable Map<String, Object> kwargs, - @Nullable Location loc, @Nullable Environment env) + @Nullable Location loc) throws EvalException { Object[] arguments = new Object[getArgArraySize()]; @@ -239,7 +241,7 @@ public abstract class BaseFunction implements SkylarkValue { Tuple.copyOf(args.subList(numPositionalParams, numPositionalArgs)); numPositionalArgs = numPositionalParams; // clip numPositionalArgs } else { - arguments[starParamIndex] = Tuple.empty(); + arguments[starParamIndex] = Tuple.EMPTY; } } else if (numPositionalArgs > numPositionalParams) { throw new EvalException(loc, @@ -278,7 +280,7 @@ public abstract class BaseFunction implements SkylarkValue { // If there's a kwParam, it's empty. if (hasKwParam) { // TODO(bazel-team): create a fresh mutable dict, like Python does - arguments[kwParamIndex] = SkylarkDict.of(env); + arguments[kwParamIndex] = ImmutableMap.<String, Object>of(); } } else if (hasKwParam && numNamedParams == 0) { // Easy case (2b): there are no named parameters, but there is a **kwParam. @@ -286,21 +288,18 @@ public abstract class BaseFunction implements SkylarkValue { // Note that *starParam and **kwParam themselves don't count as named. // Also note that no named parameters means no mandatory parameters that weren't passed, // and no missing optional parameters for which to use a default. Thus, no loops. - // NB: not 2a means kwarg isn't null - arguments[kwParamIndex] = SkylarkDict.copyOf(env, kwargs); + // TODO(bazel-team): create a fresh mutable dict, like Python does + arguments[kwParamIndex] = kwargs; // NB: not 2a means kwarg isn't null } else { // Hard general case (2c): some keyword arguments may correspond to named parameters - SkylarkDict<String, Object> kwArg = hasKwParam - ? SkylarkDict.<String, Object>of(env) : SkylarkDict.<String, Object>empty(); + HashMap<String, Object> kwArg = hasKwParam ? new HashMap<String, Object>() : null; // For nicer stabler error messages, start by checking against // an argument being provided both as positional argument and as keyword argument. ArrayList<String> bothPosKey = new ArrayList<>(); for (int i = 0; i < numPositionalArgs; i++) { String name = names.get(i); - if (kwargs.containsKey(name)) { - bothPosKey.add(name); - } + if (kwargs.containsKey(name)) { bothPosKey.add(name); } } if (!bothPosKey.isEmpty()) { throw new EvalException(loc, @@ -326,12 +325,12 @@ public abstract class BaseFunction implements SkylarkValue { throw new EvalException(loc, String.format( "%s got multiple values for keyword argument '%s'", this, keyword)); } - kwArg.put(keyword, value, loc, env); + kwArg.put(keyword, value); } } if (hasKwParam) { // TODO(bazel-team): create a fresh mutable dict, like Python does - arguments[kwParamIndex] = SkylarkDict.copyOf(env, kwArg); + arguments[kwParamIndex] = ImmutableMap.copyOf(kwArg); } // Check that all mandatory parameters were filled in general case 2c. @@ -437,7 +436,7 @@ public abstract class BaseFunction implements SkylarkValue { // ast is null when called from Java (as there's no Skylark call site). Location loc = ast == null ? Location.BUILTIN : ast.getLocation(); - Object[] arguments = processArguments(args, kwargs, loc, env); + Object[] arguments = processArguments(args, kwargs, loc); canonicalizeArguments(arguments, loc); return call(arguments, ast, env); |