OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 universe; | 5 library universe; |
6 | 6 |
7 import '../closure.dart'; | 7 import '../closure.dart'; |
8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
9 import '../dart2jslib.dart'; | 9 import '../dart2jslib.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 return hasMatchingSelector(invokedSetters[member.name], member, compiler); | 82 return hasMatchingSelector(invokedSetters[member.name], member, compiler); |
83 } | 83 } |
84 | 84 |
85 bool hasFieldGetter(Element member, Compiler compiler) { | 85 bool hasFieldGetter(Element member, Compiler compiler) { |
86 return fieldGetters.contains(member); | 86 return fieldGetters.contains(member); |
87 } | 87 } |
88 | 88 |
89 bool hasFieldSetter(Element member, Compiler compiler) { | 89 bool hasFieldSetter(Element member, Compiler compiler) { |
90 return fieldSetters.contains(member); | 90 return fieldSetters.contains(member); |
91 } | 91 } |
| 92 |
| 93 /** |
| 94 * Compute type arguments of classes that use one of their type variables in |
| 95 * is-checks and add the is-checks that they imply. |
| 96 * |
| 97 * This function must be called after all is-checks have been registered. |
| 98 * |
| 99 * TODO(karlklose): move these computations into a function producing an |
| 100 * immutable datastructure. |
| 101 */ |
| 102 void addImplicitChecks(Iterable<ClassElement> classesUsingChecks) { |
| 103 // If there are no classes that use their variables in checks, there is |
| 104 // nothing to do. |
| 105 if (classesUsingChecks.isEmpty) return; |
| 106 // Find all instantiated types that are a subtype of a class that uses |
| 107 // one of its type arguments in an is-check and add the arguments to the |
| 108 // set of is-checks. |
| 109 // TODO(karlklose): replace this with code that uses a subtype lookup |
| 110 // datastructure in the world. |
| 111 for (DartType type in instantiatedTypes) { |
| 112 if (type.kind != TypeKind.INTERFACE) continue; |
| 113 InterfaceType classType = type; |
| 114 for (ClassElement cls in classesUsingChecks) { |
| 115 // We need the type as instance of its superclass anyway, so we just |
| 116 // try to compute the substitution; if the result is [:null:], the |
| 117 // classes are not related. |
| 118 InterfaceType instance = classType.asInstanceOf(cls); |
| 119 if (instance == null) continue; |
| 120 Link<DartType> typeArguments = instance.typeArguments; |
| 121 for (DartType argument in typeArguments) { |
| 122 isChecks.add(argument); |
| 123 } |
| 124 } |
| 125 } |
| 126 } |
92 } | 127 } |
93 | 128 |
94 class SelectorKind { | 129 class SelectorKind { |
95 final String name; | 130 final String name; |
96 const SelectorKind(this.name); | 131 const SelectorKind(this.name); |
97 | 132 |
98 static const SelectorKind GETTER = const SelectorKind('getter'); | 133 static const SelectorKind GETTER = const SelectorKind('getter'); |
99 static const SelectorKind SETTER = const SelectorKind('setter'); | 134 static const SelectorKind SETTER = const SelectorKind('setter'); |
100 static const SelectorKind CALL = const SelectorKind('call'); | 135 static const SelectorKind CALL = const SelectorKind('call'); |
101 static const SelectorKind OPERATOR = const SelectorKind('operator'); | 136 static const SelectorKind OPERATOR = const SelectorKind('operator'); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 ClassElement cls = self; | 528 ClassElement cls = self; |
494 if (cls.isSubclassOf(other)) { | 529 if (cls.isSubclassOf(other)) { |
495 // Resolve an invocation of [element.name] on [self]. If it | 530 // Resolve an invocation of [element.name] on [self]. If it |
496 // is found, this selector is a candidate. | 531 // is found, this selector is a candidate. |
497 return hasElementIn(cls, element) && appliesUntyped(element, compiler); | 532 return hasElementIn(cls, element) && appliesUntyped(element, compiler); |
498 } | 533 } |
499 } | 534 } |
500 return false; | 535 return false; |
501 } | 536 } |
502 } | 537 } |
OLD | NEW |