| 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 // IrNodes are kept in a separate library to have precise control over their | 5 // IrNodes are kept in a separate library to have precise control over their |
| 6 // dependencies on other parts of the system. | 6 // dependencies on other parts of the system. |
| 7 library dart2js.ir_nodes; | 7 library dart2js.ir_nodes; |
| 8 | 8 |
| 9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
| 10 import '../constants/values.dart' as values show ConstantValue; | 10 import '../constants/values.dart' as values show ConstantValue; |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 class Constant extends Primitive { | 631 class Constant extends Primitive { |
| 632 final ConstantExpression expression; | 632 final ConstantExpression expression; |
| 633 | 633 |
| 634 Constant(this.expression); | 634 Constant(this.expression); |
| 635 | 635 |
| 636 values.ConstantValue get value => expression.value; | 636 values.ConstantValue get value => expression.value; |
| 637 | 637 |
| 638 accept(Visitor visitor) => visitor.visitConstant(this); | 638 accept(Visitor visitor) => visitor.visitConstant(this); |
| 639 } | 639 } |
| 640 | 640 |
| 641 class This extends Primitive { | |
| 642 This(); | |
| 643 | |
| 644 accept(Visitor visitor) => visitor.visitThis(this); | |
| 645 } | |
| 646 | |
| 647 /// Reify the given type variable as a [Type]. | 641 /// Reify the given type variable as a [Type]. |
| 648 /// This depends on the current binding of 'this'. | 642 /// This depends on the current binding of 'this'. |
| 649 class ReifyTypeVar extends Primitive implements DartSpecificNode { | 643 class ReifyTypeVar extends Primitive implements DartSpecificNode { |
| 650 final TypeVariableElement typeVariable; | 644 final TypeVariableElement typeVariable; |
| 651 | 645 |
| 652 ReifyTypeVar(this.typeVariable); | 646 ReifyTypeVar(this.typeVariable); |
| 653 | 647 |
| 654 values.ConstantValue get constant => null; | 648 values.ConstantValue get constant => null; |
| 655 | 649 |
| 656 accept(Visitor visitor) => visitor.visitReifyTypeVar(this); | 650 accept(Visitor visitor) => visitor.visitReifyTypeVar(this); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 super.hint = hint; | 693 super.hint = hint; |
| 700 } | 694 } |
| 701 | 695 |
| 702 // In addition to a parent pointer to the containing Continuation or | 696 // In addition to a parent pointer to the containing Continuation or |
| 703 // FunctionDefinition, parameters have an index into the list of parameters | 697 // FunctionDefinition, parameters have an index into the list of parameters |
| 704 // bound by the parent. This gives constant-time access to the continuation | 698 // bound by the parent. This gives constant-time access to the continuation |
| 705 // from the parent. | 699 // from the parent. |
| 706 int parentIndex; | 700 int parentIndex; |
| 707 | 701 |
| 708 accept(Visitor visitor) => visitor.visitParameter(this); | 702 accept(Visitor visitor) => visitor.visitParameter(this); |
| 703 |
| 704 String toString() => 'Parameter(${hint == null ? null : hint.name})'; |
| 709 } | 705 } |
| 710 | 706 |
| 711 /// Continuations are normally bound by 'let cont'. A continuation with one | 707 /// Continuations are normally bound by 'let cont'. A continuation with one |
| 712 /// parameter and no body is used to represent a function's return continuation. | 708 /// parameter and no body is used to represent a function's return continuation. |
| 713 /// The return continuation is bound by the Function, not by 'let cont'. | 709 /// The return continuation is bound by the Function, not by 'let cont'. |
| 714 class Continuation extends Definition<Continuation> implements InteriorNode { | 710 class Continuation extends Definition<Continuation> implements InteriorNode { |
| 715 final List<Parameter> parameters; | 711 final List<Parameter> parameters; |
| 716 Expression body = null; | 712 Expression body = null; |
| 717 | 713 |
| 718 // In addition to a parent pointer to the containing LetCont, continuations | 714 // In addition to a parent pointer to the containing LetCont, continuations |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 final Continuation returnContinuation; | 786 final Continuation returnContinuation; |
| 791 RunnableBody(this.body, this.returnContinuation); | 787 RunnableBody(this.body, this.returnContinuation); |
| 792 accept(Visitor visitor) => visitor.visitRunnableBody(this); | 788 accept(Visitor visitor) => visitor.visitRunnableBody(this); |
| 793 } | 789 } |
| 794 | 790 |
| 795 /// A function definition, consisting of parameters and a body. The parameters | 791 /// A function definition, consisting of parameters and a body. The parameters |
| 796 /// include a distinguished continuation parameter (held by the body). | 792 /// include a distinguished continuation parameter (held by the body). |
| 797 class FunctionDefinition extends Node | 793 class FunctionDefinition extends Node |
| 798 implements ExecutableDefinition { | 794 implements ExecutableDefinition { |
| 799 final FunctionElement element; | 795 final FunctionElement element; |
| 796 final Parameter thisParameter; |
| 800 /// Mixed list of [Parameter]s and [MutableVariable]s. | 797 /// Mixed list of [Parameter]s and [MutableVariable]s. |
| 801 final List<Definition> parameters; | 798 final List<Definition> parameters; |
| 802 final RunnableBody body; | 799 final RunnableBody body; |
| 803 final List<ConstDeclaration> localConstants; | 800 final List<ConstDeclaration> localConstants; |
| 804 | 801 |
| 805 /// Values for optional parameters. | 802 /// Values for optional parameters. |
| 806 final List<ConstantExpression> defaultParameterValues; | 803 final List<ConstantExpression> defaultParameterValues; |
| 807 | 804 |
| 808 FunctionDefinition(this.element, | 805 FunctionDefinition(this.element, |
| 806 this.thisParameter, |
| 809 this.parameters, | 807 this.parameters, |
| 810 this.body, | 808 this.body, |
| 811 this.localConstants, | 809 this.localConstants, |
| 812 this.defaultParameterValues); | 810 this.defaultParameterValues); |
| 813 | 811 |
| 814 FunctionDefinition.abstract(this.element, | 812 FunctionDefinition.abstract(this.element, |
| 813 this.thisParameter, |
| 815 this.parameters, | 814 this.parameters, |
| 816 this.defaultParameterValues) | 815 this.defaultParameterValues) |
| 817 : body = null, | 816 : body = null, |
| 818 localConstants = const <ConstDeclaration>[]; | 817 localConstants = const <ConstDeclaration>[]; |
| 819 | 818 |
| 820 accept(Visitor visitor) => visitor.visitFunctionDefinition(this); | 819 accept(Visitor visitor) => visitor.visitFunctionDefinition(this); |
| 821 applyPass(Pass pass) => pass.rewriteFunctionDefinition(this); | 820 applyPass(Pass pass) => pass.rewriteFunctionDefinition(this); |
| 822 | 821 |
| 823 /// Returns `true` if this function is abstract or external. | 822 /// Returns `true` if this function is abstract or external. |
| 824 /// | 823 /// |
| (...skipping 16 matching lines...) Expand all Loading... |
| 841 final List<RunnableBody> arguments; | 840 final List<RunnableBody> arguments; |
| 842 final Selector selector; | 841 final Selector selector; |
| 843 SuperInitializer(this.target, this.arguments, this.selector); | 842 SuperInitializer(this.target, this.arguments, this.selector); |
| 844 accept(Visitor visitor) => visitor.visitSuperInitializer(this); | 843 accept(Visitor visitor) => visitor.visitSuperInitializer(this); |
| 845 } | 844 } |
| 846 | 845 |
| 847 class ConstructorDefinition extends FunctionDefinition { | 846 class ConstructorDefinition extends FunctionDefinition { |
| 848 final List<Initializer> initializers; | 847 final List<Initializer> initializers; |
| 849 | 848 |
| 850 ConstructorDefinition(ConstructorElement element, | 849 ConstructorDefinition(ConstructorElement element, |
| 850 Definition thisParameter, // only Dart |
| 851 List<Definition> parameters, | 851 List<Definition> parameters, |
| 852 RunnableBody body, | 852 RunnableBody body, |
| 853 this.initializers, | 853 this.initializers, |
| 854 List<ConstDeclaration> localConstants, | 854 List<ConstDeclaration> localConstants, |
| 855 List<ConstantExpression> defaultParameterValues) | 855 List<ConstantExpression> defaultParameterValues) |
| 856 : super(element, parameters, body, localConstants, | 856 : super(element, thisParameter, parameters, body, localConstants, |
| 857 defaultParameterValues); | 857 defaultParameterValues); |
| 858 | 858 |
| 859 // 'Abstract' here means "has no body" and is used to represent external | 859 // 'Abstract' here means "has no body" and is used to represent external |
| 860 // constructors. | 860 // constructors. |
| 861 ConstructorDefinition.abstract( | 861 ConstructorDefinition.abstract( |
| 862 ConstructorElement element, | 862 ConstructorElement element, |
| 863 List<Definition> parameters, | 863 List<Definition> parameters, |
| 864 List<ConstantExpression> defaultParameterValues) | 864 List<ConstantExpression> defaultParameterValues) |
| 865 : initializers = null, | 865 : initializers = null, |
| 866 super.abstract(element, parameters, defaultParameterValues); | 866 super.abstract(element, null, parameters, defaultParameterValues); |
| 867 | 867 |
| 868 accept(Visitor visitor) => visitor.visitConstructorDefinition(this); | 868 accept(Visitor visitor) => visitor.visitConstructorDefinition(this); |
| 869 applyPass(Pass pass) => pass.rewriteConstructorDefinition(this); | 869 applyPass(Pass pass) => pass.rewriteConstructorDefinition(this); |
| 870 } | 870 } |
| 871 | 871 |
| 872 /// Converts the internal representation of a type to a Dart object of type | 872 /// Converts the internal representation of a type to a Dart object of type |
| 873 /// [Type]. | 873 /// [Type]. |
| 874 class ReifyRuntimeType extends Primitive implements JsSpecificNode { | 874 class ReifyRuntimeType extends Primitive implements JsSpecificNode { |
| 875 /// Reference to the internal representation of a type (as produced, for | 875 /// Reference to the internal representation of a type (as produced, for |
| 876 /// example, by [ReadTypeVariable]). | 876 /// example, by [ReadTypeVariable]). |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 T visitConcatenateStrings(ConcatenateStrings node); | 930 T visitConcatenateStrings(ConcatenateStrings node); |
| 931 T visitBranch(Branch node); | 931 T visitBranch(Branch node); |
| 932 T visitTypeOperator(TypeOperator node); | 932 T visitTypeOperator(TypeOperator node); |
| 933 T visitSetMutableVariable(SetMutableVariable node); | 933 T visitSetMutableVariable(SetMutableVariable node); |
| 934 T visitDeclareFunction(DeclareFunction node); | 934 T visitDeclareFunction(DeclareFunction node); |
| 935 | 935 |
| 936 // Definitions. | 936 // Definitions. |
| 937 T visitLiteralList(LiteralList node); | 937 T visitLiteralList(LiteralList node); |
| 938 T visitLiteralMap(LiteralMap node); | 938 T visitLiteralMap(LiteralMap node); |
| 939 T visitConstant(Constant node); | 939 T visitConstant(Constant node); |
| 940 T visitThis(This node); | |
| 941 T visitReifyTypeVar(ReifyTypeVar node); | 940 T visitReifyTypeVar(ReifyTypeVar node); |
| 942 T visitCreateFunction(CreateFunction node); | 941 T visitCreateFunction(CreateFunction node); |
| 943 T visitGetMutableVariable(GetMutableVariable node); | 942 T visitGetMutableVariable(GetMutableVariable node); |
| 944 T visitParameter(Parameter node); | 943 T visitParameter(Parameter node); |
| 945 T visitContinuation(Continuation node); | 944 T visitContinuation(Continuation node); |
| 946 T visitMutableVariable(MutableVariable node); | 945 T visitMutableVariable(MutableVariable node); |
| 947 | 946 |
| 948 // JavaScript specific nodes. | 947 // JavaScript specific nodes. |
| 949 | 948 |
| 950 // Conditions. | 949 // Conditions. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 visitFieldDefinition(FieldDefinition node) { | 982 visitFieldDefinition(FieldDefinition node) { |
| 984 processFieldDefinition(node); | 983 processFieldDefinition(node); |
| 985 if (node.hasInitializer) { | 984 if (node.hasInitializer) { |
| 986 visit(node.body); | 985 visit(node.body); |
| 987 } | 986 } |
| 988 } | 987 } |
| 989 | 988 |
| 990 processFunctionDefinition(FunctionDefinition node) {} | 989 processFunctionDefinition(FunctionDefinition node) {} |
| 991 visitFunctionDefinition(FunctionDefinition node) { | 990 visitFunctionDefinition(FunctionDefinition node) { |
| 992 processFunctionDefinition(node); | 991 processFunctionDefinition(node); |
| 992 if (node.thisParameter != null) visit(node.thisParameter); |
| 993 node.parameters.forEach(visit); | 993 node.parameters.forEach(visit); |
| 994 if (!node.isAbstract) { | 994 if (!node.isAbstract) { |
| 995 visit(node.body); | 995 visit(node.body); |
| 996 } | 996 } |
| 997 } | 997 } |
| 998 | 998 |
| 999 processConstructorDefinition(ConstructorDefinition node) {} | 999 processConstructorDefinition(ConstructorDefinition node) {} |
| 1000 visitConstructorDefinition(ConstructorDefinition node) { | 1000 visitConstructorDefinition(ConstructorDefinition node) { |
| 1001 processConstructorDefinition(node); | 1001 processConstructorDefinition(node); |
| 1002 if (node.thisParameter != null) visit(node.thisParameter); |
| 1002 node.parameters.forEach(visit); | 1003 node.parameters.forEach(visit); |
| 1003 node.initializers.forEach(visit); | 1004 node.initializers.forEach(visit); |
| 1004 visit(node.body); | 1005 visit(node.body); |
| 1005 } | 1006 } |
| 1006 | 1007 |
| 1007 processFieldInitializer(FieldInitializer node) {} | 1008 processFieldInitializer(FieldInitializer node) {} |
| 1008 visitFieldInitializer(FieldInitializer node) { | 1009 visitFieldInitializer(FieldInitializer node) { |
| 1009 processFieldInitializer(node); | 1010 processFieldInitializer(node); |
| 1010 visit(node.body); | 1011 visit(node.body); |
| 1011 } | 1012 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 processLiteralMap(node); | 1136 processLiteralMap(node); |
| 1136 for (LiteralMapEntry entry in node.entries) { | 1137 for (LiteralMapEntry entry in node.entries) { |
| 1137 processReference(entry.key); | 1138 processReference(entry.key); |
| 1138 processReference(entry.value); | 1139 processReference(entry.value); |
| 1139 } | 1140 } |
| 1140 } | 1141 } |
| 1141 | 1142 |
| 1142 processConstant(Constant node) {} | 1143 processConstant(Constant node) {} |
| 1143 visitConstant(Constant node) => processConstant(node); | 1144 visitConstant(Constant node) => processConstant(node); |
| 1144 | 1145 |
| 1145 processThis(This node) {} | |
| 1146 visitThis(This node) => processThis(node); | |
| 1147 | |
| 1148 processReifyTypeVar(ReifyTypeVar node) {} | 1146 processReifyTypeVar(ReifyTypeVar node) {} |
| 1149 visitReifyTypeVar(ReifyTypeVar node) => processReifyTypeVar(node); | 1147 visitReifyTypeVar(ReifyTypeVar node) => processReifyTypeVar(node); |
| 1150 | 1148 |
| 1151 processCreateFunction(CreateFunction node) {} | 1149 processCreateFunction(CreateFunction node) {} |
| 1152 visitCreateFunction(CreateFunction node) { | 1150 visitCreateFunction(CreateFunction node) { |
| 1153 processCreateFunction(node); | 1151 processCreateFunction(node); |
| 1154 visit(node.definition); | 1152 visit(node.definition); |
| 1155 } | 1153 } |
| 1156 | 1154 |
| 1157 processMutableVariable(node) {} | 1155 processMutableVariable(node) {} |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 } | 1412 } |
| 1415 } | 1413 } |
| 1416 | 1414 |
| 1417 void visitTypeOperator(TypeOperator node) { | 1415 void visitTypeOperator(TypeOperator node) { |
| 1418 visitReference(node.receiver); | 1416 visitReference(node.receiver); |
| 1419 } | 1417 } |
| 1420 | 1418 |
| 1421 void visitConstant(Constant node) { | 1419 void visitConstant(Constant node) { |
| 1422 } | 1420 } |
| 1423 | 1421 |
| 1424 void visitThis(This node) { | |
| 1425 } | |
| 1426 | |
| 1427 void visitReifyTypeVar(ReifyTypeVar node) { | 1422 void visitReifyTypeVar(ReifyTypeVar node) { |
| 1428 } | 1423 } |
| 1429 | 1424 |
| 1430 void visitCreateFunction(CreateFunction node) { | 1425 void visitCreateFunction(CreateFunction node) { |
| 1431 new RegisterAllocator(internalError).visit(node.definition); | 1426 new RegisterAllocator(internalError).visit(node.definition); |
| 1432 } | 1427 } |
| 1433 | 1428 |
| 1434 void visitGetMutableVariable(GetMutableVariable node) { | 1429 void visitGetMutableVariable(GetMutableVariable node) { |
| 1435 } | 1430 } |
| 1436 | 1431 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 } | 1494 } |
| 1500 | 1495 |
| 1501 void visitReifyRuntimeType(ReifyRuntimeType node) { | 1496 void visitReifyRuntimeType(ReifyRuntimeType node) { |
| 1502 visitReference(node.value); | 1497 visitReference(node.value); |
| 1503 } | 1498 } |
| 1504 | 1499 |
| 1505 void visitReadTypeVariable(ReadTypeVariable node) { | 1500 void visitReadTypeVariable(ReadTypeVariable node) { |
| 1506 visitReference(node.target); | 1501 visitReference(node.target); |
| 1507 } | 1502 } |
| 1508 } | 1503 } |
| OLD | NEW |