Skip to content

Commit

Permalink
[cfe] Create fields through SourcePropertyBuilder
Browse files Browse the repository at this point in the history
Change-Id: I20c9dd7baa705aba77d90b94ba0a46ed64eb02ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403600
Commit-Queue: Johnni Winther <[email protected]>
Reviewed-by: Chloe Stefantsova <[email protected]>
  • Loading branch information
johnniwinther authored and Commit Queue committed Jan 9, 2025
1 parent ad562fd commit a6b99af
Show file tree
Hide file tree
Showing 40 changed files with 3,310 additions and 468 deletions.
5 changes: 3 additions & 2 deletions pkg/front_end/lib/src/base/incremental_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import '../base/processed_options.dart' show ProcessedOptions;
import '../builder/builder.dart' show Builder;
import '../builder/declaration_builders.dart'
show ClassBuilder, ExtensionBuilder, ExtensionTypeDeclarationBuilder;
import '../builder/field_builder.dart' show FieldBuilder;
import '../builder/library_builder.dart'
show CompilationUnit, LibraryBuilder, SourceCompilationUnit;
import '../builder/member_builder.dart' show MemberBuilder;
Expand Down Expand Up @@ -741,7 +740,9 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
if (sourceBuilder == null) {
sourceBuilder = sourceLibraryBuilder.exportNameSpace
.lookupLocalMember(name, setter: false);
if (sourceBuilder is FieldBuilder && sourceBuilder.isAssignable) {
if (sourceBuilder is MemberBuilder &&
sourceBuilder.isField &&
sourceBuilder.isAssignable) {
// Assignable fields can be lowered into a getter and setter.
return;
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/front_end/lib/src/base/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,14 @@ mixin ErroneousMemberBuilderMixin implements SourceMemberBuilder {
// Coverage-ignore(suite): Not run.
bool get isAbstract => false;

@override
// Coverage-ignore(suite): Not run.
bool get isFinal => false;

@override
// Coverage-ignore(suite): Not run.
bool get isSynthesized => false;

@override
bool get isConflictingSetter => false;

Expand Down Expand Up @@ -1503,8 +1511,9 @@ extension on Builder {
return _hasPatchAnnotation(self.metadata);
} else if (self is SourceMethodBuilder) {
return _hasPatchAnnotation(self.metadata);
} else if (self is SourceExtensionTypeDeclarationBuilder) {
// Coverage-ignore-block(suite): Not run.
}
// Coverage-ignore(suite): Not run.
else if (self is SourceExtensionTypeDeclarationBuilder) {
return _hasPatchAnnotation(self.metadata);
}
return false;
Expand Down
9 changes: 4 additions & 5 deletions pkg/front_end/lib/src/builder/builder_mixins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import '../base/problems.dart';
import '../base/scope.dart';
import 'builder.dart';
import 'declaration_builders.dart';
import 'field_builder.dart';
import 'library_builder.dart';
import 'member_builder.dart';
import 'nullability_builder.dart';
Expand Down Expand Up @@ -96,16 +95,16 @@ mixin DeclarationBuilderMixin implements IDeclarationBuilder {
if (builder == null && setter) {
// When looking up setters, we include assignable fields.
builder = lookupLocalMember(name.text, setter: false, required: required);
if (builder is! FieldBuilder || !builder.isAssignable) {
if (builder is! MemberBuilder ||
!builder.isField ||
!builder.isAssignable) {
builder = null;
}
}
if (builder != null) {
if (name.isPrivate && libraryBuilder.library != name.library) {
builder = null;
} else if (builder is FieldBuilder &&
!builder.isStatic &&
!builder.isExternal) {
} else if (builder.isField && !builder.isStatic && !builder.isExternal) {
// Non-external extension instance fields are invalid.
builder = null;
} else if (builder.isDuplicate) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/front_end/lib/src/builder/formal_parameter_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import '../kernel/wildcard_lowering.dart';
import '../source/builder_factory.dart';
import '../source/constructor_declaration.dart';
import '../source/source_factory_builder.dart';
import '../source/source_field_builder.dart';
import '../source/source_library_builder.dart';
import 'builder.dart';
import 'constructor_builder.dart';
import 'declaration_builders.dart';
import 'member_builder.dart';
import 'omitted_type_builder.dart';
import 'property_builder.dart';
import 'type_builder.dart';
import 'variable_builder.dart';

Expand Down Expand Up @@ -229,7 +229,7 @@ class FormalParameterBuilder extends BuilderImpl
ClassHierarchyBase hierarchy) {
String fieldName = isWildcardLoweredFormalParameter(name) ? '_' : name;
Builder? fieldBuilder = declarationBuilder.lookupLocalMember(fieldName);
if (fieldBuilder is SourceFieldBuilder) {
if (fieldBuilder is PropertyBuilder && fieldBuilder.isField) {
DartType fieldType = fieldBuilder.inferType(hierarchy);
fieldType = constructorDeclaration.substituteFieldType(fieldType);
type.registerInferredType(fieldType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class InvalidTypeDeclarationBuilder extends TypeDeclarationBuilderImpl

@override
// Coverage-ignore(suite): Not run.
Uri? get fileUri => message.uri;
Uri get fileUri => message.uri!;

@override
DartType buildAliasedType(
Expand Down
4 changes: 4 additions & 0 deletions pkg/front_end/lib/src/builder/member_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ abstract class BuilderClassMember implements ClassMember {
Uri get fileUri => memberBuilder.fileUri;

@override
// Coverage-ignore(suite): Not run.
bool get isExtensionTypeMember => memberBuilder.isExtensionTypeMember;

@override
Expand All @@ -206,6 +207,7 @@ abstract class BuilderClassMember implements ClassMember {
bool get isDuplicate => memberBuilder.isDuplicate;

@override
// Coverage-ignore(suite): Not run.
bool get isField => memberBuilder.isField;

@override
Expand All @@ -231,9 +233,11 @@ abstract class BuilderClassMember implements ClassMember {
bool get isSynthesized => false;

@override
// Coverage-ignore(suite): Not run.
bool get isInternalImplementation => false;

@override
// Coverage-ignore(suite): Not run.
bool get isNoSuchMethodForwarder => false;

@override
Expand Down
41 changes: 41 additions & 0 deletions pkg/front_end/lib/src/builder/property_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2025, 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.

import 'package:kernel/ast.dart';
import 'package:kernel/class_hierarchy.dart';

import 'member_builder.dart';

abstract class PropertyBuilder implements MemberBuilder {
bool get hasInitializer;

@override
Uri get fileUri;

bool get isExtensionTypeDeclaredInstanceField;

bool get isLate;

bool get isFinal;

abstract DartType fieldType;

DartType inferType(ClassHierarchyBase hierarchy);

/// Builds the field initializers for each field used to encode this field
/// using the [fileOffset] for the created nodes and [value] as the initial
/// field value.
List<Initializer> buildInitializer(int fileOffset, Expression value,
{required bool isSynthetic});

/// Creates the AST node for this field as the default initializer.
void buildImplicitDefaultValue();

/// Create the [Initializer] for the implicit initialization of this field
/// in a constructor.
Initializer buildImplicitInitializer();

Initializer buildErroneousInitializer(Expression effect, Expression value,
{required int fileOffset});
}
Loading

0 comments on commit a6b99af

Please sign in to comment.