| 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.selector; | 5 library dart2js.selector; |
| 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' show Element, Elements, FunctionSignature; | 9 import '../elements/elements.dart' show Elements; |
| 10 import '../elements/entities.dart'; | 10 import '../elements/entities.dart'; |
| 11 import '../elements/names.dart'; | 11 import '../elements/names.dart'; |
| 12 import '../elements/operators.dart'; | 12 import '../elements/operators.dart'; |
| 13 import '../util/util.dart' show Hashing; | 13 import '../util/util.dart' show Hashing; |
| 14 import 'call_structure.dart' show CallStructure; | 14 import 'call_structure.dart' show CallStructure; |
| 15 | 15 |
| 16 class SelectorKind { | 16 class SelectorKind { |
| 17 final String name; | 17 final String name; |
| 18 final int hashCode; | 18 final int hashCode; |
| 19 const SelectorKind(this.name, this.hashCode); | 19 const SelectorKind(this.name, this.hashCode); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 assert(existing.hashCode == hashCode); | 105 assert(existing.hashCode == hashCode); |
| 106 return existing; | 106 return existing; |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 Selector result = | 109 Selector result = |
| 110 new Selector.internal(kind, name, callStructure, hashCode); | 110 new Selector.internal(kind, name, callStructure, hashCode); |
| 111 list.add(result); | 111 list.add(result); |
| 112 return result; | 112 return result; |
| 113 } | 113 } |
| 114 | 114 |
| 115 factory Selector.fromElement(Element element) { | 115 factory Selector.fromElement(MemberEntity element) { |
| 116 Name name = new Name(element.name, element.library); | 116 Name name = new Name(element.name, element.library); |
| 117 if (element.isFunction) { | 117 if (element.isFunction) { |
| 118 FunctionEntity function = element; |
| 118 if (name == Names.INDEX_NAME) { | 119 if (name == Names.INDEX_NAME) { |
| 119 return new Selector.index(); | 120 return new Selector.index(); |
| 120 } else if (name == Names.INDEX_SET_NAME) { | 121 } else if (name == Names.INDEX_SET_NAME) { |
| 121 return new Selector.indexSet(); | 122 return new Selector.indexSet(); |
| 122 } | 123 } |
| 123 FunctionSignature signature = | 124 CallStructure callStructure = function.parameterStructure.callStructure; |
| 124 element.asFunctionElement().functionSignature; | 125 if (isOperatorName(element.name)) { |
| 125 int arity = signature.parameterCount; | |
| 126 List<String> namedArguments = null; | |
| 127 if (signature.optionalParametersAreNamed) { | |
| 128 namedArguments = | |
| 129 signature.orderedOptionalParameters.map((e) => e.name).toList(); | |
| 130 } | |
| 131 if (element.isOperator) { | |
| 132 // Operators cannot have named arguments, however, that doesn't prevent | 126 // Operators cannot have named arguments, however, that doesn't prevent |
| 133 // a user from declaring such an operator. | 127 // a user from declaring such an operator. |
| 134 return new Selector(SelectorKind.OPERATOR, name, | 128 return new Selector(SelectorKind.OPERATOR, name, callStructure); |
| 135 new CallStructure(arity, namedArguments)); | |
| 136 } else { | 129 } else { |
| 137 return new Selector.call( | 130 return new Selector.call(name, callStructure); |
| 138 name, new CallStructure(arity, namedArguments)); | |
| 139 } | 131 } |
| 140 } else if (element.isSetter) { | 132 } else if (element.isSetter) { |
| 141 return new Selector.setter(name); | 133 return new Selector.setter(name); |
| 142 } else if (element.isGetter) { | 134 } else if (element.isGetter) { |
| 143 return new Selector.getter(name); | 135 return new Selector.getter(name); |
| 144 } else if (element.isField) { | 136 } else if (element.isField) { |
| 145 return new Selector.getter(name); | 137 return new Selector.getter(name); |
| 146 } else if (element.isConstructor) { | 138 } else if (element.isConstructor) { |
| 147 return new Selector.callConstructor(name); | 139 return new Selector.callConstructor(name); |
| 148 } else { | 140 } else { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 // Add bits from the call structure. | 256 // Add bits from the call structure. |
| 265 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); | 257 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); |
| 266 } | 258 } |
| 267 | 259 |
| 268 String toString() { | 260 String toString() { |
| 269 return 'Selector($kind, $name, ${callStructure.structureToString()})'; | 261 return 'Selector($kind, $name, ${callStructure.structureToString()})'; |
| 270 } | 262 } |
| 271 | 263 |
| 272 Selector toCallSelector() => new Selector.callClosureFrom(this); | 264 Selector toCallSelector() => new Selector.callClosureFrom(this); |
| 273 } | 265 } |
| OLD | NEW |