Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: runtime/vm/class_finalizer.cc

Issue 9285031: Remove support for obsolete syntax of factory methods and default classes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 interface_name.ToCString(), 374 interface_name.ToCString(),
375 factory_name.ToCString()); 375 factory_name.ToCString());
376 } 376 }
377 interface.set_factory_class(factory_class); 377 interface.set_factory_class(factory_class);
378 // Check that the type parameter lists are identical. 378 // Check that the type parameter lists are identical.
379 const Class& factory_signature_class = Class::Handle( 379 const Class& factory_signature_class = Class::Handle(
380 unresolved_factory_class.factory_signature_class()); 380 unresolved_factory_class.factory_signature_class());
381 ASSERT(!factory_signature_class.IsNull()); 381 ASSERT(!factory_signature_class.IsNull());
382 ResolveAndFinalizeUpperBounds(factory_class); 382 ResolveAndFinalizeUpperBounds(factory_class);
383 ResolveAndFinalizeUpperBounds(factory_signature_class); 383 ResolveAndFinalizeUpperBounds(factory_signature_class);
384 const intptr_t num_type_params = factory_signature_class.NumTypeParameters();
385 bool mismatch = factory_class.NumTypeParameters() != num_type_params;
386 if (mismatch && (num_type_params == 0)) {
387 // TODO(regis): For now, and until the core lib is fixed, we accept a
388 // factory clause with a class missing its list of type parameters.
389 // See bug 5408808.
390 const String& interface_name = String::Handle(interface.Name());
391 const String& factory_name = String::Handle(factory_class.Name());
392 const Script& script = Script::Handle(interface.script());
393 ReportWarning(script, unresolved_factory_class.token_index(),
394 "class '%s' in default clause of interface '%s' is "
395 "missing its type parameter list.\n",
396 factory_name.ToCString(),
397 interface_name.ToCString());
398 return;
399 }
400 String& expected_type_name = String::Handle(); 384 String& expected_type_name = String::Handle();
401 String& actual_type_name = String::Handle(); 385 String& actual_type_name = String::Handle();
402 AbstractType& expected_type_extends = AbstractType::Handle(); 386 AbstractType& expected_type_extends = AbstractType::Handle();
403 AbstractType& actual_type_extends = AbstractType::Handle(); 387 AbstractType& actual_type_extends = AbstractType::Handle();
404 const Array& expected_type_names = 388 const Array& expected_type_names =
405 Array::Handle(factory_signature_class.type_parameters()); 389 Array::Handle(factory_signature_class.type_parameters());
406 const Array& actual_type_names = 390 const Array& actual_type_names =
407 Array::Handle(factory_class.type_parameters()); 391 Array::Handle(factory_class.type_parameters());
408 const TypeArguments& expected_extends_array = 392 const TypeArguments& expected_extends_array =
409 TypeArguments::Handle(factory_signature_class.type_parameter_extends()); 393 TypeArguments::Handle(factory_signature_class.type_parameter_extends());
410 const TypeArguments& actual_extends_array = 394 const TypeArguments& actual_extends_array =
411 TypeArguments::Handle(factory_class.type_parameter_extends()); 395 TypeArguments::Handle(factory_class.type_parameter_extends());
396 const intptr_t num_type_params = factory_signature_class.NumTypeParameters();
397 bool mismatch = factory_class.NumTypeParameters() != num_type_params;
412 for (intptr_t i = 0; !mismatch && (i < num_type_params); i++) { 398 for (intptr_t i = 0; !mismatch && (i < num_type_params); i++) {
413 expected_type_name ^= expected_type_names.At(i); 399 expected_type_name ^= expected_type_names.At(i);
414 actual_type_name ^= actual_type_names.At(i); 400 actual_type_name ^= actual_type_names.At(i);
415 expected_type_extends = expected_extends_array.TypeAt(i); 401 expected_type_extends = expected_extends_array.TypeAt(i);
416 actual_type_extends = actual_extends_array.TypeAt(i); 402 actual_type_extends = actual_extends_array.TypeAt(i);
417 if (!expected_type_name.Equals(actual_type_name) || 403 if (!expected_type_name.Equals(actual_type_name) ||
418 !expected_type_extends.Equals(actual_type_extends)) { 404 !expected_type_extends.Equals(actual_type_extends)) {
419 mismatch = true; 405 mismatch = true;
420 } 406 }
421 } 407 }
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 } 704 }
719 UNREACHABLE(); 705 UNREACHABLE();
720 return NULL; 706 return NULL;
721 } 707 }
722 708
723 709
724 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, 710 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls,
725 const Function& function) { 711 const Function& function) {
726 // Resolve result type. 712 // Resolve result type.
727 AbstractType& type = AbstractType::Handle(function.result_type()); 713 AbstractType& type = AbstractType::Handle(function.result_type());
728 if (!type.IsResolved()) { 714 ResolveType(cls, type);
729 if (function.IsFactory()) {
730 // TODO(regis): Factory functions should not declare type parameters
731 // anymore. Remove this code once all libraries are fixed.
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.
736 const UnresolvedClass& unresolved_type_class =
737 UnresolvedClass::Handle(type.unresolved_class());
738 const Class& factory_signature_class =
739 Class::Handle(unresolved_type_class.factory_signature_class());
740
741 if (!factory_signature_class.IsNull()) {
742 // TODO(regis): Remove support for obsolete syntax in the parser.
743 ASSERT(factory_signature_class.NumTypeParameters() > 0);
744 function.set_signature_class(factory_signature_class);
745 ResolveType(cls, type);
746 const Class& type_class = Class::Handle(type.type_class());
747 // Verify that the factory signature declares the same number of type
748 // parameters as the return type class or interface.
749 ResolveAndFinalizeUpperBounds(factory_signature_class);
750 if (factory_signature_class.NumTypeParameters() !=
751 type_class.NumTypeParameters()) {
752 const String& function_name = String::Handle(function.name());
753 const Class& enclosing_class = Class::Handle(function.owner());
754 const Script& script = Script::Handle(enclosing_class.script());
755 ReportError(script, unresolved_type_class.token_index(),
756 "factory method '%s' declares wrong number of type "
757 "parameters (obsolete syntax).\n",
758 function_name.ToCString());
759 }
760 } else {
761 ResolveType(cls, type);
762 }
763 } else {
764 ResolveType(cls, type);
765 }
766 }
767 type = FinalizeType(cls, type); 715 type = FinalizeType(cls, type);
768 function.set_result_type(type); 716 function.set_result_type(type);
769 // Resolve formal parameter types. 717 // Resolve formal parameter types.
770 const intptr_t num_parameters = function.NumberOfParameters(); 718 const intptr_t num_parameters = function.NumberOfParameters();
771 for (intptr_t i = 0; i < num_parameters; i++) { 719 for (intptr_t i = 0; i < num_parameters; i++) {
772 type = function.ParameterTypeAt(i); 720 type = function.ParameterTypeAt(i);
773 ResolveType(cls, type); 721 ResolveType(cls, type);
774 type = FinalizeType(cls, type); 722 type = FinalizeType(cls, type);
775 function.SetParameterTypeAt(i, type); 723 function.SetParameterTypeAt(i, type);
776 } 724 }
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 va_end(args); 1243 va_end(args);
1296 if (FLAG_warning_as_error) { 1244 if (FLAG_warning_as_error) {
1297 Isolate::Current()->long_jump_base()->Jump(1, error); 1245 Isolate::Current()->long_jump_base()->Jump(1, error);
1298 UNREACHABLE(); 1246 UNREACHABLE();
1299 } else { 1247 } else {
1300 OS::Print("%s", error.ToErrorCString()); 1248 OS::Print("%s", error.ToErrorCString());
1301 } 1249 }
1302 } 1250 }
1303 1251
1304 } // namespace dart 1252 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/code_generator_ia32.cc » ('j') | tests/language/src/NonParameterizedFactory2Test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698