Skip to content

Commit

Permalink
Version 3.7.0-36.0.dev
Browse files Browse the repository at this point in the history
Merge 66f0fc6 into dev
  • Loading branch information
Dart CI committed Oct 17, 2024
2 parents 95fe32c + 66f0fc6 commit 3413267
Show file tree
Hide file tree
Showing 32 changed files with 1,010 additions and 220 deletions.
63 changes: 62 additions & 1 deletion pkg/front_end/lib/src/fragment/constructor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

part of 'fragment.dart';

class ConstructorFragment implements Fragment {
class ConstructorFragment implements Fragment, FunctionFragment {
final String name;
final Uri fileUri;
final int startCharOffset;
Expand Down Expand Up @@ -57,6 +57,67 @@ class ConstructorFragment implements Fragment {
_builder = value;
}

@override
FunctionBodyBuildingContext createFunctionBodyBuildingContext() {
return new _ConstructorBodyBuildingContext(this);
}

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

class _ConstructorBodyBuildingContext implements FunctionBodyBuildingContext {
ConstructorFragment _fragment;

_ConstructorBodyBuildingContext(this._fragment);

@override
// TODO(johnniwinther): This matches what is passed when parsing, but seems
// odd given that it used to allow 'covariant' modifiers, which shouldn't be
// allowed on constructors.
MemberKind get memberKind => MemberKind.NonStaticMethod;

@override
bool get shouldBuild =>
// TODO(johnniwinther): Ensure building of const extension type
// constructor body. An error is reported by the parser but we skip
// the body here to avoid overwriting the already lowering const
// constructor.
!(_fragment.builder is SourceExtensionTypeConstructorBuilder &&
_fragment.modifiers.isConst);

@override
LocalScope computeFormalParameterScope(LookupScope typeParameterScope) {
return _fragment.builder.computeFormalParameterScope(typeParameterScope);
}

@override
LookupScope computeTypeParameterScope(LookupScope enclosingScope) {
return _fragment.builder.computeTypeParameterScope(enclosingScope);
}

@override
BodyBuilderContext createBodyBuilderContext(
{required bool inOutlineBuildingPhase,
required bool inMetadata,
required bool inConstFields}) {
return _fragment.builder.createBodyBuilderContext(
inOutlineBuildingPhase: inOutlineBuildingPhase,
inMetadata: inMetadata,
inConstFields: inConstFields);
}

@override
InferenceDataForTesting? get inferenceDataForTesting => _fragment
.builder
.dataForTesting
// Coverage-ignore(suite): Not run.
?.inferenceData;

@override
List<TypeParameter>? get thisTypeParameters =>
_fragment.builder.thisTypeParameters;

@override
VariableDeclaration? get thisVariable => _fragment.builder.thisVariable;
}
55 changes: 54 additions & 1 deletion pkg/front_end/lib/src/fragment/factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

part of 'fragment.dart';

class FactoryFragment implements Fragment {
class FactoryFragment implements Fragment, FunctionFragment {
final String name;
final Uri fileUri;
final int startCharOffset;
Expand Down Expand Up @@ -49,6 +49,59 @@ class FactoryFragment implements Fragment {
_builder = value;
}

@override
FunctionBodyBuildingContext createFunctionBodyBuildingContext() {
return new _FactoryBodyBuildingContext(this);
}

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

class _FactoryBodyBuildingContext implements FunctionBodyBuildingContext {
FactoryFragment _fragment;

_FactoryBodyBuildingContext(this._fragment);

@override
// Coverage-ignore(suite): Not run.
MemberKind get memberKind => MemberKind.Factory;

@override
bool get shouldBuild => true;

@override
LocalScope computeFormalParameterScope(LookupScope typeParameterScope) {
return _fragment.builder.computeFormalParameterScope(typeParameterScope);
}

@override
LookupScope computeTypeParameterScope(LookupScope enclosingScope) {
return _fragment.builder.computeTypeParameterScope(enclosingScope);
}

@override
BodyBuilderContext createBodyBuilderContext(
{required bool inOutlineBuildingPhase,
required bool inMetadata,
required bool inConstFields}) {
return _fragment.builder.createBodyBuilderContext(
inOutlineBuildingPhase: inOutlineBuildingPhase,
inMetadata: inMetadata,
inConstFields: inConstFields);
}

@override
InferenceDataForTesting? get inferenceDataForTesting => _fragment
.builder
.dataForTesting
// Coverage-ignore(suite): Not run.
?.inferenceData;

@override
List<TypeParameter>? get thisTypeParameters =>
_fragment.builder.thisTypeParameters;

@override
VariableDeclaration? get thisVariable => _fragment.builder.thisVariable;
}
6 changes: 6 additions & 0 deletions pkg/front_end/lib/src/fragment/fragment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:_fe_analyzer_shared/src/scanner/scanner.dart' show Token;
import 'package:_fe_analyzer_shared/src/parser/member_kind.dart';
import 'package:kernel/ast.dart';

import '../base/local_scope.dart';
import '../base/modifiers.dart';
import '../base/scope.dart';
import '../builder/builder.dart';
Expand All @@ -14,6 +16,7 @@ import '../builder/formal_parameter_builder.dart';
import '../builder/metadata_builder.dart';
import '../builder/mixin_application_builder.dart';
import '../builder/type_builder.dart';
import '../kernel/body_builder_context.dart';
import '../source/name_scheme.dart';
import '../source/source_class_builder.dart';
import '../source/source_constructor_builder.dart';
Expand All @@ -25,6 +28,7 @@ import '../source/source_field_builder.dart';
import '../source/source_procedure_builder.dart';
import '../source/source_type_alias_builder.dart';
import '../source/type_parameter_scope_builder.dart';
import '../type_inference/type_inference_engine.dart';

part 'class.dart';
part 'constructor.dart';
Expand All @@ -33,10 +37,12 @@ part 'extension.dart';
part 'extension_type.dart';
part 'factory.dart';
part 'field.dart';
part 'function.dart';
part 'getter.dart';
part 'method.dart';
part 'mixin.dart';
part 'named_mixin_application.dart';
part 'primary_constructor.dart';
part 'setter.dart';
part 'typedef.dart';

Expand Down
35 changes: 35 additions & 0 deletions pkg/front_end/lib/src/fragment/function.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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';

/// A fragment with function syntax, i.e. a method, getter, setter, constructor,
/// or factory.
sealed class FunctionFragment {
FunctionBodyBuildingContext createFunctionBodyBuildingContext();
}

abstract class FunctionBodyBuildingContext {
/// Returns the [MemberKind] for the function body being built.
MemberKind get memberKind;

/// Returns `true` if the function body should be built.
// TODO(johnniwinther): Avoid the need for this.
bool get shouldBuild;

BodyBuilderContext createBodyBuilderContext(
{required bool inOutlineBuildingPhase,
required bool inMetadata,
required bool inConstFields});

LookupScope computeTypeParameterScope(LookupScope enclosingScope);

LocalScope computeFormalParameterScope(LookupScope typeParameterScope);

VariableDeclaration? get thisVariable;

List<TypeParameter>? get thisTypeParameters;

InferenceDataForTesting? get inferenceDataForTesting;
}
60 changes: 59 additions & 1 deletion pkg/front_end/lib/src/fragment/getter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

part of 'fragment.dart';

class GetterFragment implements Fragment {
class GetterFragment implements Fragment, FunctionFragment {
final String name;
final Uri fileUri;
final int startCharOffset;
final int charOffset;
final int charOpenParenOffset;
final int charEndOffset;
final bool isTopLevel;
final List<MetadataBuilder>? metadata;
final Modifiers modifiers;
final TypeBuilder returnType;
Expand All @@ -28,6 +29,7 @@ class GetterFragment implements Fragment {
required this.charOffset,
required this.charOpenParenOffset,
required this.charEndOffset,
required this.isTopLevel,
required this.metadata,
required this.modifiers,
required this.returnType,
Expand All @@ -47,6 +49,62 @@ class GetterFragment implements Fragment {
_builder = value;
}

@override
FunctionBodyBuildingContext createFunctionBodyBuildingContext() {
return new _GetterBodyBuildingContext(this);
}

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

class _GetterBodyBuildingContext implements FunctionBodyBuildingContext {
GetterFragment _fragment;

_GetterBodyBuildingContext(this._fragment);

@override
MemberKind get memberKind => _fragment.isTopLevel
? MemberKind.TopLevelMethod
: (_fragment.modifiers.isStatic
? MemberKind.StaticMethod
: MemberKind.NonStaticMethod);

@override
bool get shouldBuild => true;

@override
LocalScope computeFormalParameterScope(LookupScope typeParameterScope) {
return _fragment.builder.computeFormalParameterScope(typeParameterScope);
}

@override
LookupScope computeTypeParameterScope(LookupScope enclosingScope) {
return _fragment.builder.computeTypeParameterScope(enclosingScope);
}

@override
BodyBuilderContext createBodyBuilderContext(
{required bool inOutlineBuildingPhase,
required bool inMetadata,
required bool inConstFields}) {
return _fragment.builder.createBodyBuilderContext(
inOutlineBuildingPhase: inOutlineBuildingPhase,
inMetadata: inMetadata,
inConstFields: inConstFields);
}

@override
InferenceDataForTesting? get inferenceDataForTesting => _fragment
.builder
.dataForTesting
// Coverage-ignore(suite): Not run.
?.inferenceData;

@override
List<TypeParameter>? get thisTypeParameters =>
_fragment.builder.thisTypeParameters;

@override
VariableDeclaration? get thisVariable => _fragment.builder.thisVariable;
}
60 changes: 59 additions & 1 deletion pkg/front_end/lib/src/fragment/method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

part of 'fragment.dart';

class MethodFragment implements Fragment {
class MethodFragment implements Fragment, FunctionFragment {
final String name;
final Uri fileUri;
final int startCharOffset;
final int charOffset;
final int charOpenParenOffset;
final int charEndOffset;
final bool isTopLevel;
final List<MetadataBuilder>? metadata;
final Modifiers modifiers;
final TypeBuilder returnType;
Expand All @@ -29,6 +30,7 @@ class MethodFragment implements Fragment {
required this.charOffset,
required this.charOpenParenOffset,
required this.charEndOffset,
required this.isTopLevel,
required this.metadata,
required this.modifiers,
required this.returnType,
Expand All @@ -49,6 +51,62 @@ class MethodFragment implements Fragment {
_builder = value;
}

@override
FunctionBodyBuildingContext createFunctionBodyBuildingContext() {
return new _MethodBodyBuildingContext(this);
}

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

class _MethodBodyBuildingContext implements FunctionBodyBuildingContext {
MethodFragment _fragment;

_MethodBodyBuildingContext(this._fragment);

@override
MemberKind get memberKind => _fragment.isTopLevel
? MemberKind.TopLevelMethod
: (_fragment.modifiers.isStatic
? MemberKind.StaticMethod
: MemberKind.NonStaticMethod);

@override
bool get shouldBuild => true;

@override
LocalScope computeFormalParameterScope(LookupScope typeParameterScope) {
return _fragment.builder.computeFormalParameterScope(typeParameterScope);
}

@override
LookupScope computeTypeParameterScope(LookupScope enclosingScope) {
return _fragment.builder.computeTypeParameterScope(enclosingScope);
}

@override
BodyBuilderContext createBodyBuilderContext(
{required bool inOutlineBuildingPhase,
required bool inMetadata,
required bool inConstFields}) {
return _fragment.builder.createBodyBuilderContext(
inOutlineBuildingPhase: inOutlineBuildingPhase,
inMetadata: inMetadata,
inConstFields: inConstFields);
}

@override
InferenceDataForTesting? get inferenceDataForTesting => _fragment
.builder
.dataForTesting
// Coverage-ignore(suite): Not run.
?.inferenceData;

@override
List<TypeParameter>? get thisTypeParameters =>
_fragment.builder.thisTypeParameters;

@override
VariableDeclaration? get thisVariable => _fragment.builder.thisVariable;
}
Loading

0 comments on commit 3413267

Please sign in to comment.