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

Side by Side Diff: frog/leg/universe.dart

Issue 9316026: Support named arguments for dynamic calls. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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
« no previous file with comments | « frog/leg/ssa/js_names.dart ('k') | tests/language/language-leg.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 class Universe { 5 class Universe {
6 final Element scope; 6 final Element scope;
7 7
8 Map<SourceString, Element> elements; 8 Map<SourceString, Element> elements;
9 Map<Element, String> generatedCode; 9 Map<Element, String> generatedCode;
10 Map<Element, String> generatedBailoutCode; 10 Map<Element, String> generatedBailoutCode;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 static final Selector UNARY_OPERATOR = 72 static final Selector UNARY_OPERATOR =
73 const Selector(SelectorKind.OPERATOR, 0); 73 const Selector(SelectorKind.OPERATOR, 0);
74 static final Selector BINARY_OPERATOR = 74 static final Selector BINARY_OPERATOR =
75 const Selector(SelectorKind.OPERATOR, 1); 75 const Selector(SelectorKind.OPERATOR, 1);
76 static final Selector INDEX = const Selector(SelectorKind.INDEX, 1); 76 static final Selector INDEX = const Selector(SelectorKind.INDEX, 1);
77 static final Selector INDEX_SET = const Selector(SelectorKind.INDEX, 2); 77 static final Selector INDEX_SET = const Selector(SelectorKind.INDEX, 2);
78 static final Selector INDEX_AND_INDEX_SET = 78 static final Selector INDEX_AND_INDEX_SET =
79 const Selector(SelectorKind.INDEX, 2); 79 const Selector(SelectorKind.INDEX, 2);
80 static final Selector GETTER_AND_SETTER = 80 static final Selector GETTER_AND_SETTER =
81 const Selector(SelectorKind.SETTER, 1); 81 const Selector(SelectorKind.SETTER, 1);
82 static final Selector INVOCATION_0 = const Invocation(0); 82 static final Selector INVOCATION_0 =
83 const Selector(SelectorKind.INVOCATION, 0);
83 84
84 bool applies(Compiler compiler, FunctionElement element) { 85 bool applies(Compiler compiler, FunctionElement element) {
85 FunctionParameters parameters = element.computeParameters(compiler); 86 FunctionParameters parameters = element.computeParameters(compiler);
86 if (argumentCount > parameters.parameterCount) return false; 87 if (argumentCount > parameters.parameterCount) return false;
87 int requiredParameterCount = parameters.requiredParameterCount; 88 int requiredParameterCount = parameters.requiredParameterCount;
88 int optionalParameterCount = parameters.optionalParameterCount; 89 int optionalParameterCount = parameters.optionalParameterCount;
89 90
90 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty(); 91 bool hasOptionalParameters = !parameters.optionalParameters.isEmpty();
91 if (namedArguments.isEmpty()) { 92 if (namedArguments.isEmpty()) {
92 if (!hasOptionalParameters) { 93 if (!hasOptionalParameters) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 126 }
126 return true; 127 return true;
127 } 128 }
128 129
129 bool operator ==(other) { 130 bool operator ==(other) {
130 if (other is !Invocation) return false; 131 if (other is !Invocation) return false;
131 return argumentCount == other.argumentCount 132 return argumentCount == other.argumentCount
132 && namedArguments.length == other.namedArguments.length 133 && namedArguments.length == other.namedArguments.length
133 && sameNames(namedArguments, other.namedArguments); 134 && sameNames(namedArguments, other.namedArguments);
134 } 135 }
136
137 List<SourceString> getOrderedNamedArguments() => namedArguments;
138
139 String toString() => '$argumentCount';
135 } 140 }
136 141
137 class Invocation extends Selector { 142 class Invocation extends Selector {
138 final List<SourceString> namedArguments; 143 final List<SourceString> namedArguments;
144 List<SourceString> orderedNamedArguments;
139 int get namedArgumentCount() => namedArguments.length; 145 int get namedArgumentCount() => namedArguments.length;
140 int get positionalArgumentCount() => argumentCount - namedArgumentCount; 146 int get positionalArgumentCount() => argumentCount - namedArgumentCount;
141 147
142 const Invocation( 148 Invocation(int argumentCount,
143 int argumentCount, 149 [List<SourceString> names = const <SourceString>[]])
144 [List<SourceString> this.namedArguments = const <SourceString>[]]) 150 : super(SelectorKind.INVOCATION, argumentCount),
145 : super(SelectorKind.INVOCATION, argumentCount); 151 namedArguments = names,
152 orderedNamedArguments = const <SourceString>[];
153
154 String toString() {
155 StringBuffer buffer = new StringBuffer();
156 for (SourceString name in orderedNamedArguments) {
157 buffer.add('\$$name');
158 }
159 return '$argumentCount$buffer';
160 }
161
162 List<SourceString> getOrderedNamedArguments() {
163 if (namedArguments.isEmpty()) return namedArguments;
164 // We use the empty const List as a sentinel.
165 if (!orderedNamedArguments.isEmpty()) return namedArguments;
166
167 List<SourceString> list = new List<SourceString>.from(namedArguments);
168 list.sort((SourceString first, SourceString second) {
169 return first.stringValue.compareTo(second.stringValue);
170 });
171 orderedNamedArguments = list;
172 return orderedNamedArguments;
173 }
146 } 174 }
OLDNEW
« no previous file with comments | « frog/leg/ssa/js_names.dart ('k') | tests/language/language-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698