Skip to content

Commit c0b6ec4

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Cleanup constructor and factory builder properties
This removes properties from the builders that belong to the declarations. Change-Id: If576f6b62b64bf57b1e629eb6caf0ab4db522980 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435125 Reviewed-by: Chloe Stefantsova <[email protected]>
1 parent 0677fca commit c0b6ec4

11 files changed

+39
-65
lines changed

pkg/front_end/lib/src/fragment/constructor/body_builder_context.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ConstructorBodyBuilderContext extends BodyBuilderContext {
7373
@override
7474
// Coverage-ignore(suite): Not run.
7575
bool get isNativeMethod {
76-
return _builder.isNative;
76+
return _declaration.isNative;
7777
}
7878

7979
@override

pkg/front_end/lib/src/fragment/constructor/declaration.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,10 @@ class RegularConstructorDeclaration
774774
@override
775775
String? get _nativeMethodName => _fragment.nativeMethodName;
776776

777+
@override
778+
// Coverage-ignore(suite): Not run.
779+
bool get isNative => _fragment.nativeMethodName != null;
780+
777781
@override
778782
LookupScope get _typeParameterScope => _fragment.typeParameterScope;
779783

@@ -951,6 +955,10 @@ class DefaultEnumConstructorDeclaration
951955
throw new UnsupportedError("$runtimeType.becomeNative()");
952956
}
953957

958+
@override
959+
// Coverage-ignore(suite): Not run.
960+
bool get isNative => false;
961+
954962
@override
955963
LookupScope get _typeParameterScope => _lookupScope;
956964

@@ -1054,6 +1062,10 @@ class PrimaryConstructorDeclaration
10541062
// Coverage-ignore(suite): Not run.
10551063
String? get _nativeMethodName => null;
10561064

