| 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 fasta.analyzer_loader; | 5 library fasta.analyzer_loader; |
| 6 | 6 |
| 7 import 'package:front_end/physical_file_system.dart'; | 7 import 'package:front_end/physical_file_system.dart'; |
| 8 import 'package:kernel/ast.dart' show Program; | 8 import 'package:kernel/ast.dart' show Program; |
| 9 | 9 |
| 10 import 'package:front_end/src/fasta/builder/builder.dart' show LibraryBuilder; | 10 import 'package:front_end/src/fasta/builder/builder.dart' show LibraryBuilder; |
| 11 | 11 |
| 12 import 'package:front_end/src/fasta/target_implementation.dart' | 12 import 'package:front_end/src/fasta/target_implementation.dart' |
| 13 show TargetImplementation; | 13 show TargetImplementation; |
| 14 | 14 |
| 15 import 'package:front_end/src/fasta/source/source_class_builder.dart' | 15 import 'package:front_end/src/fasta/source/source_class_builder.dart' |
| 16 show SourceClassBuilder; | 16 show SourceClassBuilder; |
| 17 | 17 |
| 18 import 'package:front_end/src/fasta/source/source_loader.dart' | 18 import 'package:front_end/src/fasta/source/source_loader.dart' |
| 19 show SourceLoader; | 19 show SourceLoader; |
| 20 | 20 |
| 21 import 'package:analyzer/src/fasta/element_store.dart' show ElementStore; | |
| 22 | |
| 23 import 'analyzer_diet_listener.dart' show AnalyzerDietListener; | 21 import 'analyzer_diet_listener.dart' show AnalyzerDietListener; |
| 24 | 22 |
| 25 import 'package:kernel/core_types.dart' show CoreTypes; | 23 import 'package:kernel/core_types.dart' show CoreTypes; |
| 26 import 'package:kernel/src/incremental_class_hierarchy.dart'; | 24 import 'package:kernel/src/incremental_class_hierarchy.dart'; |
| 27 | 25 |
| 28 class AnalyzerLoader<L> extends SourceLoader<L> { | 26 class AnalyzerLoader<L> extends SourceLoader<L> { |
| 29 ElementStore elementStore; | 27 AnalyzerLoader(TargetImplementation target) |
| 30 | |
| 31 /// Indicates whether a kernel representation of the code should be generated. | |
| 32 /// | |
| 33 /// When `false`, an analyzer AST is generated, and type inference is copied | |
| 34 /// over to it, but the result is not converted to a kernel representation. | |
| 35 /// | |
| 36 /// TODO(paulberry): remove this once "kompile" functionality is no longer | |
| 37 /// needed. | |
| 38 final bool generateKernel; | |
| 39 | |
| 40 /// Indicates whether a resolved AST should be generated. | |
| 41 /// | |
| 42 /// When `false`, an analyzer AST is generated, but none of the types or | |
| 43 /// elements pointed to by the AST are guaranteed to be correct. | |
| 44 /// | |
| 45 /// This is needed in order to support the old "kompile" use case, since the | |
| 46 /// tests of that functionality were based on the behavior prior to | |
| 47 /// integrating resolution and type inference with analyzer. | |
| 48 /// | |
| 49 /// TODO(paulberry): remove this once "kompile" functionality is no longer | |
| 50 /// needed. | |
| 51 final bool doResolution; | |
| 52 | |
| 53 AnalyzerLoader( | |
| 54 TargetImplementation target, this.generateKernel, this.doResolution) | |
| 55 : super(PhysicalFileSystem.instance, target); | 28 : super(PhysicalFileSystem.instance, target); |
| 56 | 29 |
| 57 @override | 30 @override |
| 58 void computeHierarchy(Program program) { | 31 void computeHierarchy(Program program) { |
| 59 elementStore = new ElementStore(coreLibrary, builders); | |
| 60 ticker.logMs("Built analyzer element model."); | 32 ticker.logMs("Built analyzer element model."); |
| 61 hierarchy = new IncrementalClassHierarchy(); | 33 hierarchy = new IncrementalClassHierarchy(); |
| 62 ticker.logMs("Computed class hierarchy"); | 34 ticker.logMs("Computed class hierarchy"); |
| 63 coreTypes = new CoreTypes(program); | 35 coreTypes = new CoreTypes(program); |
| 64 ticker.logMs("Computed core types"); | 36 ticker.logMs("Computed core types"); |
| 65 } | 37 } |
| 66 | 38 |
| 67 @override | 39 @override |
| 68 AnalyzerDietListener createDietListener(LibraryBuilder library) { | 40 AnalyzerDietListener createDietListener(LibraryBuilder library) { |
| 69 return new AnalyzerDietListener(library, elementStore, hierarchy, coreTypes, | 41 return new AnalyzerDietListener( |
| 70 typeInferenceEngine, generateKernel, doResolution); | 42 library, hierarchy, coreTypes, typeInferenceEngine); |
| 71 } | 43 } |
| 72 | 44 |
| 73 @override | 45 @override |
| 74 void checkOverrides(List<SourceClassBuilder> sourceClasses) { | 46 void checkOverrides(List<SourceClassBuilder> sourceClasses) { |
| 75 // Not implemented yet. Requires [hierarchy]. | 47 // Not implemented yet. Requires [hierarchy]. |
| 76 } | 48 } |
| 77 } | 49 } |
| OLD | NEW |