Skip to content

Commit

Permalink
[cfe] Create enum elements through SourcePropertyBuilder
Browse files Browse the repository at this point in the history
TEST=existing

Change-Id: I94ffff0ca5d891b43e0bc7b64d78eb0c03e3dd12
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404103
Reviewed-by: Alexander Markov <[email protected]>
Commit-Queue: Johnni Winther <[email protected]>
Reviewed-by: Chloe Stefantsova <[email protected]>
  • Loading branch information
johnniwinther authored and Commit Queue committed Jan 16, 2025
1 parent d0b90e5 commit 81b669d
Show file tree
Hide file tree
Showing 432 changed files with 3,187 additions and 2,135 deletions.
20 changes: 10 additions & 10 deletions pkg/dart2bytecode/testcases/literals.dart.expect
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ ConstantPool {
Class 'A', script = 'DART_SDK/pkg/dart2bytecode/testcases/literals.dart', enum
extends dart:core::_Enum

Field 'values', type = dart:core::List < DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A >, getter = 'get:values', reflectable, static, const, final, is-late, has-initializer
Field 'elem1', type = DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A, getter = 'get:elem1', reflectable, static, const, final, is-late, has-initializer
initializer
Bytecode {
Entry 0
Expand All @@ -474,11 +474,11 @@ Bytecode {
ReturnTOS
}
ConstantPool {
[0] = ObjectRef const List<DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A> [const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 0, dart:core::_Enum::_name (field): 'elem1'}, const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 1, dart:core::_Enum::_name (field): 'elem2'}, const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 2, dart:core::_Enum::_name (field): 'elem3'}, const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 3, dart:core::_Enum::_name (field): 'elem4'}]
[0] = ObjectRef const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 0, dart:core::_Enum::_name (field): 'elem1'}
}


Field 'elem1', type = DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A, getter = 'get:elem1', reflectable, static, const, final, is-late, has-initializer
Field 'elem2', type = DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A, getter = 'get:elem2', reflectable, static, const, final, is-late, has-initializer
initializer
Bytecode {
Entry 0
Expand All @@ -487,11 +487,11 @@ Bytecode {
ReturnTOS
}
ConstantPool {
[0] = ObjectRef const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 0, dart:core::_Enum::_name (field): 'elem1'}
[0] = ObjectRef const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 1, dart:core::_Enum::_name (field): 'elem2'}
}


Field 'elem2', type = DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A, getter = 'get:elem2', reflectable, static, const, final, is-late, has-initializer
Field 'elem3', type = DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A, getter = 'get:elem3', reflectable, static, const, final, is-late, has-initializer
initializer
Bytecode {
Entry 0
Expand All @@ -500,11 +500,11 @@ Bytecode {
ReturnTOS
}
ConstantPool {
[0] = ObjectRef const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 1, dart:core::_Enum::_name (field): 'elem2'}
[0] = ObjectRef const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 2, dart:core::_Enum::_name (field): 'elem3'}
}


Field 'elem3', type = DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A, getter = 'get:elem3', reflectable, static, const, final, is-late, has-initializer
Field 'elem4', type = DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A, getter = 'get:elem4', reflectable, static, const, final, is-late, has-initializer
initializer
Bytecode {
Entry 0
Expand All @@ -513,11 +513,11 @@ Bytecode {
ReturnTOS
}
ConstantPool {
[0] = ObjectRef const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 2, dart:core::_Enum::_name (field): 'elem3'}
[0] = ObjectRef const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 3, dart:core::_Enum::_name (field): 'elem4'}
}


Field 'elem4', type = DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A, getter = 'get:elem4', reflectable, static, const, final, is-late, has-initializer
Field 'values', type = dart:core::List < DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A >, getter = 'get:values', reflectable, static, const, final, is-late, has-initializer
initializer
Bytecode {
Entry 0
Expand All @@ -526,7 +526,7 @@ Bytecode {
ReturnTOS
}
ConstantPool {
[0] = ObjectRef const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 3, dart:core::_Enum::_name (field): 'elem4'}
[0] = ObjectRef const List<DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A> [const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 0, dart:core::_Enum::_name (field): 'elem1'}, const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 1, dart:core::_Enum::_name (field): 'elem2'}, const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 2, dart:core::_Enum::_name (field): 'elem3'}, const DART_SDK/pkg/dart2bytecode/testcases/literals.dart::A {dart:core::_Enum::index (field): const 3, dart:core::_Enum::_name (field): 'elem4'}]
}


