| 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 name == element.name || | 388 name == element.name || |
| 389 name == 'assert' && world.isAssertMethod(element); | 389 name == 'assert' && world.isAssertMethod(element); |
| 390 } | 390 } |
| 391 | 391 |
| 392 bool applies(Element element, World world) { | 392 bool applies(Element element, World world) { |
| 393 if (!sameNameHack(element, world)) return false; | 393 if (!sameNameHack(element, world)) return false; |
| 394 return appliesUnnamed(element, world); | 394 return appliesUnnamed(element, world); |
| 395 } | 395 } |
| 396 | 396 |
| 397 /** | 397 /** |
| 398 * Fills [list] with the arguments in a defined order. | 398 * Fills [list] with the arguments in the normalized order. |
| 399 * | 399 * |
| 400 * [compileArgument] is a function that returns a compiled version | 400 * [compileArgument] is a function that returns a compiled version |
| 401 * of an argument located in [arguments]. | 401 * of an argument located in [arguments]. |
| 402 * | 402 * |
| 403 * [compileConstant] is a function that returns a compiled constant | 403 * [compileDefaultValue] is a function that returns a compiled constant |
| 404 * of an optional argument that is not in [arguments]. | 404 * of an optional argument that is not in [arguments]. |
| 405 * | 405 * |
| 406 * Returns [:true:] if the selector and the [element] match; [:false:] | 406 * Returns [:true:] if the selector and the [element] match; [:false:] |
| 407 * otherwise. | 407 * otherwise. |
| 408 * | 408 * |
| 409 * Invariant: [element] must be the implementation element. | 409 * Invariant: [element] must be the implementation element. |
| 410 */ | 410 */ |
| 411 bool addArgumentsToList(Link<Node> arguments, | 411 /*<T>*/ bool addArgumentsToList( |
| 412 List list, | 412 Link<Node> arguments, |
| 413 FunctionElement element, | 413 List/*<T>*/ list, |
| 414 compileArgument(Node argument), | 414 FunctionElement element, |
| 415 compileConstant(Element element), | 415 /*T*/ compileArgument(Node argument), |
| 416 World world) { | 416 /*T*/ compileDefaultValue(ParameterElement element), |
| 417 World world) { |
| 417 assert(invariant(element, element.isImplementation)); | 418 assert(invariant(element, element.isImplementation)); |
| 418 if (!this.applies(element, world)) return false; | 419 if (!this.applies(element, world)) return false; |
| 419 | 420 |
| 420 FunctionSignature parameters = element.functionSignature; | 421 FunctionSignature parameters = element.functionSignature; |
| 421 parameters.forEachRequiredParameter((element) { | 422 parameters.forEachRequiredParameter((ParameterElement element) { |
| 422 list.add(compileArgument(arguments.head)); | 423 list.add(compileArgument(arguments.head)); |
| 423 arguments = arguments.tail; | 424 arguments = arguments.tail; |
| 424 }); | 425 }); |
| 425 | 426 |
| 426 if (!parameters.optionalParametersAreNamed) { | 427 if (!parameters.optionalParametersAreNamed) { |
| 427 parameters.forEachOptionalParameter((element) { | 428 parameters.forEachOptionalParameter((ParameterElement element) { |
| 428 if (!arguments.isEmpty) { | 429 if (!arguments.isEmpty) { |
| 429 list.add(compileArgument(arguments.head)); | 430 list.add(compileArgument(arguments.head)); |
| 430 arguments = arguments.tail; | 431 arguments = arguments.tail; |
| 431 } else { | 432 } else { |
| 432 list.add(compileConstant(element)); | 433 list.add(compileDefaultValue(element)); |
| 433 } | 434 } |
| 434 }); | 435 }); |
| 435 } else { | 436 } else { |
| 436 // Visit named arguments and add them into a temporary list. | 437 // Visit named arguments and add them into a temporary list. |
| 437 List compiledNamedArguments = []; | 438 List compiledNamedArguments = []; |
| 438 for (; !arguments.isEmpty; arguments = arguments.tail) { | 439 for (; !arguments.isEmpty; arguments = arguments.tail) { |
| 439 NamedArgument namedArgument = arguments.head; | 440 NamedArgument namedArgument = arguments.head; |
| 440 compiledNamedArguments.add(compileArgument(namedArgument.expression)); | 441 compiledNamedArguments.add(compileArgument(namedArgument.expression)); |
| 441 } | 442 } |
| 442 // Iterate over the optional parameters of the signature, and try to | 443 // Iterate over the optional parameters of the signature, and try to |
| 443 // find them in [compiledNamedArguments]. If found, we use the | 444 // find them in [compiledNamedArguments]. If found, we use the |
| 444 // value in the temporary list, otherwise the default value. | 445 // value in the temporary list, otherwise the default value. |
| 445 parameters.orderedOptionalParameters.forEach((element) { | 446 parameters.orderedOptionalParameters.forEach((ParameterElement element) { |
| 446 int foundIndex = namedArguments.indexOf(element.name); | 447 int foundIndex = namedArguments.indexOf(element.name); |
| 447 if (foundIndex != -1) { | 448 if (foundIndex != -1) { |
| 448 list.add(compiledNamedArguments[foundIndex]); | 449 list.add(compiledNamedArguments[foundIndex]); |
| 449 } else { | 450 } else { |
| 450 list.add(compileConstant(element)); | 451 list.add(compileDefaultValue(element)); |
| 451 } | 452 } |
| 452 }); | 453 }); |
| 453 } | 454 } |
| 454 return true; | 455 return true; |
| 455 } | 456 } |
| 456 | 457 |
| 457 /** | 458 /** |
| 458 * Fills [list] with the arguments in the order expected by | 459 * Fills [list] with the arguments in the order expected by |
| 459 * [callee], and where [caller] is a synthesized element | 460 * [callee], and where [caller] is a synthesized element |
| 460 * | 461 * |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 | 696 |
| 696 Selector extendIfReachesAll(Compiler compiler) { | 697 Selector extendIfReachesAll(Compiler compiler) { |
| 697 bool canReachAll = compiler.enabledInvokeOn | 698 bool canReachAll = compiler.enabledInvokeOn |
| 698 && mask.needsNoSuchMethodHandling(this, compiler.world); | 699 && mask.needsNoSuchMethodHandling(this, compiler.world); |
| 699 return canReachAll | 700 return canReachAll |
| 700 ? new TypedSelector( | 701 ? new TypedSelector( |
| 701 compiler.typesTask.dynamicType, this, compiler.world) | 702 compiler.typesTask.dynamicType, this, compiler.world) |
| 702 : this; | 703 : this; |
| 703 } | 704 } |
| 704 } | 705 } |
| OLD | NEW |