Skip to content

Commit

Permalink
[cfe] Various changes to reduce use of SourceCompilationUnitImpl._sou…
Browse files Browse the repository at this point in the history
…rceLibraryBuilder

Change-Id: I36e00aa09b16855b22d9b0c6a4ce94ec4aee7de6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375641
Reviewed-by: Chloe Stefantsova <[email protected]>
  • Loading branch information
johnniwinther authored and Commit Queue committed Jul 16, 2024
1 parent 59e9a1a commit b288e5d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
46 changes: 32 additions & 14 deletions pkg/front_end/lib/src/source/source_compilation_unit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class SourceCompilationUnitImpl
/// an explicit @dart= language version annotation.
LanguageVersion _languageVersion;

bool postponedProblemsIssued = false;
List<PostponedProblem>? postponedProblems;
bool _postponedProblemsIssued = false;
List<PostponedProblem>? _postponedProblems;

/// Index of the library we use references for.
@override
Expand Down Expand Up @@ -256,26 +256,26 @@ class SourceCompilationUnitImpl
@override
void addPostponedProblem(
Message message, int charOffset, int length, Uri fileUri) {
if (postponedProblemsIssued) {
if (_postponedProblemsIssued) {
// Coverage-ignore-block(suite): Not run.
addProblem(message, charOffset, length, fileUri);
} else {
postponedProblems ??= <PostponedProblem>[];
postponedProblems!
_postponedProblems ??= <PostponedProblem>[];
_postponedProblems!
.add(new PostponedProblem(message, charOffset, length, fileUri));
}
}

@override
void issuePostponedProblems() {
postponedProblemsIssued = true;
if (postponedProblems == null) return;
for (int i = 0; i < postponedProblems!.length; ++i) {
PostponedProblem postponedProblem = postponedProblems![i];
_postponedProblemsIssued = true;
if (_postponedProblems == null) return;
for (int i = 0; i < _postponedProblems!.length; ++i) {
PostponedProblem postponedProblem = _postponedProblems![i];
addProblem(postponedProblem.message, postponedProblem.charOffset,
postponedProblem.length, postponedProblem.fileUri);
}
postponedProblems = null;
_postponedProblems = null;
}

@override
Expand Down Expand Up @@ -341,6 +341,24 @@ class SourceCompilationUnitImpl
@override
String toString() => 'SourceCompilationUnitImpl($fileUri)';

void _addNativeDependency(Library library, String nativeImportPath) {
MemberBuilder constructor = loader.getNativeAnnotation();
Arguments arguments =
new Arguments(<Expression>[new StringLiteral(nativeImportPath)]);
Expression annotation;
if (constructor.isConstructor) {
annotation = new ConstructorInvocation(
constructor.member as Constructor, arguments)
..isConst = true;
} else {
// Coverage-ignore-block(suite): Not run.
annotation =
new StaticInvocation(constructor.member as Procedure, arguments)
..isConst = true;
}
library.addAnnotation(annotation);
}

@override
void addDependencies(Library library, Set<SourceCompilationUnit> seen) {
if (!seen.add(this)) {
Expand All @@ -350,7 +368,7 @@ class SourceCompilationUnitImpl
for (Import import in _builderFactoryResult.imports) {
// Rather than add a LibraryDependency, we attach an annotation.
if (import.nativeImportPath != null) {
_sourceLibraryBuilder.addNativeDependency(import.nativeImportPath!);
_addNativeDependency(library, import.nativeImportPath!);
continue;
}

Expand Down Expand Up @@ -698,7 +716,7 @@ class SourceCompilationUnitImpl

@override
void addImportsToScope() {
bool explicitCoreImport = _sourceLibraryBuilder == loader.coreLibrary;
bool hasCoreImport = originImportUri == dartCore && !forPatchLibrary;
for (Import import in _builderFactoryResult.imports) {
if (import.importedCompilationUnit?.isPart ?? false) {
// Coverage-ignore-block(suite): Not run.
Expand All @@ -710,11 +728,11 @@ class SourceCompilationUnitImpl
fileUri);
}
if (import.importedLibraryBuilder == loader.coreLibrary) {
explicitCoreImport = true;
hasCoreImport = true;
}
import.finalizeImports(this);
}
if (!explicitCoreImport) {
if (!hasCoreImport) {
NameIterator<Builder> iterator = loader.coreLibrary.exportScope
.filteredNameIterator(
includeDuplicates: false, includeAugmentations: false);
Expand Down
18 changes: 0 additions & 18 deletions pkg/front_end/lib/src/source/source_library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1264,24 +1264,6 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
}
}

void addNativeDependency(String nativeImportPath) {
MemberBuilder constructor = loader.getNativeAnnotation();
Arguments arguments =
new Arguments(<Expression>[new StringLiteral(nativeImportPath)]);
Expression annotation;
if (constructor.isConstructor) {
annotation = new ConstructorInvocation(
constructor.member as Constructor, arguments)
..isConst = true;
} else {
// Coverage-ignore-block(suite): Not run.
annotation =
new StaticInvocation(constructor.member as Procedure, arguments)
..isConst = true;
}
library.addAnnotation(annotation);
}

void addDependencies(Library library, Set<SourceCompilationUnit> seen) {
compilationUnit.addDependencies(library, seen);
for (SourceCompilationUnit part in parts) {
Expand Down

0 comments on commit b288e5d

Please sign in to comment.