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 part of js_backend; | 5 part of js_backend; |
6 | 6 |
7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
8 | 8 |
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 }); | 1012 }); |
1013 | 1013 |
1014 if (elements == null) return false; | 1014 if (elements == null) return false; |
1015 if (elements.isEmpty) return false; | 1015 if (elements.isEmpty) return false; |
1016 return elements.any((element) { | 1016 return elements.any((element) { |
1017 return selector.applies(element, compiler.world) && | 1017 return selector.applies(element, compiler.world) && |
1018 (mask == null || mask.canHit(element, selector, compiler.world)); | 1018 (mask == null || mask.canHit(element, selector, compiler.world)); |
1019 }); | 1019 }); |
1020 } | 1020 } |
1021 | 1021 |
| 1022 /// True if the given class is an internal class used for type inference |
| 1023 /// and never exists at runtime. |
| 1024 bool isCompileTimeOnlyClass(ClassElement class_) { |
| 1025 return class_ == jsPositiveIntClass || |
| 1026 class_ == jsUInt32Class || |
| 1027 class_ == jsUInt31Class || |
| 1028 class_ == jsFixedArrayClass || |
| 1029 class_ == jsUnmodifiableArrayClass || |
| 1030 class_ == jsMutableArrayClass || |
| 1031 class_ == jsExtendableArrayClass; |
| 1032 } |
| 1033 |
| 1034 /// Maps compile-time classes to their runtime class. The runtime class is |
| 1035 /// always a superclass or the class itself. |
| 1036 ClassElement getRuntimeClass(ClassElement class_) { |
| 1037 if (class_.isSubclassOf(jsIntClass)) return jsIntClass; |
| 1038 if (class_.isSubclassOf(jsArrayClass)) return jsArrayClass; |
| 1039 return class_; |
| 1040 } |
| 1041 |
1022 final Map<String, Set<ClassElement>> interceptedClassesCache = | 1042 final Map<String, Set<ClassElement>> interceptedClassesCache = |
1023 new Map<String, Set<ClassElement>>(); | 1043 new Map<String, Set<ClassElement>>(); |
1024 | 1044 |
1025 /** | 1045 /** |
1026 * Returns a set of interceptor classes that contain a member named | 1046 * Returns a set of interceptor classes that contain a member named |
1027 * [name]. Returns [:null:] if there is no class. | 1047 * [name]. Returns [:null:] if there is no class. |
1028 */ | 1048 */ |
1029 Set<ClassElement> getInterceptedClassesOn(String name) { | 1049 Set<ClassElement> getInterceptedClassesOn(String name) { |
1030 Set<Element> intercepted = interceptedElements[name]; | 1050 Set<Element> intercepted = interceptedElements[name]; |
1031 if (intercepted == null) return null; | 1051 if (intercepted == null) return null; |
1032 return interceptedClassesCache.putIfAbsent(name, () { | 1052 return interceptedClassesCache.putIfAbsent(name, () { |
1033 // Populate the cache by running through all the elements and | 1053 // Populate the cache by running through all the elements and |
1034 // determine if the given selector applies to them. | 1054 // determine if the given selector applies to them. |
1035 Set<ClassElement> result = new Set<ClassElement>(); | 1055 Set<ClassElement> result = new Set<ClassElement>(); |
1036 for (Element element in intercepted) { | 1056 for (Element element in intercepted) { |
1037 ClassElement classElement = element.enclosingClass; | 1057 ClassElement classElement = element.enclosingClass; |
| 1058 if (isCompileTimeOnlyClass(classElement)) continue; |
1038 if (isNativeOrExtendsNative(classElement) | 1059 if (isNativeOrExtendsNative(classElement) |
1039 || interceptedClasses.contains(classElement)) { | 1060 || interceptedClasses.contains(classElement)) { |
1040 result.add(classElement); | 1061 result.add(classElement); |
1041 } | 1062 } |
1042 if (classesMixedIntoInterceptedClasses.contains(classElement)) { | 1063 if (classesMixedIntoInterceptedClasses.contains(classElement)) { |
1043 Set<ClassElement> nativeSubclasses = | 1064 Set<ClassElement> nativeSubclasses = |
1044 nativeSubclassesOfMixin(classElement); | 1065 nativeSubclassesOfMixin(classElement); |
1045 if (nativeSubclasses != null) result.addAll(nativeSubclasses); | 1066 if (nativeSubclasses != null) result.addAll(nativeSubclasses); |
1046 } | 1067 } |
1047 } | 1068 } |
(...skipping 2266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3314 } | 3335 } |
3315 } | 3336 } |
3316 | 3337 |
3317 /// Records that [constant] is used by the element behind [registry]. | 3338 /// Records that [constant] is used by the element behind [registry]. |
3318 class Dependency { | 3339 class Dependency { |
3319 final ConstantValue constant; | 3340 final ConstantValue constant; |
3320 final Element annotatedElement; | 3341 final Element annotatedElement; |
3321 | 3342 |
3322 const Dependency(this.constant, this.annotatedElement); | 3343 const Dependency(this.constant, this.annotatedElement); |
3323 } | 3344 } |
3324 | |
OLD | NEW |