| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:front_end/file_system.dart'; | 7 import 'package:front_end/file_system.dart'; |
| 8 import 'package:front_end/incremental_kernel_generator.dart'; | 8 import 'package:front_end/incremental_kernel_generator.dart'; |
| 9 import 'package:front_end/incremental_resolved_ast_generator.dart'; | 9 import 'package:front_end/incremental_resolved_ast_generator.dart'; |
| 10 import 'package:front_end/src/base/processed_options.dart'; | 10 import 'package:front_end/src/base/processed_options.dart'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } | 22 } |
| 23 | 23 |
| 24 /// Implementation of [IncrementalKernelGenerator]. | 24 /// Implementation of [IncrementalKernelGenerator]. |
| 25 /// | 25 /// |
| 26 /// TODO(scheglov) Update the documentation. | 26 /// TODO(scheglov) Update the documentation. |
| 27 /// | 27 /// |
| 28 /// Theory of operation: an instance of [IncrementalResolvedAstGenerator] is | 28 /// Theory of operation: an instance of [IncrementalResolvedAstGenerator] is |
| 29 /// used to obtain resolved ASTs, and these are fed into kernel code generation | 29 /// used to obtain resolved ASTs, and these are fed into kernel code generation |
| 30 /// logic. | 30 /// logic. |
| 31 class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator { | 31 class IncrementalKernelGeneratorImpl implements IncrementalKernelGenerator { |
| 32 /// The URI of the program entry point. | |
| 33 final Uri _entryPoint; | |
| 34 | |
| 35 /// The compiler options, such as the [FileSystem], the SDK dill location, | 32 /// The compiler options, such as the [FileSystem], the SDK dill location, |
| 36 /// etc. | 33 /// etc. |
| 37 final ProcessedOptions _options; | 34 final ProcessedOptions _options; |
| 38 | 35 |
| 36 /// The object that knows how to resolve "package:" and "dart:" URIs. |
| 37 final TranslateUri _uriTranslator; |
| 38 |
| 39 /// The current file system state. |
| 40 final FileSystemState _fsState; |
| 41 |
| 42 /// The URI of the program entry point. |
| 43 final Uri _entryPoint; |
| 44 |
| 39 /// The set of absolute file URIs that were reported through [invalidate] | 45 /// The set of absolute file URIs that were reported through [invalidate] |
| 40 /// and not checked for actual changes yet. | 46 /// and not checked for actual changes yet. |
| 41 final Set<Uri> _invalidatedFiles = new Set<Uri>(); | 47 final Set<Uri> _invalidatedFiles = new Set<Uri>(); |
| 42 | 48 |
| 43 /// The object that knows how to resolve "package:" and "dart:" URIs. | |
| 44 TranslateUri _uriTranslator; | |
| 45 | |
| 46 /// The current file system state. | |
| 47 FileSystemState _fsState; | |
| 48 | |
| 49 /// The cached SDK kernel. | 49 /// The cached SDK kernel. |
| 50 DillTarget _sdkDillTarget; | 50 DillTarget _sdkDillTarget; |
| 51 | 51 |
| 52 IncrementalKernelGeneratorImpl(this._entryPoint, this._options); | 52 IncrementalKernelGeneratorImpl( |
| 53 this._options, this._uriTranslator, this._entryPoint) |
| 54 : _fsState = new FileSystemState(_options.fileSystem, _uriTranslator); |
| 53 | 55 |
| 54 @override | 56 @override |
| 55 Future<DeltaProgram> computeDelta( | 57 Future<DeltaProgram> computeDelta( |
| 56 {Future<Null> watch(Uri uri, bool used)}) async { | 58 {Future<Null> watch(Uri uri, bool used)}) async { |
| 57 await _initialize(); | |
| 58 await _ensureVmLibrariesLoaded(); | 59 await _ensureVmLibrariesLoaded(); |
| 59 await _refreshInvalidatedFiles(); | 60 await _refreshInvalidatedFiles(); |
| 60 | 61 |
| 61 // Ensure that the graph starting at the entry point is ready. | 62 // Ensure that the graph starting at the entry point is ready. |
| 62 await _fsState.getFile(_entryPoint); | 63 await _fsState.getFile(_entryPoint); |
| 63 | 64 |
| 64 DillTarget sdkTarget = await _getSdkDillTarget(); | 65 DillTarget sdkTarget = await _getSdkDillTarget(); |
| 65 // TODO(scheglov) Use it to also serve other package kernels. | 66 // TODO(scheglov) Use it to also serve other package kernels. |
| 66 | 67 |
| 67 KernelTarget kernelTarget = new KernelTarget(_fsState.fileSystemView, | 68 KernelTarget kernelTarget = new KernelTarget(_fsState.fileSystemView, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // TODO(scheglov) Read the SDK kernel. | 109 // TODO(scheglov) Read the SDK kernel. |
| 109 // _sdkDillTarget.read(options.sdkSummary); | 110 // _sdkDillTarget.read(options.sdkSummary); |
| 110 // await _sdkDillTarget.writeOutline(null); | 111 // await _sdkDillTarget.writeOutline(null); |
| 111 } else { | 112 } else { |
| 112 // Program sdkProgram = _sdkDillTarget.loader.program; | 113 // Program sdkProgram = _sdkDillTarget.loader.program; |
| 113 // sdkProgram.visitChildren(new _ClearCanonicalNamesVisitor()); | 114 // sdkProgram.visitChildren(new _ClearCanonicalNamesVisitor()); |
| 114 } | 115 } |
| 115 return _sdkDillTarget; | 116 return _sdkDillTarget; |
| 116 } | 117 } |
| 117 | 118 |
| 118 /// Ensure that asynchronous data from options is ready. | |
| 119 /// | |
| 120 /// Ideally this data should be prepared in the constructor, but constructors | |
| 121 /// cannot be asynchronous. | |
| 122 Future<Null> _initialize() async { | |
| 123 _uriTranslator ??= await _options.getUriTranslator(); | |
| 124 _fsState ??= new FileSystemState(_options.fileSystem, _uriTranslator); | |
| 125 } | |
| 126 | |
| 127 /// Refresh all the invalidated files and update dependencies. | 119 /// Refresh all the invalidated files and update dependencies. |
| 128 Future<Null> _refreshInvalidatedFiles() async { | 120 Future<Null> _refreshInvalidatedFiles() async { |
| 129 for (Uri fileUri in _invalidatedFiles) { | 121 for (Uri fileUri in _invalidatedFiles) { |
| 130 FileState file = await _fsState.getFile(fileUri); | 122 FileState file = await _fsState.getFile(fileUri); |
| 131 await file.refresh(); | 123 await file.refresh(); |
| 132 } | 124 } |
| 133 _invalidatedFiles.clear(); | 125 _invalidatedFiles.clear(); |
| 134 } | 126 } |
| 135 } | 127 } |
| 136 | 128 |
| 137 ///// Clears canonical names of [NamedNode] references. | 129 ///// Clears canonical names of [NamedNode] references. |
| 138 //class _ClearCanonicalNamesVisitor extends Visitor { | 130 //class _ClearCanonicalNamesVisitor extends Visitor { |
| 139 // defaultNode(Node node) { | 131 // defaultNode(Node node) { |
| 140 // if (node is NamedNode) { | 132 // if (node is NamedNode) { |
| 141 // node.reference.canonicalName = null; | 133 // node.reference.canonicalName = null; |
| 142 // } | 134 // } |
| 143 // node.visitChildren(this); | 135 // node.visitChildren(this); |
| 144 // } | 136 // } |
| 145 //} | 137 //} |
| OLD | NEW |