| 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 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 * such as `foo(){ }`. | 791 * such as `foo(){ }`. |
| 792 */ | 792 */ |
| 793 void _ensureReturn() { | 793 void _ensureReturn() { |
| 794 if (!isOpen) return; | 794 if (!isOpen) return; |
| 795 ir.Constant constant = buildNullLiteral(); | 795 ir.Constant constant = buildNullLiteral(); |
| 796 add(new ir.InvokeContinuation(state.returnContinuation, [constant])); | 796 add(new ir.InvokeContinuation(state.returnContinuation, [constant])); |
| 797 _current = null; | 797 _current = null; |
| 798 } | 798 } |
| 799 | 799 |
| 800 ir.SuperInitializer makeSuperInitializer(ConstructorElement target, | 800 ir.SuperInitializer makeSuperInitializer(ConstructorElement target, |
| 801 List<ir.RunnableBody> arguments, | 801 List<ir.Body> arguments, |
| 802 Selector selector) { | 802 Selector selector) { |
| 803 return new ir.SuperInitializer(target, arguments, selector); | 803 return new ir.SuperInitializer(target, arguments, selector); |
| 804 } | 804 } |
| 805 | 805 |
| 806 ir.FieldInitializer makeFieldInitializer(FieldElement element, | 806 ir.FieldInitializer makeFieldInitializer(FieldElement element, |
| 807 ir.RunnableBody body) { | 807 ir.Body body) { |
| 808 return new ir.FieldInitializer(element, body); | 808 return new ir.FieldInitializer(element, body); |
| 809 } | 809 } |
| 810 | 810 |
| 811 /// Create a [ir.FieldDefinition] for the current [Element] using [_root] as | 811 /// Create a [ir.FieldDefinition] for the current [Element] using [_root] as |
| 812 /// the body using [initializer] as the initial value. | 812 /// the body using [initializer] as the initial value. |
| 813 ir.FieldDefinition makeFieldDefinition(ir.Primitive initializer) { | 813 ir.FieldDefinition makeFieldDefinition(ir.Primitive initializer) { |
| 814 if (initializer == null) { | 814 if (initializer == null) { |
| 815 return new ir.FieldDefinition.withoutInitializer(state.currentElement); | 815 return new ir.FieldDefinition.withoutInitializer(state.currentElement); |
| 816 } else { | 816 } else { |
| 817 ir.RunnableBody body = makeRunnableBody(initializer); | 817 ir.Body body = makeBody(initializer); |
| 818 return new ir.FieldDefinition(state.currentElement, body); | 818 return new ir.FieldDefinition(state.currentElement, body); |
| 819 } | 819 } |
| 820 } | 820 } |
| 821 | 821 |
| 822 ir.RunnableBody makeRunnableBody([ir.Primitive value]) { | 822 ir.Body makeBody([ir.Primitive value]) { |
| 823 if (value == null) { | 823 if (value == null) { |
| 824 _ensureReturn(); | 824 _ensureReturn(); |
| 825 } else { | 825 } else { |
| 826 buildReturn(value); | 826 buildReturn(value); |
| 827 } | 827 } |
| 828 return new ir.RunnableBody(_root, state.returnContinuation); | 828 return new ir.Body(_root, state.returnContinuation); |
| 829 } | 829 } |
| 830 | 830 |
| 831 /// Create a [ir.FunctionDefinition] for [element] using [_root] as the body. | 831 /// Create a [ir.FunctionDefinition] for [element] using [_root] as the body. |
| 832 /// | 832 /// |
| 833 /// Parameters must be created before the construction of the body using | 833 /// Parameters must be created before the construction of the body using |
| 834 /// [createFunctionParameter]. | 834 /// [createFunctionParameter]. |
| 835 ir.FunctionDefinition makeFunctionDefinition( | 835 ir.FunctionDefinition makeFunctionDefinition( |
| 836 List<ConstantExpression> defaults) { | 836 List<ConstantExpression> defaults) { |
| 837 FunctionElement element = state.currentElement; | 837 FunctionElement element = state.currentElement; |
| 838 if (element.isAbstract || element.isExternal) { | 838 if (element.isAbstract || element.isExternal) { |
| 839 assert(invariant(element, _root == null, | 839 assert(invariant(element, _root == null, |
| 840 message: "Non-empty body for abstract method $element: $_root")); | 840 message: "Non-empty body for abstract method $element: $_root")); |
| 841 assert(invariant(element, state.localConstants.isEmpty, | 841 assert(invariant(element, state.localConstants.isEmpty, |
| 842 message: "Local constants for abstract method $element: " | 842 message: "Local constants for abstract method $element: " |
| 843 "${state.localConstants}")); | 843 "${state.localConstants}")); |
| 844 return new ir.FunctionDefinition.abstract( | 844 return new ir.FunctionDefinition.abstract( |
| 845 element, state.thisParameter, state.functionParameters, defaults); | 845 element, state.functionParameters, defaults); |
| 846 } else { | 846 } else { |
| 847 ir.RunnableBody body = makeRunnableBody(); | 847 ir.Body body = makeBody(); |
| 848 return new ir.FunctionDefinition( | 848 return new ir.FunctionDefinition( |
| 849 element, state.thisParameter, state.functionParameters, body, | 849 element, state.thisParameter, state.functionParameters, body, |
| 850 state.localConstants, defaults); | 850 state.localConstants, defaults); |
| 851 } | 851 } |
| 852 } | 852 } |
| 853 | 853 |
| 854 /// Create a constructor definition without a body, for representing | 854 /// Create a constructor definition without a body, for representing |
| 855 /// external constructors declarations. | 855 /// external constructors declarations. |
| 856 ir.ConstructorDefinition makeAbstractConstructorDefinition( | 856 ir.ConstructorDefinition makeAbstractConstructorDefinition( |
| 857 List<ConstantExpression> defaults) { | 857 List<ConstantExpression> defaults) { |
| 858 FunctionElement element = state.currentElement; | 858 FunctionElement element = state.currentElement; |
| 859 assert(invariant(element, _root == null, | 859 assert(invariant(element, _root == null, |
| 860 message: "Non-empty body for external constructor $element: $_root")); | 860 message: "Non-empty body for external constructor $element: $_root")); |
| 861 assert(invariant(element, state.localConstants.isEmpty, | 861 assert(invariant(element, state.localConstants.isEmpty, |
| 862 message: "Local constants for external constructor $element: " | 862 message: "Local constants for external constructor $element: " |
| 863 "${state.localConstants}")); | 863 "${state.localConstants}")); |
| 864 return new ir.ConstructorDefinition.abstract( | 864 return new ir.ConstructorDefinition.abstract( |
| 865 element, state.functionParameters, defaults); | 865 element, state.functionParameters, defaults); |
| 866 } | 866 } |
| 867 | 867 |
| 868 ir.ConstructorDefinition makeConstructorDefinition( | 868 ir.ConstructorDefinition makeConstructorDefinition( |
| 869 List<ConstantExpression> defaults, List<ir.Initializer> initializers) { | 869 List<ConstantExpression> defaults, List<ir.Initializer> initializers) { |
| 870 FunctionElement element = state.currentElement; | 870 FunctionElement element = state.currentElement; |
| 871 ir.RunnableBody body = makeRunnableBody(); | 871 ir.Body body = makeBody(); |
| 872 return new ir.ConstructorDefinition( | 872 return new ir.ConstructorDefinition( |
| 873 element, state.thisParameter, state.functionParameters, body, initialize
rs, | 873 element, state.thisParameter, state.functionParameters, body, initialize
rs, |
| 874 state.localConstants, defaults); | 874 state.localConstants, defaults); |
| 875 } | 875 } |
| 876 | 876 |
| 877 /// Create a super invocation where the method name and the argument structure | 877 /// Create a super invocation where the method name and the argument structure |
| 878 /// are defined by [selector] and the argument values are defined by | 878 /// are defined by [selector] and the argument values are defined by |
| 879 /// [arguments]. | 879 /// [arguments]. |
| 880 ir.Primitive buildSuperInvocation(Element target, | 880 ir.Primitive buildSuperInvocation(Element target, |
| 881 Selector selector, | 881 Selector selector, |
| (...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2536 } | 2536 } |
| 2537 | 2537 |
| 2538 /// Synthetic parameter to a JavaScript factory method that takes the type | 2538 /// Synthetic parameter to a JavaScript factory method that takes the type |
| 2539 /// argument given for the type variable [variable]. | 2539 /// argument given for the type variable [variable]. |
| 2540 class TypeInformationParameter implements Local { | 2540 class TypeInformationParameter implements Local { |
| 2541 final TypeVariableElement variable; | 2541 final TypeVariableElement variable; |
| 2542 final ExecutableElement executableContext; | 2542 final ExecutableElement executableContext; |
| 2543 TypeInformationParameter(this.variable, this.executableContext); | 2543 TypeInformationParameter(this.variable, this.executableContext); |
| 2544 String get name => variable.name; | 2544 String get name => variable.name; |
| 2545 } | 2545 } |
| OLD | NEW |