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 library dart2js.ir_nodes; | 4 library dart2js.ir_nodes; |
5 | 5 |
6 import '../constants/expressions.dart'; | 6 import '../constants/expressions.dart'; |
7 import '../constants/values.dart' as values show ConstantValue; | 7 import '../constants/values.dart' as values show ConstantValue; |
8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; | 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; |
9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
10 import '../io/source_information.dart' show SourceInformation; | 10 import '../io/source_information.dart' show SourceInformation; |
11 import '../universe/universe.dart' show Selector, SelectorKind; | 11 import '../universe/universe.dart' show Selector, SelectorKind; |
12 | 12 |
| 13 // These imports are only used for the JavaScript specific nodes. If we want to |
| 14 // support more than one native backend, we should probably create better |
| 15 // abstractions for native code and its type and effect system. |
| 16 import '../js/js.dart' as js show Template; |
| 17 import '../native/native.dart' as native show NativeBehavior; |
| 18 import '../types/types.dart' as types show TypeMask; |
| 19 |
13 abstract class Node { | 20 abstract class Node { |
14 /// A pointer to the parent node. Is null until set by optimization passes. | 21 /// A pointer to the parent node. Is null until set by optimization passes. |
15 Node parent; | 22 Node parent; |
16 | 23 |
17 accept(Visitor visitor); | 24 accept(Visitor visitor); |
18 } | 25 } |
19 | 26 |
20 /// Expressions can be evaluated, and may diverge, throw, and/or have | 27 /// Expressions can be evaluated, and may diverge, throw, and/or have |
21 /// side-effects. | 28 /// side-effects. |
22 /// | 29 /// |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 class CreateInvocationMirror extends Primitive { | 722 class CreateInvocationMirror extends Primitive { |
716 final Selector selector; | 723 final Selector selector; |
717 final List<Reference<Primitive>> arguments; | 724 final List<Reference<Primitive>> arguments; |
718 | 725 |
719 CreateInvocationMirror(this.selector, List<Primitive> arguments) | 726 CreateInvocationMirror(this.selector, List<Primitive> arguments) |
720 : this.arguments = _referenceList(arguments); | 727 : this.arguments = _referenceList(arguments); |
721 | 728 |
722 accept(Visitor visitor) => visitor.visitCreateInvocationMirror(this); | 729 accept(Visitor visitor) => visitor.visitCreateInvocationMirror(this); |
723 } | 730 } |
724 | 731 |
| 732 class ForeignCode extends Expression { |
| 733 final js.Template codeTemplate; |
| 734 |
| 735 final types.TypeMask type; |
| 736 final List<Reference<Primitive>> arguments; |
| 737 final Reference<Continuation> continuation; |
| 738 final native.NativeBehavior nativeBehavior; |
| 739 final FunctionElement dependency; |
| 740 |
| 741 ForeignCode(this.codeTemplate, this.type, List<Primitive> arguments, |
| 742 Continuation continuation, this.nativeBehavior, {this.dependency}) |
| 743 : arguments = _referenceList(arguments), |
| 744 continuation = new Reference<Continuation>(continuation); |
| 745 |
| 746 accept(Visitor visitor) => visitor.visitForeignCode(this); |
| 747 } |
| 748 |
725 class Constant extends Primitive { | 749 class Constant extends Primitive { |
726 final ConstantExpression expression; | 750 final ConstantExpression expression; |
727 final values.ConstantValue value; | 751 final values.ConstantValue value; |
728 | 752 |
729 Constant(this.expression, this.value); | 753 Constant(this.expression, this.value); |
730 | 754 |
731 accept(Visitor visitor) => visitor.visitConstant(this); | 755 accept(Visitor visitor) => visitor.visitConstant(this); |
732 } | 756 } |
733 | 757 |
734 class LiteralList extends Primitive { | 758 class LiteralList extends Primitive { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 T visitGetField(GetField node); | 972 T visitGetField(GetField node); |
949 T visitCreateBox(CreateBox node); | 973 T visitCreateBox(CreateBox node); |
950 T visitReifyRuntimeType(ReifyRuntimeType node); | 974 T visitReifyRuntimeType(ReifyRuntimeType node); |
951 T visitReadTypeVariable(ReadTypeVariable node); | 975 T visitReadTypeVariable(ReadTypeVariable node); |
952 T visitTypeExpression(TypeExpression node); | 976 T visitTypeExpression(TypeExpression node); |
953 T visitCreateInvocationMirror(CreateInvocationMirror node); | 977 T visitCreateInvocationMirror(CreateInvocationMirror node); |
954 T visitTypeTest(TypeTest node); | 978 T visitTypeTest(TypeTest node); |
955 | 979 |
956 // Conditions. | 980 // Conditions. |
957 T visitIsTrue(IsTrue node); | 981 T visitIsTrue(IsTrue node); |
| 982 |
| 983 // Support for literal foreign code. |
| 984 T visitForeignCode(ForeignCode node); |
958 } | 985 } |
959 | 986 |
960 /// Recursively visits the entire CPS term, and calls abstract `process*` | 987 /// Recursively visits the entire CPS term, and calls abstract `process*` |
961 /// (i.e. `processLetPrim`) functions in pre-order. | 988 /// (i.e. `processLetPrim`) functions in pre-order. |
962 class RecursiveVisitor implements Visitor { | 989 class RecursiveVisitor implements Visitor { |
963 const RecursiveVisitor(); | 990 const RecursiveVisitor(); |
964 | 991 |
965 visit(Node node) => node.accept(this); | 992 visit(Node node) => node.accept(this); |
966 | 993 |
967 processReference(Reference ref) {} | 994 processReference(Reference ref) {} |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 processNonTailThrow(node); | 1254 processNonTailThrow(node); |
1228 processReference(node.value); | 1255 processReference(node.value); |
1229 } | 1256 } |
1230 | 1257 |
1231 processCreateInvocationMirror(CreateInvocationMirror node) {} | 1258 processCreateInvocationMirror(CreateInvocationMirror node) {} |
1232 visitCreateInvocationMirror(CreateInvocationMirror node) { | 1259 visitCreateInvocationMirror(CreateInvocationMirror node) { |
1233 processCreateInvocationMirror(node); | 1260 processCreateInvocationMirror(node); |
1234 node.arguments.forEach(processReference); | 1261 node.arguments.forEach(processReference); |
1235 } | 1262 } |
1236 | 1263 |
| 1264 processForeignCode(ForeignCode node) {} |
| 1265 visitForeignCode(ForeignCode node) { |
| 1266 processForeignCode(node); |
| 1267 processReference(node.continuation); |
| 1268 node.arguments.forEach(processReference); |
| 1269 } |
| 1270 |
1237 processUnreachable(Unreachable node) {} | 1271 processUnreachable(Unreachable node) {} |
1238 visitUnreachable(Unreachable node) { | 1272 visitUnreachable(Unreachable node) { |
1239 processUnreachable(node); | 1273 processUnreachable(node); |
1240 } | 1274 } |
1241 } | 1275 } |
1242 | 1276 |
1243 /// Visit a just-deleted subterm and unlink all [Reference]s in it. | 1277 /// Visit a just-deleted subterm and unlink all [Reference]s in it. |
1244 class RemovalVisitor extends RecursiveVisitor { | 1278 class RemovalVisitor extends RecursiveVisitor { |
1245 const RemovalVisitor(); | 1279 const RemovalVisitor(); |
1246 | 1280 |
1247 processReference(Reference reference) { | 1281 processReference(Reference reference) { |
1248 reference.unlink(); | 1282 reference.unlink(); |
1249 } | 1283 } |
1250 | 1284 |
1251 static void remove(Node node) { | 1285 static void remove(Node node) { |
1252 (const RemovalVisitor()).visit(node); | 1286 (const RemovalVisitor()).visit(node); |
1253 } | 1287 } |
1254 } | 1288 } |
OLD | NEW |