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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 * getter and only registers an invoked getter. | 43 * getter and only registers an invoked getter. |
44 */ | 44 */ |
45 final Set<Element> fieldGetters; | 45 final Set<Element> fieldGetters; |
46 | 46 |
47 /** | 47 /** |
48 * Fields set. See comment in [fieldGetters]. | 48 * Fields set. See comment in [fieldGetters]. |
49 */ | 49 */ |
50 final Set<Element> fieldSetters; | 50 final Set<Element> fieldSetters; |
51 final Set<DartType> isChecks; | 51 final Set<DartType> isChecks; |
52 | 52 |
| 53 bool usingFactoryWithTypeArguments = false; |
| 54 |
53 Universe() : instantiatedClasses = new Set<ClassElement>(), | 55 Universe() : instantiatedClasses = new Set<ClassElement>(), |
54 instantiatedTypes = new Set<DartType>(), | 56 instantiatedTypes = new Set<DartType>(), |
55 staticFunctionsNeedingGetter = new Set<FunctionElement>(), | 57 staticFunctionsNeedingGetter = new Set<FunctionElement>(), |
56 invokedNames = new Map<SourceString, Set<Selector>>(), | 58 invokedNames = new Map<SourceString, Set<Selector>>(), |
57 invokedGetters = new Map<SourceString, Set<Selector>>(), | 59 invokedGetters = new Map<SourceString, Set<Selector>>(), |
58 invokedSetters = new Map<SourceString, Set<Selector>>(), | 60 invokedSetters = new Map<SourceString, Set<Selector>>(), |
59 fieldGetters = new Set<Element>(), | 61 fieldGetters = new Set<Element>(), |
60 fieldSetters = new Set<Element>(), | 62 fieldSetters = new Set<Element>(), |
61 isChecks = new Set<DartType>(); | 63 isChecks = new Set<DartType>(); |
62 | 64 |
(...skipping 19 matching lines...) Expand all Loading... |
82 return hasMatchingSelector(invokedSetters[member.name], member, compiler); | 84 return hasMatchingSelector(invokedSetters[member.name], member, compiler); |
83 } | 85 } |
84 | 86 |
85 bool hasFieldGetter(Element member, Compiler compiler) { | 87 bool hasFieldGetter(Element member, Compiler compiler) { |
86 return fieldGetters.contains(member); | 88 return fieldGetters.contains(member); |
87 } | 89 } |
88 | 90 |
89 bool hasFieldSetter(Element member, Compiler compiler) { | 91 bool hasFieldSetter(Element member, Compiler compiler) { |
90 return fieldSetters.contains(member); | 92 return fieldSetters.contains(member); |
91 } | 93 } |
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 } | |
127 } | 94 } |
128 | 95 |
129 class SelectorKind { | 96 class SelectorKind { |
130 final String name; | 97 final String name; |
131 const SelectorKind(this.name); | 98 const SelectorKind(this.name); |
132 | 99 |
133 static const SelectorKind GETTER = const SelectorKind('getter'); | 100 static const SelectorKind GETTER = const SelectorKind('getter'); |
134 static const SelectorKind SETTER = const SelectorKind('setter'); | 101 static const SelectorKind SETTER = const SelectorKind('setter'); |
135 static const SelectorKind CALL = const SelectorKind('call'); | 102 static const SelectorKind CALL = const SelectorKind('call'); |
136 static const SelectorKind OPERATOR = const SelectorKind('operator'); | 103 static const SelectorKind OPERATOR = const SelectorKind('operator'); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 ClassElement cls = self; | 509 ClassElement cls = self; |
543 if (cls.isSubclassOf(other)) { | 510 if (cls.isSubclassOf(other)) { |
544 // Resolve an invocation of [element.name] on [self]. If it | 511 // Resolve an invocation of [element.name] on [self]. If it |
545 // is found, this selector is a candidate. | 512 // is found, this selector is a candidate. |
546 return hasElementIn(cls, element) && appliesUntyped(element, compiler); | 513 return hasElementIn(cls, element) && appliesUntyped(element, compiler); |
547 } | 514 } |
548 } | 515 } |
549 return false; | 516 return false; |
550 } | 517 } |
551 } | 518 } |
OLD | NEW |