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: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart

Issue 886053003: dart2dart: Remove the list of closureVariables from FunctionDefinitions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Restore inadvertently removed code. 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 | « pkg/analyzer2dart/test/sexpr_data.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 List<LocalElement> loopVariables); 241 List<LocalElement> loopVariables);
242 242
243 /// Called before building the update of a for-loop. 243 /// Called before building the update of a for-loop.
244 void _enterForLoopUpdate(ClosureScope scope, 244 void _enterForLoopUpdate(ClosureScope scope,
245 List<LocalElement> loopVariables); 245 List<LocalElement> loopVariables);
246 246
247 /// Add the given function parameter to the IR, and bind it in the environment 247 /// Add the given function parameter to the IR, and bind it in the environment
248 /// or put it in its box, if necessary. 248 /// or put it in its box, if necessary.
249 void _createFunctionParameter(ParameterElement parameterElement); 249 void _createFunctionParameter(ParameterElement parameterElement);
250 250
251 /// Returns the list of closure variables declared in the given function or
252 /// field initializer.
253 List<ir.ClosureVariable> _getDeclaredClosureVariables(ExecutableElement elm);
254
255 /// Creates an access to the receiver from the current (or enclosing) method. 251 /// Creates an access to the receiver from the current (or enclosing) method.
256 /// 252 ///
257 /// If inside a closure class, [buildThis] will redirect access through 253 /// If inside a closure class, [buildThis] will redirect access through
258 /// closure fields in order to access the receiver from the enclosing method. 254 /// closure fields in order to access the receiver from the enclosing method.
259 ir.Primitive buildThis(); 255 ir.Primitive buildThis();
260 256
261 // TODO(johnniwinther): Make these field final and remove the default values 257 // TODO(johnniwinther): Make these field final and remove the default values
262 // when [IrBuilder] is a property of [IrBuilderVisitor] instead of a mixin. 258 // when [IrBuilder] is a property of [IrBuilderVisitor] instead of a mixin.
263 259
264 final List<ir.Parameter> _parameters = <ir.Parameter>[]; 260 final List<ir.Parameter> _parameters = <ir.Parameter>[];
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 message: "Non-empty body for abstract method $element: $_root")); 597 message: "Non-empty body for abstract method $element: $_root"));
602 assert(invariant(element, state.localConstants.isEmpty, 598 assert(invariant(element, state.localConstants.isEmpty,
603 message: "Local constants for abstract method $element: " 599 message: "Local constants for abstract method $element: "
604 "${state.localConstants}")); 600 "${state.localConstants}"));
605 return new ir.FunctionDefinition.abstract( 601 return new ir.FunctionDefinition.abstract(
606 element, state.functionParameters, defaults); 602 element, state.functionParameters, defaults);
607 } else { 603 } else {
608 ir.RunnableBody body = makeRunnableBody(); 604 ir.RunnableBody body = makeRunnableBody();
609 return new ir.FunctionDefinition( 605 return new ir.FunctionDefinition(
610 element, state.functionParameters, body, 606 element, state.functionParameters, body,
611 state.localConstants, defaults, 607 state.localConstants, defaults);
612 _getDeclaredClosureVariables(element));
613 } 608 }
614 } 609 }
615 610
616 ir.ConstructorDefinition makeConstructorDefinition( 611 ir.ConstructorDefinition makeConstructorDefinition(
617 List<ConstantExpression> defaults, List<ir.Initializer> initializers) { 612 List<ConstantExpression> defaults, List<ir.Initializer> initializers) {
618 FunctionElement element = state.currentElement; 613 FunctionElement element = state.currentElement;
619 if (element.isExternal) { 614 if (element.isExternal) {
620 assert(invariant(element, _root == null, 615 assert(invariant(element, _root == null,
621 message: "Non-empty body for external constructor $element: $_root")); 616 message: "Non-empty body for external constructor $element: $_root"));
622 assert(invariant(element, state.localConstants.isEmpty, 617 assert(invariant(element, state.localConstants.isEmpty,
623 message: "Local constants for external constructor $element: " 618 message: "Local constants for external constructor $element: "
624 "${state.localConstants}")); 619 "${state.localConstants}"));
625 return new ir.ConstructorDefinition.abstract( 620 return new ir.ConstructorDefinition.abstract(
626 element, state.functionParameters, defaults); 621 element, state.functionParameters, defaults);
627 } 622 }
628 ir.RunnableBody body = makeRunnableBody(); 623 ir.RunnableBody body = makeRunnableBody();
629 return new ir.ConstructorDefinition( 624 return new ir.ConstructorDefinition(
630 element, state.functionParameters, body, initializers, 625 element, state.functionParameters, body, initializers,
631 state.localConstants, defaults, 626 state.localConstants, defaults);
632 _getDeclaredClosureVariables(element));
633 } 627 }
634 628
635 /// Create a super invocation where the method name and the argument structure 629 /// Create a super invocation where the method name and the argument structure
636 /// are defined by [selector] and the argument values are defined by 630 /// are defined by [selector] and the argument values are defined by
637 /// [arguments]. 631 /// [arguments].
638 ir.Primitive buildSuperInvocation(Element target, 632 ir.Primitive buildSuperInvocation(Element target,
639 Selector selector, 633 Selector selector,
640 List<ir.Primitive> arguments); 634 List<ir.Primitive> arguments);
641 635
642 /// Create a setter invocation on the super class where the setter name and 636 /// Create a setter invocation on the super class where the setter name and
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 /// Captured variables are translated to ref cells (see [ClosureVariable]) 1562 /// Captured variables are translated to ref cells (see [ClosureVariable])
1569 /// using [GetClosureVariable] and [SetClosureVariable]. 1563 /// using [GetClosureVariable] and [SetClosureVariable].
1570 class DartIrBuilder extends IrBuilder { 1564 class DartIrBuilder extends IrBuilder {
1571 final DartIrBuilderSharedState dartState; 1565 final DartIrBuilderSharedState dartState;
1572 1566
1573 IrBuilder _makeInstance() => new DartIrBuilder._blank(dartState); 1567 IrBuilder _makeInstance() => new DartIrBuilder._blank(dartState);
1574 DartIrBuilder._blank(this.dartState); 1568 DartIrBuilder._blank(this.dartState);
1575 1569
1576 DartIrBuilder(ConstantSystem constantSystem, 1570 DartIrBuilder(ConstantSystem constantSystem,
1577 ExecutableElement currentElement, 1571 ExecutableElement currentElement,
1578 DartCapturedVariableInfo closureVariables) 1572 DartCapturedVariableInfo closureVariables)
1579 : dartState = new DartIrBuilderSharedState(closureVariables) { 1573 : dartState = new DartIrBuilderSharedState(closureVariables) {
1580 _init(constantSystem, currentElement); 1574 _init(constantSystem, currentElement);
1581 } 1575 }
1582 1576
1583 /// True if [local] should currently be accessed from a [ClosureVariable]. 1577 /// True if [local] should currently be accessed from a [ClosureVariable].
1584 bool isInClosureVariable(Local local) { 1578 bool isInClosureVariable(Local local) {
1585 return dartState.local2closure.containsKey(local) && 1579 return dartState.local2closure.containsKey(local) &&
1586 !dartState.registerizedClosureVariables.contains(local); 1580 !dartState.registerizedClosureVariables.contains(local);
1587 } 1581 }
1588 1582
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 assert(isOpen); 1707 assert(isOpen);
1714 if (isInClosureVariable(local)) { 1708 if (isInClosureVariable(local)) {
1715 add(new ir.SetClosureVariable(getClosureVariable(local), value)); 1709 add(new ir.SetClosureVariable(getClosureVariable(local), value));
1716 } else { 1710 } else {
1717 value.useElementAsHint(local); 1711 value.useElementAsHint(local);
1718 environment.update(local, value); 1712 environment.update(local, value);
1719 } 1713 }
1720 return value; 1714 return value;
1721 } 1715 }
1722 1716
1723 List<ir.ClosureVariable> _getDeclaredClosureVariables(
1724 ExecutableElement element) {
1725 return dartState.getClosureList(element);
1726 }
1727
1728 ir.Primitive buildThis() { 1717 ir.Primitive buildThis() {
1729 ir.Primitive thisPrim = new ir.This(); 1718 ir.Primitive thisPrim = new ir.This();
1730 add(new ir.LetPrim(thisPrim)); 1719 add(new ir.LetPrim(thisPrim));
1731 return thisPrim; 1720 return thisPrim;
1732 } 1721 }
1733 1722
1734 ir.Primitive buildSuperInvocation(Element target, 1723 ir.Primitive buildSuperInvocation(Element target,
1735 Selector selector, 1724 Selector selector,
1736 List<ir.Primitive> arguments) { 1725 List<ir.Primitive> arguments) {
1737 return _buildInvokeSuper(target, selector, arguments); 1726 return _buildInvokeSuper(target, selector, arguments);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 add(new ir.LetPrim(newBox)); 1910 add(new ir.LetPrim(newBox));
1922 for (VariableElement loopVar in scope.boxedLoopVariables) { 1911 for (VariableElement loopVar in scope.boxedLoopVariables) {
1923 ClosureLocation location = scope.capturedVariables[loopVar]; 1912 ClosureLocation location = scope.capturedVariables[loopVar];
1924 ir.Primitive get = new ir.GetField(box, location.field); 1913 ir.Primitive get = new ir.GetField(box, location.field);
1925 add(new ir.LetPrim(get)); 1914 add(new ir.LetPrim(get));
1926 add(new ir.SetField(newBox, location.field, get)); 1915 add(new ir.SetField(newBox, location.field, get));
1927 } 1916 }
1928 environment.update(scope.box, newBox); 1917 environment.update(scope.box, newBox);
1929 } 1918 }
1930 1919
1931 List<ir.ClosureVariable> _getDeclaredClosureVariables(
1932 ExecutableElement element) {
1933 return <ir.ClosureVariable>[];
1934 }
1935
1936 ir.Primitive buildThis() { 1920 ir.Primitive buildThis() {
1937 if (jsState.receiver != null) return jsState.receiver; 1921 if (jsState.receiver != null) return jsState.receiver;
1938 ir.Primitive thisPrim = new ir.This(); 1922 ir.Primitive thisPrim = new ir.This();
1939 add(new ir.LetPrim(thisPrim)); 1923 add(new ir.LetPrim(thisPrim));
1940 return thisPrim; 1924 return thisPrim;
1941 } 1925 }
1942 1926
1943 ir.Primitive buildSuperInvocation(Element target, 1927 ir.Primitive buildSuperInvocation(Element target,
1944 Selector selector, 1928 Selector selector,
1945 List<ir.Primitive> arguments) { 1929 List<ir.Primitive> arguments) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 ClosureEnvironment(this.selfReference, this.thisLocal, this.freeVariables); 2028 ClosureEnvironment(this.selfReference, this.thisLocal, this.freeVariables);
2045 } 2029 }
2046 2030
2047 /// Information about which variables are captured by a nested function. 2031 /// Information about which variables are captured by a nested function.
2048 /// 2032 ///
2049 /// This is used by the [DartIrBuilder] instead of [ClosureScope] and 2033 /// This is used by the [DartIrBuilder] instead of [ClosureScope] and
2050 /// [ClosureEnvironment]. 2034 /// [ClosureEnvironment].
2051 abstract class DartCapturedVariableInfo { 2035 abstract class DartCapturedVariableInfo {
2052 Iterable<Local> get capturedVariables; 2036 Iterable<Local> get capturedVariables;
2053 } 2037 }
OLDNEW
« no previous file with comments | « pkg/analyzer2dart/test/sexpr_data.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698