OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library kernel.transformations.insert_covariance_checks; | 4 library kernel.transformations.insert_covariance_checks; |
5 | 5 |
6 import '../class_hierarchy.dart'; | 6 import '../class_hierarchy.dart'; |
7 import '../clone.dart'; | 7 import '../clone.dart'; |
8 import '../core_types.dart'; | 8 import '../core_types.dart'; |
9 import '../kernel.dart'; | 9 import '../kernel.dart'; |
10 import '../log.dart'; | 10 import '../log.dart'; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 /// the type argument is exact. For example: | 46 /// the type argument is exact. For example: |
47 /// | 47 /// |
48 /// void foo(List<num> numbers) { | 48 /// void foo(List<num> numbers) { |
49 /// numbers.add(3.5); // before | 49 /// numbers.add(3.5); // before |
50 /// numbers.add$cc(3.5); // after | 50 /// numbers.add$cc(3.5); // after |
51 /// } | 51 /// } |
52 /// | 52 /// |
53 /// Currently, we only deduce that the type arguments are exact when the | 53 /// Currently, we only deduce that the type arguments are exact when the |
54 /// receiver is `this`. | 54 /// receiver is `this`. |
55 class InsertCovarianceChecks { | 55 class InsertCovarianceChecks { |
| 56 final CoreTypes coreTypes; |
56 ClassHierarchy hierarchy; | 57 ClassHierarchy hierarchy; |
57 CoreTypes coreTypes; | |
58 TypeEnvironment types; | 58 TypeEnvironment types; |
59 | 59 |
60 /// Maps unsafe members to their checked entry point, to be used at call sites | 60 /// Maps unsafe members to their checked entry point, to be used at call sites |
61 /// where the arguments cannot be guaranteed to satisfy the generic parameter | 61 /// where the arguments cannot be guaranteed to satisfy the generic parameter |
62 /// types of the actual target. | 62 /// types of the actual target. |
63 final Map<Member, Procedure> unsafeMemberEntryPoint = <Member, Procedure>{}; | 63 final Map<Member, Procedure> unsafeMemberEntryPoint = <Member, Procedure>{}; |
64 | 64 |
65 /// Members that may be invoked through a checked entry point. | 65 /// Members that may be invoked through a checked entry point. |
66 /// | 66 /// |
67 /// Note that these members are not necessarily unsafe, because a safe member | 67 /// Note that these members are not necessarily unsafe, because a safe member |
68 /// can override an unsafe member, and thereby be invoked through a checked | 68 /// can override an unsafe member, and thereby be invoked through a checked |
69 /// entry point. This set is not therefore not the same as the set of keys | 69 /// entry point. This set is not therefore not the same as the set of keys |
70 /// in [unsafeMemberEntryPoint]. | 70 /// in [unsafeMemberEntryPoint]. |
71 final Set<Member> membersWithCheckedEntryPoint = new Set<Member>(); | 71 final Set<Member> membersWithCheckedEntryPoint = new Set<Member>(); |
72 | 72 |
73 InsertCovarianceChecks({this.hierarchy, this.coreTypes}); | 73 InsertCovarianceChecks(this.coreTypes, {this.hierarchy}); |
74 | 74 |
75 void transformProgram(Program program) { | 75 void transformProgram(Program program) { |
76 hierarchy ??= new ClassHierarchy(program); | 76 hierarchy ??= new ClassHierarchy(program); |
77 coreTypes ??= new CoreTypes(program); | |
78 types = new TypeEnvironment(coreTypes, hierarchy); | 77 types = new TypeEnvironment(coreTypes, hierarchy); |
79 // We transform every class before their subtypes. | 78 // We transform every class before their subtypes. |
80 // This ensures that transitive overrides are taken into account. | 79 // This ensures that transitive overrides are taken into account. |
81 hierarchy.classes.forEach(transformClass); | 80 hierarchy.classes.forEach(transformClass); |
82 | 81 |
83 program.accept(new _CallTransformer(this)); | 82 program.accept(new _CallTransformer(this)); |
84 } | 83 } |
85 | 84 |
86 void transformClass(Class class_) { | 85 void transformClass(Class class_) { |
87 new _ClassTransformer(class_, this).transformClass(); | 86 new _ClassTransformer(class_, this).transformClass(); |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 @override | 515 @override |
517 visitPropertySet(PropertySet node) { | 516 visitPropertySet(PropertySet node) { |
518 var target = getChecked(node.receiver, node.interfaceTarget); | 517 var target = getChecked(node.receiver, node.interfaceTarget); |
519 if (target != null) { | 518 if (target != null) { |
520 node.interfaceTarget = target; | 519 node.interfaceTarget = target; |
521 node.name = target.name; | 520 node.name = target.name; |
522 } | 521 } |
523 node.visitChildren(this); | 522 node.visitChildren(this); |
524 } | 523 } |
525 } | 524 } |
OLD | NEW |