| 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 Script::Handle(target_class.script()), | 382 Script::Handle(target_class.script()), |
| 383 factory.token_pos(), | 383 factory.token_pos(), |
| 384 "class '%s' has no constructor or factory named '%s'", | 384 "class '%s' has no constructor or factory named '%s'", |
| 385 target_class_name.ToCString(), | 385 target_class_name.ToCString(), |
| 386 user_visible_target_name.ToCString()); | 386 user_visible_target_name.ToCString()); |
| 387 factory.SetRedirectionType(type); | 387 factory.SetRedirectionType(type); |
| 388 ASSERT(factory.RedirectionTarget() == Function::null()); | 388 ASSERT(factory.RedirectionTarget() == Function::null()); |
| 389 return; | 389 return; |
| 390 } | 390 } |
| 391 | 391 |
| 392 if (Isolate::Current()->flags().error_on_bad_override()) { | 392 if (Isolate::Current()->error_on_bad_override()) { |
| 393 // Verify that the target is compatible with the redirecting factory. | 393 // Verify that the target is compatible with the redirecting factory. |
| 394 Error& error = Error::Handle(); | 394 Error& error = Error::Handle(); |
| 395 if (!target.HasCompatibleParametersWith(factory, &error)) { | 395 if (!target.HasCompatibleParametersWith(factory, &error)) { |
| 396 const Script& script = Script::Handle(target_class.script()); | 396 const Script& script = Script::Handle(target_class.script()); |
| 397 type = NewFinalizedMalformedType( | 397 type = NewFinalizedMalformedType( |
| 398 error, script, target.token_pos(), | 398 error, script, target.token_pos(), |
| 399 "constructor '%s' has incompatible parameters with " | 399 "constructor '%s' has incompatible parameters with " |
| 400 "redirecting factory '%s'", | 400 "redirecting factory '%s'", |
| 401 String::Handle(target.name()).ToCString(), | 401 String::Handle(target.name()).ToCString(), |
| 402 String::Handle(factory.name()).ToCString()); | 402 String::Handle(factory.name()).ToCString()); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 // The class has num_type_parameters type parameters. | 670 // The class has num_type_parameters type parameters. |
| 671 const intptr_t num_type_parameters = type_class.NumTypeParameters(); | 671 const intptr_t num_type_parameters = type_class.NumTypeParameters(); |
| 672 | 672 |
| 673 // Initialize the type argument vector. | 673 // Initialize the type argument vector. |
| 674 // Check the number of parsed type arguments, if any. | 674 // Check the number of parsed type arguments, if any. |
| 675 // Specifying no type arguments indicates a raw type, which is not an error. | 675 // Specifying no type arguments indicates a raw type, which is not an error. |
| 676 // However, type parameter bounds are checked below, even for a raw type. | 676 // However, type parameter bounds are checked below, even for a raw type. |
| 677 TypeArguments& arguments = TypeArguments::Handle(Z, type.arguments()); | 677 TypeArguments& arguments = TypeArguments::Handle(Z, type.arguments()); |
| 678 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) { | 678 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) { |
| 679 // Wrong number of type arguments. The type is mapped to the raw type. | 679 // Wrong number of type arguments. The type is mapped to the raw type. |
| 680 if (Isolate::Current()->flags().error_on_bad_type()) { | 680 if (Isolate::Current()->error_on_bad_type()) { |
| 681 const String& type_class_name = String::Handle(Z, type_class.Name()); | 681 const String& type_class_name = String::Handle(Z, type_class.Name()); |
| 682 ReportError(cls, type.token_pos(), | 682 ReportError(cls, type.token_pos(), |
| 683 "wrong number of type arguments for class '%s'", | 683 "wrong number of type arguments for class '%s'", |
| 684 type_class_name.ToCString()); | 684 type_class_name.ToCString()); |
| 685 } | 685 } |
| 686 // Make the type raw and continue without reporting any error. | 686 // Make the type raw and continue without reporting any error. |
| 687 // A static warning should have been reported. | 687 // A static warning should have been reported. |
| 688 arguments = TypeArguments::null(); | 688 arguments = TypeArguments::null(); |
| 689 type.set_arguments(arguments); | 689 type.set_arguments(arguments); |
| 690 } | 690 } |
| (...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 } else { | 1449 } else { |
| 1450 ASSERT(type.IsInstantiated()); | 1450 ASSERT(type.IsInstantiated()); |
| 1451 } | 1451 } |
| 1452 const Instance& const_value = | 1452 const Instance& const_value = |
| 1453 Instance::Handle(Z, field.StaticValue()); | 1453 Instance::Handle(Z, field.StaticValue()); |
| 1454 if (!error.IsNull() || | 1454 if (!error.IsNull() || |
| 1455 (!type.IsDynamicType() && | 1455 (!type.IsDynamicType() && |
| 1456 !const_value.IsInstanceOf(type, | 1456 !const_value.IsInstanceOf(type, |
| 1457 Object::null_type_arguments(), | 1457 Object::null_type_arguments(), |
| 1458 &error))) { | 1458 &error))) { |
| 1459 if (Isolate::Current()->flags().error_on_bad_type()) { | 1459 if (Isolate::Current()->error_on_bad_type()) { |
| 1460 const AbstractType& const_value_type = AbstractType::Handle( | 1460 const AbstractType& const_value_type = AbstractType::Handle( |
| 1461 Z, const_value.GetType()); | 1461 Z, const_value.GetType()); |
| 1462 const String& const_value_type_name = String::Handle( | 1462 const String& const_value_type_name = String::Handle( |
| 1463 Z, const_value_type.UserVisibleName()); | 1463 Z, const_value_type.UserVisibleName()); |
| 1464 const String& type_name = String::Handle(Z, type.UserVisibleName()); | 1464 const String& type_name = String::Handle(Z, type.UserVisibleName()); |
| 1465 ReportErrors(error, cls, field.token_pos(), | 1465 ReportErrors(error, cls, field.token_pos(), |
| 1466 "error initializing static %s field '%s': " | 1466 "error initializing static %s field '%s': " |
| 1467 "type '%s' is not a subtype of type '%s'", | 1467 "type '%s' is not a subtype of type '%s'", |
| 1468 field.is_const() ? "const" : "final", | 1468 field.is_const() ? "const" : "final", |
| 1469 name.ToCString(), | 1469 name.ToCString(), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1512 array = cls.functions(); | 1512 array = cls.functions(); |
| 1513 Function& function = Function::Handle(Z); | 1513 Function& function = Function::Handle(Z); |
| 1514 Function& overridden_function = Function::Handle(Z); | 1514 Function& overridden_function = Function::Handle(Z); |
| 1515 const intptr_t num_functions = array.Length(); | 1515 const intptr_t num_functions = array.Length(); |
| 1516 Error& error = Error::Handle(Z); | 1516 Error& error = Error::Handle(Z); |
| 1517 for (intptr_t i = 0; i < num_functions; i++) { | 1517 for (intptr_t i = 0; i < num_functions; i++) { |
| 1518 function ^= array.At(i); | 1518 function ^= array.At(i); |
| 1519 FinalizeSignature(cls, function); | 1519 FinalizeSignature(cls, function); |
| 1520 name = function.name(); | 1520 name = function.name(); |
| 1521 // Report signature conflicts only. | 1521 // Report signature conflicts only. |
| 1522 if (Isolate::Current()->flags().error_on_bad_override() && | 1522 if (Isolate::Current()->error_on_bad_override() && |
| 1523 !function.is_static() && !function.IsGenerativeConstructor()) { | 1523 !function.is_static() && !function.IsGenerativeConstructor()) { |
| 1524 // A constructor cannot override anything. | 1524 // A constructor cannot override anything. |
| 1525 for (intptr_t i = 0; i < interfaces.length(); i++) { | 1525 for (intptr_t i = 0; i < interfaces.length(); i++) { |
| 1526 const Class* super_class = interfaces.At(i); | 1526 const Class* super_class = interfaces.At(i); |
| 1527 // Finalize superclass since overrides check relies on all members | 1527 // Finalize superclass since overrides check relies on all members |
| 1528 // of the superclass to be finalized. | 1528 // of the superclass to be finalized. |
| 1529 FinalizeClass(*super_class); | 1529 FinalizeClass(*super_class); |
| 1530 overridden_function = super_class->LookupDynamicFunction(name); | 1530 overridden_function = super_class->LookupDynamicFunction(name); |
| 1531 if (!overridden_function.IsNull() && | 1531 if (!overridden_function.IsNull() && |
| 1532 !function.HasCompatibleParametersWith(overridden_function, | 1532 !function.HasCompatibleParametersWith(overridden_function, |
| (...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2703 if (num_type_arguments > 0) { | 2703 if (num_type_arguments > 0) { |
| 2704 if (num_type_arguments == num_type_parameters) { | 2704 if (num_type_arguments == num_type_parameters) { |
| 2705 for (intptr_t i = 0; i < num_type_arguments; i++) { | 2705 for (intptr_t i = 0; i < num_type_arguments; i++) { |
| 2706 arg = type_args.TypeAt(i); | 2706 arg = type_args.TypeAt(i); |
| 2707 arg = arg.CloneUnfinalized(); | 2707 arg = arg.CloneUnfinalized(); |
| 2708 ASSERT(!arg.IsBeingFinalized()); | 2708 ASSERT(!arg.IsBeingFinalized()); |
| 2709 collected_args.Add(arg); | 2709 collected_args.Add(arg); |
| 2710 } | 2710 } |
| 2711 return; | 2711 return; |
| 2712 } | 2712 } |
| 2713 if (Isolate::Current()->flags().error_on_bad_type()) { | 2713 if (Isolate::Current()->error_on_bad_type()) { |
| 2714 const String& type_class_name = String::Handle(type_class.Name()); | 2714 const String& type_class_name = String::Handle(type_class.Name()); |
| 2715 ReportError(cls, type.token_pos(), | 2715 ReportError(cls, type.token_pos(), |
| 2716 "wrong number of type arguments for class '%s'", | 2716 "wrong number of type arguments for class '%s'", |
| 2717 type_class_name.ToCString()); | 2717 type_class_name.ToCString()); |
| 2718 } | 2718 } |
| 2719 // Discard provided type arguments and treat type as raw. | 2719 // Discard provided type arguments and treat type as raw. |
| 2720 } | 2720 } |
| 2721 // Fill arguments with type dynamic. | 2721 // Fill arguments with type dynamic. |
| 2722 for (intptr_t i = 0; i < num_type_parameters; i++) { | 2722 for (intptr_t i = 0; i < num_type_parameters; i++) { |
| 2723 arg = Type::DynamicType(); | 2723 arg = Type::DynamicType(); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3135 void ClassFinalizer::MarkTypeMalformed(const Error& prev_error, | 3135 void ClassFinalizer::MarkTypeMalformed(const Error& prev_error, |
| 3136 const Script& script, | 3136 const Script& script, |
| 3137 const Type& type, | 3137 const Type& type, |
| 3138 const char* format, | 3138 const char* format, |
| 3139 va_list args) { | 3139 va_list args) { |
| 3140 LanguageError& error = LanguageError::Handle( | 3140 LanguageError& error = LanguageError::Handle( |
| 3141 LanguageError::NewFormattedV( | 3141 LanguageError::NewFormattedV( |
| 3142 prev_error, script, type.token_pos(), Report::AtLocation, | 3142 prev_error, script, type.token_pos(), Report::AtLocation, |
| 3143 Report::kMalformedType, Heap::kOld, | 3143 Report::kMalformedType, Heap::kOld, |
| 3144 format, args)); | 3144 format, args)); |
| 3145 if (Isolate::Current()->flags().error_on_bad_type()) { | 3145 if (Isolate::Current()->error_on_bad_type()) { |
| 3146 ReportError(error); | 3146 ReportError(error); |
| 3147 } | 3147 } |
| 3148 type.set_error(error); | 3148 type.set_error(error); |
| 3149 // Make the type raw, since it may not be possible to | 3149 // Make the type raw, since it may not be possible to |
| 3150 // properly finalize its type arguments. | 3150 // properly finalize its type arguments. |
| 3151 type.set_type_class(Class::Handle(Object::dynamic_class())); | 3151 type.set_type_class(Class::Handle(Object::dynamic_class())); |
| 3152 type.set_arguments(Object::null_type_arguments()); | 3152 type.set_arguments(Object::null_type_arguments()); |
| 3153 if (!type.IsFinalized()) { | 3153 if (!type.IsFinalized()) { |
| 3154 type.SetIsFinalized(); | 3154 type.SetIsFinalized(); |
| 3155 // Do not canonicalize malformed types, since they contain an error field. | 3155 // Do not canonicalize malformed types, since they contain an error field. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3197 const AbstractType& type, | 3197 const AbstractType& type, |
| 3198 const char* format, ...) { | 3198 const char* format, ...) { |
| 3199 va_list args; | 3199 va_list args; |
| 3200 va_start(args, format); | 3200 va_start(args, format); |
| 3201 LanguageError& error = LanguageError::Handle( | 3201 LanguageError& error = LanguageError::Handle( |
| 3202 LanguageError::NewFormattedV( | 3202 LanguageError::NewFormattedV( |
| 3203 prev_error, script, type.token_pos(), Report::AtLocation, | 3203 prev_error, script, type.token_pos(), Report::AtLocation, |
| 3204 Report::kMalboundedType, Heap::kOld, | 3204 Report::kMalboundedType, Heap::kOld, |
| 3205 format, args)); | 3205 format, args)); |
| 3206 va_end(args); | 3206 va_end(args); |
| 3207 if (Isolate::Current()->flags().error_on_bad_type()) { | 3207 if (Isolate::Current()->error_on_bad_type()) { |
| 3208 ReportError(error); | 3208 ReportError(error); |
| 3209 } | 3209 } |
| 3210 type.set_error(error); | 3210 type.set_error(error); |
| 3211 if (!type.IsFinalized()) { | 3211 if (!type.IsFinalized()) { |
| 3212 type.SetIsFinalized(); | 3212 type.SetIsFinalized(); |
| 3213 // Do not canonicalize malbounded types. | 3213 // Do not canonicalize malbounded types. |
| 3214 } | 3214 } |
| 3215 } | 3215 } |
| 3216 | 3216 |
| 3217 | 3217 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3315 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); | 3315 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); |
| 3316 field ^= fields_array.At(0); | 3316 field ^= fields_array.At(0); |
| 3317 ASSERT(field.Offset() == ByteBuffer::data_offset()); | 3317 ASSERT(field.Offset() == ByteBuffer::data_offset()); |
| 3318 name ^= field.name(); | 3318 name ^= field.name(); |
| 3319 expected_name ^= String::New("_data"); | 3319 expected_name ^= String::New("_data"); |
| 3320 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 3320 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
| 3321 #endif | 3321 #endif |
| 3322 } | 3322 } |
| 3323 | 3323 |
| 3324 } // namespace dart | 3324 } // namespace dart |
| OLD | NEW |