Skip to content

Commit 27c9d5a

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Rename offsets in field fragment/builder
+ make constructors use named parameters. Change-Id: I226db6c8d409949eede8b7e220ee5b445b7d5080 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392361 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]>
1 parent f2bb37f commit 27c9d5a

File tree

8 files changed

+325
-377
lines changed

8 files changed

+325
-377
lines changed

pkg/front_end/lib/src/fragment/field.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class FieldFragment implements Fragment {
99
final String name;
1010

1111
final Uri fileUri;
12-
final int charOffset;
13-
final int charEndOffset;
12+
final int nameOffset;
13+
final int endOffset;
1414
Token? _initializerToken;
1515
Token? _constInitializerToken;
1616
final List<MetadataBuilder>? metadata;
@@ -23,8 +23,8 @@ class FieldFragment implements Fragment {
2323
FieldFragment(
2424
{required this.name,
2525
required this.fileUri,
26-
required this.charOffset,
27-
required this.charEndOffset,
26+
required this.nameOffset,
27+
required this.endOffset,
2828
required Token? initializerToken,
2929
required Token? constInitializerToken,
3030
required this.metadata,
@@ -60,5 +60,5 @@ class FieldFragment implements Fragment {
6060
}
6161

6262
@override
63-
String toString() => '$runtimeType($name,$fileUri,$charOffset)';
63+
String toString() => '$runtimeType($name,$fileUri,$nameOffset)';
6464
}

pkg/front_end/lib/src/fragment/typedef.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TypedefFragment implements Fragment {
1313
final List<NominalParameterBuilder>? typeParameters;
1414
final TypeBuilder type;
1515
final Uri fileUri;
16-
final int fileOffset;
16+
final int nameOffset;
1717

1818
SourceTypeAliasBuilder? _builder;
1919

@@ -23,7 +23,7 @@ class TypedefFragment implements Fragment {
2323
required this.typeParameters,
2424
required this.type,
2525
required this.fileUri,
26-
required this.fileOffset});
26+
required this.nameOffset});
2727

2828
@override
2929
// Coverage-ignore(suite): Not run.
@@ -38,5 +38,5 @@ class TypedefFragment implements Fragment {
3838
}
3939

4040
@override
41-
String toString() => "$runtimeType($name,$fileUri,$fileOffset)";
41+
String toString() => "$runtimeType($name,$fileUri,$nameOffset)";
4242
}

pkg/front_end/lib/src/source/builder_factory.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ abstract class BuilderFactory {
288288
String name,
289289
List<NominalParameterBuilder>? typeParameters,
290290
TypeBuilder type,
291-
int charOffset);
291+
int nameOffset);
292292

293293
void addClassMethod(
294294
{required OffsetMap offsetMap,
@@ -344,7 +344,7 @@ abstract class BuilderFactory {
344344
{required List<MetadataBuilder>? metadata,
345345
required TypeBuilder type,
346346
required String name,
347-
required int charOffset});
347+
required int nameOffset});
348348

349349
void addFactoryMethod(
350350
{required OffsetMap offsetMap,
@@ -498,8 +498,8 @@ class FieldInfo {
498498
final Identifier identifier;
499499
final Token? initializerToken;
500500
final Token? beforeLast;
501-
final int charEndOffset;
501+
final int endOffset;
502502

503503
const FieldInfo(this.identifier, this.initializerToken, this.beforeLast,
504-
this.charEndOffset);
504+
this.endOffset);
505505
}

pkg/front_end/lib/src/source/outline_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ class OutlineBuilder extends StackListenerImpl {
16551655
metadata: null,
16561656
type: formal.type,
16571657
name: formal.name,
1658-
charOffset: formal.fileOffset);
1658+
nameOffset: formal.fileOffset);
16591659
formals[i] = formal.forPrimaryConstructor(_builderFactory);
16601660
}
16611661
if (inExtensionType) {

pkg/front_end/lib/src/source/source_builder_factory.dart

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult {
13081308
String name,
13091309
List<NominalParameterBuilder>? typeParameters,
13101310
TypeBuilder type,
1311-
int charOffset) {
1311+
int nameOffset) {
13121312
if (typeParameters != null) {
13131313
for (NominalParameterBuilder typeParameter in typeParameters) {
13141314
typeParameter.varianceCalculationValue =
@@ -1326,7 +1326,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult {
13261326
typeParameters: typeParameters,
13271327
type: type,
13281328
fileUri: _compilationUnit.fileUri,
1329-
fileOffset: charOffset);
1329+
nameOffset: nameOffset);
13301330
_addFragment(fragment);
13311331
}
13321332

@@ -1687,17 +1687,17 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult {
16871687
{required List<MetadataBuilder>? metadata,
16881688
required TypeBuilder type,
16891689
required String name,
1690-
required int charOffset}) {
1690+
required int nameOffset}) {
16911691
_declarationFragments.current.addPrimaryConstructorField(_addField(
1692-
metadata,
1693-
Modifiers.Final,
1694-
/* isTopLevel = */ false,
1695-
type,
1696-
name,
1697-
/* charOffset = */ charOffset,
1698-
/* charEndOffset = */ charOffset,
1699-
/* initializerToken = */ null,
1700-
/* hasInitializer = */ false));
1692+
metadata: metadata,
1693+
modifiers: Modifiers.Final,
1694+
isTopLevel: false,
1695+
type: type,
1696+
name: name,
1697+
nameOffset: nameOffset,
1698+
endOffset: nameOffset,
1699+
initializerToken: null,
1700+
hasInitializer: false));
17011701
}
17021702

