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

Side by Side Diff: lib/compiler/implementation/elements/elements.dart

Issue 10991034: Order the parameters of a function at the definition site. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
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('dart:uri'); 7 #import('dart:uri');
8 8
9 #import('../tree/tree.dart'); 9 #import('../tree/tree.dart');
10 #import('../scanner/scannerlib.dart'); 10 #import('../scanner/scannerlib.dart');
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 938
939 // TODO(johnniwinther): [FunctionSignature] should be merged with 939 // TODO(johnniwinther): [FunctionSignature] should be merged with
940 // [FunctionType]. 940 // [FunctionType].
941 class FunctionSignature { 941 class FunctionSignature {
942 final Link<Element> requiredParameters; 942 final Link<Element> requiredParameters;
943 final Link<Element> optionalParameters; 943 final Link<Element> optionalParameters;
944 final DartType returnType; 944 final DartType returnType;
945 final int requiredParameterCount; 945 final int requiredParameterCount;
946 final int optionalParameterCount; 946 final int optionalParameterCount;
947 final bool optionalParametersAreNamed; 947 final bool optionalParametersAreNamed;
948
949 List<Element> _orderedOptionalParameters;
950
948 FunctionSignature(this.requiredParameters, 951 FunctionSignature(this.requiredParameters,
949 this.optionalParameters, 952 this.optionalParameters,
950 this.requiredParameterCount, 953 this.requiredParameterCount,
951 this.optionalParameterCount, 954 this.optionalParameterCount,
952 this.optionalParametersAreNamed, 955 this.optionalParametersAreNamed,
953 this.returnType); 956 this.returnType);
954 957
955 void forEachRequiredParameter(void function(Element parameter)) { 958 void forEachRequiredParameter(void function(Element parameter)) {
956 for (Link<Element> link = requiredParameters; 959 for (Link<Element> link = requiredParameters;
957 !link.isEmpty(); 960 !link.isEmpty();
958 link = link.tail) { 961 link = link.tail) {
959 function(link.head); 962 function(link.head);
960 } 963 }
961 } 964 }
962 965
963 void forEachOptionalParameter(void function(Element parameter)) { 966 void forEachOptionalParameter(void function(Element parameter)) {
964 for (Link<Element> link = optionalParameters; 967 for (Link<Element> link = optionalParameters;
965 !link.isEmpty(); 968 !link.isEmpty();
966 link = link.tail) { 969 link = link.tail) {
967 function(link.head); 970 function(link.head);
968 } 971 }
969 } 972 }
970 973
974 List<Element> get orderedOptionalParameters {
975 if (_orderedOptionalParameters != null) return _orderedOptionalParameters;
976 List<Element> list = <Element>[];
977 if (optionalParametersAreNamed) {
978 optionalParameters.forEach((Element element) { list.add(element); });
kasperl 2012/09/26 11:53:55 Can you get rid of this and use: list = new Li
ngeoffray 2012/09/26 12:28:47 Good point. Done.
979 list.sort((Element a, Element b) {
980 return a.name.slowToString().compareTo(b.name.slowToString());
981 });
982 } else {
983 optionalParameters.forEach((Element element) { list.add(element); });
984 }
985 _orderedOptionalParameters = list;
986 return list;
987 }
988
971 void forEachParameter(void function(Element parameter)) { 989 void forEachParameter(void function(Element parameter)) {
972 forEachRequiredParameter(function); 990 forEachRequiredParameter(function);
973 forEachOptionalParameter(function); 991 forEachOptionalParameter(function);
974 } 992 }
975 993
994 void orderedForEachParameter(void function(Element parameter)) {
995 forEachRequiredParameter(function);
996 orderedOptionalParameters.forEach(function);
997 }
998
976 int get parameterCount => requiredParameterCount + optionalParameterCount; 999 int get parameterCount => requiredParameterCount + optionalParameterCount;
977 } 1000 }
978 1001
979 class FunctionElement extends Element { 1002 class FunctionElement extends Element {
980 FunctionExpression cachedNode; 1003 FunctionExpression cachedNode;
981 DartType type; 1004 DartType type;
982 final Modifiers modifiers; 1005 final Modifiers modifiers;
983 1006
984 FunctionSignature functionSignature; 1007 FunctionSignature functionSignature;
985 1008
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 1834
1812 MetadataAnnotation ensureResolved(Compiler compiler) { 1835 MetadataAnnotation ensureResolved(Compiler compiler) {
1813 if (resolutionState == STATE_NOT_STARTED) { 1836 if (resolutionState == STATE_NOT_STARTED) {
1814 compiler.resolver.resolveMetadataAnnotation(this); 1837 compiler.resolver.resolveMetadataAnnotation(this);
1815 } 1838 }
1816 return this; 1839 return this;
1817 } 1840 }
1818 1841
1819 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 1842 String toString() => 'MetadataAnnotation($value, $resolutionState)';
1820 } 1843 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698