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

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

Issue 10827450: Move class hierarchy analysis to its own source. (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
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 bool ClassTable::HasSubclasses(intptr_t cid) const {
101 const Class& cls = Class::Handle(At(cid));
102 ASSERT(!cls.IsNull());
103 // TODO(regis): Replace assert below with ASSERT(cid > kDartObjectCid).
104 ASSERT(!cls.IsObjectClass());
105 const GrowableObjectArray& cls_direct_subclasses =
106 GrowableObjectArray::Handle(cls.direct_subclasses());
107 return
108 !cls_direct_subclasses.IsNull() && (cls_direct_subclasses.Length() > 0);
109 }
110
111
112 // Returns true if the given array of cids contains the given cid.
113 static bool ContainsCid(ZoneGrowableArray<intptr_t>* cids, intptr_t cid) {
114 for (intptr_t i = 0; i < cids->length(); i++) {
115 if ((*cids)[i] == cid) {
116 return true;
117 }
118 }
119 return false;
120 }
121
122
123 // Recursively collect direct and indirect subclass ids of cls.
124 static void CollectSubclassIds(ZoneGrowableArray<intptr_t>* cids,
125 const Class& cls) {
126 const GrowableObjectArray& cls_direct_subclasses =
127 GrowableObjectArray::Handle(cls.direct_subclasses());
128 if (cls_direct_subclasses.IsNull()) {
129 return;
130 }
131 Class& direct_subclass = Class::Handle();
132 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) {
133 direct_subclass ^= cls_direct_subclasses.At(i);
134 intptr_t direct_subclass_id = direct_subclass.id();
135 if (!ContainsCid(cids, direct_subclass_id)) {
136 cids->Add(direct_subclass_id);
137 CollectSubclassIds(cids, direct_subclass);
138 }
139 }
140 }
141
142
143 ZoneGrowableArray<intptr_t>* ClassTable::GetSubclassIdsOf(intptr_t cid) const {
144 const Class& cls = Class::Handle(At(cid));
145 ASSERT(!cls.IsNull());
146 // TODO(regis): Replace assert below with ASSERT(cid > kDartObjectCid).
147 ASSERT(!cls.IsObjectClass());
148 ZoneGrowableArray<intptr_t>* ids = new ZoneGrowableArray<intptr_t>();
149 CollectSubclassIds(ids, cls);
150 return ids;
151 }
152
153
154 ZoneGrowableArray<Function*>* ClassTable::GetNamedInstanceFunctionsOf(
155 const ZoneGrowableArray<intptr_t>& cids,
156 const String& function_name) const {
157 ASSERT(!function_name.IsNull());
158 ZoneGrowableArray<Function*>* functions = new ZoneGrowableArray<Function*>();
159 Class& cls = Class::Handle();
160 Function& cls_function = Function::Handle();
161 for (intptr_t i = 0; i < cids.length(); i++) {
162 const intptr_t cid = cids[i];
163 cls = At(cid);
164 // TODO(regis): Replace assert below with ASSERT(cid > kDartObjectCid).
165 ASSERT(!cls.IsObjectClass());
166 cls_function = cls.LookupDynamicFunction(function_name);
167 if (!cls_function.IsNull()) {
168 functions->Add(&Function::ZoneHandle(cls_function.raw()));
169 }
170 }
171 return functions;
172 }
173
174
175 ZoneGrowableArray<Function*>* ClassTable::GetOverridesOf(
176 const Function& function) const {
177 ASSERT(!function.IsNull());
178 ASSERT(function.IsDynamicFunction());
179 const Class& function_owner = Class::Handle(function.Owner());
180 const String& function_name = String::Handle(function.name());
181 ZoneGrowableArray<intptr_t>* cids = new ZoneGrowableArray<intptr_t>();
182 CollectSubclassIds(cids, function_owner);
183 return GetNamedInstanceFunctionsOf(*cids, function_name);
184 }
185
186 } // namespace dart 99 } // namespace dart
OLDNEW
« runtime/vm/cha.h ('K') | « 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