| 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 '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common_elements.dart'; | 8 import '../common_elements.dart'; |
| 9 import '../common/backend_api.dart'; | 9 import '../common/backend_api.dart'; |
| 10 import '../common/names.dart'; |
| 10 import '../common/resolution.dart'; | 11 import '../common/resolution.dart'; |
| 11 import '../common/tasks.dart'; | 12 import '../common/tasks.dart'; |
| 12 import '../compiler.dart'; | 13 import '../compiler.dart'; |
| 13 import '../elements/elements.dart'; | 14 import '../elements/elements.dart'; |
| 14 import '../elements/entities.dart'; | 15 import '../elements/entities.dart'; |
| 16 import '../elements/modelx.dart'; |
| 15 import '../elements/resolution_types.dart'; | 17 import '../elements/resolution_types.dart'; |
| 16 import '../environment.dart'; | 18 import '../environment.dart'; |
| 17 import '../enqueue.dart'; | 19 import '../enqueue.dart'; |
| 18 import '../frontend_strategy.dart'; | 20 import '../frontend_strategy.dart'; |
| 19 import '../js_backend/backend.dart'; | 21 import '../js_backend/backend.dart'; |
| 20 import '../js_backend/backend_usage.dart'; | 22 import '../js_backend/backend_usage.dart'; |
| 21 import '../js_backend/custom_elements_analysis.dart'; | 23 import '../js_backend/custom_elements_analysis.dart'; |
| 22 import '../js_backend/mirrors_analysis.dart'; | 24 import '../js_backend/mirrors_analysis.dart'; |
| 23 import '../js_backend/mirrors_data.dart'; | 25 import '../js_backend/mirrors_data.dart'; |
| 24 import '../js_backend/native_data.dart'; | 26 import '../js_backend/native_data.dart'; |
| 25 import '../js_backend/no_such_method_registry.dart'; | 27 import '../js_backend/no_such_method_registry.dart'; |
| 26 import '../library_loader.dart'; | 28 import '../library_loader.dart'; |
| 27 import '../native/resolver.dart'; | 29 import '../native/resolver.dart'; |
| 28 import '../serialization/task.dart'; | 30 import '../serialization/task.dart'; |
| 29 import '../patch_parser.dart'; | 31 import '../patch_parser.dart'; |
| 30 import '../resolved_uri_translator.dart'; | 32 import '../resolved_uri_translator.dart'; |
| 31 import '../universe/call_structure.dart'; | 33 import '../universe/call_structure.dart'; |
| 34 import '../universe/use.dart'; |
| 32 import '../universe/world_builder.dart'; | 35 import '../universe/world_builder.dart'; |
| 36 import '../universe/world_impact.dart'; |
| 33 | 37 |
| 34 /// [FrontendStrategy] that loads '.dart' files and creates a resolved element | 38 /// [FrontendStrategy] that loads '.dart' files and creates a resolved element |
| 35 /// model using the resolver. | 39 /// model using the resolver. |
| 36 class ResolutionFrontEndStrategy implements FrontEndStrategy { | 40 class ResolutionFrontEndStrategy implements FrontEndStrategy { |
| 37 final Compiler _compiler; | 41 final Compiler _compiler; |
| 38 final ElementEnvironment elementEnvironment; | 42 final ElementEnvironment elementEnvironment; |
| 39 AnnotationProcessor _annotationProcessor; | 43 AnnotationProcessor _annotationProcessor; |
| 40 | 44 |
| 41 ResolutionFrontEndStrategy(this._compiler) | 45 ResolutionFrontEndStrategy(this._compiler) |
| 42 : elementEnvironment = new _CompilerElementEnvironment(_compiler); | 46 : elementEnvironment = new _CompilerElementEnvironment(_compiler); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 patchParser, | 64 patchParser, |
| 61 environment, | 65 environment, |
| 62 reporter, | 66 reporter, |
| 63 measurer); | 67 measurer); |
| 64 } | 68 } |
| 65 | 69 |
| 66 AnnotationProcessor get annotationProcesser => | 70 AnnotationProcessor get annotationProcesser => |
| 67 _annotationProcessor ??= new _ElementAnnotationProcessor(_compiler); | 71 _annotationProcessor ??= new _ElementAnnotationProcessor(_compiler); |
| 68 | 72 |
| 69 @override | 73 @override |
| 70 NativeClassFinder createNativeClassResolver(NativeBasicData nativeBasicData) { | 74 NativeClassFinder createNativeClassFinder(NativeBasicData nativeBasicData) { |
| 71 return new ResolutionNativeClassFinder( | 75 return new ResolutionNativeClassFinder( |
| 72 _compiler.resolution, | 76 _compiler.resolution, |
| 73 _compiler.reporter, | 77 _compiler.reporter, |
| 74 elementEnvironment, | 78 elementEnvironment, |
| 75 _compiler.commonElements, | 79 _compiler.commonElements, |
| 76 nativeBasicData); | 80 nativeBasicData); |
| 77 } | 81 } |
| 78 | 82 |
| 79 NoSuchMethodResolver createNoSuchMethodResolver() => | 83 NoSuchMethodResolver createNoSuchMethodResolver() => |
| 80 new NoSuchMethodResolverImpl(); | 84 new NoSuchMethodResolverImpl(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 107 NativeBasicData nativeBasicData, | 111 NativeBasicData nativeBasicData, |
| 108 SelectorConstraintsStrategy selectorConstraintsStrategy) { | 112 SelectorConstraintsStrategy selectorConstraintsStrategy) { |
| 109 return new ElementResolutionWorldBuilder( | 113 return new ElementResolutionWorldBuilder( |
| 110 _compiler.backend, _compiler.resolution, selectorConstraintsStrategy); | 114 _compiler.backend, _compiler.resolution, selectorConstraintsStrategy); |
| 111 } | 115 } |
| 112 | 116 |
| 113 WorkItemBuilder createResolutionWorkItemBuilder( | 117 WorkItemBuilder createResolutionWorkItemBuilder( |
| 114 ImpactTransformer impactTransformer) { | 118 ImpactTransformer impactTransformer) { |
| 115 return new ResolutionWorkItemBuilder(_compiler.resolution); | 119 return new ResolutionWorkItemBuilder(_compiler.resolution); |
| 116 } | 120 } |
| 121 |
| 122 FunctionEntity computeMain( |
| 123 LibraryElement mainApp, WorldImpactBuilder impactBuilder) { |
| 124 if (mainApp == null) return null; |
| 125 MethodElement mainFunction; |
| 126 Element main = mainApp.findExported(Identifiers.main); |
| 127 ErroneousElement errorElement = null; |
| 128 if (main == null) { |
| 129 if (_compiler.options.analyzeOnly) { |
| 130 if (!_compiler.analyzeAll) { |
| 131 errorElement = new ErroneousElementX(MessageKind.CONSIDER_ANALYZE_ALL, |
| 132 {'main': Identifiers.main}, Identifiers.main, mainApp); |
| 133 } |
| 134 } else { |
| 135 // Compilation requires a main method. |
| 136 errorElement = new ErroneousElementX(MessageKind.MISSING_MAIN, |
| 137 {'main': Identifiers.main}, Identifiers.main, mainApp); |
| 138 } |
| 139 mainFunction = _compiler.backend.helperForMissingMain(); |
| 140 } else if (main.isError && main.isSynthesized) { |
| 141 if (main is ErroneousElement) { |
| 142 errorElement = main; |
| 143 } else { |
| 144 _compiler.reporter |
| 145 .internalError(main, 'Problem with ${Identifiers.main}.'); |
| 146 } |
| 147 mainFunction = _compiler.backend.helperForBadMain(); |
| 148 } else if (!main.isFunction) { |
| 149 errorElement = new ErroneousElementX(MessageKind.MAIN_NOT_A_FUNCTION, |
| 150 {'main': Identifiers.main}, Identifiers.main, main); |
| 151 mainFunction = _compiler.backend.helperForBadMain(); |
| 152 } else { |
| 153 mainFunction = main; |
| 154 mainFunction.computeType(_compiler.resolution); |
| 155 FunctionSignature parameters = mainFunction.functionSignature; |
| 156 if (parameters.requiredParameterCount > 2) { |
| 157 int index = 0; |
| 158 parameters.orderedForEachParameter((Element parameter) { |
| 159 if (index++ < 2) return; |
| 160 errorElement = new ErroneousElementX( |
| 161 MessageKind.MAIN_WITH_EXTRA_PARAMETER, |
| 162 {'main': Identifiers.main}, |
| 163 Identifiers.main, |
| 164 parameter); |
| 165 // Don't warn about main not being used: |
| 166 impactBuilder.registerStaticUse( |
| 167 new StaticUse.staticInvoke(mainFunction, CallStructure.NO_ARGS)); |
| 168 |
| 169 mainFunction = _compiler.backend.helperForMainArity(); |
| 170 }); |
| 171 } |
| 172 } |
| 173 if (mainFunction == null) { |
| 174 if (errorElement == null && |
| 175 !_compiler.options.analyzeOnly && |
| 176 !_compiler.analyzeAll) { |
| 177 _compiler.reporter |
| 178 .internalError(mainApp, "Problem with '${Identifiers.main}'."); |
| 179 } else { |
| 180 mainFunction = errorElement; |
| 181 } |
| 182 } |
| 183 if (errorElement != null && |
| 184 errorElement.isSynthesized && |
| 185 !mainApp.isSynthesized) { |
| 186 _compiler.reporter.reportWarningMessage(errorElement, |
| 187 errorElement.messageKind, errorElement.messageArguments); |
| 188 } |
| 189 MethodElement mainMethod; |
| 190 if (mainFunction != null && !mainFunction.isMalformed) { |
| 191 mainFunction.computeType(_compiler.resolution); |
| 192 mainMethod = mainFunction; |
| 193 } |
| 194 return mainMethod; |
| 195 } |
| 117 } | 196 } |
| 118 | 197 |
| 119 /// An element environment base on a [Compiler]. | 198 /// An element environment base on a [Compiler]. |
| 120 class _CompilerElementEnvironment implements ElementEnvironment { | 199 class _CompilerElementEnvironment implements ElementEnvironment { |
| 121 final Compiler _compiler; | 200 final Compiler _compiler; |
| 122 | 201 |
| 123 _CompilerElementEnvironment(this._compiler); | 202 _CompilerElementEnvironment(this._compiler); |
| 124 | 203 |
| 125 LibraryProvider get _libraryProvider => _compiler.libraryLoader; | 204 LibraryProvider get _libraryProvider => _compiler.libraryLoader; |
| 126 Resolution get _resolution => _compiler.resolution; | 205 Resolution get _resolution => _compiler.resolution; |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 library.forEachLocalMember((Element element) { | 456 library.forEachLocalMember((Element element) { |
| 378 if (element.isClass) { | 457 if (element.isClass) { |
| 379 ClassElement cls = element; | 458 ClassElement cls = element; |
| 380 if (checkJsInteropAnnotation(element)) { | 459 if (checkJsInteropAnnotation(element)) { |
| 381 nativeBasicDataBuilder.markAsJsInteropClass(cls); | 460 nativeBasicDataBuilder.markAsJsInteropClass(cls); |
| 382 } | 461 } |
| 383 } | 462 } |
| 384 }); | 463 }); |
| 385 } | 464 } |
| 386 } | 465 } |
| OLD | NEW |