| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 ASSERT(!class_array.IsNull()); | 66 ASSERT(!class_array.IsNull()); |
| 67 Class& cls = Class::Handle(); | 67 Class& cls = Class::Handle(); |
| 68 // First resolve all superclasses. | 68 // First resolve all superclasses. |
| 69 for (intptr_t i = 0; i < class_array.Length(); i++) { | 69 for (intptr_t i = 0; i < class_array.Length(); i++) { |
| 70 cls ^= class_array.At(i); | 70 cls ^= class_array.At(i); |
| 71 if (FLAG_trace_class_finalization) { | 71 if (FLAG_trace_class_finalization) { |
| 72 OS::Print("Resolving super and default: %s\n", cls.ToCString()); | 72 OS::Print("Resolving super and default: %s\n", cls.ToCString()); |
| 73 } | 73 } |
| 74 ResolveSuperType(cls); | 74 ResolveSuperType(cls); |
| 75 if (cls.is_interface()) { | 75 if (cls.is_interface()) { |
| 76 ResolveFactoryClass(cls); | 76 ResolveDefaultClass(cls); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 // Finalize all classes. | 79 // Finalize all classes. |
| 80 for (intptr_t i = 0; i < class_array.Length(); i++) { | 80 for (intptr_t i = 0; i < class_array.Length(); i++) { |
| 81 cls ^= class_array.At(i); | 81 cls ^= class_array.At(i); |
| 82 FinalizeClass(cls, generating_snapshot); | 82 FinalizeClass(cls, generating_snapshot); |
| 83 } | 83 } |
| 84 if (FLAG_print_classes) { | 84 if (FLAG_print_classes) { |
| 85 for (intptr_t i = 0; i < class_array.Length(); i++) { | 85 for (intptr_t i = 0; i < class_array.Length(); i++) { |
| 86 cls ^= class_array.At(i); | 86 cls ^= class_array.At(i); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 ReportError(script, -1, | 343 ReportError(script, -1, |
| 344 "'%s' is not allowed to extend '%s'\n", | 344 "'%s' is not allowed to extend '%s'\n", |
| 345 String::Handle(cls.Name()).ToCString(), | 345 String::Handle(cls.Name()).ToCString(), |
| 346 String::Handle(super_class.Name()).ToCString()); | 346 String::Handle(super_class.Name()).ToCString()); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 return; | 349 return; |
| 350 } | 350 } |
| 351 | 351 |
| 352 | 352 |
| 353 void ClassFinalizer::ResolveFactoryClass(const Class& interface) { | 353 void ClassFinalizer::ResolveDefaultClass(const Class& interface) { |
| 354 ASSERT(interface.is_interface()); | 354 ASSERT(interface.is_interface()); |
| 355 if (interface.is_finalized() || | 355 if (interface.is_finalized() || |
| 356 !interface.HasFactoryClass() || | 356 !interface.HasFactoryClass() || |
| 357 interface.HasResolvedFactoryClass()) { | 357 interface.HasResolvedFactoryClass()) { |
| 358 return; | 358 return; |
| 359 } | 359 } |
| 360 const UnresolvedClass& unresolved_factory_class = | 360 const UnresolvedClass& unresolved_factory_class = |
| 361 UnresolvedClass::Handle(interface.UnresolvedFactoryClass()); | 361 UnresolvedClass::Handle(interface.UnresolvedFactoryClass()); |
| 362 | 362 |
| 363 // Lookup the factory class. | 363 // Lookup the factory class. |
| 364 const Class& factory_class = | 364 const Class& factory_class = |
| 365 Class::Handle(ResolveClass(interface, unresolved_factory_class)); | 365 Class::Handle(ResolveClass(interface, unresolved_factory_class)); |
| 366 ASSERT(!factory_class.IsNull()); | 366 ASSERT(!factory_class.IsNull()); |
| 367 if (factory_class.is_interface()) { | 367 if (factory_class.is_interface()) { |
| 368 const String& interface_name = String::Handle(interface.Name()); | 368 const String& interface_name = String::Handle(interface.Name()); |
| 369 const String& factory_name = String::Handle(factory_class.Name()); | 369 const String& factory_name = String::Handle(factory_class.Name()); |
| 370 const Script& script = Script::Handle(interface.script()); | 370 const Script& script = Script::Handle(interface.script()); |
| 371 ReportError(script, unresolved_factory_class.token_index(), | 371 ReportError(script, unresolved_factory_class.token_index(), |
| 372 "factory clause of interface '%s' names non-class '%s'.\n", | 372 "default clause of interface '%s' names non-class '%s'.\n", |
| 373 interface_name.ToCString(), | 373 interface_name.ToCString(), |
| 374 factory_name.ToCString()); | 374 factory_name.ToCString()); |
| 375 } | 375 } |
| 376 interface.set_factory_class(factory_class); | 376 interface.set_factory_class(factory_class); |
| 377 // Check that the type parameter lists are identical. | 377 // Check that the type parameter lists are identical. |
| 378 const Class& factory_signature_class = Class::Handle( | 378 const Class& factory_signature_class = Class::Handle( |
| 379 unresolved_factory_class.factory_signature_class()); | 379 unresolved_factory_class.factory_signature_class()); |
| 380 ASSERT(!factory_signature_class.IsNull()); | 380 ASSERT(!factory_signature_class.IsNull()); |
| 381 ResolveAndFinalizeUpperBounds(factory_class); | 381 ResolveAndFinalizeUpperBounds(factory_class); |
| 382 ResolveAndFinalizeUpperBounds(factory_signature_class); | 382 ResolveAndFinalizeUpperBounds(factory_signature_class); |
| 383 const intptr_t num_type_params = factory_signature_class.NumTypeParameters(); | 383 const intptr_t num_type_params = factory_signature_class.NumTypeParameters(); |
| 384 bool mismatch = factory_class.NumTypeParameters() != num_type_params; | 384 bool mismatch = factory_class.NumTypeParameters() != num_type_params; |
| 385 if (mismatch && (num_type_params == 0)) { | 385 if (mismatch && (num_type_params == 0)) { |
| 386 // TODO(regis): For now, and until the core lib is fixed, we accept a | 386 // TODO(regis): For now, and until the core lib is fixed, we accept a |
| 387 // factory clause with a class missing its list of type parameters. | 387 // factory clause with a class missing its list of type parameters. |
| 388 // See bug 5408808. | 388 // See bug 5408808. |
| 389 const String& interface_name = String::Handle(interface.Name()); | 389 const String& interface_name = String::Handle(interface.Name()); |
| 390 const String& factory_name = String::Handle(factory_class.Name()); | 390 const String& factory_name = String::Handle(factory_class.Name()); |
| 391 const Script& script = Script::Handle(interface.script()); | 391 const Script& script = Script::Handle(interface.script()); |
| 392 ReportWarning(script, unresolved_factory_class.token_index(), | 392 ReportWarning(script, unresolved_factory_class.token_index(), |
| 393 "class '%s' in factory clause of interface '%s' is " | 393 "class '%s' in default clause of interface '%s' is " |
| 394 "missing its type parameter list.\n", | 394 "missing its type parameter list.\n", |
| 395 factory_name.ToCString(), | 395 factory_name.ToCString(), |
| 396 interface_name.ToCString()); | 396 interface_name.ToCString()); |
| 397 return; | 397 return; |
| 398 } | 398 } |
| 399 String& expected_type_name = String::Handle(); | 399 String& expected_type_name = String::Handle(); |
| 400 String& actual_type_name = String::Handle(); | 400 String& actual_type_name = String::Handle(); |
| 401 AbstractType& expected_type_extends = AbstractType::Handle(); | 401 AbstractType& expected_type_extends = AbstractType::Handle(); |
| 402 AbstractType& actual_type_extends = AbstractType::Handle(); | 402 AbstractType& actual_type_extends = AbstractType::Handle(); |
| 403 const Array& expected_type_names = | 403 const Array& expected_type_names = |
| (...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 va_end(args); | 1303 va_end(args); |
| 1304 if (FLAG_warning_as_error) { | 1304 if (FLAG_warning_as_error) { |
| 1305 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); | 1305 Isolate::Current()->long_jump_base()->Jump(1, message_buffer); |
| 1306 UNREACHABLE(); | 1306 UNREACHABLE(); |
| 1307 } else { | 1307 } else { |
| 1308 OS::Print(message_buffer); | 1308 OS::Print(message_buffer); |
| 1309 } | 1309 } |
| 1310 } | 1310 } |
| 1311 | 1311 |
| 1312 } // namespace dart | 1312 } // namespace dart |
| OLD | NEW |