OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 part of world_builder; | 5 part of world_builder; |
6 | 6 |
7 /// World builder specific to codegen. | 7 /// World builder specific to codegen. |
8 /// | 8 /// |
9 /// This adds additional access to liveness of selectors and elements. | 9 /// This adds additional access to liveness of selectors and elements. |
10 abstract class CodegenWorldBuilder implements WorldBuilder { | 10 abstract class CodegenWorldBuilder implements WorldBuilder { |
11 /// Calls [f] with every instance field, together with its declarer, in an | 11 /// Calls [f] with every instance field, together with its declarer, in an |
12 /// instance of [cls]. | 12 /// instance of [cls]. |
13 void forEachInstanceField( | 13 void forEachInstanceField(covariant ClassEntity cls, |
14 ClassEntity cls, void f(ClassEntity declarer, FieldEntity field)); | 14 void f(ClassEntity declarer, FieldEntity field)); |
15 | 15 |
16 /// Calls [f] for each parameter of [function] providing the type and name of | 16 /// Calls [f] for each parameter of [function] providing the type and name of |
17 /// the parameter and the [defaultValue] if the parameter is optional. | 17 /// the parameter and the [defaultValue] if the parameter is optional. |
18 void forEachParameter(FunctionEntity function, | 18 void forEachParameter(covariant FunctionEntity function, |
19 void f(DartType type, String name, ConstantValue defaultValue)); | 19 void f(DartType type, String name, ConstantValue defaultValue)); |
20 | 20 |
21 void forEachInvokedName( | 21 void forEachInvokedName( |
22 f(String name, Map<Selector, SelectorConstraints> selectors)); | 22 f(String name, Map<Selector, SelectorConstraints> selectors)); |
23 | 23 |
24 void forEachInvokedGetter( | 24 void forEachInvokedGetter( |
25 f(String name, Map<Selector, SelectorConstraints> selectors)); | 25 f(String name, Map<Selector, SelectorConstraints> selectors)); |
26 | 26 |
27 void forEachInvokedSetter( | 27 void forEachInvokedSetter( |
28 f(String name, Map<Selector, SelectorConstraints> selectors)); | 28 f(String name, Map<Selector, SelectorConstraints> selectors)); |
29 | 29 |
30 /// Returns `true` if [field] constant or final with a constant initializer. | 30 /// Returns `true` if [field] constant or final with a constant initializer. |
31 bool hasConstantFieldInitializer(FieldEntity field); | 31 bool hasConstantFieldInitializer(covariant FieldEntity field); |
32 | 32 |
33 /// Returns `true` if [member] is invoked as a setter. | 33 /// Returns `true` if [member] is invoked as a setter. |
34 bool hasInvokedSetter(MemberEntity member, ClosedWorld world); | 34 bool hasInvokedSetter(MemberEntity member, ClosedWorld world); |
35 | 35 |
36 bool hasInvokedGetter(MemberEntity member, ClosedWorld world); | 36 bool hasInvokedGetter(MemberEntity member, ClosedWorld world); |
37 | 37 |
38 Map<Selector, SelectorConstraints> invocationsByName(String name); | 38 Map<Selector, SelectorConstraints> invocationsByName(String name); |
39 | 39 |
40 Map<Selector, SelectorConstraints> getterInvocationsByName(String name); | 40 Map<Selector, SelectorConstraints> getterInvocationsByName(String name); |
41 | 41 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 void forEachInvokedGetter( | 316 void forEachInvokedGetter( |
317 f(String name, Map<Selector, SelectorConstraints> selectors)) { | 317 f(String name, Map<Selector, SelectorConstraints> selectors)) { |
318 _invokedGetters.forEach(f); | 318 _invokedGetters.forEach(f); |
319 } | 319 } |
320 | 320 |
321 void forEachInvokedSetter( | 321 void forEachInvokedSetter( |
322 f(String name, Map<Selector, SelectorConstraints> selectors)) { | 322 f(String name, Map<Selector, SelectorConstraints> selectors)) { |
323 _invokedSetters.forEach(f); | 323 _invokedSetters.forEach(f); |
324 } | 324 } |
325 | 325 |
326 void registerIsCheck(DartType type) { | 326 void registerIsCheck(covariant DartType type) { |
327 isChecks.add(type.unaliased); | 327 isChecks.add(type.unaliased); |
328 } | 328 } |
329 | 329 |
330 void _registerStaticUse(StaticUse staticUse) { | 330 void _registerStaticUse(StaticUse staticUse) { |
331 if (staticUse.element is FieldEntity) { | 331 if (staticUse.element is FieldEntity) { |
332 FieldEntity field = staticUse.element; | 332 FieldEntity field = staticUse.element; |
333 if (field.isTopLevel || field.isStatic) { | 333 if (field.isTopLevel || field.isStatic) { |
334 allReferencedStaticFields.add(field); | 334 allReferencedStaticFields.add(field); |
335 } | 335 } |
336 } | 336 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 closurizedMembers.add(element); | 413 closurizedMembers.add(element); |
414 } | 414 } |
415 | 415 |
416 void processClassMembers(ClassEntity cls, MemberUsedCallback memberUsed) { | 416 void processClassMembers(ClassEntity cls, MemberUsedCallback memberUsed) { |
417 _elementEnvironment.forEachClassMember(cls, | 417 _elementEnvironment.forEachClassMember(cls, |
418 (ClassEntity cls, MemberEntity member) { | 418 (ClassEntity cls, MemberEntity member) { |
419 _processInstantiatedClassMember(cls, member, memberUsed); | 419 _processInstantiatedClassMember(cls, member, memberUsed); |
420 }); | 420 }); |
421 } | 421 } |
422 | 422 |
423 void _processInstantiatedClassMember( | 423 void _processInstantiatedClassMember(ClassEntity cls, |
424 ClassEntity cls, MemberEntity member, MemberUsedCallback memberUsed) { | 424 covariant MemberEntity member, MemberUsedCallback memberUsed) { |
425 if (!member.isInstanceMember) return; | 425 if (!member.isInstanceMember) return; |
426 _getMemberUsage(member, memberUsed); | 426 _getMemberUsage(member, memberUsed); |
427 } | 427 } |
428 | 428 |
429 _MemberUsage _getMemberUsage( | 429 _MemberUsage _getMemberUsage( |
430 MemberEntity member, MemberUsedCallback memberUsed) { | 430 covariant MemberEntity member, MemberUsedCallback memberUsed) { |
431 return _instanceMemberUsage.putIfAbsent(member, () { | 431 return _instanceMemberUsage.putIfAbsent(member, () { |
432 String memberName = member.name; | 432 String memberName = member.name; |
433 ClassEntity cls = member.enclosingClass; | 433 ClassEntity cls = member.enclosingClass; |
434 bool isNative = _nativeBasicData.isNativeClass(cls); | 434 bool isNative = _nativeBasicData.isNativeClass(cls); |
435 _MemberUsage usage = new _MemberUsage(member, isNative: isNative); | 435 _MemberUsage usage = new _MemberUsage(member, isNative: isNative); |
436 EnumSet<MemberUse> useSet = new EnumSet<MemberUse>(); | 436 EnumSet<MemberUse> useSet = new EnumSet<MemberUse>(); |
437 useSet.addAll(usage.appliedUse); | 437 useSet.addAll(usage.appliedUse); |
438 if (hasInvokedGetter(member, _world)) { | 438 if (hasInvokedGetter(member, _world)) { |
439 useSet.addAll(usage.read()); | 439 useSet.addAll(usage.read()); |
440 } | 440 } |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 | 641 |
642 @override | 642 @override |
643 void forEachInstanceField( | 643 void forEachInstanceField( |
644 ClassEntity cls, void f(ClassEntity declarer, FieldEntity field)) { | 644 ClassEntity cls, void f(ClassEntity declarer, FieldEntity field)) { |
645 _elementEnvironment.forEachClassMember(cls, | 645 _elementEnvironment.forEachClassMember(cls, |
646 (ClassEntity declarer, MemberEntity member) { | 646 (ClassEntity declarer, MemberEntity member) { |
647 if (member.isField && member.isInstanceMember) f(declarer, member); | 647 if (member.isField && member.isInstanceMember) f(declarer, member); |
648 }); | 648 }); |
649 } | 649 } |
650 } | 650 } |
OLD | NEW |