| 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 RUNTIME_VM_CLASS_FINALIZER_H_ | 5 #ifndef RUNTIME_VM_CLASS_FINALIZER_H_ |
| 6 #define RUNTIME_VM_CLASS_FINALIZER_H_ | 6 #define RUNTIME_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; | 18 typedef ZoneGrowableHandlePtrArray<const AbstractType> PendingTypes; |
| 19 | 19 |
| 20 // Modes for type resolution and finalization. The ordering is relevant. | 20 // Modes for type resolution and finalization. The ordering is relevant. |
| 21 enum FinalizationKind { | 21 enum FinalizationKind { |
| 22 kIgnore, // Type is ignored and replaced by dynamic. | 22 kIgnore, // Type is ignored and replaced by dynamic. |
| 23 kDoNotResolve, // Type resolution is postponed. | 23 kDoNotResolve, // Type resolution is postponed. |
| 24 kResolveTypeParameters, // Resolve type parameters only. | 24 kResolveTypeParameters, // Resolve type parameters only. |
| 25 kFinalize, // Type resolution and finalization are required. | 25 kFinalize, // Type resolution and finalization are required. |
| 26 kCanonicalize, // Same as kFinalize, but with canonicalization. | 26 kCanonicalize, // Same as kFinalize, but with canonicalization. |
| 27 kCanonicalizeWellFormed // Error-free resolution, finalization, and | 27 kCanonicalizeWellFormed // Error-free resolution, finalization, and |
| 28 // canonicalization are required. | 28 // canonicalization are required. |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 // Finalize given type while parsing class cls. | 31 // Finalize given type while parsing class cls. |
| 32 // Also canonicalize type if applicable. | 32 // Also canonicalize type if applicable. |
| 33 static RawAbstractType* FinalizeType( | 33 static RawAbstractType* FinalizeType(const Class& cls, |
| 34 const Class& cls, | 34 const AbstractType& type, |
| 35 const AbstractType& type, | 35 FinalizationKind finalization, |
| 36 FinalizationKind finalization, | 36 PendingTypes* pending_types = NULL); |
| 37 PendingTypes* pending_types = NULL); | |
| 38 | 37 |
| 39 // Allocate, finalize, and return a new malformed type as if it was declared | 38 // Allocate, finalize, and return a new malformed type as if it was declared |
| 40 // in class cls at the given token position. | 39 // in class cls at the given token position. |
| 41 // If not null, prepend prev_error to the error message built from the format | 40 // If not null, prepend prev_error to the error message built from the format |
| 42 // string and its arguments. | 41 // string and its arguments. |
| 43 static RawType* NewFinalizedMalformedType(const Error& prev_error, | 42 static RawType* NewFinalizedMalformedType(const Error& prev_error, |
| 44 const Script& script, | 43 const Script& script, |
| 45 TokenPosition type_pos, | 44 TokenPosition type_pos, |
| 46 const char* format, ...) | 45 const char* format, |
| 47 PRINTF_ATTRIBUTE(4, 5); | 46 ...) PRINTF_ATTRIBUTE(4, 5); |
| 48 | 47 |
| 49 // Mark the given type as malformed. | 48 // Mark the given type as malformed. |
| 50 // If not null, prepend prev_error to the error message built from the format | 49 // If not null, prepend prev_error to the error message built from the format |
| 51 // string and its arguments. | 50 // string and its arguments. |
| 52 static void FinalizeMalformedType(const Error& prev_error, | 51 static void FinalizeMalformedType(const Error& prev_error, |
| 53 const Script& script, | 52 const Script& script, |
| 54 const Type& type, | 53 const Type& type, |
| 55 const char* format, ...) | 54 const char* format, |
| 56 PRINTF_ATTRIBUTE(4, 5); | 55 ...) PRINTF_ATTRIBUTE(4, 5); |
| 57 | 56 |
| 58 // Mark the given type as malbounded. | 57 // Mark the given type as malbounded. |
| 59 // If not null, prepend prev_error to the error message built from the format | 58 // If not null, prepend prev_error to the error message built from the format |
| 60 // string and its arguments. | 59 // string and its arguments. |
| 61 static void FinalizeMalboundedType(const Error& prev_error, | 60 static void FinalizeMalboundedType(const Error& prev_error, |
| 62 const Script& script, | 61 const Script& script, |
| 63 const AbstractType& type, | 62 const AbstractType& type, |
| 64 const char* format, ...) | 63 const char* format, |
| 65 PRINTF_ATTRIBUTE(4, 5); | 64 ...) PRINTF_ATTRIBUTE(4, 5); |
| 66 | 65 |
| 67 // Return false if we still have classes pending to be finalized. | 66 // Return false if we still have classes pending to be finalized. |
| 68 static bool AllClassesFinalized(); | 67 static bool AllClassesFinalized(); |
| 69 | 68 |
| 70 // Return whether processing pending classes (ObjectStore::pending_classes_) | 69 // Return whether processing pending classes (ObjectStore::pending_classes_) |
| 71 // failed. The function returns true if the processing was successful. | 70 // failed. The function returns true if the processing was successful. |
| 72 // If processing fails, an error message is set in the sticky error field | 71 // If processing fails, an error message is set in the sticky error field |
| 73 // in the object store. | 72 // in the object store. |
| 74 static bool ProcessPendingClasses(); | 73 static bool ProcessPendingClasses(); |
| 75 | 74 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 static void CheckTypeArgumentBounds(const Class& cls, | 148 static void CheckTypeArgumentBounds(const Class& cls, |
| 150 const TypeArguments& arguments, | 149 const TypeArguments& arguments, |
| 151 Error* bound_error); | 150 Error* bound_error); |
| 152 static void ResolveUpperBounds(const Class& cls); | 151 static void ResolveUpperBounds(const Class& cls); |
| 153 static void FinalizeUpperBounds(const Class& cls, | 152 static void FinalizeUpperBounds(const Class& cls, |
| 154 FinalizationKind finalization); | 153 FinalizationKind finalization); |
| 155 static void ResolveSignature(const Class& cls, const Function& function); | 154 static void ResolveSignature(const Class& cls, const Function& function); |
| 156 static void FinalizeSignature(const Class& cls, const Function& function); | 155 static void FinalizeSignature(const Class& cls, const Function& function); |
| 157 static void ResolveAndFinalizeMemberTypes(const Class& cls); | 156 static void ResolveAndFinalizeMemberTypes(const Class& cls); |
| 158 static void PrintClassInformation(const Class& cls); | 157 static void PrintClassInformation(const Class& cls); |
| 159 static void CollectInterfaces( | 158 static void CollectInterfaces(const Class& cls, |
| 160 const Class& cls, GrowableArray<const Class*>* collected); | 159 GrowableArray<const Class*>* collected); |
| 161 | 160 |
| 162 static void MarkTypeMalformed(const Error& prev_error, | 161 static void MarkTypeMalformed(const Error& prev_error, |
| 163 const Script& script, | 162 const Script& script, |
| 164 const Type& type, | 163 const Type& type, |
| 165 const char* format, | 164 const char* format, |
| 166 va_list args); | 165 va_list args); |
| 167 static void ReportError(const Error& error); | 166 static void ReportError(const Error& error); |
| 168 static void ReportError(const Class& cls, | 167 static void ReportError(const Class& cls, |
| 169 TokenPosition token_pos, | 168 TokenPosition token_pos, |
| 170 const char* format, ...) PRINTF_ATTRIBUTE(3, 4); | 169 const char* format, |
| 170 ...) PRINTF_ATTRIBUTE(3, 4); |
| 171 static void ReportErrors(const Error& prev_error, | 171 static void ReportErrors(const Error& prev_error, |
| 172 const Class& cls, | 172 const Class& cls, |
| 173 TokenPosition token_pos, | 173 TokenPosition token_pos, |
| 174 const char* format, ...) PRINTF_ATTRIBUTE(4, 5); | 174 const char* format, |
| 175 ...) PRINTF_ATTRIBUTE(4, 5); |
| 175 | 176 |
| 176 // Verify implicit offsets recorded in the VM for direct access to fields of | 177 // Verify implicit offsets recorded in the VM for direct access to fields of |
| 177 // Dart instances (e.g: _TypedListView, _ByteDataView). | 178 // Dart instances (e.g: _TypedListView, _ByteDataView). |
| 178 static void VerifyImplicitFieldOffsets(); | 179 static void VerifyImplicitFieldOffsets(); |
| 179 }; | 180 }; |
| 180 | 181 |
| 181 } // namespace dart | 182 } // namespace dart |
| 182 | 183 |
| 183 #endif // RUNTIME_VM_CLASS_FINALIZER_H_ | 184 #endif // RUNTIME_VM_CLASS_FINALIZER_H_ |
| OLD | NEW |