Skip to content

Commit c0bcfc0

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Simplify InformativeDataApplier API.
Change-Id: I870ddc6e2e862e5a4cabb597ada27813383168d5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441401 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 1172d43 commit c0bcfc0

File tree

3 files changed

+40
-53
lines changed

3 files changed

+40
-53
lines changed

pkg/analyzer/lib/src/summary2/bundle_reader.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,11 @@ class LibraryReader {
217217

218218
_declareDartCoreDynamicNever();
219219

220-
InformativeDataApplier(
220+
InformativeDataApplier().applyToLibrary(
221221
_elementFactory,
222+
_libraryElement,
222223
_unitsInformativeBytes,
223-
).applyTo(_libraryElement);
224+
);
224225

225226
return _libraryElement;
226227
}

pkg/analyzer/lib/src/summary2/informative_data.dart

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,44 @@ Uint8List writeUnitInformative(CompilationUnit unit) {
2626
}
2727

2828
class InformativeDataApplier {
29-
final LinkedElementFactory _elementFactory;
30-
final Map<Uri, Uint8List> _unitsInformativeBytes2;
29+
void applyFromNode(LibraryFragmentImpl fragment, CompilationUnit node) {
30+
var unitInfo = _InfoBuilder().build(node);
31+
_applyFromInfo(fragment, unitInfo);
3132

32-
InformativeDataApplier(this._elementFactory, this._unitsInformativeBytes2);
33+
// TODO(scheglov): generalize
34+
for (var classFragment in fragment.classes) {
35+
classFragment.applyMembersConstantOffsets?.call();
36+
classFragment.applyMembersConstantOffsets = null;
37+
}
38+
}
39+
40+
void applyToLibrary(
41+
LinkedElementFactory elementFactory,
42+
LibraryElementImpl libraryElement,
43+
Map<Uri, Uint8List> unitsInformativeBytes,
44+
) {
45+
if (elementFactory.isApplyingInformativeData) {
46+
throw StateError('Unexpected recursion.');
47+
}
48+
elementFactory.isApplyingInformativeData = true;
3349

34-
void applyFromInfoUnit(LibraryFragmentImpl unitElement, _InfoUnit unitInfo) {
50+
for (var unitElement in libraryElement.units) {
51+
var uri = unitElement.source.uri;
52+
if (unitsInformativeBytes[uri] case var infoBytes?) {
53+
_applyFromBytes(unitElement, infoBytes);
54+
}
55+
}
56+
57+
elementFactory.isApplyingInformativeData = false;
58+
}
59+
60+
void _applyFromBytes(LibraryFragmentImpl unitElement, Uint8List infoBytes) {
61+
var unitReader = SummaryDataReader(infoBytes);
62+
var unitInfo = _InfoUnit.read(unitReader);
63+
_applyFromInfo(unitElement, unitInfo);
64+
}
65+
66+
void _applyFromInfo(LibraryFragmentImpl unitElement, _InfoUnit unitInfo) {
3567
var libraryElement = unitElement.library;
3668
if (identical(libraryElement.definingCompilationUnit, unitElement)) {
3769
_applyToLibrary(libraryElement, unitInfo);
@@ -131,43 +163,6 @@ class InformativeDataApplier {
131163
);
132164
}
133165

134-
void applyFromUnit(LibraryFragmentImpl unitElement, CompilationUnit unit) {
135-
var unitInfo = _InfoBuilder().build(unit);
136-
applyFromInfoUnit(unitElement, unitInfo);
137-
138-
// TODO(scheglov): generalize
139-
for (var classFragment in unitElement.classes) {
140-
classFragment.applyMembersConstantOffsets?.call();
141-
classFragment.applyMembersConstantOffsets = null;
142-
}
143-
}
144-
145-
void applyTo(LibraryElementImpl libraryElement) {
146-
if (_elementFactory.isApplyingInformativeData) {
147-
throw StateError('Unexpected recursion.');
148-
}
149-
_elementFactory.isApplyingInformativeData = true;
150-
151-
var unitElements = libraryElement.units;
152-
for (var i = 0; i < unitElements.length; i++) {
153-
var unitElement = unitElements[i];
154-
var unitInfoBytes = _getInfoUnitBytes(unitElement);
155-
if (unitInfoBytes != null) {
156-
applyToUnit(unitElement, unitInfoBytes);
157-
} else {
158-
unitElement.lineInfo = LineInfo([0]);
159-
}
160-
}
161-
162-
_elementFactory.isApplyingInformativeData = false;
163-
}
164-
165-
void applyToUnit(LibraryFragmentImpl unitElement, Uint8List unitInfoBytes) {
166-
var unitReader = SummaryDataReader(unitInfoBytes);
167-
var unitInfo = _InfoUnit.read(unitReader);
168-
applyFromInfoUnit(unitElement, unitInfo);
169-
}
170-
171166
void _applyToAccessors(
172167
List<PropertyAccessorFragmentImpl> elementList,
173168
List<_InfoExecutableDeclaration> infoList,
@@ -617,11 +612,6 @@ class InformativeDataApplier {
617612
}
618613
}
619614

620-
Uint8List? _getInfoUnitBytes(LibraryFragmentImpl element) {
621-
var uri = element.source.uri;
622-
return _unitsInformativeBytes2[uri];
623-
}
624-
625615
void _setupApplyConstantOffsetsForTypeAlias(
626616
TypeAliasFragmentImpl element,
627617
Uint32List constantOffsets, {

pkg/analyzer/lib/src/summary2/library_builder.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,8 @@ class LibraryBuilder {
199199
parentChildFragments: _parentChildFragments,
200200
);
201201

202-
var informativeDataApplier = InformativeDataApplier(
203-
linker.elementFactory,
204-
{}, // No bytes from summary, we are building from source.
205-
);
206202
for (var linkingUnit in units) {
207-
informativeDataApplier.applyFromUnit(
203+
InformativeDataApplier().applyFromNode(
208204
linkingUnit.element,
209205
linkingUnit.node,
210206
);

0 commit comments

Comments
 (0)