17031703
@override
@@ -2122,39 +2122,39 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult {
21222122
offsetMap.registerField(
21232123
info.identifier,
21242124
_addField(
2125-
metadata,
2126-
modifiers,
2127-
isTopLevel,
2128-
type ?? addInferableType(),
2129-
info.identifier.name,
2130-
info.identifier.nameOffset,
2131-
info.charEndOffset,
2132-
startToken,
2133-
hasInitializer,
2125+
metadata: metadata,
2126+
modifiers: modifiers,
2127+
isTopLevel: isTopLevel,
2128+
type: type ?? addInferableType(),
2129+
name: info.identifier.name,
2130+
nameOffset: info.identifier.nameOffset,
2131+
endOffset: info.endOffset,
2132+
initializerToken: startToken,
2133+
hasInitializer: hasInitializer,
21342134
constInitializerToken:
21352135
potentiallyNeedInitializerInOutline ? startToken : null));
21362136
}
21372137
}
21382138

21392139
FieldFragment _addField(
2140-
List<MetadataBuilder>? metadata,
2141-
Modifiers modifiers,
2142-
bool isTopLevel,
2143-
TypeBuilder type,
2144-
String name,
2145-
int charOffset,
2146-
int charEndOffset,
2147-
Token? initializerToken,
2148-
bool hasInitializer,
2149-
{Token? constInitializerToken}) {
2140+
{required List<MetadataBuilder>? metadata,
2141+
required Modifiers modifiers,
2142+
required bool isTopLevel,
2143+
required TypeBuilder type,
2144+
required String name,
2145+
required int nameOffset,
2146+
required int endOffset,
2147+
required Token? initializerToken,
2148+
required bool hasInitializer,
2149+
Token? constInitializerToken}) {
21502150
if (hasInitializer) {
21512151
modifiers |= Modifiers.HasInitializer;
21522152
}
21532153
FieldFragment fragment = new FieldFragment(
21542154
name: name,
21552155
fileUri: _compilationUnit.fileUri,
2156-
charOffset: charOffset,
2157-
charEndOffset: charEndOffset,
2156+
nameOffset: nameOffset,
2157+
endOffset: endOffset,
21582158
initializerToken: initializerToken,
21592159
constInitializerToken: constInitializerToken,
21602160
metadata: metadata,

pkg/front_end/lib/src/source/source_enum_builder.dart

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,18 @@ class SourceEnumBuilder extends SourceClassBuilder {
315315
}
316316

317317
SourceFieldBuilder valuesBuilder = new SourceFieldBuilder(
318-
/* metadata = */ null,
319-
listType,
320-
"values",
321-
Modifiers.Const | Modifiers.Static | Modifiers.HasInitializer,
322-
/* isTopLevel = */ false,
323-
libraryBuilder,
324-
this,
325-
fileUri,
326-
fileOffset,
327-
fileOffset,
328-
staticFieldNameScheme,
318+
metadata: null,
319+
type: listType,
320+
name: "values",
321+
modifiers:
322+
Modifiers.Const | Modifiers.Static | Modifiers.HasInitializer,
323+
isTopLevel: false,
324+
libraryBuilder: libraryBuilder,
325+
declarationBuilder: this,
326+
fileUri: fileUri,
327+
nameOffset: fileOffset,
328+
endOffset: fileOffset,
329+
nameScheme: staticFieldNameScheme,
329330
fieldReference: valuesFieldReference,
330331
fieldGetterReference: valuesGetterReference,
331332
fieldSetterReference: valuesSetterReference,
@@ -436,11 +437,11 @@ class SourceEnumBuilder extends SourceClassBuilder {
436437
// Report the error on the member that occurs later in the code.
437438
int existingOffset;
438439
int duplicateOffset;
439-
if (existing.fileOffset < enumConstantInfo.charOffset) {
440+
if (existing.fileOffset < enumConstantInfo.nameOffset) {
440441
existingOffset = existing.fileOffset;
441-
duplicateOffset = enumConstantInfo.charOffset;
442+
duplicateOffset = enumConstantInfo.nameOffset;
442443
} else {
443-
existingOffset = enumConstantInfo.charOffset;
444+
existingOffset = enumConstantInfo.nameOffset;
444445
duplicateOffset = existing.fileOffset;
445446
}
446447

@@ -467,7 +468,7 @@ class SourceEnumBuilder extends SourceClassBuilder {
467468
} else if (name == className) {
468469
libraryBuilder.addProblem(
469470
templateEnumConstantSameNameAsEnclosing.withArguments(name),
470-
enumConstantInfo.charOffset,
471+
enumConstantInfo.nameOffset,
471472
name.length,
472473
libraryBuilder.fileUri);
473474
}
@@ -481,17 +482,18 @@ class SourceEnumBuilder extends SourceClassBuilder {
481482
setterReference = indexedClass!.lookupSetterReference(nameName);
482483
}
483484
SourceFieldBuilder fieldBuilder = new SourceFieldBuilder(
484-
metadata,
485-
libraryBuilder.loader.inferableTypes.addInferableType(),
486-
name,
487-
Modifiers.Const | Modifiers.Static | Modifiers.HasInitializer,
488-
/* isTopLevel = */ false,
489-
libraryBuilder,
490-
this,
491-
fileUri,
492-
enumConstantInfo.charOffset,
493-
enumConstantInfo.charOffset,
494-
staticFieldNameScheme,
485+
metadata: metadata,
486+
type: libraryBuilder.loader.inferableTypes.addInferableType(),
487+
name: name,
488+
modifiers:
489+
Modifiers.Const | Modifiers.Static | Modifiers.HasInitializer,
490+
isTopLevel: false,
491+
libraryBuilder: libraryBuilder,
492+
declarationBuilder: this,
493+
fileUri: fileUri,
494+
nameOffset: enumConstantInfo.nameOffset,
495+
endOffset: enumConstantInfo.nameOffset,
496+
nameScheme: staticFieldNameScheme,
495497
fieldReference: fieldReference,
496498
fieldGetterReference: getterReference,
497499
fieldSetterReference: setterReference,
@@ -608,7 +610,7 @@ class SourceEnumBuilder extends SourceClassBuilder {
608610
String fullConstructorNameForErrors =
609611
enumConstantInfo.constructorReferenceBuilder?.fullNameForErrors ?? name;
610612
int fileOffset = enumConstantInfo.constructorReferenceBuilder?.charOffset ??
611-
enumConstantInfo.charOffset;
613+
enumConstantInfo.nameOffset;
612614
constructorName = constructorName == "new" ? "" : constructorName;
613615
MemberBuilder? constructorBuilder =
614616
nameSpace.lookupConstructor(constructorName);
@@ -794,9 +796,9 @@ class SourceEnumBuilder extends SourceClassBuilder {
794796
class EnumConstantInfo {
795797
final List<MetadataBuilder>? metadata;
796798
final String name;
797-
final int charOffset;
799+
final int nameOffset;
798800
ConstructorReferenceBuilder? constructorReferenceBuilder;
799801
Token? argumentsBeginToken;
800802

801-
EnumConstantInfo(this.metadata, this.name, this.charOffset);
803+
EnumConstantInfo(this.metadata, this.name, this.nameOffset);
802804
}

0 commit comments

Comments
 (0)