From 574a6b3b72e0560e783a5efb3823d39a07d2f4ff Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Fri, 18 Oct 2024 07:06:23 +0000 Subject: [PATCH] [cfe] Rename offsets 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 Commit-Queue: Johnni Winther --- pkg/front_end/lib/src/base/identifiers.dart | 2 +- pkg/front_end/lib/src/base/scope.dart | 20 +- pkg/front_end/lib/src/builder/builder.dart | 4 +- .../builtin_type_declaration_builder.dart | 4 +- .../src/builder/formal_parameter_builder.dart | 12 +- .../src/builder/function_type_builder.dart | 2 +- .../invalid_type_declaration_builder.dart | 2 +- .../lib/src/builder/library_builder.dart | 2 +- .../lib/src/builder/member_builder.dart | 2 +- .../lib/src/builder/metadata_builder.dart | 20 +- .../lib/src/builder/named_type_builder.dart | 4 +- .../omitted_type_declaration_builder.dart | 2 +- .../lib/src/builder/prefix_builder.dart | 4 +- .../lib/src/builder/type_alias_builder.dart | 12 +- .../src/builder/type_variable_builder.dart | 8 +- .../lib/src/dill/dill_class_builder.dart | 2 +- .../lib/src/dill/dill_extension_builder.dart | 2 +- ...ll_extension_type_declaration_builder.dart | 2 +- .../lib/src/dill/dill_member_builder.dart | 2 +- .../lib/src/dill/dill_type_alias_builder.dart | 2 +- pkg/front_end/lib/src/fragment/class.dart | 1 - .../lib/src/fragment/constructor.dart | 18 +- pkg/front_end/lib/src/fragment/enum.dart | 5 +- pkg/front_end/lib/src/fragment/extension.dart | 2 +- pkg/front_end/lib/src/fragment/factory.dart | 18 +- pkg/front_end/lib/src/fragment/getter.dart | 18 +- pkg/front_end/lib/src/fragment/method.dart | 18 +- pkg/front_end/lib/src/fragment/mixin.dart | 1 - .../src/fragment/named_mixin_application.dart | 14 +- .../lib/src/fragment/primary_constructor.dart | 12 +- pkg/front_end/lib/src/fragment/setter.dart | 18 +- .../lib/src/kernel/body_builder.dart | 56 +- .../lib/src/kernel/body_builder_context.dart | 2 +- .../src/kernel/combined_member_signature.dart | 2 +- .../lib/src/kernel/expression_generator.dart | 2 +- .../src/kernel/hierarchy/class_member.dart | 4 +- .../lib/src/kernel/hierarchy/delayed.dart | 2 +- .../hierarchy/extension_type_members.dart | 4 +- .../src/kernel/hierarchy/hierarchy_node.dart | 4 +- .../src/kernel/hierarchy/members_node.dart | 12 +- .../src/kernel/hierarchy/mixin_inferrer.dart | 4 +- .../lib/src/kernel/implicit_field_type.dart | 4 +- .../lib/src/kernel/kernel_target.dart | 20 +- .../src/kernel/kernel_variable_builder.dart | 2 +- .../lib/src/kernel/load_library_builder.dart | 10 +- .../lib/src/kernel/macro/introspectors.dart | 18 +- .../lib/src/kernel/type_algorithms.dart | 8 +- .../lib/src/source/builder_factory.dart | 287 ++++---- .../lib/src/source/class_declaration.dart | 2 +- pkg/front_end/lib/src/source/offset_map.dart | 2 +- .../lib/src/source/outline_builder.dart | 337 ++++----- .../src/source/source_builder_factory.dart | 637 +++++++++--------- .../lib/src/source/source_builder_mixins.dart | 18 +- .../lib/src/source/source_class_builder.dart | 113 ++-- .../src/source/source_compilation_unit.dart | 12 +- .../source/source_constructor_builder.dart | 46 +- .../lib/src/source/source_enum_builder.dart | 231 ++++--- .../src/source/source_extension_builder.dart | 10 +- ...ce_extension_type_declaration_builder.dart | 30 +- .../src/source/source_factory_builder.dart | 140 ++-- .../lib/src/source/source_field_builder.dart | 28 +- .../src/source/source_function_builder.dart | 16 +- .../src/source/source_library_builder.dart | 34 +- .../lib/src/source/source_loader.dart | 106 +-- .../lib/src/source/source_member_builder.dart | 2 +- .../src/source/source_procedure_builder.dart | 58 +- .../src/source/source_type_alias_builder.dart | 16 +- .../source/type_parameter_scope_builder.dart | 383 +++++------ .../inference_visitor_base.dart | 6 +- .../test/coverage_suite_expected.dart | 14 +- .../application/macro_application_test.dart | 2 +- 71 files changed, 1451 insertions(+), 1468 deletions(-) diff --git a/pkg/front_end/lib/src/base/identifiers.dart b/pkg/front_end/lib/src/base/identifiers.dart index 177cc9398af0..17f769bff248 100644 --- a/pkg/front_end/lib/src/base/identifiers.dart +++ b/pkg/front_end/lib/src/base/identifiers.dart @@ -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)"; diff --git a/pkg/front_end/lib/src/base/scope.dart b/pkg/front_end/lib/src/base/scope.dart index b1cb906010ad..341f2329babb 100644 --- a/pkg/front_end/lib/src/base/scope.dart +++ b/pkg/front_end/lib/src/base/scope.dart @@ -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; @@ -1143,10 +1143,10 @@ abstract class MergedScope { 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 { @@ -1175,7 +1175,7 @@ abstract class MergedScope { templateUnmatchedAugmentationDeclaration.withArguments(name); } originLibrary.addProblem( - message, newBuilder.charOffset, name.length, newBuilder.fileUri); + message, newBuilder.fileOffset, name.length, newBuilder.fileUri); } else { if (inPatchLibrary && !name.startsWith('_') && @@ -1183,7 +1183,7 @@ abstract class MergedScope { originLibrary.addProblem( templatePatchInjectionFailed.withArguments( name, originLibrary.importUri), - newBuilder.charOffset, + newBuilder.fileOffset, noLength, newBuilder.fileUri); } @@ -1345,13 +1345,13 @@ class MergedClassMemberScope extends MergedScope { // 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) ]); } @@ -1365,7 +1365,7 @@ class MergedClassMemberScope extends MergedScope { // Coverage-ignore(suite): Not run. templateUnmatchedAugmentationConstructor .withArguments(newConstructor.fullNameForErrors), - newConstructor.charOffset, + newConstructor.fileOffset, noLength, newConstructor.fileUri); } else { @@ -1384,7 +1384,7 @@ class MergedClassMemberScope extends MergedScope { originLibrary.addProblem( templatePatchInjectionFailed.withArguments( name, originLibrary.importUri), - newConstructor.charOffset, + newConstructor.fileOffset, noLength, newConstructor.fileUri); } diff --git a/pkg/front_end/lib/src/builder/builder.dart b/pkg/front_end/lib/src/builder/builder.dart index ea554d03a4cd..e23cc2ea8226 100644 --- a/pkg/front_end/lib/src/builder/builder.dart +++ b/pkg/front_end/lib/src/builder/builder.dart @@ -16,7 +16,7 @@ abstract class Builder { Uri? get fileUri; - int get charOffset; + int get fileOffset; Builder get origin; @@ -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 diff --git a/pkg/front_end/lib/src/builder/builtin_type_declaration_builder.dart b/pkg/front_end/lib/src/builder/builtin_type_declaration_builder.dart index 9b156d8f5f2b..2feaeaed498d 100644 --- a/pkg/front_end/lib/src/builder/builtin_type_declaration_builder.dart +++ b/pkg/front_end/lib/src/builder/builtin_type_declaration_builder.dart @@ -10,7 +10,7 @@ abstract class BuiltinTypeDeclarationBuilder extends TypeDeclarationBuilderImpl final LibraryBuilder parent; @override - final int charOffset; + final int fileOffset; @override final String name; @@ -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 diff --git a/pkg/front_end/lib/src/builder/formal_parameter_builder.dart b/pkg/front_end/lib/src/builder/formal_parameter_builder.dart index d028f4c85281..a49647badbc7 100644 --- a/pkg/front_end/lib/src/builder/formal_parameter_builder.dart +++ b/pkg/front_end/lib/src/builder/formal_parameter_builder.dart @@ -57,7 +57,7 @@ class FormalParameterBuilder extends BuilderImpl SourceFunctionBuilder? _parent; @override - final int charOffset; + final int fileOffset; final Modifiers modifiers; @@ -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, @@ -182,7 +182,7 @@ class FormalParameterBuilder extends BuilderImpl isLowered: isExtensionThis, isSynthesized: name == noNameSentinel, isWildcard: isWildcard) - ..fileOffset = charOffset; + ..fileOffset = fileOffset; } return variable!; } @@ -200,7 +200,7 @@ class FormalParameterBuilder extends BuilderImpl modifiers | Modifiers.InitializingFormal, builderFactory.addInferableType(), name, - charOffset, + fileOffset, fileUri: fileUri, isExtensionThis: isExtensionThis, hasImmediatelyDeclaredInitializer: hasImmediatelyDeclaredInitializer) @@ -215,7 +215,7 @@ class FormalParameterBuilder extends BuilderImpl modifiers | Modifiers.Final | Modifiers.InitializingFormal, type, name, - charOffset, + fileOffset, fileUri: fileUri, isExtensionThis: isExtensionThis, hasImmediatelyDeclaredInitializer: hasImmediatelyDeclaredInitializer) @@ -227,7 +227,7 @@ class FormalParameterBuilder extends BuilderImpl modifiers | Modifiers.Final | Modifiers.SuperInitializingFormal, type, name, - charOffset, + fileOffset, fileUri: fileUri, isExtensionThis: isExtensionThis, hasImmediatelyDeclaredInitializer: hasImmediatelyDeclaredInitializer) diff --git a/pkg/front_end/lib/src/builder/function_type_builder.dart b/pkg/front_end/lib/src/builder/function_type_builder.dart index 7adf6ece175a..6c4bda06faec 100644 --- a/pkg/front_end/lib/src/builder/function_type_builder.dart +++ b/pkg/front_end/lib/src/builder/function_type_builder.dart @@ -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) { diff --git a/pkg/front_end/lib/src/builder/invalid_type_declaration_builder.dart b/pkg/front_end/lib/src/builder/invalid_type_declaration_builder.dart index a072c8967ef3..484019321bf7 100644 --- a/pkg/front_end/lib/src/builder/invalid_type_declaration_builder.dart +++ b/pkg/front_end/lib/src/builder/invalid_type_declaration_builder.dart @@ -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. diff --git a/pkg/front_end/lib/src/builder/library_builder.dart b/pkg/front_end/lib/src/builder/library_builder.dart index 2b46cf5c57cc..617d452701dd 100644 --- a/pkg/front_end/lib/src/builder/library_builder.dart +++ b/pkg/front_end/lib/src/builder/library_builder.dart @@ -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; diff --git a/pkg/front_end/lib/src/builder/member_builder.dart b/pkg/front_end/lib/src/builder/member_builder.dart index 9b2c2a9ee509..ce4b388482d4 100644 --- a/pkg/front_end/lib/src/builder/member_builder.dart +++ b/pkg/front_end/lib/src/builder/member_builder.dart @@ -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 => diff --git a/pkg/front_end/lib/src/builder/metadata_builder.dart b/pkg/front_end/lib/src/builder/metadata_builder.dart index 315e768944a8..d4b5a1e04cef 100644 --- a/pkg/front_end/lib/src/builder/metadata_builder.dart +++ b/pkg/front_end/lib/src/builder/metadata_builder.dart @@ -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'. /// @@ -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, @@ -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; @@ -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); } diff --git a/pkg/front_end/lib/src/builder/named_type_builder.dart b/pkg/front_end/lib/src/builder/named_type_builder.dart index ec339bb70c85..0d899b781591 100644 --- a/pkg/front_end/lib/src/builder/named_type_builder.dart +++ b/pkg/front_end/lib/src/builder/named_type_builder.dart @@ -244,7 +244,7 @@ abstract class NamedTypeBuilderImpl extends NamedTypeBuilder { template = templateNotAType; context = [ messageNotATypeContext.withLocation( - member.fileUri!, member.charOffset, nameLength) + member.fileUri!, member.fileOffset, nameLength) ]; message = template.withArguments(nameText); } @@ -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; } diff --git a/pkg/front_end/lib/src/builder/omitted_type_declaration_builder.dart b/pkg/front_end/lib/src/builder/omitted_type_declaration_builder.dart index deecb4cf0159..b456e50fb8f9 100644 --- a/pkg/front_end/lib/src/builder/omitted_type_declaration_builder.dart +++ b/pkg/front_end/lib/src/builder/omitted_type_declaration_builder.dart @@ -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( diff --git a/pkg/front_end/lib/src/builder/prefix_builder.dart b/pkg/front_end/lib/src/builder/prefix_builder.dart index 010073e957df..931ea4ffa49b 100644 --- a/pkg/front_end/lib/src/builder/prefix_builder.dart +++ b/pkg/front_end/lib/src/builder/prefix_builder.dart @@ -35,7 +35,7 @@ class PrefixBuilder extends BuilderImpl { final Uri fileUri; @override - final int charOffset; + final int fileOffset; final LoadLibraryBuilder? loadLibraryBuilder; @@ -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."); diff --git a/pkg/front_end/lib/src/builder/type_alias_builder.dart b/pkg/front_end/lib/src/builder/type_alias_builder.dart index 2dd6705fffb1..b09794077bef 100644 --- a/pkg/front_end/lib/src/builder/type_alias_builder.dart +++ b/pkg/front_end/lib/src/builder/type_alias_builder.dart @@ -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); } } @@ -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(): @@ -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. @@ -367,7 +367,7 @@ abstract class TypeAliasBuilderImpl extends TypeDeclarationBuilderImpl typeVariable, const NullabilityBuilder.omitted(), arguments: const [], fileUri: fileUri, - charOffset: charOffset, + charOffset: fileOffset, instanceTypeVariableAccess: InstanceTypeVariableAccessState.Unexpected), ]; @@ -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; } @@ -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(); diff --git a/pkg/front_end/lib/src/builder/type_variable_builder.dart b/pkg/front_end/lib/src/builder/type_variable_builder.dart index 0621fe43b1cc..6efeccc4ac6c 100644 --- a/pkg/front_end/lib/src/builder/type_variable_builder.dart +++ b/pkg/front_end/lib/src/builder/type_variable_builder.dart @@ -25,7 +25,7 @@ enum TypeVariableKind { sealed class TypeVariableBuilder extends TypeDeclarationBuilderImpl implements TypeDeclarationBuilder { @override - final int charOffset; + final int fileOffset; @override final String name; @@ -45,7 +45,7 @@ sealed class TypeVariableBuilder extends TypeDeclarationBuilderImpl final List? metadata; - TypeVariableBuilder(this.name, this.charOffset, this.fileUri, + TypeVariableBuilder(this.name, this.fileOffset, this.fileUri, {this.bound, this.defaultType, required this.kind, @@ -406,7 +406,7 @@ class NominalVariableBuilder extends TypeVariableBuilder { TypeUse.typeParameterBound, fileUri ?? // Coverage-ignore(suite): Not run. missingUri, - charOffset, + fileOffset, /* hierarchy = */ null, hasExplicitTypeArguments: false); if (hasUnsetParameterBound) { @@ -723,7 +723,7 @@ class StructuralVariableBuilder extends TypeVariableBuilder { TypeUse.typeParameterBound, fileUri ?? // Coverage-ignore(suite): Not run. missingUri, - charOffset, + fileOffset, /* hierarchy = */ null, hasExplicitTypeArguments: false); if (identical(parameter.bound, StructuralParameter.unsetBoundSentinel)) { diff --git a/pkg/front_end/lib/src/dill/dill_class_builder.dart b/pkg/front_end/lib/src/dill/dill_class_builder.dart index b33e506af059..34fdca942252 100644 --- a/pkg/front_end/lib/src/dill/dill_class_builder.dart +++ b/pkg/front_end/lib/src/dill/dill_class_builder.dart @@ -76,7 +76,7 @@ class DillClassBuilder extends ClassBuilderImpl } @override - int get charOffset => cls.fileOffset; + int get fileOffset => cls.fileOffset; @override String get name => cls.name; diff --git a/pkg/front_end/lib/src/dill/dill_extension_builder.dart b/pkg/front_end/lib/src/dill/dill_extension_builder.dart index 87e0c4b3c2fe..76d81ee40d09 100644 --- a/pkg/front_end/lib/src/dill/dill_extension_builder.dart +++ b/pkg/front_end/lib/src/dill/dill_extension_builder.dart @@ -102,7 +102,7 @@ class DillExtensionBuilder extends ExtensionBuilderImpl Reference get reference => extension.reference; @override - int get charOffset => extension.fileOffset; + int get fileOffset => extension.fileOffset; @override String get name => extension.name; diff --git a/pkg/front_end/lib/src/dill/dill_extension_type_declaration_builder.dart b/pkg/front_end/lib/src/dill/dill_extension_type_declaration_builder.dart index d21a93f15dc3..62504bee79ba 100644 --- a/pkg/front_end/lib/src/dill/dill_extension_type_declaration_builder.dart +++ b/pkg/front_end/lib/src/dill/dill_extension_type_declaration_builder.dart @@ -151,7 +151,7 @@ class DillExtensionTypeDeclarationBuilder @override // Coverage-ignore(suite): Not run. - int get charOffset => _extensionTypeDeclaration.fileOffset; + int get fileOffset => _extensionTypeDeclaration.fileOffset; @override String get name => _extensionTypeDeclaration.name; diff --git a/pkg/front_end/lib/src/dill/dill_member_builder.dart b/pkg/front_end/lib/src/dill/dill_member_builder.dart index 07c999de4abd..67f760aca8bb 100644 --- a/pkg/front_end/lib/src/dill/dill_member_builder.dart +++ b/pkg/front_end/lib/src/dill/dill_member_builder.dart @@ -40,7 +40,7 @@ abstract class DillMemberBuilder extends MemberBuilderImpl { Member get member; @override - int get charOffset => member.fileOffset; + int get fileOffset => member.fileOffset; @override Uri get fileUri => member.fileUri; diff --git a/pkg/front_end/lib/src/dill/dill_type_alias_builder.dart b/pkg/front_end/lib/src/dill/dill_type_alias_builder.dart index 132c33a42ed5..80ca8ce66713 100644 --- a/pkg/front_end/lib/src/dill/dill_type_alias_builder.dart +++ b/pkg/front_end/lib/src/dill/dill_type_alias_builder.dart @@ -32,7 +32,7 @@ class DillTypeAliasBuilder extends TypeAliasBuilderImpl { DillTypeAliasBuilder(this.typedef, this.tearOffs, this.parent); @override - int get charOffset => typedef.fileOffset; + int get fileOffset => typedef.fileOffset; @override String get name => typedef.name; diff --git a/pkg/front_end/lib/src/fragment/class.dart b/pkg/front_end/lib/src/fragment/class.dart index 85434651f16e..afb10b29ba47 100644 --- a/pkg/front_end/lib/src/fragment/class.dart +++ b/pkg/front_end/lib/src/fragment/class.dart @@ -20,7 +20,6 @@ class ClassFragment extends DeclarationFragment implements Fragment { late final List? interfaces; late final List constructorReferences; late final int startOffset; - late final int charOffset; late final int endOffset; ClassFragment(this.name, super.fileUri, this.nameOffset, super.typeParameters, diff --git a/pkg/front_end/lib/src/fragment/constructor.dart b/pkg/front_end/lib/src/fragment/constructor.dart index 7224899138e3..6efaaf2f528c 100644 --- a/pkg/front_end/lib/src/fragment/constructor.dart +++ b/pkg/front_end/lib/src/fragment/constructor.dart @@ -7,10 +7,10 @@ part of 'fragment.dart'; class ConstructorFragment implements Fragment, FunctionFragment { final String name; final Uri fileUri; - final int startCharOffset; - final int charOffset; - final int charOpenParenOffset; - final int charEndOffset; + final int startOffset; + final int nameOffset; + final int formalsOffset; + final int endOffset; final Modifiers modifiers; final List? metadata; final OmittedTypeBuilder returnType; @@ -25,10 +25,10 @@ class ConstructorFragment implements Fragment, FunctionFragment { ConstructorFragment( {required this.name, required this.fileUri, - required this.startCharOffset, - required this.charOffset, - required this.charOpenParenOffset, - required this.charEndOffset, + required this.startOffset, + required this.nameOffset, + required this.formalsOffset, + required this.endOffset, required this.modifiers, required this.metadata, required this.returnType, @@ -63,7 +63,7 @@ class ConstructorFragment implements Fragment, FunctionFragment { } @override - String toString() => '$runtimeType($name,$fileUri,$charOffset)'; + String toString() => '$runtimeType($name,$fileUri,$nameOffset)'; } class _ConstructorBodyBuildingContext implements FunctionBodyBuildingContext { diff --git a/pkg/front_end/lib/src/fragment/enum.dart b/pkg/front_end/lib/src/fragment/enum.dart index 315054ba4b0f..9cd63cfc0b36 100644 --- a/pkg/front_end/lib/src/fragment/enum.dart +++ b/pkg/front_end/lib/src/fragment/enum.dart @@ -18,9 +18,8 @@ class EnumFragment extends DeclarationFragment implements Fragment { late final List? interfaces; late final List? enumConstantInfos; late final List constructorReferences; - late final int startCharOffset; - late final int charOffset; - late final int charEndOffset; + late final int startOffset; + late final int endOffset; EnumFragment(this.name, super.fileUri, this.nameOffset, super.typeParameters, super.typeParameterScope, super._nominalParameterNameSpace); diff --git a/pkg/front_end/lib/src/fragment/extension.dart b/pkg/front_end/lib/src/fragment/extension.dart index 6ebebdbd8294..475e111531a1 100644 --- a/pkg/front_end/lib/src/fragment/extension.dart +++ b/pkg/front_end/lib/src/fragment/extension.dart @@ -22,7 +22,7 @@ class ExtensionFragment extends DeclarationFragment implements Fragment { late final Modifiers modifiers; late final TypeBuilder onType; late final int startOffset; - late final int nameOffset; + late final int nameOrExtensionOffset; late final int endOffset; ExtensionFragment( diff --git a/pkg/front_end/lib/src/fragment/factory.dart b/pkg/front_end/lib/src/fragment/factory.dart index 756147d30881..63c56faa35ea 100644 --- a/pkg/front_end/lib/src/fragment/factory.dart +++ b/pkg/front_end/lib/src/fragment/factory.dart @@ -7,10 +7,10 @@ part of 'fragment.dart'; class FactoryFragment implements Fragment, FunctionFragment { final String name; final Uri fileUri; - final int startCharOffset; - final int charOffset; - final int charOpenParenOffset; - final int charEndOffset; + final int startOffset; + final int nameOffset; + final int formalsOffset; + final int endOffset; final Modifiers modifiers; final List? metadata; final TypeBuilder returnType; @@ -25,10 +25,10 @@ class FactoryFragment implements Fragment, FunctionFragment { FactoryFragment( {required this.name, required this.fileUri, - required this.startCharOffset, - required this.charOffset, - required this.charOpenParenOffset, - required this.charEndOffset, + required this.startOffset, + required this.nameOffset, + required this.formalsOffset, + required this.endOffset, required this.modifiers, required this.metadata, required this.returnType, @@ -55,7 +55,7 @@ class FactoryFragment implements Fragment, FunctionFragment { } @override - String toString() => '$runtimeType($name,$fileUri,$charOffset)'; + String toString() => '$runtimeType($name,$fileUri,$nameOffset)'; } class _FactoryBodyBuildingContext implements FunctionBodyBuildingContext { diff --git a/pkg/front_end/lib/src/fragment/getter.dart b/pkg/front_end/lib/src/fragment/getter.dart index 505a4d7fffe7..5431f69d015f 100644 --- a/pkg/front_end/lib/src/fragment/getter.dart +++ b/pkg/front_end/lib/src/fragment/getter.dart @@ -7,10 +7,10 @@ part of 'fragment.dart'; class GetterFragment implements Fragment, FunctionFragment { final String name; final Uri fileUri; - final int startCharOffset; - final int charOffset; - final int charOpenParenOffset; - final int charEndOffset; + final int startOffset; + final int nameOffset; + final int formalsOffset; + final int endOffset; final bool isTopLevel; final List? metadata; final Modifiers modifiers; @@ -25,10 +25,10 @@ class GetterFragment implements Fragment, FunctionFragment { GetterFragment( {required this.name, required this.fileUri, - required this.startCharOffset, - required this.charOffset, - required this.charOpenParenOffset, - required this.charEndOffset, + required this.startOffset, + required this.nameOffset, + required this.formalsOffset, + required this.endOffset, required this.isTopLevel, required this.metadata, required this.modifiers, @@ -55,7 +55,7 @@ class GetterFragment implements Fragment, FunctionFragment { } @override - String toString() => '$runtimeType($name,$fileUri,$charOffset)'; + String toString() => '$runtimeType($name,$fileUri,$nameOffset)'; } class _GetterBodyBuildingContext implements FunctionBodyBuildingContext { diff --git a/pkg/front_end/lib/src/fragment/method.dart b/pkg/front_end/lib/src/fragment/method.dart index fb5ba5396933..49c12f566d51 100644 --- a/pkg/front_end/lib/src/fragment/method.dart +++ b/pkg/front_end/lib/src/fragment/method.dart @@ -7,10 +7,10 @@ part of 'fragment.dart'; class MethodFragment implements Fragment, FunctionFragment { final String name; final Uri fileUri; - final int startCharOffset; - final int charOffset; - final int charOpenParenOffset; - final int charEndOffset; + final int startOffset; + final int nameOffset; + final int formalsOffset; + final int endOffset; final bool isTopLevel; final List? metadata; final Modifiers modifiers; @@ -26,10 +26,10 @@ class MethodFragment implements Fragment, FunctionFragment { MethodFragment( {required this.name, required this.fileUri, - required this.startCharOffset, - required this.charOffset, - required this.charOpenParenOffset, - required this.charEndOffset, + required this.startOffset, + required this.nameOffset, + required this.formalsOffset, + required this.endOffset, required this.isTopLevel, required this.metadata, required this.modifiers, @@ -57,7 +57,7 @@ class MethodFragment implements Fragment, FunctionFragment { } @override - String toString() => '$runtimeType($name,$fileUri,$charOffset)'; + String toString() => '$runtimeType($name,$fileUri,$nameOffset)'; } class _MethodBodyBuildingContext implements FunctionBodyBuildingContext { diff --git a/pkg/front_end/lib/src/fragment/mixin.dart b/pkg/front_end/lib/src/fragment/mixin.dart index c958006fe29d..bd0bdf519a98 100644 --- a/pkg/front_end/lib/src/fragment/mixin.dart +++ b/pkg/front_end/lib/src/fragment/mixin.dart @@ -20,7 +20,6 @@ class MixinFragment extends DeclarationFragment implements Fragment { late final List? interfaces; late final List constructorReferences; late final int startOffset; - late final int charOffset; late final int endOffset; MixinFragment(this.name, super.fileUri, this.nameOffset, super.typeParameters, diff --git a/pkg/front_end/lib/src/fragment/named_mixin_application.dart b/pkg/front_end/lib/src/fragment/named_mixin_application.dart index b038baf16f3e..45171d43ef71 100644 --- a/pkg/front_end/lib/src/fragment/named_mixin_application.dart +++ b/pkg/front_end/lib/src/fragment/named_mixin_application.dart @@ -7,9 +7,9 @@ part of 'fragment.dart'; class NamedMixinApplicationFragment implements Fragment { final String name; final Uri fileUri; - final int startCharOffset; - final int charOffset; - final int charEndOffset; + final int startOffset; + final int nameOffset; + final int endOffset; final Modifiers modifiers; final List? metadata; final List? typeParameters; @@ -23,9 +23,9 @@ class NamedMixinApplicationFragment implements Fragment { NamedMixinApplicationFragment( {required this.name, required this.fileUri, - required this.startCharOffset, - required this.charOffset, - required this.charEndOffset, + required this.startOffset, + required this.nameOffset, + required this.endOffset, required this.modifiers, required this.metadata, required this.typeParameters, @@ -48,5 +48,5 @@ class NamedMixinApplicationFragment implements Fragment { } @override - String toString() => '$runtimeType($name,$fileUri,$charOffset)'; + String toString() => '$runtimeType($name,$fileUri,$nameOffset)'; } diff --git a/pkg/front_end/lib/src/fragment/primary_constructor.dart b/pkg/front_end/lib/src/fragment/primary_constructor.dart index 2742905dee70..ae963ba2d434 100644 --- a/pkg/front_end/lib/src/fragment/primary_constructor.dart +++ b/pkg/front_end/lib/src/fragment/primary_constructor.dart @@ -7,7 +7,9 @@ part of 'fragment.dart'; class PrimaryConstructorFragment implements Fragment, FunctionFragment { final String name; final Uri fileUri; - final int charOffset; + final int startOffset; + final int? nameOffset; + final int formalsOffset; final Modifiers modifiers; final OmittedTypeBuilder returnType; final List? typeParameters; @@ -20,7 +22,9 @@ class PrimaryConstructorFragment implements Fragment, FunctionFragment { PrimaryConstructorFragment( {required this.name, required this.fileUri, - required this.charOffset, + required this.startOffset, + required this.nameOffset, + required this.formalsOffset, required this.modifiers, required this.returnType, required this.typeParameters, @@ -29,6 +33,8 @@ class PrimaryConstructorFragment implements Fragment, FunctionFragment { required Token? beginInitializers}) : _beginInitializers = beginInitializers; + int get fileOffset => nameOffset ?? formalsOffset; + Token? get beginInitializers { Token? result = _beginInitializers; // Ensure that we don't hold onto the token. @@ -53,7 +59,7 @@ class PrimaryConstructorFragment implements Fragment, FunctionFragment { } @override - String toString() => '$runtimeType($name,$fileUri,$charOffset)'; + String toString() => '$runtimeType($name,$fileUri,$formalsOffset)'; } class _PrimaryConstructorBodyBuildingContext diff --git a/pkg/front_end/lib/src/fragment/setter.dart b/pkg/front_end/lib/src/fragment/setter.dart index f71345777b20..ca4f05b1eedd 100644 --- a/pkg/front_end/lib/src/fragment/setter.dart +++ b/pkg/front_end/lib/src/fragment/setter.dart @@ -7,10 +7,10 @@ part of 'fragment.dart'; class SetterFragment implements Fragment, FunctionFragment { final String name; final Uri fileUri; - final int startCharOffset; - final int charOffset; - final int charOpenParenOffset; - final int charEndOffset; + final int startOffset; + final int nameOffset; + final int formalsOffset; + final int endOffset; final bool isTopLevel; final List? metadata; final Modifiers modifiers; @@ -25,10 +25,10 @@ class SetterFragment implements Fragment, FunctionFragment { SetterFragment( {required this.name, required this.fileUri, - required this.startCharOffset, - required this.charOffset, - required this.charOpenParenOffset, - required this.charEndOffset, + required this.startOffset, + required this.nameOffset, + required this.formalsOffset, + required this.endOffset, required this.isTopLevel, required this.metadata, required this.modifiers, @@ -55,7 +55,7 @@ class SetterFragment implements Fragment, FunctionFragment { } @override - String toString() => '$runtimeType($name,$fileUri,$charOffset)'; + String toString() => '$runtimeType($name,$fileUri,$nameOffset)'; } class _SetterBodyBuildingContext implements FunctionBodyBuildingContext { diff --git a/pkg/front_end/lib/src/kernel/body_builder.dart b/pkg/front_end/lib/src/kernel/body_builder.dart index 475bda042693..dd8248e360c3 100644 --- a/pkg/front_end/lib/src/kernel/body_builder.dart +++ b/pkg/front_end/lib/src/kernel/body_builder.dart @@ -635,7 +635,7 @@ class BodyBuilder extends StackListenerImpl return buildProblem( fasta.messageSuperAsExpression, node.fileOffset, noLength); } else if (node is ProblemBuilder) { - return buildProblem(node.message, node.charOffset, noLength); + return buildProblem(node.message, node.fileOffset, noLength); } else { return unhandled("${node.runtimeType}", "toValue", -1, uri); } @@ -657,7 +657,7 @@ class BodyBuilder extends StackListenerImpl // Coverage-ignore(suite): Not run. else if (node is ProblemBuilder) { Expression expression = - buildProblem(node.message, node.charOffset, noLength); + buildProblem(node.message, node.fileOffset, noLength); return forest.createConstantPattern(expression); } else { return unhandled("${node.runtimeType}", "toPattern", -1, uri); @@ -760,7 +760,7 @@ class BodyBuilder extends StackListenerImpl variable, fasta.templateDuplicatedDeclaration, [ fasta.templateDuplicatedDeclarationCause .withArguments(name) - .withLocation(uri, existing.charOffset, name.length) + .withLocation(uri, existing.fileOffset, name.length) ]); return; } @@ -949,12 +949,12 @@ class BodyBuilder extends StackListenerImpl while (declaration.next != null) { // If we have duplicates, we try to find the right declaration. if (declaration.fileUri == uri && - declaration.charOffset == fileOffset) { + declaration.fileOffset == fileOffset) { break; } declaration = declaration.next!; } - if (declaration.fileUri != uri || declaration.charOffset != fileOffset) { + if (declaration.fileUri != uri || declaration.fileOffset != fileOffset) { // If we don't have the right declaration, skip the initializer. continue; } @@ -1044,15 +1044,15 @@ class BodyBuilder extends StackListenerImpl buildInvalidInitializer( buildProblem( fasta.messageExternalConstructorWithFieldInitializers, - formal.charOffset, + formal.fileOffset, formal.name.length), - formal.charOffset) + formal.fileOffset) ]; } else { initializers = buildFieldInitializer( formal.name, - formal.charOffset, - formal.charOffset, + formal.fileOffset, + formal.fileOffset, new VariableGet(formal.variable!), formal: formal); } @@ -1159,12 +1159,12 @@ class BodyBuilder extends StackListenerImpl if (formal.isNamed) { (superParametersAsArguments ??= []).add(new NamedExpression( formal.name, - createVariableGet(formal.variable!, formal.charOffset, + createVariableGet(formal.variable!, formal.fileOffset, forNullGuardedAccess: false)) - ..fileOffset = formal.charOffset); + ..fileOffset = formal.fileOffset); } else { (superParametersAsArguments ??= []).add(createVariableGet( - formal.variable!, formal.charOffset, + formal.variable!, formal.fileOffset, forNullGuardedAccess: false)); } } @@ -1815,9 +1815,9 @@ class BodyBuilder extends StackListenerImpl if (formal.isNamed) { NamedExpression superParameterAsArgument = new NamedExpression( formal.name, - createVariableGet(formal.variable!, formal.charOffset, + createVariableGet(formal.variable!, formal.fileOffset, forNullGuardedAccess: false)) - ..fileOffset = formal.charOffset; + ..fileOffset = formal.fileOffset; (namedSuperParametersAsArguments ??= []) .add(superParameterAsArgument); (namedSuperParameterNames ??= {}).add(formal.name); @@ -1825,7 +1825,7 @@ class BodyBuilder extends StackListenerImpl .add(superParameterAsArgument); } else { Expression superParameterAsArgument = createVariableGet( - formal.variable!, formal.charOffset, + formal.variable!, formal.fileOffset, forNullGuardedAccess: false); (positionalSuperParametersAsArguments ??= []) .add(superParameterAsArgument); @@ -2755,7 +2755,7 @@ class BodyBuilder extends StackListenerImpl } else { if (left is ProblemBuilder) { ProblemBuilder problem = left; - left = buildProblem(problem.message, problem.charOffset, noLength); + left = buildProblem(problem.message, problem.fileOffset, noLength); } assert(left is Expression); push(forest.createEquals(fileOffset, left as Expression, right, @@ -2778,7 +2778,7 @@ class BodyBuilder extends StackListenerImpl } else { if (left is ProblemBuilder) { ProblemBuilder problem = left; - left = buildProblem(problem.message, problem.charOffset, noLength); + left = buildProblem(problem.message, problem.fileOffset, noLength); } assert(left is Expression); push(forest.createBinary(fileOffset, left as Expression, name, right)); @@ -5015,14 +5015,14 @@ class BodyBuilder extends StackListenerImpl } else if (name is ProblemBuilder) { // TODO(ahe): Arguments could be passed here. libraryBuilder.addProblem( - name.message, name.charOffset, name.name.length, name.fileUri); + name.message, name.fileOffset, name.name.length, name.fileUri); result = new NamedTypeBuilderImpl.forInvalidType( name.name, isMarkedAsNullable ? const NullabilityBuilder.nullable() : const NullabilityBuilder.omitted(), name.message - .withLocation(name.fileUri, name.charOffset, name.name.length)); + .withLocation(name.fileUri, name.fileOffset, name.name.length)); } else { unhandled( "${name.runtimeType}", "handleType", beginToken.charOffset, uri); @@ -5050,7 +5050,7 @@ class BodyBuilder extends StackListenerImpl _localScope.addLocalVariable(name, builder); } else { // Coverage-ignore-block(suite): Not run. - reportDuplicatedDeclaration(existing, name, builder.charOffset); + reportDuplicatedDeclaration(existing, name, builder.fileOffset); } } } @@ -5070,7 +5070,7 @@ class BodyBuilder extends StackListenerImpl _localScope.addLocalVariable(name, builder); } else { // Coverage-ignore-block(suite): Not run. - reportDuplicatedDeclaration(existing, name, builder.charOffset); + reportDuplicatedDeclaration(existing, name, builder.fileOffset); } } } @@ -5707,7 +5707,7 @@ class BodyBuilder extends StackListenerImpl FormalParameterBuilder parameter = catchParameters.parameters![i]; compileTimeErrors ??= []; compileTimeErrors.add(buildProblemStatement( - fasta.messageCatchSyntaxExtraParameters, parameter.charOffset, + fasta.messageCatchSyntaxExtraParameters, parameter.fileOffset, length: parameter.name.length)); } } @@ -8822,7 +8822,7 @@ class BodyBuilder extends StackListenerImpl case StructuralVariableBuilder(): if (!libraryFeatures.genericMetadata.isEnabled) { addProblem(fasta.messageAnnotationOnFunctionTypeTypeVariable, - variable.charOffset, variable.name.length); + variable.fileOffset, variable.name.length); } break; case NominalVariableBuilder(): @@ -9089,7 +9089,7 @@ class BodyBuilder extends StackListenerImpl context: [ fasta.templateFieldAlreadyInitializedAtDeclarationCause .withArguments(name) - .withLocation(uri, builder.charOffset, name.length) + .withLocation(uri, builder.fileOffset, name.length) ]); MemberBuilder constructor = libraryBuilder.loader.getDuplicatedFieldInitializerError(); @@ -9120,7 +9120,7 @@ class BodyBuilder extends StackListenerImpl uri, context: [ fasta.messageInitializingFormalTypeMismatchField.withLocation( - builder.fileUri, builder.charOffset, noLength) + builder.fileUri, builder.fileOffset, noLength) ]); } } @@ -9187,7 +9187,7 @@ class BodyBuilder extends StackListenerImpl if (formal.isSuperInitializingFormal) { addProblem( fasta.messageUnexpectedSuperParametersInGenerativeConstructors, - formal.charOffset, + formal.fileOffset, noLength); } } @@ -9481,7 +9481,7 @@ class BodyBuilder extends StackListenerImpl fasta.templateDuplicatedDeclarationCause .withArguments(name) .withLocation( - existing.fileUri!, existing.charOffset, name.length) + existing.fileUri!, existing.fileOffset, name.length) ]; addProblem(fasta.templateDuplicatedDeclaration.withArguments(name), charOffset, name.length, @@ -10179,7 +10179,7 @@ class FormalParameters { Builder? existing = local[parameter.name]; if (existing != null) { helper.reportDuplicatedDeclaration( - existing, parameter.name, parameter.charOffset); + existing, parameter.name, parameter.fileOffset); } else { local[parameter.name] = parameter; } diff --git a/pkg/front_end/lib/src/kernel/body_builder_context.dart b/pkg/front_end/lib/src/kernel/body_builder_context.dart index 293836853438..61b485fb8c28 100644 --- a/pkg/front_end/lib/src/kernel/body_builder_context.dart +++ b/pkg/front_end/lib/src/kernel/body_builder_context.dart @@ -635,7 +635,7 @@ mixin _MemberBodyBuilderContext } @override - int get memberCharOffset => _member.charOffset; + int get memberCharOffset => _member.fileOffset; @override void registerSuperCall() { diff --git a/pkg/front_end/lib/src/kernel/combined_member_signature.dart b/pkg/front_end/lib/src/kernel/combined_member_signature.dart index c316b8cebb98..ef3e1842fc8f 100644 --- a/pkg/front_end/lib/src/kernel/combined_member_signature.dart +++ b/pkg/front_end/lib/src/kernel/combined_member_signature.dart @@ -647,7 +647,7 @@ abstract class CombinedMemberSignatureBase { type = member.type; } else { unhandled("${member.runtimeType}", "$member", - declarationBuilder.charOffset, declarationBuilder.fileUri); + declarationBuilder.fileOffset, declarationBuilder.fileUri); } if (member.enclosingTypeDeclaration!.typeParameters.isEmpty) { return type; diff --git a/pkg/front_end/lib/src/kernel/expression_generator.dart b/pkg/front_end/lib/src/kernel/expression_generator.dart index 26b48e379c87..b191cecba359 100644 --- a/pkg/front_end/lib/src/kernel/expression_generator.dart +++ b/pkg/front_end/lib/src/kernel/expression_generator.dart @@ -3412,7 +3412,7 @@ class TypeUseGenerator extends AbstractReadOnlyAccessGenerator { } } else if (member is AmbiguousBuilder) { return _helper.buildProblem( - member.message, member.charOffset, name.text.length); + member.message, member.fileOffset, name.text.length); } else if (member.isStatic && !member.isFactory && typeArguments != null) { diff --git a/pkg/front_end/lib/src/kernel/hierarchy/class_member.dart b/pkg/front_end/lib/src/kernel/hierarchy/class_member.dart index 07cf621668f1..492d929e7a5c 100644 --- a/pkg/front_end/lib/src/kernel/hierarchy/class_member.dart +++ b/pkg/front_end/lib/src/kernel/hierarchy/class_member.dart @@ -574,7 +574,7 @@ class SynthesizedInterfaceMember extends SynthesizedMember { classBuilder.addProblem( templateCombinedMemberSignatureFailed.withArguments( name, declarations.first.fullNameForErrors), - classBuilder.charOffset, + classBuilder.fileOffset, nameLength, context: context); // TODO(johnniwinther): Maybe we should have an invalid marker to avoid @@ -948,7 +948,7 @@ class SynthesizedNonExtensionTypeMember extends SynthesizedMember { extensionTypeDeclarationBuilder.addProblem( templateExtensionTypeCombinedMemberSignatureFailed.withArguments( name, declarations.first.fullNameForErrors), - extensionTypeDeclarationBuilder.charOffset, + extensionTypeDeclarationBuilder.fileOffset, nameLength, context: context); // TODO(johnniwinther): Maybe we should have an invalid marker to avoid diff --git a/pkg/front_end/lib/src/kernel/hierarchy/delayed.dart b/pkg/front_end/lib/src/kernel/hierarchy/delayed.dart index add0a10b6842..9a488eba58ed 100644 --- a/pkg/front_end/lib/src/kernel/hierarchy/delayed.dart +++ b/pkg/front_end/lib/src/kernel/hierarchy/delayed.dart @@ -82,7 +82,7 @@ abstract class DelayedGetterSetterCheck implements DelayedCheck { LibraryBuilder get libraryBuilder => declarationBuilder.libraryBuilder; - int get declarationOffset => declarationBuilder.charOffset; + int get declarationOffset => declarationBuilder.fileOffset; Uri get declarationUri => declarationBuilder.fileUri; diff --git a/pkg/front_end/lib/src/kernel/hierarchy/extension_type_members.dart b/pkg/front_end/lib/src/kernel/hierarchy/extension_type_members.dart index 899829f81110..d034f546b213 100644 --- a/pkg/front_end/lib/src/kernel/hierarchy/extension_type_members.dart +++ b/pkg/front_end/lib/src/kernel/hierarchy/extension_type_members.dart @@ -977,7 +977,7 @@ class _SanitizedMember { extensionTypeDeclarationBuilder.addProblem( templateImplementNonExtensionTypeAndExtensionTypeMember .withArguments(extensionTypeDeclarationBuilder.name, name.text), - extensionTypeDeclarationBuilder.charOffset, + extensionTypeDeclarationBuilder.fileOffset, extensionTypeDeclarationBuilder.name.length, context: context); } else if (extensionTypeMemberDeclarations.length > 1) { @@ -989,7 +989,7 @@ class _SanitizedMember { extensionTypeDeclarationBuilder.addProblem( templateImplementMultipleExtensionTypeMembers.withArguments( extensionTypeDeclarationBuilder.name, name.text), - extensionTypeDeclarationBuilder.charOffset, + extensionTypeDeclarationBuilder.fileOffset, extensionTypeDeclarationBuilder.name.length, context: context); } diff --git a/pkg/front_end/lib/src/kernel/hierarchy/hierarchy_node.dart b/pkg/front_end/lib/src/kernel/hierarchy/hierarchy_node.dart index 10e588910ccf..68796e6825fc 100644 --- a/pkg/front_end/lib/src/kernel/hierarchy/hierarchy_node.dart +++ b/pkg/front_end/lib/src/kernel/hierarchy/hierarchy_node.dart @@ -116,7 +116,7 @@ class ClassHierarchyNodeBuilder extends HierarchyNodeBuilder { String get _name => _classBuilder.name; @override - int get _fileOffset => _classBuilder.charOffset; + int get _fileOffset => _classBuilder.fileOffset; @override Uri get _fileUri => _classBuilder.fileUri; @@ -402,7 +402,7 @@ class ExtensionTypeHierarchyNodeBuilder extends HierarchyNodeBuilder { String get _name => _extensionTypeBuilder.name; @override - int get _fileOffset => _extensionTypeBuilder.charOffset; + int get _fileOffset => _extensionTypeBuilder.fileOffset; @override Uri get _fileUri => _extensionTypeBuilder.fileUri; diff --git a/pkg/front_end/lib/src/kernel/hierarchy/members_node.dart b/pkg/front_end/lib/src/kernel/hierarchy/members_node.dart index 0e83139b41bb..89f450228160 100644 --- a/pkg/front_end/lib/src/kernel/hierarchy/members_node.dart +++ b/pkg/front_end/lib/src/kernel/hierarchy/members_node.dart @@ -103,7 +103,7 @@ abstract class MembersNodeBuilder { } else { declarationBuilder.addProblem( messageInheritedMembersConflict, - declarationBuilder.charOffset, + declarationBuilder.fileOffset, declarationBuilder.fullNameForErrors.length, context: _inheritedConflictContext(a, b)); } @@ -1089,7 +1089,7 @@ class ClassMembersNodeBuilder extends MembersNodeBuilder { classBuilder.addProblem( templateMissingImplementationNotAbstract.withArguments( classBuilder.fullNameForErrors, names), - classBuilder.charOffset, + classBuilder.fileOffset, classBuilder.fullNameForErrors.length, context: context); } @@ -2849,7 +2849,7 @@ void reportCantInferParameterType(ClassBuilder cls, .toList(); cls.addProblem( templateCantInferTypeDueToNoCombinedSignature.withArguments(name), - parameter.charOffset, + parameter.fileOffset, name.length, wasHandled: true, context: context); @@ -2870,7 +2870,7 @@ void reportCantInferTypes(ClassBuilder cls, SourceProcedureBuilder member, .toList(); cls.addProblem( templateCantInferTypesDueToNoCombinedSignature.withArguments(name), - member.charOffset, + member.fileOffset, name.length, wasHandled: true, context: context); @@ -2938,7 +2938,7 @@ void reportCantInferReturnType(ClassBuilder cls, SourceProcedureBuilder member, // } cls.addProblem( templateCantInferReturnTypeDueToNoCombinedSignature.withArguments(name), - member.charOffset, + member.fileOffset, name.length, wasHandled: true, context: context); @@ -2959,7 +2959,7 @@ void reportCantInferFieldType(ClassBuilder cls, SourceFieldBuilder member, String name = member.fullNameForErrors; cls.addProblem( templateCantInferTypeDueToNoCombinedSignature.withArguments(name), - member.charOffset, + member.fileOffset, name.length, wasHandled: true, context: context); diff --git a/pkg/front_end/lib/src/kernel/hierarchy/mixin_inferrer.dart b/pkg/front_end/lib/src/kernel/hierarchy/mixin_inferrer.dart index da797b54104b..d7d36d4b72b0 100644 --- a/pkg/front_end/lib/src/kernel/hierarchy/mixin_inferrer.dart +++ b/pkg/front_end/lib/src/kernel/hierarchy/mixin_inferrer.dart @@ -185,12 +185,12 @@ class BuilderMixinInferrer { // Coverage-ignore(suite): Not run. void reportProblem(Message message, Class kernelClass) { int length = cls.isMixinApplication ? 1 : cls.fullNameForErrors.length; - cls.addProblem(message, cls.charOffset, length); + cls.addProblem(message, cls.fileOffset, length); } // Coverage-ignore(suite): Not run. Never reportUnsupportedProblem(String operation) { - return unsupported(operation, cls.charOffset, cls.fileUri); + return unsupported(operation, cls.fileOffset, cls.fileUri); } } diff --git a/pkg/front_end/lib/src/kernel/implicit_field_type.dart b/pkg/front_end/lib/src/kernel/implicit_field_type.dart index a593ea6ab739..9b2a4934699c 100644 --- a/pkg/front_end/lib/src/kernel/implicit_field_type.dart +++ b/pkg/front_end/lib/src/kernel/implicit_field_type.dart @@ -106,7 +106,7 @@ class _ImplicitFieldTypeRoot extends InferredType { @override // Coverage-ignore(suite): Not run. - int get charOffset => fieldBuilder.charOffset; + int get charOffset => fieldBuilder.fileOffset; @override DartType inferType(ClassHierarchyBase hierarchy) { @@ -119,7 +119,7 @@ class _ImplicitFieldTypeRoot extends InferredType { fieldBuilder.libraryBuilder.addProblem( templateCantInferTypeDueToCircularity .withArguments(fieldBuilder.name), - fieldBuilder.charOffset, + fieldBuilder.fileOffset, fieldBuilder.name.length, fieldBuilder.fileUri); DartType type = const InvalidType(); diff --git a/pkg/front_end/lib/src/kernel/kernel_target.dart b/pkg/front_end/lib/src/kernel/kernel_target.dart index acf8007e2a11..5a118408ff12 100644 --- a/pkg/front_end/lib/src/kernel/kernel_target.dart +++ b/pkg/front_end/lib/src/kernel/kernel_target.dart @@ -1564,10 +1564,10 @@ class KernelTarget { if (constructor.isEffectivelyRedirecting) continue; if (constructor.isConst && nonFinalFields.isNotEmpty) { classDeclaration.addProblem(messageConstConstructorNonFinalField, - constructor.charOffset, noLength, + constructor.fileOffset, noLength, context: nonFinalFields .map((field) => messageConstConstructorNonFinalFieldCause - .withLocation(field.fileUri, field.charOffset, noLength)) + .withLocation(field.fileUri, field.fileOffset, noLength)) .toList()); nonFinalFields.clear(); } @@ -1575,11 +1575,11 @@ class KernelTarget { for (FieldBuilder field in lateFinalFields) { classDeclaration.addProblem( messageConstConstructorLateFinalFieldError, - field.charOffset, + field.fileOffset, noLength, context: [ messageConstConstructorLateFinalFieldCause.withLocation( - constructor.fileUri!, constructor.charOffset, noLength) + constructor.fileUri!, constructor.fileOffset, noLength) ]); } lateFinalFields.clear(); @@ -1623,7 +1623,7 @@ class KernelTarget { libraryBuilder.addProblem( templateFinalFieldNotInitialized .withArguments(fieldBuilder.name), - fieldBuilder.charOffset, + fieldBuilder.fileOffset, fieldBuilder.name.length, fieldBuilder.fileUri); } @@ -1632,7 +1632,7 @@ class KernelTarget { libraryBuilder.addProblem( templateFieldNonNullableWithoutInitializerError.withArguments( fieldBuilder.name, fieldBuilder.fieldType), - fieldBuilder.charOffset, + fieldBuilder.fileOffset, fieldBuilder.name.length, fieldBuilder.fileUri); } @@ -1656,14 +1656,14 @@ class KernelTarget { libraryBuilder.addProblem( templateFinalFieldNotInitializedByConstructor .withArguments(fieldBuilder.name), - constructorBuilder.charOffset, + constructorBuilder.fileOffset, constructorBuilder.name.length, constructorBuilder.fileUri, context: [ templateMissingImplementationCause .withArguments(fieldBuilder.name) .withLocation(fieldBuilder.fileUri, - fieldBuilder.charOffset, fieldBuilder.name.length) + fieldBuilder.fileOffset, fieldBuilder.name.length) ]); } else if (fieldBuilder.field.type is! InvalidType && !fieldBuilder.isLate && @@ -1671,14 +1671,14 @@ class KernelTarget { libraryBuilder.addProblem( templateFieldNonNullableNotInitializedByConstructorError .withArguments(fieldBuilder.name, fieldBuilder.field.type), - constructorBuilder.charOffset, + constructorBuilder.fileOffset, noLength, constructorBuilder.fileUri, context: [ templateMissingImplementationCause .withArguments(fieldBuilder.name) .withLocation(fieldBuilder.fileUri, - fieldBuilder.charOffset, fieldBuilder.name.length) + fieldBuilder.fileOffset, fieldBuilder.name.length) ]); } } diff --git a/pkg/front_end/lib/src/kernel/kernel_variable_builder.dart b/pkg/front_end/lib/src/kernel/kernel_variable_builder.dart index fb4b9cc04c0c..ae491c998161 100644 --- a/pkg/front_end/lib/src/kernel/kernel_variable_builder.dart +++ b/pkg/front_end/lib/src/kernel/kernel_variable_builder.dart @@ -23,7 +23,7 @@ class VariableBuilderImpl extends BuilderImpl implements VariableBuilder { Builder? get parent => null; @override - int get charOffset => variable.fileOffset; + int get fileOffset => variable.fileOffset; @override bool get isLocal => true; diff --git a/pkg/front_end/lib/src/kernel/load_library_builder.dart b/pkg/front_end/lib/src/kernel/load_library_builder.dart index 7f7723ea3fae..1b1955c7e6ed 100644 --- a/pkg/front_end/lib/src/kernel/load_library_builder.dart +++ b/pkg/front_end/lib/src/kernel/load_library_builder.dart @@ -37,7 +37,7 @@ class LoadLibraryBuilder extends BuilderImpl { /// Offset of the import prefix. @override - final int charOffset; + final int fileOffset; /// Synthetic static method to represent the tear-off of 'loadLibrary'. If /// null, no tear-offs were seen in the code and no method is generated. @@ -51,7 +51,7 @@ class LoadLibraryBuilder extends BuilderImpl { final List? _combinators; - LoadLibraryBuilder(this.parent, this.charOffset, this._imported, this._prefix, + LoadLibraryBuilder(this.parent, this.fileOffset, this._imported, this._prefix, this._importCharOffset, this._combinators); @override @@ -68,7 +68,7 @@ class LoadLibraryBuilder extends BuilderImpl { // Coverage-ignore-block(suite): Not run. return tearoff!; } - LoadLibrary expression = createLoadLibrary(charOffset, forest, null); + LoadLibrary expression = createLoadLibrary(fileOffset, forest, null); String prefix = expression.import.name!; Name name = new Name('_#loadLibrary_$prefix', parent.library); Reference? reference = parent.indexedLibrary?.lookupGetterReference(name); @@ -81,8 +81,8 @@ class LoadLibraryBuilder extends BuilderImpl { fileUri: parent.library.fileUri, isStatic: true, reference: reference) - ..fileStartOffset = charOffset - ..fileOffset = charOffset; + ..fileStartOffset = fileOffset + ..fileOffset = fileOffset; } @override diff --git a/pkg/front_end/lib/src/kernel/macro/introspectors.dart b/pkg/front_end/lib/src/kernel/macro/introspectors.dart index ae0c63ba4742..e2fb61dd0897 100644 --- a/pkg/front_end/lib/src/kernel/macro/introspectors.dart +++ b/pkg/front_end/lib/src/kernel/macro/introspectors.dart @@ -284,7 +284,7 @@ class MacroIntrospection { : null); _classBuilders[declaration] = builder; _declarationOffsets[declaration] = - new UriOffset(builder.fileUri, builder.charOffset); + new UriOffset(builder.fileUri, builder.fileOffset); return declaration; } @@ -334,7 +334,7 @@ class MacroIntrospection { aliasedType: types.getTypeAnnotation(builder.libraryBuilder, builder.type)); _declarationOffsets[declaration] = - new UriOffset(builder.fileUri, builder.charOffset); + new UriOffset(builder.fileUri, builder.fileOffset); return declaration; } @@ -374,7 +374,7 @@ class MacroIntrospection { ); namedParameters.add(declaration); _declarationOffsets[declaration] = - new UriOffset(formal.fileUri, formal.charOffset); + new UriOffset(formal.fileUri, formal.fileOffset); } else { macro.FormalParameterDeclarationImpl declaration = new macro.FormalParameterDeclarationImpl( @@ -390,7 +390,7 @@ class MacroIntrospection { ); positionalParameters.add(declaration); _declarationOffsets[declaration] = - new UriOffset(formal.fileUri, formal.charOffset); + new UriOffset(formal.fileUri, formal.fileOffset); } } return (positionalParameters, namedParameters); @@ -443,7 +443,7 @@ class MacroIntrospection { ); if (builder.fileUri != null) { _declarationOffsets[declaration] = - new UriOffset(builder.fileUri!, builder.charOffset); + new UriOffset(builder.fileUri!, builder.fileOffset); } return declaration; } @@ -488,7 +488,7 @@ class MacroIntrospection { typeParameters: const [], ); _declarationOffsets[declaration] = - new UriOffset(builder.fileUri, builder.charOffset); + new UriOffset(builder.fileUri, builder.fileOffset); return declaration; } @@ -560,7 +560,7 @@ class MacroIntrospection { typeParameters: const []); } _declarationOffsets[declaration] = - new UriOffset(builder.fileUri, builder.charOffset); + new UriOffset(builder.fileUri, builder.fileOffset); return declaration; } @@ -616,7 +616,7 @@ class MacroIntrospection { type: types.getTypeAnnotation(builder.libraryBuilder, builder.type)); } _declarationOffsets[declaration] = - new UriOffset(builder.fileUri, builder.charOffset); + new UriOffset(builder.fileUri, builder.fileOffset); return declaration; } @@ -643,7 +643,7 @@ class MacroIntrospection { : null); if (nominalVariableBuilder.fileUri != null) { _declarationOffsets[declaration] = new UriOffset( - nominalVariableBuilder.fileUri!, nominalVariableBuilder.charOffset); + nominalVariableBuilder.fileUri!, nominalVariableBuilder.fileOffset); } return declaration; } diff --git a/pkg/front_end/lib/src/kernel/type_algorithms.dart b/pkg/front_end/lib/src/kernel/type_algorithms.dart index c1d0e3af92d4..777976339f32 100644 --- a/pkg/front_end/lib/src/kernel/type_algorithms.dart +++ b/pkg/front_end/lib/src/kernel/type_algorithms.dart @@ -330,7 +330,7 @@ List getInboundReferenceIssues( [ templateNonSimpleBoundViaVariable .withArguments(dependency.declaration!.name) - .withLocation(dependent.fileUri!, dependent.charOffset, + .withLocation(dependent.fileUri!, dependent.fileOffset, dependent.name.length) ])); } @@ -556,7 +556,7 @@ List> findRawTypeCycles( declaration, declaration.typeParameters); } else { unhandled('$declaration (${declaration.runtimeType})', 'findRawTypeCycles', - declaration.charOffset, declaration.fileUri); + declaration.fileOffset, declaration.fileUri); } return const []; } @@ -590,7 +590,7 @@ List convertRawTypeCyclesIntoIssues( .withArguments(cycleElement.type.declaration!.name) .withLocation( cycleElement.typeVariable!.fileUri!, - cycleElement.typeVariable!.charOffset, + cycleElement.typeVariable!.fileOffset, cycleElement.typeVariable!.name.length)); } @@ -645,7 +645,7 @@ List getNonSimplicityIssuesForDeclaration( unhandled( '$declaration (${declaration.runtimeType})', 'getNonSimplicityIssuesForDeclaration', - declaration.charOffset, + declaration.fileOffset, declaration.fileUri); } List> cyclesToReport = diff --git a/pkg/front_end/lib/src/source/builder_factory.dart b/pkg/front_end/lib/src/source/builder_factory.dart index 3d72c239a34a..01304be81099 100644 --- a/pkg/front_end/lib/src/source/builder_factory.dart +++ b/pkg/front_end/lib/src/source/builder_factory.dart @@ -67,9 +67,9 @@ abstract class BuilderFactory { void beginClassOrNamedMixinApplicationHeader(); /// Registers that this builder is preparing for a class declaration with the - /// given [name] and [typeVariables] located [charOffset]. + /// given [name] and [typeVariables] located at [nameOffset]. void beginClassDeclaration( - String name, int charOffset, List? typeVariables); + String name, int nameOffset, List? typeVariables); void beginClassBody(); @@ -79,9 +79,9 @@ abstract class BuilderFactory { List? typeVariables); /// Registers that this builder is preparing for a mixin declaration with the - /// given [name] and [typeVariables] located [charOffset]. + /// given [name] and [typeVariables] located at [nameOffset]. void beginMixinDeclaration( - String name, int charOffset, List? typeVariables); + String name, int nameOffset, List? typeVariables); void beginMixinBody(); @@ -103,9 +103,9 @@ abstract class BuilderFactory { void beginEnumDeclarationHeader(String name); /// Registers that this builder is preparing for an enum declaration with - /// the given [name] and [typeVariables] located [charOffset]. + /// the given [name] and [typeVariables] located at [nameOffset]. void beginEnumDeclaration( - String name, int charOffset, List? typeVariables); + String name, int nameOffset, List? typeVariables); void beginEnumBody(); @@ -126,9 +126,9 @@ abstract class BuilderFactory { void endExtensionDeclaration(String? name); /// Registers that this builder is preparing for an extension type declaration - /// with the given [name] and [typeVariables] located [charOffset]. + /// with the given [name] and [typeVariables] located at [nameOffset]. void beginExtensionTypeDeclaration( - String name, int charOffset, List? typeVariables); + String name, int nameOffset, List? typeVariables); void beginExtensionTypeBody(); @@ -218,76 +218,75 @@ abstract class BuilderFactory { int uriOffset); void addClass( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - Identifier identifier, - List? typeVariables, - TypeBuilder? supertype, - MixinApplicationBuilder? mixins, - List? interfaces, - int startOffset, - int nameOffset, - int endOffset, - int supertypeOffset); + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required Identifier identifier, + required List? typeVariables, + required TypeBuilder? supertype, + required MixinApplicationBuilder? mixins, + required List? interfaces, + required int startOffset, + required int nameOffset, + required int endOffset, + required int supertypeOffset}); void addEnum( - OffsetMap offsetMap, - List? metadata, - Identifier identifier, - List? typeVariables, - MixinApplicationBuilder? supertypeBuilder, - List? interfaceBuilders, - List? enumConstantInfos, - int startCharOffset, - int charEndOffset); + {required OffsetMap offsetMap, + required List? metadata, + required Identifier identifier, + required List? typeVariables, + required MixinApplicationBuilder? supertypeBuilder, + required List? interfaceBuilders, + required List? enumConstantInfos, + required int startOffset, + required int endOffset}); void addExtensionDeclaration( - OffsetMap offsetMap, - Token beginToken, - List? metadata, - Modifiers modifiers, - Identifier? identifier, - List? typeVariables, - TypeBuilder type, - int startOffset, - int nameOffset, - int endOffset); + {required OffsetMap offsetMap, + required Token beginToken, + required List? metadata, + required Modifiers modifiers, + required Identifier? identifier, + required List? typeVariables, + required TypeBuilder onType, + required int startOffset, + required int nameOrExtensionOffset, + required int endOffset}); void addExtensionTypeDeclaration( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - Identifier identifier, - List? typeVariables, - List? interfaces, - int startOffset, - int endOffset); + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required Identifier identifier, + required List? typeVariables, + required List? interfaces, + required int startOffset, + required int endOffset}); void addMixinDeclaration( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - Identifier identifier, - List? typeVariables, - List? supertypeConstraints, - List? interfaces, - int startOffset, - int nameOffset, - int endOffset, - int supertypeOffset); + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required Identifier identifier, + required List? typeVariables, + required List? supertypeConstraints, + required List? interfaces, + required int startOffset, + required int nameOffset, + required int endOffset}); void addNamedMixinApplication( - List? metadata, - String name, - List? typeVariables, - Modifiers modifiers, - TypeBuilder? supertype, - MixinApplicationBuilder mixinApplication, - List? interfaces, - int startCharOffset, - int charOffset, - int charEndOffset); + {required List? metadata, + required String name, + required List? typeVariables, + required Modifiers modifiers, + required TypeBuilder? supertype, + required MixinApplicationBuilder mixinApplication, + required List? interfaces, + required int startOffset, + required int nameOffset, + required int endOffset}); MixinApplicationBuilder addMixinApplication( List mixins, int charOffset); @@ -308,9 +307,9 @@ abstract class BuilderFactory { required List? formals, required List? typeVariables, required Token? beginInitializers, - required int startCharOffset, - required int endCharOffset, - required int charOffset, + required int startOffset, + required int endOffset, + required int nameOffset, required int formalsOffset, required Modifiers modifiers, required bool inConstructor, @@ -324,19 +323,19 @@ abstract class BuilderFactory { required ProcedureKind? kind}); void addConstructor( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - Identifier identifier, - String constructorName, - List? typeVariables, - List? formals, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - String? nativeMethodName, - {Token? beginInitializers, + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required Identifier identifier, + required String constructorName, + required List? typeVariables, + required List? formals, + required int startOffset, + required int nameOffset, + required int formalsOffset, + required int endOffset, + required String? nativeMethodName, + required Token? beginInitializers, required bool forAbstractClassOrMixin}); void addPrimaryConstructor( @@ -344,7 +343,9 @@ abstract class BuilderFactory { required Token beginToken, required String constructorName, required List? formals, - required int charOffset, + required int startOffset, + required int? nameOffset, + required int formalsOffset, required bool isConst}); void addPrimaryConstructorField( @@ -354,78 +355,78 @@ abstract class BuilderFactory { required int charOffset}); void addFactoryMethod( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - Identifier identifier, - List? formals, - ConstructorReferenceBuilder? redirectionTarget, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - String? nativeMethodName, - AsyncMarker asyncModifier); + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required Identifier identifier, + required List? formals, + required ConstructorReferenceBuilder? redirectionTarget, + required int startOffset, + required int nameOffset, + required int formalsOffset, + required int endOffset, + required String? nativeMethodName, + required AsyncMarker asyncModifier}); String? computeAndValidateConstructorName( DeclarationFragment enclosingDeclaration, Identifier identifier, {isFactory = false}); void addMethod( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - TypeBuilder? returnType, - Identifier identifier, - String name, - List? typeVariables, - List? formals, - ProcedureKind kind, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - String? nativeMethodName, - AsyncMarker asyncModifier, - {required bool isInstanceMember, + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required TypeBuilder? returnType, + required Identifier identifier, + required String name, + required List? typeVariables, + required List? formals, + required ProcedureKind kind, + required int startOffset, + required int nameOffset, + required int formalsOffset, + required int endOffset, + required String? nativeMethodName, + required AsyncMarker asyncModifier, + required bool isInstanceMember, required bool isExtensionMember, required bool isExtensionTypeMember}); void addGetter( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - TypeBuilder? returnType, - Identifier identifier, - String name, - List? typeVariables, - List? formals, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - String? nativeMethodName, - AsyncMarker asyncModifier, - {required bool isInstanceMember, + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required TypeBuilder? returnType, + required Identifier identifier, + required String name, + required List? typeVariables, + required List? formals, + required int startOffset, + required int nameOffset, + required int formalsOffset, + required int endOffset, + required String? nativeMethodName, + required AsyncMarker asyncModifier, + required bool isInstanceMember, required bool isExtensionMember, required bool isExtensionTypeMember}); void addSetter( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - TypeBuilder? returnType, - Identifier identifier, - String name, - List? typeVariables, - List? formals, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - String? nativeMethodName, - AsyncMarker asyncModifier, - {required bool isInstanceMember, + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required TypeBuilder? returnType, + required Identifier identifier, + required String name, + required List? typeVariables, + required List? formals, + required int startOffset, + required int nameOffset, + required int formalsOffset, + required int endOffset, + required String? nativeMethodName, + required AsyncMarker asyncModifier, + required bool isInstanceMember, required bool isExtensionMember, required bool isExtensionTypeMember}); diff --git a/pkg/front_end/lib/src/source/class_declaration.dart b/pkg/front_end/lib/src/source/class_declaration.dart index 065492f06d80..9fdec69b76ef 100644 --- a/pkg/front_end/lib/src/source/class_declaration.dart +++ b/pkg/front_end/lib/src/source/class_declaration.dart @@ -104,7 +104,7 @@ mixin ClassDeclarationMixin implements ClassDeclaration { MemberBuilder declaration = iterator.current; if (declaration.declarationBuilder?.origin != origin) { unexpected("$fileUri", "${declaration.declarationBuilder!.fileUri}", - charOffset, fileUri); + fileOffset, fileUri); } if (declaration is RedirectingFactoryBuilder) { // Compute the immediate redirection target, not the effective. diff --git a/pkg/front_end/lib/src/source/offset_map.dart b/pkg/front_end/lib/src/source/offset_map.dart index bc187b77329d..8dd2b2718a73 100644 --- a/pkg/front_end/lib/src/source/offset_map.dart +++ b/pkg/front_end/lib/src/source/offset_map.dart @@ -172,7 +172,7 @@ class OffsetMap { templateInternalProblemNotFound.withArguments(name), charOffset, uri); } if (uri != declaration.fileUri) { - unexpected("$uri", "${declaration.fileUri}", declaration.charOffset, + unexpected("$uri", "${declaration.fileUri}", declaration.fileOffset, declaration.fileUri); } return declaration; diff --git a/pkg/front_end/lib/src/source/outline_builder.dart b/pkg/front_end/lib/src/source/outline_builder.dart index 4913210501c3..d0439d8ed594 100644 --- a/pkg/front_end/lib/src/source/outline_builder.dart +++ b/pkg/front_end/lib/src/source/outline_builder.dart @@ -1306,8 +1306,7 @@ class OutlineBuilder extends StackListenerImpl { _builderFactory.endClassDeclarationForParserRecovery(typeVariables); } else { Identifier identifier = name as Identifier; - final int startCharOffset = - metadata == null ? beginToken.charOffset : metadata.first.charOffset; + final int startOffset = metadata?.first.atOffset ?? beginToken.charOffset; String classNameForErrors = identifier.name; if (supertype != null) { @@ -1350,18 +1349,18 @@ class OutlineBuilder extends StackListenerImpl { modifiers |= Modifiers.Abstract; } _builderFactory.addClass( - _offsetMap, - metadata, - modifiers, - identifier, - typeVariables, - supertype, - mixinApplication, - interfaces, - startCharOffset, - identifier.nameOffset, - endToken.charOffset, - supertypeOffset); + offsetMap: _offsetMap, + metadata: metadata, + modifiers: modifiers, + identifier: identifier, + typeVariables: typeVariables, + supertype: supertype, + mixins: mixinApplication, + interfaces: interfaces, + startOffset: startOffset, + nameOffset: identifier.nameOffset, + endOffset: endToken.charOffset, + supertypeOffset: supertypeOffset); } popDeclarationContext(DeclarationContext.Class); } @@ -1401,11 +1400,11 @@ class OutlineBuilder extends StackListenerImpl { _builderFactory.endMixinDeclarationForParserRecovery(typeVariables); } else { Identifier identifier = name as Identifier; - int startOffset = metadata == null - ? beginToken.charOffset - : - // Coverage-ignore(suite): Not run. - metadata.first.charOffset; + int startOffset = metadata + // Coverage-ignore(suite): Not run. + ?.first // Coverage-ignore(suite): Not run. + .atOffset ?? + beginToken.charOffset; String classNameForErrors = identifier.name; if (supertypeConstraints != null) { for (TypeBuilder supertype in supertypeConstraints) { @@ -1433,17 +1432,16 @@ class OutlineBuilder extends StackListenerImpl { } _builderFactory.addMixinDeclaration( - _offsetMap, - metadata, - modifiers, - identifier, - typeVariables, - supertypeConstraints, - interfaces, - startOffset, - identifier.nameOffset, - endToken.charOffset, - -1); + offsetMap: _offsetMap, + metadata: metadata, + modifiers: modifiers, + identifier: identifier, + typeVariables: typeVariables, + supertypeConstraints: supertypeConstraints, + interfaces: interfaces, + startOffset: startOffset, + nameOffset: identifier.nameOffset, + endOffset: endToken.charOffset); } popDeclarationContext(DeclarationContext.Mixin); } @@ -1495,25 +1493,23 @@ class OutlineBuilder extends StackListenerImpl { List? typeVariables = pop(NullValues.NominalVariables) as List?; Identifier? name = pop(NullValues.Identifier) as Identifier?; - int nameOffset = name?.nameOffset ?? extensionKeyword.charOffset; + int nameOrExtensionOffset = name?.nameOffset ?? extensionKeyword.charOffset; List? metadata = pop(NullValues.Metadata) as List?; checkEmpty(extensionKeyword.charOffset); - int startOffset = metadata == null - ? extensionKeyword.charOffset - : metadata.first.charOffset; + int startOffset = metadata?.first.atOffset ?? extensionKeyword.charOffset; _builderFactory.addExtensionDeclaration( - _offsetMap, - beginToken, - metadata, + offsetMap: _offsetMap, + beginToken: beginToken, + metadata: metadata, // TODO(johnniwinther): Support modifiers on extensions? - Modifiers.empty, - name, - typeVariables, - onType as TypeBuilder, - startOffset, - nameOffset, - endToken.charOffset); + modifiers: Modifiers.empty, + identifier: name, + typeVariables: typeVariables, + onType: onType as TypeBuilder, + startOffset: startOffset, + nameOrExtensionOffset: nameOrExtensionOffset, + endOffset: endToken.charOffset); popDeclarationContext(DeclarationContext.Extension); } @@ -1528,10 +1524,11 @@ class OutlineBuilder extends StackListenerImpl { List? typeVariables = pop() as List?; String name = nameToken.lexeme; - int offset = nameToken.charOffset; + int nameOffset = nameToken.charOffset; push(new SimpleIdentifier(nameToken)); push(typeVariables ?? NullValues.NominalVariables); - _builderFactory.beginExtensionTypeDeclaration(name, offset, typeVariables); + _builderFactory.beginExtensionTypeDeclaration( + name, nameOffset, typeVariables); } @override @@ -1557,19 +1554,17 @@ class OutlineBuilder extends StackListenerImpl { reportIfNotEnabled(libraryFeatures.inlineClass, extensionKeyword.next!.charOffset, extensionKeyword.next!.length); - int startOffset = metadata == null - ? extensionKeyword.charOffset - : metadata.first.charOffset; + int startOffset = metadata?.first.atOffset ?? beginToken.charOffset; _builderFactory.addExtensionTypeDeclaration( - _offsetMap, - metadata, + offsetMap: _offsetMap, + metadata: metadata, // TODO(johnniwinther): Support modifiers on extension types? - Modifiers.empty, - identifier, - typeVariables, - interfaces, - startOffset, - endToken.charOffset); + modifiers: Modifiers.empty, + identifier: identifier, + typeVariables: typeVariables, + interfaces: interfaces, + startOffset: startOffset, + endOffset: endToken.charOffset); popDeclarationContext(DeclarationContext.ExtensionType); } @@ -1588,13 +1583,20 @@ class OutlineBuilder extends StackListenerImpl { List? formals = pop(NullValues.FormalParameters) as List?; int charOffset = pop() as int; // Pop formals char offset + + int? nameOffset; + int formalsOffset = charOffset; + String constructorName = ''; if (hasConstructorName) { // TODO(johnniwinther): Handle [ParserRecovery]. Identifier identifier = pop() as Identifier; - charOffset = identifier.nameOffset; + nameOffset = charOffset = identifier.nameOffset; constructorName = identifier.name; } + + int? startOffset = constKeyword?.charOffset ?? nameOffset ?? formalsOffset; + bool inExtensionType = declarationContext == DeclarationContext.ExtensionType; if (formals != null) { @@ -1610,25 +1612,25 @@ class OutlineBuilder extends StackListenerImpl { _compilationUnit.addProblem( // ignore: lines_longer_than_80_chars messageExtensionTypePrimaryConstructorFunctionFormalParameterSyntax, - formal.charOffset, + formal.fileOffset, formal.name.length, formal.fileUri); } if (type is ImplicitTypeBuilder) { _compilationUnit.addProblem(messageExpectedRepresentationType, - formal.charOffset, formal.name.length, formal.fileUri); + formal.fileOffset, formal.name.length, formal.fileUri); formal.type = - new InvalidTypeBuilderImpl(formal.fileUri, formal.charOffset); + new InvalidTypeBuilderImpl(formal.fileUri, formal.fileOffset); } if (formal.modifiers.containsSyntacticModifiers( ignoreCovariant: true, ignoreRequired: true)) { _compilationUnit.addProblem(messageRepresentationFieldModifier, - formal.charOffset, formal.name.length, formal.fileUri); + formal.fileOffset, formal.name.length, formal.fileUri); } if (formal.isInitializingFormal) { _compilationUnit.addProblem( messageExtensionTypePrimaryConstructorWithInitializingFormal, - formal.charOffset, + formal.fileOffset, formal.name.length, formal.fileUri); } @@ -1636,13 +1638,13 @@ class OutlineBuilder extends StackListenerImpl { if (formal.isPositional) { if (formal.isOptionalPositional) { - firstOptionalPositionalParameterOffset = formal.charOffset; + firstOptionalPositionalParameterOffset = formal.fileOffset; } else { requiredPositionalCount++; } } if (formal.isNamed) { - firstNamedParameterOffset = formal.charOffset; + firstNamedParameterOffset = formal.fileOffset; } _builderFactory.addPrimaryConstructorField( // TODO(johnniwinther): Support annotations on annotations on fields @@ -1652,7 +1654,7 @@ class OutlineBuilder extends StackListenerImpl { metadata: null, type: formal.type, name: formal.name, - charOffset: formal.charOffset); + charOffset: formal.fileOffset); formals[i] = formal.forPrimaryConstructor(_builderFactory); } if (inExtensionType) { @@ -1682,7 +1684,10 @@ class OutlineBuilder extends StackListenerImpl { offsetMap: _offsetMap, beginToken: beginToken, constructorName: constructorName == "new" ? "" : constructorName, - charOffset: charOffset, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + // TODO(johnniwinther): Provide `endOffset`. formals: formals, isConst: constKeyword != null); } @@ -1745,66 +1750,67 @@ class OutlineBuilder extends StackListenerImpl { checkEmpty(beginToken.charOffset); if (identifier is Identifier) { _builderFactory.endTopLevelMethod(); - final int startCharOffset = - metadata == null ? beginToken.charOffset : metadata.first.charOffset; + final int startOffset = metadata?.first.atOffset ?? beginToken.charOffset; + int nameOffset = identifier.nameOffset; + int endOffset = endToken.charOffset; ProcedureKind kind = computeProcedureKind(getOrSet); switch (kind) { case ProcedureKind.Method: case ProcedureKind.Operator: _builderFactory.addMethod( - _offsetMap, - metadata, - modifiers, - returnType, - identifier, - identifier.name, - typeVariables, - formals, - kind, - startCharOffset, - identifier.nameOffset, - formalsOffset, - endToken.charOffset, - nativeMethodName, - asyncModifier, + offsetMap: _offsetMap, + metadata: metadata, + modifiers: modifiers, + returnType: returnType, + identifier: identifier, + name: identifier.name, + typeVariables: typeVariables, + formals: formals, + kind: kind, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, + nativeMethodName: nativeMethodName, + asyncModifier: asyncModifier, isInstanceMember: false, isExtensionMember: false, isExtensionTypeMember: false); case ProcedureKind.Getter: _builderFactory.addGetter( - _offsetMap, - metadata, - modifiers, - returnType, - identifier, - identifier.name, - typeVariables, - formals, - startCharOffset, - identifier.nameOffset, - formalsOffset, - endToken.charOffset, - nativeMethodName, - asyncModifier, + offsetMap: _offsetMap, + metadata: metadata, + modifiers: modifiers, + returnType: returnType, + identifier: identifier, + name: identifier.name, + typeVariables: typeVariables, + formals: formals, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, + nativeMethodName: nativeMethodName, + asyncModifier: asyncModifier, isInstanceMember: false, isExtensionMember: false, isExtensionTypeMember: false); case ProcedureKind.Setter: _builderFactory.addSetter( - _offsetMap, - metadata, - modifiers, - returnType, - identifier, - identifier.name, - typeVariables, - formals, - startCharOffset, - identifier.nameOffset, - formalsOffset, - endToken.charOffset, - nativeMethodName, - asyncModifier, + offsetMap: _offsetMap, + metadata: metadata, + modifiers: modifiers, + returnType: returnType, + identifier: identifier, + name: identifier.name, + typeVariables: typeVariables, + formals: formals, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, + nativeMethodName: nativeMethodName, + asyncModifier: asyncModifier, isInstanceMember: false, isExtensionMember: false, isExtensionTypeMember: false); @@ -2072,7 +2078,7 @@ class OutlineBuilder extends StackListenerImpl { String name; ProcedureKind? kind; - int charOffset = identifier.qualifierOffset; + int nameOffset = identifier.qualifierOffset; if (operator != null) { name = operator.text; kind = ProcedureKind.Operator; @@ -2101,12 +2107,12 @@ class OutlineBuilder extends StackListenerImpl { unhandled("$requiredArgumentCount", "operatorRequiredArgumentCount", identifier.nameOffset, uri); } - addProblem(template.withArguments(name), charOffset, name.length); + addProblem(template.withArguments(name), nameOffset, name.length); } else { if (formals != null) { for (FormalParameterBuilder formal in formals) { if (!formal.isRequiredPositional) { - addProblem(messageOperatorWithOptionalFormals, formal.charOffset, + addProblem(messageOperatorWithOptionalFormals, formal.fileOffset, formal.name.length); } } @@ -2115,7 +2121,7 @@ class OutlineBuilder extends StackListenerImpl { if (typeVariables != null) { NominalVariableBuilder typeVariableBuilder = typeVariables.first; addProblem(messageOperatorWithTypeParameters, - typeVariableBuilder.charOffset, typeVariableBuilder.name.length); + typeVariableBuilder.fileOffset, typeVariableBuilder.name.length); } } else { name = identifier.name; @@ -2201,10 +2207,9 @@ class OutlineBuilder extends StackListenerImpl { } } - int startCharOffset = - metadata == null ? beginToken.charOffset : metadata.first.charOffset; + int startOffset = metadata?.first.atOffset ?? beginToken.charOffset; - int endCharOffset = endToken.charOffset; + int endOffset = endToken.charOffset; bool forAbstractClassOrMixin = inAbstractOrSealedClass || methodKind == _MethodKind.mixinConstructor; @@ -2221,9 +2226,9 @@ class OutlineBuilder extends StackListenerImpl { formals: formals, typeVariables: typeVariables, beginInitializers: beginInitializers, - startCharOffset: startCharOffset, - endCharOffset: endCharOffset, - charOffset: charOffset, + startOffset: startOffset, + endOffset: endOffset, + nameOffset: nameOffset, formalsOffset: formalsOffset, modifiers: modifiers, inConstructor: inConstructor, @@ -2375,19 +2380,19 @@ class OutlineBuilder extends StackListenerImpl { modifiers |= Modifiers.Abstract; } - int startCharOffset = beginToken.charOffset; - int charEndOffset = endToken.charOffset; + int startOffset = metadata?.first.atOffset ?? beginToken.charOffset; + int endOffset = endToken.charOffset; _builderFactory.addNamedMixinApplication( - metadata, - identifier.name, - typeVariables, - modifiers, - supertype as TypeBuilder?, - mixinApplication, - interfaces, - startCharOffset, - identifier.nameOffset, - charEndOffset); + metadata: metadata, + name: identifier.name, + typeVariables: typeVariables, + modifiers: modifiers, + supertype: supertype as TypeBuilder?, + mixinApplication: mixinApplication, + interfaces: interfaces, + startOffset: startOffset, + nameOffset: identifier.nameOffset, + endOffset: endOffset); } popDeclarationContext(DeclarationContext.NamedMixinApplication); } @@ -2656,13 +2661,13 @@ class OutlineBuilder extends StackListenerImpl { !formals[0].isWildcard) { addProblem( templateDuplicatedParameterName.withArguments(formals[1].name), - formals[1].charOffset, + formals[1].fileOffset, formals[1].name.length, context: [ templateDuplicatedParameterNameCause .withArguments(formals[1].name) .withLocation( - uri, formals[0].charOffset, formals[0].name.length) + uri, formals[0].fileOffset, formals[0].name.length) ]); } } else if (formals.length > 2) { @@ -2677,12 +2682,12 @@ class OutlineBuilder extends StackListenerImpl { // Coverage-ignore-block(suite): Not run. addProblem( templateDuplicatedParameterName.withArguments(formal.name), - formal.charOffset, + formal.fileOffset, formal.name.length, context: [ templateDuplicatedParameterNameCause .withArguments(formal.name) - .withLocation(uri, seenNames[formal.name]!.charOffset, + .withLocation(uri, seenNames[formal.name]!.fileOffset, seenNames[formal.name]!.name.length) ]); } else { @@ -2709,7 +2714,7 @@ class OutlineBuilder extends StackListenerImpl { if (formal.isSuperInitializingFormal) { _compilationUnit.addProblem( messageExtensionTypeConstructorWithSuperFormalParameter, - formal.charOffset, + formal.fileOffset, formal.name.length, formal.fileUri); } @@ -2809,7 +2814,6 @@ class OutlineBuilder extends StackListenerImpl { push(mixins ?? NullValues.MixinApplicationBuilder); push(interfaces ?? NullValues.TypeBuilderList); - push(enumKeyword.charOffset); // start char offset. push(leftBrace.endGroup!.charOffset); // end char offset. } @@ -2833,7 +2837,6 @@ class OutlineBuilder extends StackListenerImpl { /* enum constants */ ...repeatedKind( ValueKinds.EnumConstantInfoOrNull, elementsCount), /* endCharOffset */ ValueKinds.Integer, - /* startCharOffset */ ValueKinds.Integer, /* interfaces */ ValueKinds.TypeBuilderListOrNull, /* mixins */ unionOfKinds([ ValueKinds.MixinApplicationBuilderOrNull, @@ -2868,8 +2871,8 @@ class OutlineBuilder extends StackListenerImpl { } } - int endCharOffset = popCharOffset(); - int startCharOffset = popCharOffset(); + int endOffset = popCharOffset(); + List? interfaces = nullIfParserRecovery(pop()) as List?; MixinApplicationBuilder? mixinBuilder = @@ -2878,8 +2881,9 @@ class OutlineBuilder extends StackListenerImpl { pop() as List?; Object? identifier = pop(); List? metadata = pop() as List?; - checkEmpty(startCharOffset); + checkEmpty(beginToken.charOffset); + int startOffset = metadata?.first.atOffset ?? beginToken.charOffset; if (identifier is Identifier) { if (enumConstantInfos == null) { if (!leftBrace.isSynthetic) { @@ -2894,7 +2898,7 @@ class OutlineBuilder extends StackListenerImpl { _compilationUnit.addProblem( templateNullableInterfaceError .withArguments(interface.fullNameForErrors), - interface.charOffset ?? startCharOffset, + interface.charOffset ?? startOffset, identifier.name.length, uri); } @@ -2902,15 +2906,15 @@ class OutlineBuilder extends StackListenerImpl { } _builderFactory.addEnum( - _offsetMap, - metadata, - identifier, - typeVariables, - mixinBuilder, - interfaces, - enumConstantInfos, - startCharOffset, - endCharOffset); + offsetMap: _offsetMap, + metadata: metadata, + identifier: identifier, + typeVariables: typeVariables, + supertypeBuilder: mixinBuilder, + interfaceBuilders: interfaces, + enumConstantInfos: enumConstantInfos, + startOffset: startOffset, + endOffset: endOffset); } else { _builderFactory.endEnumDeclarationForParserRecovery(typeVariables); } @@ -3623,19 +3627,18 @@ class OutlineBuilder extends StackListenerImpl { _builderFactory.endFactoryMethodForParserRecovery(); } else { _builderFactory.addFactoryMethod( - _offsetMap, - metadata, - modifiers, - name, - formals, - redirectionTarget, - beginToken.charOffset, - name.qualifierOffset, - formalsOffset, - endToken.charOffset, - nativeMethodName, - asyncModifier, - ); + offsetMap: _offsetMap, + metadata: metadata, + modifiers: modifiers, + identifier: name, + formals: formals, + redirectionTarget: redirectionTarget, + startOffset: metadata?.first.atOffset ?? beginToken.charOffset, + nameOffset: name.qualifierOffset, + formalsOffset: formalsOffset, + endOffset: endToken.charOffset, + nativeMethodName: nativeMethodName, + asyncModifier: asyncModifier); } nativeMethodName = null; inConstructor = false; diff --git a/pkg/front_end/lib/src/source/source_builder_factory.dart b/pkg/front_end/lib/src/source/source_builder_factory.dart index ad76e9ea2e13..d10765874db5 100644 --- a/pkg/front_end/lib/src/source/source_builder_factory.dart +++ b/pkg/front_end/lib/src/source/source_builder_factory.dart @@ -161,12 +161,12 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { } @override - void beginClassDeclaration(String name, int charOffset, + void beginClassDeclaration(String name, int nameOffset, List? typeVariables) { _declarationFragments.push(new ClassFragment( name, _compilationUnit.fileUri, - charOffset, + nameOffset, typeVariables, _typeScopes.current.lookupScope, _nominalParameterNameSpaces.current)); @@ -206,12 +206,12 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { } @override - void beginMixinDeclaration(String name, int charOffset, + void beginMixinDeclaration(String name, int nameOffset, List? typeVariables) { _declarationFragments.push(new MixinFragment( name, _compilationUnit.fileUri, - charOffset, + nameOffset, typeVariables, _typeScopes.current.lookupScope, _nominalParameterNameSpaces.current)); @@ -286,12 +286,12 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { } @override - void beginEnumDeclaration(String name, int charOffset, + void beginEnumDeclaration(String name, int nameOffset, List? typeVariables) { _declarationFragments.push(new EnumFragment( name, _compilationUnit.fileUri, - charOffset, + nameOffset, typeVariables, _typeScopes.current.lookupScope, _nominalParameterNameSpaces.current)); @@ -375,12 +375,12 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { } @override - void beginExtensionTypeDeclaration(String name, int charOffset, + void beginExtensionTypeDeclaration(String name, int nameOffset, List? typeVariables) { _declarationFragments.push(new ExtensionTypeFragment( name, _compilationUnit.fileUri, - charOffset, + nameOffset, typeVariables, _typeScopes.current.lookupScope, _nominalParameterNameSpaces.current)); @@ -824,18 +824,18 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { @override void addClass( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - Identifier identifier, - List? typeVariables, - TypeBuilder? supertype, - MixinApplicationBuilder? mixins, - List? interfaces, - int startOffset, - int nameOffset, - int endOffset, - int supertypeOffset) { + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required Identifier identifier, + required List? typeVariables, + required TypeBuilder? supertype, + required MixinApplicationBuilder? mixins, + required List? interfaces, + required int startOffset, + required int nameOffset, + required int endOffset, + required int supertypeOffset}) { String className = identifier.name; endClassDeclaration(className); @@ -861,7 +861,6 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { declarationFragment.constructorReferences = new List.of(_constructorReferences); declarationFragment.startOffset = startOffset; - declarationFragment.charOffset = nameOffset; declarationFragment.endOffset = endOffset; _constructorReferences.clear(); @@ -872,17 +871,16 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { @override void addEnum( - OffsetMap offsetMap, - List? metadata, - Identifier identifier, - List? typeVariables, - MixinApplicationBuilder? supertypeBuilder, - List? interfaceBuilders, - List? enumConstantInfos, - int startCharOffset, - int charEndOffset) { + {required OffsetMap offsetMap, + required List? metadata, + required Identifier identifier, + required List? typeVariables, + required MixinApplicationBuilder? supertypeBuilder, + required List? interfaceBuilders, + required List? enumConstantInfos, + required int startOffset, + required int endOffset}) { String name = identifier.name; - int charOffset = identifier.nameOffset; // Nested declaration began in `OutlineBuilder.beginEnum`. endEnumDeclaration(name); @@ -902,9 +900,8 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { declarationFragment.enumConstantInfos = enumConstantInfos; declarationFragment.constructorReferences = new List.of(_constructorReferences); - declarationFragment.startCharOffset = startCharOffset; - declarationFragment.charOffset = charOffset; - declarationFragment.charEndOffset = charEndOffset; + declarationFragment.startOffset = startOffset; + declarationFragment.endOffset = endOffset; _constructorReferences.clear(); @@ -915,17 +912,16 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { @override void addMixinDeclaration( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - Identifier identifier, - List? typeVariables, - List? supertypeConstraints, - List? interfaces, - int startOffset, - int nameOffset, - int endOffset, - int supertypeOffset) { + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required Identifier identifier, + required List? typeVariables, + required List? supertypeConstraints, + required List? interfaces, + required int startOffset, + required int nameOffset, + required int endOffset}) { TypeBuilder? supertype; MixinApplicationBuilder? mixinApplication; if (supertypeConstraints != null && supertypeConstraints.isNotEmpty) { @@ -963,7 +959,6 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { declarationFragment.constructorReferences = new List.of(_constructorReferences); declarationFragment.startOffset = startOffset; - declarationFragment.charOffset = nameOffset; declarationFragment.endOffset = endOffset; _constructorReferences.clear(); @@ -982,16 +977,16 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { @override void addNamedMixinApplication( - List? metadata, - String name, - List? typeVariables, - Modifiers modifiers, - TypeBuilder? supertype, - MixinApplicationBuilder mixinApplication, - List? interfaces, - int startCharOffset, - int charOffset, - int charEndOffset) { + {required List? metadata, + required String name, + required List? typeVariables, + required Modifiers modifiers, + required TypeBuilder? supertype, + required MixinApplicationBuilder mixinApplication, + required List? interfaces, + required int startOffset, + required int nameOffset, + required int endOffset}) { // Nested declaration began in `OutlineBuilder.beginNamedMixinApplication`. endNamedMixinApplication(name); @@ -1005,9 +1000,9 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { _addFragment(new NamedMixinApplicationFragment( name: name, fileUri: _compilationUnit.fileUri, - startCharOffset: startCharOffset, - charOffset: charOffset, - charEndOffset: charEndOffset, + startOffset: startOffset, + nameOffset: nameOffset, + endOffset: endOffset, modifiers: modifiers, metadata: metadata, typeParameters: typeVariables, @@ -1023,9 +1018,9 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { required List unboundNominalVariables, required TypeBuilder? supertype, required MixinApplicationBuilder? mixinApplicationBuilder, - required int startCharOffset, - required int charOffset, - required int charEndOffset, + required int startOffset, + required int nameOffset, + required int endOffset, required String subclassName, required bool isMixinDeclaration, required IndexedLibrary? indexedLibrary, @@ -1045,10 +1040,10 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { // The following parameters should only be used when building a named // mixin application. if (metadata != null) { - unhandled("metadata", "unnamed mixin application", charOffset, fileUri); + unhandled("metadata", "unnamed mixin application", nameOffset, fileUri); } else if (interfaces != null) { unhandled( - "interfaces", "unnamed mixin application", charOffset, fileUri); + "interfaces", "unnamed mixin application", nameOffset, fileUri); } } if (mixinApplicationBuilder != null) { @@ -1179,7 +1174,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { typeVariable, const NullabilityBuilder.omitted(), fileUri: fileUri, - charOffset: charOffset, + charOffset: nameOffset, instanceTypeVariableAccess: InstanceTypeVariableAccessState.Allowed); applicationTypeArguments.add(applicationTypeArgument); @@ -1195,10 +1190,10 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { mixin, newToOldVariableMap, substitutionMap); } } - final int computedStartCharOffset = + final int computedStartOffset = !isNamedMixinApplication || metadata == null - ? startCharOffset - : metadata.first.charOffset; + ? startOffset + : metadata.first.atOffset; IndexedClass? referencesFromIndexedClass; if (indexedLibrary != null) { @@ -1211,41 +1206,40 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { DeclarationNameSpaceBuilder nameSpaceBuilder = new DeclarationNameSpaceBuilder.empty(); SourceClassBuilder application = new SourceClassBuilder( - isNamedMixinApplication ? metadata : null, - isNamedMixinApplication + metadata: isNamedMixinApplication ? metadata : null, + modifiers: isNamedMixinApplication ? modifiers | Modifiers.NamedMixinApplication : Modifiers.Abstract, - fullname, - applicationTypeVariables, - isMixinDeclaration ? null : supertype, - isNamedMixinApplication + name: fullname, + typeVariables: applicationTypeVariables, + supertypeBuilder: isMixinDeclaration ? null : supertype, + interfaceBuilders: isNamedMixinApplication ? interfaces : isMixinDeclaration ? [supertype!, mixin] : null, - null, - // No `on` clause types. - typeParameterScope, - nameSpaceBuilder, - enclosingLibraryBuilder, - [], - fileUri, - computedStartCharOffset, - charOffset, - charEndOffset, - referencesFromIndexedClass, + onTypes: null, + typeParameterScope: typeParameterScope, + nameSpaceBuilder: nameSpaceBuilder, + libraryBuilder: enclosingLibraryBuilder, + constructorReferences: [], + fileUri: fileUri, + startOffset: computedStartOffset, + nameOffset: nameOffset, + endOffset: endOffset, + indexedClass: referencesFromIndexedClass, mixedInTypeBuilder: isMixinDeclaration ? null : mixin); // TODO(ahe, kmillikin): Should always be true? // pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart can't // handle that :( application.cls.isAnonymousMixin = !isNamedMixinApplication; - addBuilder(fullname, application, charOffset, + addBuilder(fullname, application, nameOffset, getterReference: referencesFromIndexedClass?.reference); supertype = new NamedTypeBuilderImpl.fromTypeDeclarationBuilder( application, const NullabilityBuilder.omitted(), arguments: applicationTypeArguments, fileUri: fileUri, - charOffset: charOffset, + charOffset: nameOffset, instanceTypeVariableAccess: InstanceTypeVariableAccessState.Allowed); mixinApplications[application] = mixin; @@ -1258,16 +1252,16 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { @override void addExtensionDeclaration( - OffsetMap offsetMap, - Token beginToken, - List? metadata, - Modifiers modifiers, - Identifier? identifier, - List? typeVariables, - TypeBuilder type, - int startOffset, - int nameOffset, - int endOffset) { + {required OffsetMap offsetMap, + required Token beginToken, + required List? metadata, + required Modifiers modifiers, + required Identifier? identifier, + required List? typeVariables, + required TypeBuilder onType, + required int startOffset, + required int nameOrExtensionOffset, + required int endOffset}) { String? name = identifier?.name; // Nested declaration began in // `OutlineBuilder.beginExtensionDeclarationPrelude`. @@ -1283,9 +1277,9 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { declarationFragment.metadata = metadata; declarationFragment.modifiers = modifiers; - declarationFragment.onType = type; + declarationFragment.onType = onType; declarationFragment.startOffset = startOffset; - declarationFragment.nameOffset = nameOffset; + declarationFragment.nameOrExtensionOffset = nameOrExtensionOffset; declarationFragment.endOffset = endOffset; _constructorReferences.clear(); @@ -1302,14 +1296,14 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { @override void addExtensionTypeDeclaration( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - Identifier identifier, - List? typeVariables, - List? interfaces, - int startOffset, - int endOffset) { + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required Identifier identifier, + required List? typeVariables, + required List? interfaces, + required int startOffset, + required int endOffset}) { String name = identifier.name; // Nested declaration began in `OutlineBuilder.beginExtensionDeclaration`. endExtensionTypeDeclaration(name); @@ -1374,9 +1368,9 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { required List? formals, required List? typeVariables, required Token? beginInitializers, - required int startCharOffset, - required int endCharOffset, - required int charOffset, + required int startOffset, + required int endOffset, + required int nameOffset, required int formalsOffset, required Modifiers modifiers, required bool inConstructor, @@ -1450,7 +1444,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { } List synthesizedFormals = [ new FormalParameterBuilder(FormalParameterKind.requiredPositional, - Modifiers.Final, thisType, syntheticThisName, charOffset, + Modifiers.Final, thisType, syntheticThisName, nameOffset, fileUri: _compilationUnit.fileUri, isExtensionThis: true, hasImmediatelyDeclaredInitializer: false) @@ -1476,7 +1470,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { } TypeBuilder thisType = addNamedType( - new SyntheticTypeName(declarationFragment.name, charOffset), + new SyntheticTypeName(declarationFragment.name, nameOffset), const NullabilityBuilder.omitted(), declarationFragment.typeParameters != null ? new List.generate( @@ -1488,7 +1482,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { instanceTypeVariableAccess: InstanceTypeVariableAccessState.Allowed)) : null, - charOffset, + nameOffset, instanceTypeVariableAccess: InstanceTypeVariableAccessState.Allowed); @@ -1500,7 +1494,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { } List synthesizedFormals = [ new FormalParameterBuilder(FormalParameterKind.requiredPositional, - Modifiers.Final, thisType, syntheticThisName, charOffset, + Modifiers.Final, thisType, syntheticThisName, nameOffset, fileUri: _compilationUnit.fileUri, isExtensionThis: true, hasImmediatelyDeclaredInitializer: false) @@ -1520,18 +1514,18 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { computeAndValidateConstructorName(declarationFragment, identifier) ?? name; addConstructor( - offsetMap, - metadata, - modifiers, - identifier, - constructorName, - typeVariables, - formals, - startCharOffset, - charOffset, - formalsOffset, - endCharOffset, - nativeMethodName, + offsetMap: offsetMap, + metadata: metadata, + modifiers: modifiers, + identifier: identifier, + constructorName: constructorName, + typeVariables: typeVariables, + formals: formals, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, + nativeMethodName: nativeMethodName, beginInitializers: beginInitializers, forAbstractClassOrMixin: forAbstractClassOrMixin); } else { @@ -1539,59 +1533,59 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { case ProcedureKind.Method: case ProcedureKind.Operator: addMethod( - offsetMap, - metadata, - modifiers, - returnType, - identifier, - name, - typeVariables, - formals, - kind, - startCharOffset, - charOffset, - formalsOffset, - endCharOffset, - nativeMethodName, - asyncModifier, + offsetMap: offsetMap, + metadata: metadata, + modifiers: modifiers, + returnType: returnType, + identifier: identifier, + name: name, + typeVariables: typeVariables, + formals: formals, + kind: kind, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, + nativeMethodName: nativeMethodName, + asyncModifier: asyncModifier, isInstanceMember: !isStatic, isExtensionMember: isExtensionMember, isExtensionTypeMember: isExtensionTypeMember); case ProcedureKind.Getter: addGetter( - offsetMap, - metadata, - modifiers, - returnType, - identifier, - name, - typeVariables, - formals, - startCharOffset, - charOffset, - formalsOffset, - endCharOffset, - nativeMethodName, - asyncModifier, + offsetMap: offsetMap, + metadata: metadata, + modifiers: modifiers, + returnType: returnType, + identifier: identifier, + name: name, + typeVariables: typeVariables, + formals: formals, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, + nativeMethodName: nativeMethodName, + asyncModifier: asyncModifier, isInstanceMember: !isStatic, isExtensionMember: isExtensionMember, isExtensionTypeMember: isExtensionTypeMember); case ProcedureKind.Setter: addSetter( - offsetMap, - metadata, - modifiers, - returnType, - identifier, - name, - typeVariables, - formals, - startCharOffset, - charOffset, - formalsOffset, - endCharOffset, - nativeMethodName, - asyncModifier, + offsetMap: offsetMap, + metadata: metadata, + modifiers: modifiers, + returnType: returnType, + identifier: identifier, + name: name, + typeVariables: typeVariables, + formals: formals, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, + nativeMethodName: nativeMethodName, + asyncModifier: asyncModifier, isInstanceMember: !isStatic, isExtensionMember: isExtensionMember, isExtensionTypeMember: isExtensionTypeMember); @@ -1604,34 +1598,55 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { @override void addConstructor( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - Identifier identifier, - String constructorName, - List? typeVariables, - List? formals, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - String? nativeMethodName, - {Token? beginInitializers, + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required Identifier identifier, + required String constructorName, + required List? typeVariables, + required List? formals, + required int startOffset, + required int nameOffset, + required int formalsOffset, + required int endOffset, + required String? nativeMethodName, + required Token? beginInitializers, required bool forAbstractClassOrMixin}) { - ConstructorFragment fragment = _addConstructor( - metadata, - modifiers, - constructorName, - typeVariables, - formals, - startCharOffset, - charOffset, - charOpenParenOffset, - charEndOffset, - nativeMethodName, - beginInitializers: beginInitializers, + ConstructorFragment fragment = new ConstructorFragment( + name: constructorName, + fileUri: _compilationUnit.fileUri, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, + modifiers: modifiers - Modifiers.Abstract, + metadata: metadata, + returnType: addInferableType(), + typeParameters: typeVariables, + formals: formals, + nativeMethodName: nativeMethodName, forAbstractClassOrMixin: forAbstractClassOrMixin, - isConst: modifiers.isConst); + beginInitializers: modifiers.isConst || + libraryFeatures.superParameters.isEnabled + // const constructors will have their initializers compiled and + // written into the outline. In case of super-parameters language + // feature, the super initializers are required to infer the types + // of super parameters. + // TODO(johnniwinther): Avoid using a dummy token to ensure building + // of constant constructors in the outline phase. + ? (beginInitializers ?? new Token.eof(-1)) + : null); + + _nominalParameterNameSpaces.pop().addTypeVariables( + _problemReporting, typeVariables, + ownerName: constructorName, allowNameConflict: true); + _addFragment(fragment); + if (nativeMethodName != null) { + _addNativeConstructorFragment(fragment); + } + if (modifiers.isConst) { + _declarationFragments.current.declaresConstConstructor = true; + } offsetMap.registerConstructorFragment(identifier, fragment); } @@ -1641,7 +1656,9 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { required Token beginToken, required String constructorName, required List? formals, - required int charOffset, + required int startOffset, + required int? nameOffset, + required int formalsOffset, required bool isConst}) { beginConstructor(); endConstructor(); @@ -1655,7 +1672,9 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { PrimaryConstructorFragment fragment = new PrimaryConstructorFragment( name: constructorName, fileUri: _compilationUnit.fileUri, - charOffset: charOffset, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, modifiers: isConst ? Modifiers.Const : Modifiers.empty, returnType: addInferableType(), typeParameters: typeVariables, @@ -1700,72 +1719,20 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { /* hasInitializer = */ false)); } - ConstructorFragment _addConstructor( - List? metadata, - Modifiers modifiers, - String constructorName, - List? typeVariables, - List? formals, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - String? nativeMethodName, - {Token? beginInitializers, - required bool isConst, - required bool forAbstractClassOrMixin}) { - ConstructorFragment fragment = new ConstructorFragment( - name: constructorName, - fileUri: _compilationUnit.fileUri, - startCharOffset: startCharOffset, - charOffset: charOffset, - charOpenParenOffset: charOpenParenOffset, - charEndOffset: charEndOffset, - modifiers: modifiers - Modifiers.Abstract, - metadata: metadata, - returnType: addInferableType(), - typeParameters: typeVariables, - formals: formals, - nativeMethodName: nativeMethodName, - forAbstractClassOrMixin: forAbstractClassOrMixin, - beginInitializers: isConst || libraryFeatures.superParameters.isEnabled - - // const constructors will have their initializers compiled and - // written into the outline. In case of super-parameters language - // feature, the super initializers are required to infer the types - // of super parameters. - // TODO(johnniwinther): Avoid using a dummy token to ensure building - // of constant constructors in the outline phase. - ? (beginInitializers ?? new Token.eof(-1)) - : null); - - _nominalParameterNameSpaces.pop().addTypeVariables( - _problemReporting, typeVariables, - ownerName: constructorName, allowNameConflict: true); - _addFragment(fragment); - if (nativeMethodName != null) { - _addNativeConstructorFragment(fragment); - } - if (isConst) { - _declarationFragments.current.declaresConstConstructor = true; - } - return fragment; - } - @override void addFactoryMethod( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - Identifier identifier, - List? formals, - ConstructorReferenceBuilder? redirectionTarget, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - String? nativeMethodName, - AsyncMarker asyncModifier) { + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required Identifier identifier, + required List? formals, + required ConstructorReferenceBuilder? redirectionTarget, + required int startOffset, + required int nameOffset, + required int formalsOffset, + required int endOffset, + required String? nativeMethodName, + required AsyncMarker asyncModifier}) { TypeBuilder returnType; List? returnTypeArguments; DeclarationFragment enclosingDeclaration = _declarationFragments.current; @@ -1777,13 +1744,13 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { name, const NullabilityBuilder.omitted(), messageExtensionDeclaresConstructor.withLocation( - _compilationUnit.fileUri, charOffset, name.length)); + _compilationUnit.fileUri, nameOffset, name.length)); } else { returnType = addNamedType( - new SyntheticTypeName(enclosingDeclaration.name, charOffset), + new SyntheticTypeName(enclosingDeclaration.name, nameOffset), const NullabilityBuilder.omitted(), returnTypeArguments = [], - charOffset, + nameOffset, instanceTypeVariableAccess: InstanceTypeVariableAccessState.Allowed); } @@ -1806,10 +1773,10 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { FactoryFragment fragment = new FactoryFragment( name: procedureName, fileUri: _compilationUnit.fileUri, - startCharOffset: startCharOffset, - charOffset: charOffset, - charOpenParenOffset: charOpenParenOffset, - charEndOffset: charEndOffset, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, modifiers: modifiers | Modifiers.Static, metadata: metadata, returnType: returnType, @@ -1822,10 +1789,10 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { if (returnTypeArguments != null && typeVariables != null) { for (TypeVariableBuilder typeVariable in typeVariables) { returnTypeArguments.add(addNamedType( - new SyntheticTypeName(typeVariable.name, charOffset), + new SyntheticTypeName(typeVariable.name, nameOffset), const NullabilityBuilder.omitted(), null, - charOffset, + nameOffset, instanceTypeVariableAccess: InstanceTypeVariableAccessState.Allowed)); } @@ -1955,21 +1922,21 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { @override void addGetter( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - TypeBuilder? returnType, - Identifier identifier, - String name, - List? typeVariables, - List? formals, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - String? nativeMethodName, - AsyncMarker asyncModifier, - {required bool isInstanceMember, + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required TypeBuilder? returnType, + required Identifier identifier, + required String name, + required List? typeVariables, + required List? formals, + required int startOffset, + required int nameOffset, + required int formalsOffset, + required int endOffset, + required String? nativeMethodName, + required AsyncMarker asyncModifier, + required bool isInstanceMember, required bool isExtensionMember, required bool isExtensionTypeMember}) { DeclarationFragment? enclosingDeclaration = @@ -1984,10 +1951,10 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { GetterFragment fragment = new GetterFragment( name: name, fileUri: _compilationUnit.fileUri, - startCharOffset: startCharOffset, - charOffset: charOffset, - charOpenParenOffset: charOpenParenOffset, - charEndOffset: charEndOffset, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, isTopLevel: enclosingDeclaration == null, metadata: metadata, modifiers: modifiers, @@ -2008,21 +1975,21 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { @override void addSetter( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - TypeBuilder? returnType, - Identifier identifier, - String name, - List? typeVariables, - List? formals, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - String? nativeMethodName, - AsyncMarker asyncModifier, - {required bool isInstanceMember, + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required TypeBuilder? returnType, + required Identifier identifier, + required String name, + required List? typeVariables, + required List? formals, + required int startOffset, + required int nameOffset, + required int formalsOffset, + required int endOffset, + required String? nativeMethodName, + required AsyncMarker asyncModifier, + required bool isInstanceMember, required bool isExtensionMember, required bool isExtensionTypeMember}) { DeclarationFragment? enclosingDeclaration = @@ -2035,16 +2002,16 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { DeclarationFragmentKind.extensionTypeDeclaration); if (returnType == null) { - returnType = addVoidType(charOffset); + returnType = addVoidType(nameOffset); } SetterFragment fragment = new SetterFragment( name: name, fileUri: _compilationUnit.fileUri, - startCharOffset: startCharOffset, - charOffset: charOffset, - charOpenParenOffset: charOpenParenOffset, - charEndOffset: charEndOffset, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, isTopLevel: enclosingDeclaration == null, metadata: metadata, modifiers: modifiers, @@ -2065,22 +2032,22 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { @override void addMethod( - OffsetMap offsetMap, - List? metadata, - Modifiers modifiers, - TypeBuilder? returnType, - Identifier identifier, - String name, - List? typeVariables, - List? formals, - ProcedureKind kind, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - String? nativeMethodName, - AsyncMarker asyncModifier, - {required bool isInstanceMember, + {required OffsetMap offsetMap, + required List? metadata, + required Modifiers modifiers, + required TypeBuilder? returnType, + required Identifier identifier, + required String name, + required List? typeVariables, + required List? formals, + required ProcedureKind kind, + required int startOffset, + required int nameOffset, + required int formalsOffset, + required int endOffset, + required String? nativeMethodName, + required AsyncMarker asyncModifier, + required bool isInstanceMember, required bool isExtensionMember, required bool isExtensionTypeMember}) { DeclarationFragment? enclosingDeclaration = @@ -2095,20 +2062,20 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { if (returnType == null) { if (kind == ProcedureKind.Operator && identical(name, indexSetName.text)) { - returnType = addVoidType(charOffset); + returnType = addVoidType(nameOffset); } else if (kind == ProcedureKind.Setter) { // Coverage-ignore-block(suite): Not run. - returnType = addVoidType(charOffset); + returnType = addVoidType(nameOffset); } } MethodFragment fragment = new MethodFragment( name: name, fileUri: _compilationUnit.fileUri, - startCharOffset: startCharOffset, - charOffset: charOffset, - charOpenParenOffset: charOpenParenOffset, - charEndOffset: charEndOffset, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, isTopLevel: enclosingDeclaration == null, metadata: metadata, modifiers: modifiers, @@ -2285,7 +2252,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { if (!libraryFeatures.genericMetadata.isEnabled) { _problemReporting.addProblem( messageAnnotationOnFunctionTypeTypeVariable, - builder.charOffset, + builder.fileOffset, builder.name.length, builder.fileUri); } @@ -2309,11 +2276,11 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { if (existing != null) { // Coverage-ignore-block(suite): Not run. _problemReporting.addProblem(messageTypeVariableDuplicatedName, - tv.charOffset, tv.name.length, _compilationUnit.fileUri, + tv.fileOffset, tv.name.length, _compilationUnit.fileUri, context: [ templateTypeVariableDuplicatedNameCause .withArguments(tv.name) - .withLocation(_compilationUnit.fileUri, existing.charOffset, + .withLocation(_compilationUnit.fileUri, existing.fileOffset, existing.name.length) ]); } else { @@ -2393,7 +2360,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult { []; for (NominalVariableBuilder oldVariable in oldVariableBuilders) { NominalVariableBuilder newVariable = new NominalVariableBuilder( - oldVariable.name, oldVariable.charOffset, oldVariable.fileUri, + oldVariable.name, oldVariable.fileOffset, oldVariable.fileUri, kind: kind, variableVariance: oldVariable.parameter.isLegacyCovariant ? null diff --git a/pkg/front_end/lib/src/source/source_builder_mixins.dart b/pkg/front_end/lib/src/source/source_builder_mixins.dart index b6ec523a3fe6..df11caaf37ff 100644 --- a/pkg/front_end/lib/src/source/source_builder_mixins.dart +++ b/pkg/front_end/lib/src/source/source_builder_mixins.dart @@ -71,17 +71,17 @@ mixin SourceDeclarationBuilderMixin // type declarations. templateExtensionMemberConflictsWithObjectMember .withArguments(name), - declaration.charOffset, + declaration.fileOffset, name.length); } if (declaration.parent != this) { // Coverage-ignore-block(suite): Not run. if (fileUri != declaration.parent!.fileUri) { - unexpected("$fileUri", "${declaration.parent!.fileUri}", charOffset, + unexpected("$fileUri", "${declaration.parent!.fileUri}", fileOffset, fileUri); } else { unexpected(fullNameForErrors, declaration.parent!.fullNameForErrors, - charOffset, fileUri); + fileOffset, fileUri); } } else if (declaration is SourceMemberBuilder) { SourceMemberBuilder memberBuilder = declaration; @@ -94,7 +94,7 @@ mixin SourceDeclarationBuilderMixin }); } else { unhandled("${declaration.runtimeType}", "buildBuilders", - declaration.charOffset, declaration.fileUri); + declaration.fileOffset, declaration.fileUri); } } @@ -300,17 +300,17 @@ mixin SourceTypedDeclarationBuilderMixin implements IDeclarationBuilder { // TODO(ahe): Revisit these messages. It seems like the last two should // be `context` parameter to this message. addProblem(templateConflictsWithMember.withArguments(name), - constructor.charOffset, noLength); + constructor.fileOffset, noLength); if (constructor.isFactory) { addProblem( templateConflictsWithFactory.withArguments("${this.name}.${name}"), - member.charOffset, + member.fileOffset, noLength); } else { addProblem( templateConflictsWithConstructor .withArguments("${this.name}.${name}"), - member.charOffset, + member.fileOffset, noLength); } } @@ -320,9 +320,9 @@ mixin SourceTypedDeclarationBuilderMixin implements IDeclarationBuilder { if (constructor == null || !setter.isStatic) return; // Coverage-ignore-block(suite): Not run. addProblem(templateConflictsWithConstructor.withArguments(name), - setter.charOffset, noLength); + setter.fileOffset, noLength); addProblem(templateConflictsWithSetter.withArguments(name), - constructor.charOffset, noLength); + constructor.fileOffset, noLength); }); } } diff --git a/pkg/front_end/lib/src/source/source_class_builder.dart b/pkg/front_end/lib/src/source/source_class_builder.dart index c0c8ded38af0..64197d353370 100644 --- a/pkg/front_end/lib/src/source/source_class_builder.dart +++ b/pkg/front_end/lib/src/source/source_class_builder.dart @@ -58,9 +58,9 @@ Class initializeClass( List? typeVariables, String name, Uri fileUri, - int startCharOffset, - int charOffset, - int charEndOffset, + int startOffset, + int nameOffset, + int endOffset, IndexedClass? indexedClass, {required bool isAugmentation}) { Class cls = new Class( @@ -74,13 +74,13 @@ Class initializeClass( reference: isAugmentation ? null : indexedClass?.reference, fileUri: fileUri); if (cls.startFileOffset == TreeNode.noOffset) { - cls.startFileOffset = startCharOffset; + cls.startFileOffset = startOffset; } if (cls.fileOffset == TreeNode.noOffset) { - cls.fileOffset = charOffset; + cls.fileOffset = nameOffset; } if (cls.fileEndOffset == TreeNode.noOffset) { - cls.fileEndOffset = charEndOffset; + cls.fileEndOffset = endOffset; } return cls; @@ -93,10 +93,9 @@ class SourceClassBuilder extends ClassBuilderImpl ClassDeclaration, SourceDeclarationBuilder { @override - final SourceLibraryBuilder parent; + final SourceLibraryBuilder libraryBuilder; - @override - final int charOffset; + final int nameOffset; @override final String name; @@ -163,31 +162,34 @@ class SourceClassBuilder extends ClassBuilderImpl MergedClassMemberScope? _mergedScope; SourceClassBuilder( - this.metadata, - this._modifiers, - this.name, - this.typeVariables, - this.supertypeBuilder, - this.interfaceBuilders, - this.onTypes, - this.typeParameterScope, - this.nameSpaceBuilder, - this.parent, - this.constructorReferences, - this.fileUri, - int startCharOffset, - int nameOffset, - int charEndOffset, + {required this.metadata, + required Modifiers modifiers, + required this.name, + required this.typeVariables, + required this.supertypeBuilder, + required this.interfaceBuilders, + required this.onTypes, + required this.typeParameterScope, + required this.nameSpaceBuilder, + required this.libraryBuilder, + required this.constructorReferences, + required this.fileUri, + required int startOffset, + required this.nameOffset, + required int endOffset, this.indexedClass, - {this.mixedInTypeBuilder, + this.mixedInTypeBuilder, this.isMixinDeclaration = false}) - : charOffset = nameOffset, - actualCls = initializeClass(typeVariables, name, fileUri, - startCharOffset, nameOffset, charEndOffset, indexedClass, - isAugmentation: _modifiers.isAugment) { + : _modifiers = modifiers, + actualCls = initializeClass(typeVariables, name, fileUri, startOffset, + nameOffset, endOffset, indexedClass, + isAugmentation: modifiers.isAugment) { actualCls.hasConstConstructor = declaresConstConstructor; } + @override + int get fileOffset => nameOffset; + @override bool get isAbstract => _modifiers.isAbstract; @@ -276,8 +278,7 @@ class SourceClassBuilder extends ClassBuilderImpl Class get cls => origin.actualCls; @override - SourceLibraryBuilder get libraryBuilder => - super.libraryBuilder as SourceLibraryBuilder; + SourceLibraryBuilder get parent => libraryBuilder; Class build(LibraryBuilder coreLibrary) { SourceLibraryBuilder.checkMemberConflicts(libraryBuilder, nameSpace, @@ -291,13 +292,13 @@ class SourceClassBuilder extends ClassBuilderImpl if (declaration.parent?.origin != origin) { // Coverage-ignore-block(suite): Not run. if (fileUri != declaration.parent?.fileUri) { - unexpected("$fileUri", "${declaration.parent?.fileUri}", charOffset, + unexpected("$fileUri", "${declaration.parent?.fileUri}", fileOffset, fileUri); } else { unexpected( fullNameForErrors, declaration.parent?.fullNameForErrors ?? '', - charOffset, + fileOffset, fileUri); } } @@ -314,7 +315,7 @@ class SourceClassBuilder extends ClassBuilderImpl }); } else { unhandled("${declaration.runtimeType}", "buildBuilders", - declaration.charOffset, declaration.fileUri); + declaration.fileOffset, declaration.fileUri); } } @@ -341,7 +342,7 @@ class SourceClassBuilder extends ClassBuilderImpl // and that is allowed to be a mixin's interface. libraryBuilder.addProblem( templateSupertypeIsIllegal.withArguments(actualCls.superclass!.name), - charOffset, + fileOffset, noLength, fileUri); supertype = null; @@ -640,8 +641,8 @@ class SourceClassBuilder extends ClassBuilderImpl if (originLength != augmentationLength) { // Coverage-ignore-block(suite): Not run. augmentation.addProblem(messagePatchClassTypeVariablesMismatch, - augmentation.charOffset, noLength, context: [ - messagePatchClassOrigin.withLocation(fileUri, charOffset, noLength) + augmentation.fileOffset, noLength, context: [ + messagePatchClassOrigin.withLocation(fileUri, fileOffset, noLength) ]); } else if (typeVariables != null) { int count = 0; @@ -652,9 +653,9 @@ class SourceClassBuilder extends ClassBuilderImpl } else { // Coverage-ignore-block(suite): Not run. libraryBuilder.addProblem(messagePatchDeclarationMismatch, - augmentation.charOffset, noLength, augmentation.fileUri, context: [ + augmentation.fileOffset, noLength, augmentation.fileUri, context: [ messagePatchDeclarationOrigin.withLocation( - fileUri, charOffset, noLength) + fileUri, fileOffset, noLength) ]); } } @@ -737,7 +738,7 @@ class SourceClassBuilder extends ClassBuilderImpl } if (!cls.isAbstract && !cls.isEnum && hasEnumSuperinterface) { addProblem(templateEnumSupertypeOfNonAbstractClass.withArguments(name), - charOffset, noLength); + fileOffset, noLength); } if (hasEnumSuperinterface && cls != underscoreEnumClass) { @@ -754,7 +755,7 @@ class SourceClassBuilder extends ClassBuilderImpl libraryBuilder.addProblem( templateEnumImplementerContainsValuesDeclaration .withArguments(this.name), - customValuesDeclaration!.charOffset, + customValuesDeclaration!.fileOffset, customValuesDeclaration.fullNameForErrors.length, fileUri); } @@ -770,7 +771,7 @@ class SourceClassBuilder extends ClassBuilderImpl libraryBuilder.addProblem( templateEnumImplementerContainsValuesDeclaration .withArguments(this.name), - customValuesDeclaration!.charOffset, + customValuesDeclaration!.fileOffset, customValuesDeclaration.fullNameForErrors.length, fileUri); } @@ -778,7 +779,7 @@ class SourceClassBuilder extends ClassBuilderImpl libraryBuilder.addProblem( templateInheritedRestrictedMemberOfEnumImplementer.withArguments( "values", superclassDeclaringConcreteValues.name), - charOffset, + fileOffset, noLength, fileUri); } @@ -792,7 +793,7 @@ class SourceClassBuilder extends ClassBuilderImpl libraryBuilder.addProblem( templateEnumImplementerContainsRestrictedInstanceDeclaration .withArguments(this.name, restrictedMemberName), - member.charOffset, + member.fileOffset, member.fullNameForErrors.length, fileUri); } @@ -805,7 +806,7 @@ class SourceClassBuilder extends ClassBuilderImpl templateInheritedRestrictedMemberOfEnumImplementer .withArguments(restrictedMemberName, restrictedNameMemberProvider.name), - charOffset, + fileOffset, noLength, fileUri); } @@ -830,7 +831,7 @@ class SourceClassBuilder extends ClassBuilderImpl } if (isMacroFound) { addProblem(templateMacroClassNotDeclaredMacro.withArguments(name), - charOffset, noLength); + fileOffset, noLength); } } @@ -842,7 +843,7 @@ class SourceClassBuilder extends ClassBuilderImpl // Coverage-ignore-block(suite): Not run. addProblem(message, nameOffset, nameLength, context: [ messageTypedefCause.withLocation( - aliasBuilder.fileUri, aliasBuilder.charOffset, noLength), + aliasBuilder.fileUri, aliasBuilder.fileOffset, noLength), ]); } else { addProblem(message, nameOffset, nameLength); @@ -882,7 +883,7 @@ class SourceClassBuilder extends ClassBuilderImpl addProblem( templateIllegalMixinDueToConstructors .withArguments(fullNameForErrors), - constructor.charOffset, + constructor.fileOffset, noLength); } } @@ -926,14 +927,14 @@ class SourceClassBuilder extends ClassBuilderImpl ClassBuilder interface = unaliasedDeclaration; if (superClass == interface) { addProblem(templateImplementsSuperClass.withArguments(interface.name), - this.charOffset, noLength); + this.fileOffset, noLength); } else if (interface.cls.name == "FutureOr" && // Coverage-ignore(suite): Not run. interface.cls.enclosingLibrary.importUri.isScheme("dart") && // Coverage-ignore(suite): Not run. interface.cls.enclosingLibrary.importUri.path == "async") { // Coverage-ignore-block(suite): Not run. - addProblem(messageImplementsFutureOr, this.charOffset, noLength); + addProblem(messageImplementsFutureOr, this.fileOffset, noLength); } else if (implemented.contains(interface)) { // Aggregate repetitions. problems ??= {}; @@ -1040,7 +1041,7 @@ class SourceClassBuilder extends ClassBuilderImpl variance.keyword, supertype.typeName!.name); } - libraryBuilder.addProblem(message, charOffset, noLength, fileUri); + libraryBuilder.addProblem(message, fileOffset, noLength, fileUri); } } if (message != null) { @@ -1048,13 +1049,13 @@ class SourceClassBuilder extends ClassBuilderImpl return new NamedTypeBuilderImpl( typeName, const NullabilityBuilder.omitted(), fileUri: fileUri, - charOffset: charOffset, + charOffset: fileOffset, instanceTypeVariableAccess: InstanceTypeVariableAccessState.Unexpected) ..bind( libraryBuilder, new InvalidTypeDeclarationBuilder(typeName.name, - message.withLocation(fileUri, charOffset, noLength))); + message.withLocation(fileUri, fileOffset, noLength))); } return supertype; } @@ -1066,14 +1067,14 @@ class SourceClassBuilder extends ClassBuilderImpl computeVariance(typeParameter, fieldBuilder.fieldType); if (fieldBuilder.isClassInstanceMember) { reportVariancePositionIfInvalid(fieldVariance, typeParameter, - fieldBuilder.fileUri, fieldBuilder.charOffset); + fieldBuilder.fileUri, fieldBuilder.fileOffset); } if (fieldBuilder.isClassInstanceMember && fieldBuilder.isAssignable && !fieldBuilder.isCovariantByDeclaration) { fieldVariance = Variance.contravariant.combine(fieldVariance); reportVariancePositionIfInvalid(fieldVariance, typeParameter, - fieldBuilder.fileUri, fieldBuilder.charOffset); + fieldBuilder.fileUri, fieldBuilder.fileOffset); } } } @@ -1288,7 +1289,7 @@ class SourceClassBuilder extends ClassBuilderImpl int compareTo(SourceClassBuilder other) { int result = "$fileUri".compareTo("${other.fileUri}"); if (result != 0) return result; - return charOffset.compareTo(other.charOffset); + return fileOffset.compareTo(other.fileOffset); } void _handleSeenCovariant( diff --git a/pkg/front_end/lib/src/source/source_compilation_unit.dart b/pkg/front_end/lib/src/source/source_compilation_unit.dart index c6959127d2d9..47baa2434c1b 100644 --- a/pkg/front_end/lib/src/source/source_compilation_unit.dart +++ b/pkg/front_end/lib/src/source/source_compilation_unit.dart @@ -959,7 +959,7 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit { void reportIssues(List issues) { for (NonSimplicityIssue issue in issues) { - addProblem(issue.message, issue.declaration.charOffset, + addProblem(issue.message, issue.declaration.fileOffset, issue.declaration.name.length, issue.declaration.fileUri, context: issue.context); } @@ -1144,7 +1144,7 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit { typeVariable.bound, typeVariableName: typeVariable.name, fileUri: typeVariable.fileUri, - charOffset: typeVariable.charOffset) || + charOffset: typeVariable.fileOffset) || hasReportedErrors; hasReportedErrors = _recursivelyReportGenericFunctionTypesAsBoundsForType( typeVariable.bound) || @@ -1179,7 +1179,7 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit { typeVariable.bound, typeVariableName: typeVariable.name, fileUri: typeVariable.fileUri, - charOffset: typeVariable.charOffset) || + charOffset: typeVariable.fileOffset) || hasReportedErrors; } } @@ -1304,9 +1304,9 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit { int? otherFileOffset; if (prefixFragment.deferred) { deferredFileOffset = prefixFragment.prefixOffset; - otherFileOffset = existing.charOffset; + otherFileOffset = existing.fileOffset; } else if (existing.deferred) { - deferredFileOffset = existing.charOffset; + deferredFileOffset = existing.fileOffset; otherFileOffset = prefixFragment.prefixOffset; } if (deferredFileOffset != null) { @@ -1334,7 +1334,7 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit { templateDuplicatedDeclarationCause .withArguments(fullName) .withLocation( - existing.fileUri!, existing.charOffset, fullName.length) + existing.fileUri!, existing.fileOffset, fullName.length) ]); } // TODO(johnniwinther): For enhanced parts, this should be the prefix name diff --git a/pkg/front_end/lib/src/source/source_constructor_builder.dart b/pkg/front_end/lib/src/source/source_constructor_builder.dart index 82046d03e432..bd6f94945801 100644 --- a/pkg/front_end/lib/src/source/source_constructor_builder.dart +++ b/pkg/front_end/lib/src/source/source_constructor_builder.dart @@ -134,7 +134,7 @@ abstract class AbstractSourceConstructorBuilder void inferFormalTypes(ClassHierarchyBase hierarchy) { if (_hasFormalsInferred) return; if (formals != null) { - libraryBuilder.loader.withUriForCrashReporting(fileUri, charOffset, () { + libraryBuilder.loader.withUriForCrashReporting(fileUri, fileOffset, () { for (FormalParameterBuilder formal in formals!) { if (formal.type is InferableTypeBuilder) { if (formal.isInitializingFormal) { @@ -399,7 +399,7 @@ class DeclaredSourceConstructorBuilder } @override - final int charOffset; + final int fileOffset; @override final Uri fileUri; @@ -420,10 +420,10 @@ class DeclaredSourceConstructorBuilder required this.libraryBuilder, required this.declarationBuilder, required this.fileUri, - required int startCharOffset, - required this.charOffset, - required int charOpenParenOffset, - required int charEndOffset, + required int startOffset, + required this.fileOffset, + required int formalsOffset, + required int endOffset, required Reference? constructorReference, required Reference? tearOffReference, required NameScheme nameScheme, @@ -435,15 +435,15 @@ class DeclaredSourceConstructorBuilder formals?.any((formal) => formal.isSuperInitializingFormal) ?? false, _memberName = nameScheme.getDeclaredName(name), super(metadata, modifiers, returnType, name, typeVariables, formals, - charOpenParenOffset, nativeMethodName, beginInitializers) { + formalsOffset, nativeMethodName, beginInitializers) { _constructor = new Constructor(new FunctionNode(null), name: dummyName, fileUri: fileUri, reference: constructorReference, isSynthetic: isSynthetic) - ..startFileOffset = startCharOffset - ..fileOffset = charOffset - ..fileEndOffset = charEndOffset; + ..startFileOffset = startOffset + ..fileOffset = fileOffset + ..fileEndOffset = endOffset; nameScheme .getConstructorMemberName(name, isTearOff: false) .attachMember(_constructor); @@ -451,7 +451,7 @@ class DeclaredSourceConstructorBuilder nameScheme.getConstructorMemberName(name, isTearOff: true), libraryBuilder, fileUri, - charOffset, + fileOffset, tearOffReference, forAbstractClassOrEnumOrMixin: forAbstractClassOrEnumOrMixin); } @@ -613,7 +613,7 @@ class DeclaredSourceConstructorBuilder superTarget = (initializers.last as SuperInitializer).target; } else { MemberBuilder? memberBuilder = superclassBuilder.constructorScope - .lookup("", charOffset, libraryBuilder.fileUri); + .lookup("", fileOffset, libraryBuilder.fileUri); if (memberBuilder is ConstructorBuilder) { superTarget = memberBuilder.invokeTarget; } else { @@ -627,7 +627,7 @@ class DeclaredSourceConstructorBuilder MemberBuilder? constructorBuilder = superclassBuilder.findConstructorOrFactory(superTarget.name.text, - charOffset, libraryBuilder.fileUri, libraryBuilder); + fileOffset, libraryBuilder.fileUri, libraryBuilder); if (constructorBuilder is ConstructorBuilder) { return constructorBuilder; } else { @@ -1063,7 +1063,7 @@ class SyntheticSourceConstructorBuilder extends MemberBuilderImpl @override // Coverage-ignore(suite): Not run. - int get charOffset => _constructor.fileOffset; + int get fileOffset => _constructor.fileOffset; @override // Coverage-ignore(suite): Not run. @@ -1232,7 +1232,7 @@ class SourceExtensionTypeConstructorBuilder DelayedDefaultValueCloner? _delayedDefaultValueCloner; @override - final int charOffset; + final int fileOffset; @override final Uri fileUri; @@ -1247,10 +1247,10 @@ class SourceExtensionTypeConstructorBuilder required this.libraryBuilder, required this.declarationBuilder, required this.fileUri, - required int startCharOffset, - required this.charOffset, - required int charOpenParenOffset, - required int charEndOffset, + required int startOffset, + required this.fileOffset, + required int formalsOffset, + required int endOffset, required Reference? constructorReference, required Reference? tearOffReference, required NameScheme nameScheme, @@ -1259,12 +1259,12 @@ class SourceExtensionTypeConstructorBuilder required Token? beginInitializers}) : _memberName = nameScheme.getDeclaredName(name), super(metadata, modifiers, returnType, name, typeVariables, formals, - charOpenParenOffset, nativeMethodName, beginInitializers) { + formalsOffset, nativeMethodName, beginInitializers) { _constructor = new Procedure( dummyName, ProcedureKind.Method, new FunctionNode(null), fileUri: fileUri, reference: constructorReference) - ..fileOffset = charOffset - ..fileEndOffset = charEndOffset; + ..fileOffset = fileOffset + ..fileEndOffset = endOffset; nameScheme .getConstructorMemberName(name, isTearOff: false) .attachMember(_constructor); @@ -1272,7 +1272,7 @@ class SourceExtensionTypeConstructorBuilder nameScheme.getConstructorMemberName(name, isTearOff: true), libraryBuilder, fileUri, - charOffset, + fileOffset, tearOffReference, forAbstractClassOrEnumOrMixin: forAbstractClassOrEnumOrMixin, forceCreateLowering: true) diff --git a/pkg/front_end/lib/src/source/source_enum_builder.dart b/pkg/front_end/lib/src/source/source_enum_builder.dart index 2e3d2824a3f1..bb9e287d701b 100644 --- a/pkg/front_end/lib/src/source/source_enum_builder.dart +++ b/pkg/front_end/lib/src/source/source_enum_builder.dart @@ -60,8 +60,8 @@ import 'source_procedure_builder.dart'; import 'type_parameter_scope_builder.dart'; class SourceEnumBuilder extends SourceClassBuilder { - final int startCharOffset; - final int charEndOffset; + final int startOffset; + final int endOffset; final List? enumConstantInfos; @@ -85,77 +85,76 @@ class SourceEnumBuilder extends SourceClassBuilder { new Set.identity(); SourceEnumBuilder.internal( - List? metadata, - String name, - List? typeVariables, - this._underscoreEnumTypeBuilder, - TypeBuilder supertypeBuilder, - List? interfaceBuilders, - LookupScope typeParameterScope, - DeclarationNameSpaceBuilder nameSpaceBuilder, - this.enumConstantInfos, - SourceLibraryBuilder parent, - List constructorReferences, - Uri fileUri, - this.startCharOffset, - int charOffset, - this.charEndOffset, - IndexedClass? referencesFromIndexed) - : super( - metadata, - Modifiers.empty, - name, - typeVariables, - supertypeBuilder, - interfaceBuilders, - /* onTypes = */ null, - typeParameterScope, - nameSpaceBuilder, - parent, - constructorReferences, - fileUri, - startCharOffset, - charOffset, - charEndOffset, - referencesFromIndexed); + {required List? metadata, + required String name, + required List? typeVariables, + required TypeBuilder underscoreEnumTypeBuilder, + required TypeBuilder supertypeBuilder, + required List? interfaceBuilders, + required LookupScope typeParameterScope, + required DeclarationNameSpaceBuilder nameSpaceBuilder, + required this.enumConstantInfos, + required SourceLibraryBuilder libraryBuilder, + required List constructorReferences, + required Uri fileUri, + required this.startOffset, + required int nameOffset, + required this.endOffset, + required IndexedClass? indexedClass}) + : _underscoreEnumTypeBuilder = underscoreEnumTypeBuilder, + super( + metadata: metadata, + modifiers: Modifiers.empty, + name: name, + typeVariables: typeVariables, + supertypeBuilder: supertypeBuilder, + interfaceBuilders: interfaceBuilders, + onTypes: null, + typeParameterScope: typeParameterScope, + nameSpaceBuilder: nameSpaceBuilder, + libraryBuilder: libraryBuilder, + constructorReferences: constructorReferences, + fileUri: fileUri, + startOffset: startOffset, + nameOffset: nameOffset, + endOffset: endOffset, + indexedClass: indexedClass); factory SourceEnumBuilder( - List? metadata, - String name, - List? typeVariables, - TypeBuilder underscoreEnumTypeBuilder, - TypeBuilder? supertypeBuilder, - List? interfaceBuilders, - List? enumConstantInfos, - SourceLibraryBuilder libraryBuilder, - List constructorReferences, - Uri fileUri, - int startCharOffset, - int charOffset, - int charEndOffset, - IndexedClass? referencesFromIndexed, - LookupScope typeParameterScope, - DeclarationNameSpaceBuilder nameSpaceBuilder) { - final int startCharOffsetComputed = - metadata == null ? startCharOffset : metadata.first.charOffset; + {required List? metadata, + required String name, + required List? typeVariables, + required TypeBuilder underscoreEnumTypeBuilder, + required TypeBuilder? supertypeBuilder, + required List? interfaceBuilders, + required List? enumConstantInfos, + required SourceLibraryBuilder libraryBuilder, + required List constructorReferences, + required Uri fileUri, + required int startOffset, + required int nameOffset, + required int endOffset, + required IndexedClass? indexedClass, + required LookupScope typeParameterScope, + required DeclarationNameSpaceBuilder nameSpaceBuilder}) { supertypeBuilder ??= underscoreEnumTypeBuilder; SourceEnumBuilder enumBuilder = new SourceEnumBuilder.internal( - metadata, - name, - typeVariables, - underscoreEnumTypeBuilder, - supertypeBuilder, - interfaceBuilders, - typeParameterScope, - nameSpaceBuilder, - enumConstantInfos, - libraryBuilder, - constructorReferences, - fileUri, - startCharOffsetComputed, - charOffset, - charEndOffset, - referencesFromIndexed); + metadata: metadata, + name: name, + typeVariables: typeVariables, + underscoreEnumTypeBuilder: underscoreEnumTypeBuilder, + supertypeBuilder: supertypeBuilder, + interfaceBuilders: interfaceBuilders, + typeParameterScope: typeParameterScope, + nameSpaceBuilder: nameSpaceBuilder, + enumConstantInfos: enumConstantInfos, + libraryBuilder: libraryBuilder, + constructorReferences: constructorReferences, + fileUri: fileUri, + startOffset: startOffset, + nameOffset: nameOffset, + endOffset: endOffset, + indexedClass: indexedClass); return enumBuilder; } @@ -174,14 +173,14 @@ class SourceEnumBuilder extends SourceClassBuilder { FormalParameterBuilder nameFormalParameterBuilder = new FormalParameterBuilder(FormalParameterKind.requiredPositional, - Modifiers.empty, stringType, "#name", charOffset, + Modifiers.empty, stringType, "#name", fileOffset, fileUri: fileUri, hasImmediatelyDeclaredInitializer: false); member.formals!.insert(0, nameFormalParameterBuilder); nameFormalParameterBuilder.parent = member; FormalParameterBuilder indexFormalParameterBuilder = new FormalParameterBuilder(FormalParameterKind.requiredPositional, - Modifiers.empty, intType, "#index", charOffset, + Modifiers.empty, intType, "#index", fileOffset, fileUri: fileUri, hasImmediatelyDeclaredInitializer: false); member.formals!.insert(0, indexFormalParameterBuilder); indexFormalParameterBuilder.parent = member; @@ -195,7 +194,7 @@ class SourceEnumBuilder extends SourceClassBuilder { MemberBuilder constructorBuilder = constructorIterator.current; if (!constructorBuilder.isFactory && !constructorBuilder.isConst) { libraryBuilder.addProblem(messageEnumNonConstConstructor, - constructorBuilder.charOffset, noLength, fileUri); + constructorBuilder.fileOffset, noLength, fileUri); } } } @@ -224,11 +223,11 @@ class SourceEnumBuilder extends SourceClassBuilder { objectType = new NamedTypeBuilderImpl( const PredefinedTypeName("Object"), const NullabilityBuilder.omitted(), instanceTypeVariableAccess: InstanceTypeVariableAccessState.Unexpected); - selfType = new NamedTypeBuilderImpl(new SyntheticTypeName(name, charOffset), + selfType = new NamedTypeBuilderImpl(new SyntheticTypeName(name, fileOffset), const NullabilityBuilder.omitted(), instanceTypeVariableAccess: InstanceTypeVariableAccessState.Unexpected, fileUri: fileUri, - charOffset: charOffset); + charOffset: fileOffset); listType = new NamedTypeBuilderImpl( const PredefinedTypeName("List"), const NullabilityBuilder.omitted(), arguments: [selfType], @@ -283,7 +282,7 @@ class SourceEnumBuilder extends SourceClassBuilder { } libraryBuilder.addProblem( messageEnumContainsValuesDeclaration, - customValuesDeclaration!.charOffset, + customValuesDeclaration!.fileOffset, customValuesDeclaration.fullNameForErrors.length, fileUri); } @@ -305,7 +304,7 @@ class SourceEnumBuilder extends SourceClassBuilder { libraryBuilder.addProblem( templateEnumContainsRestrictedInstanceDeclaration .withArguments(restrictedInstanceMemberName), - customIndexDeclaration!.charOffset, + customIndexDeclaration!.fileOffset, customIndexDeclaration.fullNameForErrors.length, fileUri); } @@ -320,8 +319,8 @@ class SourceEnumBuilder extends SourceClassBuilder { libraryBuilder, this, fileUri, - charOffset, - charOffset, + fileOffset, + fileOffset, staticFieldNameScheme, fieldReference: valuesFieldReference, fieldGetterReference: valuesGetterReference, @@ -361,10 +360,10 @@ class SourceEnumBuilder extends SourceClassBuilder { libraryBuilder: libraryBuilder, declarationBuilder: this, fileUri: fileUri, - startCharOffset: charOffset, - charOffset: charOffset, - charOpenParenOffset: charOffset, - charEndOffset: charEndOffset, + startOffset: fileOffset, + fileOffset: fileOffset, + formalsOffset: fileOffset, + endOffset: endOffset, constructorReference: constructorReference, tearOffReference: tearOffReference, nameScheme: new NameScheme( @@ -389,24 +388,24 @@ class SourceEnumBuilder extends SourceClassBuilder { } ProcedureBuilder toStringBuilder = new SourceProcedureBuilder( - /* metadata = */ null, - Modifiers.empty, - stringType, - "_enumToString", - /* typeVariables = */ null, - /* formals = */ null, - ProcedureKind.Method, - libraryBuilder, - this, - fileUri, - charOffset, - charOffset, - charOffset, - charEndOffset, - toStringReference, - /* tearOffReference = */ null, - AsyncMarker.Sync, - new NameScheme( + metadata: null, + modifiers: Modifiers.empty, + returnType: stringType, + name: "_enumToString", + typeVariables: null, + formals: null, + kind: ProcedureKind.Method, + libraryBuilder: libraryBuilder, + declarationBuilder: this, + fileUri: fileUri, + startOffset: fileOffset, + nameOffset: fileOffset, + formalsOffset: fileOffset, + endOffset: endOffset, + procedureReference: toStringReference, + tearOffReference: null, + asyncModifier: AsyncMarker.Sync, + nameScheme: new NameScheme( isInstanceMember: true, containerName: new ClassName(name), containerType: ContainerType.Class, @@ -428,17 +427,17 @@ class SourceEnumBuilder extends SourceClassBuilder { if (existing != null) { // The existing declaration is synthetic if it has the same // charOffset as the enclosing enum. - bool isSynthetic = existing.charOffset == charOffset; + bool isSynthetic = existing.fileOffset == fileOffset; // Report the error on the member that occurs later in the code. int existingOffset; int duplicateOffset; - if (existing.charOffset < enumConstantInfo.charOffset) { - existingOffset = existing.charOffset; + if (existing.fileOffset < enumConstantInfo.charOffset) { + existingOffset = existing.fileOffset; duplicateOffset = enumConstantInfo.charOffset; } else { existingOffset = enumConstantInfo.charOffset; - duplicateOffset = existing.charOffset; + duplicateOffset = existing.fileOffset; } List context = isSynthetic @@ -446,7 +445,7 @@ class SourceEnumBuilder extends SourceClassBuilder { templateDuplicatedDeclarationSyntheticCause .withArguments(name) .withLocation( - libraryBuilder.fileUri, charOffset, className.length) + libraryBuilder.fileUri, fileOffset, className.length) ] : [ templateDuplicatedDeclarationCause @@ -506,7 +505,7 @@ class SourceEnumBuilder extends SourceClassBuilder { if (name == "values") { libraryBuilder.addProblem( - messageEnumWithNameValues, this.charOffset, name.length, fileUri); + messageEnumWithNameValues, this.fileOffset, name.length, fileUri); } } @@ -518,12 +517,12 @@ class SourceEnumBuilder extends SourceClassBuilder { @override Class build(LibraryBuilder coreLibrary) { - intType.resolveIn(coreLibrary.scope, charOffset, fileUri, libraryBuilder); + intType.resolveIn(coreLibrary.scope, fileOffset, fileUri, libraryBuilder); stringType.resolveIn( - coreLibrary.scope, charOffset, fileUri, libraryBuilder); + coreLibrary.scope, fileOffset, fileUri, libraryBuilder); objectType.resolveIn( - coreLibrary.scope, charOffset, fileUri, libraryBuilder); - listType.resolveIn(coreLibrary.scope, charOffset, fileUri, libraryBuilder); + coreLibrary.scope, fileOffset, fileUri, libraryBuilder); + listType.resolveIn(coreLibrary.scope, fileOffset, fileUri, libraryBuilder); Class cls = super.build(coreLibrary); cls.isEnum = true; @@ -542,7 +541,7 @@ class SourceEnumBuilder extends SourceClassBuilder { ClassBuilder enumClass = _underscoreEnumTypeBuilder.declaration as ClassBuilder; MemberBuilder? superConstructor = enumClass.findConstructorOrFactory( - "", charOffset, fileUri, libraryBuilder); + "", fileOffset, fileUri, libraryBuilder); if (superConstructor == null || !superConstructor.isConstructor) { // Coverage-ignore-block(suite): Not run. // TODO(ahe): Ideally, we would also want to check that [Object]'s @@ -553,7 +552,7 @@ class SourceEnumBuilder extends SourceClassBuilder { // Object here.) libraryBuilder.addProblem( messageNoUnnamedConstructorInObject, - objectClass.charOffset, + objectClass.fileOffset, objectClass.name.length, objectClass.fileUri); } else { @@ -685,7 +684,7 @@ class SourceEnumBuilder extends SourceClassBuilder { Expression initializer = bodyBuilder.buildStaticInvocation( constructorBuilder.invokeTarget, arguments, constness: Constness.explicitConst, - charOffset: fieldBuilder.charOffset, + charOffset: fieldBuilder.fileOffset, isConstructorInvocation: true); ExpressionInferenceResult inferenceResult = bodyBuilder.typeInferrer .inferFieldInitializer( @@ -713,14 +712,14 @@ class SourceEnumBuilder extends SourceClassBuilder { Severity.error) .plain; if (!fieldBuilder.hasBodyBeenBuilt) { - fieldBuilder.buildBody( - coreTypes, new InvalidExpression(text)..fileOffset = charOffset); + fieldBuilder.buildBody(coreTypes, + new InvalidExpression(text)..fileOffset = this.fileOffset); } } else { Expression initializer = new ConstructorInvocation( constructorBuilder.invokeTarget as Constructor, arguments, isConst: true) - ..fileOffset = fieldBuilder.charOffset; + ..fileOffset = fieldBuilder.fileOffset; if (!fieldBuilder.hasBodyBeenBuilt) { fieldBuilder.buildBody(coreTypes, initializer); } diff --git a/pkg/front_end/lib/src/source/source_extension_builder.dart b/pkg/front_end/lib/src/source/source_extension_builder.dart index 2c2bdfe68f80..9acc683e2952 100644 --- a/pkg/front_end/lib/src/source/source_extension_builder.dart +++ b/pkg/front_end/lib/src/source/source_extension_builder.dart @@ -113,7 +113,7 @@ class SourceExtensionBuilder extends ExtensionBuilderImpl Iterable? get metadata => _introductory.metadata; @override - int get charOffset => _nameOffset; + int get fileOffset => _nameOffset; @override String get name => extensionName.name; @@ -239,7 +239,7 @@ class SourceExtensionBuilder extends ExtensionBuilderImpl void addMemberInternal(SourceMemberBuilder memberBuilder, BuiltMemberKind memberKind, Member member, Member? tearOff) { unhandled("${memberBuilder.runtimeType}:${memberKind}", "addMemberInternal", - memberBuilder.charOffset, memberBuilder.fileUri); + memberBuilder.fileOffset, memberBuilder.fileUri); } @override @@ -268,7 +268,7 @@ class SourceExtensionBuilder extends ExtensionBuilderImpl unhandled( "${memberBuilder.runtimeType}:${memberKind}", "addMemberDescriptorInternal", - memberBuilder.charOffset, + memberBuilder.fileOffset, memberBuilder.fileUri); case BuiltMemberKind.ExtensionField: case BuiltMemberKind.LateIsSetField: @@ -327,9 +327,9 @@ class SourceExtensionBuilder extends ExtensionBuilderImpl } else { // Coverage-ignore-block(suite): Not run. libraryBuilder.addProblem(messagePatchDeclarationMismatch, - augmentation.charOffset, noLength, augmentation.fileUri, context: [ + augmentation.fileOffset, noLength, augmentation.fileUri, context: [ messagePatchDeclarationOrigin.withLocation( - fileUri, charOffset, noLength) + fileUri, fileOffset, noLength) ]); } } diff --git a/pkg/front_end/lib/src/source/source_extension_type_declaration_builder.dart b/pkg/front_end/lib/src/source/source_extension_type_declaration_builder.dart index 9921527fc6cf..4ec6c92612b9 100644 --- a/pkg/front_end/lib/src/source/source_extension_type_declaration_builder.dart +++ b/pkg/front_end/lib/src/source/source_extension_type_declaration_builder.dart @@ -53,7 +53,7 @@ class SourceExtensionTypeDeclarationBuilder final SourceLibraryBuilder parent; @override - final int charOffset; + final int fileOffset; @override final String name; @@ -111,7 +111,7 @@ class SourceExtensionTypeDeclarationBuilder required this.indexedContainer, required FieldFragment? representationFieldFragment}) : parent = enclosingLibraryBuilder, - charOffset = nameOffset, + fileOffset = nameOffset, _modifiers = fragment.modifiers, typeParameters = fragment.typeParameters, interfaceBuilders = fragment.interfaces, @@ -220,7 +220,7 @@ class SourceExtensionTypeDeclarationBuilder int compareTo(SourceExtensionTypeDeclarationBuilder other) { int result = "$fileUri".compareTo("${other.fileUri}"); if (result != 0) return result; - return charOffset.compareTo(other.charOffset); + return fileOffset.compareTo(other.fileOffset); } /// Builds the [ExtensionTypeDeclaration] for this extension type declaration @@ -280,7 +280,7 @@ class SourceExtensionTypeDeclarationBuilder if (aliasBuilder != null) { errorContext = [ messageTypedefCause.withLocation( - aliasBuilder.fileUri, aliasBuilder.charOffset, noLength), + aliasBuilder.fileUri, aliasBuilder.fileOffset, noLength), ]; } } else { @@ -297,7 +297,7 @@ class SourceExtensionTypeDeclarationBuilder if (aliasBuilder != null) { errorContext = [ messageTypedefCause.withLocation( - aliasBuilder.fileUri, aliasBuilder.charOffset, noLength), + aliasBuilder.fileUri, aliasBuilder.fileOffset, noLength), ]; } } @@ -311,7 +311,7 @@ class SourceExtensionTypeDeclarationBuilder .withArguments(typeBuilder.fullNameForErrors, interface); errorContext = [ messageTypedefCause.withLocation( - aliasBuilder.fileUri, aliasBuilder.charOffset, noLength), + aliasBuilder.fileUri, aliasBuilder.fileOffset, noLength), ]; } else { errorMessage = templateSuperExtensionTypeIsIllegal @@ -328,7 +328,7 @@ class SourceExtensionTypeDeclarationBuilder // Coverage-ignore-block(suite): Not run. errorContext = [ messageTypedefCause.withLocation( - aliasBuilder.fileUri, aliasBuilder.charOffset, noLength), + aliasBuilder.fileUri, aliasBuilder.fileOffset, noLength), ]; } } else { @@ -337,7 +337,7 @@ class SourceExtensionTypeDeclarationBuilder .withArguments(typeBuilder.fullNameForErrors, interface); errorContext = [ messageTypedefCause.withLocation( - aliasBuilder.fileUri, aliasBuilder.charOffset, noLength), + aliasBuilder.fileUri, aliasBuilder.fileOffset, noLength), ]; } else { errorMessage = templateSuperExtensionTypeIsIllegal @@ -380,7 +380,7 @@ class SourceExtensionTypeDeclarationBuilder if (isBottom(representationType)) { libraryBuilder.addProblem( messageExtensionTypeRepresentationTypeBottom, - representationFieldBuilder!.charOffset, + representationFieldBuilder!.fileOffset, representationFieldBuilder!.name.length, representationFieldBuilder!.fileUri); representationType = const InvalidType(); @@ -432,14 +432,14 @@ class SourceExtensionTypeDeclarationBuilder if (extensionTypeDeclarationBuilder != this) { context.add(messageExtensionTypeDeclarationCause.withLocation( extensionTypeDeclarationBuilder.fileUri, - extensionTypeDeclarationBuilder.charOffset, + extensionTypeDeclarationBuilder.fileOffset, extensionTypeDeclarationBuilder.name.length)); } } for (TypeAliasBuilder typeAliasBuilder in usedTypeAliasBuilders) { context.add(messageTypedefCause.withLocation( typeAliasBuilder.fileUri, - typeAliasBuilder.charOffset, + typeAliasBuilder.fileOffset, typeAliasBuilder.name.length)); } libraryBuilder.addProblem( @@ -781,7 +781,7 @@ class SourceExtensionTypeDeclarationBuilder unhandled( "${memberBuilder.runtimeType}:${memberKind}", "addMemberInternal", - memberBuilder.charOffset, + memberBuilder.fileOffset, memberBuilder.fileUri); case BuiltMemberKind.ExtensionTypeRepresentationField: assert(tearOff == null, "Unexpected tear-off $tearOff"); @@ -810,7 +810,7 @@ class SourceExtensionTypeDeclarationBuilder case BuiltMemberKind.ExtensionTypeRepresentationField: // Coverage-ignore(suite): Not run. unhandled("${memberBuilder.runtimeType}:${memberKind}", "buildMembers", - memberBuilder.charOffset, memberBuilder.fileUri); + memberBuilder.fileOffset, memberBuilder.fileUri); case BuiltMemberKind.ExtensionField: case BuiltMemberKind.LateIsSetField: kind = ExtensionTypeMemberKind.Field; @@ -872,9 +872,9 @@ class SourceExtensionTypeDeclarationBuilder // with origin declaration. } else { libraryBuilder.addProblem(messagePatchDeclarationMismatch, - augmentation.charOffset, noLength, augmentation.fileUri, context: [ + augmentation.fileOffset, noLength, augmentation.fileUri, context: [ messagePatchDeclarationOrigin.withLocation( - fileUri, charOffset, noLength) + fileUri, fileOffset, noLength) ]); } } diff --git a/pkg/front_end/lib/src/source/source_factory_builder.dart b/pkg/front_end/lib/src/source/source_factory_builder.dart index cdd8522b652c..2d04cfbcad2c 100644 --- a/pkg/front_end/lib/src/source/source_factory_builder.dart +++ b/pkg/front_end/lib/src/source/source_factory_builder.dart @@ -52,7 +52,7 @@ class SourceFactoryBuilder extends SourceFunctionBuilderImpl { @override final DeclarationBuilder declarationBuilder; - final int charOpenParenOffset; + final int formalsOffset; AsyncMarker actualAsyncModifier = AsyncMarker.Sync; @@ -73,31 +73,30 @@ class SourceFactoryBuilder extends SourceFunctionBuilderImpl { DelayedDefaultValueCloner? _delayedDefaultValueCloner; - @override - final int charOffset; + final int nameOffset; @override final Uri fileUri; SourceFactoryBuilder( - List? metadata, - Modifiers modifiers, - this.returnType, - String name, - List? typeVariables, - List? formals, - this.libraryBuilder, - this.declarationBuilder, - this.fileUri, - int startCharOffset, - this.charOffset, - this.charOpenParenOffset, - int charEndOffset, - Reference? procedureReference, - Reference? tearOffReference, - AsyncMarker asyncModifier, - NameScheme nameScheme, - {String? nativeMethodName}) + {required List? metadata, + required Modifiers modifiers, + required this.returnType, + required String name, + required List? typeVariables, + required List? formals, + required this.libraryBuilder, + required this.declarationBuilder, + required this.fileUri, + required int startOffset, + required this.nameOffset, + required this.formalsOffset, + required int endOffset, + required Reference? procedureReference, + required Reference? tearOffReference, + required AsyncMarker asyncModifier, + required NameScheme nameScheme, + String? nativeMethodName}) : _memberName = nameScheme.getDeclaredName(name), super(metadata, modifiers, name, typeVariables, formals, nativeMethodName) { @@ -109,9 +108,9 @@ class SourceFactoryBuilder extends SourceFunctionBuilderImpl { new FunctionNode(null), fileUri: fileUri, reference: procedureReference) - ..fileStartOffset = startCharOffset - ..fileOffset = charOffset - ..fileEndOffset = charEndOffset + ..fileStartOffset = startOffset + ..fileOffset = nameOffset + ..fileEndOffset = endOffset ..isExtensionTypeMember = nameScheme.isExtensionTypeMember; nameScheme .getConstructorMemberName(name, isTearOff: false) @@ -120,13 +119,16 @@ class SourceFactoryBuilder extends SourceFunctionBuilderImpl { nameScheme.getConstructorMemberName(name, isTearOff: true), libraryBuilder, fileUri, - charOffset, + nameOffset, tearOffReference, forceCreateLowering: nameScheme.isExtensionTypeMember) ?..isExtensionTypeMember = nameScheme.isExtensionTypeMember; this.asyncModifier = asyncModifier; } + @override + int get fileOffset => nameOffset; + @override Builder get parent => declarationBuilder; @@ -193,7 +195,7 @@ class SourceFactoryBuilder extends SourceFunctionBuilderImpl { void _build() { buildFunction(); - _procedureInternal.function.fileOffset = charOpenParenOffset; + _procedureInternal.function.fileOffset = formalsOffset; _procedureInternal.function.fileEndOffset = _procedureInternal.fileEndOffset; _procedureInternal.isAbstract = isAbstract; @@ -256,7 +258,7 @@ class SourceFactoryBuilder extends SourceFunctionBuilderImpl { void setRedirectingFactoryBody(Member target, List typeArguments) { if (bodyInternal != null) { - unexpected("null", "${bodyInternal.runtimeType}", charOffset, fileUri); + unexpected("null", "${bodyInternal.runtimeType}", fileOffset, fileUri); } bodyInternal = createRedirectingFactoryBody(target, typeArguments, function); @@ -371,42 +373,42 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder { bool _hasBeenCheckedAsRedirectingFactory = false; RedirectingFactoryBuilder( - List? metadata, - Modifiers modifiers, - TypeBuilder returnType, - String name, - List? typeVariables, - List? formals, - SourceLibraryBuilder libraryBuilder, - DeclarationBuilder declarationBuilder, - Uri fileUri, - int startCharOffset, - int charOffset, - int charOpenParenOffset, - int charEndOffset, - Reference? procedureReference, - Reference? tearOffReference, - NameScheme nameScheme, - String? nativeMethodName, - this.redirectionTarget) + {required List? metadata, + required Modifiers modifiers, + required TypeBuilder returnType, + required String name, + required List? typeVariables, + required List? formals, + required SourceLibraryBuilder libraryBuilder, + required DeclarationBuilder declarationBuilder, + required Uri fileUri, + required int startOffset, + required int nameOffset, + required int formalsOffset, + required int endOffset, + required Reference? procedureReference, + required Reference? tearOffReference, + required NameScheme nameScheme, + required String? nativeMethodName, + required this.redirectionTarget}) : super( - metadata, - modifiers, - returnType, - name, - typeVariables, - formals, - libraryBuilder, - declarationBuilder, - fileUri, - startCharOffset, - charOffset, - charOpenParenOffset, - charEndOffset, - procedureReference, - tearOffReference, - AsyncMarker.Sync, - nameScheme, + metadata: metadata, + modifiers: modifiers, + returnType: returnType, + name: name, + typeVariables: typeVariables, + formals: formals, + libraryBuilder: libraryBuilder, + declarationBuilder: declarationBuilder, + fileUri: fileUri, + startOffset: startOffset, + nameOffset: nameOffset, + formalsOffset: formalsOffset, + endOffset: endOffset, + procedureReference: procedureReference, + tearOffReference: tearOffReference, + asyncModifier: AsyncMarker.Sync, + nameScheme: nameScheme, nativeMethodName: nativeMethodName); @override @@ -415,14 +417,14 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder { @override void setRedirectingFactoryBody(Member target, List typeArguments) { if (bodyInternal != null) { - unexpected("null", "${bodyInternal.runtimeType}", charOffset, fileUri); + unexpected("null", "${bodyInternal.runtimeType}", fileOffset, fileUri); } // Ensure that constant factories only have constant targets/bodies. if (isConst && !target.isConst) { // Coverage-ignore-block(suite): Not run. libraryBuilder.addProblem(messageConstFactoryRedirectionToNonConst, - charOffset, noLength, fileUri); + fileOffset, noLength, fileUri); } bodyInternal = @@ -472,7 +474,7 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder { @override void _build() { buildFunction(); - _procedureInternal.function.fileOffset = charOpenParenOffset; + _procedureInternal.function.fileOffset = formalsOffset; _procedureInternal.function.fileEndOffset = _procedureInternal.fileEndOffset; _procedureInternal.isAbstract = isAbstract; @@ -543,7 +545,7 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder { target = targetBuilder.invokeTarget!; } else { unhandled("${targetBuilder.runtimeType}", "buildOutlineExpressions", - charOffset, fileUri); + fileOffset, fileUri); } // Type arguments for the targets of redirecting factories can only be @@ -566,7 +568,7 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder { helper, _procedureInternal.function.returnType, _procedure.function, - charOffset, + fileOffset, target, target.function!.computeFunctionType(Nullability.nonNullable)); if (typeArguments == null) { @@ -678,7 +680,7 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder { return null; } else { unhandled("${targetBuilder.runtimeType}", "computeRedirecteeType", - charOffset, fileUri); + fileOffset, fileUri); } List? typeArguments = factory.getTypeArguments(); @@ -807,7 +809,7 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder { templateCyclicRedirectingFactoryConstructors .withArguments("${declarationBuilder.name}" "${name == '' ? '' : '.${name}'}"), - charOffset, + fileOffset, noLength, fileUri); return; diff --git a/pkg/front_end/lib/src/source/source_field_builder.dart b/pkg/front_end/lib/src/source/source_field_builder.dart index e36621b8b42c..2978d02b94a4 100644 --- a/pkg/front_end/lib/src/source/source_field_builder.dart +++ b/pkg/front_end/lib/src/source/source_field_builder.dart @@ -86,7 +86,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl final DeclarationBuilder? declarationBuilder; @override - final int charOffset; + final int fileOffset; @override final Uri fileUri; @@ -100,7 +100,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl this.libraryBuilder, this.declarationBuilder, this.fileUri, - this.charOffset, + this.fileOffset, int charEndOffset, NameScheme fieldNameScheme, {Reference? fieldReference, @@ -138,7 +138,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl name, fieldNameScheme, fileUri, - charOffset, + fileOffset, charEndOffset, fieldGetterReference, fieldSetterReference, @@ -160,7 +160,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl name, fieldNameScheme, fileUri, - charOffset, + fileOffset, charEndOffset, fieldGetterReference); } else if (isLate && @@ -175,7 +175,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl name, fieldNameScheme, fileUri, - charOffset, + fileOffset, charEndOffset, fieldReference, fieldGetterReference, @@ -192,7 +192,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl name, fieldNameScheme, fileUri, - charOffset, + fileOffset, charEndOffset, fieldReference, fieldGetterReference, @@ -211,7 +211,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl name, fieldNameScheme, fileUri, - charOffset, + fileOffset, charEndOffset, fieldReference, fieldGetterReference, @@ -228,7 +228,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl name, fieldNameScheme, fileUri, - charOffset, + fileOffset, charEndOffset, fieldReference, fieldGetterReference, @@ -253,7 +253,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl name, fieldNameScheme, fileUri, - charOffset, + fileOffset, charEndOffset, fieldReference, fieldGetterReference, @@ -270,7 +270,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl name, fieldNameScheme, fileUri, - charOffset, + fileOffset, charEndOffset, fieldReference, fieldGetterReference, @@ -290,7 +290,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl assert(lateGetterReference == null); assert(lateSetterReference == null); _fieldEncoding = new RegularFieldEncoding( - name, fieldNameScheme, fileUri, charOffset, charEndOffset, + name, fieldNameScheme, fileUri, fileOffset, charEndOffset, isFinal: isFinal, isConst: isConst, isLate: isLate, @@ -368,7 +368,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl // Coverage-ignore(suite): Not run. !isFinal) { internalProblem( - messageInternalProblemAlreadyInitialized, charOffset, fileUri); + messageInternalProblemAlreadyInitialized, fileOffset, fileUri); } _fieldEncoding.createBodies(coreTypes, initializer); } @@ -538,7 +538,7 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl return fieldType; } - return libraryBuilder.loader.withUriForCrashReporting(fileUri, charOffset, + return libraryBuilder.loader.withUriForCrashReporting(fileUri, fileOffset, () { InferredType implicitFieldType = fieldType as InferredType; DartType inferredType = implicitFieldType.computeType(hierarchy); @@ -1677,7 +1677,7 @@ class _SynthesizedFieldClassMember implements ClassMember { Uri get fileUri => fieldBuilder.fileUri; @override - int get charOffset => fieldBuilder.charOffset; + int get charOffset => fieldBuilder.fileOffset; @override bool get isAbstract => _member.isAbstract; diff --git a/pkg/front_end/lib/src/source/source_function_builder.dart b/pkg/front_end/lib/src/source/source_function_builder.dart index 51065ea18958..65b2d3b8cb68 100644 --- a/pkg/front_end/lib/src/source/source_function_builder.dart +++ b/pkg/front_end/lib/src/source/source_function_builder.dart @@ -257,11 +257,11 @@ abstract class SourceFunctionBuilderImpl extends SourceMemberBuilderImpl for (FormalParameterBuilder formal in formals!) { if (formal.isWildcard && identifier.name == '_' && - formal.charOffset == identifier.nameOffset) { + formal.fileOffset == identifier.nameOffset) { return formal; } if (formal.name == identifier.name && - formal.charOffset == identifier.nameOffset) { + formal.fileOffset == identifier.nameOffset) { return formal; } } @@ -354,7 +354,7 @@ abstract class SourceFunctionBuilderImpl extends SourceMemberBuilderImpl libraryBuilder.addProblem( templateRequiredNamedParameterHasDefaultValueError .withArguments(formal.name), - formal.charOffset, + formal.fileOffset, formal.name.length, formal.fileUri); } @@ -406,7 +406,7 @@ abstract class SourceFunctionBuilderImpl extends SourceMemberBuilderImpl extensionTypeDeclarationBuilder.extensionTypeDeclaration, Nullability.nonNullable, typeArguments)) - ..fileOffset = charOffset + ..fileOffset = fileOffset ..isLowered = true; } else { _thisVariable = function.positionalParameters.first; @@ -531,9 +531,9 @@ abstract class SourceFunctionBuilderImpl extends SourceMemberBuilderImpl if (!isExternal && !augmentation.libraryBuilder.isAugmentationLibrary) { // Coverage-ignore-block(suite): Not run. augmentation.libraryBuilder.addProblem(messagePatchNonExternal, - augmentation.charOffset, noLength, augmentation.fileUri!, context: [ + augmentation.fileOffset, noLength, augmentation.fileUri!, context: [ messagePatchDeclarationOrigin.withLocation( - fileUri, charOffset, noLength) + fileUri, fileOffset, noLength) ]); return false; } @@ -544,8 +544,8 @@ abstract class SourceFunctionBuilderImpl extends SourceMemberBuilderImpl // Coverage-ignore(suite): Not run. void reportAugmentationMismatch(Builder augmentation) { libraryBuilder.addProblem(messagePatchDeclarationMismatch, - augmentation.charOffset, noLength, augmentation.fileUri!, context: [ - messagePatchDeclarationOrigin.withLocation(fileUri, charOffset, noLength) + augmentation.fileOffset, noLength, augmentation.fileUri!, context: [ + messagePatchDeclarationOrigin.withLocation(fileUri, fileOffset, noLength) ]); } } diff --git a/pkg/front_end/lib/src/source/source_library_builder.dart b/pkg/front_end/lib/src/source/source_library_builder.dart index d372abd8bfc9..9578219c2371 100644 --- a/pkg/front_end/lib/src/source/source_library_builder.dart +++ b/pkg/front_end/lib/src/source/source_library_builder.dart @@ -619,13 +619,13 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { if (currentSetter.isConflictingSetter) { sourceLibraryBuilder.addProblem( templateConflictsWithImplicitSetter.withArguments(name), - currentSetter.charOffset, + currentSetter.fileOffset, noLength, currentSetter.fileUri); } else { sourceLibraryBuilder.addProblem( templateConflictsWithMember.withArguments(name), - currentSetter.charOffset, + currentSetter.fileOffset, noLength, currentSetter.fileUri); } @@ -635,7 +635,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { // TODO(ahe): Context argument to previous message? sourceLibraryBuilder.addProblem( templateConflictsWithSetter.withArguments(name), - conflictingGetable.charOffset, + conflictingGetable.fileOffset, noLength, conflictingGetable.fileUri!); } @@ -787,7 +787,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { case NominalVariableBuilder(): case StructuralVariableBuilder(): unhandled( - 'member', 'exportScope', builder.charOffset, builder.fileUri); + 'member', 'exportScope', builder.fileOffset, builder.fileUri); } } else if (builder is MemberBuilder) { for (Member exportedMember in builder.exportedMembers) { @@ -805,7 +805,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { } } else { unhandled( - 'member', 'exportScope', builder.charOffset, builder.fileUri); + 'member', 'exportScope', builder.fileOffset, builder.fileUri); } } } @@ -1197,14 +1197,14 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { addProblem( templateInvalidGetterSetterType.withArguments( getterType, getterMemberName, setterType, setterMemberName), - getterBuilder.charOffset, + getterBuilder.fileOffset, getterBuilder.name.length, getterBuilder.fileUri, context: [ templateInvalidGetterSetterTypeSetterContext .withArguments(setterMemberName) .withLocation(setterBuilder.fileUri!, - setterBuilder.charOffset, setterBuilder.name.length) + setterBuilder.fileOffset, setterBuilder.name.length) ]); } } @@ -1374,7 +1374,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { return; } else { unhandled("${declaration.runtimeType}", "buildBuilder", - declaration.charOffset, declaration.fileUri); + declaration.fileOffset, declaration.fileUri); } } @@ -1405,7 +1405,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { library.addProcedure(member); } } else { - unhandled("${member.runtimeType}", "_buildMember", declaration.charOffset, + unhandled("${member.runtimeType}", "_buildMember", declaration.fileOffset, declaration.fileUri); } } @@ -1675,7 +1675,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { // Nothing needed. } else { unhandled("${builder.runtimeType}", "buildBodyNodes", - builder.charOffset, builder.fileUri); + builder.fileOffset, builder.fileUri); } } return count; @@ -1836,7 +1836,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { addProblem( templateFieldNonNullableWithoutInitializerError.withArguments( fieldBuilder.name, fieldBuilder.fieldType), - fieldBuilder.charOffset, + fieldBuilder.fileOffset, fieldBuilder.name.length, fieldBuilder.fileUri); } @@ -1855,7 +1855,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { addProblem( templateOptionalNonNullableWithoutInitializerError.withArguments( formal.name, formal.variable!.type), - formal.charOffset, + formal.fileOffset, formal.name.length, formal.fileUri); } @@ -2189,15 +2189,15 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { } addProblem( message, - dependency.typeVariableBoundOfItself.charOffset, + dependency.typeVariableBoundOfItself.fileOffset, dependency.typeVariableBoundOfItself.name.length, dependency.typeVariableBoundOfItself.fileUri); typeVariable.bound = new NamedTypeBuilderImpl( - new SyntheticTypeName(typeVariable.name, typeVariable.charOffset), + new SyntheticTypeName(typeVariable.name, typeVariable.fileOffset), const NullabilityBuilder.omitted(), fileUri: typeVariable.fileUri, - charOffset: typeVariable.charOffset, + charOffset: typeVariable.fileOffset, instanceTypeVariableAccess: InstanceTypeVariableAccessState.Unexpected) ..bind( @@ -2208,7 +2208,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { dependency.typeVariableBoundOfItself .fileUri ?? // Coverage-ignore(suite): Not run. fileUri, - dependency.typeVariableBoundOfItself.charOffset, + dependency.typeVariableBoundOfItself.fileOffset, dependency.typeVariableBoundOfItself.name.length))); } } @@ -2467,7 +2467,7 @@ Uri computeLibraryUri(Builder declaration) { current = current.parent; } return unhandled("no library parent", "${declaration.runtimeType}", - declaration.charOffset, declaration.fileUri); + declaration.fileOffset, declaration.fileUri); } class PostponedProblem { diff --git a/pkg/front_end/lib/src/source/source_loader.dart b/pkg/front_end/lib/src/source/source_loader.dart index 7d17d3768f66..9e4f9318a71d 100644 --- a/pkg/front_end/lib/src/source/source_loader.dart +++ b/pkg/front_end/lib/src/source/source_loader.dart @@ -1361,24 +1361,24 @@ severity: $severity } } SourceProcedureBuilder builder = new SourceProcedureBuilder( - /* metadata = */ null, - Modifiers.empty, - const ImplicitTypeBuilder(), - "debugExpr", - /* type variables = */ null, - /* formals = */ null, - ProcedureKind.Method, - libraryBuilder, - declarationBuilder, - libraryBuilder.fileUri, - /* start char offset = */ 0, - /* char offset = */ 0, - /* open paren offset = */ -1, - /* end offset = */ -1, - /* procedure reference = */ null, - /* tear off reference = */ null, - AsyncMarker.Sync, - new NameScheme( + metadata: null, + modifiers: Modifiers.empty, + returnType: const ImplicitTypeBuilder(), + name: "debugExpr", + typeVariables: null, + formals: null, + kind: ProcedureKind.Method, + libraryBuilder: libraryBuilder, + declarationBuilder: declarationBuilder, + fileUri: libraryBuilder.fileUri, + startOffset: 0, + nameOffset: 0, + formalsOffset: -1, + endOffset: -1, + procedureReference: null, + tearOffReference: null, + asyncModifier: AsyncMarker.Sync, + nameScheme: new NameScheme( containerName: null, containerType: ContainerType.Library, isInstanceMember: false, @@ -1968,16 +1968,16 @@ severity: $severity if (objectClass.supertypeBuilder != null) { objectClass.supertypeBuilder = null; objectClass.addProblem( - messageObjectExtends, objectClass.charOffset, noLength); + messageObjectExtends, objectClass.fileOffset, noLength); } if (objectClass.interfaceBuilders != null) { objectClass.addProblem( - messageObjectImplements, objectClass.charOffset, noLength); + messageObjectImplements, objectClass.fileOffset, noLength); objectClass.interfaceBuilders = null; } if (objectClass.mixedInTypeBuilder != null) { objectClass.addProblem( - messageObjectMixesIn, objectClass.charOffset, noLength); + messageObjectMixesIn, objectClass.fileOffset, noLength); objectClass.mixedInTypeBuilder = null; } } @@ -2062,7 +2062,7 @@ severity: $severity classBuilder.addProblem( templateCyclicClassHierarchy .withArguments(classBuilder.fullNameForErrors), - classBuilder.charOffset, + classBuilder.fileOffset, noLength); } } @@ -2094,7 +2094,7 @@ severity: $severity extensionTypeBuilder.addProblem( templateCyclicClassHierarchy .withArguments(extensionTypeBuilder.fullNameForErrors), - extensionTypeBuilder.charOffset, + extensionTypeBuilder.fileOffset, noLength); } } @@ -2114,13 +2114,13 @@ severity: $severity cls.addProblem( templateIllegalMixinDueToConstructors .withArguments(builder.fullNameForErrors), - cls.charOffset, + cls.fileOffset, noLength, context: [ templateIllegalMixinDueToConstructorsCause .withArguments(builder.fullNameForErrors) .withLocation( - constructor.fileUri!, constructor.charOffset, noLength) + constructor.fileUri!, constructor.fileOffset, noLength) ]); } } @@ -2131,7 +2131,7 @@ severity: $severity // Coverage-ignore-block(suite): Not run. cls.addProblem( templateEnumSupertypeOfNonAbstractClass.withArguments(cls.name), - cls.charOffset, + cls.fileOffset, noLength); return true; } @@ -2152,7 +2152,7 @@ severity: $severity // Coverage-ignore-block(suite): Not run. classBuilder.addProblem( templateExtendingEnum.withArguments(supertype.name), - classBuilder.charOffset, + classBuilder.fileOffset, noLength); } else if (!classBuilder.libraryBuilder.mayImplementRestrictedTypes && (denyListedClasses.contains(supertype) || @@ -2163,17 +2163,17 @@ severity: $severity classBuilder.addProblem( templateExtendingRestricted .withArguments(supertype!.fullNameForErrors), - classBuilder.charOffset, + classBuilder.fileOffset, noLength, context: [ messageTypedefCause.withLocation( - aliasBuilder.fileUri, aliasBuilder.charOffset, noLength), + aliasBuilder.fileUri, aliasBuilder.fileOffset, noLength), ]); } else { classBuilder.addProblem( templateExtendingRestricted .withArguments(supertype!.fullNameForErrors), - classBuilder.charOffset, + classBuilder.fileOffset, noLength); } } @@ -2192,13 +2192,13 @@ severity: $severity classBuilder.addProblem( templateExtendingRestricted .withArguments(mixedInTypeBuilder.fullNameForErrors), - classBuilder.charOffset, + classBuilder.fileOffset, noLength, context: declaration is TypeAliasBuilder ? [ messageTypedefUnaliasedTypeCause.withLocation( unaliasedDeclaration.fileUri, - unaliasedDeclaration.charOffset, + unaliasedDeclaration.fileOffset, noLength), ] : null); @@ -2215,12 +2215,12 @@ severity: $severity classBuilder.addProblem( templateIllegalMixin .withArguments(mixedInTypeBuilder.fullNameForErrors), - classBuilder.charOffset, + classBuilder.fileOffset, noLength, context: declaration is TypeAliasBuilder ? [ messageTypedefCause.withLocation( - declaration.fileUri, declaration.charOffset, noLength), + declaration.fileUri, declaration.fileOffset, noLength), ] : null); } @@ -2418,7 +2418,7 @@ severity: $severity cls.addProblem( template.withArguments(cls.fullNameForErrors, baseOrFinalSuperClass.fullNameForErrors), - cls.charOffset, + cls.fileOffset, noLength); } else if (baseOrFinalSuperClass.isBase) { final Template template = @@ -2428,7 +2428,7 @@ severity: $severity cls.addProblem( template.withArguments(cls.fullNameForErrors, baseOrFinalSuperClass.fullNameForErrors), - cls.charOffset, + cls.fileOffset, noLength); } } @@ -2539,7 +2539,7 @@ severity: $severity .withArguments(interfaceDeclaration.fullNameForErrors, checkedClass.fullNameForErrors) .withLocation(checkedClass.fileUri, - checkedClass.charOffset, noLength) + checkedClass.fileOffset, noLength) ]; if (checkedClass.isBase && !cls.cls.isAnonymousMixin) { @@ -2746,7 +2746,7 @@ severity: $severity member.isAbstract == false) { classBuilder.libraryBuilder.addProblem( templateEnumInheritsRestricted.withArguments(name.text), - classBuilder.charOffset, + classBuilder.fileOffset, classBuilder.name.length, classBuilder.fileUri, context: [ @@ -2990,15 +2990,15 @@ severity: $severity if (mainBuilder.isField || mainBuilder.isGetter || mainBuilder.isSetter) { if (mainBuilder.libraryBuilder != libraryBuilder) { libraryBuilder.addProblem(messageMainNotFunctionDeclarationExported, - libraryBuilder.charOffset, noLength, libraryBuilder.fileUri, + libraryBuilder.fileOffset, noLength, libraryBuilder.fileUri, context: [ messageExportedMain.withLocation(mainBuilder.fileUri!, - mainBuilder.charOffset, mainBuilder.name.length) + mainBuilder.fileOffset, mainBuilder.name.length) ]); } else { libraryBuilder.addProblem( messageMainNotFunctionDeclaration, - mainBuilder.charOffset, + mainBuilder.fileOffset, mainBuilder.name.length, mainBuilder.fileUri); } @@ -3008,17 +3008,17 @@ severity: $severity if (mainBuilder.libraryBuilder != libraryBuilder) { libraryBuilder.addProblem( messageMainTooManyRequiredParametersExported, - libraryBuilder.charOffset, + libraryBuilder.fileOffset, noLength, libraryBuilder.fileUri, context: [ messageExportedMain.withLocation(mainBuilder.fileUri!, - mainBuilder.charOffset, mainBuilder.name.length) + mainBuilder.fileOffset, mainBuilder.name.length) ]); } else { libraryBuilder.addProblem( messageMainTooManyRequiredParameters, - mainBuilder.charOffset, + mainBuilder.fileOffset, mainBuilder.name.length, mainBuilder.fileUri); } @@ -3027,17 +3027,17 @@ severity: $severity if (mainBuilder.libraryBuilder != libraryBuilder) { libraryBuilder.addProblem( messageMainRequiredNamedParametersExported, - libraryBuilder.charOffset, + libraryBuilder.fileOffset, noLength, libraryBuilder.fileUri, context: [ messageExportedMain.withLocation(mainBuilder.fileUri!, - mainBuilder.charOffset, mainBuilder.name.length) + mainBuilder.fileOffset, mainBuilder.name.length) ]); } else { libraryBuilder.addProblem( messageMainRequiredNamedParameters, - mainBuilder.charOffset, + mainBuilder.fileOffset, mainBuilder.name.length, mainBuilder.fileUri); } @@ -3051,18 +3051,18 @@ severity: $severity libraryBuilder.addProblem( templateMainWrongParameterTypeExported.withArguments( parameterType, listOfString), - libraryBuilder.charOffset, + libraryBuilder.fileOffset, noLength, libraryBuilder.fileUri, context: [ messageExportedMain.withLocation(mainBuilder.fileUri!, - mainBuilder.charOffset, mainBuilder.name.length) + mainBuilder.fileOffset, mainBuilder.name.length) ]); } else { libraryBuilder.addProblem( templateMainWrongParameterType.withArguments( parameterType, listOfString), - mainBuilder.charOffset, + mainBuilder.fileOffset, mainBuilder.name.length, mainBuilder.fileUri); } @@ -3072,14 +3072,14 @@ severity: $severity } else if (mainBuilder != null) { if (mainBuilder.parent != libraryBuilder) { libraryBuilder.addProblem(messageMainNotFunctionDeclarationExported, - libraryBuilder.charOffset, noLength, libraryBuilder.fileUri, + libraryBuilder.fileOffset, noLength, libraryBuilder.fileUri, context: [ messageExportedMain.withLocation( - mainBuilder.fileUri!, mainBuilder.charOffset, noLength) + mainBuilder.fileUri!, mainBuilder.fileOffset, noLength) ]); } else { libraryBuilder.addProblem(messageMainNotFunctionDeclaration, - mainBuilder.charOffset, noLength, mainBuilder.fileUri); + mainBuilder.fileOffset, noLength, mainBuilder.fileUri); } } } diff --git a/pkg/front_end/lib/src/source/source_member_builder.dart b/pkg/front_end/lib/src/source/source_member_builder.dart index 707ff320f72f..1f31c6bdc192 100644 --- a/pkg/front_end/lib/src/source/source_member_builder.dart +++ b/pkg/front_end/lib/src/source/source_member_builder.dart @@ -173,7 +173,7 @@ abstract class SourceMemberBuilderImpl extends MemberBuilderImpl // TODO(johnniwinther): Remove this and create a [ProcedureBuilder] interface. @override // Coverage-ignore(suite): Not run. - ProcedureKind? get kind => unsupported("kind", charOffset, fileUri); + ProcedureKind? get kind => unsupported("kind", fileOffset, fileUri); @override // Coverage-ignore(suite): Not run. diff --git a/pkg/front_end/lib/src/source/source_procedure_builder.dart b/pkg/front_end/lib/src/source/source_procedure_builder.dart index 6c1ce14e4fe9..59d650b8180b 100644 --- a/pkg/front_end/lib/src/source/source_procedure_builder.dart +++ b/pkg/front_end/lib/src/source/source_procedure_builder.dart @@ -38,7 +38,7 @@ class SourceProcedureBuilder extends SourceFunctionBuilderImpl @override final DeclarationBuilder? declarationBuilder; - final int charOpenParenOffset; + final int formalsOffset; AsyncMarker actualAsyncModifier = AsyncMarker.Sync; @@ -83,34 +83,34 @@ class SourceProcedureBuilder extends SourceFunctionBuilderImpl final MemberName _memberName; - @override - final int charOffset; + final int nameOffset; @override final Uri fileUri; SourceProcedureBuilder( - List? metadata, - Modifiers modifiers, - this.returnType, - String name, - List? typeVariables, - List? formals, - this.kind, - this.libraryBuilder, - this.declarationBuilder, - this.fileUri, - int startCharOffset, - this.charOffset, - this.charOpenParenOffset, - int charEndOffset, - Reference? procedureReference, - this._tearOffReference, - AsyncMarker asyncModifier, - NameScheme nameScheme, - {String? nativeMethodName, + {required List? metadata, + required Modifiers modifiers, + required this.returnType, + required String name, + required List? typeVariables, + required List? formals, + required this.kind, + required this.libraryBuilder, + required this.declarationBuilder, + required this.fileUri, + required int startOffset, + required this.nameOffset, + required this.formalsOffset, + required int endOffset, + required Reference? procedureReference, + required Reference? tearOffReference, + required AsyncMarker asyncModifier, + required NameScheme nameScheme, + String? nativeMethodName, bool isSynthetic = false}) : assert(kind != ProcedureKind.Factory), + _tearOffReference = tearOffReference, this.isExtensionInstanceMember = nameScheme.isInstanceMember && nameScheme.isExtensionMember, this.isExtensionTypeInstanceMember = @@ -127,9 +127,9 @@ class SourceProcedureBuilder extends SourceFunctionBuilderImpl fileUri: fileUri, reference: procedureReference, isSynthetic: isSynthetic) - ..fileStartOffset = startCharOffset - ..fileOffset = charOffset - ..fileEndOffset = charEndOffset; + ..fileStartOffset = startOffset + ..fileOffset = nameOffset + ..fileEndOffset = endOffset; nameScheme.getProcedureMemberName(kind, name).attachMember(_procedure); this.asyncModifier = asyncModifier; if ((isExtensionInstanceMember || isExtensionTypeInstanceMember) && @@ -140,13 +140,17 @@ class SourceProcedureBuilder extends SourceFunctionBuilderImpl isExtensionMember: isExtensionInstanceMember, isExtensionTypeMember: isExtensionTypeInstanceMember, reference: _tearOffReference, - fileUri: fileUri); + fileUri: fileUri) + ..fileOffset = nameOffset; nameScheme .getProcedureMemberName(ProcedureKind.Getter, name) .attachMember(_extensionTearOff!); } } + @override + int get fileOffset => nameOffset; + @override Builder get parent => declarationBuilder ?? libraryBuilder; @@ -340,7 +344,7 @@ class SourceProcedureBuilder extends SourceFunctionBuilderImpl void _build() { buildFunction(); - _procedure.function.fileOffset = charOpenParenOffset; + _procedure.function.fileOffset = formalsOffset; _procedure.function.fileEndOffset = _procedure.fileEndOffset; _procedure.isAbstract = isAbstract; _procedure.isExternal = isExternal; diff --git a/pkg/front_end/lib/src/source/source_type_alias_builder.dart b/pkg/front_end/lib/src/source/source_type_alias_builder.dart index 89ff05257c53..a0a14263b0af 100644 --- a/pkg/front_end/lib/src/source/source_type_alias_builder.dart +++ b/pkg/front_end/lib/src/source/source_type_alias_builder.dart @@ -32,7 +32,7 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl { final SourceLibraryBuilder parent; @override - final int charOffset; + final int fileOffset; @override final String name; @@ -64,7 +64,7 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl { required int fileOffset, required TypedefFragment fragment, required Reference? reference}) - : charOffset = fileOffset, + : fileOffset = fileOffset, parent = enclosingLibraryBuilder, _reference = reference ?? new Reference(), _introductory = fragment, @@ -109,10 +109,10 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl { NominalVariableBuilder.typeParametersFromBuilders(typeVariables), fileUri: fileUri, reference: _reference) - ..fileOffset = charOffset; + ..fileOffset = fileOffset; if (_checkCyclicTypedefDependency(type, this, {this})) { typedef.type = new InvalidType(); - _type = new InvalidTypeBuilderImpl(fileUri, charOffset); + _type = new InvalidTypeBuilderImpl(fileUri, fileOffset); } if (typeVariables != null) { for (TypeVariableBuilder typeVariable in typeVariables!) { @@ -120,13 +120,13 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl { // The bound is erroneous and should be set to [InvalidType]. typeVariable.parameterBound = new InvalidType(); typeVariable.parameterDefaultType = new InvalidType(); - typeVariable.bound = new InvalidTypeBuilderImpl(fileUri, charOffset); + typeVariable.bound = new InvalidTypeBuilderImpl(fileUri, fileOffset); typeVariable.defaultType = - new InvalidTypeBuilderImpl(fileUri, charOffset); + new InvalidTypeBuilderImpl(fileUri, fileOffset); // The typedef itself can't be used without proper bounds of its type // variables, so we set it to mean [InvalidType] too. typedef.type = new InvalidType(); - _type = new InvalidTypeBuilderImpl(fileUri, charOffset); + _type = new InvalidTypeBuilderImpl(fileUri, fileOffset); } } } @@ -168,7 +168,7 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl { seenTypeAliasBuilder.libraryBuilder.addProblem( templateCyclicTypedef .withArguments(seenTypeAliasBuilder.name), - seenTypeAliasBuilder.charOffset, + seenTypeAliasBuilder.fileOffset, seenTypeAliasBuilder.name.length, seenTypeAliasBuilder.fileUri); } diff --git a/pkg/front_end/lib/src/source/type_parameter_scope_builder.dart b/pkg/front_end/lib/src/source/type_parameter_scope_builder.dart index 737be00c9e44..3784cc401606 100644 --- a/pkg/front_end/lib/src/source/type_parameter_scope_builder.dart +++ b/pkg/front_end/lib/src/source/type_parameter_scope_builder.dart @@ -68,11 +68,11 @@ class _Added { IndexedClass? indexedClass = indexedLibrary?.lookupIndexedClass(fragment.name); SourceClassBuilder classBuilder = new SourceClassBuilder( - fragment.metadata, - fragment.modifiers, - fragment.name, - fragment.typeParameters, - BuilderFactoryImpl.applyMixins( + metadata: fragment.metadata, + modifiers: fragment.modifiers, + name: fragment.name, + typeVariables: fragment.typeParameters, + supertypeBuilder: BuilderFactoryImpl.applyMixins( unboundNominalVariables: unboundNominalVariables, compilationUnitScope: fragment.compilationUnitScope, problemReporting: problemReporting, @@ -83,9 +83,9 @@ class _Added { supertype: fragment.supertype, mixinApplicationBuilder: fragment.mixins, mixinApplications: mixinApplications, - startCharOffset: fragment.startOffset, - charOffset: fragment.charOffset, - charEndOffset: fragment.endOffset, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + endOffset: fragment.endOffset, subclassName: fragment.name, isMixinDeclaration: false, typeVariables: fragment.typeParameters, @@ -99,17 +99,17 @@ class _Added { builders.add(new _AddBuilder( name, declaration, fragment.fileUri, charOffset)); }), - fragment.interfaces, - /* onTypes = */ null, - fragment.typeParameterScope, - fragment.toDeclarationNameSpaceBuilder(), - enclosingLibraryBuilder, - fragment.constructorReferences, - fragment.fileUri, - fragment.startOffset, - fragment.charOffset, - fragment.endOffset, - indexedClass, + interfaceBuilders: fragment.interfaces, + onTypes: null, + typeParameterScope: fragment.typeParameterScope, + nameSpaceBuilder: fragment.toDeclarationNameSpaceBuilder(), + libraryBuilder: enclosingLibraryBuilder, + constructorReferences: fragment.constructorReferences, + fileUri: fragment.fileUri, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + endOffset: fragment.endOffset, + indexedClass: indexedClass, isMixinDeclaration: false); fragment.builder = classBuilder; fragment.bodyScope.declarationBuilder = classBuilder; @@ -123,11 +123,11 @@ class _Added { IndexedClass? indexedClass = indexedLibrary?.lookupIndexedClass(fragment.name); SourceClassBuilder mixinBuilder = new SourceClassBuilder( - fragment.metadata, - fragment.modifiers, - fragment.name, - fragment.typeParameters, - BuilderFactoryImpl.applyMixins( + metadata: fragment.metadata, + modifiers: fragment.modifiers, + name: fragment.name, + typeVariables: fragment.typeParameters, + supertypeBuilder: BuilderFactoryImpl.applyMixins( unboundNominalVariables: unboundNominalVariables, compilationUnitScope: fragment.compilationUnitScope, problemReporting: problemReporting, @@ -138,9 +138,9 @@ class _Added { supertype: fragment.supertype, mixinApplicationBuilder: fragment.mixins, mixinApplications: mixinApplications, - startCharOffset: fragment.startOffset, - charOffset: fragment.charOffset, - charEndOffset: fragment.endOffset, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + endOffset: fragment.endOffset, subclassName: fragment.name, isMixinDeclaration: true, typeVariables: fragment.typeParameters, @@ -154,19 +154,19 @@ class _Added { builders.add(new _AddBuilder( name, declaration, fragment.fileUri, charOffset)); }), - fragment.interfaces, + interfaceBuilders: fragment.interfaces, // TODO(johnniwinther): Add the `on` clause types of a mixin // declaration here. - /* onTypes = */ null, - fragment.typeParameterScope, - fragment.toDeclarationNameSpaceBuilder(), - enclosingLibraryBuilder, - fragment.constructorReferences, - fragment.fileUri, - fragment.startOffset, - fragment.charOffset, - fragment.endOffset, - indexedClass, + onTypes: null, + typeParameterScope: fragment.typeParameterScope, + nameSpaceBuilder: fragment.toDeclarationNameSpaceBuilder(), + libraryBuilder: enclosingLibraryBuilder, + constructorReferences: fragment.constructorReferences, + fileUri: fragment.fileUri, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + endOffset: fragment.endOffset, + indexedClass: indexedClass, isMixinDeclaration: true); fragment.builder = mixinBuilder; fragment.bodyScope.declarationBuilder = mixinBuilder; @@ -188,9 +188,9 @@ class _Added { supertype: fragment.supertype, mixinApplicationBuilder: fragment.mixins, mixinApplications: mixinApplications, - startCharOffset: fragment.startCharOffset, - charOffset: fragment.charOffset, - charEndOffset: fragment.charEndOffset, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + endOffset: fragment.endOffset, subclassName: fragment.name, isMixinDeclaration: false, metadata: fragment.metadata, @@ -212,11 +212,11 @@ class _Added { IndexedClass? indexedClass = indexedLibrary?.lookupIndexedClass(fragment.name); SourceEnumBuilder enumBuilder = new SourceEnumBuilder( - fragment.metadata, - fragment.name, - fragment.typeParameters, - loader.target.underscoreEnumType, - BuilderFactoryImpl.applyMixins( + metadata: fragment.metadata, + name: fragment.name, + typeVariables: fragment.typeParameters, + underscoreEnumTypeBuilder: loader.target.underscoreEnumType, + supertypeBuilder: BuilderFactoryImpl.applyMixins( unboundNominalVariables: unboundNominalVariables, compilationUnitScope: fragment.compilationUnitScope, problemReporting: problemReporting, @@ -227,9 +227,9 @@ class _Added { supertype: loader.target.underscoreEnumType, mixinApplicationBuilder: fragment.supertypeBuilder, mixinApplications: mixinApplications, - startCharOffset: fragment.startCharOffset, - charOffset: fragment.charOffset, - charEndOffset: fragment.charEndOffset, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + endOffset: fragment.endOffset, subclassName: fragment.name, isMixinDeclaration: false, typeVariables: fragment.typeParameters, @@ -243,17 +243,17 @@ class _Added { builders.add(new _AddBuilder( name, declaration, fragment.fileUri, charOffset)); }), - fragment.interfaces, - fragment.enumConstantInfos, - enclosingLibraryBuilder, - fragment.constructorReferences, - fragment.fileUri, - fragment.startCharOffset, - fragment.charOffset, - fragment.charEndOffset, - indexedClass, - fragment.typeParameterScope, - fragment.toDeclarationNameSpaceBuilder()); + interfaceBuilders: fragment.interfaces, + enumConstantInfos: fragment.enumConstantInfos, + libraryBuilder: enclosingLibraryBuilder, + constructorReferences: fragment.constructorReferences, + fileUri: fragment.fileUri, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + endOffset: fragment.endOffset, + indexedClass: indexedClass, + typeParameterScope: fragment.typeParameterScope, + nameSpaceBuilder: fragment.toDeclarationNameSpaceBuilder()); fragment.builder = enumBuilder; fragment.bodyScope.declarationBuilder = enumBuilder; builders.add(new _AddBuilder( @@ -271,7 +271,7 @@ class _Added { enclosingLibraryBuilder: enclosingLibraryBuilder, fileUri: fragment.fileUri, startOffset: fragment.startOffset, - nameOffset: fragment.nameOffset, + nameOffset: fragment.nameOrExtensionOffset, endOffset: fragment.endOffset, fragment: fragment, reference: reference); @@ -464,28 +464,29 @@ class _Added { } SourceProcedureBuilder procedureBuilder = new SourceProcedureBuilder( - fragment.metadata, - fragment.modifiers, - fragment.returnType, - name, - fragment.typeParameters, - fragment.formals, - kind, - enclosingLibraryBuilder, - declarationBuilder, - fragment.fileUri, - fragment.startCharOffset, - fragment.charOffset, - fragment.charOpenParenOffset, - fragment.charEndOffset, - procedureReference, - /* tearOffReference = */ null, - fragment.asyncModifier, - nameScheme, + metadata: fragment.metadata, + modifiers: fragment.modifiers, + returnType: fragment.returnType, + name: name, + typeVariables: fragment.typeParameters, + formals: fragment.formals, + kind: kind, + libraryBuilder: enclosingLibraryBuilder, + declarationBuilder: declarationBuilder, + fileUri: fragment.fileUri, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + // TODO(johnniwinther): Avoid formals offset on getter. + formalsOffset: fragment.formalsOffset, + endOffset: fragment.endOffset, + procedureReference: procedureReference, + tearOffReference: null, + asyncModifier: fragment.asyncModifier, + nameScheme: nameScheme, nativeMethodName: fragment.nativeMethodName); fragment.builder = procedureBuilder; builders.add(new _AddBuilder(fragment.name, procedureBuilder, - fragment.fileUri, fragment.charOffset)); + fragment.fileUri, fragment.nameOffset)); if (procedureReference != null) { loader.buildersCreatedWithReferences[procedureReference] = procedureBuilder; @@ -529,28 +530,28 @@ class _Added { } SourceProcedureBuilder procedureBuilder = new SourceProcedureBuilder( - fragment.metadata, - fragment.modifiers, - fragment.returnType, - name, - fragment.typeParameters, - fragment.formals, - kind, - enclosingLibraryBuilder, - declarationBuilder, - fragment.fileUri, - fragment.startCharOffset, - fragment.charOffset, - fragment.charOpenParenOffset, - fragment.charEndOffset, - procedureReference, - /* tearOffReference = */ null, - fragment.asyncModifier, - nameScheme, + metadata: fragment.metadata, + modifiers: fragment.modifiers, + returnType: fragment.returnType, + name: name, + typeVariables: fragment.typeParameters, + formals: fragment.formals, + kind: kind, + libraryBuilder: enclosingLibraryBuilder, + declarationBuilder: declarationBuilder, + fileUri: fragment.fileUri, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + formalsOffset: fragment.formalsOffset, + endOffset: fragment.endOffset, + procedureReference: procedureReference, + tearOffReference: null, + asyncModifier: fragment.asyncModifier, + nameScheme: nameScheme, nativeMethodName: fragment.nativeMethodName); fragment.builder = procedureBuilder; builders.add(new _AddBuilder(fragment.name, procedureBuilder, - fragment.fileUri, fragment.charOffset)); + fragment.fileUri, fragment.nameOffset)); if (procedureReference != null) { loader.buildersCreatedWithReferences[procedureReference] = procedureBuilder; @@ -594,28 +595,28 @@ class _Added { } SourceProcedureBuilder procedureBuilder = new SourceProcedureBuilder( - fragment.metadata, - fragment.modifiers, - fragment.returnType, - name, - fragment.typeParameters, - fragment.formals, - kind, - enclosingLibraryBuilder, - declarationBuilder, - fragment.fileUri, - fragment.startCharOffset, - fragment.charOffset, - fragment.charOpenParenOffset, - fragment.charEndOffset, - procedureReference, - tearOffReference, - fragment.asyncModifier, - nameScheme, + metadata: fragment.metadata, + modifiers: fragment.modifiers, + returnType: fragment.returnType, + name: name, + typeVariables: fragment.typeParameters, + formals: fragment.formals, + kind: kind, + libraryBuilder: enclosingLibraryBuilder, + declarationBuilder: declarationBuilder, + fileUri: fragment.fileUri, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + formalsOffset: fragment.formalsOffset, + endOffset: fragment.endOffset, + procedureReference: procedureReference, + tearOffReference: tearOffReference, + asyncModifier: fragment.asyncModifier, + nameScheme: nameScheme, nativeMethodName: fragment.nativeMethodName); fragment.builder = procedureBuilder; builders.add(new _AddBuilder(fragment.name, procedureBuilder, - fragment.fileUri, fragment.charOffset)); + fragment.fileUri, fragment.nameOffset)); if (procedureReference != null) { loader.buildersCreatedWithReferences[procedureReference] = procedureBuilder; @@ -653,10 +654,10 @@ class _Added { libraryBuilder: enclosingLibraryBuilder, declarationBuilder: declarationBuilder, fileUri: fragment.fileUri, - startCharOffset: fragment.startCharOffset, - charOffset: fragment.charOffset, - charOpenParenOffset: fragment.charOpenParenOffset, - charEndOffset: fragment.charEndOffset, + startOffset: fragment.startOffset, + fileOffset: fragment.nameOffset, + formalsOffset: fragment.formalsOffset, + endOffset: fragment.endOffset, constructorReference: constructorReference, tearOffReference: tearOffReference, nameScheme: nameScheme, @@ -674,10 +675,10 @@ class _Added { libraryBuilder: enclosingLibraryBuilder, declarationBuilder: declarationBuilder!, fileUri: fragment.fileUri, - startCharOffset: fragment.startCharOffset, - charOffset: fragment.charOffset, - charOpenParenOffset: fragment.charOpenParenOffset, - charEndOffset: fragment.charEndOffset, + startOffset: fragment.startOffset, + fileOffset: fragment.nameOffset, + formalsOffset: fragment.formalsOffset, + endOffset: fragment.endOffset, constructorReference: constructorReference, tearOffReference: tearOffReference, nameScheme: nameScheme, @@ -687,7 +688,7 @@ class _Added { } fragment.builder = constructorBuilder; builders.add(new _AddBuilder(fragment.name, constructorBuilder, - fragment.fileUri, fragment.charOffset)); + fragment.fileUri, fragment.nameOffset)); // TODO(johnniwinther): There is no way to pass the tear off reference // here. @@ -728,10 +729,11 @@ class _Added { libraryBuilder: enclosingLibraryBuilder, declarationBuilder: declarationBuilder, fileUri: fragment.fileUri, - startCharOffset: fragment.charOffset, - charOffset: fragment.charOffset, - charOpenParenOffset: fragment.charOffset, - charEndOffset: fragment.charOffset, + startOffset: fragment.startOffset, + fileOffset: fragment.fileOffset, + formalsOffset: fragment.formalsOffset, + // TODO(johnniwinther): Provide `endOffset`. + endOffset: fragment.formalsOffset, constructorReference: constructorReference, tearOffReference: tearOffReference, nameScheme: nameScheme, @@ -749,10 +751,11 @@ class _Added { libraryBuilder: enclosingLibraryBuilder, declarationBuilder: declarationBuilder!, fileUri: fragment.fileUri, - startCharOffset: fragment.charOffset, - charOffset: fragment.charOffset, - charOpenParenOffset: fragment.charOffset, - charEndOffset: fragment.charOffset, + startOffset: fragment.startOffset, + fileOffset: fragment.fileOffset, + formalsOffset: fragment.formalsOffset, + // TODO(johnniwinther): Provide `endOffset`. + endOffset: fragment.formalsOffset, constructorReference: constructorReference, tearOffReference: tearOffReference, nameScheme: nameScheme, @@ -761,7 +764,7 @@ class _Added { } fragment.builder = constructorBuilder; builders.add(new _AddBuilder(fragment.name, constructorBuilder, - fragment.fileUri, fragment.charOffset)); + fragment.fileUri, fragment.fileOffset)); // TODO(johnniwinther): There is no way to pass the tear off reference // here. @@ -780,17 +783,17 @@ class _Added { ? new LibraryName(indexedLibrary.library.reference) : enclosingLibraryBuilder.libraryName); - Reference? constructorReference; + Reference? procedureReference; Reference? tearOffReference; if (indexedContainer != null) { - constructorReference = indexedContainer.lookupConstructorReference( + procedureReference = indexedContainer.lookupConstructorReference( nameScheme.getConstructorMemberName(name, isTearOff: false).name); tearOffReference = indexedContainer.lookupGetterReference( nameScheme.getConstructorMemberName(name, isTearOff: true).name); } // Coverage-ignore(suite): Not run. else if (indexedLibrary != null) { - constructorReference = indexedLibrary.lookupGetterReference( + procedureReference = indexedLibrary.lookupGetterReference( nameScheme.getConstructorMemberName(name, isTearOff: false).name); tearOffReference = indexedLibrary.lookupGetterReference( nameScheme.getConstructorMemberName(name, isTearOff: true).name); @@ -799,54 +802,54 @@ class _Added { SourceFactoryBuilder factoryBuilder; if (fragment.redirectionTarget != null) { factoryBuilder = new RedirectingFactoryBuilder( - fragment.metadata, - fragment.modifiers, - fragment.returnType, - name, - fragment.typeParameters, - fragment.formals, - enclosingLibraryBuilder, - declarationBuilder!, - fragment.fileUri, - fragment.startCharOffset, - fragment.charOffset, - fragment.charOpenParenOffset, - fragment.charEndOffset, - constructorReference, - tearOffReference, - nameScheme, - fragment.nativeMethodName, - fragment.redirectionTarget!); + metadata: fragment.metadata, + modifiers: fragment.modifiers, + returnType: fragment.returnType, + name: name, + typeVariables: fragment.typeParameters, + formals: fragment.formals, + libraryBuilder: enclosingLibraryBuilder, + declarationBuilder: declarationBuilder!, + fileUri: fragment.fileUri, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + formalsOffset: fragment.formalsOffset, + endOffset: fragment.endOffset, + procedureReference: procedureReference, + tearOffReference: tearOffReference, + nameScheme: nameScheme, + nativeMethodName: fragment.nativeMethodName, + redirectionTarget: fragment.redirectionTarget!); (enclosingLibraryBuilder.redirectingFactoryBuilders ??= []) .add(factoryBuilder as RedirectingFactoryBuilder); } else { factoryBuilder = new SourceFactoryBuilder( - fragment.metadata, - fragment.modifiers, - fragment.returnType, - name, - fragment.typeParameters, - fragment.formals, - enclosingLibraryBuilder, - declarationBuilder!, - fragment.fileUri, - fragment.startCharOffset, - fragment.charOffset, - fragment.charOpenParenOffset, - fragment.charEndOffset, - constructorReference, - tearOffReference, - fragment.asyncModifier, - nameScheme, + metadata: fragment.metadata, + modifiers: fragment.modifiers, + returnType: fragment.returnType, + name: name, + typeVariables: fragment.typeParameters, + formals: fragment.formals, + libraryBuilder: enclosingLibraryBuilder, + declarationBuilder: declarationBuilder!, + fileUri: fragment.fileUri, + startOffset: fragment.startOffset, + nameOffset: fragment.nameOffset, + formalsOffset: fragment.formalsOffset, + endOffset: fragment.endOffset, + procedureReference: procedureReference, + tearOffReference: tearOffReference, + asyncModifier: fragment.asyncModifier, + nameScheme: nameScheme, nativeMethodName: fragment.nativeMethodName); } fragment.builder = factoryBuilder; builders.add(new _AddBuilder(fragment.name, factoryBuilder, - fragment.fileUri, fragment.charOffset)); + fragment.fileUri, fragment.nameOffset)); // TODO(johnniwinther): There is no way to pass the tear off reference // here. - if (constructorReference != null) { - loader.buildersCreatedWithReferences[constructorReference] = + if (procedureReference != null) { + loader.buildersCreatedWithReferences[procedureReference] = factoryBuilder; } } @@ -919,9 +922,9 @@ class LibraryNameSpaceBuilder { // Coverage-ignore(suite): Not run. declaration.next != existing) { unexpected( - "${declaration.next!.fileUri}@${declaration.next!.charOffset}", - "${existing?.fileUri}@${existing?.charOffset}", - declaration.charOffset, + "${declaration.next!.fileUri}@${declaration.next!.fileOffset}", + "${existing?.fileUri}@${existing?.fileOffset}", + declaration.fileOffset, declaration.fileUri); } declaration.next = existing; @@ -936,7 +939,7 @@ class LibraryNameSpaceBuilder { templateDuplicatedDeclarationCause .withArguments(fullName) .withLocation( - existing!.fileUri!, existing.charOffset, fullName.length) + existing!.fileUri!, existing.fileOffset, fullName.length) ]); } else if (declaration.isExtension) { // We add the extension declaration to the extension scope only if its @@ -1008,11 +1011,11 @@ class NominalParameterNameSpace { _typeParametersByName[tv.name] = tv; } else { _problemReporting.addProblem(messageTypeVariableDuplicatedName, - tv.charOffset, tv.name.length, tv.fileUri, + tv.fileOffset, tv.name.length, tv.fileUri, context: [ templateTypeVariableDuplicatedNameCause .withArguments(tv.name) - .withLocation(existing.fileUri!, existing.charOffset, + .withLocation(existing.fileUri!, existing.fileOffset, existing.name.length) ]); } @@ -1024,7 +1027,7 @@ class NominalParameterNameSpace { // [#54602](https://github.com/dart-lang/sdk/issues/54602). if (tv.name == ownerName && !allowNameConflict) { _problemReporting.addProblem(messageTypeVariableSameNameAsEnclosing, - tv.charOffset, tv.name.length, tv.fileUri); + tv.fileOffset, tv.name.length, tv.fileUri); } } } @@ -1129,9 +1132,9 @@ class DeclarationNameSpaceBuilder { // Coverage-ignore(suite): Not run. declaration.next != existing) { unexpected( - "${declaration.next!.fileUri}@${declaration.next!.charOffset}", - "${existing?.fileUri}@${existing?.charOffset}", - declaration.charOffset, + "${declaration.next!.fileUri}@${declaration.next!.fileOffset}", + "${existing?.fileUri}@${existing?.fileOffset}", + declaration.fileOffset, declaration.fileUri); } declaration.next = existing; @@ -1153,7 +1156,7 @@ class DeclarationNameSpaceBuilder { templateDuplicatedDeclarationCause .withArguments(fullName) .withLocation( - existing!.fileUri!, existing.charOffset, fullName.length) + existing!.fileUri!, existing.fileOffset, fullName.length) ]); } else if (declaration.isAugment) { // Coverage-ignore-block(suite): Not run. @@ -1178,12 +1181,12 @@ class DeclarationNameSpaceBuilder { if (tv != null) { _problemReporting.addProblem( templateConflictsWithTypeVariable.withArguments(name), - member.charOffset, + member.fileOffset, name.length, fileUri, context: [ messageConflictsWithTypeVariableCause.withLocation( - tv.fileUri!, tv.charOffset, name.length) + tv.fileUri!, tv.fileOffset, name.length) ]); } } diff --git a/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart b/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart index 0f06d5f3f599..15156c1b4597 100644 --- a/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart +++ b/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart @@ -3976,7 +3976,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor { .map((ExtensionAccessCandidate c) => messageAmbiguousExtensionCause.withLocation( c.memberBuilder.fileUri!, - c.memberBuilder.charOffset, + c.memberBuilder.fileOffset, name == unaryMinusName ? 1 : c.memberBuilder.name.length)) .toList(); template = ambiguousTemplate; @@ -4504,7 +4504,7 @@ class _WhyNotPromotedVisitor reason.propertyName, field.readTarget.enclosingClass!.name, NonPromotionDocumentationLink.conflictingNonPromotableField.url) - .withLocation(field.fileUri, field.charOffset, noLength)); + .withLocation(field.fileUri, field.fileOffset, noLength)); } for (SourceProcedureBuilder getter in fieldNameInfo.conflictingGetters) { messages.add(templateFieldNotPromotedBecauseConflictingGetter @@ -4512,7 +4512,7 @@ class _WhyNotPromotedVisitor reason.propertyName, getter.procedure.enclosingClass!.name, NonPromotionDocumentationLink.conflictingGetter.url) - .withLocation(getter.fileUri, getter.charOffset, noLength)); + .withLocation(getter.fileUri, getter.fileOffset, noLength)); } for (Class nsmClass in fieldNameInfo.conflictingNsmClasses) { messages.add(templateFieldNotPromotedBecauseConflictingNsmForwarder diff --git a/pkg/front_end/test/coverage_suite_expected.dart b/pkg/front_end/test/coverage_suite_expected.dart index ead482669adc..03f5369b0379 100644 --- a/pkg/front_end/test/coverage_suite_expected.dart +++ b/pkg/front_end/test/coverage_suite_expected.dart @@ -530,7 +530,7 @@ const Map _expect = { ), // 100.0%. "package:front_end/src/fragment/primary_constructor.dart": ( - hitCount: 41, + hitCount: 44, missCount: 0, ), // 100.0%. @@ -865,7 +865,7 @@ const Map _expect = { ), // 100.0%. "package:front_end/src/source/source_builder_factory.dart": ( - hitCount: 1266, + hitCount: 1261, missCount: 0, ), // 100.0%. @@ -875,7 +875,7 @@ const Map _expect = { ), // 100.0%. "package:front_end/src/source/source_class_builder.dart": ( - hitCount: 1261, + hitCount: 1263, missCount: 0, ), // 100.0%. @@ -890,7 +890,7 @@ const Map _expect = { ), // 100.0%. "package:front_end/src/source/source_enum_builder.dart": ( - hitCount: 517, + hitCount: 515, missCount: 0, ), // 100.0%. @@ -906,7 +906,7 @@ const Map _expect = { ), // 100.0%. "package:front_end/src/source/source_factory_builder.dart": ( - hitCount: 586, + hitCount: 588, missCount: 0, ), // 100.0%. @@ -936,7 +936,7 @@ const Map _expect = { ), // 100.0%. "package:front_end/src/source/source_procedure_builder.dart": ( - hitCount: 524, + hitCount: 528, missCount: 0, ), // 100.0%. @@ -986,7 +986,7 @@ const Map _expect = { ), // 100.0%. "package:front_end/src/type_inference/inference_visitor.dart": ( - hitCount: 8218, + hitCount: 8222, missCount: 0, ), // 100.0%. diff --git a/pkg/front_end/test/macros/application/macro_application_test.dart b/pkg/front_end/test/macros/application/macro_application_test.dart index 04c222791e93..4c297b94f7da 100644 --- a/pkg/front_end/test/macros/application/macro_application_test.dart +++ b/pkg/front_end/test/macros/application/macro_application_test.dart @@ -265,7 +265,7 @@ class MacroDataComputer extends CfeDataComputer { lookupMemberBuilder(testResultData.compilerResult, member)!; if (resultsText.isNotEmpty) { registry.registerValue(memberBuilder.fileUri!, - memberBuilder.charOffset, id, '\n$resultsText', member); + memberBuilder.fileOffset, id, '\n$resultsText', member); } } }