Skip to content

Commit

Permalink
[cfe] Rename offsets
Browse files Browse the repository at this point in the history
This renames the fragment/builder offsets. Offsets for the first token
are called `startOffset`, for the last token `endOffset`, for the
first parenthesis of formals  `formalsOffset` and for the name
`nameOffset`. The default builder offset is renamed to `fileOffset`.

Change-Id: I658bf8819ac0de2f56497cd99f72b502a2253525
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390740
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
  • Loading branch information
johnniwinther authored and Commit Queue committed Oct 18, 2024
1 parent 1a6ae2e commit 574a6b3
Show file tree
Hide file tree
Showing 71 changed files with 1,451 additions and 1,468 deletions.
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/base/identifiers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class QualifiedNameBuilder extends QualifiedName {

@override
// Coverage-ignore(suite): Not run.
int get firstOffset => qualifier.charOffset;
int get firstOffset => qualifier.fileOffset;

@override
String toString() => "qualified-name-builder($qualifier, $name)";
Expand Down
20 changes: 10 additions & 10 deletions pkg/front_end/lib/src/base/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,12 @@ abstract class ProblemBuilder extends BuilderImpl {
final Builder builder;

@override
final int charOffset;
final int fileOffset;

@override
final Uri fileUri;

ProblemBuilder(this.name, this.builder, this.charOffset, this.fileUri);
ProblemBuilder(this.name, this.builder, this.fileOffset, this.fileUri);

@override
bool get hasProblem => true;
Expand Down Expand Up @@ -1143,10 +1143,10 @@ abstract class MergedScope<T extends Builder> {
context = messageNonAugmentationMemberConflictCause;
}
originLibrary.addProblem(
message, newBuilder.charOffset, name.length, newBuilder.fileUri,
message, newBuilder.fileOffset, name.length, newBuilder.fileUri,
context: [
context.withLocation(existingBuilder.fileUri!,
existingBuilder.charOffset, name.length)
existingBuilder.fileOffset, name.length)
]);
}
} else {
Expand Down Expand Up @@ -1175,15 +1175,15 @@ abstract class MergedScope<T extends Builder> {
templateUnmatchedAugmentationDeclaration.withArguments(name);
}
originLibrary.addProblem(
message, newBuilder.charOffset, name.length, newBuilder.fileUri);
message, newBuilder.fileOffset, name.length, newBuilder.fileUri);
} else {
if (inPatchLibrary &&
!name.startsWith('_') &&
!_allowInjectedPublicMember(newBuilder)) {
originLibrary.addProblem(
templatePatchInjectionFailed.withArguments(
name, originLibrary.importUri),
newBuilder.charOffset,
newBuilder.fileOffset,
noLength,
newBuilder.fileUri);
}
Expand Down Expand Up @@ -1345,13 +1345,13 @@ class MergedClassMemberScope extends MergedScope<SourceClassBuilder> {
// Coverage-ignore(suite): Not run.
templateNonAugmentationConstructorConflict
.withArguments(newConstructor.fullNameForErrors),
newConstructor.charOffset,
newConstructor.fileOffset,
noLength,
newConstructor.fileUri,
context: [
messageNonAugmentationConstructorConflictCause.withLocation(
existingConstructor.fileUri!,
existingConstructor.charOffset,
existingConstructor.fileOffset,
noLength)
]);
}
Expand All @@ -1365,7 +1365,7 @@ class MergedClassMemberScope extends MergedScope<SourceClassBuilder> {
// Coverage-ignore(suite): Not run.
templateUnmatchedAugmentationConstructor
.withArguments(newConstructor.fullNameForErrors),
newConstructor.charOffset,
newConstructor.fileOffset,
noLength,
newConstructor.fileUri);
} else {
Expand All @@ -1384,7 +1384,7 @@ class MergedClassMemberScope extends MergedScope<SourceClassBuilder> {
originLibrary.addProblem(
templatePatchInjectionFailed.withArguments(
name, originLibrary.importUri),
newConstructor.charOffset,
newConstructor.fileOffset,
noLength,
newConstructor.fileUri);
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/front_end/lib/src/builder/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class Builder {

Uri? get fileUri;

int get charOffset;
int get fileOffset;

Builder get origin;

Expand Down Expand Up @@ -367,7 +367,7 @@ abstract class BuilderImpl implements Builder {
@override
// Coverage-ignore(suite): Not run.
void applyAugmentation(Builder augmentation) {
unsupported("${runtimeType}.applyAugmentation", charOffset, fileUri);
unsupported("${runtimeType}.applyAugmentation", fileOffset, fileUri);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class BuiltinTypeDeclarationBuilder extends TypeDeclarationBuilderImpl
final LibraryBuilder parent;

@override
final int charOffset;
final int fileOffset;

@override
final String name;
Expand All @@ -21,7 +21,7 @@ abstract class BuiltinTypeDeclarationBuilder extends TypeDeclarationBuilderImpl
final Uri fileUri;

BuiltinTypeDeclarationBuilder(
this.name, this.type, this.parent, this.charOffset)
this.name, this.type, this.parent, this.fileOffset)
: fileUri = parent.fileUri;

@override
Expand Down
12 changes: 6 additions & 6 deletions pkg/front_end/lib/src/builder/formal_parameter_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class FormalParameterBuilder extends BuilderImpl
SourceFunctionBuilder? _parent;

@override
final int charOffset;
final int fileOffset;

final Modifiers modifiers;

Expand Down Expand Up @@ -98,7 +98,7 @@ class FormalParameterBuilder extends BuilderImpl
final bool isWildcard;

FormalParameterBuilder(
this.kind, this.modifiers, this.type, this.name, this.charOffset,
this.kind, this.modifiers, this.type, this.name, this.fileOffset,
{required this.fileUri,
this.isExtensionThis = false,
required this.hasImmediatelyDeclaredInitializer,
Expand Down Expand Up @@ -182,7 +182,7 @@ class FormalParameterBuilder extends BuilderImpl
isLowered: isExtensionThis,
isSynthesized: name == noNameSentinel,
isWildcard: isWildcard)
..fileOffset = charOffset;
..fileOffset = fileOffset;
}
return variable!;
}
Expand All @@ -200,7 +200,7 @@ class FormalParameterBuilder extends BuilderImpl
modifiers | Modifiers.InitializingFormal,
builderFactory.addInferableType(),
name,
charOffset,
fileOffset,
fileUri: fileUri,
isExtensionThis: isExtensionThis,
hasImmediatelyDeclaredInitializer: hasImmediatelyDeclaredInitializer)
Expand All @@ -215,7 +215,7 @@ class FormalParameterBuilder extends BuilderImpl
modifiers | Modifiers.Final | Modifiers.InitializingFormal,
type,
name,
charOffset,
fileOffset,
fileUri: fileUri,
isExtensionThis: isExtensionThis,
hasImmediatelyDeclaredInitializer: hasImmediatelyDeclaredInitializer)
Expand All @@ -227,7 +227,7 @@ class FormalParameterBuilder extends BuilderImpl
modifiers | Modifiers.Final | Modifiers.SuperInitializingFormal,
type,
name,
charOffset,
fileOffset,
fileUri: fileUri,
isExtensionThis: isExtensionThis,
hasImmediatelyDeclaredInitializer: hasImmediatelyDeclaredInitializer)
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/builder/function_type_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ abstract class FunctionTypeBuilderImpl extends FunctionTypeBuilder {
newTypeVariables ??= typeVariables.toList();
StructuralVariableBuilder newTypeVariableBuilder =
newTypeVariables[i] = new StructuralVariableBuilder(
variable.name, variable.charOffset, variable.fileUri,
variable.name, variable.fileOffset, variable.fileUri,
bound: bound);
unboundTypeVariables.add(newTypeVariableBuilder);
if (functionTypeUpperSubstitution == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class InvalidTypeDeclarationBuilder extends TypeDeclarationBuilderImpl

@override
// Coverage-ignore(suite): Not run.
int get charOffset => message.charOffset;
int get fileOffset => message.charOffset;

@override
// Coverage-ignore(suite): Not run.
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/builder/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ abstract class LibraryBuilderImpl extends BuilderImpl
Builder? get parent => null;

@override
int get charOffset => -1;
int get fileOffset => -1;

@override
bool get isPart => false;
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/builder/member_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ abstract class BuilderClassMember implements ClassMember {
MemberBuilderImpl get memberBuilder;

@override
int get charOffset => memberBuilder.charOffset;
int get charOffset => memberBuilder.fileOffset;

@override
DeclarationBuilder get declarationBuilder =>
Expand Down
20 changes: 10 additions & 10 deletions pkg/front_end/lib/src/builder/metadata_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import '../source/source_library_builder.dart' show SourceLibraryBuilder;

class MetadataBuilder {
/// Token for `@` for annotations that have not yet been parsed.
Token? _beginToken;
Token? _atToken;

final int charOffset;
final int atOffset;

/// `true` if the annotation begins with 'patch'.
///
Expand All @@ -28,12 +28,12 @@ class MetadataBuilder {
/// Expression for an already parsed annotation.
Expression? _expression;

MetadataBuilder(Token this._beginToken)
: charOffset = _beginToken.charOffset,
hasPatch = _beginToken.next?.lexeme == 'patch';
MetadataBuilder(Token this._atToken)
: atOffset = _atToken.charOffset,
hasPatch = _atToken.next?.lexeme == 'patch';

// Coverage-ignore(suite): Not run.
Token? get beginToken => _beginToken;
Token? get beginToken => _atToken;

static void buildAnnotations(
Annotatable parent,
Expand All @@ -59,15 +59,15 @@ class MetadataBuilder {

for (int i = 0; i < metadata.length; ++i) {
MetadataBuilder annotationBuilder = metadata[i];
Token? beginToken = annotationBuilder._beginToken;
Token? beginToken = annotationBuilder._atToken;
if (beginToken != null) {
bodyBuilder ??= library.loader.createBodyBuilderForOutlineExpression(
library, bodyBuilderContext, scope, fileUri);
Expression annotation = bodyBuilder.parseAnnotation(beginToken);
annotationBuilder._beginToken = null;
annotationBuilder._atToken = null;
if (createFileUriExpression) {
annotation = new FileUriExpression(annotation, fileUri)
..fileOffset = annotationBuilder.charOffset;
..fileOffset = annotationBuilder.atOffset;
}
// Record the index of [annotation] in `parent.annotations`.
parsedAnnotationBuilders[annotationBuilder] = parent.annotations.length;
Expand Down Expand Up @@ -98,7 +98,7 @@ class MetadataBuilder {
// Coverage-ignore(suite): Not run.
if (createFileUriExpression && annotation is! FileUriExpression) {
annotation = new FileUriExpression(annotation, fileUri)
..fileOffset = annotationBuilder.charOffset;
..fileOffset = annotationBuilder.atOffset;
}
parent.addAnnotation(annotation);
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/front_end/lib/src/builder/named_type_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ abstract class NamedTypeBuilderImpl extends NamedTypeBuilder {
template = templateNotAType;
context = <LocatedMessage>[
messageNotATypeContext.withLocation(
member.fileUri!, member.charOffset, nameLength)
member.fileUri!, member.fileOffset, nameLength)
];
message = template.withArguments(nameText);
}
Expand Down Expand Up @@ -391,7 +391,7 @@ abstract class NamedTypeBuilderImpl extends NamedTypeBuilder {
}
library.addProblem(message, charOffset!, noLength, fileUri, context: [
messageTypedefCause.withLocation(
aliasBuilder.fileUri, aliasBuilder.charOffset, noLength),
aliasBuilder.fileUri, aliasBuilder.fileOffset, noLength),
]);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OmittedTypeDeclarationBuilder extends TypeDeclarationBuilderImpl
this.name, this.omittedTypeBuilder, this.parent);

@override
int get charOffset => TreeNode.noOffset;
int get fileOffset => TreeNode.noOffset;

@override
DartType buildAliasedType(
Expand Down
4 changes: 2 additions & 2 deletions pkg/front_end/lib/src/builder/prefix_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PrefixBuilder extends BuilderImpl {
final Uri fileUri;

@override
final int charOffset;
final int fileOffset;

final LoadLibraryBuilder? loadLibraryBuilder;

Expand All @@ -45,7 +45,7 @@ class PrefixBuilder extends BuilderImpl {
{required this.fileUri,
required int prefixOffset,
required int importOffset})
: charOffset = prefixOffset,
: fileOffset = prefixOffset,
isWildcard = name == '_' {
assert(deferred == (loadLibraryBuilder != null),
"LoadLibraryBuilder must be provided iff prefix is deferred.");
Expand Down
12 changes: 6 additions & 6 deletions pkg/front_end/lib/src/builder/type_alias_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ abstract class TypeAliasBuilderImpl extends TypeDeclarationBuilderImpl
// Coverage-ignore(suite): Not run.
case ExtensionBuilder():
unexpected(
"type", "${rhsTypeDeclaration.runtimeType}", charOffset, fileUri);
"type", "${rhsTypeDeclaration.runtimeType}", fileOffset, fileUri);
}
}

Expand All @@ -259,7 +259,7 @@ abstract class TypeAliasBuilderImpl extends TypeDeclarationBuilderImpl
// alias, which is ensured by the call to [_ensureUnaliasedType]
// earlier.
return unexpected(
"unaliased", "${rhsDeclaration.runtimeType}", charOffset, fileUri);
"unaliased", "${rhsDeclaration.runtimeType}", fileOffset, fileUri);
case ClassBuilder():
case ExtensionTypeDeclarationBuilder():
case NominalVariableBuilder():
Expand Down Expand Up @@ -343,7 +343,7 @@ abstract class TypeAliasBuilderImpl extends TypeDeclarationBuilderImpl
// Cyclic type alias.
currentAliasBuilder.libraryBuilder.addProblem(
templateCyclicTypedef.withArguments(this.name),
charOffset,
fileOffset,
noLength,
fileUri);
// Ensure that it is not reported again.
Expand All @@ -367,7 +367,7 @@ abstract class TypeAliasBuilderImpl extends TypeDeclarationBuilderImpl
typeVariable, const NullabilityBuilder.omitted(),
arguments: const [],
fileUri: fileUri,
charOffset: charOffset,
charOffset: fileOffset,
instanceTypeVariableAccess:
InstanceTypeVariableAccessState.Unexpected),
];
Expand All @@ -388,7 +388,7 @@ abstract class TypeAliasBuilderImpl extends TypeDeclarationBuilderImpl
usedAsClassFileUri,
context: [
messageTypedefTypeVariableNotConstructorCause.withLocation(
current.fileUri!, current.charOffset, noLength),
current.fileUri!, current.fileOffset, noLength),
]);
return this;
}
Expand Down Expand Up @@ -447,7 +447,7 @@ abstract class TypeAliasBuilderImpl extends TypeDeclarationBuilderImpl
previousAliasBuilder.libraryBuilder.addProblem(
templateTypeArgumentMismatch.withArguments(
currentAliasBuilder.typeVariables?.length ?? 0),
previousAliasBuilder.charOffset,
previousAliasBuilder.fileOffset,
noLength,
previousAliasBuilder.fileUri);
previousAliasBuilder.thisType = const InvalidType();
Expand Down
Loading

0 comments on commit 574a6b3

Please sign in to comment.