Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:async'; | |
| 6 | |
| 7 import 'package:front_end/src/base/processed_options.dart'; | |
| 8 import 'package:front_end/src/incremental_resolved_ast_generator_impl.dart'; | |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | |
| 10 | |
| 11 import 'compiler_options.dart'; | |
| 12 | |
| 13 /// Represents the difference between "old" and "new" states of a program. | |
| 14 /// | |
| 15 /// Not intended to be implemented or extended by clients. | |
| 16 class DeltaLibraries { | |
| 17 /// The new state of the program, as a map from Uri to resolved AST. | |
|
scheglov
2017/01/16 19:24:58
"to resolved library"?
Paul Berry
2017/01/17 13:45:31
Done.
| |
| 18 /// | |
| 19 /// Libraries whose resolved AST is known to be unchanged since the last | |
| 20 /// [DeltaLibraries] are not included. | |
| 21 final Map<Uri, ResolvedLibrary> newState; | |
| 22 | |
| 23 DeltaLibraries(this.newState); | |
| 24 | |
| 25 /// TODO(paulberry): add information about libraries that were removed. | |
| 26 } | |
| 27 | |
| 28 /// Represents the resolved ASTs for all the compilation units in a single | |
| 29 /// library. | |
| 30 /// | |
| 31 /// Not intended to be implemented or extended by clients. | |
| 32 class ResolvedLibrary { | |
| 33 final CompilationUnit definingCompilationUnit; | |
| 34 | |
| 35 ResolvedLibrary(this.definingCompilationUnit); | |
| 36 | |
| 37 // TODO(paulberry): add support for parts. | |
| 38 } | |
| 39 | |
| 40 /// Interface for generating an initial resolved representation of a program and | |
| 41 /// keeping it up to date as incremental changes are made. | |
| 42 /// | |
| 43 /// This class maintains an internal "previous program state"; each | |
| 44 /// time [computeDelta] is called, it updates the previous program state and | |
| 45 /// produces a representation of what has changed. When there are few changes, | |
| 46 /// a call to [computeDelta] should be much faster than compiling the whole | |
| 47 /// program from scratch. | |
| 48 /// | |
| 49 /// This class also maintains a set of "valid sources", which is a (possibly | |
| 50 /// empty) subset of the sources constituting the previous program state. Files | |
| 51 /// in this set are assumed to be unchanged since the last call to | |
| 52 /// [computeDelta]. | |
| 53 /// | |
| 54 /// Behavior is undefined if the client does not obey the following concurrency | |
| 55 /// restrictions: | |
| 56 /// - no two invocations of [computeDelta] may be outstanding at any given time. | |
| 57 /// - neither [invalidate] nor [invalidateAll] may be called while an invocation | |
| 58 /// of [computeDelta] is outstanding. | |
| 59 /// | |
| 60 /// Not intended to be implemented or extended by clients. | |
| 61 abstract class IncrementalResolvedAstGenerator { | |
| 62 /// Creates an [IncrementalResolvedAstGenerator] which is prepared to generate | |
| 63 /// resolved ASTs for the program whose main library is in the given | |
| 64 /// [source]. | |
| 65 /// | |
| 66 /// No file system access is performed by this constructor; the initial | |
| 67 /// "previous program state" is an empty program containing no code, and the | |
| 68 /// initial set of valid sources is empty. To obtain a resolved AST | |
| 69 /// representation of the program, call [computeDelta]. | |
| 70 factory IncrementalResolvedAstGenerator(Uri source, CompilerOptions options) = > | |
| 71 new IncrementalResolvedAstGeneratorImpl(source, new ProcessedOptions(optio ns)); | |
| 72 | |
| 73 /// Generates a resolved AST representation of the changes to the program, | |
| 74 /// assuming that all valid sources are unchanged since the last call to | |
| 75 /// [computeDelta]. | |
| 76 /// | |
| 77 /// Source files in the set of valid sources are guaranteed not to be re-read | |
| 78 /// from disk; they are assumed to be unchanged regardless of the state of the | |
| 79 /// filesystem. | |
| 80 /// | |
| 81 /// If the future completes successfully, the previous file state is updated | |
| 82 /// and the set of valid sources is set to the set of all sources in the | |
| 83 /// program. | |
| 84 /// | |
| 85 /// If the future completes with an error (due to errors in the compiled | |
| 86 /// source code), the caller may consider the previous file state and the set | |
| 87 /// of valid sources to be unchanged; this means that once the user fixes the | |
| 88 /// errors, it is safe to call [computeDelta] again. | |
| 89 Future<DeltaLibraries> computeDelta(); | |
| 90 | |
| 91 /// Remove any source file(s) associated with the given file path from the set | |
| 92 /// of valid sources. This guarantees that those files will be re-read on the | |
| 93 /// next call to [computeDelta]). | |
| 94 void invalidate(String path); | |
| 95 | |
| 96 /// Remove all source files from the set of valid sources. This guarantees | |
| 97 /// that all files will be re-read on the next call to [computeDelta]. | |
| 98 /// | |
| 99 /// Note that this does not erase the previous program state; the next time | |
| 100 /// [computeDelta] is called, if parts of the program are discovered to be | |
| 101 /// unchanged, parts of the previous program state will still be re-used to | |
| 102 /// speed up compilation. | |
| 103 void invalidateAll(); | |
| 104 } | |
| OLD | NEW |