| OLD | NEW |
| 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 Loading... |
| 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 /*<T>*/ List/*<T>*/ makeArgumentsList( | 509 /*<S, 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( |
| 510 Link<Node> arguments, | 552 Link<Node> arguments, |
| 511 FunctionElement element, | 553 FunctionElement element, |
| 512 /*T*/ compileArgument(Node argument), | 554 /*T*/ compileArgument(Node argument), |
| 513 /*T*/ compileDefaultValue(ParameterElement element)) { | 555 /*T*/ compileDefaultValue(ParameterElement element)) { |
| 514 assert(invariant(element, element.isImplementation)); | 556 assert(invariant(element, element.isImplementation)); |
| 515 List/*<T>*/ result = new List(); | 557 List/*<T>*/ result = new List(); |
| 516 | 558 |
| 517 FunctionSignature parameters = element.functionSignature; | 559 FunctionSignature parameters = element.functionSignature; |
| 518 parameters.forEachRequiredParameter((ParameterElement element) { | 560 parameters.forEachRequiredParameter((ParameterElement element) { |
| 519 result.add(compileArgument(arguments.head)); | 561 result.add(compileArgument(arguments.head)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 544 if (foundIndex != -1) { | 586 if (foundIndex != -1) { |
| 545 result.add(compiledNamedArguments[foundIndex]); | 587 result.add(compiledNamedArguments[foundIndex]); |
| 546 } else { | 588 } else { |
| 547 result.add(compileDefaultValue(element)); | 589 result.add(compileDefaultValue(element)); |
| 548 } | 590 } |
| 549 }); | 591 }); |
| 550 } | 592 } |
| 551 return result; | 593 return result; |
| 552 } | 594 } |
| 553 | 595 |
| 596 |
| 554 /** | 597 /** |
| 555 * Fills [list] with the arguments in the order expected by | 598 * Fills [list] with the arguments in the order expected by |
| 556 * [callee], and where [caller] is a synthesized element | 599 * [callee], and where [caller] is a synthesized element |
| 557 * | 600 * |
| 558 * [compileArgument] is a function that returns a compiled version | 601 * [compileArgument] is a function that returns a compiled version |
| 559 * of a parameter of [callee]. | 602 * of a parameter of [callee]. |
| 560 * | 603 * |
| 561 * [compileConstant] is a function that returns a compiled constant | 604 * [compileConstant] is a function that returns a compiled constant |
| 562 * of an optional argument that is not in the parameters of [callee]. | 605 * of an optional argument that is not in the parameters of [callee]. |
| 563 * | 606 * |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 if (signature.optionalParametersAreNamed) { | 654 if (signature.optionalParametersAreNamed) { |
| 612 namedParameters = | 655 namedParameters = |
| 613 signature.optionalParameters.mapToList((e) => e.name); | 656 signature.optionalParameters.mapToList((e) => e.name); |
| 614 } | 657 } |
| 615 Selector selector = new Selector.call(callee.name, | 658 Selector selector = new Selector.call(callee.name, |
| 616 caller.library, | 659 caller.library, |
| 617 signature.parameterCount, | 660 signature.parameterCount, |
| 618 namedParameters); | 661 namedParameters); |
| 619 | 662 |
| 620 if (!selector.applies(callee, world)) return false; | 663 if (!selector.applies(callee, world)) return false; |
| 621 list.addAll(selector.makeArgumentsList(nodes, | 664 list.addAll(selector.makeArgumentsList2(nodes, |
| 622 callee, | 665 callee, |
| 623 internalCompileArgument, | 666 internalCompileArgument, |
| 624 compileConstant)); | 667 compileConstant)); |
| 625 | 668 |
| 626 return true; | 669 return true; |
| 627 } | 670 } |
| 628 | 671 |
| 629 static bool sameNames(List<String> first, List<String> second) { | 672 static bool sameNames(List<String> first, List<String> second) { |
| 630 for (int i = 0; i < first.length; i++) { | 673 for (int i = 0; i < first.length; i++) { |
| 631 if (first[i] != second[i]) return false; | 674 if (first[i] != second[i]) return false; |
| 632 } | 675 } |
| 633 return true; | 676 return true; |
| 634 } | 677 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 | 842 |
| 800 Selector extendIfReachesAll(Compiler compiler) { | 843 Selector extendIfReachesAll(Compiler compiler) { |
| 801 bool canReachAll = compiler.enabledInvokeOn | 844 bool canReachAll = compiler.enabledInvokeOn |
| 802 && mask.needsNoSuchMethodHandling(this, compiler.world); | 845 && mask.needsNoSuchMethodHandling(this, compiler.world); |
| 803 return canReachAll | 846 return canReachAll |
| 804 ? new TypedSelector( | 847 ? new TypedSelector( |
| 805 compiler.typesTask.dynamicType, this, compiler.world) | 848 compiler.typesTask.dynamicType, this, compiler.world) |
| 806 : this; | 849 : this; |
| 807 } | 850 } |
| 808 } | 851 } |
| OLD | NEW |