| 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_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 AbstractType; | 13 class AbstractType; |
| 14 class AbstractTypeArguments; | 14 class AbstractTypeArguments; |
| 15 class Class; | 15 class Class; |
| 16 class Error; | 16 class Error; |
| 17 class Function; | 17 class Function; |
| 18 class GrowableObjectArray; | 18 class GrowableObjectArray; |
| 19 class RawAbstractType; | 19 class RawAbstractType; |
| 20 class RawClass; | 20 class RawClass; |
| 21 class RawType; | 21 class RawType; |
| 22 class Script; | 22 class Script; |
| 23 class Type; | 23 class Type; |
| 24 class UnresolvedClass; | 24 class UnresolvedClass; |
| 25 | 25 |
| 26 // Traverses all pending, unfinalized classes, validates and marks them as | 26 // Traverses all pending, unfinalized classes, validates and marks them as |
| 27 // finalized. | 27 // finalized. |
| 28 class ClassFinalizer : public AllStatic { | 28 class ClassFinalizer : public AllStatic { |
| 29 public: | 29 public: |
| 30 enum { | |
| 31 kGeneratingSnapshot = true, | |
| 32 kNotGeneratingSnapshot = false | |
| 33 }; | |
| 34 | |
| 35 // Add 'interface' to 'interface_list' if it is not already in the list and | |
| 36 // return true. Also return true if 'interface' is not added, because it is | |
| 37 // not unique, i.e. it is already in the list. | |
| 38 // Return false if 'interface' conflicts with an interface already in the list | |
| 39 // with the same class, but different type arguments. | |
| 40 // In the case of a conflict, set 'conflicting' to the existing interface. | |
| 41 static bool AddInterfaceIfUnique(const GrowableObjectArray& interface_list, | |
| 42 const AbstractType& interface, | |
| 43 AbstractType* conflicting); | |
| 44 | |
| 45 // Modes for type resolution and finalization. The ordering is relevant. | 30 // Modes for type resolution and finalization. The ordering is relevant. |
| 46 enum FinalizationKind { | 31 enum FinalizationKind { |
| 47 kIgnore, // Parsed type is ignored and replaced by Dynamic. | 32 kIgnore, // Parsed type is ignored and replaced by Dynamic. |
| 48 kDoNotResolve, // Type resolution is postponed. | 33 kDoNotResolve, // Type resolution is postponed. |
| 49 kTryResolve, // Type resolution is attempted, but not required. | 34 kTryResolve, // Type resolution is attempted, but not required. |
| 50 kFinalize, // Type resolution and type finalization are | 35 kFinalize, // Type resolution and type finalization are |
| 51 // required; a malformed type is tolerated. | 36 // required; a malformed type is tolerated. |
| 52 kCanonicalize, // Same as kFinalize, but with canonicalization. | 37 kCanonicalize, // Same as kFinalize, but with canonicalization. |
| 53 kCanonicalizeWellFormed // Error-free resolution, finalization, and | 38 kCanonicalizeWellFormed // Error-free resolution, finalization, and |
| 54 // canonicalization are required; a malformed type | 39 // canonicalization are required; a malformed type |
| (...skipping 15 matching lines...) Expand all Loading... |
| 70 FinalizationKind finalization, | 55 FinalizationKind finalization, |
| 71 const char* format, ...); | 56 const char* format, ...); |
| 72 | 57 |
| 73 // Return false if we still have classes pending to be finalized. | 58 // Return false if we still have classes pending to be finalized. |
| 74 static bool AllClassesFinalized(); | 59 static bool AllClassesFinalized(); |
| 75 | 60 |
| 76 // Return whether class finalization failed. | 61 // Return whether class finalization failed. |
| 77 // The function returns true if the finalization was successful. | 62 // The function returns true if the finalization was successful. |
| 78 // If finalization fails, an error message is set in the sticky error field | 63 // If finalization fails, an error message is set in the sticky error field |
| 79 // in the object store. | 64 // in the object store. |
| 80 static bool FinalizePendingClasses() { | 65 static bool FinalizePendingClasses(); |
| 81 return FinalizePendingClasses(kNotGeneratingSnapshot); | |
| 82 } | |
| 83 static bool FinalizePendingClassesForSnapshotCreation() { | |
| 84 return FinalizePendingClasses(kGeneratingSnapshot); | |
| 85 } | |
| 86 | 66 |
| 87 // Verify that the pending classes have been properly prefinalized. This is | 67 |
| 68 // Verify that the classes have been properly prefinalized. This is |
| 88 // needed during bootstrapping where the classes have been preloaded. | 69 // needed during bootstrapping where the classes have been preloaded. |
| 89 static void VerifyBootstrapClasses(); | 70 static void VerifyBootstrapClasses(); |
| 90 | 71 |
| 91 private: | 72 private: |
| 92 static bool FinalizePendingClasses(bool generating_snapshot); | 73 static void FinalizeClass(const Class& cls); |
| 93 static void FinalizeClass(const Class& cls, bool generating_snapshot); | |
| 94 static bool IsSuperCycleFree(const Class& cls); | 74 static bool IsSuperCycleFree(const Class& cls); |
| 95 static bool IsAliasCycleFree(const Class& cls, | 75 static bool IsAliasCycleFree(const Class& cls, |
| 96 GrowableArray<intptr_t>* visited); | 76 GrowableArray<intptr_t>* visited); |
| 97 static void CheckForLegalConstClass(const Class& cls); | 77 static void CheckForLegalConstClass(const Class& cls); |
| 98 static RawClass* ResolveClass(const Class& cls, | 78 static RawClass* ResolveClass(const Class& cls, |
| 99 const UnresolvedClass& unresolved_class); | 79 const UnresolvedClass& unresolved_class); |
| 100 static void ResolveSuperType(const Class& cls); | 80 static void ResolveSuperType(const Class& cls); |
| 101 static void ResolveFactoryClass(const Class& cls); | 81 static void ResolveFactoryClass(const Class& cls); |
| 102 static void ResolveInterfaces(const Class& cls, | 82 static void ResolveInterfaces(const Class& cls, |
| 103 GrowableArray<intptr_t>* visited); | 83 GrowableArray<intptr_t>* visited); |
| 104 static void FinalizeTypeParameters(const Class& cls); | 84 static void FinalizeTypeParameters(const Class& cls); |
| 105 static void FinalizeTypeArguments(const Class& cls, | 85 static void FinalizeTypeArguments(const Class& cls, |
| 106 const AbstractTypeArguments& arguments, | 86 const AbstractTypeArguments& arguments, |
| 107 FinalizationKind finalization); | 87 FinalizationKind finalization); |
| 108 static void ResolveType(const Class& cls, | 88 static void ResolveType(const Class& cls, |
| 109 const AbstractType& type, | 89 const AbstractType& type, |
| 110 FinalizationKind finalization); | 90 FinalizationKind finalization); |
| 111 static void ResolveAndFinalizeUpperBounds(const Class& cls); | 91 static void ResolveAndFinalizeUpperBounds(const Class& cls); |
| 112 static void ResolveAndFinalizeSignature(const Class& cls, | 92 static void ResolveAndFinalizeSignature(const Class& cls, |
| 113 const Function& function); | 93 const Function& function); |
| 114 static void ResolveAndFinalizeMemberTypes(const Class& cls); | 94 static void ResolveAndFinalizeMemberTypes(const Class& cls); |
| 115 static void PrintClassInformation(const Class& cls); | 95 static void PrintClassInformation(const Class& cls); |
| 116 static void VerifyClassImplements(const Class& cls); | |
| 117 static void CollectInterfaces(const Class& cls, | 96 static void CollectInterfaces(const Class& cls, |
| 118 const GrowableObjectArray& interfaces); | 97 const GrowableObjectArray& interfaces); |
| 119 static void ReportError(const Error& error); | 98 static void ReportError(const Error& error); |
| 120 static void ReportError(const Script& script, | 99 static void ReportError(const Script& script, |
| 121 intptr_t token_index, | 100 intptr_t token_index, |
| 122 const char* format, ...); | 101 const char* format, ...); |
| 123 static void ReportError(const char* format, ...); | 102 static void ReportError(const char* format, ...); |
| 124 }; | 103 }; |
| 125 | 104 |
| 126 } // namespace dart | 105 } // namespace dart |
| 127 | 106 |
| 128 #endif // VM_CLASS_FINALIZER_H_ | 107 #endif // VM_CLASS_FINALIZER_H_ |
| OLD | NEW |