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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 final Local closureEntity; | 364 final Local closureEntity; |
365 final Local thisLocal; | 365 final Local thisLocal; |
366 final JClass closureClassEntity; | 366 final JClass closureClassEntity; |
367 | 367 |
368 final Map<Local, JField> localToFieldMap = new Map<Local, JField>(); | 368 final Map<Local, JField> localToFieldMap = new Map<Local, JField>(); |
369 | 369 |
370 KernelClosureClass.fromScopeInfo( | 370 KernelClosureClass.fromScopeInfo( |
371 this.closureClassEntity, | 371 this.closureClassEntity, |
372 ir.FunctionNode closureSourceNode, | 372 ir.FunctionNode closureSourceNode, |
373 KernelScopeInfo info, | 373 KernelScopeInfo info, |
374 KernelToLocalsMap localsMap) | 374 KernelToLocalsMap localsMap, |
375 : closureEntity = closureSourceNode.parent is ir.Member | 375 this.closureEntity, |
376 ? null | 376 this.thisLocal) |
377 // TODO(johnniwinther,efortuna): This is the only place we call | 377 : super.from(info, localsMap); |
378 // [getLocalFunction]. Therefore the [closureEntity] doesn't need | |
379 // to be derived from the node. | |
380 // | |
381 // What we should do instead: If `closureSourceNode.parent` is | |
382 // an [ir.FunctionDeclaration] we should use the local for its | |
383 // variable. If `closureSourceNode.parent` is an | |
384 // [ir.FunctionExpression], we should create a fresh local. | |
385 : localsMap.getLocalFunction(closureSourceNode.parent), | |
386 thisLocal = | |
387 info.hasThisLocal ? new ThisLocal(localsMap.currentMember) : null, | |
388 super.from(info, localsMap); | |
389 | 378 |
390 List<Local> get createdFieldEntities => localToFieldMap.keys.toList(); | 379 List<Local> get createdFieldEntities => localToFieldMap.keys.toList(); |
391 | 380 |
392 FieldEntity get thisFieldEntity => localToFieldMap[thisLocal]; | 381 FieldEntity get thisFieldEntity => localToFieldMap[thisLocal]; |
393 | 382 |
394 void forEachCapturedVariable(f(Local from, JField to)) { | 383 void forEachCapturedVariable(f(Local from, JField to)) { |
395 localToFieldMap.forEach(f); | 384 localToFieldMap.forEach(f); |
396 } | 385 } |
397 | 386 |
398 @override | 387 @override |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 KernelScopeInfo scopeInfo; | 559 KernelScopeInfo scopeInfo; |
571 | 560 |
572 /// Collected [CapturedScope] data for nodes. | 561 /// Collected [CapturedScope] data for nodes. |
573 Map<ir.Node, KernelCapturedScope> capturedScopesMap = | 562 Map<ir.Node, KernelCapturedScope> capturedScopesMap = |
574 <ir.Node, KernelCapturedScope>{}; | 563 <ir.Node, KernelCapturedScope>{}; |
575 | 564 |
576 /// Collected [ScopeInfo] data for nodes. | 565 /// Collected [ScopeInfo] data for nodes. |
577 Map<ir.FunctionNode, KernelScopeInfo> closuresToGenerate = | 566 Map<ir.FunctionNode, KernelScopeInfo> closuresToGenerate = |
578 <ir.FunctionNode, KernelScopeInfo>{}; | 567 <ir.FunctionNode, KernelScopeInfo>{}; |
579 } | 568 } |
OLD | NEW |