| 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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 int get hashCode { | 414 int get hashCode { |
| 415 return Hashing.listHash(namedArguments, | 415 return Hashing.listHash(namedArguments, |
| 416 Hashing.objectHash(argumentCount, namedArguments.length)); | 416 Hashing.objectHash(argumentCount, namedArguments.length)); |
| 417 } | 417 } |
| 418 | 418 |
| 419 bool operator ==(other) { | 419 bool operator ==(other) { |
| 420 if (other is! CallStructure) return false; | 420 if (other is! CallStructure) return false; |
| 421 return match(other); | 421 return match(other); |
| 422 } | 422 } |
| 423 | 423 |
| 424 bool signatureApplies(FunctionElement function) { | 424 bool signatureApplies(FunctionSignature parameters) { |
| 425 if (Elements.isUnresolved(function)) return false; | |
| 426 FunctionSignature parameters = function.functionSignature; | |
| 427 if (argumentCount > parameters.parameterCount) return false; | 425 if (argumentCount > parameters.parameterCount) return false; |
| 428 int requiredParameterCount = parameters.requiredParameterCount; | 426 int requiredParameterCount = parameters.requiredParameterCount; |
| 429 int optionalParameterCount = parameters.optionalParameterCount; | 427 int optionalParameterCount = parameters.optionalParameterCount; |
| 430 if (positionalArgumentCount < requiredParameterCount) return false; | 428 if (positionalArgumentCount < requiredParameterCount) return false; |
| 431 | 429 |
| 432 if (!parameters.optionalParametersAreNamed) { | 430 if (!parameters.optionalParametersAreNamed) { |
| 433 // We have already checked that the number of arguments are | 431 // We have already checked that the number of arguments are |
| 434 // not greater than the number of parameters. Therefore the | 432 // not greater than the number of parameters. Therefore the |
| 435 // number of positional arguments are not greater than the | 433 // number of positional arguments are not greater than the |
| 436 // number of parameters. | 434 // number of parameters. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 * | 520 * |
| 523 * Returns [:true:] if the signature of the [caller] matches the | 521 * Returns [:true:] if the signature of the [caller] matches the |
| 524 * signature of the [callee], [:false:] otherwise. | 522 * signature of the [callee], [:false:] otherwise. |
| 525 */ | 523 */ |
| 526 static /*<T>*/ bool addForwardingElementArgumentsToList( | 524 static /*<T>*/ bool addForwardingElementArgumentsToList( |
| 527 ConstructorElement caller, | 525 ConstructorElement caller, |
| 528 List/*<T>*/ list, | 526 List/*<T>*/ list, |
| 529 ConstructorElement callee, | 527 ConstructorElement callee, |
| 530 /*T*/ compileArgument(ParameterElement element), | 528 /*T*/ compileArgument(ParameterElement element), |
| 531 /*T*/ compileConstant(ParameterElement element)) { | 529 /*T*/ compileConstant(ParameterElement element)) { |
| 530 assert(invariant(caller, !callee.isErroneous, |
| 531 message: "Cannot compute arguments to erroneous constructor: " |
| 532 "$caller calling $callee.")); |
| 532 | 533 |
| 533 FunctionSignature signature = caller.functionSignature; | 534 FunctionSignature signature = caller.functionSignature; |
| 534 Map<Node, ParameterElement> mapping = <Node, ParameterElement>{}; | 535 Map<Node, ParameterElement> mapping = <Node, ParameterElement>{}; |
| 535 | 536 |
| 536 // TODO(ngeoffray): This is a hack that fakes up AST nodes, so | 537 // TODO(ngeoffray): This is a hack that fakes up AST nodes, so |
| 537 // that we can call [addArgumentsToList]. | 538 // that we can call [addArgumentsToList]. |
| 538 Link<Node> computeCallNodesFromParameters() { | 539 Link<Node> computeCallNodesFromParameters() { |
| 539 LinkBuilder<Node> builder = new LinkBuilder<Node>(); | 540 LinkBuilder<Node> builder = new LinkBuilder<Node>(); |
| 540 signature.forEachRequiredParameter((ParameterElement element) { | 541 signature.forEachRequiredParameter((ParameterElement element) { |
| 541 Node node = element.node; | 542 Node node = element.node; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 565 | 566 |
| 566 // Synthesize a structure for the call. | 567 // Synthesize a structure for the call. |
| 567 // TODO(ngeoffray): Should the resolver do it instead? | 568 // TODO(ngeoffray): Should the resolver do it instead? |
| 568 List<String> namedParameters; | 569 List<String> namedParameters; |
| 569 if (signature.optionalParametersAreNamed) { | 570 if (signature.optionalParametersAreNamed) { |
| 570 namedParameters = | 571 namedParameters = |
| 571 signature.optionalParameters.map((e) => e.name).toList(); | 572 signature.optionalParameters.map((e) => e.name).toList(); |
| 572 } | 573 } |
| 573 CallStructure callStructure = | 574 CallStructure callStructure = |
| 574 new CallStructure(signature.parameterCount, namedParameters); | 575 new CallStructure(signature.parameterCount, namedParameters); |
| 575 if (!callStructure.signatureApplies(callee)) { | 576 if (!callStructure.signatureApplies(signature)) { |
| 576 return false; | 577 return false; |
| 577 } | 578 } |
| 578 list.addAll(callStructure.makeArgumentsList( | 579 list.addAll(callStructure.makeArgumentsList( |
| 579 nodes, | 580 nodes, |
| 580 callee, | 581 callee, |
| 581 internalCompileArgument, | 582 internalCompileArgument, |
| 582 compileConstant)); | 583 compileConstant)); |
| 583 | 584 |
| 584 return true; | 585 return true; |
| 585 } | 586 } |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 return isSetter | 847 return isSetter |
| 847 ? !element.isFinal && !element.isConst | 848 ? !element.isFinal && !element.isConst |
| 848 : isGetter || isCall; | 849 : isGetter || isCall; |
| 849 } | 850 } |
| 850 if (isGetter) return true; | 851 if (isGetter) return true; |
| 851 if (isSetter) return false; | 852 if (isSetter) return false; |
| 852 return signatureApplies(element); | 853 return signatureApplies(element); |
| 853 } | 854 } |
| 854 | 855 |
| 855 bool signatureApplies(FunctionElement function) { | 856 bool signatureApplies(FunctionElement function) { |
| 856 return callStructure.signatureApplies(function); | 857 if (Elements.isUnresolved(function)) return false; |
| 858 return callStructure.signatureApplies(function.functionSignature); |
| 857 } | 859 } |
| 858 | 860 |
| 859 bool sameNameHack(Element element, World world) { | 861 bool sameNameHack(Element element, World world) { |
| 860 // TODO(ngeoffray): Remove workaround checks. | 862 // TODO(ngeoffray): Remove workaround checks. |
| 861 return element.isConstructor || | 863 return element.isConstructor || |
| 862 name == element.name || | 864 name == element.name || |
| 863 name == 'assert' && world.isAssertMethod(element); | 865 name == 'assert' && world.isAssertMethod(element); |
| 864 } | 866 } |
| 865 | 867 |
| 866 bool applies(Element element, World world) { | 868 bool applies(Element element, World world) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 884 // Add bits from the call structure. | 886 // Add bits from the call structure. |
| 885 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); | 887 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); |
| 886 } | 888 } |
| 887 | 889 |
| 888 String toString() { | 890 String toString() { |
| 889 return 'Selector($kind, $name, ${callStructure.structureToString()})'; | 891 return 'Selector($kind, $name, ${callStructure.structureToString()})'; |
| 890 } | 892 } |
| 891 | 893 |
| 892 Selector toCallSelector() => new Selector.callClosureFrom(this); | 894 Selector toCallSelector() => new Selector.callClosureFrom(this); |
| 893 } | 895 } |
| OLD | NEW |