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 const Class& scope_class = Class::Handle(type.type_class()); | 552 Type& signature_type = Type::Handle(signature.SignatureType()); |
553 if (scope_class.IsTypedefClass()) { | 553 if (signature_type.raw() != type.raw()) { |
554 ResolveSignature(scope_class, signature); | 554 ResolveType(cls, signature_type); |
555 } else { | 555 } else { |
556 ResolveSignature(cls, signature); | 556 const Class& scope_class = Class::Handle(type.type_class()); |
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 // TODO(regis): Setting the owner to null is breaking mirrors. | |
565 // signature.set_owner(Object::Handle()); | |
566 signature.set_parent_function(Function::Handle()); | |
567 // TODO(regis): As long as we support metadata in typedef signatures, | |
568 // we cannot reset the token position to TokenPosition::kNoSource. | |
siva
2016/12/27 18:08:28
Is it necessary to drop the other fields? I can un
regis
2016/12/27 18:28:48
No, it is not necessary to drop them, but they are
| |
569 } | |
557 } | 570 } |
558 } | 571 } |
559 } | 572 } |
560 | 573 |
561 | 574 |
562 void ClassFinalizer::FinalizeTypeParameters(const Class& cls, | 575 void ClassFinalizer::FinalizeTypeParameters(const Class& cls, |
563 PendingTypes* pending_types) { | 576 PendingTypes* pending_types) { |
564 if (FLAG_trace_type_finalization) { | 577 if (FLAG_trace_type_finalization) { |
565 THR_Print("Finalizing type parameters of '%s'\n", | 578 THR_Print("Finalizing type parameters of '%s'\n", |
566 String::Handle(cls.Name()).ToCString()); | 579 String::Handle(cls.Name()).ToCString()); |
(...skipping 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2324 super_type = FinalizeType(cls, super_type, kCanonicalizeWellFormed); | 2337 super_type = FinalizeType(cls, super_type, kCanonicalizeWellFormed); |
2325 cls.set_super_type(super_type); | 2338 cls.set_super_type(super_type); |
2326 } | 2339 } |
2327 // Finalize mixin type. | 2340 // Finalize mixin type. |
2328 Type& mixin_type = Type::Handle(cls.mixin()); | 2341 Type& mixin_type = Type::Handle(cls.mixin()); |
2329 if (!mixin_type.IsNull()) { | 2342 if (!mixin_type.IsNull()) { |
2330 mixin_type ^= FinalizeType(cls, mixin_type, kCanonicalizeWellFormed); | 2343 mixin_type ^= FinalizeType(cls, mixin_type, kCanonicalizeWellFormed); |
2331 cls.set_mixin(mixin_type); | 2344 cls.set_mixin(mixin_type); |
2332 } | 2345 } |
2333 if (cls.IsTypedefClass()) { | 2346 if (cls.IsTypedefClass()) { |
2334 const Function& signature = Function::Handle(cls.signature_function()); | 2347 Function& signature = Function::Handle(cls.signature_function()); |
2335 Type& type = Type::Handle(signature.SignatureType()); | 2348 Type& type = Type::Handle(signature.SignatureType()); |
2349 ASSERT(type.signature() == signature.raw()); | |
2336 | 2350 |
2337 // Check for illegal self references. | 2351 // Check for illegal self references. |
2338 GrowableArray<intptr_t> visited_aliases; | 2352 GrowableArray<intptr_t> visited_aliases; |
2339 if (!IsTypedefCycleFree(cls, type, &visited_aliases)) { | 2353 if (!IsTypedefCycleFree(cls, type, &visited_aliases)) { |
2340 const String& name = String::Handle(cls.Name()); | 2354 const String& name = String::Handle(cls.Name()); |
2341 ReportError(cls, cls.token_pos(), | 2355 ReportError(cls, cls.token_pos(), |
2342 "typedef '%s' illegally refers to itself", name.ToCString()); | 2356 "typedef '%s' illegally refers to itself", name.ToCString()); |
2343 } | 2357 } |
2344 cls.set_is_type_finalized(); | 2358 cls.set_is_type_finalized(); |
2345 | 2359 |
2346 // Resolve and finalize the result and parameter types of the signature | 2360 // Resolve and finalize the result and parameter types of the signature |
2347 // function of this typedef class. | 2361 // function of this typedef class. |
2348 FinalizeSignature(cls, signature); // Does not modify signature type. | 2362 FinalizeSignature(cls, signature); // Does not modify signature type. |
2349 ASSERT(signature.SignatureType() == type.raw()); | 2363 ASSERT(signature.SignatureType() == type.raw()); |
2350 | 2364 |
2351 // Resolve and finalize the signature type of this typedef. | 2365 // Resolve and finalize the signature type of this typedef. |
2352 type ^= FinalizeType(cls, type, kCanonicalizeWellFormed); | 2366 type ^= FinalizeType(cls, type, kCanonicalizeWellFormed); |
2367 | |
2368 // If a different canonical signature type is returned, update the signature | |
2369 // function of the typedef. | |
2370 signature = type.signature(); | |
2353 signature.SetSignatureType(type); | 2371 signature.SetSignatureType(type); |
2372 cls.set_signature_function(signature); | |
2354 | 2373 |
2355 // Closure instances do not refer to this typedef as their class, so there | 2374 // Closure instances do not refer to this typedef as their class, so there |
2356 // is no need to add this typedef class to the subclasses of _Closure. | 2375 // is no need to add this typedef class to the subclasses of _Closure. |
2357 ASSERT(super_type.IsNull() || super_type.IsObjectType()); | 2376 ASSERT(super_type.IsNull() || super_type.IsObjectType()); |
2358 | 2377 |
2359 return; | 2378 return; |
2360 } | 2379 } |
2361 | 2380 |
2362 // Finalize interface types (but not necessarily interface classes). | 2381 // Finalize interface types (but not necessarily interface classes). |
2363 Array& interface_types = Array::Handle(cls.interfaces()); | 2382 Array& interface_types = Array::Handle(cls.interfaces()); |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3350 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); | 3369 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); |
3351 field ^= fields_array.At(0); | 3370 field ^= fields_array.At(0); |
3352 ASSERT(field.Offset() == ByteBuffer::data_offset()); | 3371 ASSERT(field.Offset() == ByteBuffer::data_offset()); |
3353 name ^= field.name(); | 3372 name ^= field.name(); |
3354 expected_name ^= String::New("_data"); | 3373 expected_name ^= String::New("_data"); |
3355 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 3374 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
3356 #endif | 3375 #endif |
3357 } | 3376 } |
3358 | 3377 |
3359 } // namespace dart | 3378 } // namespace dart |
OLD | NEW |