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

Unified Diff: frog/leg/ssa/builder.dart

Issue 9316026: Support named arguments for dynamic calls. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 months 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: frog/leg/ssa/builder.dart
===================================================================
--- frog/leg/ssa/builder.dart (revision 3778)
+++ frog/leg/ssa/builder.dart (working copy)
@@ -887,8 +887,35 @@
if (selector.namedArgumentCount == 0) {
addGenericSendArgumentsToList(node.arguments, list);
} else {
- compiler.cancel(
- 'Unimplemented named argument for dynamic sends', node: node);
+ // Visit positional arguments and add them to the list.
kasperl 2012/02/01 10:21:21 I would factor this out into a couple of helper fu
+ Link<Node> arguments = node.arguments;
+ int positionalArgumentCount = selector.positionalArgumentCount;
+ for (int i = 0;
+ i < positionalArgumentCount;
+ arguments = arguments.tail, i++) {
+ visit(arguments.head);
+ list.add(pop());
+ }
+
+ // Visit named arguments and add them into a temporary map.
+ Map<SourceString, HInstruction> instructions =
+ new Map<SourceString, HInstruction>();
+ List<SourceString> namedArguments = selector.namedArguments;
+ int nameIndex = 0;
+ for (; !arguments.isEmpty(); arguments = arguments.tail) {
+ visit(arguments.head);
+ instructions[namedArguments[nameIndex++]] = pop();
+ }
+
+ // Iterate through the named arguments to add them to the list
+ // of instructions, in the order set by the map.
+ List<SourceString> keys = instructions.getKeys();
+ for (SourceString name in keys) {
+ list.add(instructions[name]);
+ }
+
+ // Update the selector with an ordered list of named arguments.
+ selector.orderedNamedArguments = keys;
}
}

Powered by Google App Engine
This is Rietveld 408576698