Expand Down
4 changes: 4 additions & 0 deletions pkg/front_end/lib/src/base/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,10 @@ mixin ErroneousMemberBuilderMixin implements SourceMemberBuilder {
// Coverage-ignore(suite): Not run.
bool get isSynthesized => false;

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

@override
bool get isConflictingSetter => false;

Expand Down
3 changes: 3 additions & 0 deletions pkg/front_end/lib/src/builder/member_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ abstract class MemberBuilder implements Builder {

bool get isAbstract;

/// Returns `true` if this member is declared by an enum element.
bool get isEnumElement;

/// Returns `true` if this member is a setter that conflicts with the implicit
/// setter of a field.
bool get isConflictingSetter;
Expand Down
24 changes: 24 additions & 0 deletions pkg/front_end/lib/src/dill/dill_extension_member_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class DillExtensionFieldBuilder extends DillExtensionMemberBuilder {
// Coverage-ignore(suite): Not run.
bool get isProperty => true;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences =>
Expand Down Expand Up @@ -124,6 +128,10 @@ class DillExtensionSetterBuilder extends DillExtensionMemberBuilder {
// Coverage-ignore(suite): Not run.
Reference? get invokeTargetReference => null;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences => [procedure.reference];
Expand Down Expand Up @@ -165,6 +173,10 @@ class DillExtensionGetterBuilder extends DillExtensionMemberBuilder {
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences => [procedure.reference];
Expand Down Expand Up @@ -206,6 +218,10 @@ class DillExtensionOperatorBuilder extends DillExtensionMemberBuilder {
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences => [procedure.reference];
Expand Down Expand Up @@ -249,6 +265,10 @@ class DillExtensionStaticMethodBuilder extends DillExtensionMemberBuilder {
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences => [procedure.reference];
Expand Down Expand Up @@ -294,6 +314,10 @@ class DillExtensionInstanceMethodBuilder extends DillExtensionMemberBuilder {
@override
Member get invokeTarget => procedure;

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

@override
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;
Expand Down
32 changes: 32 additions & 0 deletions pkg/front_end/lib/src/dill/dill_extension_type_member_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ class DillExtensionTypeFieldBuilder extends DillExtensionTypeMemberBuilder {
// Coverage-ignore(suite): Not run.
bool get isProperty => true;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences =>
Expand Down Expand Up @@ -165,6 +169,10 @@ class DillExtensionTypeSetterBuilder extends DillExtensionTypeMemberBuilder {
// Coverage-ignore(suite): Not run.
Reference? get invokeTargetReference => null;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences => [procedure.reference];
Expand Down Expand Up @@ -206,6 +214,10 @@ class DillExtensionTypeGetterBuilder extends DillExtensionTypeMemberBuilder {
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences => [procedure.reference];
Expand Down Expand Up @@ -247,6 +259,10 @@ class DillExtensionTypeOperatorBuilder extends DillExtensionTypeMemberBuilder {
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences => [procedure.reference];
Expand Down Expand Up @@ -290,6 +306,10 @@ class DillExtensionTypeStaticMethodBuilder
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences => [procedure.reference];
Expand Down Expand Up @@ -339,6 +359,10 @@ class DillExtensionTypeInstanceMethodBuilder
@override
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;

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

class DillExtensionTypeConstructorBuilder extends DillExtensionTypeMemberBuilder
Expand Down Expand Up @@ -389,6 +413,10 @@ class DillExtensionTypeConstructorBuilder extends DillExtensionTypeMemberBuilder
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => constructor.reference;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences => [constructor.reference];
Expand Down Expand Up @@ -433,6 +461,10 @@ class DillExtensionTypeFactoryBuilder extends DillExtensionTypeMemberBuilder {
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => _procedure.reference;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences => [_procedure.reference];
Expand Down
28 changes: 28 additions & 0 deletions pkg/front_end/lib/src/dill/dill_member_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class DillFieldBuilder extends DillMemberBuilder implements FieldBuilder {
@override
// Coverage-ignore(suite): Not run.
bool get isProperty => true;

@override
// Coverage-ignore(suite): Not run.
bool get isEnumElement => field.isEnumElement;
}

abstract class DillProcedureBuilder extends DillMemberBuilder
Expand Down Expand Up @@ -229,6 +233,10 @@ class DillGetterBuilder extends DillProcedureBuilder {
@override
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;

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

class DillSetterBuilder extends DillProcedureBuilder {
Expand Down Expand Up @@ -262,6 +270,10 @@ class DillSetterBuilder extends DillProcedureBuilder {

@override
Reference? get invokeTargetReference => null;

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

class DillMethodBuilder extends DillProcedureBuilder {
Expand Down Expand Up @@ -295,6 +307,10 @@ class DillMethodBuilder extends DillProcedureBuilder {
@override
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;

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

class DillOperatorBuilder extends DillProcedureBuilder {
Expand Down Expand Up @@ -332,6 +348,10 @@ class DillOperatorBuilder extends DillProcedureBuilder {
@override
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;

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

class DillFactoryBuilder extends DillProcedureBuilder {
Expand Down Expand Up @@ -368,6 +388,10 @@ class DillFactoryBuilder extends DillProcedureBuilder {
@override
// Coverage-ignore(suite): Not run.
Reference get invokeTargetReference => procedure.reference;

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

class DillConstructorBuilder extends DillMemberBuilder
Expand Down Expand Up @@ -415,6 +439,10 @@ class DillConstructorBuilder extends DillMemberBuilder
// Coverage-ignore(suite): Not run.
bool get isConst => constructor.isConst;

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

@override
// Coverage-ignore(suite): Not run.
Iterable<Reference> get exportedMemberReferences => [constructor.reference];
Expand Down
8 changes: 7 additions & 1 deletion pkg/front_end/lib/src/fragment/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ class EnumFragment extends DeclarationFragment implements Fragment {
late final List<MetadataBuilder>? metadata;
late final MixinApplicationBuilder? supertypeBuilder;
late final List<TypeBuilder>? interfaces;
late final List<EnumConstantInfo?>? enumConstantInfos;
late final List<ConstructorReferenceBuilder> constructorReferences;
late final int startOffset;
late final int endOffset;

final List<EnumElementFragment> enumElements = [];

EnumFragment(this.name, super.fileUri, this.nameOffset, super.typeParameters,
super.typeParameterScope, super._nominalParameterNameSpace);

Expand All @@ -38,6 +39,11 @@ class EnumFragment extends DeclarationFragment implements Fragment {
_builder = value;
}

@override
void addEnumElement(EnumElementFragment fragment) {
enumElements.add(fragment);
}

@override
DeclarationFragmentKind get kind => DeclarationFragmentKind.enumDeclaration;

Expand Down
Loading

0 comments on commit 81b669d

Please sign in to comment.