22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- import '../builder/builder.dart' ;
65import '../builder/declaration_builders.dart' ;
76import '../builder/variable_builder.dart' ;
7+ import 'lookup_result.dart' ;
88import 'scope.dart' ;
99
1010abstract class LocalScope implements LookupScope {
@@ -16,12 +16,12 @@ abstract class LocalScope implements LookupScope {
1616
1717 LocalScope createNestedFixedScope (
1818 {required String debugName,
19- required Map <String , Builder > local,
19+ required Map <String , VariableBuilder > local,
2020 required ScopeKind kind});
2121
22- Iterable <Builder > get localVariables;
22+ Iterable <VariableBuilder > get localVariables;
2323
24- Builder ? lookupLocalVariable (String name);
24+ VariableBuilder ? lookupLocalVariable (String name);
2525
2626 /// Declares that the meaning of [name] in this scope is [builder] .
2727 ///
@@ -30,12 +30,6 @@ abstract class LocalScope implements LookupScope {
3030 /// [name] being used before its declared.
3131 List <int >? declare (String name, VariableBuilder builder);
3232
33- @override
34- Builder ? lookupGetable (String name, int charOffset, Uri fileUri);
35-
36- @override
37- Builder ? lookupSetable (String name, int charOffset, Uri uri);
38-
3933 Map <String , List <int >>? get usedNames;
4034}
4135
@@ -49,53 +43,32 @@ abstract base class BaseLocalScope implements LocalScope {
4943 @override
5044 LocalScope createNestedFixedScope (
5145 {required String debugName,
52- required Map <String , Builder > local,
46+ required Map <String , VariableBuilder > local,
5347 required ScopeKind kind}) {
5448 return new FixedLocalScope (
5549 kind: kind, parent: this , local: local, debugName: debugName);
5650 }
5751}
5852
59- mixin LocalScopeMixin implements LookupScopeMixin , LocalScope {
53+ mixin LocalScopeMixin implements LocalScope {
6054 LookupScope ? get _parent;
6155
62- Map <String , Builder >? get _local;
63-
64- @override
65- String get classNameOrDebugName;
56+ Map <String , VariableBuilder >? get _local;
6657
6758 @override
68- Iterable <Builder > get localVariables => _local? .values ?? const {} ;
59+ Iterable <VariableBuilder > get localVariables => _local? .values ?? const [] ;
6960
7061 @override
71- Builder ? lookupGetable (String name, int charOffset, Uri fileUri) {
72- _recordUse (name, charOffset);
73- if (_local != null ) {
74- Builder ? builder = lookupGetableIn (name, charOffset, fileUri, _local! );
75- if (builder != null ) {
76- return builder;
77- }
78- }
79- return _parent? .lookupGetable (name, charOffset, fileUri);
62+ LookupResult ? lookup (String name, int fileOffset, Uri fileUri) {
63+ _recordUse (name, fileOffset);
64+ return _local? [name] ?? _parent? .lookup (name, fileOffset, fileUri);
8065 }
8166
8267 @override
83- Builder ? lookupLocalVariable (String name) {
68+ VariableBuilder ? lookupLocalVariable (String name) {
8469 return _local? [name];
8570 }
8671
87- @override
88- Builder ? lookupSetable (String name, int charOffset, Uri fileUri) {
89- _recordUse (name, charOffset);
90- if (_local != null ) {
91- Builder ? builder = lookupSetableIn (name, charOffset, fileUri, _local);
92- if (builder != null ) {
93- return builder;
94- }
95- }
96- return _parent? .lookupSetable (name, charOffset, fileUri);
97- }
98-
9972 void _recordUse (String name, int charOffset) {}
10073
10174 @override
@@ -106,13 +79,12 @@ mixin LocalScopeMixin implements LookupScopeMixin, LocalScope {
10679}
10780
10881final class LocalScopeImpl extends BaseLocalScope
109- with LookupScopeMixin , LocalScopeMixin
82+ with LocalScopeMixin
11083 implements LocalScope {
11184 @override
11285 final LocalScope ? _parent;
11386
114- @override
115- final String classNameOrDebugName;
87+ final String _debugName;
11688
11789 /// Names declared in this scope.
11890 @override
@@ -124,7 +96,7 @@ final class LocalScopeImpl extends BaseLocalScope
12496 @override
12597 final ScopeKind kind;
12698
127- LocalScopeImpl (this ._parent, this .kind, this .classNameOrDebugName );
99+ LocalScopeImpl (this ._parent, this .kind, this ._debugName );
128100
129101 @override
130102 List <int >? declare (String name, VariableBuilder builder) {
@@ -145,8 +117,7 @@ final class LocalScopeImpl extends BaseLocalScope
145117 }
146118
147119 @override
148- String toString () =>
149- "$runtimeType (${kind }, $classNameOrDebugName , ${_local ?.keys })" ;
120+ String toString () => "$runtimeType (${kind }, $_debugName , ${_local ?.keys })" ;
150121}
151122
152123mixin ImmutableLocalScopeMixin implements LocalScope {
@@ -161,12 +132,12 @@ mixin ImmutableLocalScopeMixin implements LocalScope {
161132}
162133
163134final class LocalTypeParameterScope extends BaseLocalScope
164- with LookupScopeMixin , ImmutableLocalScopeMixin , LocalScopeMixin {
165- @override
135+ with ImmutableLocalScopeMixin {
166136 final LocalScope ? _parent;
137+
167138 @override
168139 final ScopeKind kind;
169- @override
140+
170141 final Map <String , TypeParameterBuilder >? _local;
171142
172143 final String _debugName;
@@ -181,61 +152,70 @@ final class LocalTypeParameterScope extends BaseLocalScope
181152 _debugName = debugName;
182153
183154 @override
184- String get classNameOrDebugName => _debugName;
155+ // Coverage-ignore(suite): Not run.
156+ Iterable <VariableBuilder > get localVariables => const [];
185157
186158 @override
187- String toString () =>
188- "$runtimeType (${kind }, $classNameOrDebugName , ${_local ?.keys })" ;
159+ LookupResult ? lookup (String name, int fileOffset, Uri fileUri) {
160+ return _local? [name] ?? _parent? .lookup (name, fileOffset, fileUri);
161+ }
162+
163+ @override
164+ // Coverage-ignore(suite): Not run.
165+ VariableBuilder ? lookupLocalVariable (String name) => null ;
166+
167+ @override
168+ // Coverage-ignore(suite): Not run.
169+ void forEachExtension (void Function (ExtensionBuilder ) f) {
170+ _parent? .forEachExtension (f);
171+ }
172+
173+ @override
174+ String toString () => "$runtimeType (${kind }, $_debugName , ${_local ?.keys })" ;
189175}
190176
191177final class FixedLocalScope extends BaseLocalScope
192- with LookupScopeMixin , ImmutableLocalScopeMixin , LocalScopeMixin {
178+ with ImmutableLocalScopeMixin , LocalScopeMixin {
193179 @override
194180 final LocalScope ? _parent;
195181 @override
196182 final ScopeKind kind;
197183 @override
198- final Map <String , Builder >? _local;
184+ final Map <String , VariableBuilder >? _local;
199185
200186 final String _debugName;
201187
202188 FixedLocalScope (
203189 {required this .kind,
204190 LocalScope ? parent,
205- Map <String , Builder >? local,
191+ Map <String , VariableBuilder >? local,
206192 required String debugName})
207193 : _parent = parent,
208194 _local = local,
209195 _debugName = debugName;
210196
211197 @override
212- String get classNameOrDebugName => _debugName;
213-
214- @override
215- String toString () =>
216- "$runtimeType (${kind }, $classNameOrDebugName , ${_local ?.keys })" ;
198+ String toString () => "$runtimeType (${kind }, $_debugName , ${_local ?.keys })" ;
217199}
218200
219201final class FormalParameterScope extends BaseLocalScope
220- with LookupScopeMixin , ImmutableLocalScopeMixin , LocalScopeMixin {
202+ with ImmutableLocalScopeMixin , LocalScopeMixin {
221203 @override
222204 final LookupScope ? _parent;
223205 @override
224- final Map <String , Builder >? _local;
206+ final Map <String , VariableBuilder >? _local;
225207
226- FormalParameterScope ({LookupScope ? parent, Map <String , Builder >? local})
208+ FormalParameterScope (
209+ {LookupScope ? parent, Map <String , VariableBuilder >? local})
227210 : _parent = parent,
228211 _local = local;
229212
230213 @override
231214 ScopeKind get kind => ScopeKind .formals;
232215
233- @override
234- String get classNameOrDebugName => "formal parameter" ;
235-
236216 @override
237217 String toString () =>
238- "$runtimeType (${kind }, $ classNameOrDebugName , ${_local ?.keys })" ;
218+ "$runtimeType (${kind }, formal parameter , ${_local ?.keys })" ;
239219}
240220
241221final class EnclosingLocalScope extends BaseLocalScope
@@ -249,21 +229,16 @@ final class EnclosingLocalScope extends BaseLocalScope
249229
250230 @override
251231 // Coverage-ignore(suite): Not run.
252- Iterable <Builder > get localVariables => const [];
232+ Iterable <VariableBuilder > get localVariables => const [];
253233
254234 @override
255- Builder ? lookupGetable (String name, int charOffset , Uri fileUri) {
256- return _scope.lookupGetable (name, charOffset , fileUri);
235+ LookupResult ? lookup (String name, int fileOffset , Uri fileUri) {
236+ return _scope.lookup (name, fileOffset , fileUri);
257237 }
258238
259239 @override
260240 // Coverage-ignore(suite): Not run.
261- Builder ? lookupLocalVariable (String name) => null ;
262-
263- @override
264- Builder ? lookupSetable (String name, int charOffset, Uri uri) {
265- return _scope.lookupSetable (name, charOffset, uri);
266- }
241+ VariableBuilder ? lookupLocalVariable (String name) => null ;
267242
268243 @override
269244 // Coverage-ignore(suite): Not run.
0 commit comments