| 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2042 Isolate::Current()->RegisterClass(result); | 2042 Isolate::Current()->RegisterClass(result); |
| 2043 return result.raw(); | 2043 return result.raw(); |
| 2044 } | 2044 } |
| 2045 | 2045 |
| 2046 | 2046 |
| 2047 | 2047 |
| 2048 static void ReportTooManyTypeArguments(const Class& cls) { | 2048 static void ReportTooManyTypeArguments(const Class& cls) { |
| 2049 Report::MessageF(Report::kError, | 2049 Report::MessageF(Report::kError, |
| 2050 Script::Handle(cls.script()), | 2050 Script::Handle(cls.script()), |
| 2051 cls.token_pos(), | 2051 cls.token_pos(), |
| 2052 Report::AtLocation, |
| 2052 "too many type parameters declared in class '%s' or in its " | 2053 "too many type parameters declared in class '%s' or in its " |
| 2053 "super classes", | 2054 "super classes", |
| 2054 String::Handle(cls.Name()).ToCString()); | 2055 String::Handle(cls.Name()).ToCString()); |
| 2055 UNREACHABLE(); | 2056 UNREACHABLE(); |
| 2056 } | 2057 } |
| 2057 | 2058 |
| 2058 | 2059 |
| 2059 void Class::set_num_type_arguments(intptr_t value) const { | 2060 void Class::set_num_type_arguments(intptr_t value) const { |
| 2060 if (!Utils::IsInt(16, value)) { | 2061 if (!Utils::IsInt(16, value)) { |
| 2061 ReportTooManyTypeArguments(*this); | 2062 ReportTooManyTypeArguments(*this); |
| (...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2891 } | 2892 } |
| 2892 } else if (func.UserVisibleSignature() != | 2893 } else if (func.UserVisibleSignature() != |
| 2893 orig_func.UserVisibleSignature() | 2894 orig_func.UserVisibleSignature() |
| 2894 && !FLAG_ignore_patch_signature_mismatch) { | 2895 && !FLAG_ignore_patch_signature_mismatch) { |
| 2895 // Compare user visible signatures to ignore different implicit parameters | 2896 // Compare user visible signatures to ignore different implicit parameters |
| 2896 // when patching a constructor with a factory. | 2897 // when patching a constructor with a factory. |
| 2897 *error = LanguageError::NewFormatted( | 2898 *error = LanguageError::NewFormatted( |
| 2898 *error, // No previous error. | 2899 *error, // No previous error. |
| 2899 Script::Handle(patch.script()), | 2900 Script::Handle(patch.script()), |
| 2900 func.token_pos(), | 2901 func.token_pos(), |
| 2902 Report::AtLocation, |
| 2901 Report::kError, | 2903 Report::kError, |
| 2902 Heap::kNew, | 2904 Heap::kNew, |
| 2903 "signature mismatch: '%s'", member_name.ToCString()); | 2905 "signature mismatch: '%s'", member_name.ToCString()); |
| 2904 return false; | 2906 return false; |
| 2905 } | 2907 } |
| 2906 } | 2908 } |
| 2907 for (intptr_t i = 0; i < patch_len; i++) { | 2909 for (intptr_t i = 0; i < patch_len; i++) { |
| 2908 func ^= patch_list.At(i); | 2910 func ^= patch_list.At(i); |
| 2909 if (func.IsGenerativeConstructor() || func.IsFactory()) { | 2911 if (func.IsGenerativeConstructor() || func.IsFactory()) { |
| 2910 // Do not preserve the original implicit constructor, if any. | 2912 // Do not preserve the original implicit constructor, if any. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2936 member_name = field.name(); | 2938 member_name = field.name(); |
| 2937 // TODO(iposva): Verify non-public fields only. | 2939 // TODO(iposva): Verify non-public fields only. |
| 2938 | 2940 |
| 2939 // Verify no duplicate additions. | 2941 // Verify no duplicate additions. |
| 2940 orig_field ^= LookupField(member_name); | 2942 orig_field ^= LookupField(member_name); |
| 2941 if (!orig_field.IsNull()) { | 2943 if (!orig_field.IsNull()) { |
| 2942 *error = LanguageError::NewFormatted( | 2944 *error = LanguageError::NewFormatted( |
| 2943 *error, // No previous error. | 2945 *error, // No previous error. |
| 2944 Script::Handle(patch.script()), | 2946 Script::Handle(patch.script()), |
| 2945 field.token_pos(), | 2947 field.token_pos(), |
| 2948 Report::AtLocation, |
| 2946 Report::kError, | 2949 Report::kError, |
| 2947 Heap::kNew, | 2950 Heap::kNew, |
| 2948 "duplicate field: %s", member_name.ToCString()); | 2951 "duplicate field: %s", member_name.ToCString()); |
| 2949 return false; | 2952 return false; |
| 2950 } | 2953 } |
| 2951 new_list.SetAt(i, field); | 2954 new_list.SetAt(i, field); |
| 2952 } | 2955 } |
| 2953 for (intptr_t i = 0; i < orig_len; i++) { | 2956 for (intptr_t i = 0; i < orig_len; i++) { |
| 2954 field ^= orig_list.At(i); | 2957 field ^= orig_list.At(i); |
| 2955 new_list.SetAt(patch_len + i, field); | 2958 new_list.SetAt(patch_len + i, field); |
| (...skipping 3206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6162 // function's signature type. | 6165 // function's signature type. |
| 6163 if (!TypeTest(kIsSubtypeOf, Object::null_type_arguments(), | 6166 if (!TypeTest(kIsSubtypeOf, Object::null_type_arguments(), |
| 6164 other, Object::null_type_arguments(), bound_error, | 6167 other, Object::null_type_arguments(), bound_error, |
| 6165 Heap::kOld)) { | 6168 Heap::kOld)) { |
| 6166 // For more informative error reporting, use the location of the other | 6169 // For more informative error reporting, use the location of the other |
| 6167 // function here, since the caller will use the location of this function. | 6170 // function here, since the caller will use the location of this function. |
| 6168 *bound_error = LanguageError::NewFormatted( | 6171 *bound_error = LanguageError::NewFormatted( |
| 6169 *bound_error, // A bound error if non null. | 6172 *bound_error, // A bound error if non null. |
| 6170 Script::Handle(other.script()), | 6173 Script::Handle(other.script()), |
| 6171 other.token_pos(), | 6174 other.token_pos(), |
| 6175 Report::AtLocation, |
| 6172 Report::kError, | 6176 Report::kError, |
| 6173 Heap::kNew, | 6177 Heap::kNew, |
| 6174 "signature type '%s' of function '%s' is not a subtype of signature " | 6178 "signature type '%s' of function '%s' is not a subtype of signature " |
| 6175 "type '%s' of function '%s'", | 6179 "type '%s' of function '%s'", |
| 6176 String::Handle(UserVisibleSignature()).ToCString(), | 6180 String::Handle(UserVisibleSignature()).ToCString(), |
| 6177 String::Handle(UserVisibleName()).ToCString(), | 6181 String::Handle(UserVisibleName()).ToCString(), |
| 6178 String::Handle(other.UserVisibleSignature()).ToCString(), | 6182 String::Handle(other.UserVisibleSignature()).ToCString(), |
| 6179 String::Handle(other.UserVisibleName()).ToCString()); | 6183 String::Handle(other.UserVisibleName()).ToCString()); |
| 6180 return false; | 6184 return false; |
| 6181 } | 6185 } |
| (...skipping 3051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9233 obj = array_.At(next_ix_); | 9237 obj = array_.At(next_ix_); |
| 9234 } | 9238 } |
| 9235 } | 9239 } |
| 9236 | 9240 |
| 9237 | 9241 |
| 9238 static void ReportTooManyImports(const Library& lib) { | 9242 static void ReportTooManyImports(const Library& lib) { |
| 9239 const String& url = String::Handle(lib.url()); | 9243 const String& url = String::Handle(lib.url()); |
| 9240 Report::MessageF(Report::kError, | 9244 Report::MessageF(Report::kError, |
| 9241 Script::Handle(lib.LookupScript(url)), | 9245 Script::Handle(lib.LookupScript(url)), |
| 9242 Scanner::kNoSourcePos, | 9246 Scanner::kNoSourcePos, |
| 9247 Report::AtLocation, |
| 9243 "too many imports in library '%s'", | 9248 "too many imports in library '%s'", |
| 9244 url.ToCString()); | 9249 url.ToCString()); |
| 9245 UNREACHABLE(); | 9250 UNREACHABLE(); |
| 9246 } | 9251 } |
| 9247 | 9252 |
| 9248 | 9253 |
| 9249 void Library::set_num_imports(intptr_t value) const { | 9254 void Library::set_num_imports(intptr_t value) const { |
| 9250 if (!Utils::IsUint(16, value)) { | 9255 if (!Utils::IsUint(16, value)) { |
| 9251 ReportTooManyImports(*this); | 9256 ReportTooManyImports(*this); |
| 9252 } | 9257 } |
| (...skipping 5243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14496 RawObject* raw = Object::Allocate(LanguageError::kClassId, | 14501 RawObject* raw = Object::Allocate(LanguageError::kClassId, |
| 14497 LanguageError::InstanceSize(), | 14502 LanguageError::InstanceSize(), |
| 14498 Heap::kOld); | 14503 Heap::kOld); |
| 14499 return reinterpret_cast<RawLanguageError*>(raw); | 14504 return reinterpret_cast<RawLanguageError*>(raw); |
| 14500 } | 14505 } |
| 14501 | 14506 |
| 14502 | 14507 |
| 14503 RawLanguageError* LanguageError::NewFormattedV(const Error& prev_error, | 14508 RawLanguageError* LanguageError::NewFormattedV(const Error& prev_error, |
| 14504 const Script& script, | 14509 const Script& script, |
| 14505 intptr_t token_pos, | 14510 intptr_t token_pos, |
| 14511 bool report_after_token, |
| 14506 Report::Kind kind, | 14512 Report::Kind kind, |
| 14507 Heap::Space space, | 14513 Heap::Space space, |
| 14508 const char* format, | 14514 const char* format, |
| 14509 va_list args) { | 14515 va_list args) { |
| 14510 ASSERT(Object::language_error_class() != Class::null()); | 14516 ASSERT(Object::language_error_class() != Class::null()); |
| 14511 LanguageError& result = LanguageError::Handle(); | 14517 LanguageError& result = LanguageError::Handle(); |
| 14512 { | 14518 { |
| 14513 RawObject* raw = Object::Allocate(LanguageError::kClassId, | 14519 RawObject* raw = Object::Allocate(LanguageError::kClassId, |
| 14514 LanguageError::InstanceSize(), | 14520 LanguageError::InstanceSize(), |
| 14515 space); | 14521 space); |
| 14516 NoSafepointScope no_safepoint; | 14522 NoSafepointScope no_safepoint; |
| 14517 result ^= raw; | 14523 result ^= raw; |
| 14518 } | 14524 } |
| 14519 result.set_previous_error(prev_error); | 14525 result.set_previous_error(prev_error); |
| 14520 result.set_script(script); | 14526 result.set_script(script); |
| 14521 result.set_token_pos(token_pos); | 14527 result.set_token_pos(token_pos); |
| 14528 result.set_report_after_token(report_after_token); |
| 14522 result.set_kind(kind); | 14529 result.set_kind(kind); |
| 14523 result.set_message(String::Handle( | 14530 result.set_message(String::Handle( |
| 14524 String::NewFormattedV(format, args, space))); | 14531 String::NewFormattedV(format, args, space))); |
| 14525 return result.raw(); | 14532 return result.raw(); |
| 14526 } | 14533 } |
| 14527 | 14534 |
| 14528 | 14535 |
| 14529 RawLanguageError* LanguageError::NewFormatted(const Error& prev_error, | 14536 RawLanguageError* LanguageError::NewFormatted(const Error& prev_error, |
| 14530 const Script& script, | 14537 const Script& script, |
| 14531 intptr_t token_pos, | 14538 intptr_t token_pos, |
| 14539 bool report_after_token, |
| 14532 Report::Kind kind, | 14540 Report::Kind kind, |
| 14533 Heap::Space space, | 14541 Heap::Space space, |
| 14534 const char* format, ...) { | 14542 const char* format, ...) { |
| 14535 va_list args; | 14543 va_list args; |
| 14536 va_start(args, format); | 14544 va_start(args, format); |
| 14537 RawLanguageError* result = LanguageError::NewFormattedV( | 14545 RawLanguageError* result = LanguageError::NewFormattedV( |
| 14538 prev_error, script, token_pos, kind, space, format, args); | 14546 prev_error, script, token_pos, report_after_token, |
| 14547 kind, space, format, args); |
| 14539 NoSafepointScope no_safepoint; | 14548 NoSafepointScope no_safepoint; |
| 14540 va_end(args); | 14549 va_end(args); |
| 14541 return result; | 14550 return result; |
| 14542 } | 14551 } |
| 14543 | 14552 |
| 14544 | 14553 |
| 14545 RawLanguageError* LanguageError::New(const String& formatted_message, | 14554 RawLanguageError* LanguageError::New(const String& formatted_message, |
| 14546 Report::Kind kind, | 14555 Report::Kind kind, |
| 14547 Heap::Space space) { | 14556 Heap::Space space) { |
| 14548 ASSERT(Object::language_error_class() != Class::null()); | 14557 ASSERT(Object::language_error_class() != Class::null()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 14569 StorePointer(&raw_ptr()->script_, value.raw()); | 14578 StorePointer(&raw_ptr()->script_, value.raw()); |
| 14570 } | 14579 } |
| 14571 | 14580 |
| 14572 | 14581 |
| 14573 void LanguageError::set_token_pos(intptr_t token_pos) const { | 14582 void LanguageError::set_token_pos(intptr_t token_pos) const { |
| 14574 ASSERT(Scanner::ValidSourcePosition(token_pos)); | 14583 ASSERT(Scanner::ValidSourcePosition(token_pos)); |
| 14575 StoreNonPointer(&raw_ptr()->token_pos_, token_pos); | 14584 StoreNonPointer(&raw_ptr()->token_pos_, token_pos); |
| 14576 } | 14585 } |
| 14577 | 14586 |
| 14578 | 14587 |
| 14588 void LanguageError::set_report_after_token(bool value) { |
| 14589 StoreNonPointer(&raw_ptr()->report_after_token_, value); |
| 14590 } |
| 14591 |
| 14592 |
| 14579 void LanguageError::set_kind(uint8_t value) const { | 14593 void LanguageError::set_kind(uint8_t value) const { |
| 14580 StoreNonPointer(&raw_ptr()->kind_, value); | 14594 StoreNonPointer(&raw_ptr()->kind_, value); |
| 14581 } | 14595 } |
| 14582 | 14596 |
| 14583 | 14597 |
| 14584 void LanguageError::set_message(const String& value) const { | 14598 void LanguageError::set_message(const String& value) const { |
| 14585 StorePointer(&raw_ptr()->message_, value.raw()); | 14599 StorePointer(&raw_ptr()->message_, value.raw()); |
| 14586 } | 14600 } |
| 14587 | 14601 |
| 14588 | 14602 |
| 14589 void LanguageError::set_formatted_message(const String& value) const { | 14603 void LanguageError::set_formatted_message(const String& value) const { |
| 14590 StorePointer(&raw_ptr()->formatted_message_, value.raw()); | 14604 StorePointer(&raw_ptr()->formatted_message_, value.raw()); |
| 14591 } | 14605 } |
| 14592 | 14606 |
| 14593 | 14607 |
| 14594 RawString* LanguageError::FormatMessage() const { | 14608 RawString* LanguageError::FormatMessage() const { |
| 14595 if (formatted_message() != String::null()) { | 14609 if (formatted_message() != String::null()) { |
| 14596 return formatted_message(); | 14610 return formatted_message(); |
| 14597 } | 14611 } |
| 14598 String& result = String::Handle( | 14612 String& result = String::Handle( |
| 14599 Report::PrependSnippet(kind(), | 14613 Report::PrependSnippet(kind(), |
| 14600 Script::Handle(script()), | 14614 Script::Handle(script()), |
| 14601 token_pos(), | 14615 token_pos(), |
| 14616 report_after_token(), |
| 14602 String::Handle(message()))); | 14617 String::Handle(message()))); |
| 14603 // Prepend previous error message. | 14618 // Prepend previous error message. |
| 14604 const Error& prev_error = Error::Handle(previous_error()); | 14619 const Error& prev_error = Error::Handle(previous_error()); |
| 14605 if (!prev_error.IsNull()) { | 14620 if (!prev_error.IsNull()) { |
| 14606 result = String::Concat( | 14621 result = String::Concat( |
| 14607 String::Handle(String::New(prev_error.ToErrorCString())), result); | 14622 String::Handle(String::New(prev_error.ToErrorCString())), result); |
| 14608 } | 14623 } |
| 14609 set_formatted_message(result); | 14624 set_formatted_message(result); |
| 14610 return result.raw(); | 14625 return result.raw(); |
| 14611 } | 14626 } |
| (...skipping 2128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16740 const String& type_param_name = String::Handle(UserVisibleName()); | 16755 const String& type_param_name = String::Handle(UserVisibleName()); |
| 16741 const Class& cls = Class::Handle(parameterized_class()); | 16756 const Class& cls = Class::Handle(parameterized_class()); |
| 16742 const String& class_name = String::Handle(cls.Name()); | 16757 const String& class_name = String::Handle(cls.Name()); |
| 16743 const Script& script = Script::Handle(cls.script()); | 16758 const Script& script = Script::Handle(cls.script()); |
| 16744 // Since the bound may have been canonicalized, its token index is | 16759 // Since the bound may have been canonicalized, its token index is |
| 16745 // meaningless, therefore use the token index of this type parameter. | 16760 // meaningless, therefore use the token index of this type parameter. |
| 16746 *bound_error = LanguageError::NewFormatted( | 16761 *bound_error = LanguageError::NewFormatted( |
| 16747 *bound_error, | 16762 *bound_error, |
| 16748 script, | 16763 script, |
| 16749 token_pos(), | 16764 token_pos(), |
| 16765 Report::AtLocation, |
| 16750 Report::kMalboundedType, | 16766 Report::kMalboundedType, |
| 16751 Heap::kNew, | 16767 Heap::kNew, |
| 16752 "type parameter '%s' of class '%s' must extend bound '%s', " | 16768 "type parameter '%s' of class '%s' must extend bound '%s', " |
| 16753 "but type argument '%s' is not a subtype of '%s'\n", | 16769 "but type argument '%s' is not a subtype of '%s'\n", |
| 16754 type_param_name.ToCString(), | 16770 type_param_name.ToCString(), |
| 16755 class_name.ToCString(), | 16771 class_name.ToCString(), |
| 16756 declared_bound_name.ToCString(), | 16772 declared_bound_name.ToCString(), |
| 16757 bounded_type_name.ToCString(), | 16773 bounded_type_name.ToCString(), |
| 16758 upper_bound_name.ToCString()); | 16774 upper_bound_name.ToCString()); |
| 16759 } | 16775 } |
| (...skipping 5340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22100 return tag_label.ToCString(); | 22116 return tag_label.ToCString(); |
| 22101 } | 22117 } |
| 22102 | 22118 |
| 22103 | 22119 |
| 22104 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 22120 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 22105 Instance::PrintJSONImpl(stream, ref); | 22121 Instance::PrintJSONImpl(stream, ref); |
| 22106 } | 22122 } |
| 22107 | 22123 |
| 22108 | 22124 |
| 22109 } // namespace dart | 22125 } // namespace dart |
| OLD | NEW |