Skip to content

Commit 93146ec

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Pass content maps to NameSpaceImpl
This moves the computation of the content map from getables/setable outside the NameSpaceImpl. This is in preparation for implementing getter/setter and final field/setter through the same PropertyBuilder. Change-Id: I2c91f7ee9f2650f87ac9512d18834c31684c7309 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429942 Reviewed-by: Chloe Stefantsova <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent dceefd0 commit 93146ec

File tree

3 files changed

+58
-56
lines changed

3 files changed

+58
-56
lines changed

pkg/front_end/lib/src/base/lookup_result.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,32 @@ abstract class LookupResult {
110110
}
111111
}
112112
}
113+
114+
static void addNamedBuilder(
115+
Map<String, LookupResult> content, String name, NamedBuilder member,
116+
{required bool setter}) {
117+
LookupResult? existing = content[name];
118+
if (existing != null) {
119+
if (setter) {
120+
assert(existing.getable != null,
121+
"No existing getable for $name: $existing.");
122+
content[name] = new GetableSetableResult(existing.getable!, member);
123+
return;
124+
} else {
125+
assert(existing.setable != null,
126+
"No existing setable for $name: $existing.");
127+
content[name] = new GetableSetableResult(member, existing.setable!);
128+
return;
129+
}
130+
}
131+
if (member is LookupResult) {
132+
content[name] = member as LookupResult;
133+
} else {
134+
// Coverage-ignore-block(suite): Not run.
135+
content[name] =
136+
setter ? new SetableResult(member) : new GetableResult(member);
137+
}
138+
}
113139
}
114140

