Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: runtime/vm/class_table_test.cc

Issue 10828399: Implement class hierarchy analysis in the VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/class_table.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "platform/assert.h"
6 #include "vm/class_finalizer.h"
7 #include "vm/class_table.h"
8 #include "vm/dart_entry.h"
9 #include "vm/globals.h"
10 #include "vm/symbols.h"
11 #include "vm/unit_test.h"
12
13 namespace dart {
14
15 TEST_CASE(ClassHierarchyAnalysis) {
16 const char* kScriptChars =
17 "class A {"
18 " foo() { }"
19 " bar() { }"
20 "}\n"
21 "class B extends A {"
22 "}\n"
23 "class C extends B {"
24 " foo() { }"
25 "}\n"
26 "class D extends A {"
27 " foo() { }"
28 " bar() { }"
29 "}\n";
30
31 TestCase::LoadTestScript(kScriptChars, NULL);
32 EXPECT(ClassFinalizer::FinalizePendingClasses());
33 const String& name = String::Handle(String::New(TestCase::url()));
34 const Library& lib = Library::Handle(Library::LookupLibrary(name));
35 EXPECT(!lib.IsNull());
36
37 const Class& class_a = Class::Handle(
38 lib.LookupClass(String::Handle(Symbols::New("A"))));
39 EXPECT(!class_a.IsNull());
40 const intptr_t class_a_id = class_a.id();
41
42 const Class& class_b = Class::Handle(
43 lib.LookupClass(String::Handle(Symbols::New("B"))));
44 EXPECT(!class_b.IsNull());
45 const intptr_t class_b_id = class_b.id();
46
47 const Class& class_c = Class::Handle(
48 lib.LookupClass(String::Handle(Symbols::New("C"))));
49 EXPECT(!class_c.IsNull());
50 const intptr_t class_c_id = class_c.id();
51
52 const Class& class_d = Class::Handle(
53 lib.LookupClass(String::Handle(Symbols::New("D"))));
54 EXPECT(!class_d.IsNull());
55 const intptr_t class_d_id = class_d.id();
56
57 const String& function_foo_name = String::Handle(String::New("foo"));
58 const String& function_bar_name = String::Handle(String::New("bar"));
59
60 const Function& class_a_foo =
61 Function::Handle(class_a.LookupDynamicFunction(function_foo_name));
62 EXPECT(!class_a_foo.IsNull());
63
64 const Function& class_a_bar =
65 Function::Handle(class_a.LookupDynamicFunction(function_bar_name));
66 EXPECT(!class_a_bar.IsNull());
67
68 const Function& class_c_foo =
69 Function::Handle(class_c.LookupDynamicFunction(function_foo_name));
70 EXPECT(!class_c_foo.IsNull());
71
72 const Function& class_d_foo =
73 Function::Handle(class_d.LookupDynamicFunction(function_foo_name));
74 EXPECT(!class_d_foo.IsNull());
75
76 const Function& class_d_bar =
77 Function::Handle(class_d.LookupDynamicFunction(function_bar_name));
78 EXPECT(!class_d_bar.IsNull());
79
80 ClassTable* class_table = Isolate::Current()->class_table();
81 EXPECT(class_table != NULL);
82
83 ZoneGrowableArray<intptr_t>* a_subclass_ids =
84 class_table->GetSubclassIdsOf(class_a_id);
85 EXPECT_EQ(3, a_subclass_ids->length());
86 EXPECT_EQ(class_b_id, (*a_subclass_ids)[0]);
87 EXPECT_EQ(class_c_id, (*a_subclass_ids)[1]);
88 EXPECT_EQ(class_d_id, (*a_subclass_ids)[2]);
89 ZoneGrowableArray<intptr_t>* b_subclass_ids =
90 class_table->GetSubclassIdsOf(class_b_id);
91 EXPECT_EQ(1, b_subclass_ids->length());
92 EXPECT_EQ(class_c_id, (*b_subclass_ids)[0]);
93 ZoneGrowableArray<intptr_t>* c_subclass_ids =
94 class_table->GetSubclassIdsOf(class_c_id);
95 EXPECT_EQ(0, c_subclass_ids->length());
96 ZoneGrowableArray<intptr_t>* d_subclass_ids =
97 class_table->GetSubclassIdsOf(class_d_id);
98 EXPECT_EQ(0, d_subclass_ids->length());
99
100 ZoneGrowableArray<Function*>* foos =
101 class_table->GetNamedInstanceFunctionsOf(*a_subclass_ids,
102 function_foo_name);
103 EXPECT_EQ(2, foos->length());
104 EXPECT_EQ(class_c_foo.raw(), (*foos)[0]->raw());
105 EXPECT_EQ(class_d_foo.raw(), (*foos)[1]->raw());
106
107 ZoneGrowableArray<Function*>* class_a_foo_overrides =
108 class_table->GetOverridesOf(class_a_foo);
109 EXPECT_EQ(2, class_a_foo_overrides->length());
110 EXPECT_EQ(class_c_foo.raw(), (*class_a_foo_overrides)[0]->raw());
111 EXPECT_EQ(class_d_foo.raw(), (*class_a_foo_overrides)[1]->raw());
112
113 ZoneGrowableArray<Function*>* bars =
114 class_table->GetNamedInstanceFunctionsOf(*a_subclass_ids,
115 function_bar_name);
116 EXPECT_EQ(1, bars->length());
117 EXPECT_EQ(class_d_bar.raw(), (*bars)[0]->raw());
118
119 ZoneGrowableArray<Function*>* class_a_bar_overrides =
120 class_table->GetOverridesOf(class_a_bar);
121 EXPECT_EQ(1, class_a_bar_overrides->length());
122 EXPECT_EQ(class_d_bar.raw(), (*class_a_bar_overrides)[0]->raw());
123 }
124
125 } // namespace dart
126
OLDNEW
« no previous file with comments | « runtime/vm/class_table.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698