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

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

Issue 2615223003: Use MemberElement instead of Element in function sets and selectors. (Closed)
Patch Set: Created 3 years, 11 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.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,
14 FunctionSignature, 13 FunctionSignature,
15 MemberElement, 14 MemberElement,
15 MethodElement,
16 Name, 16 Name,
17 LibraryElement, 17 LibraryElement,
18 PublicName; 18 PublicName;
19 import '../util/util.dart' show Hashing; 19 import '../util/util.dart' show Hashing;
20 import '../common/resolution.dart' show Target; 20 import '../common/resolution.dart' show Target;
21 import 'call_structure.dart' show CallStructure; 21 import 'call_structure.dart' show CallStructure;
22 22
23 class SelectorKind { 23 class SelectorKind {
24 final String name; 24 final String name;
25 final int hashCode; 25 final int hashCode;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 const int SETTER = 2; 211 const int SETTER = 2;
212 int kind = METHOD; 212 int kind = METHOD;
213 if (isGetter) { 213 if (isGetter) {
214 kind = GETTER; 214 kind = GETTER;
215 } else if (isSetter) { 215 } else if (isSetter) {
216 kind = SETTER; 216 kind = SETTER;
217 } 217 }
218 return kind; 218 return kind;
219 } 219 }
220 220
221 bool appliesUnnamed(Element element) { 221 bool appliesUnnamed(MemberElement element) {
222 assert(name == element.name); 222 assert(name == element.name);
223 return appliesUntyped(element); 223 return appliesUntyped(element);
224 } 224 }
225 225
226 bool appliesUntyped(Element element) { 226 bool appliesUntyped(MemberElement element) {
227 assert(name == element.name); 227 assert(name == element.name);
228 if (Elements.isUnresolved(element)) return false; 228 if (Elements.isUnresolved(element)) return false;
229 if (memberName.isPrivate && memberName.library != element.library) { 229 if (memberName.isPrivate && memberName.library != element.library) {
230 // TODO(johnniwinther): Maybe this should be 230 // TODO(johnniwinther): Maybe this should be
231 // `memberName != element.memberName`. 231 // `memberName != element.memberName`.
232 return false; 232 return false;
233 } 233 }
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(MethodElement 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 applies(MemberElement element) { 251 bool applies(MemberElement element) {
252 if (name != element.name) return false; 252 if (name != element.name) return false;
253 return appliesUnnamed(element); 253 return appliesUnnamed(element);
254 } 254 }
255 255
256 bool match(SelectorKind kind, Name memberName, CallStructure callStructure) { 256 bool match(SelectorKind kind, Name memberName, CallStructure callStructure) {
257 return this.kind == kind && 257 return this.kind == kind &&
258 this.memberName == memberName && 258 this.memberName == memberName &&
259 this.callStructure.match(callStructure); 259 this.callStructure.match(callStructure);
260 } 260 }
261 261
262 static int computeHashCode( 262 static int computeHashCode(
263 SelectorKind kind, Name name, CallStructure callStructure) { 263 SelectorKind kind, Name name, CallStructure callStructure) {
264 // Add bits from name and kind. 264 // Add bits from name and kind.
265 int hash = Hashing.mixHashCodeBits(name.hashCode, kind.hashCode); 265 int hash = Hashing.mixHashCodeBits(name.hashCode, kind.hashCode);
266 // Add bits from the call structure. 266 // Add bits from the call structure.
267 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); 267 return Hashing.mixHashCodeBits(hash, callStructure.hashCode);
268 } 268 }
269 269
270 String toString() { 270 String toString() {
271 return 'Selector($kind, $name, ${callStructure.structureToString()})'; 271 return 'Selector($kind, $name, ${callStructure.structureToString()})';
272 } 272 }
273 273
274 Selector toCallSelector() => new Selector.callClosureFrom(this); 274 Selector toCallSelector() => new Selector.callClosureFrom(this);
275 } 275 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698