| Index: pkg/compiler/lib/src/kernel/closure.dart
|
| diff --git a/pkg/compiler/lib/src/kernel/closure.dart b/pkg/compiler/lib/src/kernel/closure.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..880db615e392d7c4cb6bd04d2fb39e14e485ed80
|
| --- /dev/null
|
| +++ b/pkg/compiler/lib/src/kernel/closure.dart
|
| @@ -0,0 +1,135 @@
|
| +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +import 'package:kernel/ast.dart' as ir;
|
| +
|
| +import '../closure.dart';
|
| +import '../common.dart';
|
| +import '../common/codegen.dart' show CodegenRegistry;
|
| +import '../common/names.dart';
|
| +import '../common_elements.dart';
|
| +import '../compiler.dart';
|
| +import '../constants/values.dart'
|
| + show
|
| + ConstantValue,
|
| + InterceptorConstantValue,
|
| + StringConstantValue,
|
| + TypeConstantValue;
|
| +import '../elements/elements.dart';
|
| +import '../elements/entities.dart';
|
| +import '../elements/jumps.dart';
|
| +import '../elements/resolution_types.dart';
|
| +import '../elements/types.dart';
|
| +import '../io/source_information.dart';
|
| +import '../js/js.dart' as js;
|
| +import '../js_backend/backend.dart' show JavaScriptBackend;
|
| +import '../kernel/closure.dart';
|
| +import '../native/native.dart' as native;
|
| +import '../resolution/tree_elements.dart';
|
| +import '../tree/nodes.dart' show Node;
|
| +import '../types/masks.dart';
|
| +import '../universe/selector.dart';
|
| +import '../universe/side_effects.dart' show SideEffects;
|
| +import '../universe/use.dart' show DynamicUse;
|
| +import '../universe/world_builder.dart' show CodegenWorldBuilder;
|
| +import '../world.dart';
|
| +import 'element_map.dart';
|
| +import 'element_map_impl.dart';
|
| +
|
| +class KernelClosureDataBuilder extends ir.Visitor {
|
| + final KernelToLocalsMap _localsMap;
|
| + final KernelClosureRepresentationInfo info;
|
| +
|
| + bool _inTry = false;
|
| +
|
| + KernelClosureDataBuilder(this._localsMap, ThisLocal thisLocal)
|
| + : info = new KernelClosureRepresentationInfo(thisLocal);
|
| +
|
| + @override
|
| + defaultNode(ir.Node node) {
|
| + node.visitChildren(this);
|
| + }
|
| +
|
| + @override
|
| + visitTryCatch(ir.TryCatch node) {
|
| + bool oldInTry = _inTry;
|
| + _inTry = true;
|
| + node.visitChildren(this);
|
| + _inTry = oldInTry;
|
| + }
|
| +
|
| + @override
|
| + visitTryFinally(ir.TryFinally node) {
|
| + bool oldInTry = _inTry;
|
| + _inTry = true;
|
| + node.visitChildren(this);
|
| + _inTry = oldInTry;
|
| + }
|
| +
|
| + @override
|
| + visitVariableGet(ir.VariableGet node) {
|
| + if (_inTry) {
|
| + info.registerUsedInTryOrSync(_localsMap.getLocal(node.variable));
|
| + }
|
| + }
|
| +}
|
| +
|
| +/// TODO(johnniwinther,efortuna): Merge this with [KernelClosureConversionTask].
|
| +class KernelClosureDataLookup implements ClosureDataLookup<ir.Node> {
|
| + final KernelToElementMapImpl _elementMap;
|
| + final KernelToLocalsMap _localsMap;
|
| + Map<Entity, ClosureRepresentationInfo> _infoMap =
|
| + <Entity, ClosureRepresentationInfo>{};
|
| +
|
| + KernelClosureDataLookup(this._elementMap, this._localsMap);
|
| +
|
| + /// TODO(johnniwinther,efortuna): Implement this.
|
| + @override
|
| + ClosureAnalysisInfo getClosureAnalysisInfo(ir.Node node) {
|
| + return const ClosureAnalysisInfo();
|
| + }
|
| +
|
| + /// TODO(johnniwinther,efortuna): Implement this.
|
| + @override
|
| + LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop(
|
| + ir.Node loopNode) {
|
| + return const LoopClosureRepresentationInfo();
|
| + }
|
| +
|
| + @override
|
| + ClosureRepresentationInfo getClosureRepresentationInfo(Entity entity) {
|
| + return _infoMap.putIfAbsent(entity, () {
|
| + if (entity is MemberEntity) {
|
| + ir.Member node = _elementMap.getMemberNode(entity);
|
| + ThisLocal thisLocal;
|
| + if (entity.isInstanceMember) {
|
| + thisLocal = new ThisLocal(entity);
|
| + }
|
| + KernelClosureDataBuilder builder =
|
| + new KernelClosureDataBuilder(_localsMap, thisLocal);
|
| + node.accept(builder);
|
| + return builder.info;
|
| + }
|
| +
|
| + /// TODO(johnniwinther,efortuna): Implement this.
|
| + return const ClosureRepresentationInfo();
|
| + });
|
| + }
|
| +}
|
| +
|
| +// TODO(johnniwinther): Add unittest for the computed
|
| +// [ClosureRepresentationInfo].
|
| +class KernelClosureRepresentationInfo extends ClosureRepresentationInfo {
|
| + final ThisLocal thisLocal;
|
| + final Set<Local> _localsUsedInTryOrSync = new Set<Local>();
|
| +
|
| + KernelClosureRepresentationInfo(this.thisLocal);
|
| +
|
| + void registerUsedInTryOrSync(Local local) {
|
| + _localsUsedInTryOrSync.add(local);
|
| + }
|
| +
|
| + bool variableIsUsedInTryOrSync(Local variable) =>
|
| + _localsUsedInTryOrSync.contains(variable);
|
| +}
|
|
|