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 |
(...skipping 16 matching lines...) Expand all Loading... |
27 // Traverses all pending, unfinalized classes, validates and marks them as | 27 // Traverses all pending, unfinalized classes, validates and marks them as |
28 // finalized. | 28 // finalized. |
29 class ClassFinalizer : public AllStatic { | 29 class ClassFinalizer : public AllStatic { |
30 public: | 30 public: |
31 // Modes for type resolution and finalization. The ordering is relevant. | 31 // Modes for type resolution and finalization. The ordering is relevant. |
32 enum FinalizationKind { | 32 enum FinalizationKind { |
33 kIgnore, // Type is ignored and replaced by dynamic. | 33 kIgnore, // Type is ignored and replaced by dynamic. |
34 kDoNotResolve, // Type resolution is postponed. | 34 kDoNotResolve, // Type resolution is postponed. |
35 kResolveTypeParameters, // Resolve type parameters only. | 35 kResolveTypeParameters, // Resolve type parameters only. |
36 kFinalize, // Type resolution and type finalization are | 36 kFinalize, // Type resolution and type finalization are |
37 // required; a malformed type is tolerated, since | 37 // required; replace a malformed type by dynamic. |
38 // the type may be used as a type annotation. | |
39 kCanonicalize, // Same as kFinalize, but with canonicalization. | 38 kCanonicalize, // Same as kFinalize, but with canonicalization. |
40 kCanonicalizeExpression, // Same as kCanonicalize, but do not tolerate | |
41 // wrong number of type arguments or ambiguous | |
42 // type reference, since the type is not used as | |
43 // a type annotation, but as a type expression. | |
44 kCanonicalizeWellFormed // Error-free resolution, finalization, and | 39 kCanonicalizeWellFormed // Error-free resolution, finalization, and |
45 // canonicalization are required; a malformed | 40 // canonicalization are required; a malformed |
46 // type is not tolerated. | 41 // type is marked as such. |
47 }; | 42 }; |
48 | 43 |
49 // Finalize given type while parsing class cls. | 44 // Finalize given type while parsing class cls. |
50 // Also canonicalize type if applicable. | 45 // Also canonicalize type if applicable. |
51 static RawAbstractType* FinalizeType(const Class& cls, | 46 static RawAbstractType* FinalizeType(const Class& cls, |
52 const AbstractType& type, | 47 const AbstractType& type, |
53 FinalizationKind finalization); | 48 FinalizationKind finalization); |
54 | 49 |
55 // Allocate, finalize, and return a new malformed type as if it was declared | 50 // Allocate, finalize, and return a new malformed type as if it was declared |
56 // in class cls at the given token position. | 51 // in class cls at the given token position. |
57 // If not null, prepend prev_error to the error message built from the format | 52 // If not null, prepend prev_error to the error message built from the format |
58 // string and its arguments. | 53 // string and its arguments. |
59 static RawType* NewFinalizedMalformedType(const Error& prev_error, | 54 static RawType* NewFinalizedMalformedType(const Error& prev_error, |
60 const Class& cls, | 55 const Class& cls, |
61 intptr_t type_pos, | 56 intptr_t type_pos, |
62 FinalizationKind finalization, | |
63 const char* format, ...) | 57 const char* format, ...) |
64 PRINTF_ATTRIBUTE(5, 6); | 58 PRINTF_ATTRIBUTE(4, 5); |
65 | 59 |
66 // Depending on the given type, finalization mode, and execution mode, mark | 60 // Depending on the given type, finalization mode, and execution mode, mark |
67 // the given type as malformed or report a compile time error. | 61 // the given type as malformed or report a compile time error. |
68 // If not null, prepend prev_error to the error message built from the format | 62 // If not null, prepend prev_error to the error message built from the format |
69 // string and its arguments. | 63 // string and its arguments. |
70 static void FinalizeMalformedType(const Error& prev_error, | 64 static void FinalizeMalformedType(const Error& prev_error, |
71 const Class& cls, | 65 const Class& cls, |
72 const Type& type, | 66 const Type& type, |
73 FinalizationKind finalization, | |
74 const char* format, ...) | 67 const char* format, ...) |
75 PRINTF_ATTRIBUTE(5, 6); | 68 PRINTF_ATTRIBUTE(4, 5); |
76 | 69 |
77 // Return false if we still have classes pending to be finalized. | 70 // Return false if we still have classes pending to be finalized. |
78 static bool AllClassesFinalized(); | 71 static bool AllClassesFinalized(); |
79 | 72 |
80 // Return whether class finalization failed. | 73 // Return whether class finalization failed. |
81 // The function returns true if the finalization was successful. | 74 // The function returns true if the finalization was successful. |
82 // If finalization fails, an error message is set in the sticky error field | 75 // If finalization fails, an error message is set in the sticky error field |
83 // in the object store. | 76 // in the object store. |
84 static bool FinalizePendingClasses(); | 77 static bool FinalizePendingClasses(); |
85 | 78 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 static void FinalizeUpperBounds(const Class& cls); | 131 static void FinalizeUpperBounds(const Class& cls); |
139 static void ResolveAndFinalizeSignature(const Class& cls, | 132 static void ResolveAndFinalizeSignature(const Class& cls, |
140 const Function& function); | 133 const Function& function); |
141 static void ResolveAndFinalizeMemberTypes(const Class& cls); | 134 static void ResolveAndFinalizeMemberTypes(const Class& cls); |
142 static void PrintClassInformation(const Class& cls); | 135 static void PrintClassInformation(const Class& cls); |
143 static void CollectInterfaces(const Class& cls, | 136 static void CollectInterfaces(const Class& cls, |
144 const GrowableObjectArray& interfaces); | 137 const GrowableObjectArray& interfaces); |
145 static void ReportMalformedType(const Error& prev_error, | 138 static void ReportMalformedType(const Error& prev_error, |
146 const Class& cls, | 139 const Class& cls, |
147 const Type& type, | 140 const Type& type, |
148 FinalizationKind finalization, | |
149 const char* format, | 141 const char* format, |
150 va_list args); | 142 va_list args); |
151 static void ReportError(const Error& error); | 143 static void ReportError(const Error& error); |
152 static void ReportError(const Script& script, | 144 static void ReportError(const Script& script, |
153 intptr_t token_index, | 145 intptr_t token_index, |
154 const char* format, ...) PRINTF_ATTRIBUTE(3, 4); | 146 const char* format, ...) PRINTF_ATTRIBUTE(3, 4); |
155 static void ReportError(const char* format, ...) PRINTF_ATTRIBUTE(1, 2); | 147 static void ReportError(const char* format, ...) PRINTF_ATTRIBUTE(1, 2); |
156 | 148 |
157 // Verify implicit offsets recorded in the VM for direct access to fields of | 149 // Verify implicit offsets recorded in the VM for direct access to fields of |
158 // Dart instances (e.g: _TypedListView, _ByteDataView). | 150 // Dart instances (e.g: _TypedListView, _ByteDataView). |
159 static void VerifyImplicitFieldOffsets(); | 151 static void VerifyImplicitFieldOffsets(); |
160 }; | 152 }; |
161 | 153 |
162 } // namespace dart | 154 } // namespace dart |
163 | 155 |
164 #endif // VM_CLASS_FINALIZER_H_ | 156 #endif // VM_CLASS_FINALIZER_H_ |
OLD | NEW |