OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// Functions for asserting equivalence across serialization. | 5 /// Functions for asserting equivalence across serialization. |
6 | 6 |
7 library dart2js.serialization.equivalence; | 7 library dart2js.serialization.equivalence; |
8 | 8 |
| 9 import '../common.dart'; |
9 import '../common/resolution.dart'; | 10 import '../common/resolution.dart'; |
10 import '../constants/expressions.dart'; | 11 import '../constants/expressions.dart'; |
11 import '../dart_types.dart'; | 12 import '../dart_types.dart'; |
12 import '../elements/elements.dart'; | 13 import '../elements/elements.dart'; |
13 import '../elements/visitor.dart'; | 14 import '../elements/visitor.dart'; |
14 import '../js_backend/backend_serialization.dart' | 15 import '../js_backend/backend_serialization.dart' |
15 show JavaScriptBackendSerializer; | 16 show JavaScriptBackendSerializer; |
16 import '../native/native.dart' show NativeBehavior; | 17 import '../native/native.dart' show NativeBehavior; |
17 import '../resolution/access_semantics.dart'; | 18 import '../resolution/access_semantics.dart'; |
18 import '../resolution/send_structure.dart'; | 19 import '../resolution/send_structure.dart'; |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 } | 1048 } |
1048 } | 1049 } |
1049 | 1050 |
1050 class NodeEquivalenceVisitor implements Visitor1<bool, Node> { | 1051 class NodeEquivalenceVisitor implements Visitor1<bool, Node> { |
1051 final TestStrategy strategy; | 1052 final TestStrategy strategy; |
1052 | 1053 |
1053 const NodeEquivalenceVisitor([this.strategy = const TestStrategy()]); | 1054 const NodeEquivalenceVisitor([this.strategy = const TestStrategy()]); |
1054 | 1055 |
1055 bool testNodes( | 1056 bool testNodes( |
1056 var object1, var object2, String property, Node node1, Node node2) { | 1057 var object1, var object2, String property, Node node1, Node node2) { |
1057 if (node1 == node2) return true; | 1058 return strategy.test( |
1058 if (node1 == null || node2 == null) return false; | 1059 object1, object2, property, |
1059 return node1.accept1(this, node2); | 1060 node1, node2, (Node n1, Node n2) { |
| 1061 if (n1 == n2) return true; |
| 1062 if (n1 == null || n2 == null) return false; |
| 1063 return n1.accept1(this, n2); |
| 1064 }); |
1060 } | 1065 } |
1061 | 1066 |
1062 bool testNodeLists(var object1, var object2, String property, | 1067 bool testNodeLists(var object1, var object2, String property, |
1063 Link<Node> list1, Link<Node> list2) { | 1068 Link<Node> list1, Link<Node> list2) { |
1064 if (list1 == list2) return true; | 1069 return strategy.test( |
1065 if (list1 == null || list2 == null) return false; | 1070 object1, object2, property, |
1066 while (list1.isNotEmpty && list2.isNotEmpty) { | 1071 list1, list2, (Link<Node> l1, Link<Node> l2) { |
1067 if (!list1.head.accept1(this, list2.head)) { | 1072 if (l1 == l2) return true; |
1068 return false; | 1073 if (l1 == null || l2 == null) return false; |
| 1074 while (l1.isNotEmpty && l2.isNotEmpty) { |
| 1075 if (!l1.head.accept1(this, l2.head)) { |
| 1076 return false; |
| 1077 } |
| 1078 l1 = l1.tail; |
| 1079 l2 = l2.tail; |
1069 } | 1080 } |
1070 list1 = list1.tail; | 1081 return l1.isEmpty && l2.isEmpty; |
1071 list2 = list2.tail; | 1082 }); |
1072 } | |
1073 return list1.isEmpty && list2.isEmpty; | |
1074 } | 1083 } |
1075 | 1084 |
1076 bool testTokens( | 1085 bool testTokens( |
1077 var object1, var object2, String property, Token token1, Token token2) { | 1086 var object1, var object2, String property, Token token1, Token token2) { |
1078 if (token1 == token2) return true; | 1087 return strategy.test( |
1079 if (token1 == null || token2 == null) return false; | 1088 object1, object2, property, |
1080 return token1.hashCode == token2.hashCode; | 1089 token1, token2, (Token t1, Token t2) { |
| 1090 if (t1 == t2) return true; |
| 1091 if (t1 == null || t2 == null) return false; |
| 1092 return strategy.test(t1, t2, 'hashCode', t1.hashCode, t2.hashCode); |
| 1093 }); |
1081 } | 1094 } |
1082 | 1095 |
1083 @override | 1096 @override |
1084 bool visitAssert(Assert node1, Assert node2) { | 1097 bool visitAssert(Assert node1, Assert node2) { |
1085 return testTokens(node1, node2, 'assertToken', node1.assertToken, | 1098 return testTokens(node1, node2, 'assertToken', node1.assertToken, |
1086 node2.assertToken) && | 1099 node2.assertToken) && |
1087 testNodes( | 1100 testNodes( |
1088 node1, node2, 'condition', node1.condition, node2.condition) && | 1101 node1, node2, 'condition', node1.condition, node2.condition) && |
1089 testNodes(node1, node2, 'message', node1.message, node2.message); | 1102 testNodes(node1, node2, 'message', node1.message, node2.message); |
1090 } | 1103 } |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1745 @override | 1758 @override |
1746 bool visitStatement(Statement node1, Statement node2) { | 1759 bool visitStatement(Statement node1, Statement node2) { |
1747 throw new UnsupportedError('Unexpected nodes: $node1 <> $node2'); | 1760 throw new UnsupportedError('Unexpected nodes: $node1 <> $node2'); |
1748 } | 1761 } |
1749 | 1762 |
1750 @override | 1763 @override |
1751 bool visitStringNode(StringNode node1, StringNode node2) { | 1764 bool visitStringNode(StringNode node1, StringNode node2) { |
1752 throw new UnsupportedError('Unexpected nodes: $node1 <> $node2'); | 1765 throw new UnsupportedError('Unexpected nodes: $node1 <> $node2'); |
1753 } | 1766 } |
1754 } | 1767 } |
OLD | NEW |