| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/heap.h" | 8 #include "vm/heap.h" |
| 9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 return NULL; | 720 return NULL; |
| 721 } | 721 } |
| 722 | 722 |
| 723 | 723 |
| 724 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, | 724 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, |
| 725 const Function& function) { | 725 const Function& function) { |
| 726 // Resolve result type. | 726 // Resolve result type. |
| 727 AbstractType& type = AbstractType::Handle(function.result_type()); | 727 AbstractType& type = AbstractType::Handle(function.result_type()); |
| 728 if (!type.IsResolved()) { | 728 if (!type.IsResolved()) { |
| 729 if (function.IsFactory()) { | 729 if (function.IsFactory()) { |
| 730 // The signature class of the factory for a generic class holds the type | 730 // TODO(regis): Factory functions should not declare type parameters |
| 731 // parameters and their upper bounds. Copy the signature class from the | 731 // anymore. Remove this code once all libraries are fixed. |
| 732 // result before it gets resolved. | 732 |
| 733 // The signature class of the factory for a generic class used to hold the |
| 734 // type parameters and their upper bounds. Copy the signature class from |
| 735 // the result before it gets resolved. |
| 733 const UnresolvedClass& unresolved_type_class = | 736 const UnresolvedClass& unresolved_type_class = |
| 734 UnresolvedClass::Handle(type.unresolved_class()); | 737 UnresolvedClass::Handle(type.unresolved_class()); |
| 735 const Class& factory_signature_class = | 738 const Class& factory_signature_class = |
| 736 Class::Handle(unresolved_type_class.factory_signature_class()); | 739 Class::Handle(unresolved_type_class.factory_signature_class()); |
| 737 ASSERT(!factory_signature_class.IsNull()); | 740 |
| 738 function.set_signature_class(factory_signature_class); | 741 if (!factory_signature_class.IsNull()) { |
| 739 ResolveType(cls, type); | 742 // TODO(regis): Remove support for obsolete syntax in the parser. |
| 740 const Class& type_class = Class::Handle(type.type_class()); | 743 ASSERT(factory_signature_class.NumTypeParameters() > 0); |
| 741 // Verify that the factory signature declares the same number of type | 744 function.set_signature_class(factory_signature_class); |
| 742 // parameters as the return type class or interface. | 745 ResolveType(cls, type); |
| 743 ResolveAndFinalizeUpperBounds(factory_signature_class); | 746 const Class& type_class = Class::Handle(type.type_class()); |
| 744 if (factory_signature_class.NumTypeParameters() != | 747 // Verify that the factory signature declares the same number of type |
| 745 type_class.NumTypeParameters()) { | 748 // parameters as the return type class or interface. |
| 746 const String& function_name = String::Handle(function.name()); | 749 ResolveAndFinalizeUpperBounds(factory_signature_class); |
| 747 if (factory_signature_class.NumTypeParameters() == 0) { | 750 if (factory_signature_class.NumTypeParameters() != |
| 748 // TODO(regis): For now, and until the core lib is fixed, we accept a | 751 type_class.NumTypeParameters()) { |
| 749 // factory method with missing list of type parameters and use the | 752 const String& function_name = String::Handle(function.name()); |
| 750 // list of the enclosing class. | |
| 751 // See bug 5408808. | |
| 752 const Class& enclosing_class = Class::Handle(function.owner()); | |
| 753 function.set_signature_class(enclosing_class); | |
| 754 const Script& script = Script::Handle(enclosing_class.script()); | |
| 755 ReportWarning(script, unresolved_type_class.token_index(), | |
| 756 "factory method '%s' should declare a list of " | |
| 757 "%d type parameter%s.\n", | |
| 758 function_name.ToCString(), | |
| 759 type_class.NumTypeParameters(), | |
| 760 type_class.NumTypeParameters() > 1 ? "s" : ""); | |
| 761 } else { | |
| 762 const Class& enclosing_class = Class::Handle(function.owner()); | 753 const Class& enclosing_class = Class::Handle(function.owner()); |
| 763 const Script& script = Script::Handle(enclosing_class.script()); | 754 const Script& script = Script::Handle(enclosing_class.script()); |
| 764 ReportError(script, unresolved_type_class.token_index(), | 755 ReportError(script, unresolved_type_class.token_index(), |
| 765 "factory method '%s' must declare %d type parameter%s.\n", | 756 "factory method '%s' declares wrong number of type " |
| 766 function_name.ToCString(), | 757 "parameters (obsolete syntax).\n", |
| 767 type_class.NumTypeParameters(), | 758 function_name.ToCString()); |
| 768 type_class.NumTypeParameters() > 1 ? "s" : ""); | |
| 769 } | 759 } |
| 760 } else { |
| 761 ResolveType(cls, type); |
| 770 } | 762 } |
| 771 } else { | 763 } else { |
| 772 ResolveType(cls, type); | 764 ResolveType(cls, type); |
| 773 } | 765 } |
| 774 } | 766 } |
| 775 type = FinalizeType(cls, type); | 767 type = FinalizeType(cls, type); |
| 776 function.set_result_type(type); | 768 function.set_result_type(type); |
| 777 // Resolve formal parameter types. | 769 // Resolve formal parameter types. |
| 778 const intptr_t num_parameters = function.NumberOfParameters(); | 770 const intptr_t num_parameters = function.NumberOfParameters(); |
| 779 for (intptr_t i = 0; i < num_parameters; i++) { | 771 for (intptr_t i = 0; i < num_parameters; i++) { |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 va_end(args); | 1304 va_end(args); |
| 1313 if (FLAG_warning_as_error) { | 1305 if (FLAG_warning_as_error) { |
| 1314 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); | 1306 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); |
| 1315 UNREACHABLE(); | 1307 UNREACHABLE(); |
| 1316 } else { | 1308 } else { |
| 1317 OS::Print(message_buffer); | 1309 OS::Print(message_buffer); |
| 1318 } | 1310 } |
| 1319 } | 1311 } |
| 1320 | 1312 |
| 1321 } // namespace dart | 1313 } // namespace dart |
| OLD | NEW |