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

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

Issue 9542001: Fix this capturing in closures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « no previous file | frog/leg/ssa/closure.dart » ('j') | tests/co19/co19-leg.status » ('J')
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 Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 closureData = translator.translate(node); 254 closureData = translator.translate(node);
255 255
256 FunctionParameters params = function.computeParameters(builder.compiler); 256 FunctionParameters params = function.computeParameters(builder.compiler);
257 params.forEachParameter((Element element) { 257 params.forEachParameter((Element element) {
258 HParameterValue parameter = new HParameterValue(element); 258 HParameterValue parameter = new HParameterValue(element);
259 builder.add(parameter); 259 builder.add(parameter);
260 // Note that for constructors [element] could be a field-element which we 260 // Note that for constructors [element] could be a field-element which we
261 // treat as if it was a local. 261 // treat as if it was a local.
262 directLocals[element] = parameter; 262 directLocals[element] = parameter;
263 }); 263 });
264 if (closureData.thisElement !== null) {
265 // Note that closures, once they are mapped to classes, might have
266 // instance-members that do *not* have any thisElement.
ngeoffray 2012/02/29 12:22:17 Please explain why.
floitsch 2012/02/29 12:35:28 Done.
267 assert(function.isInstanceMember() || function.isGenerativeConstructor());
268 // We have to introduce 'this' before we enter the scope, since it might
269 // need to be copied into a box (if it is captured). This is similar
270 // to all other parameters that are introduced.
271 HInstruction thisInstruction = new HThis();
272 builder.add(thisInstruction);
273 // directLocals[closureData.thisElement] = thisInstruction;
ngeoffray 2012/02/29 12:22:17 Why is this commented out?
floitsch 2012/02/29 12:35:28 this one is the correct one...
274 updateLocal(closureData.thisElement, thisInstruction);
ngeoffray 2012/02/29 12:22:17 Why do you call updateLocal, and not use directLoc
floitsch 2012/02/29 12:35:28 debug code...
275 }
264 276
265 enterScope(node); 277 enterScope(node);
266 278
267 // If the freeVariableMapping is not empty, then this function was a 279 // If the freeVariableMapping is not empty, then this function was a
268 // nested closure that captures variables. Redirect the captured 280 // nested closure that captures variables. Redirect the captured
269 // variables to fields in the closure. 281 // variables to fields in the closure.
270 closureData.freeVariableMapping.forEach((Element from, Element to) { 282 closureData.freeVariableMapping.forEach((Element from, Element to) {
271 redirectElement(from, to); 283 redirectElement(from, to);
272 }); 284 });
273 if (closureData.isClosure()) { 285 if (closureData.isClosure()) {
274 // Inside closure redirect references to itself to [:this:]. 286 // Inside closure redirect references to itself to [:this:].
275 HInstruction thisInstruction = new HThis(); 287 HInstruction thisInstruction = new HThis();
276 builder.add(thisInstruction); 288 builder.add(thisInstruction);
277 updateLocal(closureData.closureElement, thisInstruction); 289 updateLocal(closureData.closureElement, thisInstruction);
278 } else if (function.isInstanceMember() ||
279 function.isGenerativeConstructor()) {
280 HInstruction thisInstruction = new HThis();
281 builder.add(thisInstruction);
282 updateLocal(closureData.thisElement, thisInstruction);
283 } 290 }
284 } 291 }
285 292
286 bool hasValueForDirectLocal(Element element) { 293 bool hasValueForDirectLocal(Element element) {
287 assert(element !== null); 294 assert(element !== null);
288 assert(isAccessedDirectly(element)); 295 assert(isAccessedDirectly(element));
289 return directLocals[element] !== null; 296 return directLocals[element] !== null;
290 } 297 }
291 298
292 /** 299 /**
(...skipping 2015 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 } 2315 }
2309 2316
2310 visitCatchBlock(CatchBlock node) { 2317 visitCatchBlock(CatchBlock node) {
2311 visit(node.block); 2318 visit(node.block);
2312 } 2319 }
2313 2320
2314 visitTypedef(Typedef node) { 2321 visitTypedef(Typedef node) {
2315 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); 2322 compiler.unimplemented('SsaBuilder.visitTypedef', node: node);
2316 } 2323 }
2317 } 2324 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/ssa/closure.dart » ('j') | tests/co19/co19-leg.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698