1065+
@override
1066+
// Coverage-ignore(suite): Not run.
1067+
bool get isNative => false;
1068+
10571069
@override
10581070
void createEncoding({
10591071
required ProblemReporting problemReporting,
@@ -1259,6 +1271,8 @@ abstract class ConstructorFragmentDeclaration {
12591271
bool get isConst;
12601272

12611273
bool get isExternal;
1274+
1275+
bool get isNative;
12621276
}
12631277

12641278
mixin _SyntheticConstructorDeclarationMixin implements ConstructorDeclaration {
@@ -1280,7 +1294,6 @@ mixin _SyntheticConstructorDeclarationMixin implements ConstructorDeclaration {
12801294
_constructor.function.namedParameters.isNotEmpty;
12811295

12821296
@override
1283-
// Coverage-ignore(suite): Not run.
12841297
bool get isExternal => false;
12851298

12861299
@override

pkg/front_end/lib/src/fragment/factory/encoding.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class FactoryEncoding implements InferredTypeListener {
153153
// patch a const constructor with a non-const patch. Remove this and enforce
154154
// equal constness on origin and patch.
155155
_procedure.isConst = isConst;
156-
_procedure.isStatic = _fragment.modifiers.isStatic;
156+
_procedure.isStatic = true;
157157

158158
if (_redirectionTarget != null) {
159159
if (_redirectionTarget.typeArguments != null) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,7 @@ class KernelTarget {
10941094
constructorReferences: constructorReferences,
10951095
nameScheme: nameScheme,
10961096
introductory: declaration,
1097-
isConst: isConst,
1098-
isExternal: false);
1097+
isConst: isConst);
10991098

11001099
loader.registerConstructorToBeInferred(
11011100
new InferableConstructor(constructor, constructorBuilder));
@@ -1202,7 +1201,6 @@ class KernelTarget {
12021201
constructorReferences: constructorReferences,
12031202
nameScheme: nameScheme,
12041203
introductory: declaration,
1205-
isExternal: false,
12061204
isConst: false);
12071205
}
12081206

pkg/front_end/lib/src/source/source_builder_factory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ class BuilderFactoryImpl implements BuilderFactory, BuilderFactoryResult {
13891389
startOffset: startOffset,
13901390
formalsOffset: formalsOffset,
13911391
endOffset: endOffset,
1392-
modifiers: modifiers | Modifiers.Static,
1392+
modifiers: modifiers,
13931393
metadata: metadata,
13941394
typeParameterNameSpace: typeParameterNameSpace,
13951395
enclosingScope: _declarationFragments.current.bodyScope,

pkg/front_end/lib/src/source/source_class_builder.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,9 +907,9 @@ class SourceClassBuilder extends ClassBuilderImpl
907907
if (constructor is SourceConstructorBuilder) {
908908
// Report an error if a mixin class has a constructor with parameters,
909909
// is external, or is a redirecting constructor.
910-
if (constructor.isRedirecting ||
910+
if (constructor.isEffectivelyRedirecting ||
911911
constructor.hasParameters ||
912-
constructor.isExternal) {
912+
constructor.isEffectivelyExternal) {
913913
libraryBuilder.addProblem(
914914
templateIllegalMixinDueToConstructors
915915
.withArguments(fullNameForErrors),

pkg/front_end/lib/src/source/source_constructor_builder.dart

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ class SourceConstructorBuilder extends SourceMemberBuilderImpl
115115
late final Substitution _fieldTypeSubstitution =
116116
_introductory.computeFieldTypeSubstitution(declarationBuilder);
117117

118-
final String? nativeMethodName;
119-
120118
SuperInitializer? superInitializer;
121119

122120
RedirectingInitializer? redirectingInitializer;
@@ -130,8 +128,6 @@ class SourceConstructorBuilder extends SourceMemberBuilderImpl
130128
@override
131129
final bool isConst;
132130

133-
final bool isExternal;
134-
135131
final ConstructorReferences _constructorReferences;
136132
final NameScheme _nameScheme;
137133

@@ -141,13 +137,11 @@ class SourceConstructorBuilder extends SourceMemberBuilderImpl
141137
required this.declarationBuilder,
142138
required this.fileOffset,
143139
required this.fileUri,
144-
this.nativeMethodName,
145140
required ConstructorReferences constructorReferences,
146141
required NameScheme nameScheme,
147142
required ConstructorDeclaration introductory,
148143
List<ConstructorDeclaration> augmentations = const [],
149144
required this.isConst,
150-
required this.isExternal,
151145
}) : _constructorReferences = constructorReferences,
152146
_nameScheme = nameScheme,
153147
_introductory = introductory,
@@ -206,7 +200,7 @@ class SourceConstructorBuilder extends SourceMemberBuilderImpl
206200
/// An augmented constructor is considered external if all of the origin
207201
/// and augmentation constructors are external.
208202
bool get isEffectivelyExternal {
209-
bool isExternal = this.isExternal;
203+
bool isExternal = _introductory.isExternal;
210204
if (isExternal) {
211205
for (ConstructorDeclaration augmentation in _augmentations) {
212206
isExternal &= augmentation.isExternal;
@@ -236,20 +230,10 @@ class SourceConstructorBuilder extends SourceMemberBuilderImpl
236230
// Coverage-ignore(suite): Not run.
237231
bool get isFinal => false;
238232

239-
// Coverage-ignore(suite): Not run.
240-
bool get isNative => nativeMethodName != null;
241-
242233
@override
243234
// Coverage-ignore(suite): Not run.
244235
bool get isProperty => false;
245236

246-
/// Returns `true` if this constructor is an redirecting generative
247-
/// constructor.
248-
///
249-
/// It is considered redirecting if it has at least one redirecting
250-
/// initializer.
251-
bool get isRedirecting => _lastDeclaration.isRedirecting;
252-
253237
@override
254238
bool get isStatic => false;
255239

pkg/front_end/lib/src/source/source_enum_builder.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ class SourceEnumBuilder extends SourceClassBuilder {
345345
constructorReferences: constructorReferences,
346346
nameScheme: nameScheme,
347347
introductory: constructorDeclaration,
348-
isConst: true,
349-
isExternal: false);
348+
isConst: true);
350349
constructorDeclaration.createEncoding(
351350
problemReporting: libraryBuilder,
352351
loader: libraryBuilder.loader,

pkg/front_end/lib/src/source/source_factory_builder.dart

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'package:kernel/class_hierarchy.dart';
88
import 'package:kernel/reference_from_index.dart';
99
import 'package:kernel/type_environment.dart';
1010

11-
import '../base/modifiers.dart';
1211
import '../base/name_space.dart';
1312
import '../builder/builder.dart';
1413
import '../builder/constructor_reference_builder.dart';
@@ -28,8 +27,6 @@ import 'source_member_builder.dart';
2827

2928
class SourceFactoryBuilder extends SourceMemberBuilderImpl
3029
implements FactoryBuilder {
31-
final Modifiers modifiers;
32-
3330
@override
3431
final String name;
3532

@@ -62,17 +59,20 @@ class SourceFactoryBuilder extends SourceMemberBuilderImpl
6259

6360
late final List<FactoryDeclaration> _augmentedDeclarations;
6461

62+
@override
63+
final bool isConst;
64+
6565
SourceFactoryBuilder(
66-
{required this.modifiers,
67-
required this.name,
66+
{required this.name,
6867
required this.libraryBuilder,
6968
required this.declarationBuilder,
7069
required this.fileUri,
7170
required this.fileOffset,
7271
required FactoryReferences factoryReferences,
7372
required NameScheme nameScheme,
7473
required FactoryDeclaration introductory,
75-
required List<FactoryDeclaration> augmentations})
74+
required List<FactoryDeclaration> augmentations,
75+
required this.isConst})
7676
: _nameScheme = nameScheme,
7777
_factoryReferences = factoryReferences,
7878
_memberName = nameScheme.getDeclaredName(name),
@@ -95,10 +95,7 @@ class SourceFactoryBuilder extends SourceMemberBuilderImpl
9595
_lastDeclaration.redirectionTarget;
9696

9797
@override
98-
bool get isConst => modifiers.isConst;
99-
100-
@override
101-
bool get isStatic => modifiers.isStatic;
98+
bool get isStatic => true;
10299

103100
@override
104101
// Coverage-ignore(suite): Not run.

pkg/front_end/lib/src/source/type_parameter_scope_builder.dart

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,7 +2755,6 @@ _AddBuilder _createConstructorBuilder(
27552755
required ContainerName? containerName}) {
27562756
String name = fragment.name;
27572757
bool isConst = fragment.modifiers.isConst;
2758-
bool isExternal = fragment.modifiers.isExternal;
27592758

27602759
ConstructorDeclaration constructorDeclaration =
27612760
new RegularConstructorDeclaration(fragment);
@@ -2768,10 +2767,6 @@ _AddBuilder _createConstructorBuilder(
27682767

27692768
augmentationDeclarations
27702769
.add(new RegularConstructorDeclaration(augmentation));
2771-
2772-
if (!augmentation.modifiers.isExternal) {
2773-
isExternal = false;
2774-
}
27752770
}
27762771
augmentations.clear();
27772772
}
@@ -2789,9 +2784,7 @@ _AddBuilder _createConstructorBuilder(
27892784
containerType: containerType,
27902785
indexedContainer: indexedContainer,
27912786
containerName: containerName,
2792-
nativeMethodName: fragment.nativeMethodName,
27932787
isConst: isConst,
2794-
isExternal: isExternal,
27952788
inPatch: fragment.enclosingDeclaration.isPatch);
27962789
}
27972790

@@ -2809,9 +2802,7 @@ _AddBuilder _createConstructorBuilderFromDeclarations(
28092802
required ContainerType containerType,
28102803
required IndexedContainer? indexedContainer,
28112804
required ContainerName? containerName,
2812-
required String? nativeMethodName,
28132805
required bool isConst,
2814-
required bool isExternal,
28152806
required bool inPatch}) {
28162807
NameScheme nameScheme = new NameScheme(
28172808
isInstanceMember: false,
@@ -2839,11 +2830,9 @@ _AddBuilder _createConstructorBuilderFromDeclarations(
28392830
fileOffset: uriOffset.fileOffset,
28402831
constructorReferences: constructorReferences,
28412832
nameScheme: nameScheme,
2842-
nativeMethodName: nativeMethodName,
28432833
introductory: constructorDeclaration,
28442834
augmentations: augmentationDeclarations,
2845-
isConst: isConst,
2846-
isExternal: isExternal);
2835+
isConst: isConst);
28472836
constructorReferences.registerReference(loader, constructorBuilder);
28482837

28492838
constructorDeclaration.createEncoding(
@@ -2894,9 +2883,7 @@ _AddBuilder _createPrimaryConstructorBuilder(
28942883
containerType: containerType,
28952884
indexedContainer: indexedContainer,
28962885
containerName: containerName,
2897-
nativeMethodName: null,
28982886
isConst: fragment.modifiers.isConst,
2899-
isExternal: fragment.modifiers.isExternal,
29002887
inPatch: fragment.enclosingDeclaration.isPatch);
29012888
}
29022889

@@ -2912,7 +2899,7 @@ _AddBuilder _createFactoryBuilder(
29122899
required IndexedContainer? indexedContainer,
29132900
required ContainerName? containerName}) {
29142901
String name = fragment.name;
2915-
Modifiers modifiers = fragment.modifiers;
2902+
bool isConst = fragment.modifiers.isConst;
29162903

29172904
FactoryEncodingStrategy encodingStrategy =
29182905
new FactoryEncodingStrategy(declarationBuilder!);
@@ -2945,16 +2932,11 @@ _AddBuilder _createFactoryBuilder(
29452932
augmentationDeclarations.add(new FactoryDeclarationImpl(augmentation));
29462933

29472934
isRedirectingFactory |= augmentation.redirectionTarget != null;
2948-
2949-
if (!augmentation.modifiers.isExternal) {
2950-
modifiers -= Modifiers.External;
2951-
}
29522935
}
29532936
augmentations.clear();
29542937
}
29552938

29562939
SourceFactoryBuilder factoryBuilder = new SourceFactoryBuilder(
2957-
modifiers: modifiers,
29582940
name: name,
29592941
libraryBuilder: enclosingLibraryBuilder,
29602942
declarationBuilder: declarationBuilder,
@@ -2963,7 +2945,8 @@ _AddBuilder _createFactoryBuilder(
29632945
factoryReferences: factoryReferences,
29642946
nameScheme: nameScheme,
29652947
introductory: introductoryDeclaration,
2966-
augmentations: augmentationDeclarations);
2948+
augmentations: augmentationDeclarations,
2949+
isConst: isConst);
29672950
if (isRedirectingFactory) {
29682951
(enclosingLibraryBuilder.redirectingFactoryBuilders ??= [])
29692952
.add(factoryBuilder);

0 commit comments

Comments
 (0)