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 import 'package:kernel/kernel.dart'; | 5 import 'package:kernel/kernel.dart'; |
6 import 'package:kernel/class_hierarchy.dart'; | 6 import 'package:kernel/class_hierarchy.dart'; |
7 import 'package:test/test.dart'; | 7 import 'package:test/test.dart'; |
8 import 'class_hierarchy_basic.dart'; | 8 import 'class_hierarchy_basic.dart'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:math'; | 10 import 'dart:math'; |
| 11 import 'self_check_util.dart'; |
| 12 |
| 13 main(List<String> args) { |
| 14 runSelfCheck(args, (String filename) { |
| 15 testClassHierarchyOnProgram(loadProgramFromBinary(filename)); |
| 16 }); |
| 17 } |
11 | 18 |
12 void testClassHierarchyOnProgram(Program program, {bool verbose: false}) { | 19 void testClassHierarchyOnProgram(Program program, {bool verbose: false}) { |
13 BasicClassHierarchy basic = new BasicClassHierarchy(program); | 20 BasicClassHierarchy basic = new BasicClassHierarchy(program); |
14 ClassHierarchy classHierarchy = new ClassHierarchy(program); | 21 ClassHierarchy classHierarchy = new ClassHierarchy(program); |
15 int total = classHierarchy.classes.length; | 22 int total = classHierarchy.classes.length; |
16 int progress = 0; | 23 int progress = 0; |
17 for (var class1 in classHierarchy.classes) { | 24 for (var class1 in classHierarchy.classes) { |
18 for (var class2 in classHierarchy.classes) { | 25 for (var class2 in classHierarchy.classes) { |
19 bool isSubclass = classHierarchy.isSubclassOf(class1, class2); | 26 bool isSubclass = classHierarchy.isSubclassOf(class1, class2); |
20 bool isSubmixture = classHierarchy.isSubmixtureOf(class1, class2); | 27 bool isSubmixture = classHierarchy.isSubmixtureOf(class1, class2); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 ++progress; | 115 ++progress; |
109 if (verbose) { | 116 if (verbose) { |
110 stdout.write('\rInterface queries ${100 * progress ~/ total}%'); | 117 stdout.write('\rInterface queries ${100 * progress ~/ total}%'); |
111 } | 118 } |
112 } | 119 } |
113 for (var classNode in classHierarchy.classes) { | 120 for (var classNode in classHierarchy.classes) { |
114 String getHash(member, superMember, setter) { | 121 String getHash(member, superMember, setter) { |
115 String eq = setter ? '=' : ''; | 122 String eq = setter ? '=' : ''; |
116 return '$member$eq overrides $superMember$eq'; | 123 return '$member$eq overrides $superMember$eq'; |
117 } | 124 } |
| 125 |
118 Set<String> expectedOverrides = new Set<String>(); | 126 Set<String> expectedOverrides = new Set<String>(); |
119 basic.forEachOverridePair(classNode, (member, superMember, setter) { | 127 basic.forEachOverridePair(classNode, (member, superMember, setter) { |
120 expectedOverrides.add(getHash(member, superMember, setter)); | 128 expectedOverrides.add(getHash(member, superMember, setter)); |
121 }); | 129 }); |
122 Set<String> actualOverrides = new Set<String>(); | 130 Set<String> actualOverrides = new Set<String>(); |
123 classHierarchy.forEachOverridePair(classNode, (member, superMember, setter)
{ | 131 classHierarchy.forEachOverridePair(classNode, |
| 132 (member, superMember, setter) { |
124 actualOverrides.add(getHash(member, superMember, setter)); | 133 actualOverrides.add(getHash(member, superMember, setter)); |
125 }); | 134 }); |
126 for (var actual in actualOverrides) { | 135 for (var actual in actualOverrides) { |
127 if (!expectedOverrides.contains(actual)) { | 136 if (!expectedOverrides.contains(actual)) { |
128 fail("forEachOverridePair($classNode) should not report that $actual"); | 137 fail("forEachOverridePair($classNode) should not report that $actual"); |
129 } | 138 } |
130 } | 139 } |
131 for (var expected in expectedOverrides) { | 140 for (var expected in expectedOverrides) { |
132 if (!actualOverrides.contains(expected)) { | 141 if (!actualOverrides.contains(expected)) { |
133 fail("forEachOverridePair($classNode) did not report that $expected"); | 142 fail("forEachOverridePair($classNode) did not report that $expected"); |
134 } | 143 } |
135 } | 144 } |
136 } | 145 } |
137 if (verbose) { | 146 if (verbose) { |
138 print('\rProgress 100%. Done.'); | 147 print('\rProgress 100%. Done.'); |
139 } | 148 } |
140 } | 149 } |
141 | 150 |
142 var random = new Random(12345); | 151 var random = new Random(12345); |
143 | 152 |
144 List/*<T>*/ pickRandom/*<T>*/(List/*<T>*/ items, int n) { | 153 List/*<T>*/ pickRandom/*<T>*/(List/*<T>*/ items, int n) { |
145 var result = /*<T>*/[]; | 154 var result = /*<T>*/ []; |
146 for (int i = 0; i < n; ++i) { | 155 for (int i = 0; i < n; ++i) { |
147 result.add(items[random.nextInt(items.length)]); | 156 result.add(items[random.nextInt(items.length)]); |
148 } | 157 } |
149 return result; | 158 return result; |
150 } | 159 } |
OLD | NEW |