| 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 } | 490 } |
| 491 | 491 |
| 492 bool applies(Element element, World world) { | 492 bool applies(Element element, World world) { |
| 493 if (!sameNameHack(element, world)) return false; | 493 if (!sameNameHack(element, world)) return false; |
| 494 return appliesUnnamed(element, world); | 494 return appliesUnnamed(element, world); |
| 495 } | 495 } |
| 496 | 496 |
| 497 /** | 497 /** |
| 498 * Returns a `List` with the evaluated arguments in the normalized order. | 498 * Returns a `List` with the evaluated arguments in the normalized order. |
| 499 * | 499 * |
| 500 * [compileArgument] is a function that returns a compiled version | |
| 501 * of an argument located in [arguments]. | |
| 502 * | |
| 503 * [compileDefaultValue] is a function that returns a compiled constant | 500 * [compileDefaultValue] is a function that returns a compiled constant |
| 504 * of an optional argument that is not in [arguments]. | 501 * of an optional argument that is not in [compiledArguments]. |
| 505 * | 502 * |
| 506 * Precondition: `this.applies(element, world)`. | 503 * Precondition: `this.applies(element, world)`. |
| 507 * | 504 * |
| 508 * Invariant: [element] must be the implementation element. | 505 * Invariant: [element] must be the implementation element. |
| 509 */ | 506 */ |
| 510 /*<S, T>*/ List/*<T>*/ makeArgumentsList( | 507 /*<S, T>*/ List/*<T>*/ makeArgumentsList( |
| 511 List/*<S>*/ arguments, | |
| 512 FunctionElement element, | 508 FunctionElement element, |
| 513 /*T*/ compileArgument(/*S*/ argument), | 509 List/*<T>*/ compiledArguments, |
| 514 /*T*/ compileDefaultValue(ParameterElement element)) { | 510 /*T*/ compileDefaultValue(ParameterElement element)) { |
| 515 assert(invariant(element, element.isImplementation)); | 511 assert(invariant(element, element.isImplementation)); |
| 516 List/*<T>*/ result = new List(); | 512 List/*<T>*/ result = new List(); |
| 517 FunctionSignature parameters = element.functionSignature; | 513 FunctionSignature parameters = element.functionSignature; |
| 518 int i = 0; | 514 int i = 0; |
| 519 parameters.forEachRequiredParameter((ParameterElement element) { | 515 parameters.forEachRequiredParameter((ParameterElement element) { |
| 520 result.add(compileArgument(arguments[i])); | 516 result.add(compiledArguments[i]); |
| 521 ++i; | 517 ++i; |
| 522 }); | 518 }); |
| 523 | 519 |
| 524 if (!parameters.optionalParametersAreNamed) { | 520 if (!parameters.optionalParametersAreNamed) { |
| 525 parameters.forEachOptionalParameter((ParameterElement element) { | 521 parameters.forEachOptionalParameter((ParameterElement element) { |
| 526 if (i < arguments.length) { | 522 if (i < compiledArguments.length) { |
| 527 result.add(compileArgument(arguments[i])); | 523 result.add(compiledArguments[i]); |
| 528 ++i; | 524 ++i; |
| 529 } else { | 525 } else { |
| 530 result.add(compileDefaultValue(element)); | 526 result.add(compileDefaultValue(element)); |
| 531 } | 527 } |
| 532 }); | 528 }); |
| 533 } else { | 529 } else { |
| 534 // Visit named arguments and add them into a temporary list. | 530 int offset = i; |
| 535 List compiledNamedArguments = []; | |
| 536 for (; i < arguments.length; ++i) { | |
| 537 compiledNamedArguments.add(compileArgument(arguments[i])); | |
| 538 } | |
| 539 // Iterate over the optional parameters of the signature, and try to | 531 // Iterate over the optional parameters of the signature, and try to |
| 540 // find them in [compiledNamedArguments]. If found, we use the | 532 // find them in [compiledNamedArguments]. If found, we use the |
| 541 // value in the temporary list, otherwise the default value. | 533 // value in the temporary list, otherwise the default value. |
| 542 parameters.orderedOptionalParameters | 534 parameters.orderedOptionalParameters |
| 543 .forEach((ParameterElement element) { | 535 .forEach((ParameterElement element) { |
| 544 int foundIndex = namedArguments.indexOf(element.name); | 536 int foundIndex = namedArguments.indexOf(element.name); |
| 545 if (foundIndex != -1) { | 537 if (foundIndex != -1) { |
| 546 result.add(compiledNamedArguments[foundIndex]); | 538 result.add(compiledArguments[offset + foundIndex]); |
| 547 } else { | 539 } else { |
| 548 result.add(compileDefaultValue(element)); | 540 result.add(compileDefaultValue(element)); |
| 549 } | 541 } |
| 550 }); | 542 }); |
| 551 } | 543 } |
| 552 return result; | 544 return result; |
| 553 } | 545 } |
| 554 | 546 |
| 555 /// This is a version of [makeArgumentsList] that works for a `Link` | 547 /// This is a version of [makeArgumentsList] that works for a `Link` |
| 556 /// representation of arguments. | 548 /// representation of arguments. |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 | 842 |
| 851 Selector extendIfReachesAll(Compiler compiler) { | 843 Selector extendIfReachesAll(Compiler compiler) { |
| 852 bool canReachAll = compiler.enabledInvokeOn | 844 bool canReachAll = compiler.enabledInvokeOn |
| 853 && mask.needsNoSuchMethodHandling(this, compiler.world); | 845 && mask.needsNoSuchMethodHandling(this, compiler.world); |
| 854 return canReachAll | 846 return canReachAll |
| 855 ? new TypedSelector( | 847 ? new TypedSelector( |
| 856 compiler.typesTask.dynamicType, this, compiler.world) | 848 compiler.typesTask.dynamicType, this, compiler.world) |
| 857 : this; | 849 : this; |
| 858 } | 850 } |
| 859 } | 851 } |
| OLD | NEW |