| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "vm/class_finalizer.h" | 5 #include "vm/class_finalizer.h" |
| 6 | 6 |
| 7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
| 8 #include "vm/hash_table.h" | 8 #include "vm/hash_table.h" |
| 9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 // We do this after marking this type as finalized in order to allow a | 1244 // We do this after marking this type as finalized in order to allow a |
| 1245 // typedef function type to refer to itself via its parameter types and | 1245 // typedef function type to refer to itself via its parameter types and |
| 1246 // result type. | 1246 // result type. |
| 1247 if (type.IsFunctionType()) { | 1247 if (type.IsFunctionType()) { |
| 1248 const Type& fun_type = Type::Cast(type); | 1248 const Type& fun_type = Type::Cast(type); |
| 1249 const Class& scope_class = Class::Handle(zone, fun_type.type_class()); | 1249 const Class& scope_class = Class::Handle(zone, fun_type.type_class()); |
| 1250 if (scope_class.IsTypedefClass()) { | 1250 if (scope_class.IsTypedefClass()) { |
| 1251 Function& signature = | 1251 Function& signature = |
| 1252 Function::Handle(zone, scope_class.signature_function()); | 1252 Function::Handle(zone, scope_class.signature_function()); |
| 1253 if (!scope_class.is_type_finalized()) { | 1253 if (!scope_class.is_type_finalized()) { |
| 1254 FinalizeSignature(scope_class, signature); | 1254 FinalizeSignature(scope_class, signature, finalization); |
| 1255 } | 1255 } |
| 1256 // If the function type is a generic typedef, instantiate its signature | 1256 // If the function type is a generic typedef, instantiate its signature |
| 1257 // from its type arguments. | 1257 // from its type arguments. |
| 1258 // Example: typedef F<T> = S Function<S>(T x) has uninstantiated | 1258 // Example: typedef F<T> = S Function<S>(T x) has uninstantiated |
| 1259 // signature (T x) => S. | 1259 // signature (T x) => S. |
| 1260 // The instantiated signature of F(int) becomes (int x) => S. | 1260 // The instantiated signature of F(int) becomes (int x) => S. |
| 1261 // Note that after this step, the signature of the function type is not | 1261 // Note that after this step, the signature of the function type is not |
| 1262 // identical to the canonical signature of the typedef class anymore. | 1262 // identical to the canonical signature of the typedef class anymore. |
| 1263 if (scope_class.IsGeneric() && !signature.HasInstantiatedSignature()) { | 1263 if (scope_class.IsGeneric() && !signature.HasInstantiatedSignature()) { |
| 1264 if (FLAG_trace_type_finalization) { | 1264 if (FLAG_trace_type_finalization) { |
| 1265 THR_Print("Instantiating signature '%s' of typedef '%s'\n", | 1265 THR_Print("Instantiating signature '%s' of typedef '%s'\n", |
| 1266 String::Handle(zone, signature.Signature()).ToCString(), | 1266 String::Handle(zone, signature.Signature()).ToCString(), |
| 1267 String::Handle(zone, fun_type.Name()).ToCString()); | 1267 String::Handle(zone, fun_type.Name()).ToCString()); |
| 1268 } | 1268 } |
| 1269 const TypeArguments& instantiator_type_arguments = | 1269 const TypeArguments& instantiator_type_arguments = |
| 1270 TypeArguments::Handle(zone, fun_type.arguments()); | 1270 TypeArguments::Handle(zone, fun_type.arguments()); |
| 1271 const TypeArguments& function_type_arguments = | 1271 const TypeArguments& function_type_arguments = |
| 1272 TypeArguments::Handle(zone, signature.type_parameters()); | 1272 TypeArguments::Handle(zone, signature.type_parameters()); |
| 1273 signature = signature.InstantiateSignatureFrom( | 1273 signature = signature.InstantiateSignatureFrom( |
| 1274 instantiator_type_arguments, function_type_arguments, Heap::kOld); | 1274 instantiator_type_arguments, function_type_arguments, Heap::kOld); |
| 1275 // Note that if instantiator_type_arguments contains type parameters, | 1275 // Note that if instantiator_type_arguments contains type parameters, |
| 1276 // as in F<K>, the signature is still uninstantiated (the typedef type | 1276 // as in F<K>, the signature is still uninstantiated (the typedef type |
| 1277 // parameters were substituted in the signature with typedef type | 1277 // parameters were substituted in the signature with typedef type |
| 1278 // arguments). Note also that the function type parameters were not | 1278 // arguments). Note also that the function type parameters were not |
| 1279 // modified. | 1279 // modified. |
| 1280 FinalizeSignature(scope_class, signature); // Canonicalize signature. | 1280 FinalizeSignature(scope_class, signature, finalization); |
| 1281 } | 1281 } |
| 1282 fun_type.set_signature(signature); | 1282 fun_type.set_signature(signature); |
| 1283 } else { | 1283 } else { |
| 1284 FinalizeSignature(cls, Function::Handle(zone, fun_type.signature())); | 1284 FinalizeSignature(cls, Function::Handle(zone, fun_type.signature()), |
| 1285 finalization); |
| 1285 } | 1286 } |
| 1286 } | 1287 } |
| 1287 | 1288 |
| 1288 if (FLAG_trace_type_finalization) { | 1289 if (FLAG_trace_type_finalization) { |
| 1289 THR_Print("Marking type '%s' as finalized for class '%s'\n", | 1290 THR_Print("Marking type '%s' as finalized for class '%s'\n", |
| 1290 String::Handle(zone, type.Name()).ToCString(), | 1291 String::Handle(zone, type.Name()).ToCString(), |
| 1291 String::Handle(zone, cls.Name()).ToCString()); | 1292 String::Handle(zone, cls.Name()).ToCString()); |
| 1292 } | 1293 } |
| 1293 // Mark the type as finalized. | 1294 // Mark the type as finalized. |
| 1294 type.SetIsFinalized(); | 1295 type.SetIsFinalized(); |
| (...skipping 2457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3752 ProgramVisitor::VisitFunctions(&function_visitor); | 3753 ProgramVisitor::VisitFunctions(&function_visitor); |
| 3753 | 3754 |
| 3754 class ClearCodeClassVisitor : public ClassVisitor { | 3755 class ClearCodeClassVisitor : public ClassVisitor { |
| 3755 void Visit(const Class& cls) { cls.DisableAllocationStub(); } | 3756 void Visit(const Class& cls) { cls.DisableAllocationStub(); } |
| 3756 }; | 3757 }; |
| 3757 ClearCodeClassVisitor class_visitor; | 3758 ClearCodeClassVisitor class_visitor; |
| 3758 ProgramVisitor::VisitClasses(&class_visitor); | 3759 ProgramVisitor::VisitClasses(&class_visitor); |
| 3759 } | 3760 } |
| 3760 | 3761 |
| 3761 } // namespace dart | 3762 } // namespace dart |
| OLD | NEW |