| OLD | NEW |
| 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 } | 393 } |
| 394 | 394 |
| 395 ir.Primitive _buildInvokeStatic(Element element, | 395 ir.Primitive _buildInvokeStatic(Element element, |
| 396 Selector selector, | 396 Selector selector, |
| 397 List<ir.Primitive> arguments) { | 397 List<ir.Primitive> arguments) { |
| 398 assert(isOpen); | 398 assert(isOpen); |
| 399 return _continueWithExpression( | 399 return _continueWithExpression( |
| 400 (k) => new ir.InvokeStatic(element, selector, k, arguments)); | 400 (k) => new ir.InvokeStatic(element, selector, k, arguments)); |
| 401 } | 401 } |
| 402 | 402 |
| 403 ir.Primitive _buildInvokeSuper(Selector selector, | 403 ir.Primitive _buildInvokeDirectly(Element target, |
| 404 List<ir.Primitive> arguments) { | 404 Selector selector, |
| 405 List<ir.Primitive> arguments) { |
| 405 assert(isOpen); | 406 assert(isOpen); |
| 406 return _continueWithExpression( | 407 return _continueWithExpression( |
| 407 (k) => new ir.InvokeSuperMethod(selector, k, arguments)); | 408 (k) => new ir.InvokeMethodDirectly( |
| 409 buildThis(), target, selector, k, arguments)); |
| 408 } | 410 } |
| 409 | 411 |
| 410 ir.Primitive _buildInvokeDynamic(ir.Primitive receiver, | 412 ir.Primitive _buildInvokeDynamic(ir.Primitive receiver, |
| 411 Selector selector, | 413 Selector selector, |
| 412 List<ir.Primitive> arguments) { | 414 List<ir.Primitive> arguments) { |
| 413 assert(isOpen); | 415 assert(isOpen); |
| 414 return _continueWithExpression( | 416 return _continueWithExpression( |
| 415 (k) => new ir.InvokeMethod(receiver, selector, k, arguments)); | 417 (k) => new ir.InvokeMethod(receiver, selector, k, arguments)); |
| 416 } | 418 } |
| 417 | 419 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 ir.RunnableBody body = makeRunnableBody(); | 627 ir.RunnableBody body = makeRunnableBody(); |
| 626 return new ir.ConstructorDefinition( | 628 return new ir.ConstructorDefinition( |
| 627 element, state.functionParameters, body, initializers, | 629 element, state.functionParameters, body, initializers, |
| 628 state.localConstants, defaults, | 630 state.localConstants, defaults, |
| 629 _getDeclaredClosureVariables(element)); | 631 _getDeclaredClosureVariables(element)); |
| 630 } | 632 } |
| 631 | 633 |
| 632 /// Create a super invocation where the method name and the argument structure | 634 /// Create a super invocation where the method name and the argument structure |
| 633 /// are defined by [selector] and the argument values are defined by | 635 /// are defined by [selector] and the argument values are defined by |
| 634 /// [arguments]. | 636 /// [arguments]. |
| 635 ir.Primitive buildSuperInvocation(Selector selector, | 637 ir.Primitive buildSuperInvocation(Element target, |
| 636 List<ir.Primitive> arguments) { | 638 Selector selector, |
| 637 return _buildInvokeSuper(selector, arguments); | 639 List<ir.Primitive> arguments); |
| 638 } | |
| 639 | |
| 640 /// Create a getter invocation on the super class where the getter name is | |
| 641 /// defined by [selector]. | |
| 642 ir.Primitive buildSuperGet(Selector selector) { | |
| 643 assert(selector.isGetter); | |
| 644 return _buildInvokeSuper(selector, const <ir.Primitive>[]); | |
| 645 } | |
| 646 | 640 |
| 647 /// Create a setter invocation on the super class where the setter name and | 641 /// Create a setter invocation on the super class where the setter name and |
| 648 /// argument are defined by [selector] and [value], respectively. | 642 /// argument are defined by [selector] and [value], respectively. |
| 649 ir.Primitive buildSuperSet(Selector selector, ir.Primitive value) { | 643 void buildSuperSet(Element target, Selector selector, ir.Primitive value) { |
| 650 assert(selector.isSetter); | 644 buildSuperInvocation(target, selector, [value]); |
| 651 _buildInvokeSuper(selector, <ir.Primitive>[value]); | |
| 652 return value; | |
| 653 } | 645 } |
| 654 | 646 |
| 655 /// Create an index set invocation on the super class with the provided | 647 /// Create an index set invocation on the super class with the provided |
| 656 /// [index] and [value]. | 648 /// [index] and [value]. |
| 657 ir.Primitive buildSuperIndexSet(ir.Primitive index, | 649 ir.Primitive buildSuperIndexSet(Element target, |
| 650 ir.Primitive index, |
| 658 ir.Primitive value) { | 651 ir.Primitive value) { |
| 659 _buildInvokeSuper(new Selector.indexSet(), <ir.Primitive>[index, value]); | 652 _buildInvokeDirectly(target, new Selector.indexSet(), |
| 653 <ir.Primitive>[index, value]); |
| 660 return value; | 654 return value; |
| 661 } | 655 } |
| 662 | 656 |
| 663 /// Create a dynamic invocation on [receiver] where the method name and | 657 /// Create a dynamic invocation on [receiver] where the method name and |
| 664 /// argument structure are defined by [selector] and the argument values are | 658 /// argument structure are defined by [selector] and the argument values are |
| 665 /// defined by [arguments]. | 659 /// defined by [arguments]. |
| 666 ir.Primitive buildDynamicInvocation(ir.Primitive receiver, | 660 ir.Primitive buildDynamicInvocation(ir.Primitive receiver, |
| 667 Selector selector, | 661 Selector selector, |
| 668 List<ir.Primitive> arguments) { | 662 List<ir.Primitive> arguments) { |
| 669 return _buildInvokeDynamic(receiver, selector, arguments); | 663 return _buildInvokeDynamic(receiver, selector, arguments); |
| (...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 ExecutableElement element) { | 1718 ExecutableElement element) { |
| 1725 return dartState.getClosureList(element); | 1719 return dartState.getClosureList(element); |
| 1726 } | 1720 } |
| 1727 | 1721 |
| 1728 ir.Primitive buildThis() { | 1722 ir.Primitive buildThis() { |
| 1729 ir.Primitive thisPrim = new ir.This(); | 1723 ir.Primitive thisPrim = new ir.This(); |
| 1730 add(new ir.LetPrim(thisPrim)); | 1724 add(new ir.LetPrim(thisPrim)); |
| 1731 return thisPrim; | 1725 return thisPrim; |
| 1732 } | 1726 } |
| 1733 | 1727 |
| 1728 ir.Primitive buildSuperInvocation(Element target, |
| 1729 Selector selector, |
| 1730 List<ir.Primitive> arguments) { |
| 1731 return _buildInvokeDirectly(target, selector, arguments); |
| 1732 } |
| 1733 |
| 1734 } | 1734 } |
| 1735 | 1735 |
| 1736 /// State shared between JsIrBuilders within the same function. | 1736 /// State shared between JsIrBuilders within the same function. |
| 1737 /// | 1737 /// |
| 1738 /// Note that this is not shared between builders of nested functions. | 1738 /// Note that this is not shared between builders of nested functions. |
| 1739 class JsIrBuilderSharedState { | 1739 class JsIrBuilderSharedState { |
| 1740 /// Maps boxed locals to their location. These locals are not part of | 1740 /// Maps boxed locals to their location. These locals are not part of |
| 1741 /// the environment. | 1741 /// the environment. |
| 1742 final Map<Local, ClosureLocation> boxedVariables = {}; | 1742 final Map<Local, ClosureLocation> boxedVariables = {}; |
| 1743 | 1743 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1926 ExecutableElement element) { | 1926 ExecutableElement element) { |
| 1927 return <ir.ClosureVariable>[]; | 1927 return <ir.ClosureVariable>[]; |
| 1928 } | 1928 } |
| 1929 | 1929 |
| 1930 ir.Primitive buildThis() { | 1930 ir.Primitive buildThis() { |
| 1931 if (jsState.receiver != null) return jsState.receiver; | 1931 if (jsState.receiver != null) return jsState.receiver; |
| 1932 ir.Primitive thisPrim = new ir.This(); | 1932 ir.Primitive thisPrim = new ir.This(); |
| 1933 add(new ir.LetPrim(thisPrim)); | 1933 add(new ir.LetPrim(thisPrim)); |
| 1934 return thisPrim; | 1934 return thisPrim; |
| 1935 } | 1935 } |
| 1936 |
| 1937 ir.Primitive buildSuperInvocation(Element target, |
| 1938 Selector selector, |
| 1939 List<ir.Primitive> arguments) { |
| 1940 // Direct calls to FieldElements are currently problematic because the |
| 1941 // backend will not issue a getter for the field unless it finds a dynamic |
| 1942 // access that matches its getter. |
| 1943 // As a workaround, we generate GetField for this case, although ideally |
| 1944 // this should be the result of inlining the field's getter. |
| 1945 if (target is FieldElement) { |
| 1946 if (selector.isGetter) { |
| 1947 ir.Primitive get = new ir.GetField(buildThis(), target); |
| 1948 add(new ir.LetPrim(get)); |
| 1949 return get; |
| 1950 } else { |
| 1951 assert(selector.isSetter); |
| 1952 add(new ir.SetField(buildThis(), target, arguments.single)); |
| 1953 return arguments.single; |
| 1954 } |
| 1955 } else { |
| 1956 return _buildInvokeDirectly(target, selector, arguments); |
| 1957 } |
| 1958 } |
| 1936 } | 1959 } |
| 1937 | 1960 |
| 1938 | 1961 |
| 1939 /// Location of a variable relative to a given closure. | 1962 /// Location of a variable relative to a given closure. |
| 1940 class ClosureLocation { | 1963 class ClosureLocation { |
| 1941 /// If not `null`, this location is [box].[field]. | 1964 /// If not `null`, this location is [box].[field]. |
| 1942 /// The location of [box] can be obtained separately from an | 1965 /// The location of [box] can be obtained separately from an |
| 1943 /// enclosing [ClosureEnvironment] or [ClosureScope]. | 1966 /// enclosing [ClosureEnvironment] or [ClosureScope]. |
| 1944 /// If `null`, then the location is [field] on the enclosing function object. | 1967 /// If `null`, then the location is [field] on the enclosing function object. |
| 1945 final BoxLocal box; | 1968 final BoxLocal box; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 ClosureEnvironment(this.selfReference, this.thisLocal, this.freeVariables); | 2011 ClosureEnvironment(this.selfReference, this.thisLocal, this.freeVariables); |
| 1989 } | 2012 } |
| 1990 | 2013 |
| 1991 /// Information about which variables are captured in a closure. | 2014 /// Information about which variables are captured in a closure. |
| 1992 /// | 2015 /// |
| 1993 /// This is used by the [DartIrBuilder] instead of [ClosureScope] and | 2016 /// This is used by the [DartIrBuilder] instead of [ClosureScope] and |
| 1994 /// [ClosureEnvironment]. | 2017 /// [ClosureEnvironment]. |
| 1995 abstract class ClosureVariableInfo { | 2018 abstract class ClosureVariableInfo { |
| 1996 Iterable<Local> get capturedVariables; | 2019 Iterable<Local> get capturedVariables; |
| 1997 } | 2020 } |
| OLD | NEW |