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 ValueObject { |
29 public: | 29 public: |
30 // Malformed types will not be tolerated when generating a snapshot. | |
30 enum { | 31 enum { |
31 kGeneratingSnapshot = true, | 32 kGeneratingSnapshot = true, |
hausner
2012/08/22 00:15:39
Shouldn't the constants be named for what they aff
regis
2012/08/22 02:24:26
Agreed. Note that the enum predated this cl. Also,
| |
32 kNotGeneratingSnapshot = false | 33 kNotGeneratingSnapshot = false |
33 }; | 34 }; |
34 | 35 explicit ClassFinalizer(bool generating_snapshot) |
hausner
2012/08/22 00:15:39
cf above. I would call this parameter "tolerate_ma
regis
2012/08/22 02:24:26
Would it be strange to check for native resolver o
| |
35 // Add 'interface' to 'interface_list' if it is not already in the list and | 36 : generating_snapshot_(generating_snapshot) { } |
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 | 37 |
45 // Modes for type resolution and finalization. The ordering is relevant. | 38 // Modes for type resolution and finalization. The ordering is relevant. |
46 enum FinalizationKind { | 39 enum FinalizationKind { |
47 kIgnore, // Parsed type is ignored and replaced by Dynamic. | 40 kIgnore, // Parsed type is ignored and replaced by Dynamic. |
48 kDoNotResolve, // Type resolution is postponed. | 41 kDoNotResolve, // Type resolution is postponed. |
49 kTryResolve, // Type resolution is attempted, but not required. | 42 kTryResolve, // Type resolution is attempted, but not required. |
50 kFinalize, // Type resolution and type finalization are | 43 kFinalize, // Type resolution and type finalization are |
51 // required; a malformed type is tolerated. | 44 // required; a malformed type is tolerated. |
52 kCanonicalize, // Same as kFinalize, but with canonicalization. | 45 kCanonicalize, // Same as kFinalize, but with canonicalization. |
53 kCanonicalizeWellFormed // Error-free resolution, finalization, and | 46 kCanonicalizeWellFormed // Error-free resolution, finalization, and |
54 // canonicalization are required; a malformed type | 47 // canonicalization are required; a malformed type |
55 // is not tolerated. | 48 // is not tolerated. |
56 }; | 49 }; |
57 | 50 |
58 // Finalize given type while parsing class cls. | 51 // Finalize given type while parsing class cls. |
59 // Also canonicalize type if applicable. | 52 // Also canonicalize type if applicable. |
60 static RawAbstractType* FinalizeType(const Class& cls, | 53 RawAbstractType* FinalizeType(const Class& cls, |
61 const AbstractType& type, | 54 const AbstractType& type, |
62 FinalizationKind finalization); | 55 FinalizationKind finalization) const; |
63 | 56 |
64 // Replace the malformed type with Dynamic and, depending on the given type | 57 // Replace the malformed type with Dynamic and, depending on the given type |
65 // finalization mode and execution mode, mark the type as malformed or report | 58 // finalization mode and execution mode, mark the type as malformed or report |
66 // a compile time error. Prepend prev_error if not null. | 59 // a compile time error. Prepend prev_error if not null. |
67 static void FinalizeMalformedType(const Error& prev_error, | 60 void FinalizeMalformedType(const Error& prev_error, |
68 const Class& cls, | 61 const Class& cls, |
69 const Type& type, | 62 const Type& type, |
70 FinalizationKind finalization, | 63 FinalizationKind finalization, |
71 const char* format, ...); | 64 const char* format, ...) const; |
72 | 65 |
73 // Return false if we still have classes pending to be finalized. | |
74 static bool AllClassesFinalized(); | |
75 | |
76 // Return whether class finalization failed. | |
77 // The function returns true if the finalization was successful. | 66 // The function returns true if the finalization was successful. |
78 // If finalization fails, an error message is set in the sticky error field | 67 // If finalization fails, an error message is set in the sticky error field |
79 // in the object store. | 68 // in the object store. |
80 static bool FinalizePendingClasses() { | 69 // Malformed types are tolerated or not, depending on the finalizer instance. |
81 return FinalizePendingClasses(kNotGeneratingSnapshot); | 70 bool FinalizePendingClasses() const; |
82 } | |
83 static bool FinalizePendingClassesForSnapshotCreation() { | |
84 return FinalizePendingClasses(kGeneratingSnapshot); | |
85 } | |
86 | 71 |
87 // Verify that the pending classes have been properly prefinalized. This is | 72 // Return false if we still have classes to be finalized. |
73 static bool AllClassesFinalized(); | |
74 | |
75 // Convenience function finalizing all pending classes when not generating a | |
76 // snapshot (malformed types are tolerated). | |
77 // The function returns true if the finalization was successful. | |
78 // If finalization fails, an error message is set in the sticky error field | |
79 // in the object store. | |
80 static bool FinalizeAllClasses(); | |
81 | |
82 // Verify that the classes have been properly prefinalized. This is | |
88 // needed during bootstrapping where the classes have been preloaded. | 83 // needed during bootstrapping where the classes have been preloaded. |
89 static void VerifyBootstrapClasses(); | 84 static void VerifyBootstrapClasses(); |
90 | 85 |
91 private: | 86 private: |
92 static bool FinalizePendingClasses(bool generating_snapshot); | 87 void FinalizeClass(const Class& cls) const; |
93 static void FinalizeClass(const Class& cls, bool generating_snapshot); | |
94 static bool IsSuperCycleFree(const Class& cls); | 88 static bool IsSuperCycleFree(const Class& cls); |
95 static bool IsAliasCycleFree(const Class& cls, | 89 bool IsAliasCycleFree(const Class& cls, |
96 GrowableArray<intptr_t>* visited); | 90 GrowableArray<intptr_t>* visited) const; |
97 static void CheckForLegalConstClass(const Class& cls); | 91 static void CheckForLegalConstClass(const Class& cls); |
98 static RawClass* ResolveClass(const Class& cls, | 92 static RawClass* ResolveClass(const Class& cls, |
99 const UnresolvedClass& unresolved_class); | 93 const UnresolvedClass& unresolved_class); |
100 static void ResolveSuperType(const Class& cls); | 94 void ResolveSuperType(const Class& cls) const; |
101 static void ResolveFactoryClass(const Class& cls); | 95 static void ResolveFactoryClass(const Class& cls); |
102 static void ResolveInterfaces(const Class& cls, | 96 void ResolveInterfaces(const Class& cls, |
103 GrowableArray<intptr_t>* visited); | 97 GrowableArray<intptr_t>* visited) const; |
104 static void FinalizeTypeParameters(const Class& cls); | 98 void FinalizeTypeParameters(const Class& cls) const; |
105 static void FinalizeTypeArguments(const Class& cls, | 99 void FinalizeTypeArguments(const Class& cls, |
106 const AbstractTypeArguments& arguments, | 100 const AbstractTypeArguments& arguments, |
107 FinalizationKind finalization); | 101 FinalizationKind finalization) const; |
108 static void ResolveType(const Class& cls, | 102 void ResolveType(const Class& cls, |
109 const AbstractType& type, | 103 const AbstractType& type, |
110 FinalizationKind finalization); | 104 FinalizationKind finalization) const; |
111 static void ResolveAndFinalizeUpperBounds(const Class& cls); | 105 void ResolveAndFinalizeUpperBounds(const Class& cls) const; |
112 static void ResolveAndFinalizeSignature(const Class& cls, | 106 void ResolveAndFinalizeSignature(const Class& cls, |
113 const Function& function); | 107 const Function& function) const; |
114 static void ResolveAndFinalizeMemberTypes(const Class& cls); | 108 void ResolveAndFinalizeMemberTypes(const Class& cls) const; |
115 static void PrintClassInformation(const Class& cls); | 109 static void PrintClassInformation(const Class& cls); |
116 static void VerifyClassImplements(const Class& cls); | |
117 static void CollectInterfaces(const Class& cls, | 110 static void CollectInterfaces(const Class& cls, |
118 const GrowableObjectArray& interfaces); | 111 const GrowableObjectArray& interfaces); |
119 static void ReportError(const Error& error); | 112 static void ReportError(const Error& error); |
120 static void ReportError(const Script& script, | 113 static void ReportError(const Script& script, |
121 intptr_t token_index, | 114 intptr_t token_index, |
122 const char* format, ...); | 115 const char* format, ...); |
123 static void ReportError(const char* format, ...); | 116 static void ReportError(const char* format, ...); |
117 | |
118 const bool generating_snapshot_; | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(ClassFinalizer); | |
124 }; | 121 }; |
125 | 122 |
126 } // namespace dart | 123 } // namespace dart |
127 | 124 |
128 #endif // VM_CLASS_FINALIZER_H_ | 125 #endif // VM_CLASS_FINALIZER_H_ |
OLD | NEW |