Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/closure.dart

Issue 223403003: Use closure tracer to identify closures that are not passed to Function.apply (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 closureToClassMapper; 5 library closureToClassMapper;
6 6
7 import "elements/elements.dart"; 7 import "elements/elements.dart";
8 import "dart2jslib.dart"; 8 import "dart2jslib.dart";
9 import "dart_types.dart"; 9 import "dart_types.dart";
10 import "scanner/scannerlib.dart" show Token; 10 import "scanner/scannerlib.dart" show Token;
11 import "tree/tree.dart"; 11 import "tree/tree.dart";
12 import "util/util.dart"; 12 import "util/util.dart";
13 import "elements/modelx.dart" show ElementX, FunctionElementX, ClassElementX; 13 import "elements/modelx.dart" show ElementX, SynthesizedCallMethodElementX,
14 ClassElementX;
14 import "elements/visitor.dart" show ElementVisitor; 15 import "elements/visitor.dart" show ElementVisitor;
15 16
16 class ClosureNamer { 17 class ClosureNamer {
17 String getClosureVariableName(String name, int id) { 18 String getClosureVariableName(String name, int id) {
18 return "${name}_$id"; 19 return "${name}_$id";
19 } 20 }
20 } 21 }
21 22
22 class ClosureTask extends CompilerTask { 23 class ClosureTask extends CompilerTask {
23 Map<Node, ClosureClassMap> closureMappingCache; 24 Map<Node, ClosureClassMap> closureMappingCache;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 callType = methodElement.type; 141 callType = methodElement.type;
141 } 142 }
142 143
143 bool isClosure() => true; 144 bool isClosure() => true;
144 145
145 Token position() => node.getBeginToken(); 146 Token position() => node.getBeginToken();
146 147
147 Node parseNode(DiagnosticListener listener) => node; 148 Node parseNode(DiagnosticListener listener) => node;
148 149
149 /** 150 /**
150 * The most outer method this closure is declared into. 151 * The element for the declaration of the function expression.
151 */ 152 */
152 final TypedElement methodElement; 153 final TypedElement methodElement;
153 154
154 // A [ClosureClassElement] is nested inside a function or initializer in terms 155 // A [ClosureClassElement] is nested inside a function or initializer in terms
155 // of [enclosingElement], but still has to be treated as a top-level 156 // of [enclosingElement], but still has to be treated as a top-level
156 // element. 157 // element.
157 bool isTopLevel() => true; 158 bool isTopLevel() => true;
158 159
159 get enclosingElement => methodElement; 160 get enclosingElement => methodElement;
160 161
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 parts.printOn(sb, '_'); 710 parts.printOn(sb, '_');
710 return sb.toString(); 711 return sb.toString();
711 } 712 }
712 713
713 ClosureClassMap globalizeClosure(FunctionExpression node, 714 ClosureClassMap globalizeClosure(FunctionExpression node,
714 TypedElement element) { 715 TypedElement element) {
715 String closureName = computeClosureName(element); 716 String closureName = computeClosureName(element);
716 ClassElement globalizedElement = new ClosureClassElement( 717 ClassElement globalizedElement = new ClosureClassElement(
717 node, closureName, compiler, element, element.getCompilationUnit()); 718 node, closureName, compiler, element, element.getCompilationUnit());
718 FunctionElement callElement = 719 FunctionElement callElement =
719 new FunctionElementX.from(Compiler.CALL_OPERATOR_NAME, 720 new SynthesizedCallMethodElementX(Compiler.CALL_OPERATOR_NAME,
720 element, 721 element,
721 globalizedElement); 722 globalizedElement);
722 ClosureContainer enclosing = element.enclosingElement; 723 ClosureContainer enclosing = element.enclosingElement;
723 enclosing.nestedClosures.add(callElement); 724 enclosing.nestedClosures.add(callElement);
724 globalizedElement.addMember(callElement, compiler); 725 globalizedElement.addMember(callElement, compiler);
725 // The nested function's 'this' is the same as the one for the outer 726 // The nested function's 'this' is the same as the one for the outer
726 // function. It could be [null] if we are inside a static method. 727 // function. It could be [null] if we are inside a static method.
727 Element thisElement = closureData.thisElement; 728 Element thisElement = closureData.thisElement;
728 return new ClosureClassMap(element, globalizedElement, 729 return new ClosureClassMap(element, globalizedElement,
729 callElement, thisElement); 730 callElement, thisElement);
730 } 731 }
731 732
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 } 832 }
832 833
833 visitTryStatement(TryStatement node) { 834 visitTryStatement(TryStatement node) {
834 // TODO(ngeoffray): implement finer grain state. 835 // TODO(ngeoffray): implement finer grain state.
835 bool oldInTryStatement = inTryStatement; 836 bool oldInTryStatement = inTryStatement;
836 inTryStatement = true; 837 inTryStatement = true;
837 node.visitChildren(this); 838 node.visitChildren(this);
838 inTryStatement = oldInTryStatement; 839 inTryStatement = oldInTryStatement;
839 } 840 }
840 } 841 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698