| Index: pkg/compiler/lib/src/universe/universe.dart
|
| diff --git a/pkg/compiler/lib/src/universe/universe.dart b/pkg/compiler/lib/src/universe/universe.dart
|
| index 269f261a789f2a3cf4884547301b96ec2004b416..b71d020be5c2b166d4f7b235845d9562b8b6e3dd 100644
|
| --- a/pkg/compiler/lib/src/universe/universe.dart
|
| +++ b/pkg/compiler/lib/src/universe/universe.dart
|
| @@ -495,7 +495,7 @@ class Selector {
|
| }
|
|
|
| /**
|
| - * Fills [list] with the arguments in the normalized order.
|
| + * Returns a `List` with the evaluated arguments in the normalized order.
|
| *
|
| * [compileArgument] is a function that returns a compiled version
|
| * of an argument located in [arguments].
|
| @@ -503,34 +503,78 @@ class Selector {
|
| * [compileDefaultValue] is a function that returns a compiled constant
|
| * of an optional argument that is not in [arguments].
|
| *
|
| - * Returns [:true:] if the selector and the [element] match; [:false:]
|
| - * otherwise.
|
| + * Precondition: `this.applies(element, world)`.
|
| *
|
| * Invariant: [element] must be the implementation element.
|
| */
|
| - /*<T>*/ bool addArgumentsToList(
|
| + /*<S, T>*/ List/*<T>*/ makeArgumentsList(
|
| + List/*<S>*/ arguments,
|
| + FunctionElement element,
|
| + /*T*/ compileArgument(/*S*/ argument),
|
| + /*T*/ compileDefaultValue(ParameterElement element)) {
|
| + assert(invariant(element, element.isImplementation));
|
| + List/*<T>*/ result = new List();
|
| + FunctionSignature parameters = element.functionSignature;
|
| + int i = 0;
|
| + parameters.forEachRequiredParameter((ParameterElement element) {
|
| + result.add(compileArgument(arguments[i]));
|
| + ++i;
|
| + });
|
| +
|
| + if (!parameters.optionalParametersAreNamed) {
|
| + parameters.forEachOptionalParameter((ParameterElement element) {
|
| + if (i < arguments.length) {
|
| + result.add(compileArgument(arguments[i]));
|
| + ++i;
|
| + } else {
|
| + result.add(compileDefaultValue(element));
|
| + }
|
| + });
|
| + } else {
|
| + // Visit named arguments and add them into a temporary list.
|
| + List compiledNamedArguments = [];
|
| + for (; i < arguments.length; ++i) {
|
| + compiledNamedArguments.add(compileArgument(arguments[i]));
|
| + }
|
| + // Iterate over the optional parameters of the signature, and try to
|
| + // find them in [compiledNamedArguments]. If found, we use the
|
| + // value in the temporary list, otherwise the default value.
|
| + parameters.orderedOptionalParameters
|
| + .forEach((ParameterElement element) {
|
| + int foundIndex = namedArguments.indexOf(element.name);
|
| + if (foundIndex != -1) {
|
| + result.add(compiledNamedArguments[foundIndex]);
|
| + } else {
|
| + result.add(compileDefaultValue(element));
|
| + }
|
| + });
|
| + }
|
| + return result;
|
| + }
|
| +
|
| + /// This is a version of [makeArgumentsList] that works for a `Link`
|
| + /// representation of arguments.
|
| + /*<T>*/ List/*<T>*/ makeArgumentsList2(
|
| Link<Node> arguments,
|
| - List/*<T>*/ list,
|
| FunctionElement element,
|
| /*T*/ compileArgument(Node argument),
|
| - /*T*/ compileDefaultValue(ParameterElement element),
|
| - World world) {
|
| + /*T*/ compileDefaultValue(ParameterElement element)) {
|
| assert(invariant(element, element.isImplementation));
|
| - if (!this.applies(element, world)) return false;
|
| + List/*<T>*/ result = new List();
|
|
|
| FunctionSignature parameters = element.functionSignature;
|
| parameters.forEachRequiredParameter((ParameterElement element) {
|
| - list.add(compileArgument(arguments.head));
|
| + result.add(compileArgument(arguments.head));
|
| arguments = arguments.tail;
|
| });
|
|
|
| if (!parameters.optionalParametersAreNamed) {
|
| parameters.forEachOptionalParameter((ParameterElement element) {
|
| if (!arguments.isEmpty) {
|
| - list.add(compileArgument(arguments.head));
|
| + result.add(compileArgument(arguments.head));
|
| arguments = arguments.tail;
|
| } else {
|
| - list.add(compileDefaultValue(element));
|
| + result.add(compileDefaultValue(element));
|
| }
|
| });
|
| } else {
|
| @@ -546,15 +590,16 @@ class Selector {
|
| parameters.orderedOptionalParameters.forEach((ParameterElement element) {
|
| int foundIndex = namedArguments.indexOf(element.name);
|
| if (foundIndex != -1) {
|
| - list.add(compiledNamedArguments[foundIndex]);
|
| + result.add(compiledNamedArguments[foundIndex]);
|
| } else {
|
| - list.add(compileDefaultValue(element));
|
| + result.add(compileDefaultValue(element));
|
| }
|
| });
|
| }
|
| - return true;
|
| + return result;
|
| }
|
|
|
| +
|
| /**
|
| * Fills [list] with the arguments in the order expected by
|
| * [callee], and where [caller] is a synthesized element
|
| @@ -621,12 +666,13 @@ class Selector {
|
| signature.parameterCount,
|
| namedParameters);
|
|
|
| - return selector.addArgumentsToList(nodes,
|
| - list,
|
| - callee,
|
| - internalCompileArgument,
|
| - compileConstant,
|
| - world);
|
| + if (!selector.applies(callee, world)) return false;
|
| + list.addAll(selector.makeArgumentsList2(nodes,
|
| + callee,
|
| + internalCompileArgument,
|
| + compileConstant));
|
| +
|
| + return true;
|
| }
|
|
|
| static bool sameNames(List<String> first, List<String> second) {
|
|
|