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

Side by Side Diff: runtime/vm/class_table.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.h ('k') | runtime/vm/class_table_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "vm/class_table.h" 5 #include "vm/class_table.h"
6 #include "vm/flags.h" 6 #include "vm/flags.h"
7 #include "vm/freelist.h" 7 #include "vm/freelist.h"
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/raw_object.h" 9 #include "vm/raw_object.h"
10 #include "vm/visitor.h" 10 #include "vm/visitor.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 for (intptr_t i = 1; i < top_; i++) { 90 for (intptr_t i = 1; i < top_; i++) {
91 cls = At(i); 91 cls = At(i);
92 if (cls.raw() != reinterpret_cast<RawClass*>(0)) { 92 if (cls.raw() != reinterpret_cast<RawClass*>(0)) {
93 name = cls.Name(); 93 name = cls.Name();
94 OS::Print("%d: %s\n", i, name.ToCString()); 94 OS::Print("%d: %s\n", i, name.ToCString());
95 } 95 }
96 } 96 }
97 } 97 }
98 98
99
100 // Returns true if the given array of cids contains the given cid.
101 static bool ContainsCid(ZoneGrowableArray<intptr_t>* cids, intptr_t cid) {
102 for (intptr_t i = 0; i < cids->length(); i++) {
103 if ((*cids)[i] == cid) {
104 return true;
105 }
106 }
107 return false;
108 }
109
110
111 // Recursively collect direct and indirect subclass ids of cls.
112 static void CollectSubclassIds(ZoneGrowableArray<intptr_t>* cids,
113 const Class& cls) {
114 const GrowableObjectArray& cls_direct_subclasses =
115 GrowableObjectArray::Handle(cls.direct_subclasses());
116 if (cls_direct_subclasses.IsNull()) {
117 return;
118 }
119 Class& direct_subclass = Class::Handle();
120 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) {
121 direct_subclass ^= cls_direct_subclasses.At(i);
122 intptr_t direct_subclass_id = direct_subclass.id();
123 if (!ContainsCid(cids, direct_subclass_id)) {
124 cids->Add(direct_subclass_id);
125 CollectSubclassIds(cids, direct_subclass);
126 }
127 }
128 }
129
130
131 ZoneGrowableArray<intptr_t>* ClassTable::GetSubclassIdsOf(intptr_t cid) const {
132 const Class& cls = Class::Handle(At(cid));
133 ASSERT(!cls.IsNull());
134 // TODO(regis): Replace assert below with ASSERT(cid > kDartObjectCid).
135 ASSERT(!cls.IsObjectClass());
136 ZoneGrowableArray<intptr_t>* ids = new ZoneGrowableArray<intptr_t>();
137 CollectSubclassIds(ids, cls);
138 return ids;
139 }
140
141
142 ZoneGrowableArray<Function*>* ClassTable::GetNamedInstanceFunctionsOf(
143 const ZoneGrowableArray<intptr_t>& cids,
144 const String& function_name) const {
145 ASSERT(!function_name.IsNull());
146 ZoneGrowableArray<Function*>* functions = new ZoneGrowableArray<Function*>();
147 Class& cls = Class::Handle();
148 Function& cls_function = Function::Handle();
149 for (intptr_t i = 0; i < cids.length(); i++) {
150 const intptr_t cid = cids[i];
151 cls = At(cid);
152 // TODO(regis): Replace assert below with ASSERT(cid > kDartObjectCid).
153 ASSERT(!cls.IsObjectClass());
154 cls_function = cls.LookupDynamicFunction(function_name);
155 if (!cls_function.IsNull()) {
156 functions->Add(&Function::ZoneHandle(cls_function.raw()));
157 }
158 }
159 return functions;
160 }
161
162
163 ZoneGrowableArray<Function*>* ClassTable::GetOverridesOf(
164 const Function& function) const {
165 ASSERT(!function.IsNull());
166 ASSERT(function.IsDynamicFunction());
167 const Class& function_owner = Class::Handle(function.Owner());
168 const String& function_name = String::Handle(function.name());
169 ZoneGrowableArray<intptr_t>* cids = new ZoneGrowableArray<intptr_t>();
170 CollectSubclassIds(cids, function_owner);
171 return GetNamedInstanceFunctionsOf(*cids, function_name);
172 }
173
99 } // namespace dart 174 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_table.h ('k') | runtime/vm/class_table_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698