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 '../elements/entities.dart'; | 8 import '../elements/entities.dart'; |
9 import '../kernel/element_map.dart'; | 9 import '../kernel/element_map.dart'; |
10 import 'closure.dart'; | 10 import 'closure.dart'; |
11 | 11 |
12 /// This builder walks the code to determine what variables are captured/free at | 12 /// This builder walks the code to determine what variables are captured/free at |
13 /// various points to build ClosureScope that can respond to queries | 13 /// various points to build ClosureScope that can respond to queries |
14 /// about how a particular variable is being used at any point in the code. | 14 /// about how a particular variable is being used at any point in the code. |
15 class ClosureScopeBuilder extends ir.Visitor { | 15 class ClosureScopeBuilder extends ir.Visitor { |
16 /// A map of each visited call node with the associated information about what | 16 /// A map of each for loop statement and the corresponding variable |
17 /// variables are captured/used. Each ir.Node key corresponds to a scope that | 17 /// information about what variables are captured/used in the this for loop |
18 /// was encountered while visiting a closure (initially called through | 18 /// declaration. |
19 /// [translateLazyIntializer] or [translateConstructorOrProcedure]). | |
20 // TODODODOOOOOO | |
21 final Map<ir.Statement, LoopClosureScope> _loopClosureScopeMap; | 19 final Map<ir.Statement, LoopClosureScope> _loopClosureScopeMap; |
22 | 20 |
23 /// Map entities to their corresponding scope information (such as what | 21 /// Map entities to their corresponding scope information (such as what |
24 /// variables are captured/used). The distinction between this map and | 22 /// variables are captured/used). |
25 /// [_closureInfoMap] is that [_closureInfoMap] stores this data for closures | |
26 /// specifically, whereas [_scopeInfoMap] stores this information for entities | |
27 /// that are *not* closures (this information is used by the locals handler). | |
28 /// The union of these two maps represents all the scopes encountered. | |
29 final Map<Entity, ScopeInfo> _scopeInfoMap; | 23 final Map<Entity, ScopeInfo> _scopeInfoMap; |
30 | 24 |
31 /// A map of the nodes that we have flagged as necessary to generate closure | 25 /// A map of the nodes that we have flagged as necessary to generate closure |
32 /// classes for in a later stage. We map that node to information ascertained | 26 /// classes for in a later stage. We map that node to information ascertained |
33 /// about variable usage in the surrounding scope. | 27 /// about variable usage in the surrounding scope. |
34 final Map<ir.TreeNode /* ir.Field | ir.FunctionNode */, ScopeInfo> | 28 final Map<ir.TreeNode /* ir.Field | ir.FunctionNode */, ScopeInfo> |
35 _closuresToGenerate; | 29 _closuresToGenerate; |
36 | 30 |
37 /// The local variables that have been declared in the current scope. | 31 /// The local variables that have been declared in the current scope. |
38 List<ir.VariableDeclaration> _scopeVariables; | 32 List<ir.VariableDeclaration> _scopeVariables; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 nodeToConvert.isInstanceMember)) { | 306 nodeToConvert.isInstanceMember)) { |
313 return new ThisLocal(_kernelToElementMap.getConstructor(nodeToConvert)); | 307 return new ThisLocal(_kernelToElementMap.getConstructor(nodeToConvert)); |
314 } else if (nodeToConvert is ir.Procedure && | 308 } else if (nodeToConvert is ir.Procedure && |
315 nodeToConvert.isInstanceMember) { | 309 nodeToConvert.isInstanceMember) { |
316 return new ThisLocal(_kernelToElementMap.getMethod(nodeToConvert)); | 310 return new ThisLocal(_kernelToElementMap.getMethod(nodeToConvert)); |
317 } | 311 } |
318 } | 312 } |
319 return null; | 313 return null; |
320 } | 314 } |
321 } | 315 } |
OLD | NEW |