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

Side by Side Diff: frog/leg/ssa/closure.dart

Issue 9542001: Fix this capturing in closures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 9 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
« no previous file with comments | « frog/leg/ssa/builder.dart ('k') | frog/tests/leg_only/leg_only.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 functionElement = body.constructor; 171 functionElement = body.constructor;
172 } 172 }
173 // If the element is not declared in the current function and the element 173 // If the element is not declared in the current function and the element
174 // is not the closure itself we need to mark the element as free variable. 174 // is not the closure itself we need to mark the element as free variable.
175 if (element.enclosingElement != functionElement && 175 if (element.enclosingElement != functionElement &&
176 element != functionElement) { 176 element != functionElement) {
177 assert(closureData.freeVariableMapping[element] == null || 177 assert(closureData.freeVariableMapping[element] == null ||
178 closureData.freeVariableMapping[element] == element); 178 closureData.freeVariableMapping[element] == element);
179 closureData.freeVariableMapping[element] = element; 179 closureData.freeVariableMapping[element] = element;
180 } else if (inTryCatchOrFinally) { 180 } else if (inTryCatchOrFinally) {
181 // TODO(ngeoffray): only do this if the variable is mutated. 181 // Don't mark the this-element. This would complicate things in the
182 closureData.usedVariablesInTry.add(element); 182 // builder.
183 if (element != closureData.thisElement) {
184 // TODO(ngeoffray): only do this if the variable is mutated.
185 closureData.usedVariablesInTry.add(element);
186 }
183 } 187 }
184 } 188 }
185 189
186 void declareLocal(Element element) { 190 void declareLocal(Element element) {
187 scopeVariables.add(element); 191 scopeVariables.add(element);
188 } 192 }
189 193
190 visit(Node node) => node.accept(this); 194 visit(Node node) => node.accept(this);
191 195
192 visitNode(Node node) => node.visitChildren(this); 196 visitNode(Node node) => node.visitChildren(this);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 declareLocal(elements[node]); 405 declareLocal(elements[node]);
402 } 406 }
403 407
404 visitTryStatement(TryStatement node) { 408 visitTryStatement(TryStatement node) {
405 // TODO(ngeoffray): implement finer grain state. 409 // TODO(ngeoffray): implement finer grain state.
406 inTryCatchOrFinally = true; 410 inTryCatchOrFinally = true;
407 node.visitChildren(this); 411 node.visitChildren(this);
408 inTryCatchOrFinally = false; 412 inTryCatchOrFinally = false;
409 } 413 }
410 } 414 }
OLDNEW
« no previous file with comments | « frog/leg/ssa/builder.dart ('k') | frog/tests/leg_only/leg_only.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698