Chromium Code Reviews| 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 library js_backend.interceptor_data; | 5 library js_backend.interceptor_data; |
| 6 | 6 |
| 7 import '../common/names.dart' show Identifiers; | 7 import '../common/names.dart' show Identifiers; |
| 8 import '../common_elements.dart' show CommonElements; | 8 import '../common_elements.dart' show CommonElements; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../elements/entities.dart'; | 10 import '../elements/entities.dart'; |
| 11 import '../elements/types.dart'; | |
| 11 import '../js/js.dart' as jsAst; | 12 import '../js/js.dart' as jsAst; |
| 12 import '../types/types.dart' show TypeMask; | 13 import '../types/types.dart' show TypeMask; |
| 13 import '../universe/selector.dart'; | 14 import '../universe/selector.dart'; |
| 14 import '../world.dart' show ClosedWorld; | 15 import '../world.dart' show ClosedWorld; |
| 15 import 'backend_helpers.dart'; | 16 import 'backend_helpers.dart'; |
| 16 import 'namer.dart'; | 17 import 'namer.dart'; |
| 17 import 'native_data.dart'; | 18 import 'native_data.dart'; |
| 18 | 19 |
| 19 abstract class InterceptorData { | 20 abstract class InterceptorData { |
| 20 /// Returns `true` if [cls] is an intercepted class. | 21 /// Returns `true` if [cls] is an intercepted class. |
| 21 bool isInterceptedClass(ClassEntity element); | 22 bool isInterceptedClass(ClassEntity element); |
| 22 | 23 |
| 23 bool isInterceptedMethod(MemberEntity element); | 24 bool isInterceptedMethod(MemberEntity element); |
| 24 bool fieldHasInterceptedGetter(FieldEntity element); | 25 bool fieldHasInterceptedGetter(FieldEntity element); |
| 25 bool fieldHasInterceptedSetter(FieldEntity element); | 26 bool fieldHasInterceptedSetter(FieldEntity element); |
| 26 bool isInterceptedName(String name); | 27 bool isInterceptedName(String name); |
| 27 bool isInterceptedSelector(Selector selector); | 28 bool isInterceptedSelector(Selector selector); |
| 28 bool isInterceptedMixinSelector(Selector selector, TypeMask mask); | 29 bool isInterceptedMixinSelector(Selector selector, TypeMask mask); |
| 29 Iterable<ClassEntity> get interceptedClasses; | 30 Iterable<ClassEntity> get interceptedClasses; |
| 30 bool isMixedIntoInterceptedClass(ClassEntity element); | 31 bool isMixedIntoInterceptedClass(ClassEntity element); |
| 31 | 32 |
| 32 /// Returns a set of interceptor classes that contain a member named [name] | 33 /// Returns a set of interceptor classes that contain a member named [name] |
| 33 /// | 34 /// |
| 34 /// Returns an empty set if there is no class. Do not modify the returned set. | 35 /// Returns an empty set if there is no class. Do not modify the returned set. |
| 35 Set<ClassEntity> getInterceptedClassesOn(String name); | 36 Set<ClassEntity> getInterceptedClassesOn(String name); |
| 37 | |
| 38 bool mayGenerateInstanceofCheck(DartType type); | |
|
Siggi Cherem (dart-lang)
2017/03/14 03:18:18
+dartdoc:
/// Whether the compiler can use the nat
Johnni Winther
2017/03/15 09:49:01
Done.
| |
| 36 } | 39 } |
| 37 | 40 |
| 38 abstract class InterceptorDataBuilder { | 41 abstract class InterceptorDataBuilder { |
| 39 void addInterceptors(ClassEntity cls); | 42 void addInterceptors(ClassEntity cls); |
| 40 void addInterceptorsForNativeClassMembers(ClassEntity cls); | 43 void addInterceptorsForNativeClassMembers(ClassEntity cls); |
| 41 InterceptorData onResolutionComplete(ClosedWorld closedWorld); | 44 InterceptorData onResolutionComplete(ClosedWorld closedWorld); |
| 42 } | 45 } |
| 43 | 46 |
| 44 class InterceptorDataImpl implements InterceptorData { | 47 class InterceptorDataImpl implements InterceptorData { |
| 45 final NativeData _nativeData; | 48 final NativeData _nativeData; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 if (_nativeData.isNativeOrExtendsNative(element)) return true; | 192 if (_nativeData.isNativeOrExtendsNative(element)) return true; |
| 190 if (interceptedClasses.contains(element)) return true; | 193 if (interceptedClasses.contains(element)) return true; |
| 191 if (_classesMixedIntoInterceptedClasses.contains(element)) return true; | 194 if (_classesMixedIntoInterceptedClasses.contains(element)) return true; |
| 192 return false; | 195 return false; |
| 193 } | 196 } |
| 194 | 197 |
| 195 bool isMixedIntoInterceptedClass(ClassElement element) => | 198 bool isMixedIntoInterceptedClass(ClassElement element) => |
| 196 _classesMixedIntoInterceptedClasses.contains(element); | 199 _classesMixedIntoInterceptedClasses.contains(element); |
| 197 | 200 |
| 198 Iterable<ClassElement> get interceptedClasses => _interceptedClasses; | 201 Iterable<ClassElement> get interceptedClasses => _interceptedClasses; |
| 202 | |
| 203 bool mayGenerateInstanceofCheck(DartType type) { | |
| 204 // We can use an instanceof check for raw types that have no subclass that | |
| 205 // is mixed-in or in an implements clause. | |
| 206 | |
| 207 if (!type.treatAsRaw) return false; | |
| 208 InterfaceType interfaceType = type; | |
| 209 ClassEntity classElement = interfaceType.element; | |
| 210 if (isInterceptedClass(classElement)) return false; | |
| 211 return _closedWorld.hasOnlySubclasses(classElement); | |
| 212 } | |
| 199 } | 213 } |
| 200 | 214 |
| 201 class InterceptorDataBuilderImpl implements InterceptorDataBuilder { | 215 class InterceptorDataBuilderImpl implements InterceptorDataBuilder { |
| 202 final NativeData _nativeData; | 216 final NativeData _nativeData; |
| 203 final BackendHelpers _helpers; | 217 final BackendHelpers _helpers; |
| 204 final CommonElements _commonElements; | 218 final CommonElements _commonElements; |
| 205 | 219 |
| 206 /// The members of instantiated interceptor classes: maps a member name to the | 220 /// The members of instantiated interceptor classes: maps a member name to the |
| 207 /// list of members that have that name. This map is used by the codegen to | 221 /// list of members that have that name. This map is used by the codegen to |
| 208 /// know whether a send must be intercepted or not. | 222 /// know whether a send must be intercepted or not. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 jsAst.Name name = namer.nameForGetInterceptor(classes); | 328 jsAst.Name name = namer.nameForGetInterceptor(classes); |
| 315 if (classes.contains(_helpers.jsInterceptorClass)) { | 329 if (classes.contains(_helpers.jsInterceptorClass)) { |
| 316 // We can't use a specialized [getInterceptorMethod], so we make | 330 // We can't use a specialized [getInterceptorMethod], so we make |
| 317 // sure we emit the one with all checks. | 331 // sure we emit the one with all checks. |
| 318 _specializedGetInterceptors[name] = _interceptorData.interceptedClasses; | 332 _specializedGetInterceptors[name] = _interceptorData.interceptedClasses; |
| 319 } else { | 333 } else { |
| 320 _specializedGetInterceptors[name] = classes; | 334 _specializedGetInterceptors[name] = classes; |
| 321 } | 335 } |
| 322 } | 336 } |
| 323 } | 337 } |
| OLD | NEW |