| OLD | NEW |
| 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/cha.h" | 5 #include "vm/cha.h" |
| 6 #include "vm/class_table.h" | 6 #include "vm/class_table.h" |
| 7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
| 8 #include "vm/freelist.h" | 8 #include "vm/freelist.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/raw_object.h" | 10 #include "vm/raw_object.h" |
| 11 #include "vm/visitor.h" | 11 #include "vm/visitor.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 bool CHA::HasSubclasses(intptr_t cid) { | 15 bool CHA::HasSubclasses(intptr_t cid) { |
| 16 ASSERT(cid >= kInstanceCid); |
| 16 const ClassTable& class_table = *Isolate::Current()->class_table(); | 17 const ClassTable& class_table = *Isolate::Current()->class_table(); |
| 17 const Class& cls = Class::Handle(class_table.At(cid)); | 18 const Class& cls = Class::Handle(class_table.At(cid)); |
| 18 ASSERT(!cls.IsNull()); | 19 ASSERT(!cls.IsNull()); |
| 19 // TODO(regis): Add ASSERT(cid > kDartObjectCid). | |
| 20 if (cls.IsObjectClass()) { | 20 if (cls.IsObjectClass()) { |
| 21 // Class Object has subclasses, although we do not keep track of them. | 21 // Class Object has subclasses, although we do not keep track of them. |
| 22 return true; | 22 return true; |
| 23 } | 23 } |
| 24 const GrowableObjectArray& cls_direct_subclasses = | 24 const GrowableObjectArray& cls_direct_subclasses = |
| 25 GrowableObjectArray::Handle(cls.direct_subclasses()); | 25 GrowableObjectArray::Handle(cls.direct_subclasses()); |
| 26 return | 26 return |
| 27 !cls_direct_subclasses.IsNull() && (cls_direct_subclasses.Length() > 0); | 27 !cls_direct_subclasses.IsNull() && (cls_direct_subclasses.Length() > 0); |
| 28 } | 28 } |
| 29 | 29 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 53 intptr_t direct_subclass_id = direct_subclass.id(); | 53 intptr_t direct_subclass_id = direct_subclass.id(); |
| 54 if (!ContainsCid(cids, direct_subclass_id)) { | 54 if (!ContainsCid(cids, direct_subclass_id)) { |
| 55 cids->Add(direct_subclass_id); | 55 cids->Add(direct_subclass_id); |
| 56 CollectSubclassIds(cids, direct_subclass); | 56 CollectSubclassIds(cids, direct_subclass); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 ZoneGrowableArray<intptr_t>* CHA::GetSubclassIdsOf(intptr_t cid) { | 62 ZoneGrowableArray<intptr_t>* CHA::GetSubclassIdsOf(intptr_t cid) { |
| 63 ASSERT(cid > kInstanceCid); |
| 63 const ClassTable& class_table = *Isolate::Current()->class_table(); | 64 const ClassTable& class_table = *Isolate::Current()->class_table(); |
| 64 const Class& cls = Class::Handle(class_table.At(cid)); | 65 const Class& cls = Class::Handle(class_table.At(cid)); |
| 65 ASSERT(!cls.IsNull()); | 66 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>(); | 67 ZoneGrowableArray<intptr_t>* ids = new ZoneGrowableArray<intptr_t>(); |
| 69 CollectSubclassIds(ids, cls); | 68 CollectSubclassIds(ids, cls); |
| 70 return ids; | 69 return ids; |
| 71 } | 70 } |
| 72 | 71 |
| 73 | 72 |
| 74 ZoneGrowableArray<Function*>* CHA::GetNamedInstanceFunctionsOf( | 73 ZoneGrowableArray<Function*>* CHA::GetNamedInstanceFunctionsOf( |
| 75 const ZoneGrowableArray<intptr_t>& cids, | 74 const ZoneGrowableArray<intptr_t>& cids, |
| 76 const String& function_name) { | 75 const String& function_name) { |
| 77 ASSERT(!function_name.IsNull()); | 76 ASSERT(!function_name.IsNull()); |
| 78 const ClassTable& class_table = *Isolate::Current()->class_table(); | 77 const ClassTable& class_table = *Isolate::Current()->class_table(); |
| 79 ZoneGrowableArray<Function*>* functions = new ZoneGrowableArray<Function*>(); | 78 ZoneGrowableArray<Function*>* functions = new ZoneGrowableArray<Function*>(); |
| 80 Class& cls = Class::Handle(); | 79 Class& cls = Class::Handle(); |
| 81 Function& cls_function = Function::Handle(); | 80 Function& cls_function = Function::Handle(); |
| 82 for (intptr_t i = 0; i < cids.length(); i++) { | 81 for (intptr_t i = 0; i < cids.length(); i++) { |
| 83 const intptr_t cid = cids[i]; | 82 const intptr_t cid = cids[i]; |
| 83 ASSERT(cid > kInstanceCid); |
| 84 cls = class_table.At(cid); | 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); | 85 cls_function = cls.LookupDynamicFunction(function_name); |
| 88 if (!cls_function.IsNull()) { | 86 if (!cls_function.IsNull()) { |
| 89 functions->Add(&Function::ZoneHandle(cls_function.raw())); | 87 functions->Add(&Function::ZoneHandle(cls_function.raw())); |
| 90 } | 88 } |
| 91 } | 89 } |
| 92 return functions; | 90 return functions; |
| 93 } | 91 } |
| 94 | 92 |
| 95 | 93 |
| 96 ZoneGrowableArray<Function*>* CHA::GetOverridesOf(const Function& function) { | 94 ZoneGrowableArray<Function*>* CHA::GetOverridesOf(const Function& function) { |
| 97 ASSERT(!function.IsNull()); | 95 ASSERT(!function.IsNull()); |
| 98 ASSERT(function.IsDynamicFunction()); | 96 ASSERT(function.IsDynamicFunction()); |
| 99 const Class& function_owner = Class::Handle(function.Owner()); | 97 const Class& function_owner = Class::Handle(function.Owner()); |
| 100 const String& function_name = String::Handle(function.name()); | 98 const String& function_name = String::Handle(function.name()); |
| 101 ZoneGrowableArray<intptr_t>* cids = new ZoneGrowableArray<intptr_t>(); | 99 ZoneGrowableArray<intptr_t>* cids = new ZoneGrowableArray<intptr_t>(); |
| 102 CollectSubclassIds(cids, function_owner); | 100 CollectSubclassIds(cids, function_owner); |
| 103 return GetNamedInstanceFunctionsOf(*cids, function_name); | 101 return GetNamedInstanceFunctionsOf(*cids, function_name); |
| 104 } | 102 } |
| 105 | 103 |
| 106 } // namespace dart | 104 } // namespace dart |
| OLD | NEW |