Skip to content

Commit 2b44c29

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Move parent, fileUri, and charOffset to MemberBuilder subclasses
Change-Id: I3bc30c2e12c52f6886260068f6d0f852985b7973 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390220 Reviewed-by: Chloe Stefantsova <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 0dd5d3e commit 2b44c29

17 files changed

+357
-292
lines changed

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

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -90,49 +90,12 @@ abstract class MemberBuilder implements Builder {
9090

9191
abstract class MemberBuilderImpl extends BuilderImpl implements MemberBuilder {
9292
@override
93-
String get name;
94-
95-
/// For top-level members, the parent is set correctly during
96-
/// construction. However, for class members, the parent is initially the
97-
/// library and updated later.
98-
@override
99-
Builder parent;
100-
101-
@override
102-
final int charOffset;
103-
104-
@override
105-
final Uri fileUri;
106-
107-
MemberBuilderImpl(this.parent, this.fileUri, this.charOffset);
93+
Uri get fileUri;
10894

10995
@override
110-
DeclarationBuilder? get declarationBuilder =>
111-
parent is DeclarationBuilder ? parent as DeclarationBuilder : null;
112-
113-
@override
114-
ClassBuilder? get classBuilder =>
115-
parent is ClassBuilder ? parent as ClassBuilder : null;
116-
117-
@override
118-
LibraryBuilder get libraryBuilder {
119-
if (parent is LibraryBuilder) {
120-
LibraryBuilder library = parent as LibraryBuilder;
121-
return library.partOfLibrary ?? library;
122-
}
123-
// Coverage-ignore(suite): Not run.
124-
else if (parent is ExtensionBuilder) {
125-
ExtensionBuilder extension = parent as ExtensionBuilder;
126-
return extension.libraryBuilder;
127-
} else if (parent is ExtensionTypeDeclarationBuilder) {
128-
ExtensionTypeDeclarationBuilder extensionTypeDeclaration =
129-
parent as ExtensionTypeDeclarationBuilder;
130-
return extensionTypeDeclaration.libraryBuilder;
131-
} else {
132-
ClassBuilder cls = parent as ClassBuilder;
133-
return cls.libraryBuilder;
134-
}
135-
}
96+
ClassBuilder? get classBuilder => declarationBuilder is ClassBuilder
97+
? declarationBuilder as ClassBuilder
98+
: null;
13699

137100
@override
138101
bool get isDeclarationInstanceMember => isDeclarationMember && !isStatic;

pkg/front_end/lib/src/dill/dill_class_builder.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,23 @@ class DillClassBuilder extends ClassBuilderImpl
158158
List<TypeBuilder>? get onTypes => null;
159159

160160
void addField(Field field) {
161-
DillFieldBuilder builder = new DillFieldBuilder(field, this);
161+
DillFieldBuilder builder =
162+
new DillFieldBuilder(field, libraryBuilder, this);
162163
String name = field.name.text;
163164
nameSpace.addLocalMember(name, builder, setter: false);
164165
}
165166

166167
void addConstructor(Constructor constructor, Procedure? constructorTearOff) {
167-
DillConstructorBuilder builder =
168-
new DillConstructorBuilder(constructor, constructorTearOff, this);
168+
DillConstructorBuilder builder = new DillConstructorBuilder(
169+
constructor, constructorTearOff, libraryBuilder, this);
169170
String name = constructor.name.text;
170171
nameSpace.addConstructor(name, builder);
171172
}
172173

173174
void addFactory(Procedure factory, Procedure? factoryTearOff) {
174175
String name = factory.name.text;
175-
nameSpace.addConstructor(
176-
name, new DillFactoryBuilder(factory, factoryTearOff, this));
176+
nameSpace.addConstructor(name,
177+
new DillFactoryBuilder(factory, factoryTearOff, libraryBuilder, this));
177178
}
178179

179180
void addProcedure(Procedure procedure) {
@@ -183,19 +184,23 @@ class DillClassBuilder extends ClassBuilderImpl
183184
// Coverage-ignore(suite): Not run.
184185
throw new UnsupportedError("Use addFactory for adding factories");
185186
case ProcedureKind.Setter:
186-
nameSpace.addLocalMember(name, new DillSetterBuilder(procedure, this),
187+
nameSpace.addLocalMember(
188+
name, new DillSetterBuilder(procedure, libraryBuilder, this),
187189
setter: true);
188190
break;
189191
case ProcedureKind.Getter:
190-
nameSpace.addLocalMember(name, new DillGetterBuilder(procedure, this),
192+
nameSpace.addLocalMember(
193+
name, new DillGetterBuilder(procedure, libraryBuilder, this),
191194
setter: false);
192195
break;
193196
case ProcedureKind.Operator:
194-
nameSpace.addLocalMember(name, new DillOperatorBuilder(procedure, this),
197+
nameSpace.addLocalMember(
198+
name, new DillOperatorBuilder(procedure, libraryBuilder, this),
195199
setter: false);
196200
break;
197201
case ProcedureKind.Method:
198-
nameSpace.addLocalMember(name, new DillMethodBuilder(procedure, this),
202+
nameSpace.addLocalMember(
203+
name, new DillMethodBuilder(procedure, libraryBuilder, this),
199204
setter: false);
200205
break;
201206
}

pkg/front_end/lib/src/dill/dill_extension_builder.dart

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'dill_library_builder.dart';
1616
class DillExtensionBuilder extends ExtensionBuilderImpl
1717
with DillDeclarationBuilderMixin {
1818
@override
19-
final DillLibraryBuilder parent;
19+
final DillLibraryBuilder libraryBuilder;
2020

2121
@override
2222
final Extension extension;
@@ -30,7 +30,7 @@ class DillExtensionBuilder extends ExtensionBuilderImpl
3030
List<NominalVariableBuilder>? _typeParameters;
3131
TypeBuilder? _onType;
3232

33-
DillExtensionBuilder(this.extension, this.parent)
33+
DillExtensionBuilder(this.extension, this.libraryBuilder)
3434
: _nameSpace = new DeclarationNameSpaceImpl() {
3535
_scope = new NameSpaceLookupScope(
3636
_nameSpace, ScopeKind.declaration, "extension ${extension.name}",
@@ -46,7 +46,7 @@ class DillExtensionBuilder extends ExtensionBuilderImpl
4646
nameSpace.addLocalMember(
4747
name.text,
4848
new DillExtensionStaticMethodBuilder(
49-
procedure, descriptor, this),
49+
procedure, descriptor, libraryBuilder, this),
5050
setter: false);
5151
} else {
5252
Procedure procedure = descriptor.memberReference.asProcedure;
@@ -55,38 +55,49 @@ class DillExtensionBuilder extends ExtensionBuilderImpl
5555
nameSpace.addLocalMember(
5656
name.text,
5757
new DillExtensionInstanceMethodBuilder(
58-
procedure, descriptor, this, tearOff!),
58+
procedure, descriptor, libraryBuilder, this, tearOff!),
5959
setter: false);
6060
}
6161
break;
6262
case ExtensionMemberKind.Getter:
6363
Procedure procedure = descriptor.memberReference.asProcedure;
64-
nameSpace.addLocalMember(name.text,
65-
new DillExtensionGetterBuilder(procedure, descriptor, this),
64+
nameSpace.addLocalMember(
65+
name.text,
66+
new DillExtensionGetterBuilder(
67+
procedure, descriptor, libraryBuilder, this),
6668
setter: false);
6769
break;
6870
case ExtensionMemberKind.Field:
6971
Field field = descriptor.memberReference.asField;
7072
nameSpace.addLocalMember(
71-
name.text, new DillExtensionFieldBuilder(field, descriptor, this),
73+
name.text,
74+
new DillExtensionFieldBuilder(
75+
field, descriptor, libraryBuilder, this),
7276
setter: false);
7377
break;
7478
case ExtensionMemberKind.Setter:
7579
Procedure procedure = descriptor.memberReference.asProcedure;
76-
nameSpace.addLocalMember(name.text,
77-
new DillExtensionSetterBuilder(procedure, descriptor, this),
80+
nameSpace.addLocalMember(
81+
name.text,
82+
new DillExtensionSetterBuilder(
83+
procedure, descriptor, libraryBuilder, this),
7884
setter: true);
7985
break;
8086
case ExtensionMemberKind.Operator:
8187
Procedure procedure = descriptor.memberReference.asProcedure;
82-
nameSpace.addLocalMember(name.text,
83-
new DillExtensionOperatorBuilder(procedure, descriptor, this),
88+
nameSpace.addLocalMember(
89+
name.text,
90+
new DillExtensionOperatorBuilder(
91+
procedure, descriptor, libraryBuilder, this),
8492
setter: false);
8593
break;
8694
}
8795
}
8896
}
8997

98+
@override
99+
DillLibraryBuilder get parent => libraryBuilder;
100+
90101
@override
91102
Reference get reference => extension.reference;
92103

pkg/front_end/lib/src/dill/dill_extension_member_builder.dart

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import 'package:kernel/ast.dart';
66

7-
import '../builder/builder.dart';
7+
import 'dill_extension_builder.dart';
88
import 'dill_member_builder.dart';
99

1010
abstract class DillExtensionMemberBuilder extends DillMemberBuilder {
1111
final ExtensionMemberDescriptor _descriptor;
1212

13-
DillExtensionMemberBuilder(Member member, this._descriptor, Builder parent)
14-
: super(member, parent);
13+
DillExtensionMemberBuilder(this._descriptor, super.libraryBuilder,
14+
DillExtensionBuilder super.declarationBuilder);
1515

1616
@override
1717
bool get isStatic => _descriptor.isStatic;
@@ -44,9 +44,8 @@ abstract class DillExtensionMemberBuilder extends DillMemberBuilder {
4444
class DillExtensionFieldBuilder extends DillExtensionMemberBuilder {
4545
final Field field;
4646

47-
DillExtensionFieldBuilder(
48-
this.field, ExtensionMemberDescriptor descriptor, Builder parent)
49-
: super(field, descriptor, parent);
47+
DillExtensionFieldBuilder(this.field, super.descriptor, super.libraryBuilder,
48+
super.declarationBuilder);
5049

5150
@override
5251
// Coverage-ignore(suite): Not run.
@@ -71,10 +70,9 @@ class DillExtensionFieldBuilder extends DillExtensionMemberBuilder {
7170
class DillExtensionSetterBuilder extends DillExtensionMemberBuilder {
7271
final Procedure procedure;
7372

74-
DillExtensionSetterBuilder(
75-
this.procedure, ExtensionMemberDescriptor descriptor, Builder parent)
76-
: assert(descriptor.kind == ExtensionMemberKind.Setter),
77-
super(procedure, descriptor, parent);
73+
DillExtensionSetterBuilder(this.procedure, super.descriptor,
74+
super.libraryBuilder, super.declarationBuilder)
75+
: assert(descriptor.kind == ExtensionMemberKind.Setter);
7876

7977
@override
8078
// Coverage-ignore(suite): Not run.
@@ -94,10 +92,9 @@ class DillExtensionSetterBuilder extends DillExtensionMemberBuilder {
9492
class DillExtensionGetterBuilder extends DillExtensionMemberBuilder {
9593
final Procedure procedure;
9694

97-
DillExtensionGetterBuilder(
98-
this.procedure, ExtensionMemberDescriptor descriptor, Builder parent)
99-
: assert(descriptor.kind == ExtensionMemberKind.Getter),
100-
super(procedure, descriptor, parent);
95+
DillExtensionGetterBuilder(this.procedure, super.descriptor,
96+
super.libraryBuilder, super.declarationBuilder)
97+
: assert(descriptor.kind == ExtensionMemberKind.Getter);
10198

10299
@override
103100
// Coverage-ignore(suite): Not run.
@@ -117,10 +114,9 @@ class DillExtensionGetterBuilder extends DillExtensionMemberBuilder {
117114
class DillExtensionOperatorBuilder extends DillExtensionMemberBuilder {
118115
final Procedure procedure;
119116

120-
DillExtensionOperatorBuilder(
121-
this.procedure, ExtensionMemberDescriptor descriptor, Builder parent)
122-
: assert(descriptor.kind == ExtensionMemberKind.Operator),
123-
super(procedure, descriptor, parent);
117+
DillExtensionOperatorBuilder(this.procedure, super.descriptor,
118+
super.libraryBuilder, super.declarationBuilder)
119+
: assert(descriptor.kind == ExtensionMemberKind.Operator);
124120

125121
@override
126122
// Coverage-ignore(suite): Not run.
@@ -140,11 +136,10 @@ class DillExtensionOperatorBuilder extends DillExtensionMemberBuilder {
140136
class DillExtensionStaticMethodBuilder extends DillExtensionMemberBuilder {
141137
final Procedure procedure;
142138

143-
DillExtensionStaticMethodBuilder(
144-
this.procedure, ExtensionMemberDescriptor descriptor, Builder parent)
139+
DillExtensionStaticMethodBuilder(this.procedure, super.descriptor,
140+
super.libraryBuilder, super.declarationBuilder)
145141
: assert(descriptor.kind == ExtensionMemberKind.Method),
146-
assert(descriptor.isStatic),
147-
super(procedure, descriptor, parent);
142+
assert(descriptor.isStatic);
148143

149144
@override
150145
// Coverage-ignore(suite): Not run.
@@ -166,14 +161,10 @@ class DillExtensionInstanceMethodBuilder extends DillExtensionMemberBuilder {
166161

167162
final Procedure _extensionTearOff;
168163

169-
DillExtensionInstanceMethodBuilder(
170-
this.procedure,
171-
ExtensionMemberDescriptor descriptor,
172-
Builder parent,
173-
this._extensionTearOff)
164+
DillExtensionInstanceMethodBuilder(this.procedure, super.descriptor,
165+
super.libraryBuilder, super.declarationBuilder, this._extensionTearOff)
174166
: assert(descriptor.kind == ExtensionMemberKind.Method),
175-
assert(!descriptor.isStatic),
176-
super(procedure, descriptor, parent);
167+
assert(!descriptor.isStatic);
177168

178169
@override
179170
// Coverage-ignore(suite): Not run.

0 commit comments

Comments
 (0)