| 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 #ifndef VM_CHA_H_ | 5 #ifndef VM_CHA_H_ |
| 6 #define VM_CHA_H_ | 6 #define VM_CHA_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/growable_array.h" |
| 9 | 10 |
| 10 namespace dart { | 11 namespace dart { |
| 11 | 12 |
| 12 class Class; | 13 class Class; |
| 13 class Function; | 14 class Function; |
| 14 template <typename T> class ZoneGrowableArray; | 15 template <typename T> class ZoneGrowableArray; |
| 15 class String; | 16 class String; |
| 16 | 17 |
| 17 class CHA : public AllStatic { | 18 class CHA : public StackResource { |
| 18 public: | 19 public: |
| 19 // Returns true if the class given by its cid has subclasses. | 20 explicit CHA(Isolate* isolate) |
| 20 static bool HasSubclasses(intptr_t cid); | 21 : StackResource(isolate), |
| 22 isolate_(isolate), |
| 23 cha_classes_(isolate, 1), |
| 24 previous_(isolate->cha()) { |
| 25 isolate->set_cha(this); |
| 26 } |
| 21 | 27 |
| 22 // Use only on known private classes that can never be subclassed by lazy | 28 ~CHA() { |
| 23 // class finalization. Does not affect Isolate::use_cha flag. | 29 ASSERT(isolate_->cha() == this); |
| 24 static bool HasSubclassesSafe(intptr_t cid); | 30 isolate_->set_cha(previous_); |
| 31 } |
| 25 | 32 |
| 26 // Returns an array containing the cids of the direct and indirect subclasses | 33 // Returns true if the class has subclasses. |
| 27 // of the class given by its cid. | 34 bool HasSubclasses(const Class& cls); |
| 28 // Must not be called for kInstanceCid. | 35 bool HasSubclasses(intptr_t cid); |
| 29 static ZoneGrowableArray<intptr_t>* GetSubclassIdsOf(intptr_t cid); | |
| 30 | 36 |
| 31 // Returns an array containing instance functions of the given name and | 37 // Return true if the class is implemented by some other class. |
| 32 // belonging to the classes given by their cids. | 38 bool IsImplemented(const Class& cls); |
| 33 // Cids must not contain kInstanceCid. | |
| 34 static ZoneGrowableArray<Function*>* GetNamedInstanceFunctionsOf( | |
| 35 const ZoneGrowableArray<intptr_t>& cids, | |
| 36 const String& function_name); | |
| 37 | |
| 38 // Returns an array of functions overriding the given function. | |
| 39 // Must not be called for a function of class Object. | |
| 40 static ZoneGrowableArray<Function*>* GetOverridesOf(const Function& function); | |
| 41 | 39 |
| 42 // Returns true if any subclass of 'cls' contains the function. | 40 // Returns true if any subclass of 'cls' contains the function. |
| 43 static bool HasOverride(const Class& cls, const String& function_name); | 41 bool HasOverride(const Class& cls, const String& function_name); |
| 42 |
| 43 const GrowableArray<Class*>& cha_classes() const { |
| 44 return cha_classes_; |
| 45 } |
| 46 |
| 47 private: |
| 48 void AddToCHAClasses(Class* cls); |
| 49 |
| 50 Isolate* isolate_; |
| 51 GrowableArray<Class*> cha_classes_; |
| 52 CHA* previous_; |
| 44 }; | 53 }; |
| 45 | 54 |
| 46 } // namespace dart | 55 } // namespace dart |
| 47 | 56 |
| 48 #endif // VM_CHA_H_ | 57 #endif // VM_CHA_H_ |
| OLD | NEW |