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

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

Issue 2810683002: Use entities in Selector methods (Closed)
Patch Set: Created 3 years, 8 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 Element, Elements, FunctionSignature, Name, PublicName;
11 Element,
12 Elements,
13 FunctionSignature,
14 MemberElement,
15 MethodElement,
16 Name,
17 PublicName;
18 import '../elements/entities.dart'; 11 import '../elements/entities.dart';
19 import '../util/util.dart' show Hashing; 12 import '../util/util.dart' show Hashing;
20 import 'call_structure.dart' show CallStructure; 13 import 'call_structure.dart' show CallStructure;
21 14
22 class SelectorKind { 15 class SelectorKind {
23 final String name; 16 final String name;
24 final int hashCode; 17 final int hashCode;
25 const SelectorKind(this.name, this.hashCode); 18 const SelectorKind(this.name, this.hashCode);
26 19
27 static const SelectorKind GETTER = const SelectorKind('getter', 0); 20 static const SelectorKind GETTER = const SelectorKind('getter', 0);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 const int SETTER = 2; 203 const int SETTER = 2;
211 int kind = METHOD; 204 int kind = METHOD;
212 if (isGetter) { 205 if (isGetter) {
213 kind = GETTER; 206 kind = GETTER;
214 } else if (isSetter) { 207 } else if (isSetter) {
215 kind = SETTER; 208 kind = SETTER;
216 } 209 }
217 return kind; 210 return kind;
218 } 211 }
219 212
220 bool appliesUnnamed(MemberElement element) { 213 bool appliesUnnamed(MemberEntity element) {
221 assert(name == element.name); 214 assert(name == element.name);
222 return appliesUntyped(element); 215 return appliesUntyped(element);
223 } 216 }
224 217
225 bool appliesUntyped(MemberElement element) { 218 bool appliesUntyped(MemberEntity element) {
226 assert(name == element.name); 219 assert(name == element.name);
227 if (Elements.isUnresolved(element)) return false;
228 if (memberName.isPrivate && memberName.library != element.library) { 220 if (memberName.isPrivate && memberName.library != element.library) {
229 // TODO(johnniwinther): Maybe this should be 221 // TODO(johnniwinther): Maybe this should be
230 // `memberName != element.memberName`. 222 // `memberName != element.memberName`.
231 return false; 223 return false;
232 } 224 }
233 if (element.isSetter) return isSetter; 225 if (element.isSetter) return isSetter;
234 if (element.isGetter) return isGetter || isCall; 226 if (element.isGetter) return isGetter || isCall;
235 if (element.isField) { 227 if (element.isField) {
236 return isSetter 228 return isSetter ? element.isAssignable : isGetter || isCall;
237 ? !element.isFinal && !element.isConst
238 : isGetter || isCall;
239 } 229 }
240 if (isGetter) return true; 230 if (isGetter) return true;
241 if (isSetter) return false; 231 if (isSetter) return false;
242 return signatureApplies(element); 232 return signatureApplies(element);
243 } 233 }
244 234
245 bool signatureApplies(MethodElement function) { 235 bool signatureApplies(FunctionEntity function) {
246 return callStructure.signatureApplies(function.parameterStructure); 236 return callStructure.signatureApplies(function.parameterStructure);
247 } 237 }
248 238
249 bool applies(MemberElement element) { 239 bool applies(MemberEntity element) {
250 if (name != element.name) return false; 240 if (name != element.name) return false;
251 return appliesUnnamed(element); 241 return appliesUnnamed(element);
252 } 242 }
253 243
254 bool match(SelectorKind kind, Name memberName, CallStructure callStructure) { 244 bool match(SelectorKind kind, Name memberName, CallStructure callStructure) {
255 return this.kind == kind && 245 return this.kind == kind &&
256 this.memberName == memberName && 246 this.memberName == memberName &&
257 this.callStructure.match(callStructure); 247 this.callStructure.match(callStructure);
258 } 248 }
259 249
260 static int computeHashCode( 250 static int computeHashCode(
261 SelectorKind kind, Name name, CallStructure callStructure) { 251 SelectorKind kind, Name name, CallStructure callStructure) {
262 // Add bits from name and kind. 252 // Add bits from name and kind.
263 int hash = Hashing.mixHashCodeBits(name.hashCode, kind.hashCode); 253 int hash = Hashing.mixHashCodeBits(name.hashCode, kind.hashCode);
264 // Add bits from the call structure. 254 // Add bits from the call structure.
265 return Hashing.mixHashCodeBits(hash, callStructure.hashCode); 255 return Hashing.mixHashCodeBits(hash, callStructure.hashCode);
266 } 256 }
267 257
268 String toString() { 258 String toString() {
269 return 'Selector($kind, $name, ${callStructure.structureToString()})'; 259 return 'Selector($kind, $name, ${callStructure.structureToString()})';
270 } 260 }
271 261
272 Selector toCallSelector() => new Selector.callClosureFrom(this); 262 Selector toCallSelector() => new Selector.callClosureFrom(this);
273 } 263 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/universe/codegen_world_builder.dart ('k') | pkg/compiler/lib/src/world.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698