mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
Move collectTransitive() to FileStateKind.
Change-Id: Ia9254151442cf3f8c9acae19509c94a66c0e933f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250342 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
7004b1859f
commit
0beafc3a6d
1 changed files with 44 additions and 23 deletions
|
@ -470,16 +470,6 @@ class FileState {
|
|||
return other is FileState && other.uri == uri;
|
||||
}
|
||||
|
||||
/// Collect all files that are transitively referenced by this file via
|
||||
/// imports, exports, and parts.
|
||||
void collectAllReferencedFiles(Set<String> referencedFiles) {
|
||||
for (final file in directReferencedFiles) {
|
||||
if (referencedFiles.add(file.path)) {
|
||||
file.collectAllReferencedFiles(referencedFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a new parsed unresolved [CompilationUnit].
|
||||
CompilationUnitImpl parse([AnalysisErrorListener? errorListener]) {
|
||||
errorListener ??= AnalysisErrorListener.NULL_LISTENER;
|
||||
|
@ -1330,24 +1320,23 @@ class FileSystemState {
|
|||
}
|
||||
|
||||
/// Computes the set of [FileState]'s used/not used to analyze the given
|
||||
/// [files]. Removes the [FileState]'s of the files not used for analysis from
|
||||
/// [paths]. Removes the [FileState]'s of the files not used for analysis from
|
||||
/// the cache. Returns the set of unused [FileState]'s.
|
||||
Set<FileState> removeUnusedFiles(List<String> files) {
|
||||
var allReferenced = <String>{};
|
||||
for (var path in files) {
|
||||
allReferenced.add(path);
|
||||
_pathToFile[path]?.collectAllReferencedFiles(allReferenced);
|
||||
Set<FileState> removeUnusedFiles(List<String> paths) {
|
||||
final referenced = <FileState>{};
|
||||
for (final path in paths) {
|
||||
final library = _pathToFile[path]?.kind.library;
|
||||
library?.collectTransitive(referenced);
|
||||
}
|
||||
|
||||
var unusedPaths = _pathToFile.keys.toSet();
|
||||
unusedPaths.removeAll(allReferenced);
|
||||
|
||||
var removedFiles = <FileState>{};
|
||||
for (var path in unusedPaths) {
|
||||
changeFile(path, removedFiles);
|
||||
final removed = <FileState>{};
|
||||
for (final file in _pathToFile.values.toList()) {
|
||||
if (!referenced.contains(file)) {
|
||||
changeFile(file.path, removed);
|
||||
}
|
||||
}
|
||||
|
||||
return removedFiles;
|
||||
return removed;
|
||||
}
|
||||
|
||||
/// Clear all [FileState] data - all maps from path or URI, etc.
|
||||
|
@ -1705,6 +1694,16 @@ class LibraryFileStateKind extends LibraryOrAugmentationFileKind {
|
|||
}).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
void collectTransitive(Set<FileState> files) {
|
||||
super.collectTransitive(files);
|
||||
for (final part in parts) {
|
||||
if (part is PartDirectiveWithFile) {
|
||||
files.add(part.includedFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void discoverReferencedFiles() {
|
||||
super.discoverReferencedFiles();
|
||||
|
@ -1855,6 +1854,28 @@ abstract class LibraryOrAugmentationFileKind extends FileStateKind {
|
|||
}).toList();
|
||||
}
|
||||
|
||||
/// Collect files that are transitively referenced by this library.
|
||||
@mustCallSuper
|
||||
void collectTransitive(Set<FileState> files) {
|
||||
if (files.add(file)) {
|
||||
for (final augmentation in augmentations) {
|
||||
if (augmentation is ImportAugmentationDirectiveWithFile) {
|
||||
augmentation.importedAugmentation?.collectTransitive(files);
|
||||
}
|
||||
}
|
||||
for (final export in exports) {
|
||||
if (export is ExportDirectiveWithFile) {
|
||||
export.exportedLibrary?.collectTransitive(files);
|
||||
}
|
||||
}
|
||||
for (final import in imports) {
|
||||
if (import is ImportDirectiveWithFile) {
|
||||
import.importedLibrary?.collectTransitive(files);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Directives are usually pulled lazily (so that we can parse a file
|
||||
/// without pulling all its transitive references), but when we output
|
||||
/// textual dumps we want to check that we reference only objects that
|
||||
|
|
Loading…
Reference in a new issue