mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 21:20:36 +00:00
Move 'libraryFiles' to LibraryFileStateKind.
Change-Id: Id0dd01322a2c43a678c9b0cfc9d8249f15a8cc2e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250115 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
39492df897
commit
7abfcfb83c
|
@ -777,7 +777,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
}
|
||||
|
||||
var units = <ParsedUnitResult>[];
|
||||
for (var unitFile in file.libraryFiles) {
|
||||
for (var unitFile in kind.files) {
|
||||
var unitPath = unitFile.path;
|
||||
var unitResult = parseFileSync(unitPath);
|
||||
if (unitResult is! ParsedUnitResult) {
|
||||
|
@ -1707,11 +1707,20 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
CaughtException caught = CaughtException(exception, stackTrace);
|
||||
|
||||
var fileContentMap = <String, String>{};
|
||||
var libraryFile = _fsState.getFileForPath(path);
|
||||
|
||||
var fileContent = '';
|
||||
try {
|
||||
for (var file in libraryFile.libraryFiles) {
|
||||
var path = file.path;
|
||||
fileContentMap[path] = file.content;
|
||||
final file = _fsState.getFileForPath(path);
|
||||
fileContent = file.content;
|
||||
final fileKind = file.kind;
|
||||
final libraryKind = fileKind.library;
|
||||
if (libraryKind != null) {
|
||||
for (final file in libraryKind.files) {
|
||||
fileContentMap[file.path] = file.content;
|
||||
}
|
||||
} else {
|
||||
final file = fileKind.file;
|
||||
fileContentMap[file.path] = file.content;
|
||||
}
|
||||
} catch (_) {
|
||||
// We might get an exception while parsing to access parts.
|
||||
|
@ -1728,7 +1737,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
ExceptionResult(
|
||||
filePath: path,
|
||||
fileContentMap: fileContentMap,
|
||||
fileContent: libraryFile.content,
|
||||
fileContent: fileContent,
|
||||
exception: caught,
|
||||
contextKey: contextKey,
|
||||
),
|
||||
|
|
|
@ -38,6 +38,7 @@ import 'package:analyzer/src/util/either.dart';
|
|||
import 'package:analyzer/src/util/file_paths.dart' as file_paths;
|
||||
import 'package:analyzer/src/util/performance/operation_performance.dart';
|
||||
import 'package:analyzer/src/util/uri.dart';
|
||||
import 'package:analyzer/src/utilities/extensions/collection.dart';
|
||||
import 'package:analyzer/src/workspace/workspace.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:convert/convert.dart';
|
||||
|
@ -280,7 +281,6 @@ class FileState {
|
|||
List<FileState?> _augmentationFiles = [];
|
||||
List<FileState?>? _importedFiles;
|
||||
List<FileState?>? _exportedFiles;
|
||||
List<FileState> _libraryFiles = [];
|
||||
|
||||
Set<FileState>? _directReferencedFiles;
|
||||
|
||||
|
@ -384,12 +384,6 @@ class FileState {
|
|||
|
||||
FileStateKind get kind => _kind!;
|
||||
|
||||
/// The list of files files that this library consists of, i.e. this library
|
||||
/// file itself and its [partedFiles].
|
||||
List<FileState> get libraryFiles {
|
||||
return _libraryFiles;
|
||||
}
|
||||
|
||||
/// Return information about line in the file.
|
||||
LineInfo get lineInfo => _lineInfo!;
|
||||
|
||||
|
@ -574,7 +568,6 @@ class FileState {
|
|||
|
||||
// Read parts eagerly to link parts to libraries.
|
||||
_updateKind();
|
||||
_updatePartedFiles();
|
||||
_updateAugmentationFiles();
|
||||
|
||||
// Update mapping from subtyped names to files.
|
||||
|
@ -832,14 +825,6 @@ class FileState {
|
|||
_invalidatesLibrariesOfThisPart();
|
||||
}
|
||||
|
||||
/// TODO(scheglov) Stop using [partedFiles].
|
||||
void _updatePartedFiles() {
|
||||
_libraryFiles = [
|
||||
this,
|
||||
...partedFiles.whereNotNull(),
|
||||
];
|
||||
}
|
||||
|
||||
static UnlinkedUnit serializeAstUnlinked2(
|
||||
CompilationUnit unit, {
|
||||
required bool isDartCore,
|
||||
|
@ -1602,6 +1587,29 @@ class LibraryFileStateKind extends LibraryOrAugmentationFileKind {
|
|||
required this.name,
|
||||
});
|
||||
|
||||
/// The list of files files that this library consists of, i.e. this library
|
||||
/// file itself, its [parts], and augmentations.
|
||||
List<FileState> get files {
|
||||
final files = [
|
||||
file,
|
||||
];
|
||||
|
||||
// TODO(scheglov) When we include only valid parts, use this instead.
|
||||
final includeOnlyValidParts = 0 > 1;
|
||||
for (final part in parts) {
|
||||
if (part is PartDirectiveWithFile) {
|
||||
if (includeOnlyValidParts) {
|
||||
files.addIfNotNull(part.includedPart?.file);
|
||||
} else {
|
||||
files.add(part.includedFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(scheglov) Include augmentations.
|
||||
return files;
|
||||
}
|
||||
|
||||
LibraryCycle? get internal_libraryCycle => _libraryCycle;
|
||||
|
||||
@override
|
||||
|
@ -1645,6 +1653,12 @@ class LibraryFileStateKind extends LibraryOrAugmentationFileKind {
|
|||
}).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
void discoverReferencedFiles() {
|
||||
super.discoverReferencedFiles();
|
||||
parts;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
invalidateLibraryCycle();
|
||||
|
@ -1761,6 +1775,17 @@ abstract class LibraryOrAugmentationFileKind extends FileStateKind {
|
|||
}).toList();
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// are available. So, we need to discover all referenced files before
|
||||
/// we register available objects.
|
||||
@visibleForTesting
|
||||
void discoverReferencedFiles() {
|
||||
imports;
|
||||
exports;
|
||||
}
|
||||
|
||||
bool hasAugmentation(AugmentationFileStateKind augmentation) {
|
||||
return file.augmentationFiles.contains(augmentation.file);
|
||||
}
|
||||
|
|
|
@ -280,11 +280,11 @@ class LibraryAnalyzer {
|
|||
}
|
||||
|
||||
if (_analysisOptions.lint) {
|
||||
var allUnits = _library.file.libraryFiles
|
||||
var allUnits = _library.files
|
||||
.map((file) => LinterContextUnit(file.content, units[file]!))
|
||||
.toList();
|
||||
for (int i = 0; i < allUnits.length; i++) {
|
||||
_computeLints(_library.file.libraryFiles[i], allUnits[i], allUnits,
|
||||
_computeLints(_library.files[i], allUnits[i], allUnits,
|
||||
analysisOptions: _analysisOptions);
|
||||
}
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ class LibraryAnalyzer {
|
|||
|
||||
// This must happen after all other diagnostics have been computed but
|
||||
// before the list of diagnostics has been filtered.
|
||||
for (var file in _library.file.libraryFiles) {
|
||||
for (var file in _library.files) {
|
||||
IgnoreValidator(
|
||||
_getErrorReporter(file),
|
||||
_getErrorListener(file).errors,
|
||||
|
@ -568,7 +568,7 @@ class LibraryAnalyzer {
|
|||
var units = <FileState, CompilationUnitImpl>{};
|
||||
|
||||
// Parse all files.
|
||||
for (FileState file in _library.file.libraryFiles) {
|
||||
for (FileState file in _library.files) {
|
||||
units[file] = _parse(file);
|
||||
}
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ class LibraryContext {
|
|||
var macroLibraries = <MacroLibrary>[];
|
||||
for (var library in cycle.libraries) {
|
||||
var macroClasses = <MacroClass>[];
|
||||
for (var file in library.file.libraryFiles) {
|
||||
for (var file in library.files) {
|
||||
unitsInformativeBytes[file.uri] = file.unlinked2.informativeBytes;
|
||||
for (var macroClass in file.unlinked2.macroClasses) {
|
||||
macroClasses.add(
|
||||
|
@ -182,7 +182,7 @@ class LibraryContext {
|
|||
|
||||
var inputUnits = <LinkInputUnit>[];
|
||||
var partIndex = -1;
|
||||
for (var file in library.file.libraryFiles) {
|
||||
for (var file in library.files) {
|
||||
var isSynthetic = !file.exists;
|
||||
var unit = file.parse();
|
||||
|
||||
|
@ -357,7 +357,7 @@ class LibraryContext {
|
|||
) {
|
||||
var fileContentMap = <String, String>{};
|
||||
for (var library in cycle.libraries) {
|
||||
for (var file in library.file.libraryFiles) {
|
||||
for (var file in library.files) {
|
||||
fileContentMap[file.path] = file.content;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ class LibraryCycle {
|
|||
|
||||
late final bool hasMacroClass = () {
|
||||
for (final library in libraries) {
|
||||
for (final file in library.file.libraryFiles) {
|
||||
for (final file in library.files) {
|
||||
if (file.unlinked2.macroClasses.isNotEmpty) {
|
||||
return true;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ class LibraryCycle {
|
|||
mightBeExecutedByMacroClass = true;
|
||||
// Mark each file of the cycle.
|
||||
for (final library in libraries) {
|
||||
for (final file in library.file.libraryFiles) {
|
||||
for (final file in library.files) {
|
||||
file.mightBeExecutedByMacroClass = true;
|
||||
}
|
||||
}
|
||||
|
@ -203,14 +203,16 @@ class _LibraryWalker extends graph.DependencyWalker<_LibraryNode> {
|
|||
implSignature.addLanguageVersion(file.packageLanguageVersion);
|
||||
implSignature.addString(file.uriStr);
|
||||
|
||||
apiSignature.addInt(file.libraryFiles.length);
|
||||
for (var file in file.libraryFiles) {
|
||||
final libraryFiles = node.kind.files;
|
||||
|
||||
apiSignature.addInt(libraryFiles.length);
|
||||
for (var file in libraryFiles) {
|
||||
apiSignature.addBool(file.exists);
|
||||
apiSignature.addBytes(file.apiSignature);
|
||||
}
|
||||
|
||||
implSignature.addInt(file.libraryFiles.length);
|
||||
for (var file in file.libraryFiles) {
|
||||
implSignature.addInt(libraryFiles.length);
|
||||
for (var file in libraryFiles) {
|
||||
implSignature.addBool(file.exists);
|
||||
implSignature.addString(file.contentHash);
|
||||
}
|
||||
|
|
|
@ -414,10 +414,13 @@ class Search {
|
|||
if (name.startsWith('_')) {
|
||||
String libraryPath = element.library!.source.fullName;
|
||||
if (searchedFiles.add(libraryPath, this)) {
|
||||
FileState library = _driver.fsState.getFileForPath(libraryPath);
|
||||
for (FileState file in library.libraryFiles) {
|
||||
if (file.path == path || file.referencedNames.contains(name)) {
|
||||
files.add(file.path);
|
||||
final libraryFile = _driver.fsState.getFileForPath(libraryPath);
|
||||
final libraryKind = libraryFile.kind;
|
||||
if (libraryKind is LibraryFileStateKind) {
|
||||
for (final file in libraryKind.files) {
|
||||
if (file.path == path || file.referencedNames.contains(name)) {
|
||||
files.add(file.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -336,16 +336,14 @@ class AnalyzerStatePrinter {
|
|||
}
|
||||
}
|
||||
|
||||
// Ask referenced libraries.
|
||||
// Discover referenced files.
|
||||
// This is required for consistency checking.
|
||||
// TODO(scheglov) Remove when we use these for cycles.
|
||||
for (final fileData in testData.files.values.toList()) {
|
||||
final current = fileSystemState.getExisting(fileData.file);
|
||||
if (current != null) {
|
||||
final kind = current.kind;
|
||||
if (kind is LibraryOrAugmentationFileKind) {
|
||||
kind.imports;
|
||||
kind.exports;
|
||||
kind.discoverReferencedFiles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -342,7 +342,7 @@ class Driver implements CommandLineStarter {
|
|||
if (kind is LibraryFileStateKind) {
|
||||
var status = await _runAnalyzer(file, options, formatter);
|
||||
allResult = allResult.max(status);
|
||||
analyzedFiles.addAll(file.libraryFiles);
|
||||
analyzedFiles.addAll(kind.files);
|
||||
} else if (kind is PartFileStateKind) {
|
||||
partFiles.add(file);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue