| 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 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 // We do this after marking this type as finalized in order to allow a | 1266 // We do this after marking this type as finalized in order to allow a |
| 1267 // typedef function type to refer to itself via its parameter types and | 1267 // typedef function type to refer to itself via its parameter types and |
| 1268 // result type. | 1268 // result type. |
| 1269 if (type.IsFunctionType()) { | 1269 if (type.IsFunctionType()) { |
| 1270 const Type& fun_type = Type::Cast(type); | 1270 const Type& fun_type = Type::Cast(type); |
| 1271 const Class& scope_class = Class::Handle(zone, fun_type.type_class()); | 1271 const Class& scope_class = Class::Handle(zone, fun_type.type_class()); |
| 1272 if (scope_class.IsTypedefClass()) { | 1272 if (scope_class.IsTypedefClass()) { |
| 1273 Function& signature = | 1273 Function& signature = |
| 1274 Function::Handle(zone, scope_class.signature_function()); | 1274 Function::Handle(zone, scope_class.signature_function()); |
| 1275 if (!scope_class.is_type_finalized()) { | 1275 if (!scope_class.is_type_finalized()) { |
| 1276 FinalizeSignature(scope_class, signature); | 1276 FinalizeSignature(scope_class, signature, finalization); |
| 1277 } | 1277 } |
| 1278 // If the function type is a generic typedef, instantiate its signature | 1278 // If the function type is a generic typedef, instantiate its signature |
| 1279 // from its type arguments. | 1279 // from its type arguments. |
| 1280 // Example: typedef F<T> = S Function<S>(T x) has uninstantiated | 1280 // Example: typedef F<T> = S Function<S>(T x) has uninstantiated |
| 1281 // signature (T x) => S. | 1281 // signature (T x) => S. |
| 1282 // The instantiated signature of F(int) becomes (int x) => S. | 1282 // The instantiated signature of F(int) becomes (int x) => S. |
| 1283 // Note that after this step, the signature of the function type is not | 1283 // Note that after this step, the signature of the function type is not |
| 1284 // identical to the canonical signature of the typedef class anymore. | 1284 // identical to the canonical signature of the typedef class anymore. |
| 1285 if (scope_class.IsGeneric() && !signature.HasInstantiatedSignature()) { | 1285 if (scope_class.IsGeneric() && !signature.HasInstantiatedSignature()) { |
| 1286 if (FLAG_trace_type_finalization) { | 1286 if (FLAG_trace_type_finalization) { |
| 1287 THR_Print("Instantiating signature '%s' of typedef '%s'\n", | 1287 THR_Print("Instantiating signature '%s' of typedef '%s'\n", |
| 1288 String::Handle(zone, signature.Signature()).ToCString(), | 1288 String::Handle(zone, signature.Signature()).ToCString(), |
| 1289 String::Handle(zone, fun_type.Name()).ToCString()); | 1289 String::Handle(zone, fun_type.Name()).ToCString()); |
| 1290 } | 1290 } |
| 1291 const TypeArguments& instantiator_type_arguments = | 1291 const TypeArguments& instantiator_type_arguments = |
| 1292 TypeArguments::Handle(zone, fun_type.arguments()); | 1292 TypeArguments::Handle(zone, fun_type.arguments()); |
| 1293 const TypeArguments& function_type_arguments = | 1293 const TypeArguments& function_type_arguments = |
| 1294 TypeArguments::Handle(zone, signature.type_parameters()); | 1294 TypeArguments::Handle(zone, signature.type_parameters()); |
| 1295 signature = signature.InstantiateSignatureFrom( | 1295 signature = signature.InstantiateSignatureFrom( |
| 1296 instantiator_type_arguments, function_type_arguments, Heap::kOld); | 1296 instantiator_type_arguments, function_type_arguments, Heap::kOld); |
| 1297 // Note that if instantiator_type_arguments contains type parameters, | 1297 // Note that if instantiator_type_arguments contains type parameters, |
| 1298 // as in F<K>, the signature is still uninstantiated (the typedef type | 1298 // as in F<K>, the signature is still uninstantiated (the typedef type |
| 1299 // parameters were substituted in the signature with typedef type | 1299 // parameters were substituted in the signature with typedef type |
| 1300 // arguments). Note also that the function type parameters were not | 1300 // arguments). Note also that the function type parameters were not |
| 1301 // modified. | 1301 // modified. |
| 1302 FinalizeSignature(scope_class, signature); // Canonicalize signature. | 1302 FinalizeSignature(scope_class, signature, finalization); |
| 1303 } | 1303 } |
| 1304 fun_type.set_signature(signature); | 1304 fun_type.set_signature(signature); |
| 1305 } else { | 1305 } else { |
| 1306 FinalizeSignature(cls, Function::Handle(zone, fun_type.signature())); | 1306 FinalizeSignature(cls, Function::Handle(zone, fun_type.signature()), |
| 1307 finalization); |
| 1307 } | 1308 } |
| 1308 } | 1309 } |
| 1309 | 1310 |
| 1310 if (FLAG_trace_type_finalization) { | 1311 if (FLAG_trace_type_finalization) { |
| 1311 THR_Print("Marking type '%s' as finalized for class '%s'\n", | 1312 THR_Print("Marking type '%s' as finalized for class '%s'\n", |
| 1312 String::Handle(zone, type.Name()).ToCString(), | 1313 String::Handle(zone, type.Name()).ToCString(), |
| 1313 String::Handle(zone, cls.Name()).ToCString()); | 1314 String::Handle(zone, cls.Name()).ToCString()); |
| 1314 } | 1315 } |
| 1315 // Mark the type as finalized. | 1316 // Mark the type as finalized. |
| 1316 type.SetIsFinalized(); | 1317 type.SetIsFinalized(); |
| (...skipping 2493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3810 ProgramVisitor::VisitFunctions(&function_visitor); | 3811 ProgramVisitor::VisitFunctions(&function_visitor); |
| 3811 | 3812 |
| 3812 class ClearCodeClassVisitor : public ClassVisitor { | 3813 class ClearCodeClassVisitor : public ClassVisitor { |
| 3813 void Visit(const Class& cls) { cls.DisableAllocationStub(); } | 3814 void Visit(const Class& cls) { cls.DisableAllocationStub(); } |
| 3814 }; | 3815 }; |
| 3815 ClearCodeClassVisitor class_visitor; | 3816 ClearCodeClassVisitor class_visitor; |
| 3816 ProgramVisitor::VisitClasses(&class_visitor); | 3817 ProgramVisitor::VisitClasses(&class_visitor); |
| 3817 } | 3818 } |
| 3818 | 3819 |
| 3819 } // namespace dart | 3820 } // namespace dart |
| OLD | NEW |