| 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/code_generator.h" | 7 #include "vm/code_generator.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 const intptr_t num_arguments = arguments.Length(); | 542 const intptr_t num_arguments = arguments.Length(); |
| 543 AbstractType& type_argument = AbstractType::Handle(); | 543 AbstractType& type_argument = AbstractType::Handle(); |
| 544 for (intptr_t i = 0; i < num_arguments; i++) { | 544 for (intptr_t i = 0; i < num_arguments; i++) { |
| 545 type_argument = arguments.TypeAt(i); | 545 type_argument = arguments.TypeAt(i); |
| 546 ResolveType(cls, type_argument); | 546 ResolveType(cls, type_argument); |
| 547 } | 547 } |
| 548 } | 548 } |
| 549 // Resolve signature if function type. | 549 // Resolve signature if function type. |
| 550 if (type.IsFunctionType()) { | 550 if (type.IsFunctionType()) { |
| 551 const Function& signature = Function::Handle(Type::Cast(type).signature()); | 551 const Function& signature = Function::Handle(Type::Cast(type).signature()); |
| 552 Type& signature_type = Type::Handle(signature.SignatureType()); | 552 const Class& scope_class = Class::Handle(type.type_class()); |
| 553 if (signature_type.raw() != type.raw()) { | 553 if (scope_class.IsTypedefClass()) { |
| 554 ResolveType(cls, signature_type); | 554 ResolveSignature(scope_class, signature); |
| 555 } else { | 555 } else { |
| 556 const Class& scope_class = Class::Handle(type.type_class()); | 556 ResolveSignature(cls, signature); |
| 557 if (scope_class.IsTypedefClass()) { | |
| 558 ResolveSignature(scope_class, signature); | |
| 559 } else { | |
| 560 ResolveSignature(cls, signature); | |
| 561 } | |
| 562 if (signature.IsSignatureFunction()) { | |
| 563 // Drop fields that are not necessary anymore after resolution. | |
| 564 // The parent function, owner, and token position of a shared | |
| 565 // canonical function type are meaningless, since the canonical | |
| 566 // representent is picked arbitrarily. | |
| 567 signature.set_parent_function(Function::Handle()); | |
| 568 // TODO(regis): As long as we support metadata in typedef signatures, | |
| 569 // we cannot reset these fields used to reparse a typedef. | |
| 570 // Note that the scope class of a typedef function type is always | |
| 571 // preserved as the typedef class (not reset to _Closure class), thereby | |
| 572 // preventing sharing of canonical function types between typedefs. | |
| 573 // Not being shared, these fields are therefore always meaningful for | |
| 574 // typedefs. | |
| 575 if (!scope_class.IsTypedefClass()) { | |
| 576 signature.set_owner(Object::Handle()); | |
| 577 signature.set_token_pos(TokenPosition::kNoSource); | |
| 578 } | |
| 579 } | |
| 580 } | 557 } |
| 581 } | 558 } |
| 582 } | 559 } |
| 583 | 560 |
| 584 | 561 |
| 585 void ClassFinalizer::FinalizeTypeParameters(const Class& cls, | 562 void ClassFinalizer::FinalizeTypeParameters(const Class& cls, |
| 586 PendingTypes* pending_types) { | 563 PendingTypes* pending_types) { |
| 587 if (FLAG_trace_type_finalization) { | 564 if (FLAG_trace_type_finalization) { |
| 588 THR_Print("Finalizing type parameters of '%s'\n", | 565 THR_Print("Finalizing type parameters of '%s'\n", |
| 589 String::Handle(cls.Name()).ToCString()); | 566 String::Handle(cls.Name()).ToCString()); |
| (...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2347 super_type = FinalizeType(cls, super_type, kCanonicalizeWellFormed); | 2324 super_type = FinalizeType(cls, super_type, kCanonicalizeWellFormed); |
| 2348 cls.set_super_type(super_type); | 2325 cls.set_super_type(super_type); |
| 2349 } | 2326 } |
| 2350 // Finalize mixin type. | 2327 // Finalize mixin type. |
| 2351 Type& mixin_type = Type::Handle(cls.mixin()); | 2328 Type& mixin_type = Type::Handle(cls.mixin()); |
| 2352 if (!mixin_type.IsNull()) { | 2329 if (!mixin_type.IsNull()) { |
| 2353 mixin_type ^= FinalizeType(cls, mixin_type, kCanonicalizeWellFormed); | 2330 mixin_type ^= FinalizeType(cls, mixin_type, kCanonicalizeWellFormed); |
| 2354 cls.set_mixin(mixin_type); | 2331 cls.set_mixin(mixin_type); |
| 2355 } | 2332 } |
| 2356 if (cls.IsTypedefClass()) { | 2333 if (cls.IsTypedefClass()) { |
| 2357 Function& signature = Function::Handle(cls.signature_function()); | 2334 const Function& signature = Function::Handle(cls.signature_function()); |
| 2358 Type& type = Type::Handle(signature.SignatureType()); | 2335 Type& type = Type::Handle(signature.SignatureType()); |
| 2359 ASSERT(type.signature() == signature.raw()); | |
| 2360 | 2336 |
| 2361 // Check for illegal self references. | 2337 // Check for illegal self references. |
| 2362 GrowableArray<intptr_t> visited_aliases; | 2338 GrowableArray<intptr_t> visited_aliases; |
| 2363 if (!IsTypedefCycleFree(cls, type, &visited_aliases)) { | 2339 if (!IsTypedefCycleFree(cls, type, &visited_aliases)) { |
| 2364 const String& name = String::Handle(cls.Name()); | 2340 const String& name = String::Handle(cls.Name()); |
| 2365 ReportError(cls, cls.token_pos(), | 2341 ReportError(cls, cls.token_pos(), |
| 2366 "typedef '%s' illegally refers to itself", name.ToCString()); | 2342 "typedef '%s' illegally refers to itself", name.ToCString()); |
| 2367 } | 2343 } |
| 2368 cls.set_is_type_finalized(); | 2344 cls.set_is_type_finalized(); |
| 2369 | 2345 |
| 2370 // Resolve and finalize the result and parameter types of the signature | 2346 // Resolve and finalize the result and parameter types of the signature |
| 2371 // function of this typedef class. | 2347 // function of this typedef class. |
| 2372 FinalizeSignature(cls, signature); // Does not modify signature type. | 2348 FinalizeSignature(cls, signature); // Does not modify signature type. |
| 2373 ASSERT(signature.SignatureType() == type.raw()); | 2349 ASSERT(signature.SignatureType() == type.raw()); |
| 2374 | 2350 |
| 2375 // Resolve and finalize the signature type of this typedef. | 2351 // Resolve and finalize the signature type of this typedef. |
| 2376 type ^= FinalizeType(cls, type, kCanonicalizeWellFormed); | 2352 type ^= FinalizeType(cls, type, kCanonicalizeWellFormed); |
| 2377 | |
| 2378 // If a different canonical signature type is returned, update the signature | |
| 2379 // function of the typedef. | |
| 2380 signature = type.signature(); | |
| 2381 signature.SetSignatureType(type); | 2353 signature.SetSignatureType(type); |
| 2382 cls.set_signature_function(signature); | |
| 2383 | 2354 |
| 2384 // Closure instances do not refer to this typedef as their class, so there | 2355 // Closure instances do not refer to this typedef as their class, so there |
| 2385 // is no need to add this typedef class to the subclasses of _Closure. | 2356 // is no need to add this typedef class to the subclasses of _Closure. |
| 2386 ASSERT(super_type.IsNull() || super_type.IsObjectType()); | 2357 ASSERT(super_type.IsNull() || super_type.IsObjectType()); |
| 2387 | 2358 |
| 2388 return; | 2359 return; |
| 2389 } | 2360 } |
| 2390 | 2361 |
| 2391 // Finalize interface types (but not necessarily interface classes). | 2362 // Finalize interface types (but not necessarily interface classes). |
| 2392 Array& interface_types = Array::Handle(cls.interfaces()); | 2363 Array& interface_types = Array::Handle(cls.interfaces()); |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3379 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); | 3350 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); |
| 3380 field ^= fields_array.At(0); | 3351 field ^= fields_array.At(0); |
| 3381 ASSERT(field.Offset() == ByteBuffer::data_offset()); | 3352 ASSERT(field.Offset() == ByteBuffer::data_offset()); |
| 3382 name ^= field.name(); | 3353 name ^= field.name(); |
| 3383 expected_name ^= String::New("_data"); | 3354 expected_name ^= String::New("_data"); |
| 3384 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 3355 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
| 3385 #endif | 3356 #endif |
| 3386 } | 3357 } |
| 3387 | 3358 |
| 3388 } // namespace dart | 3359 } // namespace dart |
| OLD | NEW |