Chromium Code Reviews| 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 FunctionElement, | 13 FunctionElement, |
| 14 FunctionSignature, | 14 FunctionSignature, |
| 15 Name, | 15 Name, |
| 16 LibraryElement, | 16 LibraryElement, |
| 17 PublicName; | 17 PublicName; |
| 18 import '../util/util.dart' show Hashing; | 18 import '../util/util.dart' show Hashing; |
| 19 import '../world.dart' show World; | 19 import '../common/resolution.dart' show Target; |
| 20 import 'call_structure.dart' show CallStructure; | 20 import 'call_structure.dart' show CallStructure; |
| 21 | 21 |
| 22 class SelectorKind { | 22 class SelectorKind { |
| 23 final String name; | 23 final String name; |
| 24 final int hashCode; | 24 final int hashCode; |
| 25 const SelectorKind(this.name, this.hashCode); | 25 const SelectorKind(this.name, this.hashCode); |
| 26 | 26 |
| 27 static const SelectorKind GETTER = const SelectorKind('getter', 0); | 27 static const SelectorKind GETTER = const SelectorKind('getter', 0); |
| 28 static const SelectorKind SETTER = const SelectorKind('setter', 1); | 28 static const SelectorKind SETTER = const SelectorKind('setter', 1); |
| 29 static const SelectorKind CALL = const SelectorKind('call', 2); | 29 static const SelectorKind CALL = const SelectorKind('call', 2); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 const int SETTER = 2; | 210 const int SETTER = 2; |
| 211 int kind = METHOD; | 211 int kind = METHOD; |
| 212 if (isGetter) { | 212 if (isGetter) { |
| 213 kind = GETTER; | 213 kind = GETTER; |
| 214 } else if (isSetter) { | 214 } else if (isSetter) { |
| 215 kind = SETTER; | 215 kind = SETTER; |
| 216 } | 216 } |
| 217 return kind; | 217 return kind; |
| 218 } | 218 } |
| 219 | 219 |
| 220 bool appliesUnnamed(Element element, World world) { | 220 bool appliesUnnamed(Element element, Target target) { |
| 221 assert(sameNameHack(element, world)); | 221 assert(sameNameHack(element, target)); |
| 222 return appliesUntyped(element, world); | 222 return appliesUntyped(element, target); |
| 223 } | 223 } |
| 224 | 224 |
| 225 bool appliesUntyped(Element element, World world) { | 225 bool appliesUntyped(Element element, Target target) { |
| 226 assert(sameNameHack(element, world)); | 226 assert(sameNameHack(element, target)); |
| 227 if (Elements.isUnresolved(element)) return false; | 227 if (Elements.isUnresolved(element)) return false; |
| 228 if (memberName.isPrivate && memberName.library != element.library) { | 228 if (memberName.isPrivate && memberName.library != element.library) { |
| 229 // TODO(johnniwinther): Maybe this should be | 229 // TODO(johnniwinther): Maybe this should be |
| 230 // `memberName != element.memberName`. | 230 // `memberName != element.memberName`. |
| 231 return false; | 231 return false; |
| 232 } | 232 } |
| 233 if (world.isForeign(element)) return true; | 233 if (target.isForeign(element)) return true; |
| 234 if (element.isSetter) return isSetter; | 234 if (element.isSetter) return isSetter; |
| 235 if (element.isGetter) return isGetter || isCall; | 235 if (element.isGetter) return isGetter || isCall; |
| 236 if (element.isField) { | 236 if (element.isField) { |
| 237 return isSetter | 237 return isSetter |
| 238 ? !element.isFinal && !element.isConst | 238 ? !element.isFinal && !element.isConst |
| 239 : isGetter || isCall; | 239 : isGetter || isCall; |
| 240 } | 240 } |
| 241 if (isGetter) return true; | 241 if (isGetter) return true; |
| 242 if (isSetter) return false; | 242 if (isSetter) return false; |
| 243 return signatureApplies(element); | 243 return signatureApplies(element); |
| 244 } | 244 } |
| 245 | 245 |
| 246 bool signatureApplies(FunctionElement function) { | 246 bool signatureApplies(FunctionElement function) { |
| 247 if (Elements.isUnresolved(function)) return false; | 247 if (Elements.isUnresolved(function)) return false; |
| 248 return callStructure.signatureApplies(function.functionSignature); | 248 return callStructure.signatureApplies(function.functionSignature); |
| 249 } | 249 } |
| 250 | 250 |
| 251 bool sameNameHack(Element element, World world) { | 251 bool sameNameHack(Element element, Target target) { |
|
Harry Terkelsen
2016/09/19 20:41:11
the Target argument is unused, remove?
Johnni Winther
2016/09/21 09:44:59
Done.
| |
| 252 // TODO(ngeoffray): Remove workaround checks. | 252 // TODO(ngeoffray): Remove workaround checks. |
| 253 return element.isConstructor || name == element.name; | 253 return element.isConstructor || name == element.name; |
| 254 } | 254 } |
| 255 | 255 |
| 256 bool applies(Element element, World world) { | 256 bool applies(Element element, Target target) { |
| 257 if (!sameNameHack(element, world)) return false; | 257 if (!sameNameHack(element, target)) return false; |
| 258 return appliesUnnamed(element, world); | 258 return appliesUnnamed(element, target); |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool match(SelectorKind kind, Name memberName, CallStructure callStructure) { | 261 bool match(SelectorKind kind, Name memberName, CallStructure callStructure) { |
| 262 return this.kind == kind && | 262 return this.kind == kind && |
| 263 this.memberName == memberName && | 263 this.memberName == memberName && |
| 264 this.callStructure.match(callStructure); | 264 this.callStructure.match(callStructure); |
| 265 } | 265 } |
| 266 | 266 |
| 267 static int computeHashCode( | 267 static int computeHashCode( |
| 268 SelectorKind kind, Name name, CallStructure callStructure) { | 268 SelectorKind kind, Name name, CallStructure callStructure) { |
| 269 // Add bits from name and kind. | 269 // Add bits from name and kind. |
| 270 int hash = Hashing.mixHashCodeBits(name.hashCode, kind.hashCode); | 270 int hash = Hashing.mixHashCodeBits(name.hashCode, kind.hashCode); |
| 271 // Add bits from the call structure. | 271 // Add bits from the call structure. |
| 272 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); | 272 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); |
| 273 } | 273 } |
| 274 | 274 |
| 275 String toString() { | 275 String toString() { |
| 276 return 'Selector($kind, $name, ${callStructure.structureToString()})'; | 276 return 'Selector($kind, $name, ${callStructure.structureToString()})'; |
| 277 } | 277 } |
| 278 | 278 |
| 279 Selector toCallSelector() => new Selector.callClosureFrom(this); | 279 Selector toCallSelector() => new Selector.callClosureFrom(this); |
| 280 } | 280 } |
| OLD | NEW |