Skip to content

Commit 799dc28

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Create enum values through SourcePropertyBuilder
Change-Id: I52c215cf6af660f8a4329feed528ef0f1254a12d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405005 Reviewed-by: Chloe Stefantsova <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 8f94144 commit 799dc28

File tree

11 files changed

+379
-2645
lines changed

11 files changed

+379
-2645
lines changed

pkg/front_end/lib/src/builder/class_builder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ abstract class ClassBuilderImpl extends DeclarationBuilderImpl
232232
return builder;
233233
}
234234

235+
// Coverage-ignore(suite): Not run.
235236
/// Find the first member of this class with [name]. This method isn't
236237
/// suitable for scope lookups as it will throw an error if the name isn't
237238
/// declared. The [scope] should be used for that. This method is used to

pkg/front_end/lib/src/kernel/body_builder_context.dart

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import '../source/source_enum_builder.dart';
2626
import '../source/source_extension_builder.dart';
2727
import '../source/source_extension_type_declaration_builder.dart';
2828
import '../source/source_factory_builder.dart';
29-
import '../source/source_field_builder.dart';
3029
import '../source/source_function_builder.dart';
3130
import '../source/source_library_builder.dart';
3231
import '../source/source_member_builder.dart';
@@ -740,51 +739,6 @@ mixin _MemberBodyBuilderContext<T extends SourceMemberBuilder>
740739
}
741740
}
742741

