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