OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 tree_ir_nodes; | 5 library tree_ir_nodes; |
6 | 6 |
7 import '../constants/values.dart' as values; | 7 import '../constants/values.dart' as values; |
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; |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 accept1(ExpressionVisitor1 visitor, arg) { | 397 accept1(ExpressionVisitor1 visitor, arg) { |
398 return visitor.visitConditional(this, arg); | 398 return visitor.visitConditional(this, arg); |
399 } | 399 } |
400 | 400 |
401 String toString() => 'Conditional(condition=$condition,thenExpression=' | 401 String toString() => 'Conditional(condition=$condition,thenExpression=' |
402 '$thenExpression,elseExpression=$elseExpression)'; | 402 '$thenExpression,elseExpression=$elseExpression)'; |
403 } | 403 } |
404 | 404 |
405 /// An && or || expression. The operator is internally represented as a boolean | 405 /// An && or || expression. The operator is internally represented as a boolean |
406 /// [isAnd] to simplify rewriting of logical operators. | 406 /// [isAnd] to simplify rewriting of logical operators. |
| 407 /// Note the the result of && and || is one of the arguments, which might not be |
| 408 /// boolean. 'ShortCircuitOperator' might have been a better name. |
407 class LogicalOperator extends Expression { | 409 class LogicalOperator extends Expression { |
408 Expression left; | 410 Expression left; |
409 bool isAnd; | 411 bool isAnd; |
410 Expression right; | 412 Expression right; |
411 | 413 |
412 LogicalOperator(this.left, this.right, this.isAnd); | 414 LogicalOperator(this.left, this.right, this.isAnd); |
413 LogicalOperator.and(this.left, this.right) : isAnd = true; | 415 LogicalOperator.and(this.left, this.right) : isAnd = true; |
414 LogicalOperator.or(this.left, this.right) : isAnd = false; | 416 LogicalOperator.or(this.left, this.right) : isAnd = false; |
415 | 417 |
416 String get operator => isAnd ? '&&' : '||'; | 418 String get operator => isAnd ? '&&' : '||'; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 Expression object; | 737 Expression object; |
736 Element field; | 738 Element field; |
737 Expression value; | 739 Expression value; |
738 | 740 |
739 SetField(this.object, this.field, this.value); | 741 SetField(this.object, this.field, this.value); |
740 | 742 |
741 accept(ExpressionVisitor visitor) => visitor.visitSetField(this); | 743 accept(ExpressionVisitor visitor) => visitor.visitSetField(this); |
742 accept1(ExpressionVisitor1 visitor, arg) => visitor.visitSetField(this, arg); | 744 accept1(ExpressionVisitor1 visitor, arg) => visitor.visitSetField(this, arg); |
743 } | 745 } |
744 | 746 |
| 747 |
| 748 /// Read the type test property from [object]. The value is truthy/fasly rather |
| 749 /// than bool. [object] must not be `null`. |
| 750 class GetTypeTestProperty extends Expression { |
| 751 Expression object; |
| 752 DartType dartType; |
| 753 |
| 754 GetTypeTestProperty(this.object, this.dartType); |
| 755 |
| 756 accept(ExpressionVisitor visitor) => |
| 757 visitor.visitGetTypeTestProperty(this); |
| 758 accept1(ExpressionVisitor1 visitor, arg) => |
| 759 visitor.visitGetTypeTestProperty(this, arg); |
| 760 } |
| 761 |
| 762 |
745 /// Read the value of a field, possibly provoking its initializer to evaluate, | 763 /// Read the value of a field, possibly provoking its initializer to evaluate, |
746 /// or tear off a static method. | 764 /// or tear off a static method. |
747 class GetStatic extends Expression { | 765 class GetStatic extends Expression { |
748 Element element; | 766 Element element; |
749 SourceInformation sourceInformation; | 767 SourceInformation sourceInformation; |
750 | 768 |
751 GetStatic(this.element, this.sourceInformation); | 769 GetStatic(this.element, this.sourceInformation); |
752 | 770 |
753 accept(ExpressionVisitor visitor) => visitor.visitGetStatic(this); | 771 accept(ExpressionVisitor visitor) => visitor.visitGetStatic(this); |
754 accept1(ExpressionVisitor1 visitor, arg) => visitor.visitGetStatic(this, arg); | 772 accept1(ExpressionVisitor1 visitor, arg) => visitor.visitGetStatic(this, arg); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 E visitLogicalOperator(LogicalOperator node); | 986 E visitLogicalOperator(LogicalOperator node); |
969 E visitNot(Not node); | 987 E visitNot(Not node); |
970 E visitLiteralList(LiteralList node); | 988 E visitLiteralList(LiteralList node); |
971 E visitLiteralMap(LiteralMap node); | 989 E visitLiteralMap(LiteralMap node); |
972 E visitTypeOperator(TypeOperator node); | 990 E visitTypeOperator(TypeOperator node); |
973 E visitFunctionExpression(FunctionExpression node); | 991 E visitFunctionExpression(FunctionExpression node); |
974 E visitGetField(GetField node); | 992 E visitGetField(GetField node); |
975 E visitSetField(SetField node); | 993 E visitSetField(SetField node); |
976 E visitGetStatic(GetStatic node); | 994 E visitGetStatic(GetStatic node); |
977 E visitSetStatic(SetStatic node); | 995 E visitSetStatic(SetStatic node); |
| 996 E visitGetTypeTestProperty(GetTypeTestProperty node); |
978 E visitCreateBox(CreateBox node); | 997 E visitCreateBox(CreateBox node); |
979 E visitCreateInstance(CreateInstance node); | 998 E visitCreateInstance(CreateInstance node); |
980 E visitReifyRuntimeType(ReifyRuntimeType node); | 999 E visitReifyRuntimeType(ReifyRuntimeType node); |
981 E visitReadTypeVariable(ReadTypeVariable node); | 1000 E visitReadTypeVariable(ReadTypeVariable node); |
982 E visitTypeExpression(TypeExpression node); | 1001 E visitTypeExpression(TypeExpression node); |
983 E visitCreateInvocationMirror(CreateInvocationMirror node); | 1002 E visitCreateInvocationMirror(CreateInvocationMirror node); |
984 E visitInterceptor(Interceptor node); | 1003 E visitInterceptor(Interceptor node); |
985 E visitApplyBuiltinOperator(ApplyBuiltinOperator node); | 1004 E visitApplyBuiltinOperator(ApplyBuiltinOperator node); |
986 E visitApplyBuiltinMethod(ApplyBuiltinMethod node); | 1005 E visitApplyBuiltinMethod(ApplyBuiltinMethod node); |
987 E visitForeignExpression(ForeignExpression node); | 1006 E visitForeignExpression(ForeignExpression node); |
(...skipping 17 matching lines...) Expand all Loading... |
1005 E visitLogicalOperator(LogicalOperator node, A arg); | 1024 E visitLogicalOperator(LogicalOperator node, A arg); |
1006 E visitNot(Not node, A arg); | 1025 E visitNot(Not node, A arg); |
1007 E visitLiteralList(LiteralList node, A arg); | 1026 E visitLiteralList(LiteralList node, A arg); |
1008 E visitLiteralMap(LiteralMap node, A arg); | 1027 E visitLiteralMap(LiteralMap node, A arg); |
1009 E visitTypeOperator(TypeOperator node, A arg); | 1028 E visitTypeOperator(TypeOperator node, A arg); |
1010 E visitFunctionExpression(FunctionExpression node, A arg); | 1029 E visitFunctionExpression(FunctionExpression node, A arg); |
1011 E visitGetField(GetField node, A arg); | 1030 E visitGetField(GetField node, A arg); |
1012 E visitSetField(SetField node, A arg); | 1031 E visitSetField(SetField node, A arg); |
1013 E visitGetStatic(GetStatic node, A arg); | 1032 E visitGetStatic(GetStatic node, A arg); |
1014 E visitSetStatic(SetStatic node, A arg); | 1033 E visitSetStatic(SetStatic node, A arg); |
| 1034 E visitGetTypeTestProperty(GetTypeTestProperty node, A arg); |
1015 E visitCreateBox(CreateBox node, A arg); | 1035 E visitCreateBox(CreateBox node, A arg); |
1016 E visitCreateInstance(CreateInstance node, A arg); | 1036 E visitCreateInstance(CreateInstance node, A arg); |
1017 E visitReifyRuntimeType(ReifyRuntimeType node, A arg); | 1037 E visitReifyRuntimeType(ReifyRuntimeType node, A arg); |
1018 E visitReadTypeVariable(ReadTypeVariable node, A arg); | 1038 E visitReadTypeVariable(ReadTypeVariable node, A arg); |
1019 E visitTypeExpression(TypeExpression node, A arg); | 1039 E visitTypeExpression(TypeExpression node, A arg); |
1020 E visitCreateInvocationMirror(CreateInvocationMirror node, A arg); | 1040 E visitCreateInvocationMirror(CreateInvocationMirror node, A arg); |
1021 E visitInterceptor(Interceptor node, A arg); | 1041 E visitInterceptor(Interceptor node, A arg); |
1022 E visitApplyBuiltinOperator(ApplyBuiltinOperator node, A arg); | 1042 E visitApplyBuiltinOperator(ApplyBuiltinOperator node, A arg); |
1023 E visitApplyBuiltinMethod(ApplyBuiltinMethod node, A arg); | 1043 E visitApplyBuiltinMethod(ApplyBuiltinMethod node, A arg); |
1024 E visitForeignExpression(ForeignExpression node, A arg); | 1044 E visitForeignExpression(ForeignExpression node, A arg); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 visitExpression(node.value); | 1219 visitExpression(node.value); |
1200 } | 1220 } |
1201 | 1221 |
1202 visitGetStatic(GetStatic node) { | 1222 visitGetStatic(GetStatic node) { |
1203 } | 1223 } |
1204 | 1224 |
1205 visitSetStatic(SetStatic node) { | 1225 visitSetStatic(SetStatic node) { |
1206 visitExpression(node.value); | 1226 visitExpression(node.value); |
1207 } | 1227 } |
1208 | 1228 |
| 1229 visitGetTypeTestProperty(GetTypeTestProperty node) { |
| 1230 visitExpression(node.object); |
| 1231 } |
| 1232 |
1209 visitCreateBox(CreateBox node) { | 1233 visitCreateBox(CreateBox node) { |
1210 } | 1234 } |
1211 | 1235 |
1212 visitCreateInstance(CreateInstance node) { | 1236 visitCreateInstance(CreateInstance node) { |
1213 node.arguments.forEach(visitExpression); | 1237 node.arguments.forEach(visitExpression); |
1214 node.typeInformation.forEach(visitExpression); | 1238 node.typeInformation.forEach(visitExpression); |
1215 } | 1239 } |
1216 | 1240 |
1217 visitReifyRuntimeType(ReifyRuntimeType node) { | 1241 visitReifyRuntimeType(ReifyRuntimeType node) { |
1218 visitExpression(node.value); | 1242 visitExpression(node.value); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 return node; | 1468 return node; |
1445 } | 1469 } |
1446 | 1470 |
1447 visitGetStatic(GetStatic node) => node; | 1471 visitGetStatic(GetStatic node) => node; |
1448 | 1472 |
1449 visitSetStatic(SetStatic node) { | 1473 visitSetStatic(SetStatic node) { |
1450 node.value = visitExpression(node.value); | 1474 node.value = visitExpression(node.value); |
1451 return node; | 1475 return node; |
1452 } | 1476 } |
1453 | 1477 |
| 1478 visitGetTypeTestProperty(GetTypeTestProperty node) { |
| 1479 node.object = visitExpression(node.object); |
| 1480 return node; |
| 1481 } |
| 1482 |
1454 visitCreateBox(CreateBox node) => node; | 1483 visitCreateBox(CreateBox node) => node; |
1455 | 1484 |
1456 visitCreateInstance(CreateInstance node) { | 1485 visitCreateInstance(CreateInstance node) { |
1457 _replaceExpressions(node.arguments); | 1486 _replaceExpressions(node.arguments); |
1458 _replaceExpressions(node.typeInformation); | 1487 _replaceExpressions(node.typeInformation); |
1459 return node; | 1488 return node; |
1460 } | 1489 } |
1461 | 1490 |
1462 visitReifyRuntimeType(ReifyRuntimeType node) { | 1491 visitReifyRuntimeType(ReifyRuntimeType node) { |
1463 node.value = visitExpression(node.value); | 1492 node.value = visitExpression(node.value); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 | 1596 |
1568 /// Number of uses of the current fallthrough target. | 1597 /// Number of uses of the current fallthrough target. |
1569 int get useCount => _stack.last.useCount; | 1598 int get useCount => _stack.last.useCount; |
1570 | 1599 |
1571 /// Indicate that a statement will fall through to the current fallthrough | 1600 /// Indicate that a statement will fall through to the current fallthrough |
1572 /// target. | 1601 /// target. |
1573 void use() { | 1602 void use() { |
1574 ++_stack.last.useCount; | 1603 ++_stack.last.useCount; |
1575 } | 1604 } |
1576 } | 1605 } |
OLD | NEW |