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 library dart2js.js_model.locals; | 5 library dart2js.js_model.locals; |
6 | 6 |
7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
8 | 8 |
| 9 import 'closure.dart' show JClosureClass; |
9 import '../closure.dart'; | 10 import '../closure.dart'; |
10 import '../common.dart'; | 11 import '../common.dart'; |
11 import '../elements/entities.dart'; | 12 import '../elements/entities.dart'; |
12 import '../elements/jumps.dart'; | 13 import '../elements/jumps.dart'; |
13 import '../kernel/element_map.dart'; | 14 import '../kernel/element_map.dart'; |
14 | 15 |
15 class GlobalLocalsMap { | 16 class GlobalLocalsMap { |
16 Map<MemberEntity, KernelToLocalsMap> _localsMaps = | 17 Map<MemberEntity, KernelToLocalsMap> _localsMaps = |
17 <MemberEntity, KernelToLocalsMap>{}; | 18 <MemberEntity, KernelToLocalsMap>{}; |
18 | 19 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return _jumpTargetMap[node]; | 119 return _jumpTargetMap[node]; |
119 } | 120 } |
120 | 121 |
121 @override | 122 @override |
122 JumpTarget getJumpTargetForWhile(ir.WhileStatement node) { | 123 JumpTarget getJumpTargetForWhile(ir.WhileStatement node) { |
123 _ensureJumpMap(node); | 124 _ensureJumpMap(node); |
124 return _jumpTargetMap[node]; | 125 return _jumpTargetMap[node]; |
125 } | 126 } |
126 | 127 |
127 @override | 128 @override |
128 Local getLocalVariable(ir.VariableDeclaration node) { | 129 Local getLocalVariable(ir.VariableDeclaration node, |
| 130 {bool isClosureCallMethod = false}) { |
| 131 if (isClosureCallMethod && !_map.containsKey(node)) { |
| 132 // Node might correspond to a free variable in the closure class. |
| 133 assert(currentMember.enclosingClass is JClosureClass); |
| 134 return (currentMember.enclosingClass as JClosureClass) |
| 135 .localsMap |
| 136 .getLocalVariable(node); |
| 137 } |
129 return _map.putIfAbsent(node, () { | 138 return _map.putIfAbsent(node, () { |
130 return new JLocal(node.name, currentMember); | 139 return new JLocal( |
| 140 node.name, currentMember, node.parent is ir.FunctionNode); |
131 }); | 141 }); |
132 } | 142 } |
133 | 143 |
134 @override | 144 @override |
135 // TODO(johnniwinther): Split this out into two methods -- one for | 145 // TODO(johnniwinther): Split this out into two methods -- one for |
136 // FunctionDeclaration and one for FunctionExpression, since basically the | 146 // FunctionDeclaration and one for FunctionExpression, since basically the |
137 // whole thing is different depending on the node type. The reason it's not | 147 // whole thing is different depending on the node type. The reason it's not |
138 // done yet is the version of this function that it's overriding has a little | 148 // done yet is the version of this function that it's overriding has a little |
139 // bit of commonality. | 149 // bit of commonality. |
140 Local getLocalFunction(ir.TreeNode node) { | 150 Local getLocalFunction(ir.TreeNode node) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 sb.write(isContinueTarget); | 283 sb.write(isContinueTarget); |
274 sb.write(']'); | 284 sb.write(']'); |
275 return sb.toString(); | 285 return sb.toString(); |
276 } | 286 } |
277 } | 287 } |
278 | 288 |
279 class JLocal implements Local { | 289 class JLocal implements Local { |
280 final String name; | 290 final String name; |
281 final MemberEntity memberContext; | 291 final MemberEntity memberContext; |
282 | 292 |
283 JLocal(this.name, this.memberContext); | 293 /// True if this local represents a local parameter. |
| 294 final bool isRegularParameter; |
| 295 |
| 296 JLocal(this.name, this.memberContext, [isParameter = false]) |
| 297 : isRegularParameter = isParameter; |
284 | 298 |
285 @override | 299 @override |
286 Entity get executableContext => memberContext; | 300 Entity get executableContext => memberContext; |
287 | 301 |
288 String toString() { | 302 String toString() { |
289 StringBuffer sb = new StringBuffer(); | 303 StringBuffer sb = new StringBuffer(); |
290 sb.write('local('); | 304 sb.write('local('); |
291 if (memberContext.enclosingClass != null) { | 305 if (memberContext.enclosingClass != null) { |
292 sb.write(memberContext.enclosingClass.name); | 306 sb.write(memberContext.enclosingClass.name); |
293 sb.write('.'); | 307 sb.write('.'); |
294 } | 308 } |
295 sb.write(memberContext.name); | 309 sb.write(memberContext.name); |
296 sb.write('#'); | 310 sb.write('#'); |
297 sb.write(name); | 311 sb.write(name); |
298 sb.write(')'); | 312 sb.write(')'); |
299 return sb.toString(); | 313 return sb.toString(); |
300 } | 314 } |
301 } | 315 } |
OLD | NEW |