| 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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 } else { | 693 } else { |
| 694 // FinalizeTypeArguments can modify 'full_arguments', | 694 // FinalizeTypeArguments can modify 'full_arguments', |
| 695 // canonicalize afterwards. | 695 // canonicalize afterwards. |
| 696 full_arguments ^= full_arguments.Canonicalize(); | 696 full_arguments ^= full_arguments.Canonicalize(); |
| 697 } | 697 } |
| 698 parameterized_type.set_arguments(full_arguments); | 698 parameterized_type.set_arguments(full_arguments); |
| 699 } else { | 699 } else { |
| 700 ASSERT(full_arguments.IsNull()); // Use null vector for raw type. | 700 ASSERT(full_arguments.IsNull()); // Use null vector for raw type. |
| 701 } | 701 } |
| 702 // Mark the type as finalized. | 702 // Mark the type as finalized. |
| 703 parameterized_type.set_is_finalized(); | 703 if (parameterized_type.IsInstantiated()) { |
| 704 parameterized_type.set_is_finalized_instantiated(); |
| 705 } else { |
| 706 parameterized_type.set_is_finalized_uninstantiated(); |
| 707 } |
| 704 | 708 |
| 705 // Upper bounds of the finalized type arguments are only verified in checked | 709 // Upper bounds of the finalized type arguments are only verified in checked |
| 706 // mode, since bound errors are never reported by the vm in production mode. | 710 // mode, since bound errors are never reported by the vm in production mode. |
| 707 if (FLAG_enable_type_checks && | 711 if (FLAG_enable_type_checks && |
| 708 !full_arguments.IsNull() && | 712 !full_arguments.IsNull() && |
| 709 full_arguments.IsInstantiated()) { | 713 full_arguments.IsInstantiated()) { |
| 710 ResolveAndFinalizeUpperBounds(type_class); | 714 ResolveAndFinalizeUpperBounds(type_class); |
| 711 Error& malformed_error = Error::Handle(); | 715 Error& malformed_error = Error::Handle(); |
| 712 // Pass the full type argument vector as the bounds instantiator. | 716 // Pass the full type argument vector as the bounds instantiator. |
| 713 if (!full_arguments.IsWithinBoundsOf(type_class, | 717 if (!full_arguments.IsWithinBoundsOf(type_class, |
| 714 full_arguments, | 718 full_arguments, |
| 715 &malformed_error)) { | 719 &malformed_error)) { |
| 716 ASSERT(!malformed_error.IsNull()); | 720 ASSERT(!malformed_error.IsNull()); |
| 717 // The type argument vector of the type is not within bounds. The type | 721 // The type argument vector of the type is not within bounds. The type |
| 718 // is malformed. Prepend malformed_error to new malformed type error in | 722 // is malformed. Prepend malformed_error to new malformed type error in |
| 719 // order to report both locations. | 723 // order to report both locations. |
| 720 // Note that malformed bounds never result in a compile time error, even | 724 // Note that malformed bounds never result in a compile time error, even |
| 721 // in checked mode. Therefore, overwrite finalization with kFinalize | 725 // in checked mode. Therefore, overwrite finalization with kFinalize |
| 722 // when finalizing the malformed type. | 726 // when finalizing the malformed type. |
| 723 FinalizeMalformedType( | 727 FinalizeMalformedType( |
| 724 malformed_error, | 728 malformed_error, |
| 725 cls, parameterized_type, kFinalize, | 729 cls, parameterized_type, kFinalize, |
| 726 "type arguments of type '%s' are not within bounds", | 730 "type arguments of type '%s' are not within bounds", |
| 727 String::Handle(parameterized_type.Name()).ToCString()); | 731 String::Handle(parameterized_type.Name()).ToCString()); |
| 728 return parameterized_type.raw(); | 732 return parameterized_type.raw(); |
| 729 } | 733 } |
| 730 } | 734 } |
| 731 } else { | 735 } else { |
| 732 parameterized_type.set_is_finalized(); | 736 // Mark the type as finalized. |
| 737 if (parameterized_type.IsInstantiated()) { |
| 738 parameterized_type.set_is_finalized_instantiated(); |
| 739 } else { |
| 740 parameterized_type.set_is_finalized_uninstantiated(); |
| 741 } |
| 733 } | 742 } |
| 734 return parameterized_type.Canonicalize(); | 743 return parameterized_type.Canonicalize(); |
| 735 } | 744 } |
| 736 | 745 |
| 737 | 746 |
| 738 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, | 747 void ClassFinalizer::ResolveAndFinalizeSignature(const Class& cls, |
| 739 const Function& function) { | 748 const Function& function) { |
| 740 // Resolve result type. | 749 // Resolve result type. |
| 741 AbstractType& type = AbstractType::Handle(function.result_type()); | 750 AbstractType& type = AbstractType::Handle(function.result_type()); |
| 742 FinalizationKind result_finalization = kFinalize; | 751 FinalizationKind result_finalization = kFinalize; |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 // In production mode, mark the type as malformed only if its type class is | 1307 // In production mode, mark the type as malformed only if its type class is |
| 1299 // not resolved. | 1308 // not resolved. |
| 1300 type.set_malformed_error(error); | 1309 type.set_malformed_error(error); |
| 1301 } else { | 1310 } else { |
| 1302 // In production mode, do not mark the type with a resolved type class as | 1311 // In production mode, do not mark the type with a resolved type class as |
| 1303 // malformed, but make it raw. | 1312 // malformed, but make it raw. |
| 1304 ASSERT(type.HasResolvedTypeClass()); | 1313 ASSERT(type.HasResolvedTypeClass()); |
| 1305 type.set_arguments(AbstractTypeArguments::Handle()); | 1314 type.set_arguments(AbstractTypeArguments::Handle()); |
| 1306 } | 1315 } |
| 1307 if (!type.IsFinalized()) { | 1316 if (!type.IsFinalized()) { |
| 1308 type.set_is_finalized(); | 1317 type.set_is_finalized_instantiated(); |
| 1309 // Do not canonicalize malformed types, since they may not be resolved. | 1318 // Do not canonicalize malformed types, since they may not be resolved. |
| 1310 } else { | 1319 } else { |
| 1311 // The only case where the malformed type was already finalized is when its | 1320 // The only case where the malformed type was already finalized is when its |
| 1312 // type arguments are not within bounds. In that case, we have a prev_error. | 1321 // type arguments are not within bounds. In that case, we have a prev_error. |
| 1313 ASSERT(!prev_error.IsNull()); | 1322 ASSERT(!prev_error.IsNull()); |
| 1314 } | 1323 } |
| 1315 } | 1324 } |
| 1316 | 1325 |
| 1317 | 1326 |
| 1318 void ClassFinalizer::ReportError(const Error& error) { | 1327 void ClassFinalizer::ReportError(const Error& error) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1335 void ClassFinalizer::ReportError(const char* format, ...) { | 1344 void ClassFinalizer::ReportError(const char* format, ...) { |
| 1336 va_list args; | 1345 va_list args; |
| 1337 va_start(args, format); | 1346 va_start(args, format); |
| 1338 const Error& error = Error::Handle( | 1347 const Error& error = Error::Handle( |
| 1339 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); | 1348 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); |
| 1340 va_end(args); | 1349 va_end(args); |
| 1341 ReportError(error); | 1350 ReportError(error); |
| 1342 } | 1351 } |
| 1343 | 1352 |
| 1344 } // namespace dart | 1353 } // namespace dart |
| OLD | NEW |