743-
class FieldBodyBuilderContext extends BodyBuilderContext
744-
with _MemberBodyBuilderContext<SourceFieldBuilder> {
745-
@override
746-
SourceFieldBuilder _member;
747-
748-
@override
749-
final Member _builtMember;
750-
751-
FieldBodyBuilderContext(this._member, this._builtMember)
752-
: super(_member.libraryBuilder, _member.declarationBuilder,
753-
isDeclarationInstanceMember: _member.isDeclarationInstanceMember);
754-
755-
@override
756-
// Coverage-ignore(suite): Not run.
757-
bool get isLateField => _member.isLate;
758-
759-
@override
760-
// Coverage-ignore(suite): Not run.
761-
bool get isAbstractField => _member.isAbstract;
762-
763-
@override
764-
// Coverage-ignore(suite): Not run.
765-
bool get isExternalField => _member.isExternal;
766-
767-
@override
768-
// Coverage-ignore(suite): Not run.
769-
InstanceTypeParameterAccessState get instanceTypeParameterAccessState {
770-
if (_member.isExtensionMember && !_member.isExternal) {
771-
return InstanceTypeParameterAccessState.Invalid;
772-
} else {
773-
return super.instanceTypeParameterAccessState;
774-
}
775-
}
776-
777-
@override
778-
// Coverage-ignore(suite): Not run.
779-
ConstantContext get constantContext {
780-
return _member.isConst
781-
? ConstantContext.inferred
782-
: !_member.isStatic && _declarationContext.declaresConstConstructor
783-
? ConstantContext.required
784-
: ConstantContext.none;
785-
}
786-
}
787-
788742
mixin _FunctionBodyBuilderContextMixin<T extends SourceFunctionBuilder>
789743
implements BodyBuilderContext {
790744
T get _member;

pkg/front_end/lib/src/kernel/implicit_field_type.dart

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,18 @@ import 'package:kernel/class_hierarchy.dart';
88
import 'package:kernel/src/assumptions.dart';
99
import 'package:kernel/src/printer.dart';
1010

11-
import '../base/constant_context.dart';
1211
import '../base/problems.dart' show unsupported;
1312
import '../builder/inferable_type_builder.dart';
1413
import '../builder/type_builder.dart';
1514
import '../codes/cfe_codes.dart';
16-
import '../source/source_field_builder.dart';
1715
import '../source/source_library_builder.dart';
18-
import '../type_inference/type_inferrer.dart';
19-
import 'body_builder.dart';
20-
import 'body_builder_context.dart';
2116

2217
abstract class InferredType extends AuxiliaryType {
2318
Uri? get fileUri;
2419
int? get charOffset;
2520

2621
InferredType._();
2722

28-
factory InferredType.fromFieldInitializer(
29-
SourceFieldBuilder fieldBuilder, Token? initializerToken) =
30-
_ImplicitFieldTypeRoot;
31-
3223
factory InferredType(
3324
{required SourceLibraryBuilder libraryBuilder,
3425
required TypeBuilder typeBuilder,
@@ -101,100 +92,6 @@ abstract class InferredType extends AuxiliaryType {
10192
DartType computeType(ClassHierarchyBase hierarchy);
10293
}
10394

104-
// Coverage-ignore(suite): Not run.
105-
class _ImplicitFieldTypeRoot extends InferredType {
106-
final SourceFieldBuilder fieldBuilder;
107-
108-
Token? initializerToken;
109-
bool isStarted = false;
110-
111-
_ImplicitFieldTypeRoot(this.fieldBuilder, this.initializerToken) : super._();
112-
113-
@override
114-
Uri get fileUri => fieldBuilder.fileUri;
115-
116-
@override
117-
int get charOffset => fieldBuilder.fileOffset;
118-
119-
@override
120-
DartType inferType(ClassHierarchyBase hierarchy) {
121-
return fieldBuilder.inferType(hierarchy);
122-
}
123-
124-
@override
125-
DartType computeType(ClassHierarchyBase hierarchy) {
126-
if (isStarted) {
127-
fieldBuilder.libraryBuilder.addProblem(
128-
templateCantInferTypeDueToCircularity
129-
.withArguments(fieldBuilder.name),
130-
fieldBuilder.fileOffset,
131-
fieldBuilder.name.length,
132-
fieldBuilder.fileUri);
133-
DartType type = const InvalidType();
134-
fieldBuilder.type.registerInferredType(type);
135-
return type;
136-
}
137-
isStarted = true;
138-
DartType? inferredType;
139-
if (initializerToken != null) {
140-
InterfaceType? enclosingClassThisType = fieldBuilder.classBuilder == null
141-
? null
142-
: fieldBuilder.libraryBuilder.loader.typeInferenceEngine.coreTypes
143-
.thisInterfaceType(fieldBuilder.classBuilder!.cls,
144-
fieldBuilder.libraryBuilder.library.nonNullable);
145-
TypeInferrer typeInferrer = fieldBuilder
146-
.libraryBuilder.loader.typeInferenceEngine
147-
.createTopLevelTypeInferrer(
148-
fieldBuilder.fileUri,
149-
enclosingClassThisType,
150-
fieldBuilder.libraryBuilder,
151-
fieldBuilder.dataForTesting?.inferenceData);
152-
BodyBuilderContext bodyBuilderContext =
153-
fieldBuilder.createBodyBuilderContext();
154-
BodyBuilder bodyBuilder = fieldBuilder.libraryBuilder.loader
155-
.createBodyBuilderForField(
156-
fieldBuilder.libraryBuilder,
157-
bodyBuilderContext,
158-
fieldBuilder.declarationBuilder?.scope ??
159-
fieldBuilder.libraryBuilder.scope,
160-
typeInferrer,
161-
fieldBuilder.fileUri);
162-
bodyBuilder.constantContext = fieldBuilder.isConst
163-
? ConstantContext.inferred
164-
: ConstantContext.none;
165-
bodyBuilder.inFieldInitializer = true;
166-
bodyBuilder.inLateFieldInitializer = fieldBuilder.isLate;
167-
Expression initializer =
168-
bodyBuilder.parseFieldInitializer(initializerToken!);
169-
initializerToken = null;
170-
171-
inferredType =
172-
typeInferrer.inferImplicitFieldType(bodyBuilder, initializer);
173-
} else {
174-
inferredType = const DynamicType();
175-
}
176-
return inferredType;
177-
}
178-
179-
@override
180-
void toTextInternal(AstPrinter printer) {
181-
printer.write('<implicit-field-type:$fieldBuilder>');
182-
}
183-
184-
@override
185-
bool equals(Object other, Assumptions? assumptions) {
186-
if (identical(this, other)) return true;
187-
return other is _ImplicitFieldTypeRoot &&
188-
fieldBuilder == other.fieldBuilder;
189-
}
190-
191-
@override
192-
int get hashCode => fieldBuilder.hashCode;
193-
194-
@override
195-
String toString() => 'ImplicitFieldType(${toStringInternal()})';
196-
}
197-
19895
/// Signature for function called to trigger the inference of the type of
19996
/// [_ImplicitType], if it hasn't already been computed.
20097
typedef InferTypeFunction = DartType Function(ClassHierarchyBase hierarchy);

pkg/front_end/lib/src/kernel/macro/introspectors.dart

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import '../../builder/member_builder.dart';
1818
import '../../builder/type_builder.dart';
1919
import '../../source/source_constructor_builder.dart';
2020
import '../../source/source_factory_builder.dart';
21-
import '../../source/source_field_builder.dart';
2221
import '../../source/source_loader.dart';
2322
import '../../source/source_member_builder.dart';
2423
import '../../source/source_method_builder.dart';
@@ -135,8 +134,6 @@ class MacroIntrospection {
135134
} else if (memberBuilder is SourcePropertyBuilder &&
136135
memberBuilder.isField) {
137136
return _createFieldDeclaration(memberBuilder);
138-
} else if (memberBuilder is SourceFieldBuilder) {
139-
return _createVariableDeclaration(memberBuilder);
140137
} else if (memberBuilder is SourceConstructorBuilder) {
141138
return _createConstructorDeclaration(memberBuilder);
142139
} else if (memberBuilder is SourceFactoryBuilder) {
@@ -700,62 +697,6 @@ class MacroIntrospection {
700697
return declaration;
701698
}
702699

703-
/// Creates the [macro.VariableDeclaration] corresponding to [builder].
704-
macro.VariableDeclaration _createVariableDeclaration(
705-
SourceFieldBuilder builder) {
706-
macro.ParameterizedTypeDeclaration? definingTypeDeclaration = null;
707-
Builder? parent = builder.parent;
708-
if (parent is ClassBuilder) {
709-
definingTypeDeclaration = getClassDeclaration(parent);
710-
} else if (parent is ExtensionTypeDeclarationBuilder) {
711-
definingTypeDeclaration = getExtensionTypeDeclaration(parent);
712-
}
713-
final macro.LibraryImpl library = getLibrary(builder.libraryBuilder);
714-
macro.VariableDeclaration declaration;
715-
if (definingTypeDeclaration != null) {
716-
// TODO(johnniwinther): Should static fields be field or variable
717-
// declarations?
718-
declaration = new macro.FieldDeclarationImpl(
719-
id: macro.RemoteInstance.uniqueId,
720-
identifier: new MemberBuilderIdentifier(
721-
memberBuilder: builder,
722-
id: macro.RemoteInstance.uniqueId,
723-
name: builder.name),
724-
library: library,
725-
// TODO: Provide metadata annotations.
726-
metadata: const [],
727-
definingType:
728-
definingTypeDeclaration.identifier as macro.IdentifierImpl,
729-
hasAbstract: builder.isAbstract,
730-
hasConst: builder.isConst,
731-
hasExternal: builder.isExternal,
732-
hasFinal: builder.isFinal,
733-
hasInitializer: builder.hasInitializer,
734-
hasLate: builder.isLate,
735-
hasStatic: builder.isStatic,
736-
type: types.getTypeAnnotation(builder.libraryBuilder, builder.type));
737-
} else {
738-
declaration = new macro.VariableDeclarationImpl(
739-
id: macro.RemoteInstance.uniqueId,
740-
identifier: new MemberBuilderIdentifier(
741-
memberBuilder: builder,
742-
id: macro.RemoteInstance.uniqueId,
743-
name: builder.name),
744-
library: library,
745-
// TODO: Provide metadata annotations.
746-
metadata: const [],
747-
hasConst: builder.isConst,
748-
hasExternal: builder.isExternal,
749-
hasFinal: builder.isFinal,
750-
hasInitializer: builder.hasInitializer,
751-
hasLate: builder.isLate,
752-
type: types.getTypeAnnotation(builder.libraryBuilder, builder.type));
753-
}
754-
_declarationOffsets[declaration] =
755-
new UriOffset(builder.fileUri, builder.fileOffset);
756-
return declaration;
757-
}
758-
759700
/// Creates the [macro.TypeParameterDeclarationImpl] corresponding to the
760701
/// nominal parameter [builder] occurring in [libraryBuilder].
761702
macro.TypeParameterDeclarationImpl _createTypeParameterDeclaration(

pkg/front_end/lib/src/kernel/macro/macro.dart

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import '../../source/source_constructor_builder.dart';
2828
import '../../source/source_extension_builder.dart';
2929
import '../../source/source_extension_type_declaration_builder.dart';
3030
import '../../source/source_factory_builder.dart';
31-
import '../../source/source_field_builder.dart';
3231
import '../../source/source_library_builder.dart';
3332
import '../../source/source_loader.dart';
3433
import '../../source/source_method_builder.dart';
@@ -504,18 +503,6 @@ class MacroApplications {
504503
new MemberApplicationData(_macroIntrospection, libraryBuilder,
505504
memberBuilder, macroApplications);
506505
}
507-
} else if (memberBuilder is SourceFieldBuilder) {
508-
List<MacroApplication>? macroApplications = prebuildAnnotations(
509-
enclosingLibrary: libraryBuilder,
510-
scope: builder.scope,
511-
fileUri: memberBuilder.fileUri,
512-
metadataBuilders: memberBuilder.metadata,
513-
currentMacroDeclarations: currentMacroDeclarations);
514-
if (macroApplications != null) {
515-
classMacroApplicationData.memberApplications[memberBuilder] =
516-
new MemberApplicationData(_macroIntrospection, libraryBuilder,
517-
memberBuilder, macroApplications);
518-
}
519506
} else {
520507
throw new UnsupportedError("Unexpected class member "
521508
"$memberBuilder (${memberBuilder.runtimeType})");
@@ -584,18 +571,6 @@ class MacroApplications {
584571
new MemberApplicationData(_macroIntrospection, libraryBuilder,
585572
builder, macroApplications);
586573
}
587-
} else if (builder is SourceFieldBuilder) {
588-
List<MacroApplication>? macroApplications = prebuildAnnotations(
589-
enclosingLibrary: libraryBuilder,
590-
scope: libraryBuilder.scope,
591-
fileUri: builder.fileUri,
592-
metadataBuilders: builder.metadata,
593-
currentMacroDeclarations: currentMacroDeclarations);
594-
if (macroApplications != null) {
595-
libraryMacroApplicationData.memberApplications[builder] =
596-
new MemberApplicationData(_macroIntrospection, libraryBuilder,
597-
builder, macroApplications);
598-
}
599574
} else if (builder is SourceExtensionTypeDeclarationBuilder) {
600575
ExtensionTypeMacroApplicationData extensionTypeMacroApplicationData =
601576
new ExtensionTypeMacroApplicationData();
@@ -639,19 +614,6 @@ class MacroApplications {
639614
new MemberApplicationData(_macroIntrospection, libraryBuilder,
640615
memberBuilder, macroApplications);
641616
}
642-
} else if (memberBuilder is SourceFieldBuilder) {
643-
List<MacroApplication>? macroApplications = prebuildAnnotations(
644-
enclosingLibrary: libraryBuilder,
645-
scope: builder.scope,
646-
fileUri: memberBuilder.fileUri,
647-
metadataBuilders: memberBuilder.metadata,
648-
currentMacroDeclarations: currentMacroDeclarations);
649-
if (macroApplications != null) {
650-
extensionTypeMacroApplicationData
651-
.memberApplications[memberBuilder] =
652-
new MemberApplicationData(_macroIntrospection, libraryBuilder,
653-
memberBuilder, macroApplications);
654-
}
655617
} else {
656618
throw new UnsupportedError("Unexpected class member "
657619
"$memberBuilder (${memberBuilder.runtimeType})");

pkg/front_end/lib/src/kernel/macro/metadata.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import '../../builder/null_type_declaration_builder.dart';
2525
import '../../builder/prefix_builder.dart';
2626
import '../../builder/procedure_builder.dart';
2727
import '../../builder/property_builder.dart';
28-
import '../../source/source_field_builder.dart';
2928
import '../../source/source_method_builder.dart';
3029
import '../../source/source_property_builder.dart';
3130

@@ -76,12 +75,7 @@ shared.Expression parseFieldInitializer(Loader loader, Token initializerToken,
7675
// Coverage-ignore(suite): Not run.
7776
/// Returns the [shared.Expression] for the constant initializer of [reference].
7877
shared.Expression? getFieldInitializer(shared.FieldReference reference) {
79-
if (reference is FieldReference) {
80-
FieldBuilder element = reference.builder;
81-
if (element is SourceFieldBuilder) {
82-
return element.initializerExpression;
83-
}
84-
} else if (reference is PropertyReference) {
78+
if (reference is PropertyReference) {
8579
PropertyBuilder element = reference.builder;
8680
if (element is SourcePropertyBuilder) {
8781
return element.initializerExpression;

0 commit comments

Comments
 (0)