| 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/constant_system.dart'; | 7 import '../constants/constant_system.dart'; |
| 8 import '../constants/expressions.dart'; | 8 import '../constants/expressions.dart'; |
| 9 import '../constants/values.dart' show PrimitiveConstantValue; | 9 import '../constants/values.dart' show PrimitiveConstantValue; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 sourceInformation: sourceInformation); | 678 sourceInformation: sourceInformation); |
| 679 } | 679 } |
| 680 | 680 |
| 681 | 681 |
| 682 /// Create a [ir.Constant] from [constant] and add it to the CPS term. | 682 /// Create a [ir.Constant] from [constant] and add it to the CPS term. |
| 683 ir.Constant buildConstant(ConstantExpression constant) { | 683 ir.Constant buildConstant(ConstantExpression constant) { |
| 684 assert(isOpen); | 684 assert(isOpen); |
| 685 return addPrimitive(new ir.Constant(constant)); | 685 return addPrimitive(new ir.Constant(constant)); |
| 686 } | 686 } |
| 687 | 687 |
| 688 // Helper for building primitive constants. | |
| 689 ir.Constant _buildPrimitiveConstant(PrimitiveConstantValue constant) { | |
| 690 return buildConstant(new PrimitiveConstantExpression(constant)); | |
| 691 } | |
| 692 | |
| 693 /// Create an integer constant and add it to the CPS term. | 688 /// Create an integer constant and add it to the CPS term. |
| 694 ir.Constant buildIntegerConstant(int value) { | 689 ir.Constant buildIntegerConstant(int value) { |
| 695 return _buildPrimitiveConstant(state.constantSystem.createInt(value)); | 690 return buildConstant(new IntConstantExpression( |
| 691 value, |
| 692 state.constantSystem.createInt(value))); |
| 696 } | 693 } |
| 697 | 694 |
| 698 /// Create a double constant and add it to the CPS term. | 695 /// Create a double constant and add it to the CPS term. |
| 699 ir.Constant buildDoubleConstant(double value) { | 696 ir.Constant buildDoubleConstant(double value) { |
| 700 return _buildPrimitiveConstant(state.constantSystem.createDouble(value)); | 697 return buildConstant(new DoubleConstantExpression( |
| 698 value, |
| 699 state.constantSystem.createDouble(value))); |
| 701 } | 700 } |
| 702 | 701 |
| 703 /// Create a Boolean constant and add it to the CPS term. | 702 /// Create a Boolean constant and add it to the CPS term. |
| 704 ir.Constant buildBooleanConstant(bool value) { | 703 ir.Constant buildBooleanConstant(bool value) { |
| 705 return _buildPrimitiveConstant(state.constantSystem.createBool(value)); | 704 return buildConstant(new BoolConstantExpression( |
| 705 value, |
| 706 state.constantSystem.createBool(value))); |
| 706 } | 707 } |
| 707 | 708 |
| 708 /// Create a null constant and add it to the CPS term. | 709 /// Create a null constant and add it to the CPS term. |
| 709 ir.Constant buildNullConstant() { | 710 ir.Constant buildNullConstant() { |
| 710 return _buildPrimitiveConstant(state.constantSystem.createNull()); | 711 return buildConstant(new NullConstantExpression( |
| 712 state.constantSystem.createNull())); |
| 711 } | 713 } |
| 712 | 714 |
| 713 /// Create a string constant and add it to the CPS term. | 715 /// Create a string constant and add it to the CPS term. |
| 714 ir.Constant buildStringConstant(String value) { | 716 ir.Constant buildStringConstant(String value) { |
| 715 return _buildPrimitiveConstant( | 717 return buildConstant(new StringConstantExpression( |
| 716 state.constantSystem.createString(new ast.DartString.literal(value))); | 718 value, |
| 719 state.constantSystem.createString(new ast.DartString.literal(value)))); |
| 717 } | 720 } |
| 718 | 721 |
| 719 /// Create a string constant and add it to the CPS term. | 722 /// Create a string constant and add it to the CPS term. |
| 720 ir.Constant buildDartStringConstant(ast.DartString value) { | 723 ir.Constant buildDartStringConstant(ast.DartString value) { |
| 721 return _buildPrimitiveConstant(state.constantSystem.createString(value)); | 724 return buildConstant(new StringConstantExpression( |
| 725 value.slowToString(), |
| 726 state.constantSystem.createString(value))); |
| 722 } | 727 } |
| 723 | 728 |
| 724 /// Creates a non-constant list literal of the provided [type] and with the | 729 /// Creates a non-constant list literal of the provided [type] and with the |
| 725 /// provided [values]. | 730 /// provided [values]. |
| 726 ir.Primitive buildListLiteral(InterfaceType type, | 731 ir.Primitive buildListLiteral(InterfaceType type, |
| 727 Iterable<ir.Primitive> values) { | 732 Iterable<ir.Primitive> values) { |
| 728 assert(isOpen); | 733 assert(isOpen); |
| 729 return addPrimitive(new ir.LiteralList(type, values.toList())); | 734 return addPrimitive(new ir.LiteralList(type, values.toList())); |
| 730 } | 735 } |
| 731 | 736 |
| (...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1928 // ! e is translated as e ? false : true | 1933 // ! e is translated as e ? false : true |
| 1929 | 1934 |
| 1930 // Add a continuation parameter for the result of the expression. | 1935 // Add a continuation parameter for the result of the expression. |
| 1931 ir.Parameter resultParameter = new ir.Parameter(null); | 1936 ir.Parameter resultParameter = new ir.Parameter(null); |
| 1932 | 1937 |
| 1933 ir.Continuation joinContinuation = new ir.Continuation([resultParameter]); | 1938 ir.Continuation joinContinuation = new ir.Continuation([resultParameter]); |
| 1934 ir.Continuation thenContinuation = new ir.Continuation([]); | 1939 ir.Continuation thenContinuation = new ir.Continuation([]); |
| 1935 ir.Continuation elseContinuation = new ir.Continuation([]); | 1940 ir.Continuation elseContinuation = new ir.Continuation([]); |
| 1936 | 1941 |
| 1937 ir.Constant makeBoolConstant(bool value) { | 1942 ir.Constant makeBoolConstant(bool value) { |
| 1938 return new ir.Constant(new PrimitiveConstantExpression( | 1943 return new ir.Constant(new BoolConstantExpression( |
| 1944 value, |
| 1939 state.constantSystem.createBool(value))); | 1945 state.constantSystem.createBool(value))); |
| 1940 } | 1946 } |
| 1941 | 1947 |
| 1942 ir.Constant trueConstant = makeBoolConstant(true); | 1948 ir.Constant trueConstant = makeBoolConstant(true); |
| 1943 ir.Constant falseConstant = makeBoolConstant(false); | 1949 ir.Constant falseConstant = makeBoolConstant(false); |
| 1944 | 1950 |
| 1945 thenContinuation.body = new ir.LetPrim(falseConstant) | 1951 thenContinuation.body = new ir.LetPrim(falseConstant) |
| 1946 ..plug(new ir.InvokeContinuation(joinContinuation, [falseConstant])); | 1952 ..plug(new ir.InvokeContinuation(joinContinuation, [falseConstant])); |
| 1947 elseContinuation.body = new ir.LetPrim(trueConstant) | 1953 elseContinuation.body = new ir.LetPrim(trueConstant) |
| 1948 ..plug(new ir.InvokeContinuation(joinContinuation, [trueConstant])); | 1954 ..plug(new ir.InvokeContinuation(joinContinuation, [trueConstant])); |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2655 } | 2661 } |
| 2656 | 2662 |
| 2657 /// Synthetic parameter to a JavaScript factory method that takes the type | 2663 /// Synthetic parameter to a JavaScript factory method that takes the type |
| 2658 /// argument given for the type variable [variable]. | 2664 /// argument given for the type variable [variable]. |
| 2659 class TypeInformationParameter implements Local { | 2665 class TypeInformationParameter implements Local { |
| 2660 final TypeVariableElement variable; | 2666 final TypeVariableElement variable; |
| 2661 final ExecutableElement executableContext; | 2667 final ExecutableElement executableContext; |
| 2662 TypeInformationParameter(this.variable, this.executableContext); | 2668 TypeInformationParameter(this.variable, this.executableContext); |
| 2663 String get name => variable.name; | 2669 String get name => variable.name; |
| 2664 } | 2670 } |
| OLD | NEW |