115141
class GetableResult implements LookupResult {

pkg/front_end/lib/src/base/name_space.dart

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ abstract class NameSpace {
3636

3737
abstract class MutableNameSpace implements NameSpace {
3838
void addLocalMember(String name, NamedBuilder member, {required bool setter});
39-
40-
/// Adds [builder] to the extensions in this name space.
41-
void addExtension(ExtensionBuilder builder);
4239
}
4340

4441
abstract class ComputedNameSpace implements NameSpace {
@@ -54,6 +51,9 @@ abstract class ComputedMutableNameSpace
5451
implements MutableNameSpace, ComputedNameSpace {
5552
factory ComputedMutableNameSpace() = ComputedMutableNameSpaceImpl._;
5653

54+
/// Adds [builder] to the extensions in this name space.
55+
void addExtension(ExtensionBuilder builder);
56+
5757
void replaceLocalMember(String name, NamedBuilder member,
5858
{required bool setter});
5959
}
@@ -72,53 +72,14 @@ base class NameSpaceImpl implements MutableNameSpace {
7272
Set<ExtensionBuilder>? _extensions;
7373

7474
NameSpaceImpl._(
75-
{Map<String, NamedBuilder>? getables,
76-
Map<String, NamedBuilder>? setables,
77-
Set<ExtensionBuilder>? extensions})
78-
: _extensions = extensions {
79-
if (getables != null) {
80-
for (MapEntry<String, NamedBuilder> entry in getables.entries) {
81-
addLocalMember(entry.key, entry.value, setter: false);
82-
}
83-
}
84-
if (setables != null) {
85-
for (MapEntry<String, NamedBuilder> entry in setables.entries) {
86-
addLocalMember(entry.key, entry.value, setter: true);
87-
}
88-
}
89-
}
75+
{Map<String, LookupResult>? content, Set<ExtensionBuilder>? extensions})
76+
: _content = content,
77+
_extensions = extensions;
9078

9179
@override
9280
void addLocalMember(String name, NamedBuilder member,
9381
{required bool setter}) {
94-
Map<String, LookupResult> content = _content ??= {};
95-
LookupResult? existing = content[name];
96-
if (existing != null) {
97-
if (setter) {
98-
assert(existing.getable != null,
99-
"No existing getable for $name: $existing.");
100-
content[name] = new GetableSetableResult(existing.getable!, member);
101-
return;
102-
} else {
103-
assert(existing.setable != null,
104-
"No existing setable for $name: $existing.");
105-
content[name] = new GetableSetableResult(member, existing.setable!);
106-
return;
107-
}
108-
}
109-
if (member is LookupResult) {
110-
content[name] = member as LookupResult;
111-
} else {
112-
// Coverage-ignore-block(suite): Not run.
113-
content[name] =
114-
setter ? new SetableResult(member) : new GetableResult(member);
115-
}
116-
}
117-
118-
@override
119-
// Coverage-ignore(suite): Not run.
120-
void addExtension(ExtensionBuilder builder) {
121-
(_extensions ??= {}).add(builder);
82+
LookupResult.addNamedBuilder(_content ??= {}, name, member, setter: setter);
12283
}
12384

12485
@override
@@ -265,8 +226,7 @@ base class ComputedMutableNameSpaceImpl implements ComputedMutableNameSpace {
265226

266227
final class SourceLibraryNameSpace extends NameSpaceImpl {
267228
SourceLibraryNameSpace(
268-
{required Map<String, NamedBuilder> super.getables,
269-
required Map<String, NamedBuilder> super.setables,
229+
{required Map<String, LookupResult> super.content,
270230
required Set<ExtensionBuilder> super.extensions})
271231
: super._();
272232
}
@@ -346,8 +306,7 @@ abstract base class DeclarationNameSpaceBase extends NameSpaceImpl
346306
Map<String, MemberBuilder>? _constructors;
347307

348308
DeclarationNameSpaceBase._(
349-
{super.getables,
350-
super.setables,
309+
{super.content,
351310
super.extensions,
352311
Map<String, MemberBuilder>? constructors})
353312
: _constructors = constructors,
@@ -364,8 +323,7 @@ abstract base class DeclarationNameSpaceBase extends NameSpaceImpl
364323

365324
final class SourceDeclarationNameSpace extends DeclarationNameSpaceBase {
366325
SourceDeclarationNameSpace(
367-
{required Map<String, NamedBuilder> super.getables,
368-
required Map<String, NamedBuilder> super.setables,
326+
{required Map<String, LookupResult> super.content,
369327
required Map<String, MemberBuilder>? super.constructors})
370328
: super._();
371329
}

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:kernel/ast.dart';
77
import 'package:kernel/reference_from_index.dart';
88
import 'package:kernel/src/bounds_checks.dart' show VarianceCalculationValue;
99

10+
import '../base/lookup_result.dart';
1011
import '../base/messages.dart';
1112
import '../base/modifiers.dart';
1213
import '../base/name_space.dart';
@@ -1594,6 +1595,7 @@ class LibraryNameSpaceBuilder {
15941595
required Map<SourceClassBuilder, TypeBuilder> mixinApplications,
15951596
required List<NamedBuilder> memberBuilders,
15961597
}) {
1598+
Map<String, LookupResult> content = {};
15971599
Map<String, NamedBuilder> getables = {};
15981600

15991601
Map<String, NamedBuilder> setables = {};
@@ -1693,8 +1695,15 @@ class LibraryNameSpaceBuilder {
16931695
}
16941696
}
16951697

1696-
return new SourceLibraryNameSpace(
1697-
getables: getables, setables: setables, extensions: extensions);
1698+
for (MapEntry<String, NamedBuilder> entry in getables.entries) {
1699+
LookupResult.addNamedBuilder(content, entry.key, entry.value,
1700+
setter: false);
1701+
}
1702+
for (MapEntry<String, NamedBuilder> entry in setables.entries) {
1703+
LookupResult.addNamedBuilder(content, entry.key, entry.value,
1704+
setter: true);
1705+
}
1706+
return new SourceLibraryNameSpace(content: content, extensions: extensions);
16981707
}
16991708
}
17001709

@@ -1893,6 +1902,7 @@ class DeclarationNameSpaceBuilder {
18931902
required List<SourceMemberBuilder> constructorBuilders,
18941903
required List<SourceMemberBuilder> memberBuilders}) {
18951904
List<NominalParameterBuilder> unboundNominalParameters = [];
1905+
Map<String, LookupResult> content = {};
18961906
Map<String, NamedBuilder> getables = {};
18971907
Map<String, NamedBuilder> setables = {};
18981908
Map<String, MemberBuilder> constructors = {};
@@ -1989,9 +1999,17 @@ class DeclarationNameSpaceBuilder {
19891999
enclosingLibraryBuilder
19902000
.registerUnboundNominalParameters(unboundNominalParameters);
19912001

2002+
for (MapEntry<String, NamedBuilder> entry in getables.entries) {
2003+
LookupResult.addNamedBuilder(content, entry.key, entry.value,
2004+
setter: false);
2005+
}
2006+
for (MapEntry<String, NamedBuilder> entry in setables.entries) {
2007+
LookupResult.addNamedBuilder(content, entry.key, entry.value,
2008+
setter: true);
2009+
}
2010+
19922011
return new SourceDeclarationNameSpace(
1993-
getables: getables,
1994-
setables: setables,
2012+
content: content,
19952013
// TODO(johnniwinther): Handle constructors in extensions consistently.
19962014
// Currently they are not part of the name space but still processed
19972015
// for instance when inferring redirecting factories.

0 commit comments

Comments
 (0)