Skip to content

Commit

Permalink
Version 3.7.0-83.0.dev
Browse files Browse the repository at this point in the history
Merge 1d7b790 into dev
  • Loading branch information
Dart CI committed Oct 30, 2024
2 parents 4d91906 + 1d7b790 commit 36aed36
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 123 deletions.
14 changes: 8 additions & 6 deletions pkg/front_end/lib/src/fragment/constructor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
part of 'fragment.dart';

class ConstructorFragment implements Fragment, FunctionFragment {
@override
final String name;
final ConstructorName constructorName;

final Uri fileUri;
final int startOffset;
final int nameOffset;
final int formalsOffset;
final int endOffset;
final Modifiers modifiers;
Expand All @@ -26,10 +24,9 @@ class ConstructorFragment implements Fragment, FunctionFragment {
AbstractSourceConstructorBuilder? _builder;

ConstructorFragment(
{required this.name,
{required this.constructorName,
required this.fileUri,
required this.startOffset,
required this.nameOffset,
required this.formalsOffset,
required this.endOffset,
required this.modifiers,
Expand All @@ -43,6 +40,11 @@ class ConstructorFragment implements Fragment, FunctionFragment {
required Token? beginInitializers})
: _beginInitializers = beginInitializers;

@override
String get name => constructorName.name;

int get fullNameOffset => constructorName.fullNameOffset;

Token? get beginInitializers {
Token? result = _beginInitializers;
// Ensure that we don't hold onto the token.
Expand All @@ -67,7 +69,7 @@ class ConstructorFragment implements Fragment, FunctionFragment {
}

@override
String toString() => '$runtimeType($name,$fileUri,$nameOffset)';
String toString() => '$runtimeType($name,$fileUri,$fullNameOffset)';
}

class _ConstructorBodyBuildingContext implements FunctionBodyBuildingContext {
Expand Down
14 changes: 8 additions & 6 deletions pkg/front_end/lib/src/fragment/factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
part of 'fragment.dart';

class FactoryFragment implements Fragment, FunctionFragment {
@override
final String name;
final ConstructorName constructorName;

final Uri fileUri;
final int startOffset;
final int nameOffset;
final int formalsOffset;
final int endOffset;
final Modifiers modifiers;
Expand All @@ -26,10 +24,9 @@ class FactoryFragment implements Fragment, FunctionFragment {
SourceFactoryBuilder? _builder;

FactoryFragment(
{required this.name,
{required this.constructorName,
required this.fileUri,
required this.startOffset,
required this.nameOffset,
required this.formalsOffset,
required this.endOffset,
required this.modifiers,
Expand All @@ -42,6 +39,11 @@ class FactoryFragment implements Fragment, FunctionFragment {
required this.nativeMethodName,
required this.redirectionTarget});

@override
String get name => constructorName.name;

int get fullNameOffset => constructorName.fullNameOffset;

@override
SourceFactoryBuilder get builder {
assert(_builder != null, "Builder has not been computed for $this.");
Expand All @@ -59,7 +61,7 @@ class FactoryFragment implements Fragment, FunctionFragment {
}

@override
String toString() => '$runtimeType($name,$fileUri,$nameOffset)';
String toString() => '$runtimeType($name,$fileUri,$fullNameOffset)';
}

class _FactoryBodyBuildingContext implements FunctionBodyBuildingContext {
Expand Down
1 change: 1 addition & 0 deletions pkg/front_end/lib/src/fragment/fragment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ part 'named_mixin_application.dart';
part 'primary_constructor.dart';
part 'setter.dart';
part 'typedef.dart';
part 'util.dart';

sealed class Fragment {
/// The declared name of this fragment.
Expand Down
12 changes: 6 additions & 6 deletions pkg/front_end/lib/src/fragment/primary_constructor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
part of 'fragment.dart';

class PrimaryConstructorFragment implements Fragment, FunctionFragment {
@override
final String name;
final ConstructorName constructorName;

final Uri fileUri;
final int startOffset;
final int? nameOffset;
final int formalsOffset;
final Modifiers modifiers;
final OmittedTypeBuilder returnType;
Expand All @@ -23,10 +21,9 @@ class PrimaryConstructorFragment implements Fragment, FunctionFragment {
AbstractSourceConstructorBuilder? _builder;

PrimaryConstructorFragment(
{required this.name,
{required this.constructorName,
required this.fileUri,
required this.startOffset,
required this.nameOffset,
required this.formalsOffset,
required this.modifiers,
required this.returnType,
Expand All @@ -37,7 +34,10 @@ class PrimaryConstructorFragment implements Fragment, FunctionFragment {
required Token? beginInitializers})
: _beginInitializers = beginInitializers;

int get fileOffset => nameOffset ?? formalsOffset;
@override
String get name => constructorName.name;

int get fileOffset => constructorName.nameOffset ?? formalsOffset;

Token? get beginInitializers {
Token? result = _beginInitializers;
Expand Down
36 changes: 36 additions & 0 deletions pkg/front_end/lib/src/fragment/util.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of 'fragment.dart';

class ConstructorName {
/// The name of the constructor itself.
///
/// For an unnamed constructor, this is ''.
final String name;

/// The offset of the name of the constructor, if the constructor is not
/// unnamed.
final int? nameOffset;

/// The name of the constructor including the enclosing declaration name.
final String fullName;

/// The offset at which [fullName] occurs.
///
/// This is used in messages to put the `^` at the start of the [fullName].
final int fullNameOffset;

/// The number of characters of [fullName] that occurs at [fullNameOffset].
///
/// This is used in messages to put the right amount of `^` under the name.
final int fullNameLength;

ConstructorName(
{required this.name,
required this.nameOffset,
required this.fullName,
required this.fullNameOffset,
required this.fullNameLength});
}
12 changes: 6 additions & 6 deletions pkg/front_end/lib/src/source/builder_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import '../builder/named_type_builder.dart';
import '../builder/nullability_builder.dart';
import '../builder/omitted_type_builder.dart';
import '../builder/type_builder.dart';
import '../fragment/fragment.dart';
import 'offset_map.dart';
import 'source_class_builder.dart';
import 'source_enum_builder.dart';
Expand Down Expand Up @@ -319,11 +320,10 @@ abstract class BuilderFactory {
required List<MetadataBuilder>? metadata,
required Modifiers modifiers,
required Identifier identifier,
required String constructorName,
required ConstructorName constructorName,
required List<NominalParameterBuilder>? typeParameters,
required List<FormalParameterBuilder>? formals,
required int startOffset,
required int nameOffset,
required int formalsOffset,
required int endOffset,
required String? nativeMethodName,
Expand All @@ -333,7 +333,7 @@ abstract class BuilderFactory {
void addPrimaryConstructor(
{required OffsetMap offsetMap,
required Token beginToken,
required String constructorName,
required String? name,
required List<FormalParameterBuilder>? formals,
required int startOffset,
required int? nameOffset,
Expand All @@ -360,7 +360,7 @@ abstract class BuilderFactory {
required String? nativeMethodName,
required AsyncMarker asyncModifier});

String? computeAndValidateConstructorName(
ConstructorName computeAndValidateConstructorName(
DeclarationFragment enclosingDeclaration, Identifier identifier,
{isFactory = false});

Expand Down Expand Up @@ -500,6 +500,6 @@ class FieldInfo {
final Token? beforeLast;
final int endOffset;

const FieldInfo(this.identifier, this.initializerToken, this.beforeLast,
this.endOffset);
const FieldInfo(
this.identifier, this.initializerToken, this.beforeLast, this.endOffset);
}
6 changes: 3 additions & 3 deletions pkg/front_end/lib/src/source/outline_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1588,12 +1588,12 @@ class OutlineBuilder extends StackListenerImpl {
int? nameOffset;
int formalsOffset = charOffset;

String constructorName = '';
String? name;
if (hasConstructorName) {
// TODO(johnniwinther): Handle [ParserRecovery].
Identifier identifier = pop() as Identifier;
nameOffset = charOffset = identifier.nameOffset;
constructorName = identifier.name;
name = identifier.name;
}

int? startOffset = constKeyword?.charOffset ?? nameOffset ?? formalsOffset;
Expand Down Expand Up @@ -1684,7 +1684,7 @@ class OutlineBuilder extends StackListenerImpl {
_builderFactory.addPrimaryConstructor(
offsetMap: _offsetMap,
beginToken: beginToken,
constructorName: constructorName == "new" ? "" : constructorName,
name: name,
startOffset: startOffset,
nameOffset: nameOffset,
formalsOffset: formalsOffset,
Expand Down
Loading

0 comments on commit 36aed36

Please sign in to comment.