| 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 29 matching lines...) Expand all Loading... |
| 40 import '../universe/call_structure.dart'; | 40 import '../universe/call_structure.dart'; |
| 41 import '../universe/use.dart'; | 41 import '../universe/use.dart'; |
| 42 import '../universe/world_builder.dart'; | 42 import '../universe/world_builder.dart'; |
| 43 import '../universe/world_impact.dart'; | 43 import '../universe/world_impact.dart'; |
| 44 import 'no_such_method_resolver.dart'; | 44 import 'no_such_method_resolver.dart'; |
| 45 | 45 |
| 46 /// [FrontendStrategy] that loads '.dart' files and creates a resolved element | 46 /// [FrontendStrategy] that loads '.dart' files and creates a resolved element |
| 47 /// model using the resolver. | 47 /// model using the resolver. |
| 48 class ResolutionFrontEndStrategy implements FrontendStrategy { | 48 class ResolutionFrontEndStrategy implements FrontendStrategy { |
| 49 final Compiler _compiler; | 49 final Compiler _compiler; |
| 50 final ElementEnvironment elementEnvironment; | 50 final _CompilerElementEnvironment _elementEnvironment; |
| 51 final CommonElements commonElements; | 51 final CommonElements commonElements; |
| 52 | 52 |
| 53 AnnotationProcessor _annotationProcessor; | 53 AnnotationProcessor _annotationProcessor; |
| 54 | 54 |
| 55 factory ResolutionFrontEndStrategy(Compiler compiler) { | 55 factory ResolutionFrontEndStrategy(Compiler compiler) { |
| 56 ElementEnvironment elementEnvironment = | 56 ElementEnvironment elementEnvironment = |
| 57 new _CompilerElementEnvironment(compiler); | 57 new _CompilerElementEnvironment(compiler); |
| 58 CommonElements commonElements = new CommonElements(elementEnvironment); | 58 CommonElements commonElements = new CommonElements(elementEnvironment); |
| 59 return new ResolutionFrontEndStrategy.internal( | 59 return new ResolutionFrontEndStrategy.internal( |
| 60 compiler, elementEnvironment, commonElements); | 60 compiler, elementEnvironment, commonElements); |
| 61 } | 61 } |
| 62 | 62 |
| 63 ResolutionFrontEndStrategy.internal( | 63 ResolutionFrontEndStrategy.internal( |
| 64 this._compiler, this.elementEnvironment, this.commonElements); | 64 this._compiler, this._elementEnvironment, this.commonElements); |
| 65 |
| 66 ElementEnvironment get elementEnvironment => _elementEnvironment; |
| 65 | 67 |
| 66 DartTypes get dartTypes => _compiler.types; | 68 DartTypes get dartTypes => _compiler.types; |
| 67 | 69 |
| 68 LibraryLoaderTask createLibraryLoader( | 70 LibraryLoaderTask createLibraryLoader( |
| 69 ResolvedUriTranslator uriTranslator, | 71 ResolvedUriTranslator uriTranslator, |
| 70 ScriptLoader scriptLoader, | 72 ScriptLoader scriptLoader, |
| 71 ElementScanner scriptScanner, | 73 ElementScanner scriptScanner, |
| 72 LibraryDeserializer deserializer, | 74 LibraryDeserializer deserializer, |
| 73 PatchResolverFunction patchResolverFunc, | 75 PatchResolverFunction patchResolverFunc, |
| 74 PatchParserTask patchParser, | 76 PatchParserTask patchParser, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 136 |
| 135 WorkItemBuilder createResolutionWorkItemBuilder( | 137 WorkItemBuilder createResolutionWorkItemBuilder( |
| 136 NativeBasicData nativeBasicData, | 138 NativeBasicData nativeBasicData, |
| 137 NativeDataBuilder nativeDataBuilder, | 139 NativeDataBuilder nativeDataBuilder, |
| 138 ImpactTransformer impactTransformer) { | 140 ImpactTransformer impactTransformer) { |
| 139 return new ResolutionWorkItemBuilder(_compiler.resolution); | 141 return new ResolutionWorkItemBuilder(_compiler.resolution); |
| 140 } | 142 } |
| 141 | 143 |
| 142 FunctionEntity computeMain( | 144 FunctionEntity computeMain( |
| 143 LibraryElement mainApp, WorldImpactBuilder impactBuilder) { | 145 LibraryElement mainApp, WorldImpactBuilder impactBuilder) { |
| 146 _elementEnvironment._mainLibrary = mainApp; |
| 144 if (mainApp == null) return null; | 147 if (mainApp == null) return null; |
| 145 MethodElement mainFunction; | 148 MethodElement mainFunction; |
| 146 Element main = mainApp.findExported(Identifiers.main); | 149 Element main = mainApp.findExported(Identifiers.main); |
| 147 ErroneousElement errorElement = null; | 150 ErroneousElement errorElement = null; |
| 148 if (main == null) { | 151 if (main == null) { |
| 149 if (_compiler.options.analyzeOnly) { | 152 if (_compiler.options.analyzeOnly) { |
| 150 if (!_compiler.analyzeAll) { | 153 if (!_compiler.analyzeAll) { |
| 151 errorElement = new ErroneousElementX(MessageKind.CONSIDER_ANALYZE_ALL, | 154 errorElement = new ErroneousElementX(MessageKind.CONSIDER_ANALYZE_ALL, |
| 152 {'main': Identifiers.main}, Identifiers.main, mainApp); | 155 {'main': Identifiers.main}, Identifiers.main, mainApp); |
| 153 } | 156 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 errorElement.isSynthesized && | 207 errorElement.isSynthesized && |
| 205 !mainApp.isSynthesized) { | 208 !mainApp.isSynthesized) { |
| 206 _compiler.reporter.reportWarningMessage(errorElement, | 209 _compiler.reporter.reportWarningMessage(errorElement, |
| 207 errorElement.messageKind, errorElement.messageArguments); | 210 errorElement.messageKind, errorElement.messageArguments); |
| 208 } | 211 } |
| 209 MethodElement mainMethod; | 212 MethodElement mainMethod; |
| 210 if (mainFunction != null && !mainFunction.isMalformed) { | 213 if (mainFunction != null && !mainFunction.isMalformed) { |
| 211 mainFunction.computeType(_compiler.resolution); | 214 mainFunction.computeType(_compiler.resolution); |
| 212 mainMethod = mainFunction; | 215 mainMethod = mainFunction; |
| 213 } | 216 } |
| 217 _elementEnvironment._mainFunction = mainMethod; |
| 214 return mainMethod; | 218 return mainMethod; |
| 215 } | 219 } |
| 216 | 220 |
| 217 SourceSpan spanFromToken(Element currentElement, Token token) => | 221 SourceSpan spanFromToken(Element currentElement, Token token) => |
| 218 _spanFromTokens(currentElement, token, token); | 222 _spanFromTokens(currentElement, token, token); |
| 219 | 223 |
| 220 SourceSpan _spanFromTokens(Element currentElement, Token begin, Token end, | 224 SourceSpan _spanFromTokens(Element currentElement, Token begin, Token end, |
| 221 [Uri uri]) { | 225 [Uri uri]) { |
| 222 if (begin == null || end == null) { | 226 if (begin == null || end == null) { |
| 223 // TODO(ahe): We can almost always do better. Often it is only | 227 // TODO(ahe): We can almost always do better. Often it is only |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 return node.sourcePosition; | 367 return node.sourcePosition; |
| 364 } | 368 } |
| 365 return null; | 369 return null; |
| 366 } | 370 } |
| 367 } | 371 } |
| 368 | 372 |
| 369 /// An element environment base on a [Compiler]. | 373 /// An element environment base on a [Compiler]. |
| 370 class _CompilerElementEnvironment implements ElementEnvironment { | 374 class _CompilerElementEnvironment implements ElementEnvironment { |
| 371 final Compiler _compiler; | 375 final Compiler _compiler; |
| 372 | 376 |
| 377 LibraryEntity _mainLibrary; |
| 378 FunctionEntity _mainFunction; |
| 379 |
| 373 _CompilerElementEnvironment(this._compiler); | 380 _CompilerElementEnvironment(this._compiler); |
| 374 | 381 |
| 375 LibraryProvider get _libraryProvider => _compiler.libraryLoader; | 382 LibraryProvider get _libraryProvider => _compiler.libraryLoader; |
| 376 Resolution get _resolution => _compiler.resolution; | 383 Resolution get _resolution => _compiler.resolution; |
| 377 | 384 |
| 378 ResolutionDynamicType get dynamicType => const ResolutionDynamicType(); | 385 ResolutionDynamicType get dynamicType => const ResolutionDynamicType(); |
| 379 | 386 |
| 380 @override | 387 @override |
| 381 LibraryEntity get mainLibrary => _compiler.mainApp; | 388 LibraryEntity get mainLibrary => _mainLibrary; |
| 382 | 389 |
| 383 @override | 390 @override |
| 384 FunctionEntity get mainFunction => _compiler.mainFunction; | 391 FunctionEntity get mainFunction => _mainFunction; |
| 385 | 392 |
| 386 @override | 393 @override |
| 387 Iterable<LibraryEntity> get libraries => _compiler.libraryLoader.libraries; | 394 Iterable<LibraryEntity> get libraries => _compiler.libraryLoader.libraries; |
| 388 | 395 |
| 389 @override | 396 @override |
| 390 String getLibraryName(LibraryElement library) => library.libraryName; | 397 String getLibraryName(LibraryElement library) => library.libraryName; |
| 391 | 398 |
| 392 @override | 399 @override |
| 393 ResolutionInterfaceType getThisType(ClassElement cls) { | 400 ResolutionInterfaceType getThisType(ClassElement cls) { |
| 394 cls.ensureResolved(_resolution); | 401 cls.ensureResolved(_resolution); |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 @override | 864 @override |
| 858 WorkItem createWorkItem(MemberElement element) { | 865 WorkItem createWorkItem(MemberElement element) { |
| 859 assert(element.isDeclaration, failedAt(element)); | 866 assert(element.isDeclaration, failedAt(element)); |
| 860 if (element.isMalformed) return null; | 867 if (element.isMalformed) return null; |
| 861 | 868 |
| 862 assert(element is AnalyzableElement, | 869 assert(element is AnalyzableElement, |
| 863 failedAt(element, 'Element $element is not analyzable.')); | 870 failedAt(element, 'Element $element is not analyzable.')); |
| 864 return _resolution.createWorkItem(element); | 871 return _resolution.createWorkItem(element); |
| 865 } | 872 } |
| 866 } | 873 } |
| OLD | NEW |