Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: pkg/compiler/lib/src/elements/modelx.dart

Issue 1146943002: Change Link to List in FunctionSignature. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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.modelx; 5 library elements.modelx;
6 6
7 import 'elements.dart'; 7 import 'elements.dart';
8 import '../constants/expressions.dart'; 8 import '../constants/expressions.dart';
9 import '../constants/constructors.dart'; 9 import '../constants/constructors.dart';
10 import '../helpers/helpers.dart'; // Included for debug helpers. 10 import '../helpers/helpers.dart'; // Included for debug helpers.
(...skipping 1731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 bool get isAbstract { 1742 bool get isAbstract {
1743 return getter != null && getter.isAbstract 1743 return getter != null && getter.isAbstract
1744 || setter != null && setter.isAbstract; 1744 || setter != null && setter.isAbstract;
1745 } 1745 }
1746 } 1746 }
1747 1747
1748 // TODO(johnniwinther): [FunctionSignature] should be merged with 1748 // TODO(johnniwinther): [FunctionSignature] should be merged with
1749 // [FunctionType]. 1749 // [FunctionType].
1750 // TODO(karlklose): all these lists should have element type [FormalElement]. 1750 // TODO(karlklose): all these lists should have element type [FormalElement].
1751 class FunctionSignatureX implements FunctionSignature { 1751 class FunctionSignatureX implements FunctionSignature {
1752 final Link<Element> requiredParameters; 1752 final List<Element> requiredParameters;
1753 final Link<Element> optionalParameters; 1753 final List<Element> optionalParameters;
1754 final int requiredParameterCount; 1754 final int requiredParameterCount;
1755 final int optionalParameterCount; 1755 final int optionalParameterCount;
1756 final bool optionalParametersAreNamed; 1756 final bool optionalParametersAreNamed;
1757 final List<Element> orderedOptionalParameters; 1757 final List<Element> orderedOptionalParameters;
1758 final FunctionType type; 1758 final FunctionType type;
1759 final bool hasOptionalParameters; 1759 final bool hasOptionalParameters;
1760 1760
1761 FunctionSignatureX({this.requiredParameters: const Link<Element>(), 1761 FunctionSignatureX({this.requiredParameters: const <Element>[],
1762 this.requiredParameterCount: 0, 1762 this.requiredParameterCount: 0,
1763 Link<Element> optionalParameters: const Link<Element>(), 1763 List<Element> optionalParameters: const <Element>[],
1764 this.optionalParameterCount: 0, 1764 this.optionalParameterCount: 0,
1765 this.optionalParametersAreNamed: false, 1765 this.optionalParametersAreNamed: false,
1766 this.orderedOptionalParameters: const <Element>[], 1766 this.orderedOptionalParameters: const <Element>[],
1767 this.type}) 1767 this.type})
1768 : optionalParameters = optionalParameters, 1768 : optionalParameters = optionalParameters,
1769 hasOptionalParameters = !optionalParameters.isEmpty; 1769 hasOptionalParameters = !optionalParameters.isEmpty;
1770 1770
1771 void forEachRequiredParameter(void function(Element parameter)) { 1771 void forEachRequiredParameter(void function(Element parameter)) {
1772 for (Link<Element> link = requiredParameters; 1772 requiredParameters.forEach(function);
1773 !link.isEmpty;
1774 link = link.tail) {
1775 function(link.head);
1776 }
1777 } 1773 }
1778 1774
1779 void forEachOptionalParameter(void function(Element parameter)) { 1775 void forEachOptionalParameter(void function(Element parameter)) {
1780 for (Link<Element> link = optionalParameters; 1776 optionalParameters.forEach(function);
1781 !link.isEmpty;
1782 link = link.tail) {
1783 function(link.head);
1784 }
1785 } 1777 }
1786 1778
1787 Element get firstOptionalParameter => optionalParameters.head; 1779 Element get firstOptionalParameter => optionalParameters.first;
1788 1780
1789 void forEachParameter(void function(Element parameter)) { 1781 void forEachParameter(void function(Element parameter)) {
1790 forEachRequiredParameter(function); 1782 forEachRequiredParameter(function);
1791 forEachOptionalParameter(function); 1783 forEachOptionalParameter(function);
1792 } 1784 }
1793 1785
1794 void orderedForEachParameter(void function(Element parameter)) { 1786 void orderedForEachParameter(void function(Element parameter)) {
1795 forEachRequiredParameter(function); 1787 forEachRequiredParameter(function);
1796 orderedOptionalParameters.forEach(function); 1788 orderedOptionalParameters.forEach(function);
1797 } 1789 }
1798 1790
1799 int get parameterCount => requiredParameterCount + optionalParameterCount; 1791 int get parameterCount => requiredParameterCount + optionalParameterCount;
1800 1792
1801 /** 1793 /**
1802 * Check whether a function with this signature can be used instead of a 1794 * Check whether a function with this signature can be used instead of a
1803 * function with signature [signature] without causing a `noSuchMethod` 1795 * function with signature [signature] without causing a `noSuchMethod`
1804 * exception/call. 1796 * exception/call.
1805 */ 1797 */
1806 bool isCompatibleWith(FunctionSignature signature) { 1798 bool isCompatibleWith(FunctionSignature signature) {
1807 if (optionalParametersAreNamed) { 1799 if (optionalParametersAreNamed) {
1808 if (!signature.optionalParametersAreNamed) { 1800 if (!signature.optionalParametersAreNamed) {
1809 return requiredParameterCount == signature.parameterCount; 1801 return requiredParameterCount == signature.parameterCount;
1810 } 1802 }
1811 // If both signatures have named parameters, then they must have 1803 // If both signatures have named parameters, then they must have
1812 // the same number of required parameters, and the names in 1804 // the same number of required parameters, and the names in
1813 // [signature] must all be in [:this:]. 1805 // [signature] must all be in [:this:].
1814 if (requiredParameterCount != signature.requiredParameterCount) { 1806 if (requiredParameterCount != signature.requiredParameterCount) {
1815 return false; 1807 return false;
1816 } 1808 }
1817 Set<String> names = optionalParameters.mapToSet( 1809 Set<String> names = optionalParameters.map(
1818 (Element element) => element.name); 1810 (Element element) => element.name).toSet();
1819 for (Element namedParameter in signature.optionalParameters) { 1811 for (Element namedParameter in signature.optionalParameters) {
1820 if (!names.contains(namedParameter.name)) { 1812 if (!names.contains(namedParameter.name)) {
1821 return false; 1813 return false;
1822 } 1814 }
1823 } 1815 }
1824 } else { 1816 } else {
1825 if (signature.optionalParametersAreNamed) return false; 1817 if (signature.optionalParametersAreNamed) return false;
1826 // There must be at least as many arguments as in the other signature, but 1818 // There must be at least as many arguments as in the other signature, but
1827 // this signature must not have more required parameters. Having more 1819 // this signature must not have more required parameters. Having more
1828 // optional parameters is not a problem, they simply are never provided 1820 // optional parameters is not a problem, they simply are never provided
(...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after
3225 AstElement get definingElement; 3217 AstElement get definingElement;
3226 3218
3227 bool get hasResolvedAst => definingElement.hasTreeElements; 3219 bool get hasResolvedAst => definingElement.hasTreeElements;
3228 3220
3229 ResolvedAst get resolvedAst { 3221 ResolvedAst get resolvedAst {
3230 return new ResolvedAst(declaration, 3222 return new ResolvedAst(declaration,
3231 definingElement.node, definingElement.treeElements); 3223 definingElement.node, definingElement.treeElements);
3232 } 3224 }
3233 3225
3234 } 3226 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/inferrer/concrete_types_inferrer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698