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

Side by Side Diff: pkg/compiler/lib/src/universe/call_structure.dart

Issue 1859343004: dartfmt pkg/compiler (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 dart2js.call_structure; 5 library dart2js.call_structure;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/names.dart' show 8 import '../common/names.dart' show Identifiers, Names, Selectors;
9 Identifiers,
10 Names,
11 Selectors;
12 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
13 import '../tree/tree.dart'; 10 import '../tree/tree.dart';
14 import '../util/util.dart'; 11 import '../util/util.dart';
15 12
16 import 'selector.dart' show 13 import 'selector.dart' show Selector;
17 Selector;
18 14
19 /// The structure of the arguments at a call-site. 15 /// The structure of the arguments at a call-site.
20 // TODO(johnniwinther): Should these be cached? 16 // TODO(johnniwinther): Should these be cached?
21 // TODO(johnniwinther): Should isGetter/isSetter be part of the call structure 17 // TODO(johnniwinther): Should isGetter/isSetter be part of the call structure
22 // instead of the selector? 18 // instead of the selector?
23 class CallStructure { 19 class CallStructure {
24 static const CallStructure NO_ARGS = const CallStructure.unnamed(0); 20 static const CallStructure NO_ARGS = const CallStructure.unnamed(0);
25 static const CallStructure ONE_ARG = const CallStructure.unnamed(1); 21 static const CallStructure ONE_ARG = const CallStructure.unnamed(1);
26 static const CallStructure TWO_ARGS = const CallStructure.unnamed(2); 22 static const CallStructure TWO_ARGS = const CallStructure.unnamed(2);
27 23
(...skipping 29 matching lines...) Expand all
57 53
58 /// A description of the argument structure. 54 /// A description of the argument structure.
59 String structureToString() => 'arity=$argumentCount'; 55 String structureToString() => 'arity=$argumentCount';
60 56
61 String toString() => 'CallStructure(${structureToString()})'; 57 String toString() => 'CallStructure(${structureToString()})';
62 58
63 Selector get callSelector => new Selector.call(Names.call, this); 59 Selector get callSelector => new Selector.call(Names.call, this);
64 60
65 bool match(CallStructure other) { 61 bool match(CallStructure other) {
66 if (identical(this, other)) return true; 62 if (identical(this, other)) return true;
67 return this.argumentCount == other.argumentCount 63 return this.argumentCount == other.argumentCount &&
68 && this.namedArgumentCount == other.namedArgumentCount 64 this.namedArgumentCount == other.namedArgumentCount &&
69 && sameNames(this.namedArguments, other.namedArguments); 65 sameNames(this.namedArguments, other.namedArguments);
70 } 66 }
71 67
72 // TODO(johnniwinther): Cache hash code? 68 // TODO(johnniwinther): Cache hash code?
73 int get hashCode { 69 int get hashCode {
74 return Hashing.listHash(namedArguments, 70 return Hashing.listHash(namedArguments,
75 Hashing.objectHash(argumentCount, namedArguments.length)); 71 Hashing.objectHash(argumentCount, namedArguments.length));
76 } 72 }
77 73
78 bool operator ==(other) { 74 bool operator ==(other) {
79 if (other is! CallStructure) return false; 75 if (other is! CallStructure) return false;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 * 169 *
174 * [compileArgument] is a function that returns a compiled version 170 * [compileArgument] is a function that returns a compiled version
175 * of a parameter of [callee]. 171 * of a parameter of [callee].
176 * 172 *
177 * [compileConstant] is a function that returns a compiled constant 173 * [compileConstant] is a function that returns a compiled constant
178 * of an optional argument that is not in the parameters of [callee]. 174 * of an optional argument that is not in the parameters of [callee].
179 * 175 *
180 * Returns [:true:] if the signature of the [caller] matches the 176 * Returns [:true:] if the signature of the [caller] matches the
181 * signature of the [callee], [:false:] otherwise. 177 * signature of the [callee], [:false:] otherwise.
182 */ 178 */
183 static /*<T>*/ bool addForwardingElementArgumentsToList( 179 static/*<T>*/ bool addForwardingElementArgumentsToList(
184 ConstructorElement caller, 180 ConstructorElement caller,
185 List/*<T>*/ list, 181 List/*<T>*/ list,
186 ConstructorElement callee, 182 ConstructorElement callee,
187 /*T*/ compileArgument(ParameterElement element), 183 /*T*/ compileArgument(ParameterElement element),
188 /*T*/ compileConstant(ParameterElement element)) { 184 /*T*/ compileConstant(ParameterElement element)) {
189 assert(invariant(caller, !callee.isMalformed, 185 assert(invariant(caller, !callee.isMalformed,
190 message: "Cannot compute arguments to malformed constructor: " 186 message: "Cannot compute arguments to malformed constructor: "
191 "$caller calling $callee.")); 187 "$caller calling $callee."));
192 188
193 FunctionSignature signature = caller.functionSignature; 189 FunctionSignature signature = caller.functionSignature;
194 Map<Node, ParameterElement> mapping = <Node, ParameterElement>{}; 190 Map<Node, ParameterElement> mapping = <Node, ParameterElement>{};
195 191
196 // TODO(ngeoffray): This is a hack that fakes up AST nodes, so 192 // TODO(ngeoffray): This is a hack that fakes up AST nodes, so
197 // that we can call [addArgumentsToList]. 193 // that we can call [addArgumentsToList].
198 Link<Node> computeCallNodesFromParameters() { 194 Link<Node> computeCallNodesFromParameters() {
199 LinkBuilder<Node> builder = new LinkBuilder<Node>(); 195 LinkBuilder<Node> builder = new LinkBuilder<Node>();
200 signature.forEachRequiredParameter((ParameterElement element) { 196 signature.forEachRequiredParameter((ParameterElement element) {
201 Node node = element.node; 197 Node node = element.node;
(...skipping 27 matching lines...) Expand all
229 if (signature.optionalParametersAreNamed) { 225 if (signature.optionalParametersAreNamed) {
230 namedParameters = 226 namedParameters =
231 signature.optionalParameters.map((e) => e.name).toList(); 227 signature.optionalParameters.map((e) => e.name).toList();
232 } 228 }
233 CallStructure callStructure = 229 CallStructure callStructure =
234 new CallStructure(signature.parameterCount, namedParameters); 230 new CallStructure(signature.parameterCount, namedParameters);
235 if (!callStructure.signatureApplies(signature)) { 231 if (!callStructure.signatureApplies(signature)) {
236 return false; 232 return false;
237 } 233 }
238 list.addAll(callStructure.makeArgumentsList( 234 list.addAll(callStructure.makeArgumentsList(
239 nodes, 235 nodes, callee, internalCompileArgument, compileConstant));
240 callee,
241 internalCompileArgument,
242 compileConstant));
243 236
244 return true; 237 return true;
245 } 238 }
246 239
247 static bool sameNames(List<String> first, List<String> second) { 240 static bool sameNames(List<String> first, List<String> second) {
248 for (int i = 0; i < first.length; i++) { 241 for (int i = 0; i < first.length; i++) {
249 if (first[i] != second[i]) return false; 242 if (first[i] != second[i]) return false;
250 } 243 }
251 return true; 244 return true;
252 } 245 }
(...skipping 30 matching lines...) Expand all
283 return first.compareTo(second); 276 return first.compareTo(second);
284 }); 277 });
285 return _orderedNamedArguments; 278 return _orderedNamedArguments;
286 } 279 }
287 280
288 @override 281 @override
289 String structureToString() { 282 String structureToString() {
290 return 'arity=$argumentCount, named=[${namedArguments.join(', ')}]'; 283 return 'arity=$argumentCount, named=[${namedArguments.join(', ')}]';
291 } 284 }
292 } 285 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/types/value_type_mask.dart ('k') | pkg/compiler/lib/src/universe/class_set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698