Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(700)

Unified Diff: pkg/compiler/lib/src/universe/universe.dart

Issue 742023002: Handle named and optional arguments in cps-ir. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a183390dc71cb26126da8692fdb855663e926e66 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,31 @@ 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)`.
floitsch 2014/11/20 13:14:43 can you assert this?
sigurdm 2014/11/21 09:52:53 Not without requiring the world as a parameter.
*
* Invariant: [element] must be the implementation element.
*/
- /*<T>*/ bool addArgumentsToList(
+ /*<T>*/ List/*<T>*/ makeArgumentsList(
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,13 +543,60 @@ 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;
+ }
+
+ /// This is a version of [makeArgumentsList] that works for the tree_ir
+ /// representation of arguments.
floitsch 2014/11/20 13:14:43 Reverse the order. The Ssa-one is the one that wil
sigurdm 2014/11/21 09:52:53 Done.
+ /*<S, T>*/ List/*<T>*/ makeArgumentsList2(
+ 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;
}
/**
@@ -621,12 +665,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.makeArgumentsList(nodes,
+ callee,
+ internalCompileArgument,
+ compileConstant));
+
+ return true;
}
static bool sameNames(List<String> first, List<String> second) {

Powered by Google App Engine
This is Rietveld 408576698