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

Side by Side Diff: lib/compiler/implementation/ssa/closure.dart

Issue 10398044: Reverting 7667 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 class ClosureFieldElement extends Element { 5 class ClosureFieldElement extends Element {
6 ClosureFieldElement(SourceString name, ClassElement enclosing) 6 ClosureFieldElement(SourceString name, ClassElement enclosing)
7 : super(name, ElementKind.FIELD, enclosing); 7 : super(name, ElementKind.FIELD, enclosing);
8 8
9 bool isInstanceMember() => true; 9 bool isInstanceMember() => true;
10 bool isAssignable() => false; 10 bool isAssignable() => false;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 this.thisElement) 90 this.thisElement)
91 : this.freeVariableMapping = new Map<Element, Element>(), 91 : this.freeVariableMapping = new Map<Element, Element>(),
92 this.capturedFieldMapping = new Map<Element, Element>(), 92 this.capturedFieldMapping = new Map<Element, Element>(),
93 this.capturingScopes = new Map<Node, ClosureScope>(), 93 this.capturingScopes = new Map<Node, ClosureScope>(),
94 this.usedVariablesInTry = new Set<Element>(); 94 this.usedVariablesInTry = new Set<Element>();
95 95
96 bool isClosure() => closureElement !== null; 96 bool isClosure() => closureElement !== null;
97 } 97 }
98 98
99 class ClosureTranslator extends AbstractVisitor { 99 class ClosureTranslator extends AbstractVisitor {
100 final SsaBuilder builder; 100 final Compiler compiler;
101 final TreeElements elements; 101 final TreeElements elements;
102 int closureFieldCounter = 0; 102 int closureFieldCounter = 0;
103 bool inTryCatchOrFinally = false; 103 bool inTryCatchOrFinally = false;
104 final Map<Node, ClosureData> closureDataCache; 104 final Map<Node, ClosureData> closureDataCache;
105 105
106 // Map of captured variables. Initially they will map to themselves. If 106 // Map of captured variables. Initially they will map to themselves. If
107 // a variable needs to be boxed then the scope declaring the variable 107 // a variable needs to be boxed then the scope declaring the variable
108 // will update this mapping. 108 // will update this mapping.
109 Map<Element, Element> capturedVariableMapping; 109 Map<Element, Element> capturedVariableMapping;
110 // List of encountered closures. 110 // List of encountered closures.
111 List<FunctionExpression> closures; 111 List<FunctionExpression> closures;
112 112
113 // The variables that have been declared in the current scope. 113 // The variables that have been declared in the current scope.
114 List<Element> scopeVariables; 114 List<Element> scopeVariables;
115 115
116 FunctionElement currentFunctionElement; 116 FunctionElement currentFunctionElement;
117 // The closureData of the currentFunctionElement. 117 // The closureData of the currentFunctionElement.
118 ClosureData closureData; 118 ClosureData closureData;
119 119
120 bool insideClosure = false; 120 bool insideClosure = false;
121 121
122 Compiler get compiler() => builder.compiler; 122 ClosureTranslator(Compiler compiler, this.elements)
123 123 : capturedVariableMapping = new Map<Element, Element>(),
124 ClosureTranslator(SsaBuilder builder)
125 : this.builder = builder,
126 this.elements = builder.elements,
127 capturedVariableMapping = new Map<Element, Element>(),
128 closures = <FunctionExpression>[], 124 closures = <FunctionExpression>[],
129 this.closureDataCache = builder.builder.closureDataCache; 125 this.compiler = compiler,
126 this.closureDataCache = compiler.builder.closureDataCache;
130 127
131 ClosureData translate(Node node) { 128 ClosureData translate(Node node) {
132 // Closures have already been analyzed when visiting the surrounding 129 // Closures have already been analyzed when visiting the surrounding
133 // method/function. This also shortcuts for bailout functions. 130 // method/function. This also shortcuts for bailout functions.
134 ClosureData cached = closureDataCache[node]; 131 ClosureData cached = closureDataCache[node];
135 if (cached !== null) return cached; 132 if (cached !== null) return cached;
136 133
137 visit(node); 134 visit(node);
138 // When variables need to be boxed their [capturedVariableMapping] is 135 // When variables need to be boxed their [capturedVariableMapping] is
139 // updated, but we delay updating the similar freeVariableMapping in the 136 // updated, but we delay updating the similar freeVariableMapping in the
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 declareLocal(elements[node]); 429 declareLocal(elements[node]);
433 } 430 }
434 431
435 visitTryStatement(TryStatement node) { 432 visitTryStatement(TryStatement node) {
436 // TODO(ngeoffray): implement finer grain state. 433 // TODO(ngeoffray): implement finer grain state.
437 inTryCatchOrFinally = true; 434 inTryCatchOrFinally = true;
438 node.visitChildren(this); 435 node.visitChildren(this);
439 inTryCatchOrFinally = false; 436 inTryCatchOrFinally = false;
440 } 437 }
441 } 438 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/ssa/builder.dart ('k') | lib/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698