| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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_CLASS_FINALIZER_H_ | 5 #ifndef VM_CLASS_FINALIZER_H_ |
| 6 #define VM_CLASS_FINALIZER_H_ | 6 #define VM_CLASS_FINALIZER_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/growable_array.h" | 9 #include "vm/growable_array.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 class Class; | 13 class Class; |
| 14 class Function; | 14 class Function; |
| 15 class RawClass; | |
| 16 class RawType; | 15 class RawType; |
| 17 class Script; | 16 class Script; |
| 18 class String; | 17 class String; |
| 19 class Type; | 18 class Type; |
| 20 class TypeArguments; | 19 class TypeArguments; |
| 21 class UnresolvedClass; | |
| 22 | 20 |
| 23 // Traverses all pending, unfinalized classes, validates and marks them as | 21 // Traverses all pending, unfinalized classes, validates and marks them as |
| 24 // finalized. | 22 // finalized. |
| 25 class ClassFinalizer : public AllStatic { | 23 class ClassFinalizer : public AllStatic { |
| 26 public: | 24 public: |
| 27 // Add 'interface' to 'interface_list' if it is not already in the list and | 25 // Add 'interface' to 'interface_list' if it is not already in the list and |
| 28 // return true. Also return true if 'interface' is not added, because it is | 26 // return true. Also return true if 'interface' is not added, because it is |
| 29 // not unique, i.e. it is already in the list. | 27 // not unique, i.e. it is already in the list. |
| 30 // Return false if 'interface' conflicts with an interface already in the list | 28 // Return false if 'interface' conflicts with an interface already in the list |
| 31 // with the same class, but different type arguments. | 29 // with the same class, but different type arguments. |
| 32 // In the case of a conflict, set 'conflicting' to the existing interface. | 30 // In the case of a conflict, set 'conflicting' to the existing interface. |
| 33 static bool AddInterfaceIfUnique(GrowableArray<Type*>* interface_list, | 31 static bool AddInterfaceIfUnique(GrowableArray<Type*>* interface_list, |
| 34 Type* interface, | 32 Type* interface, |
| 35 Type* conflicting); | 33 Type* conflicting); |
| 36 | 34 |
| 37 // Finalize and canonicalize type while parsing. | 35 // Finalize and canonicalize type while parsing. |
| 38 // Set the error message on failure (to String::null() if no error). | 36 // Set the error message on failure (to String::null() if no error). |
| 39 static RawType* FinalizeAndCanonicalizeType(const Type& type, String* errmsg); | 37 static RawType* FinalizeAndCanonicalizeType(const Type& type, String* errmsg); |
| 40 | 38 |
| 41 // Notify finalizer to expect classes to be finalized. | 39 // Pending classes are classes that need to be finalized. |
| 42 static void ExpectClassesToFinalize(); | 40 static void AddPendingClasses(const GrowableArray<const Class*>& classes); |
| 43 | 41 |
| 44 // Return true after a call to ExpectClassesToFinalize() and before a call to | 42 // Return false if we still have classes pending to be finalized. |
| 45 // FinalizeAllClasses(). | 43 static bool AllClassesFinalized(); |
| 46 static bool IsExpectingClassesToFinalize(); | |
| 47 | |
| 48 // Add given classes to the list of pending classes to be finalized. | |
| 49 // ExpectClassesToFinalize() must be called prior to AddClassesToFinalize(). | |
| 50 static void AddClassesToFinalize(const GrowableArray<const Class*>& classes); | |
| 51 | |
| 52 // Return false if we still have classes pending to be finalized or expecting | |
| 53 // more classes to be finalized. | |
| 54 static bool AllClassesFinalized() { return !IsExpectingClassesToFinalize(); } | |
| 55 | 44 |
| 56 // Return whether class finalization failed. | 45 // Return whether class finalization failed. |
| 57 // The function returns true if the finalization was successful. | 46 // The function returns true if the finalization was successful. |
| 58 // If finalization fails, an error message is set in the sticky error field | 47 // If finalization fails, an error message is set in the sticky error field |
| 59 // in the object store. | 48 // in the object store. |
| 60 static bool FinalizeAllClasses(); | 49 static bool FinalizePendingClasses(); |
| 61 | 50 |
| 62 // Verify that the pending classes have been properly prefinalized. This is | 51 // Verify that the pending classes have been properly prefinalized. This is |
| 63 // needed during bootstrapping where the classes have been preloaded. | 52 // needed during bootstrapping where the classes have been preloaded. |
| 64 static void VerifyBootstrapClasses(); | 53 static void VerifyBootstrapClasses(); |
| 65 | 54 |
| 66 private: | 55 private: |
| 67 static void FinalizeClass(const Class& cls); | 56 static void FinalizeClass(const Class& cls); |
| 68 static bool IsSuperCycleFree(const Class& cls); | 57 static bool IsSuperCycleFree(const Class& cls); |
| 69 static void CheckForLegalConstClass(const Class& cls); | 58 static void CheckForLegalConstClass(const Class& cls); |
| 70 static RawClass* ResolveClass(const Class& cls, | |
| 71 const UnresolvedClass& unresolved_class); | |
| 72 static void ResolveSuperClass(const Class& cls); | 59 static void ResolveSuperClass(const Class& cls); |
| 73 static void ResolveDefaultClass(const Class& cls); | 60 static void ResolveDefaultClass(const Class& cls); |
| 74 static void ResolveInterfaces(const Class& cls, | 61 static void ResolveInterfaces(const Class& cls, |
| 75 GrowableArray<const Class*>* visited); | 62 GrowableArray<const Class*>* visited); |
| 76 static void FinalizeTypeArguments(const Class& cls, | 63 static void FinalizeTypeArguments(const Class& cls, |
| 77 const TypeArguments& arguments); | 64 const TypeArguments& arguments); |
| 78 static RawType* ResolveType(const Class& cls, const Type& type); | 65 static RawType* ResolveType(const Class& cls, const Type& type); |
| 79 static RawType* FinalizeType(const Type& type); | 66 static RawType* FinalizeType(const Type& type); |
| 80 static void ResolveAndFinalizeUpperBounds(const Class& cls); | |
| 81 static void ResolveAndFinalizeSignature(const Class& cls, | 67 static void ResolveAndFinalizeSignature(const Class& cls, |
| 82 const Function& function); | 68 const Function& function); |
| 83 static void ResolveAndFinalizeMemberTypes(const Class& cls); | 69 static void ResolveAndFinalizeMemberTypes(const Class& cls); |
| 84 static void PrintClassInformation(const Class& cls); | 70 static void PrintClassInformation(const Class& cls); |
| 85 static void VerifyClassImplements(const Class& cls); | 71 static void VerifyClassImplements(const Class& cls); |
| 86 static void CollectInterfaces(const Class& cls, | 72 static void CollectInterfaces(const Class& cls, |
| 87 GrowableArray<const Class*>* interfaces); | 73 GrowableArray<const Class*>* interfaces); |
| 88 static void ReportError(const Script& script, | 74 static void ReportError(const Script& script, |
| 89 intptr_t token_index, | 75 intptr_t token_index, |
| 90 const char* format, ...); | 76 const char* format, ...); |
| 91 static void ReportError(const char* format, ...); | 77 static void ReportError(const char* format, ...); |
| 92 }; | 78 }; |
| 93 | 79 |
| 94 } // namespace dart | 80 } // namespace dart |
| 95 | 81 |
| 96 #endif // VM_CLASS_FINALIZER_H_ | 82 #endif // VM_CLASS_FINALIZER_H_ |
| OLD | NEW |