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

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
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) {
srdjan 2012/08/20 22:47:16 COde below would look simpler if you change cids t
regis 2012/08/20 23:37:21 Done.
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,
srdjan 2012/08/20 22:47:16 For later: maybe we should create a hash_set<intpt
regis 2012/08/20 23:37:21 OK
113 const Class& cls) {
114 const GrowableObjectArray& cls_direct_subclasses =
115 GrowableObjectArray::Handle(cls.direct_subclasses());
srdjan 2012/08/20 22:47:16 How about : if (cls_direct_subclasses.IsNull()) re
regis 2012/08/20 23:37:21 Done.
116 if (!cls_direct_subclasses.IsNull()) {
117 Class& direct_subclass = Class::Handle();
118 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) {
119 direct_subclass ^= cls_direct_subclasses.At(i);
120 intptr_t direct_subclass_id = direct_subclass.id();
121 if (!ContainsCid(cids, direct_subclass_id)) {
122 cids->Add(direct_subclass_id);
123 CollectSubclassIds(cids, direct_subclass);
124 }
125 }
126 }
127 }
128
129
130 ZoneGrowableArray<intptr_t>* ClassTable::GetSubclassIdsOf(intptr_t cid) const {
131 ASSERT(cid != kObjectCid);
132 ASSERT(IsValidIndex(cid));
133 const Class& cls = Class::Handle(At(cid));
134 ASSERT(!cls.IsNull());
srdjan 2012/08/20 22:47:16 ASSERT(cls.IsInstance()) ?
regis 2012/08/20 23:37:21 You can use IsInstance() on handles of objects. He
135 ZoneGrowableArray<intptr_t>* ids = new ZoneGrowableArray<intptr_t>(2);
srdjan 2012/08/20 22:47:16 Why 2? If you do not specify anything, the data do
regis 2012/08/20 23:37:21 Done.
136 CollectSubclassIds(ids, cls);
137 return ids;
138 }
139
140
141 ZoneGrowableArray<Function*>* ClassTable::GetNamedInstanceFunctionsOf(
142 ZoneGrowableArray<intptr_t>* cids, const String& function_name) const {
143 ASSERT(cids != NULL);
144 ASSERT(!function_name.IsNull());
145 ZoneGrowableArray<Function*>* functions = new ZoneGrowableArray<Function*>(2);
srdjan 2012/08/20 22:47:16 ditto
regis 2012/08/20 23:37:21 Done.
146 Class& cls = Class::Handle();
147 Function& cls_function = Function::Handle();
148 for (intptr_t i = 0; i < cids->length(); i++) {
149 const intptr_t cid = (*cids)[i];
150 ASSERT(cid != kObjectCid);
srdjan 2012/08/20 22:47:16 Assert not correct
regis 2012/08/20 23:37:21 We do not yet have kDartObjectCid. I've added a TO
151 ASSERT(IsValidIndex(cid));
152 cls = At(cid);
srdjan 2012/08/20 22:47:16 ASSERT(cls.IsInstance()).
regis 2012/08/20 23:37:21 Done.
153 cls_function = cls.LookupDynamicFunction(function_name);
154 if (!cls_function.IsNull()) {
155 functions->Add(&Function::ZoneHandle(cls_function.raw()));
156 }
157 }
158 return functions;
159 }
160
161
162 ZoneGrowableArray<Function*>* ClassTable::GetOverridesOf(
163 const Function& function) const {
164 ASSERT(!function.IsNull());
165 ASSERT(function.IsDynamicFunction());
166 const Class& function_owner = Class::Handle(function.Owner());
167 const String& function_name = String::Handle(function.name());
168 ZoneGrowableArray<intptr_t>* cids = new ZoneGrowableArray<intptr_t>(4);
srdjan 2012/08/20 22:47:16 ditto.
regis 2012/08/20 23:37:21 Done.
169 CollectSubclassIds(cids, function_owner);
170 return GetNamedInstanceFunctionsOf(cids, function_name);
171 }
172
99 } // namespace dart 173 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_table.h ('k') | runtime/vm/class_table_test.cc » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698