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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart

Issue 916403002: cps2js: Fix translation of captured 'this'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase Created 5 years, 10 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 | tests/compiler/dart2js/js_backend_cps_ir_closures_test.dart » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart2js.ir_builder; 5 library dart2js.ir_builder;
6 6
7 import '../constants/expressions.dart'; 7 import '../constants/expressions.dart';
8 import '../constants/values.dart' show PrimitiveConstantValue; 8 import '../constants/values.dart' show PrimitiveConstantValue;
9 import '../dart_types.dart'; 9 import '../dart_types.dart';
10 import '../dart2jslib.dart'; 10 import '../dart2jslib.dart';
(...skipping 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 /// Add [functionElement] to the environment with provided [definition]. 1815 /// Add [functionElement] to the environment with provided [definition].
1816 void declareLocalFunction(LocalFunctionElement functionElement, 1816 void declareLocalFunction(LocalFunctionElement functionElement,
1817 ClosureClassElement classElement) { 1817 ClosureClassElement classElement) {
1818 ir.Primitive closure = buildFunctionExpression(classElement); 1818 ir.Primitive closure = buildFunctionExpression(classElement);
1819 declareLocalVariable(functionElement, initialValue: closure); 1819 declareLocalVariable(functionElement, initialValue: closure);
1820 } 1820 }
1821 1821
1822 ir.Primitive buildFunctionExpression(ClosureClassElement classElement) { 1822 ir.Primitive buildFunctionExpression(ClosureClassElement classElement) {
1823 List<ir.Primitive> arguments = <ir.Primitive>[]; 1823 List<ir.Primitive> arguments = <ir.Primitive>[];
1824 for (ClosureFieldElement field in classElement.closureFields) { 1824 for (ClosureFieldElement field in classElement.closureFields) {
1825 arguments.add(environment.lookup(field.local)); 1825 // Captured 'this' is not available as a local in the current environment,
1826 // so treat that specially.
1827 ir.Primitive value = field.local is ThisLocal
1828 ? buildThis()
1829 : environment.lookup(field.local);
1830 arguments.add(value);
1826 } 1831 }
1827 ir.Primitive closure = new ir.CreateInstance(classElement, arguments); 1832 ir.Primitive closure = new ir.CreateInstance(classElement, arguments);
1828 add(new ir.LetPrim(closure)); 1833 add(new ir.LetPrim(closure));
1829 return closure; 1834 return closure;
1830 } 1835 }
1831 1836
1832 /// Create a read access of [local]. 1837 /// Create a read access of [local].
1833 ir.Primitive buildLocalGet(LocalElement local) { 1838 ir.Primitive buildLocalGet(LocalElement local) {
1834 assert(isOpen); 1839 assert(isOpen);
1835 ClosureLocation location = jsState.boxedVariables[local]; 1840 ClosureLocation location = jsState.boxedVariables[local];
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 ClosureEnvironment(this.selfReference, this.thisLocal, this.freeVariables); 2012 ClosureEnvironment(this.selfReference, this.thisLocal, this.freeVariables);
2008 } 2013 }
2009 2014
2010 /// Information about which variables are captured by a nested function. 2015 /// Information about which variables are captured by a nested function.
2011 /// 2016 ///
2012 /// This is used by the [DartIrBuilder] instead of [ClosureScope] and 2017 /// This is used by the [DartIrBuilder] instead of [ClosureScope] and
2013 /// [ClosureEnvironment]. 2018 /// [ClosureEnvironment].
2014 abstract class DartCapturedVariableInfo { 2019 abstract class DartCapturedVariableInfo {
2015 Iterable<Local> get capturedVariables; 2020 Iterable<Local> get capturedVariables;
2016 } 2021 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/js_backend_cps_ir_closures_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698