| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 ASSERT(!class_array.IsNull()); | 50 ASSERT(!class_array.IsNull()); |
| 51 Class& cls = Class::Handle(); | 51 Class& cls = Class::Handle(); |
| 52 // First resolve all superclasses. | 52 // First resolve all superclasses. |
| 53 for (intptr_t i = 0; i < class_array.Length(); i++) { | 53 for (intptr_t i = 0; i < class_array.Length(); i++) { |
| 54 cls ^= class_array.At(i); | 54 cls ^= class_array.At(i); |
| 55 if (FLAG_trace_class_finalization) { | 55 if (FLAG_trace_class_finalization) { |
| 56 OS::Print("Resolving super and default: %s\n", cls.ToCString()); | 56 OS::Print("Resolving super and default: %s\n", cls.ToCString()); |
| 57 } | 57 } |
| 58 ResolveSuperType(cls); | 58 ResolveSuperType(cls); |
| 59 if (cls.is_interface()) { | 59 if (cls.is_interface()) { |
| 60 ResolveDefaultClass(cls); | 60 ResolveFactoryClass(cls); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 // Finalize all classes. | 63 // Finalize all classes. |
| 64 for (intptr_t i = 0; i < class_array.Length(); i++) { | 64 for (intptr_t i = 0; i < class_array.Length(); i++) { |
| 65 cls ^= class_array.At(i); | 65 cls ^= class_array.At(i); |
| 66 FinalizeClass(cls, generating_snapshot); | 66 FinalizeClass(cls, generating_snapshot); |
| 67 } | 67 } |
| 68 if (FLAG_print_classes) { | 68 if (FLAG_print_classes) { |
| 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); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 ReportError(script, cls.token_index(), | 332 ReportError(script, cls.token_index(), |
| 333 "'%s' is not allowed to extend '%s'", | 333 "'%s' is not allowed to extend '%s'", |
| 334 String::Handle(cls.Name()).ToCString(), | 334 String::Handle(cls.Name()).ToCString(), |
| 335 String::Handle(super_class.Name()).ToCString()); | 335 String::Handle(super_class.Name()).ToCString()); |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 return; | 338 return; |
| 339 } | 339 } |
| 340 | 340 |
| 341 | 341 |
| 342 void ClassFinalizer::ResolveDefaultClass(const Class& interface) { | 342 void ClassFinalizer::ResolveFactoryClass(const Class& interface) { |
| 343 ASSERT(interface.is_interface()); | 343 ASSERT(interface.is_interface()); |
| 344 if (interface.is_finalized() || | 344 if (interface.is_finalized() || |
| 345 !interface.HasFactoryClass() || | 345 !interface.HasFactoryClass() || |
| 346 interface.HasResolvedFactoryClass()) { | 346 interface.HasResolvedFactoryClass()) { |
| 347 return; | 347 return; |
| 348 } | 348 } |
| 349 const UnresolvedClass& unresolved_factory_class = | 349 const UnresolvedClass& unresolved_factory_class = |
| 350 UnresolvedClass::Handle(interface.UnresolvedFactoryClass()); | 350 UnresolvedClass::Handle(interface.UnresolvedFactoryClass()); |
| 351 | 351 |
| 352 // Lookup the factory class. | 352 // Lookup the factory class. |
| 353 const Class& factory_class = | 353 const Class& factory_class = |
| 354 Class::Handle(ResolveClass(interface, unresolved_factory_class)); | 354 Class::Handle(ResolveClass(interface, unresolved_factory_class)); |
| 355 if (factory_class.IsNull()) { | 355 if (factory_class.IsNull()) { |
| 356 const Script& script = Script::Handle(interface.script()); | 356 const Script& script = Script::Handle(interface.script()); |
| 357 ReportError(script, unresolved_factory_class.token_index(), | 357 ReportError(script, unresolved_factory_class.token_index(), |
| 358 "cannot resolve factory class name '%s' from '%s'", | 358 "cannot resolve factory class name '%s' from '%s'", |
| 359 String::Handle(unresolved_factory_class.Name()).ToCString(), | 359 String::Handle(unresolved_factory_class.Name()).ToCString(), |
| 360 String::Handle(interface.Name()).ToCString()); | 360 String::Handle(interface.Name()).ToCString()); |
| 361 } | 361 } |
| 362 if (factory_class.is_interface()) { | 362 if (factory_class.is_interface()) { |
| 363 const String& interface_name = String::Handle(interface.Name()); | 363 const String& interface_name = String::Handle(interface.Name()); |
| 364 const String& factory_name = String::Handle(factory_class.Name()); | 364 const String& factory_name = String::Handle(factory_class.Name()); |
| 365 const Script& script = Script::Handle(interface.script()); | 365 const Script& script = Script::Handle(interface.script()); |
| 366 ReportError(script, unresolved_factory_class.token_index(), | 366 ReportError(script, unresolved_factory_class.token_index(), |
| 367 "default clause of interface '%s' names non-class '%s'", | 367 "default clause of interface '%s' names non-class '%s'", |
| 368 interface_name.ToCString(), | 368 interface_name.ToCString(), |
| 369 factory_name.ToCString()); | 369 factory_name.ToCString()); |
| 370 } | 370 } |
| 371 interface.set_factory_class(factory_class); | 371 interface.set_factory_class(factory_class); |
| 372 ResolveAndFinalizeUpperBounds(factory_class); | 372 // It is not necessary to finalize the bounds before comparing them between |
| 373 // the expected and actual factory class. |
| 373 const Class& factory_signature_class = Class::Handle( | 374 const Class& factory_signature_class = Class::Handle( |
| 374 unresolved_factory_class.factory_signature_class()); | 375 unresolved_factory_class.factory_signature_class()); |
| 375 ASSERT(!factory_signature_class.IsNull()); | 376 ASSERT(!factory_signature_class.IsNull()); |
| 376 // If a type parameter list is included in the default factory clause (it | 377 // If a type parameter list is included in the default factory clause (it |
| 377 // can be omitted), verify that it matches the list of type parameters of | 378 // can be omitted), verify that it matches the list of type parameters of |
| 378 // the factory class in number, names, and bounds. | 379 // the factory class in number, names, and bounds. |
| 379 if (factory_signature_class.NumTypeParameters() > 0) { | 380 if (factory_signature_class.NumTypeParameters() > 0) { |
| 380 ResolveAndFinalizeUpperBounds(factory_signature_class); | |
| 381 const TypeArguments& expected_type_parameters = | 381 const TypeArguments& expected_type_parameters = |
| 382 TypeArguments::Handle(factory_signature_class.type_parameters()); | 382 TypeArguments::Handle(factory_signature_class.type_parameters()); |
| 383 const TypeArguments& actual_type_parameters = | 383 const TypeArguments& actual_type_parameters = |
| 384 TypeArguments::Handle(factory_class.type_parameters()); | 384 TypeArguments::Handle(factory_class.type_parameters()); |
| 385 const TypeArguments& expected_type_parameter_bounds = | 385 const TypeArguments& expected_type_parameter_bounds = |
| 386 TypeArguments::Handle(factory_signature_class.type_parameter_bounds()); | 386 TypeArguments::Handle(factory_signature_class.type_parameter_bounds()); |
| 387 const TypeArguments& actual_type_parameter_bounds = | 387 const TypeArguments& actual_type_parameter_bounds = |
| 388 TypeArguments::Handle(factory_class.type_parameter_bounds()); | 388 TypeArguments::Handle(factory_class.type_parameter_bounds()); |
| 389 if (!TypeArguments::AreIdenticalTypeParameters(expected_type_parameters, | 389 if (!AbstractTypeArguments::AreIdentical(expected_type_parameters, |
| 390 actual_type_parameters) || | 390 actual_type_parameters) || |
| 391 !AbstractTypeArguments::AreEqual(expected_type_parameter_bounds, | 391 !AbstractTypeArguments::AreIdentical(expected_type_parameter_bounds, |
| 392 actual_type_parameter_bounds)) { | 392 actual_type_parameter_bounds)) { |
| 393 const String& interface_name = String::Handle(interface.Name()); | 393 const String& interface_name = String::Handle(interface.Name()); |
| 394 const String& factory_name = String::Handle(factory_class.Name()); | 394 const String& factory_name = String::Handle(factory_class.Name()); |
| 395 const Script& script = Script::Handle(interface.script()); | 395 const Script& script = Script::Handle(interface.script()); |
| 396 ReportError(script, unresolved_factory_class.token_index(), | 396 ReportError(script, unresolved_factory_class.token_index(), |
| 397 "mismatch in number, names, or bounds of type parameters " | 397 "mismatch in number, names, or bounds of type parameters " |
| 398 "between default clause of interface '%s' and actual factory " | 398 "between default clause of interface '%s' and actual factory " |
| 399 "class '%s'", | 399 "class '%s'", |
| 400 interface_name.ToCString(), | 400 interface_name.ToCString(), |
| 401 factory_name.ToCString()); | 401 factory_name.ToCString()); |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 // Verify that the type parameters of the factory class and of the interface | 404 // Verify that the type parameters of the factory class and of the interface |
| 405 // have identical names. | 405 // have identical names. |
| 406 const TypeArguments& interface_type_parameters = | 406 const TypeArguments& interface_type_parameters = |
| 407 TypeArguments::Handle(interface.type_parameters()); | 407 TypeArguments::Handle(interface.type_parameters()); |
| 408 const TypeArguments& factory_type_parameters = | 408 const TypeArguments& factory_type_parameters = |
| 409 TypeArguments::Handle(factory_class.type_parameters()); | 409 TypeArguments::Handle(factory_class.type_parameters()); |
| 410 if (!TypeArguments::AreIdenticalTypeParameters(interface_type_parameters, | 410 if (!AbstractTypeArguments::AreIdentical(interface_type_parameters, |
| 411 factory_type_parameters)) { | 411 factory_type_parameters)) { |
| 412 const String& interface_name = String::Handle(interface.Name()); | 412 const String& interface_name = String::Handle(interface.Name()); |
| 413 const String& factory_name = String::Handle(factory_class.Name()); | 413 const String& factory_name = String::Handle(factory_class.Name()); |
| 414 const Script& script = Script::Handle(interface.script()); | 414 const Script& script = Script::Handle(interface.script()); |
| 415 ReportError(script, unresolved_factory_class.token_index(), | 415 ReportError(script, unresolved_factory_class.token_index(), |
| 416 "mismatch in number or names of type parameters between " | 416 "mismatch in number or names of type parameters between " |
| 417 "interface '%s' and default factory class '%s'", | 417 "interface '%s' and default factory class '%s'", |
| 418 interface_name.ToCString(), | 418 interface_name.ToCString(), |
| 419 factory_name.ToCString()); | 419 factory_name.ToCString()); |
| 420 } | 420 } |
| 421 } | 421 } |
| (...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 void ClassFinalizer::ReportError(const char* format, ...) { | 1304 void ClassFinalizer::ReportError(const char* format, ...) { |
| 1305 va_list args; | 1305 va_list args; |
| 1306 va_start(args, format); | 1306 va_start(args, format); |
| 1307 const Error& error = Error::Handle( | 1307 const Error& error = Error::Handle( |
| 1308 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); | 1308 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); |
| 1309 va_end(args); | 1309 va_end(args); |
| 1310 ReportError(error); | 1310 ReportError(error); |
| 1311 } | 1311 } |
| 1312 | 1312 |
| 1313 } // namespace dart | 1313 } // namespace dart |
| OLD | NEW |