| 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 visited call node with the associated information about what |
| 17 /// variables are captured/used. Each ir.Node key corresponds to a scope that | 17 /// variables are captured/used. Each ir.Node key corresponds to a scope that |
| 18 /// was encountered while visiting a closure (initially called through | 18 /// was encountered while visiting a closure (initially called through |
| 19 /// [translateLazyIntializer] or [translateConstructorOrProcedure]). | 19 /// [translateLazyIntializer] or [translateConstructorOrProcedure]). |
| 20 Map<ir.Node, ClosureScope> _closureInfoMap = <ir.Node, ClosureScope>{}; | 20 Map<ir.Node, ClosureScope> _closureInfoMap = <ir.Node, ClosureScope>{}; |
| 21 | 21 |
| 22 /// A map of the nodes that we have flagged as necessary to generate closure | 22 /// A map of the nodes that we have flagged as necessary to generate closure |
| 23 /// classes for in a later stage. We map that node to information ascertained | 23 /// classes for in a later stage. We map that node to information ascertained |
| 24 /// about variable usage in the surrounding scope. | 24 /// about variable usage in the surrounding scope. |
| 25 Map<ir.Node /* ir.Field | ir.FunctionNode */, ScopeInfo> _closuresToGenerate = | 25 Map<ir.TreeNode /* ir.Field | ir.FunctionNode */, ScopeInfo> |
| 26 <ir.Node, ScopeInfo>{}; | 26 _closuresToGenerate = <ir.TreeNode, ScopeInfo>{}; |
| 27 | 27 |
| 28 /// The local variables that have been declared in the current scope. | 28 /// The local variables that have been declared in the current scope. |
| 29 List<ir.VariableDeclaration> _scopeVariables; | 29 List<ir.VariableDeclaration> _scopeVariables; |
| 30 | 30 |
| 31 /// Pointer to the context in which this closure is executed. | 31 /// Pointer to the context in which this closure is executed. |
| 32 /// For example, in the expression `var foo = () => 3 + i;`, the executable | 32 /// For example, in the expression `var foo = () => 3 + i;`, the executable |
| 33 /// context as we walk the nodes in that expression is the ir.Field `foo`. | 33 /// context as we walk the nodes in that expression is the ir.Field `foo`. |
| 34 ir.Node _executableContext; | 34 ir.Node _executableContext; |
| 35 | 35 |
| 36 /// A flag to indicate if we are currently inside a closure. | 36 /// A flag to indicate if we are currently inside a closure. |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 nodeToConvert.isInstanceMember)) { | 285 nodeToConvert.isInstanceMember)) { |
| 286 return new ThisLocal(_kernelToElementMap.getConstructor(nodeToConvert)); | 286 return new ThisLocal(_kernelToElementMap.getConstructor(nodeToConvert)); |
| 287 } else if (nodeToConvert is ir.Procedure && | 287 } else if (nodeToConvert is ir.Procedure && |
| 288 nodeToConvert.isInstanceMember) { | 288 nodeToConvert.isInstanceMember) { |
| 289 return new ThisLocal(_kernelToElementMap.getMethod(nodeToConvert)); | 289 return new ThisLocal(_kernelToElementMap.getMethod(nodeToConvert)); |
| 290 } | 290 } |
| 291 } | 291 } |
| 292 return null; | 292 return null; |
| 293 } | 293 } |
| 294 } | 294 } |
| OLD | NEW |