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 '../closure.dart'; | 9 import '../closure.dart'; |
10 import '../common.dart'; | 10 import '../common.dart'; |
11 import '../common/resolution.dart'; | 11 import '../common/resolution.dart'; |
12 import '../constants/expressions.dart'; | 12 import '../constants/expressions.dart'; |
13 import '../dart_types.dart'; | 13 import '../dart_types.dart'; |
14 import '../elements/elements.dart'; | 14 import '../elements/elements.dart'; |
15 import '../elements/visitor.dart'; | 15 import '../elements/visitor.dart'; |
16 import '../js_backend/backend_serialization.dart' | 16 import '../js_backend/backend_serialization.dart' |
17 show JavaScriptBackendSerializer; | 17 show NativeBehaviorSerialization; |
18 import '../native/native.dart' show NativeBehavior; | 18 import '../native/native.dart' show NativeBehavior; |
19 import '../resolution/access_semantics.dart'; | 19 import '../resolution/access_semantics.dart'; |
20 import '../resolution/send_structure.dart'; | 20 import '../resolution/send_structure.dart'; |
21 import '../resolution/tree_elements.dart'; | 21 import '../resolution/tree_elements.dart'; |
22 import '../tokens/token.dart'; | 22 import '../tokens/token.dart'; |
23 import '../tree/nodes.dart'; | 23 import '../tree/nodes.dart'; |
24 import '../universe/selector.dart'; | 24 import '../universe/selector.dart'; |
25 import '../universe/use.dart'; | 25 import '../universe/use.dart'; |
26 import '../util/util.dart'; | 26 import '../util/util.dart'; |
27 import 'resolved_ast_serialization.dart'; | 27 import 'resolved_ast_serialization.dart'; |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 TreeElementsEquivalenceVisitor visitor = new TreeElementsEquivalenceVisitor( | 853 TreeElementsEquivalenceVisitor visitor = new TreeElementsEquivalenceVisitor( |
854 indices1, indices2, elements1, elements2, strategy); | 854 indices1, indices2, elements1, elements2, strategy); |
855 resolvedAst1.node.accept(visitor); | 855 resolvedAst1.node.accept(visitor); |
856 if (visitor.success) { | 856 if (visitor.success) { |
857 return strategy.test(elements1, elements2, 'containsTryStatement', | 857 return strategy.test(elements1, elements2, 'containsTryStatement', |
858 elements1.containsTryStatement, elements2.containsTryStatement); | 858 elements1.containsTryStatement, elements2.containsTryStatement); |
859 } | 859 } |
860 return false; | 860 return false; |
861 } | 861 } |
862 | 862 |
| 863 bool testNativeBehavior(NativeBehavior a, NativeBehavior b, |
| 864 [TestStrategy strategy = const TestStrategy()]) { |
| 865 if (identical(a, b)) return true; |
| 866 if (a == null || b == null) return false; |
| 867 return strategy.test( |
| 868 a, b, 'codeTemplateText', a.codeTemplateText, b.codeTemplateText) && |
| 869 strategy.test(a, b, 'isAllocation', a.isAllocation, b.isAllocation) && |
| 870 strategy.test(a, b, 'sideEffects', a.sideEffects, b.sideEffects) && |
| 871 strategy.test(a, b, 'throwBehavior', a.throwBehavior, b.throwBehavior) && |
| 872 strategy.testTypeLists( |
| 873 a, |
| 874 b, |
| 875 'dartTypesReturned', |
| 876 NativeBehaviorSerialization.filterDartTypes(a.typesReturned), |
| 877 NativeBehaviorSerialization.filterDartTypes(b.typesReturned)) && |
| 878 strategy.testLists( |
| 879 a, |
| 880 b, |
| 881 'specialTypesReturned', |
| 882 NativeBehaviorSerialization.filterSpecialTypes(a.typesReturned), |
| 883 NativeBehaviorSerialization.filterSpecialTypes(b.typesReturned)) && |
| 884 strategy.testTypeLists( |
| 885 a, |
| 886 b, |
| 887 'dartTypesInstantiated', |
| 888 NativeBehaviorSerialization.filterDartTypes(a.typesInstantiated), |
| 889 NativeBehaviorSerialization.filterDartTypes(b.typesInstantiated)) && |
| 890 strategy.testLists( |
| 891 a, |
| 892 b, |
| 893 'specialTypesInstantiated', |
| 894 NativeBehaviorSerialization.filterSpecialTypes(a.typesInstantiated), |
| 895 NativeBehaviorSerialization |
| 896 .filterSpecialTypes(b.typesInstantiated)) && |
| 897 strategy.test(a, b, 'useGvn', a.useGvn, b.useGvn); |
| 898 } |
| 899 |
863 /// Visitor that checks the equivalence of [TreeElements] data. | 900 /// Visitor that checks the equivalence of [TreeElements] data. |
864 class TreeElementsEquivalenceVisitor extends Visitor { | 901 class TreeElementsEquivalenceVisitor extends Visitor { |
865 final TestStrategy strategy; | 902 final TestStrategy strategy; |
866 final AstIndexComputer indices1; | 903 final AstIndexComputer indices1; |
867 final AstIndexComputer indices2; | 904 final AstIndexComputer indices2; |
868 final TreeElements elements1; | 905 final TreeElements elements1; |
869 final TreeElements elements2; | 906 final TreeElements elements2; |
870 bool success = true; | 907 bool success = true; |
871 | 908 |
872 TreeElementsEquivalenceVisitor( | 909 TreeElementsEquivalenceVisitor( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 strategy.test( | 941 strategy.test( |
905 a, b, 'isBreakTarget', a.isBreakTarget, b.isBreakTarget) && | 942 a, b, 'isBreakTarget', a.isBreakTarget, b.isBreakTarget) && |
906 strategy.test( | 943 strategy.test( |
907 a, b, 'isContinueTarget', a.isContinueTarget, b.isContinueTarget); | 944 a, b, 'isContinueTarget', a.isContinueTarget, b.isContinueTarget); |
908 } | 945 } |
909 | 946 |
910 bool testNativeData(Node node1, Node node2, String property, a, b) { | 947 bool testNativeData(Node node1, Node node2, String property, a, b) { |
911 if (identical(a, b)) return true; | 948 if (identical(a, b)) return true; |
912 if (a == null || b == null) return false; | 949 if (a == null || b == null) return false; |
913 if (a is NativeBehavior && b is NativeBehavior) { | 950 if (a is NativeBehavior && b is NativeBehavior) { |
914 return strategy.test(a, b, 'codeTemplateText', a.codeTemplateText, | 951 return testNativeBehavior(a, b, strategy); |
915 b.codeTemplateText) && | |
916 strategy.test(a, b, 'isAllocation', a.isAllocation, b.isAllocation) && | |
917 strategy.test(a, b, 'sideEffects', a.sideEffects, b.sideEffects) && | |
918 strategy.test( | |
919 a, b, 'throwBehavior', a.throwBehavior, b.throwBehavior) && | |
920 strategy.testTypeLists( | |
921 a, | |
922 b, | |
923 'dartTypesReturned', | |
924 JavaScriptBackendSerializer.filterDartTypes(a.typesReturned), | |
925 JavaScriptBackendSerializer.filterDartTypes(b.typesReturned)) && | |
926 strategy.testLists( | |
927 a, | |
928 b, | |
929 'specialTypesReturned', | |
930 JavaScriptBackendSerializer.filterSpecialTypes(a.typesReturned), | |
931 JavaScriptBackendSerializer | |
932 .filterSpecialTypes(b.typesReturned)) && | |
933 strategy.testTypeLists( | |
934 a, | |
935 b, | |
936 'dartTypesInstantiated', | |
937 JavaScriptBackendSerializer.filterDartTypes(a.typesInstantiated), | |
938 JavaScriptBackendSerializer | |
939 .filterDartTypes(b.typesInstantiated)) && | |
940 strategy.testLists( | |
941 a, | |
942 b, | |
943 'specialTypesInstantiated', | |
944 JavaScriptBackendSerializer | |
945 .filterSpecialTypes(a.typesInstantiated), | |
946 JavaScriptBackendSerializer | |
947 .filterSpecialTypes(b.typesInstantiated)) && | |
948 strategy.test(a, b, 'useGvn', a.useGvn, b.useGvn); | |
949 } | 952 } |
950 return true; | 953 return true; |
951 } | 954 } |
952 | 955 |
953 visitNode(Node node1) { | 956 visitNode(Node node1) { |
954 if (!success) return; | 957 if (!success) return; |
955 int index = indices1.nodeIndices[node1]; | 958 int index = indices1.nodeIndices[node1]; |
956 Node node2 = indices2.nodeList[index]; | 959 Node node2 = indices2.nodeList[index]; |
957 success = strategy.testElements( | 960 success = strategy.testElements( |
958 node1, node2, '[$index]', elements1[node1], elements2[node2]) && | 961 node1, node2, '[$index]', elements1[node1], elements2[node2]) && |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1822 @override | 1825 @override |
1823 bool visitStatement(Statement node1, Statement node2) { | 1826 bool visitStatement(Statement node1, Statement node2) { |
1824 throw new UnsupportedError('Unexpected nodes: $node1 <> $node2'); | 1827 throw new UnsupportedError('Unexpected nodes: $node1 <> $node2'); |
1825 } | 1828 } |
1826 | 1829 |
1827 @override | 1830 @override |
1828 bool visitStringNode(StringNode node1, StringNode node2) { | 1831 bool visitStringNode(StringNode node1, StringNode node2) { |
1829 throw new UnsupportedError('Unexpected nodes: $node1 <> $node2'); | 1832 throw new UnsupportedError('Unexpected nodes: $node1 <> $node2'); |
1830 } | 1833 } |
1831 } | 1834 } |
OLD | NEW |