| 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 elements; | 5 library elements; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/resolution.dart' show Resolution; | 8 import '../common/resolution.dart' show Resolution; |
| 9 import '../constants/constructors.dart'; | 9 import '../constants/constructors.dart'; |
| 10 import '../constants/expressions.dart'; | 10 import '../constants/expressions.dart'; |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 static List<T> makeArgumentsList<T>( | 739 static List<T> makeArgumentsList<T>( |
| 740 CallStructure callStructure, | 740 CallStructure callStructure, |
| 741 Link<Node> arguments, | 741 Link<Node> arguments, |
| 742 FunctionElement element, | 742 FunctionElement element, |
| 743 T compileArgument(Node argument), | 743 T compileArgument(Node argument), |
| 744 T compileDefaultValue(ParameterElement element)) { | 744 T compileDefaultValue(ParameterElement element)) { |
| 745 assert(element.isImplementation, failedAt(element)); | 745 assert(element.isImplementation, failedAt(element)); |
| 746 List<T> result = <T>[]; | 746 List<T> result = <T>[]; |
| 747 | 747 |
| 748 FunctionSignature parameters = element.functionSignature; | 748 FunctionSignature parameters = element.functionSignature; |
| 749 parameters.forEachRequiredParameter((ParameterElement element) { | 749 parameters.forEachRequiredParameter((_) { |
| 750 result.add(compileArgument(arguments.head)); | 750 result.add(compileArgument(arguments.head)); |
| 751 arguments = arguments.tail; | 751 arguments = arguments.tail; |
| 752 }); | 752 }); |
| 753 | 753 |
| 754 if (!parameters.optionalParametersAreNamed) { | 754 if (!parameters.optionalParametersAreNamed) { |
| 755 parameters.forEachOptionalParameter((ParameterElement element) { | 755 parameters.forEachOptionalParameter((_element) { |
| 756 ParameterElement element = _element; |
| 756 if (!arguments.isEmpty) { | 757 if (!arguments.isEmpty) { |
| 757 result.add(compileArgument(arguments.head)); | 758 result.add(compileArgument(arguments.head)); |
| 758 arguments = arguments.tail; | 759 arguments = arguments.tail; |
| 759 } else { | 760 } else { |
| 760 result.add(compileDefaultValue(element)); | 761 result.add(compileDefaultValue(element)); |
| 761 } | 762 } |
| 762 }); | 763 }); |
| 763 } else { | 764 } else { |
| 764 // Visit named arguments and add them into a temporary list. | 765 // Visit named arguments and add them into a temporary list. |
| 765 List compiledNamedArguments = []; | 766 List compiledNamedArguments = []; |
| 766 for (; !arguments.isEmpty; arguments = arguments.tail) { | 767 for (; !arguments.isEmpty; arguments = arguments.tail) { |
| 767 NamedArgument namedArgument = arguments.head; | 768 NamedArgument namedArgument = arguments.head; |
| 768 compiledNamedArguments.add(compileArgument(namedArgument.expression)); | 769 compiledNamedArguments.add(compileArgument(namedArgument.expression)); |
| 769 } | 770 } |
| 770 // Iterate over the optional parameters of the signature, and try to | 771 // Iterate over the optional parameters of the signature, and try to |
| 771 // find them in [compiledNamedArguments]. If found, we use the | 772 // find them in [compiledNamedArguments]. If found, we use the |
| 772 // value in the temporary list, otherwise the default value. | 773 // value in the temporary list, otherwise the default value. |
| 773 parameters.orderedOptionalParameters.forEach((ParameterElement element) { | 774 parameters.orderedOptionalParameters.forEach((_element) { |
| 775 ParameterElement element = _element; |
| 774 int foundIndex = callStructure.namedArguments.indexOf(element.name); | 776 int foundIndex = callStructure.namedArguments.indexOf(element.name); |
| 775 if (foundIndex != -1) { | 777 if (foundIndex != -1) { |
| 776 result.add(compiledNamedArguments[foundIndex]); | 778 result.add(compiledNamedArguments[foundIndex]); |
| 777 } else { | 779 } else { |
| 778 result.add(compileDefaultValue(element)); | 780 result.add(compileDefaultValue(element)); |
| 779 } | 781 } |
| 780 }); | 782 }); |
| 781 } | 783 } |
| 782 return result; | 784 return result; |
| 783 } | 785 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 808 "Cannot compute arguments to malformed constructor: " | 810 "Cannot compute arguments to malformed constructor: " |
| 809 "$caller calling $callee.")); | 811 "$caller calling $callee.")); |
| 810 | 812 |
| 811 FunctionSignature signature = caller.functionSignature; | 813 FunctionSignature signature = caller.functionSignature; |
| 812 Map<Node, ParameterElement> mapping = <Node, ParameterElement>{}; | 814 Map<Node, ParameterElement> mapping = <Node, ParameterElement>{}; |
| 813 | 815 |
| 814 // TODO(ngeoffray): This is a hack that fakes up AST nodes, so | 816 // TODO(ngeoffray): This is a hack that fakes up AST nodes, so |
| 815 // that we can call [addArgumentsToList]. | 817 // that we can call [addArgumentsToList]. |
| 816 Link<Node> computeCallNodesFromParameters() { | 818 Link<Node> computeCallNodesFromParameters() { |
| 817 LinkBuilder<Node> builder = new LinkBuilder<Node>(); | 819 LinkBuilder<Node> builder = new LinkBuilder<Node>(); |
| 818 signature.forEachRequiredParameter((ParameterElement element) { | 820 signature.forEachRequiredParameter((_element) { |
| 821 ParameterElement element = _element; |
| 819 Node node = element.node; | 822 Node node = element.node; |
| 820 mapping[node] = element; | 823 mapping[node] = element; |
| 821 builder.addLast(node); | 824 builder.addLast(node); |
| 822 }); | 825 }); |
| 823 if (signature.optionalParametersAreNamed) { | 826 if (signature.optionalParametersAreNamed) { |
| 824 signature.forEachOptionalParameter((ParameterElement element) { | 827 signature.forEachOptionalParameter((_element) { |
| 828 ParameterElement element = _element; |
| 825 mapping[element.initializer] = element; | 829 mapping[element.initializer] = element; |
| 826 builder.addLast(new NamedArgument(null, null, element.initializer)); | 830 builder.addLast(new NamedArgument(null, null, element.initializer)); |
| 827 }); | 831 }); |
| 828 } else { | 832 } else { |
| 829 signature.forEachOptionalParameter((ParameterElement element) { | 833 signature.forEachOptionalParameter((_element) { |
| 834 ParameterElement element = _element; |
| 830 Node node = element.node; | 835 Node node = element.node; |
| 831 mapping[node] = element; | 836 mapping[node] = element; |
| 832 builder.addLast(node); | 837 builder.addLast(node); |
| 833 }); | 838 }); |
| 834 } | 839 } |
| 835 return builder.toLink(); | 840 return builder.toLink(); |
| 836 } | 841 } |
| 837 | 842 |
| 838 T internalCompileArgument(Node node) { | 843 T internalCompileArgument(Node node) { |
| 839 return compileArgument(mapping[node]); | 844 return compileArgument(mapping[node]); |
| (...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1865 /// by a field. | 1870 /// by a field. |
| 1866 bool get isDeclaredByField; | 1871 bool get isDeclaredByField; |
| 1867 | 1872 |
| 1868 /// Returns `true` if this member is abstract. | 1873 /// Returns `true` if this member is abstract. |
| 1869 bool get isAbstract; | 1874 bool get isAbstract; |
| 1870 | 1875 |
| 1871 /// If abstract, [implementation] points to the overridden concrete member, | 1876 /// If abstract, [implementation] points to the overridden concrete member, |
| 1872 /// if any. Otherwise [implementation] points to the member itself. | 1877 /// if any. Otherwise [implementation] points to the member itself. |
| 1873 Member get implementation; | 1878 Member get implementation; |
| 1874 } | 1879 } |
| OLD | NEW |