| OLD | NEW |
| (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 "vm/cha.h" |
| 6 #include "vm/flags.h" |
| 7 #include "vm/freelist.h" |
| 8 #include "vm/object.h" |
| 9 #include "vm/raw_object.h" |
| 10 #include "vm/visitor.h" |
| 11 |
| 12 namespace dart { |
| 13 |
| 14 CHA::CHA() : class_table_(*Isolate::Current()->class_table()) { } |
| 15 |
| 16 |
| 17 bool CHA::HasSubclasses(intptr_t cid) const { |
| 18 const Class& cls = Class::Handle(class_table_.At(cid)); |
| 19 ASSERT(!cls.IsNull()); |
| 20 // TODO(regis): Replace assert below with ASSERT(cid > kDartObjectCid). |
| 21 ASSERT(!cls.IsObjectClass()); |
| 22 const GrowableObjectArray& cls_direct_subclasses = |
| 23 GrowableObjectArray::Handle(cls.direct_subclasses()); |
| 24 return |
| 25 !cls_direct_subclasses.IsNull() && (cls_direct_subclasses.Length() > 0); |
| 26 } |
| 27 |
| 28 |
| 29 // Returns true if the given array of cids contains the given cid. |
| 30 static bool ContainsCid(ZoneGrowableArray<intptr_t>* cids, intptr_t cid) { |
| 31 for (intptr_t i = 0; i < cids->length(); i++) { |
| 32 if ((*cids)[i] == cid) { |
| 33 return true; |
| 34 } |
| 35 } |
| 36 return false; |
| 37 } |
| 38 |
| 39 |
| 40 // Recursively collect direct and indirect subclass ids of cls. |
| 41 static void CollectSubclassIds(ZoneGrowableArray<intptr_t>* cids, |
| 42 const Class& cls) { |
| 43 const GrowableObjectArray& cls_direct_subclasses = |
| 44 GrowableObjectArray::Handle(cls.direct_subclasses()); |
| 45 if (cls_direct_subclasses.IsNull()) { |
| 46 return; |
| 47 } |
| 48 Class& direct_subclass = Class::Handle(); |
| 49 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) { |
| 50 direct_subclass ^= cls_direct_subclasses.At(i); |
| 51 intptr_t direct_subclass_id = direct_subclass.id(); |
| 52 if (!ContainsCid(cids, direct_subclass_id)) { |
| 53 cids->Add(direct_subclass_id); |
| 54 CollectSubclassIds(cids, direct_subclass); |
| 55 } |
| 56 } |
| 57 } |
| 58 |
| 59 |
| 60 ZoneGrowableArray<intptr_t>* CHA::GetSubclassIdsOf(intptr_t cid) const { |
| 61 const Class& cls = Class::Handle(class_table_.At(cid)); |
| 62 ASSERT(!cls.IsNull()); |
| 63 // TODO(regis): Replace assert below with ASSERT(cid > kDartObjectCid). |
| 64 ASSERT(!cls.IsObjectClass()); |
| 65 ZoneGrowableArray<intptr_t>* ids = new ZoneGrowableArray<intptr_t>(); |
| 66 CollectSubclassIds(ids, cls); |
| 67 return ids; |
| 68 } |
| 69 |
| 70 |
| 71 ZoneGrowableArray<Function*>* CHA::GetNamedInstanceFunctionsOf( |
| 72 const ZoneGrowableArray<intptr_t>& cids, |
| 73 const String& function_name) const { |
| 74 ASSERT(!function_name.IsNull()); |
| 75 ZoneGrowableArray<Function*>* functions = new ZoneGrowableArray<Function*>(); |
| 76 Class& cls = Class::Handle(); |
| 77 Function& cls_function = Function::Handle(); |
| 78 for (intptr_t i = 0; i < cids.length(); i++) { |
| 79 const intptr_t cid = cids[i]; |
| 80 cls = class_table_.At(cid); |
| 81 // TODO(regis): Replace assert below with ASSERT(cid > kDartObjectCid). |
| 82 ASSERT(!cls.IsObjectClass()); |
| 83 cls_function = cls.LookupDynamicFunction(function_name); |
| 84 if (!cls_function.IsNull()) { |
| 85 functions->Add(&Function::ZoneHandle(cls_function.raw())); |
| 86 } |
| 87 } |
| 88 return functions; |
| 89 } |
| 90 |
| 91 |
| 92 ZoneGrowableArray<Function*>* CHA::GetOverridesOf( |
| 93 const Function& function) const { |
| 94 ASSERT(!function.IsNull()); |
| 95 ASSERT(function.IsDynamicFunction()); |
| 96 const Class& function_owner = Class::Handle(function.Owner()); |
| 97 const String& function_name = String::Handle(function.name()); |
| 98 ZoneGrowableArray<intptr_t>* cids = new ZoneGrowableArray<intptr_t>(); |
| 99 CollectSubclassIds(cids, function_owner); |
| 100 return GetNamedInstanceFunctionsOf(*cids, function_name); |
| 101 } |
| 102 |
| 103 } // namespace dart |
| OLD | NEW |