OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
6 | 6 |
7 import '../closure.dart'; | 7 import '../closure.dart'; |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../common/tasks.dart'; | 9 import '../common/tasks.dart'; |
10 import '../constants/expressions.dart'; | 10 import '../constants/expressions.dart'; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 @override | 158 @override |
159 ScopeInfo getScopeInfo(MemberEntity entity) { | 159 ScopeInfo getScopeInfo(MemberEntity entity) { |
160 // TODO(johnniwinther): Remove this check when constructor bodies a created | 160 // TODO(johnniwinther): Remove this check when constructor bodies a created |
161 // eagerly with the J-model; a constructor body should have it's own | 161 // eagerly with the J-model; a constructor body should have it's own |
162 // [ClosureRepresentationInfo]. | 162 // [ClosureRepresentationInfo]. |
163 if (entity is ConstructorBodyEntity) { | 163 if (entity is ConstructorBodyEntity) { |
164 ConstructorBodyEntity constructorBody = entity; | 164 ConstructorBodyEntity constructorBody = entity; |
165 entity = constructorBody.constructor; | 165 entity = constructorBody.constructor; |
166 } | 166 } |
167 | 167 |
168 return _scopeMap[entity] ?? getClosureInfoForMember(entity); | 168 ScopeInfo scopeInfo = _scopeMap[entity]; |
| 169 assert( |
| 170 scopeInfo != null, failedAt(entity, "Missing scope info for $entity.")); |
| 171 return scopeInfo; |
169 } | 172 } |
170 | 173 |
171 // TODO(efortuna): Eventually capturedScopesMap[node] should always | 174 // TODO(efortuna): Eventually capturedScopesMap[node] should always |
172 // be non-null, and we should just test that with an assert. | 175 // be non-null, and we should just test that with an assert. |
173 @override | 176 @override |
174 CapturedScope getCapturedScope(MemberEntity entity) { | 177 CapturedScope getCapturedScope(MemberEntity entity) { |
175 MemberDefinition definition = _elementMap.getMemberDefinition(entity); | 178 MemberDefinition definition = _elementMap.getMemberDefinition(entity); |
176 switch (definition.kind) { | 179 switch (definition.kind) { |
177 case MemberKind.regular: | 180 case MemberKind.regular: |
178 case MemberKind.constructor: | 181 case MemberKind.constructor: |
(...skipping 23 matching lines...) Expand all Loading... |
202 | 205 |
203 @override | 206 @override |
204 ClosureRepresentationInfo getClosureInfo(ir.Node node) { | 207 ClosureRepresentationInfo getClosureInfo(ir.Node node) { |
205 var closure = _localClosureRepresentationMap[node]; | 208 var closure = _localClosureRepresentationMap[node]; |
206 assert( | 209 assert( |
207 closure != null, | 210 closure != null, |
208 "Corresponding closure class not found for $node. " | 211 "Corresponding closure class not found for $node. " |
209 "Closures found for ${_localClosureRepresentationMap.keys}"); | 212 "Closures found for ${_localClosureRepresentationMap.keys}"); |
210 return closure; | 213 return closure; |
211 } | 214 } |
212 | |
213 @override | |
214 ClosureRepresentationInfo getClosureInfoForMemberTesting( | |
215 MemberEntity entity) { | |
216 return _memberClosureRepresentationMap[entity]; | |
217 } | |
218 | |
219 @override | |
220 ClosureRepresentationInfo getClosureInfoForTesting(ir.Node node) { | |
221 return _localClosureRepresentationMap[node]; | |
222 } | |
223 } | 215 } |
224 | 216 |
225 class KernelScopeInfo { | 217 class KernelScopeInfo { |
226 final Set<ir.VariableDeclaration> localsUsedInTryOrSync; | 218 final Set<ir.VariableDeclaration> localsUsedInTryOrSync; |
227 final bool hasThisLocal; | 219 final bool hasThisLocal; |
228 final Set<ir.VariableDeclaration> boxedVariables; | 220 final Set<ir.VariableDeclaration> boxedVariables; |
229 // If boxedVariables is empty, this will be null, because no variables will | 221 // If boxedVariables is empty, this will be null, because no variables will |
230 // need to be boxed. | 222 // need to be boxed. |
231 final NodeBox capturedVariablesAccessor; | 223 final NodeBox capturedVariablesAccessor; |
232 | 224 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 KernelScopeInfo scopeInfo; | 557 KernelScopeInfo scopeInfo; |
566 | 558 |
567 /// Collected [CapturedScope] data for nodes. | 559 /// Collected [CapturedScope] data for nodes. |
568 Map<ir.Node, KernelCapturedScope> capturedScopesMap = | 560 Map<ir.Node, KernelCapturedScope> capturedScopesMap = |
569 <ir.Node, KernelCapturedScope>{}; | 561 <ir.Node, KernelCapturedScope>{}; |
570 | 562 |
571 /// Collected [ScopeInfo] data for nodes. | 563 /// Collected [ScopeInfo] data for nodes. |
572 Map<ir.FunctionNode, KernelScopeInfo> closuresToGenerate = | 564 Map<ir.FunctionNode, KernelScopeInfo> closuresToGenerate = |
573 <ir.FunctionNode, KernelScopeInfo>{}; | 565 <ir.FunctionNode, KernelScopeInfo>{}; |
574 } | 566 } |
OLD | NEW |