| 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' | 9 import '../elements/elements.dart' |
| 10 show | 10 show |
| 11 Element, | 11 Element, |
| 12 Elements, | 12 Elements, |
| 13 FunctionSignature, | 13 FunctionSignature, |
| 14 MemberElement, | 14 MemberElement, |
| 15 MethodElement, | 15 MethodElement, |
| 16 Name, | 16 Name, |
| 17 LibraryElement, | |
| 18 PublicName; | 17 PublicName; |
| 18 import '../elements/entities.dart'; |
| 19 import '../util/util.dart' show Hashing; | 19 import '../util/util.dart' show Hashing; |
| 20 import '../common/resolution.dart' show Target; | |
| 21 import 'call_structure.dart' show CallStructure; | 20 import 'call_structure.dart' show CallStructure; |
| 22 | 21 |
| 23 class SelectorKind { | 22 class SelectorKind { |
| 24 final String name; | 23 final String name; |
| 25 final int hashCode; | 24 final int hashCode; |
| 26 const SelectorKind(this.name, this.hashCode); | 25 const SelectorKind(this.name, this.hashCode); |
| 27 | 26 |
| 28 static const SelectorKind GETTER = const SelectorKind('getter', 0); | 27 static const SelectorKind GETTER = const SelectorKind('getter', 0); |
| 29 static const SelectorKind SETTER = const SelectorKind('setter', 1); | 28 static const SelectorKind SETTER = const SelectorKind('setter', 1); |
| 30 static const SelectorKind CALL = const SelectorKind('call', 2); | 29 static const SelectorKind CALL = const SelectorKind('call', 2); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 51 | 50 |
| 52 final int hashCode; | 51 final int hashCode; |
| 53 | 52 |
| 54 int get argumentCount => callStructure.argumentCount; | 53 int get argumentCount => callStructure.argumentCount; |
| 55 int get namedArgumentCount => callStructure.namedArgumentCount; | 54 int get namedArgumentCount => callStructure.namedArgumentCount; |
| 56 int get positionalArgumentCount => callStructure.positionalArgumentCount; | 55 int get positionalArgumentCount => callStructure.positionalArgumentCount; |
| 57 List<String> get namedArguments => callStructure.namedArguments; | 56 List<String> get namedArguments => callStructure.namedArguments; |
| 58 | 57 |
| 59 String get name => memberName.text; | 58 String get name => memberName.text; |
| 60 | 59 |
| 61 LibraryElement get library => memberName.library; | 60 LibraryEntity get library => memberName.library; |
| 62 | 61 |
| 63 Selector.internal( | 62 Selector.internal( |
| 64 this.kind, this.memberName, this.callStructure, this.hashCode) { | 63 this.kind, this.memberName, this.callStructure, this.hashCode) { |
| 65 assert(invariant( | 64 assert(invariant( |
| 66 NO_LOCATION_SPANNABLE, | 65 NO_LOCATION_SPANNABLE, |
| 67 kind == SelectorKind.INDEX || | 66 kind == SelectorKind.INDEX || |
| 68 (memberName != Names.INDEX_NAME && | 67 (memberName != Names.INDEX_NAME && |
| 69 memberName != Names.INDEX_SET_NAME), | 68 memberName != Names.INDEX_SET_NAME), |
| 70 message: "kind=$kind,memberName=$memberName," | 69 message: "kind=$kind,memberName=$memberName," |
| 71 "callStructure:$callStructure")); | 70 "callStructure:$callStructure")); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 ? !element.isFinal && !element.isConst | 237 ? !element.isFinal && !element.isConst |
| 239 : isGetter || isCall; | 238 : isGetter || isCall; |
| 240 } | 239 } |
| 241 if (isGetter) return true; | 240 if (isGetter) return true; |
| 242 if (isSetter) return false; | 241 if (isSetter) return false; |
| 243 return signatureApplies(element); | 242 return signatureApplies(element); |
| 244 } | 243 } |
| 245 | 244 |
| 246 bool signatureApplies(MethodElement function) { | 245 bool signatureApplies(MethodElement function) { |
| 247 if (Elements.isUnresolved(function)) return false; | 246 if (Elements.isUnresolved(function)) return false; |
| 248 return callStructure.signatureApplies(function.functionSignature); | 247 return callStructure.signatureApplies(function.type); |
| 249 } | 248 } |
| 250 | 249 |
| 251 bool applies(MemberElement element) { | 250 bool applies(MemberElement element) { |
| 252 if (name != element.name) return false; | 251 if (name != element.name) return false; |
| 253 return appliesUnnamed(element); | 252 return appliesUnnamed(element); |
| 254 } | 253 } |
| 255 | 254 |
| 256 bool match(SelectorKind kind, Name memberName, CallStructure callStructure) { | 255 bool match(SelectorKind kind, Name memberName, CallStructure callStructure) { |
| 257 return this.kind == kind && | 256 return this.kind == kind && |
| 258 this.memberName == memberName && | 257 this.memberName == memberName && |
| 259 this.callStructure.match(callStructure); | 258 this.callStructure.match(callStructure); |
| 260 } | 259 } |
| 261 | 260 |
| 262 static int computeHashCode( | 261 static int computeHashCode( |
| 263 SelectorKind kind, Name name, CallStructure callStructure) { | 262 SelectorKind kind, Name name, CallStructure callStructure) { |
| 264 // Add bits from name and kind. | 263 // Add bits from name and kind. |
| 265 int hash = Hashing.mixHashCodeBits(name.hashCode, kind.hashCode); | 264 int hash = Hashing.mixHashCodeBits(name.hashCode, kind.hashCode); |
| 266 // Add bits from the call structure. | 265 // Add bits from the call structure. |
| 267 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); | 266 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); |
| 268 } | 267 } |
| 269 | 268 |
| 270 String toString() { | 269 String toString() { |
| 271 return 'Selector($kind, $name, ${callStructure.structureToString()})'; | 270 return 'Selector($kind, $name, ${callStructure.structureToString()})'; |
| 272 } | 271 } |
| 273 | 272 |
| 274 Selector toCallSelector() => new Selector.callClosureFrom(this); | 273 Selector toCallSelector() => new Selector.callClosureFrom(this); |
| 275 } | 274 } |
| OLD | NEW |