| OLD | NEW |
| 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 Names; | 8 import '../common/names.dart' show Names; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../tree/tree.dart'; | 10 import '../tree/tree.dart'; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 const CallStructure.unnamed(this.argumentCount); | 32 const CallStructure.unnamed(this.argumentCount); |
| 33 | 33 |
| 34 factory CallStructure(int argumentCount, [List<String> namedArguments]) { | 34 factory CallStructure(int argumentCount, [List<String> namedArguments]) { |
| 35 if (namedArguments == null || namedArguments.isEmpty) { | 35 if (namedArguments == null || namedArguments.isEmpty) { |
| 36 return new CallStructure.unnamed(argumentCount); | 36 return new CallStructure.unnamed(argumentCount); |
| 37 } | 37 } |
| 38 return new NamedCallStructure(argumentCount, namedArguments); | 38 return new NamedCallStructure(argumentCount, namedArguments); |
| 39 } | 39 } |
| 40 | 40 |
| 41 /// Creates the [CallStructure] corresponding to calling [signature] as |
| 42 /// declared, that is, all named arguments are in the order of declaration. |
| 43 factory CallStructure.fromSignature(FunctionSignature signature) { |
| 44 List<String> namedParameters; |
| 45 if (signature.optionalParametersAreNamed) { |
| 46 namedParameters = |
| 47 signature.optionalParameters.map((e) => e.name).toList(); |
| 48 } |
| 49 return new CallStructure(signature.parameterCount, namedParameters); |
| 50 } |
| 51 |
| 41 /// `true` if this call has named arguments. | 52 /// `true` if this call has named arguments. |
| 42 bool get isNamed => false; | 53 bool get isNamed => false; |
| 43 | 54 |
| 44 /// `true` if this call has no named arguments. | 55 /// `true` if this call has no named arguments. |
| 45 bool get isUnnamed => true; | 56 bool get isUnnamed => true; |
| 46 | 57 |
| 47 /// The names of the named arguments in call-site order. | 58 /// The names of the named arguments in call-site order. |
| 48 List<String> get namedArguments => const <String>[]; | 59 List<String> get namedArguments => const <String>[]; |
| 49 | 60 |
| 50 /// The names of the named arguments in canonicalized order. | 61 /// The names of the named arguments in canonicalized order. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 224 } |
| 214 | 225 |
| 215 /*T*/ internalCompileArgument(Node node) { | 226 /*T*/ internalCompileArgument(Node node) { |
| 216 return compileArgument(mapping[node]); | 227 return compileArgument(mapping[node]); |
| 217 } | 228 } |
| 218 | 229 |
| 219 Link<Node> nodes = computeCallNodesFromParameters(); | 230 Link<Node> nodes = computeCallNodesFromParameters(); |
| 220 | 231 |
| 221 // Synthesize a structure for the call. | 232 // Synthesize a structure for the call. |
| 222 // TODO(ngeoffray): Should the resolver do it instead? | 233 // TODO(ngeoffray): Should the resolver do it instead? |
| 223 List<String> namedParameters; | 234 CallStructure callStructure = new CallStructure.fromSignature(signature); |
| 224 if (signature.optionalParametersAreNamed) { | |
| 225 namedParameters = | |
| 226 signature.optionalParameters.map((e) => e.name).toList(); | |
| 227 } | |
| 228 CallStructure callStructure = | |
| 229 new CallStructure(signature.parameterCount, namedParameters); | |
| 230 if (!callStructure.signatureApplies(signature)) { | 235 if (!callStructure.signatureApplies(signature)) { |
| 231 return false; | 236 return false; |
| 232 } | 237 } |
| 233 list.addAll(callStructure.makeArgumentsList( | 238 list.addAll(callStructure.makeArgumentsList( |
| 234 nodes, callee, internalCompileArgument, compileConstant)); | 239 nodes, callee, internalCompileArgument, compileConstant)); |
| 235 | 240 |
| 236 return true; | 241 return true; |
| 237 } | 242 } |
| 238 | 243 |
| 239 static bool sameNames(List<String> first, List<String> second) { | 244 static bool sameNames(List<String> first, List<String> second) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 return first.compareTo(second); | 280 return first.compareTo(second); |
| 276 }); | 281 }); |
| 277 return _orderedNamedArguments; | 282 return _orderedNamedArguments; |
| 278 } | 283 } |
| 279 | 284 |
| 280 @override | 285 @override |
| 281 String structureToString() { | 286 String structureToString() { |
| 282 return 'arity=$argumentCount, named=[${namedArguments.join(', ')}]'; | 287 return 'arity=$argumentCount, named=[${namedArguments.join(', ')}]'; |
| 283 } | 288 } |
| 284 } | 289 } |
| OLD | NEW |