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

Side by Side Diff: pkg/compiler/lib/src/universe/universe.dart

Issue 908863003: dart2js cps: Handle optional parameters in builder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix static invoke Created 5 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library universe; 5 library universe;
6 6
7 import '../elements/elements.dart'; 7 import '../elements/elements.dart';
8 import '../dart2jslib.dart'; 8 import '../dart2jslib.dart';
9 import '../dart_types.dart'; 9 import '../dart_types.dart';
10 import '../types/types.dart'; 10 import '../types/types.dart';
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 /** 499 /**
500 * Returns a `List` with the evaluated arguments in the normalized order. 500 * Returns a `List` with the evaluated arguments in the normalized order.
501 * 501 *
502 * [compileDefaultValue] is a function that returns a compiled constant 502 * [compileDefaultValue] is a function that returns a compiled constant
503 * of an optional argument that is not in [compiledArguments]. 503 * of an optional argument that is not in [compiledArguments].
504 * 504 *
505 * Precondition: `this.applies(element, world)`. 505 * Precondition: `this.applies(element, world)`.
506 * 506 *
507 * Invariant: [element] must be the implementation element. 507 * Invariant: [element] must be the implementation element.
508 */ 508 */
509 /*<S, T>*/ List/*<T>*/ makeArgumentsList( 509 /*<T>*/ List/*<T>*/ makeArgumentsList(
510 FunctionElement element,
511 List/*<T>*/ compiledArguments,
512 /*T*/ compileDefaultValue(ParameterElement element)) {
513 assert(invariant(element, element.isImplementation));
514 List/*<T>*/ result = new List();
515 FunctionSignature parameters = element.functionSignature;
516 int i = 0;
517 parameters.forEachRequiredParameter((ParameterElement element) {
518 result.add(compiledArguments[i]);
519 ++i;
520 });
521
522 if (!parameters.optionalParametersAreNamed) {
523 parameters.forEachOptionalParameter((ParameterElement element) {
524 if (i < compiledArguments.length) {
525 result.add(compiledArguments[i]);
526 ++i;
527 } else {
528 result.add(compileDefaultValue(element));
529 }
530 });
531 } else {
532 int offset = i;
533 // Iterate over the optional parameters of the signature, and try to
534 // find them in [compiledNamedArguments]. If found, we use the
535 // value in the temporary list, otherwise the default value.
536 parameters.orderedOptionalParameters
537 .forEach((ParameterElement element) {
538 int foundIndex = namedArguments.indexOf(element.name);
539 if (foundIndex != -1) {
540 result.add(compiledArguments[offset + foundIndex]);
541 } else {
542 result.add(compileDefaultValue(element));
543 }
544 });
545 }
546 return result;
547 }
548
549 /// This is a version of [makeArgumentsList] that works for a `Link`
550 /// representation of arguments.
551 /*<T>*/ List/*<T>*/ makeArgumentsList2(
552 Link<Node> arguments, 510 Link<Node> arguments,
553 FunctionElement element, 511 FunctionElement element,
554 /*T*/ compileArgument(Node argument), 512 /*T*/ compileArgument(Node argument),
555 /*T*/ compileDefaultValue(ParameterElement element)) { 513 /*T*/ compileDefaultValue(ParameterElement element)) {
556 assert(invariant(element, element.isImplementation)); 514 assert(invariant(element, element.isImplementation));
557 List/*<T>*/ result = new List(); 515 List/*<T>*/ result = new List();
558 516
559 FunctionSignature parameters = element.functionSignature; 517 FunctionSignature parameters = element.functionSignature;
560 parameters.forEachRequiredParameter((ParameterElement element) { 518 parameters.forEachRequiredParameter((ParameterElement element) {
561 result.add(compileArgument(arguments.head)); 519 result.add(compileArgument(arguments.head));
(...skipping 24 matching lines...) Expand all
586 if (foundIndex != -1) { 544 if (foundIndex != -1) {
587 result.add(compiledNamedArguments[foundIndex]); 545 result.add(compiledNamedArguments[foundIndex]);
588 } else { 546 } else {
589 result.add(compileDefaultValue(element)); 547 result.add(compileDefaultValue(element));
590 } 548 }
591 }); 549 });
592 } 550 }
593 return result; 551 return result;
594 } 552 }
595 553
596
597 /** 554 /**
598 * Fills [list] with the arguments in the order expected by 555 * Fills [list] with the arguments in the order expected by
599 * [callee], and where [caller] is a synthesized element 556 * [callee], and where [caller] is a synthesized element
600 * 557 *
601 * [compileArgument] is a function that returns a compiled version 558 * [compileArgument] is a function that returns a compiled version
602 * of a parameter of [callee]. 559 * of a parameter of [callee].
603 * 560 *
604 * [compileConstant] is a function that returns a compiled constant 561 * [compileConstant] is a function that returns a compiled constant
605 * of an optional argument that is not in the parameters of [callee]. 562 * of an optional argument that is not in the parameters of [callee].
606 * 563 *
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 if (signature.optionalParametersAreNamed) { 611 if (signature.optionalParametersAreNamed) {
655 namedParameters = 612 namedParameters =
656 signature.optionalParameters.mapToList((e) => e.name); 613 signature.optionalParameters.mapToList((e) => e.name);
657 } 614 }
658 Selector selector = new Selector.call(callee.name, 615 Selector selector = new Selector.call(callee.name,
659 caller.library, 616 caller.library,
660 signature.parameterCount, 617 signature.parameterCount,
661 namedParameters); 618 namedParameters);
662 619
663 if (!selector.applies(callee, world)) return false; 620 if (!selector.applies(callee, world)) return false;
664 list.addAll(selector.makeArgumentsList2(nodes, 621 list.addAll(selector.makeArgumentsList(nodes,
665 callee, 622 callee,
666 internalCompileArgument, 623 internalCompileArgument,
667 compileConstant)); 624 compileConstant));
668 625
669 return true; 626 return true;
670 } 627 }
671 628
672 static bool sameNames(List<String> first, List<String> second) { 629 static bool sameNames(List<String> first, List<String> second) {
673 for (int i = 0; i < first.length; i++) { 630 for (int i = 0; i < first.length; i++) {
674 if (first[i] != second[i]) return false; 631 if (first[i] != second[i]) return false;
675 } 632 }
676 return true; 633 return true;
677 } 634 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 799
843 Selector extendIfReachesAll(Compiler compiler) { 800 Selector extendIfReachesAll(Compiler compiler) {
844 bool canReachAll = compiler.enabledInvokeOn 801 bool canReachAll = compiler.enabledInvokeOn
845 && mask.needsNoSuchMethodHandling(this, compiler.world); 802 && mask.needsNoSuchMethodHandling(this, compiler.world);
846 return canReachAll 803 return canReachAll
847 ? new TypedSelector( 804 ? new TypedSelector(
848 compiler.typesTask.dynamicType, this, compiler.world) 805 compiler.typesTask.dynamicType, this, compiler.world)
849 : this; 806 : this;
850 } 807 }
851 } 808 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698