OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/cha.h" | 6 #include "vm/cha.h" |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" |
10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 static bool ContainsCid(const GrowableArray<Class*>& classes, intptr_t cid) { | |
15 for (intptr_t i = 0; i < classes.length(); ++i) { | |
16 if (classes[i]->id() == cid) return true; | |
17 } | |
18 return false; | |
19 } | |
20 | |
21 | 14 |
22 TEST_CASE(ClassHierarchyAnalysis) { | 15 TEST_CASE(ClassHierarchyAnalysis) { |
23 const char* kScriptChars = | 16 const char* kScriptChars = |
24 "class A {" | 17 "class A {" |
25 " foo() { }" | 18 " foo() { }" |
26 " bar() { }" | 19 " bar() { }" |
27 "}\n" | 20 "}\n" |
28 "class B extends A {" | 21 "class B extends A {" |
29 "}\n" | 22 "}\n" |
30 "class C extends B {" | 23 "class C extends B {" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 75 |
83 CHA cha(Thread::Current()); | 76 CHA cha(Thread::Current()); |
84 | 77 |
85 EXPECT(cha.HasSubclasses(kInstanceCid)); | 78 EXPECT(cha.HasSubclasses(kInstanceCid)); |
86 EXPECT(!cha.HasSubclasses(kSmiCid)); | 79 EXPECT(!cha.HasSubclasses(kSmiCid)); |
87 EXPECT(!cha.HasSubclasses(kNullCid)); | 80 EXPECT(!cha.HasSubclasses(kNullCid)); |
88 | 81 |
89 EXPECT(CHA::HasSubclasses(class_a)); | 82 EXPECT(CHA::HasSubclasses(class_a)); |
90 EXPECT(CHA::HasSubclasses(class_b)); | 83 EXPECT(CHA::HasSubclasses(class_b)); |
91 EXPECT(!CHA::HasSubclasses(class_c)); | 84 EXPECT(!CHA::HasSubclasses(class_c)); |
92 cha.AddToLeafClasses(class_c); | 85 cha.AddToGuardedClasses(class_c, /*subclass_count=*/0); |
93 EXPECT(!CHA::HasSubclasses(class_d)); | 86 EXPECT(!CHA::HasSubclasses(class_d)); |
94 cha.AddToLeafClasses(class_d); | 87 cha.AddToGuardedClasses(class_d, /*subclass_count=*/0); |
95 | 88 |
96 EXPECT(!ContainsCid(cha.leaf_classes(), class_a.id())); | 89 EXPECT(!cha.IsGuardedClass(class_a.id())); |
97 EXPECT(!ContainsCid(cha.leaf_classes(), class_b.id())); | 90 EXPECT(!cha.IsGuardedClass(class_b.id())); |
98 EXPECT(ContainsCid(cha.leaf_classes(), class_c.id())); | 91 EXPECT(cha.IsGuardedClass(class_c.id())); |
99 EXPECT(ContainsCid(cha.leaf_classes(), class_d.id())); | 92 EXPECT(cha.IsGuardedClass(class_d.id())); |
100 | 93 |
101 const Class& closure_class = | 94 const Class& closure_class = |
102 Class::Handle(Isolate::Current()->object_store()->closure_class()); | 95 Class::Handle(Isolate::Current()->object_store()->closure_class()); |
103 EXPECT(!cha.HasSubclasses(closure_class.id())); | 96 EXPECT(!cha.HasSubclasses(closure_class.id())); |
104 } | 97 } |
105 | 98 |
106 } // namespace dart | 99 } // namespace dart |
OLD | NEW |