| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // Recursively collect direct and indirect subclass ids of cls. | 42 // Recursively collect direct and indirect subclass ids of cls. |
| 43 static void CollectSubclassIds(ZoneGrowableArray<intptr_t>* cids, | 43 static void CollectSubclassIds(ZoneGrowableArray<intptr_t>* cids, |
| 44 const Class& cls) { | 44 const Class& cls) { |
| 45 const GrowableObjectArray& cls_direct_subclasses = | 45 const GrowableObjectArray& cls_direct_subclasses = |
| 46 GrowableObjectArray::Handle(cls.direct_subclasses()); | 46 GrowableObjectArray::Handle(cls.direct_subclasses()); |
| 47 if (cls_direct_subclasses.IsNull()) { | 47 if (cls_direct_subclasses.IsNull()) { |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 Class& direct_subclass = Class::Handle(); | 50 Class& direct_subclass = Class::Handle(); |
| 51 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) { | 51 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) { |
| 52 direct_subclass |= cls_direct_subclasses.At(i); | 52 direct_subclass ^= cls_direct_subclasses.At(i); |
| 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 ASSERT(cid > kInstanceCid); |
| 64 const ClassTable& class_table = *Isolate::Current()->class_table(); | 64 const ClassTable& class_table = *Isolate::Current()->class_table(); |
| 65 const Class& cls = Class::Handle(class_table.At(cid)); | 65 const Class& cls = Class::Handle(class_table.At(cid)); |
| 66 ASSERT(!cls.IsNull()); | 66 ASSERT(!cls.IsNull()); |
| 67 ZoneGrowableArray<intptr_t>* ids = new ZoneGrowableArray<intptr_t>(); | 67 ZoneGrowableArray<intptr_t>* ids = new ZoneGrowableArray<intptr_t>(); |
| 68 CollectSubclassIds(ids, cls); | 68 CollectSubclassIds(ids, cls); |
| 69 return ids; | 69 return ids; |
| 70 } | 70 } |
| 71 | 71 |
| 72 | 72 |
| 73 bool CHA::HasOverride(const Class& cls, const String& function_name) { | 73 bool CHA::HasOverride(const Class& cls, const String& function_name) { |
| 74 const GrowableObjectArray& cls_direct_subclasses = | 74 const GrowableObjectArray& cls_direct_subclasses = |
| 75 GrowableObjectArray::Handle(cls.direct_subclasses()); | 75 GrowableObjectArray::Handle(cls.direct_subclasses()); |
| 76 if (cls_direct_subclasses.IsNull()) { | 76 if (cls_direct_subclasses.IsNull()) { |
| 77 return false; | 77 return false; |
| 78 } | 78 } |
| 79 Class& direct_subclass = Class::Handle(); | 79 Class& direct_subclass = Class::Handle(); |
| 80 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) { | 80 for (intptr_t i = 0; i < cls_direct_subclasses.Length(); i++) { |
| 81 direct_subclass |= cls_direct_subclasses.At(i); | 81 direct_subclass ^= cls_direct_subclasses.At(i); |
| 82 if (direct_subclass.LookupDynamicFunction(function_name) != | 82 if (direct_subclass.LookupDynamicFunction(function_name) != |
| 83 Function::null()) { | 83 Function::null()) { |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 if (HasOverride(direct_subclass, function_name)) { | 86 if (HasOverride(direct_subclass, function_name)) { |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 return false; | 90 return false; |
| 91 } | 91 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 116 ASSERT(!function.IsNull()); | 116 ASSERT(!function.IsNull()); |
| 117 ASSERT(function.IsDynamicFunction()); | 117 ASSERT(function.IsDynamicFunction()); |
| 118 const Class& function_owner = Class::Handle(function.Owner()); | 118 const Class& function_owner = Class::Handle(function.Owner()); |
| 119 const String& function_name = String::Handle(function.name()); | 119 const String& function_name = String::Handle(function.name()); |
| 120 ZoneGrowableArray<intptr_t>* cids = new ZoneGrowableArray<intptr_t>(); | 120 ZoneGrowableArray<intptr_t>* cids = new ZoneGrowableArray<intptr_t>(); |
| 121 CollectSubclassIds(cids, function_owner); | 121 CollectSubclassIds(cids, function_owner); |
| 122 return GetNamedInstanceFunctionsOf(*cids, function_name); | 122 return GetNamedInstanceFunctionsOf(*cids, function_name); |
| 123 } | 123 } |
| 124 | 124 |
| 125 } // namespace dart | 125 } // namespace dart |
| OLD | NEW |