| 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 dart2js.resolution_strategy; | 5 library dart2js.resolution_strategy; |
| 6 | 6 |
| 7 import 'package:front_end/src/fasta/scanner.dart' show Token; | 7 import 'package:front_end/src/fasta/scanner.dart' show Token; |
| 8 | 8 |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common_elements.dart'; | 10 import '../common_elements.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 import '../frontend_strategy.dart'; | 25 import '../frontend_strategy.dart'; |
| 26 import '../js_backend/backend.dart'; | 26 import '../js_backend/backend.dart'; |
| 27 import '../js_backend/backend_usage.dart'; | 27 import '../js_backend/backend_usage.dart'; |
| 28 import '../js_backend/interceptor_data.dart'; | 28 import '../js_backend/interceptor_data.dart'; |
| 29 import '../js_backend/mirrors_analysis.dart'; | 29 import '../js_backend/mirrors_analysis.dart'; |
| 30 import '../js_backend/mirrors_data.dart'; | 30 import '../js_backend/mirrors_data.dart'; |
| 31 import '../js_backend/native_data.dart'; | 31 import '../js_backend/native_data.dart'; |
| 32 import '../js_backend/no_such_method_registry.dart'; | 32 import '../js_backend/no_such_method_registry.dart'; |
| 33 import '../js_backend/runtime_types.dart'; | 33 import '../js_backend/runtime_types.dart'; |
| 34 import '../library_loader.dart'; | 34 import '../library_loader.dart'; |
| 35 import '../native/enqueue.dart' show NativeResolutionEnqueuer; |
| 35 import '../native/resolver.dart'; | 36 import '../native/resolver.dart'; |
| 36 import '../tree/tree.dart' show Node; | 37 import '../tree/tree.dart' show Node; |
| 37 import '../serialization/task.dart'; | 38 import '../serialization/task.dart'; |
| 38 import '../patch_parser.dart'; | 39 import '../patch_parser.dart'; |
| 39 import '../resolved_uri_translator.dart'; | 40 import '../resolved_uri_translator.dart'; |
| 40 import '../universe/call_structure.dart'; | 41 import '../universe/call_structure.dart'; |
| 41 import '../universe/use.dart'; | 42 import '../universe/use.dart'; |
| 42 import '../universe/world_builder.dart'; | 43 import '../universe/world_builder.dart'; |
| 43 import '../universe/world_impact.dart'; | 44 import '../universe/world_impact.dart'; |
| 44 import 'no_such_method_resolver.dart'; | 45 import 'no_such_method_resolver.dart'; |
| 45 | 46 |
| 46 /// [FrontendStrategy] that loads '.dart' files and creates a resolved element | 47 /// [FrontendStrategy] that loads '.dart' files and creates a resolved element |
| 47 /// model using the resolver. | 48 /// model using the resolver. |
| 48 class ResolutionFrontEndStrategy implements FrontendStrategy { | 49 class ResolutionFrontEndStrategy extends FrontendStrategyBase { |
| 49 final Compiler _compiler; | 50 final Compiler _compiler; |
| 50 final _CompilerElementEnvironment _elementEnvironment; | 51 final _CompilerElementEnvironment _elementEnvironment; |
| 51 final CommonElements commonElements; | 52 final CommonElements commonElements; |
| 52 | 53 |
| 53 AnnotationProcessor _annotationProcessor; | 54 AnnotationProcessor _annotationProcessor; |
| 54 | 55 |
| 55 factory ResolutionFrontEndStrategy(Compiler compiler) { | 56 factory ResolutionFrontEndStrategy(Compiler compiler) { |
| 56 ElementEnvironment elementEnvironment = | 57 ElementEnvironment elementEnvironment = |
| 57 new _CompilerElementEnvironment(compiler); | 58 new _CompilerElementEnvironment(compiler); |
| 58 CommonElements commonElements = new CommonElements(elementEnvironment); | 59 CommonElements commonElements = new CommonElements(elementEnvironment); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 82 scriptLoader, | 83 scriptLoader, |
| 83 scriptScanner, | 84 scriptScanner, |
| 84 deserializer, | 85 deserializer, |
| 85 patchResolverFunc, | 86 patchResolverFunc, |
| 86 patchParser, | 87 patchParser, |
| 87 environment, | 88 environment, |
| 88 reporter, | 89 reporter, |
| 89 measurer); | 90 measurer); |
| 90 } | 91 } |
| 91 | 92 |
| 92 AnnotationProcessor get annotationProcesser => | 93 AnnotationProcessor get annotationProcesser => _annotationProcessor ??= |
| 93 _annotationProcessor ??= new _ElementAnnotationProcessor(_compiler); | 94 new _ElementAnnotationProcessor(_compiler, nativeBasicDataBuilder); |
| 94 | 95 |
| 95 @override | 96 @override |
| 96 NativeClassFinder createNativeClassFinder(NativeBasicData nativeBasicData) { | 97 NativeClassFinder createNativeClassFinder(NativeBasicData nativeBasicData) { |
| 97 return new ResolutionNativeClassFinder( | 98 return new ResolutionNativeClassFinder( |
| 98 _compiler.resolution, | 99 _compiler.resolution, |
| 99 _compiler.reporter, | 100 _compiler.reporter, |
| 100 elementEnvironment, | 101 elementEnvironment, |
| 101 commonElements, | 102 commonElements, |
| 102 nativeBasicData); | 103 nativeBasicData); |
| 103 } | 104 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 116 RuntimeTypesNeedBuilder createRuntimeTypesNeedBuilder() { | 117 RuntimeTypesNeedBuilder createRuntimeTypesNeedBuilder() { |
| 117 return new ResolutionRuntimeTypesNeedBuilderImpl( | 118 return new ResolutionRuntimeTypesNeedBuilderImpl( |
| 118 elementEnvironment, dartTypes); | 119 elementEnvironment, dartTypes); |
| 119 } | 120 } |
| 120 | 121 |
| 121 ResolutionWorldBuilder createResolutionWorldBuilder( | 122 ResolutionWorldBuilder createResolutionWorldBuilder( |
| 122 NativeBasicData nativeBasicData, | 123 NativeBasicData nativeBasicData, |
| 123 NativeDataBuilder nativeDataBuilder, | 124 NativeDataBuilder nativeDataBuilder, |
| 124 InterceptorDataBuilder interceptorDataBuilder, | 125 InterceptorDataBuilder interceptorDataBuilder, |
| 125 BackendUsageBuilder backendUsageBuilder, | 126 BackendUsageBuilder backendUsageBuilder, |
| 127 RuntimeTypesNeedBuilder rtiNeedBuilder, |
| 128 NativeResolutionEnqueuer nativeResolutionEnqueuer, |
| 126 SelectorConstraintsStrategy selectorConstraintsStrategy) { | 129 SelectorConstraintsStrategy selectorConstraintsStrategy) { |
| 127 return new ElementResolutionWorldBuilder( | 130 return new ElementResolutionWorldBuilder( |
| 128 _compiler.backend, | 131 _compiler.backend, |
| 129 _compiler.resolution, | 132 _compiler.resolution, |
| 130 nativeBasicData, | 133 nativeBasicData, |
| 131 nativeDataBuilder, | 134 nativeDataBuilder, |
| 132 interceptorDataBuilder, | 135 interceptorDataBuilder, |
| 133 backendUsageBuilder, | 136 backendUsageBuilder, |
| 137 rtiNeedBuilder, |
| 138 nativeResolutionEnqueuer, |
| 134 selectorConstraintsStrategy); | 139 selectorConstraintsStrategy); |
| 135 } | 140 } |
| 136 | 141 |
| 137 WorkItemBuilder createResolutionWorkItemBuilder( | 142 WorkItemBuilder createResolutionWorkItemBuilder( |
| 138 NativeBasicData nativeBasicData, | 143 NativeBasicData nativeBasicData, |
| 139 NativeDataBuilder nativeDataBuilder, | 144 NativeDataBuilder nativeDataBuilder, |
| 140 ImpactTransformer impactTransformer) { | 145 ImpactTransformer impactTransformer) { |
| 141 return new ResolutionWorkItemBuilder(_compiler.resolution); | 146 return new ResolutionWorkItemBuilder(_compiler.resolution); |
| 142 } | 147 } |
| 143 | 148 |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 } | 671 } |
| 667 } | 672 } |
| 668 | 673 |
| 669 /// AST-based logic for processing annotations. These annotations are processed | 674 /// AST-based logic for processing annotations. These annotations are processed |
| 670 /// very early in the compilation pipeline, typically this is before resolution | 675 /// very early in the compilation pipeline, typically this is before resolution |
| 671 /// is complete. Because of that this processor does a lightweight parse of the | 676 /// is complete. Because of that this processor does a lightweight parse of the |
| 672 /// annotation (which is restricted to a limited subset of the annotation | 677 /// annotation (which is restricted to a limited subset of the annotation |
| 673 /// syntax), and, once resolution completes, it validates that the parsed | 678 /// syntax), and, once resolution completes, it validates that the parsed |
| 674 /// annotations correspond to the correct element. | 679 /// annotations correspond to the correct element. |
| 675 class _ElementAnnotationProcessor implements AnnotationProcessor { | 680 class _ElementAnnotationProcessor implements AnnotationProcessor { |
| 676 Compiler _compiler; | 681 final Compiler _compiler; |
| 682 final NativeBasicDataBuilder _nativeBasicDataBuilder; |
| 677 | 683 |
| 678 _ElementAnnotationProcessor(this._compiler); | 684 _ElementAnnotationProcessor(this._compiler, this._nativeBasicDataBuilder); |
| 679 | 685 |
| 680 CommonElements get _commonElements => _compiler.resolution.commonElements; | 686 CommonElements get _commonElements => _compiler.resolution.commonElements; |
| 681 | 687 |
| 682 /// Check whether [cls] has a `@Native(...)` annotation, and if so, set its | 688 /// Check whether [cls] has a `@Native(...)` annotation, and if so, set its |
| 683 /// native name from the annotation. | 689 /// native name from the annotation. |
| 684 void extractNativeAnnotations(covariant LibraryElement library, | 690 void extractNativeAnnotations(covariant LibraryElement library) { |
| 685 NativeBasicDataBuilder nativeBasicDataBuilder) { | |
| 686 library.forEachLocalMember((Element element) { | 691 library.forEachLocalMember((Element element) { |
| 687 if (element.isClass) { | 692 if (element.isClass) { |
| 688 EagerAnnotationHandler.checkAnnotation(_compiler, element, | 693 EagerAnnotationHandler.checkAnnotation(_compiler, element, |
| 689 new NativeAnnotationHandler(nativeBasicDataBuilder)); | 694 new NativeAnnotationHandler(_nativeBasicDataBuilder)); |
| 690 } | 695 } |
| 691 }); | 696 }); |
| 692 } | 697 } |
| 693 | 698 |
| 694 void extractJsInteropAnnotations(covariant LibraryElement library, | 699 void extractJsInteropAnnotations(covariant LibraryElement library) { |
| 695 NativeBasicDataBuilder nativeBasicDataBuilder) { | |
| 696 bool checkJsInteropAnnotation(Element element) { | 700 bool checkJsInteropAnnotation(Element element) { |
| 697 return EagerAnnotationHandler.checkAnnotation( | 701 return EagerAnnotationHandler.checkAnnotation( |
| 698 _compiler, element, const JsInteropAnnotationHandler()); | 702 _compiler, element, const JsInteropAnnotationHandler()); |
| 699 } | 703 } |
| 700 | 704 |
| 701 if (checkJsInteropAnnotation(library)) { | 705 if (checkJsInteropAnnotation(library)) { |
| 702 nativeBasicDataBuilder.markAsJsInteropLibrary(library); | 706 _nativeBasicDataBuilder.markAsJsInteropLibrary(library); |
| 703 } | 707 } |
| 704 library.forEachLocalMember((Element element) { | 708 library.forEachLocalMember((Element element) { |
| 705 if (element.isClass) { | 709 if (element.isClass) { |
| 706 ClassElement cls = element; | 710 ClassElement cls = element; |
| 707 if (checkJsInteropAnnotation(element)) { | 711 if (checkJsInteropAnnotation(element)) { |
| 708 nativeBasicDataBuilder.markAsJsInteropClass(cls); | 712 _nativeBasicDataBuilder.markAsJsInteropClass(cls); |
| 709 } | 713 } |
| 710 } | 714 } |
| 711 }); | 715 }); |
| 712 } | 716 } |
| 713 | 717 |
| 714 void processJsInteropAnnotations( | 718 void processJsInteropAnnotations( |
| 715 NativeBasicData nativeBasicData, NativeDataBuilder nativeDataBuilder) { | 719 NativeBasicData nativeBasicData, NativeDataBuilder nativeDataBuilder) { |
| 716 if (_commonElements.jsAnnotationClass == null) return; | 720 if (_commonElements.jsAnnotationClass == null) return; |
| 717 | 721 |
| 718 ClassElement cls = _commonElements.jsAnnotationClass; | 722 ClassElement cls = _commonElements.jsAnnotationClass; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 @override | 872 @override |
| 869 WorkItem createWorkItem(MemberElement element) { | 873 WorkItem createWorkItem(MemberElement element) { |
| 870 assert(element.isDeclaration, failedAt(element)); | 874 assert(element.isDeclaration, failedAt(element)); |
| 871 if (element.isMalformed) return null; | 875 if (element.isMalformed) return null; |
| 872 | 876 |
| 873 assert(element is AnalyzableElement, | 877 assert(element is AnalyzableElement, |
| 874 failedAt(element, 'Element $element is not analyzable.')); | 878 failedAt(element, 'Element $element is not analyzable.')); |
| 875 return _resolution.createWorkItem(element); | 879 return _resolution.createWorkItem(element); |
| 876 } | 880 } |
| 877 } | 881 } |
| OLD | NEW |