Skip to content

Commit 6efb5eb

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Store name2 in PropertyInducingElementImpl.
Change-Id: Ie56dcc3a9d3d0fd970604e06934ac21e8eccaac6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390820 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 86efd35 commit 6efb5eb

24 files changed

+862
-429
lines changed

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ import 'package:meta/meta.dart';
9696
// TODO(scheglov): Clean up the list of implicitly analyzed files.
9797
class AnalysisDriver {
9898
/// The version of data format, should be incremented on every format change.
99-
static const int DATA_VERSION = 396;
99+
static const int DATA_VERSION = 397;
100100

101101
/// The number of exception contexts allowed to write. Once this field is
102102
/// zero, we stop writing any new exception contexts in this process.

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9519,6 +9519,9 @@ abstract class PropertyInducingElementImpl
95199519
extends NonParameterVariableElementImpl
95209520
with MacroTargetElement
95219521
implements PropertyInducingElement, PropertyInducingFragment {
9522+
@override
9523+
FragmentNameImpl? name2;
9524+
95229525
/// The getter associated with this element.
95239526
@override
95249527
PropertyAccessorElementImpl? getter;
@@ -9580,21 +9583,6 @@ abstract class PropertyInducingElementImpl
95809583
LibraryFragment get libraryFragment =>
95819584
thisOrAncestorOfType<CompilationUnitElement>() as LibraryFragment;
95829585

9583-
@override
9584-
FragmentName? get name2 {
9585-
var name = this.name;
9586-
9587-
// If synthetic name.
9588-
if (name.isEmpty) {
9589-
return null;
9590-
}
9591-
9592-
return FragmentNameImpl(
9593-
name: name,
9594-
nameOffset: nameOffset,
9595-
);
9596-
}
9597-
95989586
@override
95999587
PropertyInducingFragment? get nextFragment =>
96009588
augmentation as PropertyInducingFragment?;

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,8 +1138,10 @@ class LibraryReader {
11381138
var reference = _readReference();
11391139
var getterReference = _readOptionalReference();
11401140
var setterReference = _readOptionalReference();
1141+
var fragmentName = _readFragmentName();
11411142

1142-
var name = reference.elementName;
1143+
// TODO(scheglov): we do this only because FieldElement2 uses this name.
1144+
var name = _reader.readStringReference();
11431145
var isConstElement = _reader.readBool();
11441146

11451147
FieldElementImpl element;
@@ -1148,6 +1150,7 @@ class LibraryReader {
11481150
} else {
11491151
element = FieldElementImpl(name, -1);
11501152
}
1153+
element.name2 = fragmentName;
11511154

11521155
var linkedData = FieldElementLinkedData(
11531156
reference: reference,
@@ -1691,8 +1694,10 @@ class LibraryReader {
16911694
var reference = _readReference();
16921695
var getterReference = _readOptionalReference();
16931696
var setterReference = _readOptionalReference();
1697+
var fragmentName = _readFragmentName();
16941698

1695-
var name = reference.elementName;
1699+
// TODO(scheglov): we do this only because FieldElement2 uses this name.
1700+
var name = _reader.readStringReference();
16961701
var isConst = _reader.readBool();
16971702

16981703
TopLevelVariableElementImpl element;
@@ -1701,6 +1706,7 @@ class LibraryReader {
17011706
} else {
17021707
element = TopLevelVariableElementImpl(name, -1);
17031708
}
1709+
element.name2 = fragmentName;
17041710

17051711
var linkedData = TopLevelVariableElementLinkedData(
17061712
reference: reference,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ class BundleWriter {
407407
_writeReference(element);
408408
_writeOptionalReference(element.getter?.reference);
409409
_writeOptionalReference(element.setter?.reference);
410+
_writeFragmentName(element.name2);
411+
_sink._writeStringReference(element.name);
410412
_sink.writeBool(element is ConstFieldElementImpl);
411413
FieldElementFlags.write(_sink, element);
412414
_sink._writeTopLevelInferenceError(element.typeInferenceError);
@@ -683,6 +685,8 @@ class BundleWriter {
683685
_writeReference(element);
684686
_writeOptionalReference(element.getter?.reference);
685687
_writeOptionalReference(element.setter?.reference);
688+
_writeFragmentName(element.name2);
689+
_sink._writeStringReference(element.name);
686690
_sink.writeBool(element.isConst);
687691
TopLevelVariableElementFlags.write(_sink, element);
688692
_sink._writeTopLevelInferenceError(element.typeInferenceError);

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,15 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
288288
for (var i = 0; i < constants.length; ++i) {
289289
var constant = constants[i];
290290
var name = constant.name.lexeme;
291+
var fragmentName = _buildFragmentName(constant.name);
291292
var field = ConstFieldElementImpl(name, constant.name.offset)
292293
..hasImplicitType = true
293294
..hasInitializer = true
294295
..isAugmentation = constant.augmentKeyword != null
295296
..isConst = true
296297
..isEnumConstant = true
297298
..isStatic = true;
299+
field.name2 = fragmentName;
298300
_setCodeRange(field, constant);
299301
_setDocumentation(field, constant);
300302
field.metadata = _buildAnnotationsWithUnit(
@@ -349,7 +351,10 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
349351
_linker.elementNodes[field] = variableDeclaration;
350352

351353
field.constantInitializer = initializer;
352-
holder.addNonSyntheticField(field);
354+
355+
var refName = fragmentName?.name ?? '${_nextUnnamedId++}';
356+
holder.addNonSyntheticField(refName, field);
357+
353358
valuesElements.add(
354359
SimpleIdentifierImpl(
355360
StringToken(TokenType.STRING, name, -1),
@@ -405,7 +410,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
405410
);
406411
_linker.elementNodes[valuesField] = variableDeclaration;
407412

408-
holder.addNonSyntheticField(valuesField);
413+
holder.addNonSyntheticField('values', valuesField);
409414

410415
_libraryBuilder.implicitEnumNodes[element] = ImplicitEnumNodes(
411416
element: element,
@@ -632,6 +637,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
632637
var nameToken = variable.name;
633638
var name = nameToken.lexeme;
634639
var nameOffset = nameToken.offset;
640+
var fragmentName = _buildFragmentName(nameToken);
635641

636642
var element = FieldElementImpl(name, nameOffset);
637643
if (variable.initializer case var initializer?) {
@@ -648,6 +654,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
648654
}
649655
}
650656

657+
element.name2 = fragmentName;
651658
element.hasInitializer = variable.initializer != null;
652659
element.isAbstract = node.abstractKeyword != null;
653660
element.isAugmentation = node.augmentKeyword != null;
@@ -665,7 +672,8 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
665672
element.hasImplicitType = true;
666673
}
667674

668-
_enclosingContext.addNonSyntheticField(element);
675+
var refName = fragmentName?.name ?? '${_nextUnnamedId++}';
676+
_enclosingContext.addNonSyntheticField(refName, element);
669677

670678
_linker.elementNodes[element] = variable;
671679
variable.declaredElement = element;
@@ -1273,6 +1281,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
12731281
var nameToken = variable.name;
12741282
var name = nameToken.lexeme;
12751283
var nameOffset = nameToken.offset;
1284+
var fragmentName = _buildFragmentName(nameToken);
12761285

12771286
TopLevelVariableElementImpl element;
12781287
if (node.variables.isConst) {
@@ -1282,6 +1291,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
12821291
element = TopLevelVariableElementImpl(name, nameOffset);
12831292
}
12841293

1294+
element.name2 = fragmentName;
12851295
element.hasInitializer = variable.initializer != null;
12861296
element.isAugmentation = node.augmentKeyword != null;
12871297
element.isConst = node.variables.isConst;
@@ -1296,22 +1306,24 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
12961306
element.hasImplicitType = true;
12971307
}
12981308

1309+
var refName = fragmentName?.name ?? '${_nextUnnamedId++}';
1310+
_enclosingContext.addTopLevelVariable(refName, element);
1311+
12991312
{
1300-
var ref = enclosingRef.getChild('@getter').addChild(name);
1313+
var ref = enclosingRef.getChild('@getter').addChild(refName);
13011314
var getter = element.createImplicitGetter(ref);
13021315
_enclosingContext.addPropertyAccessorSynthetic(getter);
13031316
_libraryBuilder.declare(name, ref);
13041317
}
13051318

13061319
if (element.hasSetter) {
1307-
var ref = enclosingRef.getChild('@setter').addChild(name);
1320+
var ref = enclosingRef.getChild('@setter').addChild(refName);
13081321
var setter = element.createImplicitSetter(ref);
13091322
_enclosingContext.addPropertyAccessorSynthetic(setter);
13101323
_libraryBuilder.declare('$name=', ref);
13111324
}
13121325

13131326
_linker.elementNodes[element] = variable;
1314-
_enclosingContext.addTopLevelVariable(name, element);
13151327
variable.declaredElement = element;
13161328

13171329
_libraryBuilder.topVariables.addVariable(element);
@@ -1500,11 +1512,13 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
15001512

15011513
var fieldNameToken = representation.fieldName;
15021514
var fieldName = fieldNameToken.lexeme.ifNotEmptyOrElse('<empty>');
1515+
var fieldFragmentName = _buildFragmentName(fieldNameToken);
15031516

15041517
var fieldElement = FieldElementImpl(
15051518
fieldName,
15061519
fieldNameToken.offset,
15071520
);
1521+
fieldElement.name2 = fieldFragmentName;
15081522
fieldElement.isFinal = true;
15091523
fieldElement.metadata = _buildAnnotations(representation.fieldMetadata);
15101524

@@ -1516,7 +1530,7 @@ class ElementBuilder extends ThrowingAstVisitor<void> {
15161530

15171531
representation.fieldElement = fieldElement;
15181532
_linker.elementNodes[fieldElement] = representation;
1519-
_enclosingContext.addNonSyntheticField(fieldElement);
1533+
_enclosingContext.addNonSyntheticField(fieldName, fieldElement);
15201534

15211535
var formalParameterElement = FieldFormalParameterElementImpl(
15221536
name: fieldName,
@@ -1831,8 +1845,7 @@ class _EnclosingContext {
18311845
return _addReference(containerName, name, element);
18321846
}
18331847

1834-
void addNonSyntheticField(FieldElementImpl element) {
1835-
var name = element.name;
1848+
void addNonSyntheticField(String name, FieldElementImpl element) {
18361849
addField(name, element);
18371850

18381851
// Augmenting a variable with a variable only alters its initializer.

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ class InformativeDataApplier {
447447
var representationField = element.fields.first;
448448
var infoRep = info.representation;
449449
representationField.nameOffset = infoRep.fieldNameOffset;
450+
_setFragmentNameOffset(
451+
representationField.name2,
452+
infoRep.fieldNameOffset2,
453+
);
450454
representationField.setCodeRange(
451455
infoRep.fieldCodeOffset,
452456
infoRep.fieldCodeLength,
@@ -533,6 +537,7 @@ class InformativeDataApplier {
533537
element as FieldElementImpl;
534538
element.setCodeRange(info.codeOffset, info.codeLength);
535539
element.nameOffset = info.nameOffset;
540+
_setFragmentNameOffset(element.name2, info.nameOffset2);
536541
element.documentationComment = info.documentationComment;
537542

538543
var applyOffsets = ApplyConstantOffsets(
@@ -779,6 +784,7 @@ class InformativeDataApplier {
779784
element as TopLevelVariableElementImpl;
780785
element.setCodeRange(info.codeOffset, info.codeLength);
781786
element.nameOffset = info.nameOffset;
787+
_setFragmentNameOffset(element.name2, info.nameOffset2);
782788
element.documentationComment = info.documentationComment;
783789

784790
var applyOffsets = ApplyConstantOffsets(
@@ -1139,6 +1145,7 @@ class _InfoExtensionTypeRepresentation {
11391145
final int fieldCodeOffset;
11401146
final int fieldCodeLength;
11411147
final int fieldNameOffset;
1148+
final int? fieldNameOffset2;
11421149
final Uint32List fieldConstantOffsets;
11431150

11441151
factory _InfoExtensionTypeRepresentation(SummaryDataReader reader) {
@@ -1152,6 +1159,7 @@ class _InfoExtensionTypeRepresentation {
11521159
fieldCodeOffset: reader.readUInt30(),
11531160
fieldCodeLength: reader.readUInt30(),
11541161
fieldNameOffset: reader.readUInt30(),
1162+
fieldNameOffset2: reader.readOptionalUInt30(),
11551163
fieldConstantOffsets: reader.readUInt30List(),
11561164
);
11571165
}
@@ -1166,6 +1174,7 @@ class _InfoExtensionTypeRepresentation {
11661174
required this.fieldCodeOffset,
11671175
required this.fieldCodeLength,
11681176
required this.fieldNameOffset,
1177+
required this.fieldNameOffset2,
11691178
required this.fieldConstantOffsets,
11701179
});
11711180
}
@@ -1174,6 +1183,7 @@ class _InfoFieldDeclaration {
11741183
final int codeOffset;
11751184
final int codeLength;
11761185
final int nameOffset;
1186+
final int? nameOffset2;
11771187
final String? documentationComment;
11781188
final Uint32List constantOffsets;
11791189

@@ -1182,6 +1192,7 @@ class _InfoFieldDeclaration {
11821192
codeOffset: reader.readUInt30(),
11831193
codeLength: reader.readUInt30(),
11841194
nameOffset: reader.readUInt30(),
1195+
nameOffset2: reader.readOptionalUInt30(),
11851196
documentationComment: reader.readStringUtf8().nullIfEmpty,
11861197
constantOffsets: reader.readUInt30List(),
11871198
);
@@ -1191,6 +1202,7 @@ class _InfoFieldDeclaration {
11911202
required this.codeOffset,
11921203
required this.codeLength,
11931204
required this.nameOffset,
1205+
required this.nameOffset2,
11941206
required this.documentationComment,
11951207
required this.constantOffsets,
11961208
});
@@ -1721,6 +1733,7 @@ class _InformativeDataWriter {
17211733
sink.writeUInt30(codeOffset);
17221734
sink.writeUInt30(node.end - codeOffset);
17231735
sink.writeUInt30(node.name.offset);
1736+
sink.writeOptionalUInt30(node.name.offsetIfNotEmpty);
17241737
_writeDocumentationComment(node);
17251738
_writeOffsets(
17261739
metadata: node.metadata,
@@ -1738,6 +1751,7 @@ class _InformativeDataWriter {
17381751
sink.writeUInt30(codeOffset);
17391752
sink.writeUInt30(node.end - codeOffset);
17401753
sink.writeUInt30(node.name.offset);
1754+
sink.writeOptionalUInt30(node.name.offsetIfNotEmpty);
17411755
_writeDocumentationComment(node);
17421756

17431757
// TODO(scheglov): Replace with some kind of double-iterating list.
@@ -1955,6 +1969,7 @@ class _InformativeDataWriter {
19551969
sink.writeUInt30(codeOffset);
19561970
sink.writeUInt30(codeEnd - codeOffset);
19571971
sink.writeUInt30(node.fieldName.offset);
1972+
sink.writeOptionalUInt30(node.fieldName.offsetIfNotEmpty);
19581973

19591974
_writeOffsets(
19601975
metadata: node.fieldMetadata,
@@ -1966,6 +1981,7 @@ class _InformativeDataWriter {
19661981
sink.writeUInt30(codeOffset);
19671982
sink.writeUInt30(node.end - codeOffset);
19681983
sink.writeUInt30(node.name.offset);
1984+
sink.writeOptionalUInt30(node.name.offsetIfNotEmpty);
19691985
_writeDocumentationComment(node);
19701986

19711987
// TODO(scheglov): Replace with some kind of double-iterating list.
@@ -1991,6 +2007,7 @@ class _InfoTopLevelVariable {
19912007
final int codeOffset;
19922008
final int codeLength;
19932009
final int nameOffset;
2010+
final int? nameOffset2;
19942011
final String? documentationComment;
19952012
final Uint32List constantOffsets;
19962013

@@ -1999,6 +2016,7 @@ class _InfoTopLevelVariable {
19992016
codeOffset: reader.readUInt30(),
20002017
codeLength: reader.readUInt30(),
20012018
nameOffset: reader.readUInt30(),
2019+
nameOffset2: reader.readOptionalUInt30(),
20022020
documentationComment: reader.readStringUtf8().nullIfEmpty,
20032021
constantOffsets: reader.readUInt30List(),
20042022
);
@@ -2008,6 +2026,7 @@ class _InfoTopLevelVariable {
20082026
required this.codeOffset,
20092027
required this.codeLength,
20102028
required this.nameOffset,
2029+
required this.nameOffset2,
20112030
required this.documentationComment,
20122031
required this.constantOffsets,
20132032
});

0 commit comments

Comments
 (0)