| 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 #include "vm/object.h" | 10 #include "vm/object.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 // Traverses all pending, unfinalized classes, validates and marks them as | 14 // Traverses all pending, unfinalized classes, validates and marks them as |
| 15 // finalized. | 15 // finalized. |
| 16 class ClassFinalizer : public AllStatic { | 16 class ClassFinalizer : public AllStatic { |
| 17 public: | 17 public: |
| 18 typedef ZoneGrowableHandlePtrArray<const AbstractType> PendingTypes; |
| 19 |
| 18 // Modes for type resolution and finalization. The ordering is relevant. | 20 // Modes for type resolution and finalization. The ordering is relevant. |
| 19 enum FinalizationKind { | 21 enum FinalizationKind { |
| 20 kIgnore, // Type is ignored and replaced by dynamic. | 22 kIgnore, // Type is ignored and replaced by dynamic. |
| 21 kDoNotResolve, // Type resolution is postponed. | 23 kDoNotResolve, // Type resolution is postponed. |
| 22 kResolveTypeParameters, // Resolve type parameters only. | 24 kResolveTypeParameters, // Resolve type parameters only. |
| 23 kFinalize, // Type resolution and finalization are required. | 25 kFinalize, // Type resolution and finalization are required. |
| 24 kCanonicalize, // Same as kFinalize, but with canonicalization. | 26 kCanonicalize, // Same as kFinalize, but with canonicalization. |
| 25 kCanonicalizeWellFormed // Error-free resolution, finalization, and | 27 kCanonicalizeWellFormed // Error-free resolution, finalization, and |
| 26 // canonicalization are required. | 28 // canonicalization are required. |
| 27 }; | 29 }; |
| 28 | 30 |
| 29 // Finalize given type while parsing class cls. | 31 // Finalize given type while parsing class cls. |
| 30 // Also canonicalize type if applicable. | 32 // Also canonicalize type if applicable. |
| 31 static RawAbstractType* FinalizeType( | 33 static RawAbstractType* FinalizeType( |
| 32 const Class& cls, | 34 const Class& cls, |
| 33 const AbstractType& type, | 35 const AbstractType& type, |
| 34 FinalizationKind finalization, | 36 FinalizationKind finalization, |
| 35 GrowableObjectArray* pending_types = NULL); | 37 PendingTypes* pending_types = NULL); |
| 36 | 38 |
| 37 // Allocate, finalize, and return a new malformed type as if it was declared | 39 // Allocate, finalize, and return a new malformed type as if it was declared |
| 38 // in class cls at the given token position. | 40 // in class cls at the given token position. |
| 39 // If not null, prepend prev_error to the error message built from the format | 41 // If not null, prepend prev_error to the error message built from the format |
| 40 // string and its arguments. | 42 // string and its arguments. |
| 41 static RawType* NewFinalizedMalformedType(const Error& prev_error, | 43 static RawType* NewFinalizedMalformedType(const Error& prev_error, |
| 42 const Script& script, | 44 const Script& script, |
| 43 intptr_t type_pos, | 45 intptr_t type_pos, |
| 44 const char* format, ...) | 46 const char* format, ...) |
| 45 PRINTF_ATTRIBUTE(4, 5); | 47 PRINTF_ATTRIBUTE(4, 5); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 90 |
| 89 // Resolve the class of the type, but not the type's type arguments. | 91 // Resolve the class of the type, but not the type's type arguments. |
| 90 static void ResolveTypeClass(const Class& cls, const AbstractType& type); | 92 static void ResolveTypeClass(const Class& cls, const AbstractType& type); |
| 91 | 93 |
| 92 // Resolve the type and target of the redirecting factory. | 94 // Resolve the type and target of the redirecting factory. |
| 93 static void ResolveRedirectingFactory(const Class& cls, | 95 static void ResolveRedirectingFactory(const Class& cls, |
| 94 const Function& factory); | 96 const Function& factory); |
| 95 | 97 |
| 96 // Apply the mixin type to the mixin application class. | 98 // Apply the mixin type to the mixin application class. |
| 97 static void ApplyMixinType(const Class& mixin_app_class, | 99 static void ApplyMixinType(const Class& mixin_app_class, |
| 98 GrowableObjectArray* pending_types = NULL); | 100 PendingTypes* pending_types = NULL); |
| 99 | 101 |
| 100 private: | 102 private: |
| 101 static void AllocateEnumValues(const Class& enum_cls); | 103 static void AllocateEnumValues(const Class& enum_cls); |
| 102 static bool IsSuperCycleFree(const Class& cls); | 104 static bool IsSuperCycleFree(const Class& cls); |
| 103 static bool IsTypeCycleFree(const Class& cls, | 105 static bool IsTypeCycleFree(const Class& cls, |
| 104 const AbstractType& type, | 106 const AbstractType& type, |
| 105 GrowableArray<intptr_t>* visited); | 107 GrowableArray<intptr_t>* visited); |
| 106 static bool IsAliasCycleFree(const Class& cls, | 108 static bool IsAliasCycleFree(const Class& cls, |
| 107 GrowableArray<intptr_t>* visited); | 109 GrowableArray<intptr_t>* visited); |
| 108 static bool IsMixinCycleFree(const Class& cls, | 110 static bool IsMixinCycleFree(const Class& cls, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 123 const Class& mixin_app, | 125 const Class& mixin_app, |
| 124 const GrowableObjectArray& cloned_funcs); | 126 const GrowableObjectArray& cloned_funcs); |
| 125 static void CollectTypeArguments(const Class& cls, | 127 static void CollectTypeArguments(const Class& cls, |
| 126 const Type& type, | 128 const Type& type, |
| 127 const GrowableObjectArray& collected_args); | 129 const GrowableObjectArray& collected_args); |
| 128 static RawType* ResolveMixinAppType(const Class& cls, | 130 static RawType* ResolveMixinAppType(const Class& cls, |
| 129 const MixinAppType& mixin_app_type); | 131 const MixinAppType& mixin_app_type); |
| 130 static void ResolveSuperTypeAndInterfaces(const Class& cls, | 132 static void ResolveSuperTypeAndInterfaces(const Class& cls, |
| 131 GrowableArray<intptr_t>* visited); | 133 GrowableArray<intptr_t>* visited); |
| 132 static void FinalizeTypeParameters(const Class& cls, | 134 static void FinalizeTypeParameters(const Class& cls, |
| 133 GrowableObjectArray* pending_types = NULL); | 135 PendingTypes* pending_types = NULL); |
| 134 static void FinalizeTypeArguments(const Class& cls, | 136 static void FinalizeTypeArguments(const Class& cls, |
| 135 const TypeArguments& arguments, | 137 const TypeArguments& arguments, |
| 136 intptr_t num_uninitialized_arguments, | 138 intptr_t num_uninitialized_arguments, |
| 137 Error* bound_error, | 139 Error* bound_error, |
| 138 GrowableObjectArray* pending_types, | 140 PendingTypes* pending_types, |
| 139 TrailPtr trail); | 141 TrailPtr trail); |
| 140 static void CheckRecursiveType(const Class& cls, | 142 static void CheckRecursiveType(const Class& cls, |
| 141 const Type& type, | 143 const Type& type, |
| 142 GrowableObjectArray* pending_types); | 144 PendingTypes* pending_types); |
| 143 static void CheckTypeBounds(const Class& cls, const Type& type); | 145 static void CheckTypeBounds(const Class& cls, const Type& type); |
| 144 static void CheckTypeArgumentBounds(const Class& cls, | 146 static void CheckTypeArgumentBounds(const Class& cls, |
| 145 const TypeArguments& arguments, | 147 const TypeArguments& arguments, |
| 146 Error* bound_error); | 148 Error* bound_error); |
| 147 static void ResolveUpperBounds(const Class& cls); | 149 static void ResolveUpperBounds(const Class& cls); |
| 148 static void FinalizeUpperBounds(const Class& cls); | 150 static void FinalizeUpperBounds(const Class& cls); |
| 149 static void ResolveAndFinalizeSignature(const Class& cls, | 151 static void ResolveAndFinalizeSignature(const Class& cls, |
| 150 const Function& function); | 152 const Function& function); |
| 151 static void ResolveAndFinalizeMemberTypes(const Class& cls); | 153 static void ResolveAndFinalizeMemberTypes(const Class& cls); |
| 152 static void PrintClassInformation(const Class& cls); | 154 static void PrintClassInformation(const Class& cls); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 168 const char* format, ...) PRINTF_ATTRIBUTE(4, 5); | 170 const char* format, ...) PRINTF_ATTRIBUTE(4, 5); |
| 169 | 171 |
| 170 // Verify implicit offsets recorded in the VM for direct access to fields of | 172 // Verify implicit offsets recorded in the VM for direct access to fields of |
| 171 // Dart instances (e.g: _TypedListView, _ByteDataView). | 173 // Dart instances (e.g: _TypedListView, _ByteDataView). |
| 172 static void VerifyImplicitFieldOffsets(); | 174 static void VerifyImplicitFieldOffsets(); |
| 173 }; | 175 }; |
| 174 | 176 |
| 175 } // namespace dart | 177 } // namespace dart |
| 176 | 178 |
| 177 #endif // VM_CLASS_FINALIZER_H_ | 179 #endif // VM_CLASS_FINALIZER_H_ |
| OLD | NEW |