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 28 matching lines...) Expand all Loading... |
39 import '../patch_parser.dart'; | 39 import '../patch_parser.dart'; |
40 import '../resolved_uri_translator.dart'; | 40 import '../resolved_uri_translator.dart'; |
41 import '../universe/call_structure.dart'; | 41 import '../universe/call_structure.dart'; |
42 import '../universe/use.dart'; | 42 import '../universe/use.dart'; |
43 import '../universe/world_builder.dart'; | 43 import '../universe/world_builder.dart'; |
44 import '../universe/world_impact.dart'; | 44 import '../universe/world_impact.dart'; |
45 import 'no_such_method_resolver.dart'; | 45 import 'no_such_method_resolver.dart'; |
46 | 46 |
47 /// [FrontendStrategy] that loads '.dart' files and creates a resolved element | 47 /// [FrontendStrategy] that loads '.dart' files and creates a resolved element |
48 /// model using the resolver. | 48 /// model using the resolver. |
49 class ResolutionFrontEndStrategy extends FrontendStrategyBase { | 49 class ResolutionFrontEndStrategy extends FrontendStrategyBase |
| 50 with ComputeSpannableMixin { |
50 final Compiler _compiler; | 51 final Compiler _compiler; |
51 final _CompilerElementEnvironment _elementEnvironment; | 52 final _CompilerElementEnvironment _elementEnvironment; |
52 final CommonElements commonElements; | 53 final CommonElements commonElements; |
53 | 54 |
54 AnnotationProcessor _annotationProcessor; | 55 AnnotationProcessor _annotationProcessor; |
55 | 56 |
56 factory ResolutionFrontEndStrategy(Compiler compiler) { | 57 factory ResolutionFrontEndStrategy(Compiler compiler) { |
57 ElementEnvironment elementEnvironment = | 58 ElementEnvironment elementEnvironment = |
58 new _CompilerElementEnvironment(compiler); | 59 new _CompilerElementEnvironment(compiler); |
59 CommonElements commonElements = new CommonElements(elementEnvironment); | 60 CommonElements commonElements = new CommonElements(elementEnvironment); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 errorElement.messageKind, errorElement.messageArguments); | 216 errorElement.messageKind, errorElement.messageArguments); |
216 } | 217 } |
217 MethodElement mainMethod; | 218 MethodElement mainMethod; |
218 if (mainFunction != null && !mainFunction.isMalformed) { | 219 if (mainFunction != null && !mainFunction.isMalformed) { |
219 mainFunction.computeType(_compiler.resolution); | 220 mainFunction.computeType(_compiler.resolution); |
220 mainMethod = mainFunction; | 221 mainMethod = mainFunction; |
221 } | 222 } |
222 _elementEnvironment._mainFunction = mainMethod; | 223 _elementEnvironment._mainFunction = mainMethod; |
223 return mainMethod; | 224 return mainMethod; |
224 } | 225 } |
| 226 } |
225 | 227 |
| 228 class ComputeSpannableMixin { |
226 SourceSpan spanFromToken(Element currentElement, Token token) => | 229 SourceSpan spanFromToken(Element currentElement, Token token) => |
227 _spanFromTokens(currentElement, token, token); | 230 _spanFromTokens(currentElement, token, token); |
228 | 231 |
229 SourceSpan _spanFromTokens(Element currentElement, Token begin, Token end, | 232 SourceSpan _spanFromTokens(Element currentElement, Token begin, Token end, |
230 [Uri uri]) { | 233 [Uri uri]) { |
231 if (begin == null || end == null) { | 234 if (begin == null || end == null) { |
232 // TODO(ahe): We can almost always do better. Often it is only | 235 // TODO(ahe): We can almost always do better. Often it is only |
233 // end that is null. Otherwise, we probably know the current | 236 // end that is null. Otherwise, we probably know the current |
234 // URI. | 237 // URI. |
235 throw 'Cannot find tokens to produce error message.'; | 238 throw 'Cannot find tokens to produce error message.'; |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 @override | 875 @override |
873 WorkItem createWorkItem(MemberElement element) { | 876 WorkItem createWorkItem(MemberElement element) { |
874 assert(element.isDeclaration, failedAt(element)); | 877 assert(element.isDeclaration, failedAt(element)); |
875 if (element.isMalformed) return null; | 878 if (element.isMalformed) return null; |
876 | 879 |
877 assert(element is AnalyzableElement, | 880 assert(element is AnalyzableElement, |
878 failedAt(element, 'Element $element is not analyzable.')); | 881 failedAt(element, 'Element $element is not analyzable.')); |
879 return _resolution.createWorkItem(element); | 882 return _resolution.createWorkItem(element); |
880 } | 883 } |
881 } | 884 } |
OLD | NEW |