Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: runtime/vm/object.cc

Issue 1743653002: Stop prefixing the library name to type names when reporting a type error with (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: enumerate URIs Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4903 matching lines...) Expand 10 before | Expand all | Expand 10 after
4914 } 4914 }
4915 } 4915 }
4916 ASSERT(result.Equals(*this)); 4916 ASSERT(result.Equals(*this));
4917 ASSERT(!result.IsNull()); 4917 ASSERT(!result.IsNull());
4918 ASSERT(result.IsTypeArguments()); 4918 ASSERT(result.IsTypeArguments());
4919 ASSERT(result.IsCanonical()); 4919 ASSERT(result.IsCanonical());
4920 return result.raw(); 4920 return result.raw();
4921 } 4921 }
4922 4922
4923 4923
4924 RawString* TypeArguments::EnumerateURIs() const {
4925 if (IsNull()) {
4926 return Symbols::Empty().raw();
4927 }
4928 Zone* zone = Thread::Current()->zone();
4929 AbstractType& type = AbstractType::Handle(zone);
4930 const intptr_t num_types = Length();
4931 GrowableHandlePtrArray<const String> pieces(zone, num_types);
4932 for (intptr_t i = 0; i < num_types; i++) {
4933 type = TypeAt(i);
4934 pieces.Add(String::Handle(zone, type.EnumerateURIs()));
4935 }
4936 return Symbols::FromConcatAll(pieces);
4937 }
4938
4939
4924 const char* TypeArguments::ToCString() const { 4940 const char* TypeArguments::ToCString() const {
4925 if (IsNull()) { 4941 if (IsNull()) {
4926 return "NULL TypeArguments"; 4942 return "NULL TypeArguments";
4927 } 4943 }
4928 const char* prev_cstr = "TypeArguments:"; 4944 const char* prev_cstr = "TypeArguments:";
4929 for (int i = 0; i < Length(); i++) { 4945 for (int i = 0; i < Length(); i++) {
4930 const AbstractType& type_at = AbstractType::Handle(TypeAt(i)); 4946 const AbstractType& type_at = AbstractType::Handle(TypeAt(i));
4931 const char* type_cstr = type_at.IsNull() ? "null" : type_at.ToCString(); 4947 const char* type_cstr = type_at.IsNull() ? "null" : type_at.ToCString();
4932 char* chars = OS::SCreate(Thread::Current()->zone(), 4948 char* chars = OS::SCreate(Thread::Current()->zone(),
4933 "%s [%s]", prev_cstr, type_cstr); 4949 "%s [%s]", prev_cstr, type_cstr);
(...skipping 9906 matching lines...) Expand 10 before | Expand all | Expand 10 after
14840 } 14856 }
14841 14857
14842 14858
14843 RawAbstractType* AbstractType::Canonicalize(TrailPtr trail) const { 14859 RawAbstractType* AbstractType::Canonicalize(TrailPtr trail) const {
14844 // AbstractType is an abstract class. 14860 // AbstractType is an abstract class.
14845 UNREACHABLE(); 14861 UNREACHABLE();
14846 return NULL; 14862 return NULL;
14847 } 14863 }
14848 14864
14849 14865
14866 RawString* AbstractType::EnumerateURIs() const {
14867 // AbstractType is an abstract class.
14868 UNREACHABLE();
14869 return NULL;
14870 }
14871
14872
14850 RawAbstractType* AbstractType::OnlyBuddyInTrail(TrailPtr trail) const { 14873 RawAbstractType* AbstractType::OnlyBuddyInTrail(TrailPtr trail) const {
14851 if (trail == NULL) { 14874 if (trail == NULL) {
14852 return AbstractType::null(); 14875 return AbstractType::null();
14853 } 14876 }
14854 const intptr_t len = trail->length(); 14877 const intptr_t len = trail->length();
14855 ASSERT((len % 2) == 0); 14878 ASSERT((len % 2) == 0);
14856 for (intptr_t i = 0; i < len; i += 2) { 14879 for (intptr_t i = 0; i < len; i += 2) {
14857 ASSERT(trail->At(i).IsZoneHandle()); 14880 ASSERT(trail->At(i).IsZoneHandle());
14858 ASSERT(trail->At(i + 1).IsZoneHandle()); 14881 ASSERT(trail->At(i + 1).IsZoneHandle());
14859 if (trail->At(i).raw() == this->raw()) { 14882 if (trail->At(i).raw() == this->raw()) {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
15036 name_visibility)); 15059 name_visibility));
15037 pieces.Add(args_name); 15060 pieces.Add(args_name);
15038 } 15061 }
15039 // The name is only used for type checking and debugging purposes. 15062 // The name is only used for type checking and debugging purposes.
15040 // Unless profiling data shows otherwise, it is not worth caching the name in 15063 // Unless profiling data shows otherwise, it is not worth caching the name in
15041 // the type. 15064 // the type.
15042 return Symbols::FromConcatAll(pieces); 15065 return Symbols::FromConcatAll(pieces);
15043 } 15066 }
15044 15067
15045 15068
15069 // Same as user visible name, but including the URI of each occuring type.
15070 // Used to report errors involving types with identical names.
15071 //
15072 // e.g.
15073 // MyClass<String> -> MyClass<String> where
15074 // MyClass is from my_uri
15075 // String is from dart:core
15076 // MyClass<dynamic, T> -> MyClass<dynamic, T> where
15077 // MyClass is from my_uri
15078 // T of OtherClass is from other_uri
15079 // (MyClass) => int -> (MyClass) => int where
15080 // MyClass is from my_uri
15081 // int is from dart:core
15082 RawString* AbstractType::UserVisibleNameWithURI() const {
15083 Zone* zone = Thread::Current()->zone();
15084 GrowableHandlePtrArray<const String> pieces(zone, 3);
15085 pieces.Add(String::Handle(zone, BuildName(kUserVisibleName)));
15086 pieces.Add(Symbols::SpaceWhereNewLine());
15087 pieces.Add(String::Handle(zone, EnumerateURIs()));
15088 return Symbols::FromConcatAll(pieces);
15089 }
15090
15091
15046 RawString* AbstractType::ClassName() const { 15092 RawString* AbstractType::ClassName() const {
15047 if (HasResolvedTypeClass()) { 15093 if (HasResolvedTypeClass()) {
15048 return Class::Handle(type_class()).Name(); 15094 return Class::Handle(type_class()).Name();
15049 } else { 15095 } else {
15050 return UnresolvedClass::Handle(unresolved_class()).Name(); 15096 return UnresolvedClass::Handle(unresolved_class()).Name();
15051 } 15097 }
15052 } 15098 }
15053 15099
15054 15100
15055 bool AbstractType::IsNullType() const { 15101 bool AbstractType::IsNullType() const {
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
15780 canonical_types = new_canonical_types.raw(); 15826 canonical_types = new_canonical_types.raw();
15781 } 15827 }
15782 canonical_types.SetAt(index, *this); 15828 canonical_types.SetAt(index, *this);
15783 ASSERT(IsOld()); 15829 ASSERT(IsOld());
15784 ASSERT(type_args.IsNull() || type_args.IsOld()); 15830 ASSERT(type_args.IsNull() || type_args.IsOld());
15785 SetCanonical(); 15831 SetCanonical();
15786 return this->raw(); 15832 return this->raw();
15787 } 15833 }
15788 15834
15789 15835
15836 RawString* Type::EnumerateURIs() const {
15837 if (IsDynamicType()) {
15838 return Symbols::Empty().raw();
15839 }
15840 Zone* zone = Thread::Current()->zone();
15841 GrowableHandlePtrArray<const String> pieces(zone, 6);
15842 const Class& cls = Class::Handle(zone, type_class());
15843 pieces.Add(Symbols::TwoSpaces());
15844 pieces.Add(String::Handle(zone, cls.UserVisibleName()));
15845 pieces.Add(Symbols::SpaceIsFromSpace());
15846 const Library& library = Library::Handle(zone, cls.library());
15847 pieces.Add(String::Handle(zone, library.url()));
15848 pieces.Add(Symbols::NewLine());
15849 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments());
15850 pieces.Add(String::Handle(zone, type_args.EnumerateURIs()));
15851 return Symbols::FromConcatAll(pieces);
15852 }
15853
15854
15790 intptr_t Type::Hash() const { 15855 intptr_t Type::Hash() const {
15791 ASSERT(IsFinalized()); 15856 ASSERT(IsFinalized());
15792 uint32_t result = 1; 15857 uint32_t result = 1;
15793 if (IsMalformed()) return result; 15858 if (IsMalformed()) return result;
15794 result = CombineHashes(result, Class::Handle(type_class()).id()); 15859 result = CombineHashes(result, Class::Handle(type_class()).id());
15795 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash()); 15860 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash());
15796 return FinalizeHash(result); 15861 return FinalizeHash(result);
15797 } 15862 }
15798 15863
15799 15864
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
16271 canonical_types = new_canonical_types.raw(); 16336 canonical_types = new_canonical_types.raw();
16272 } 16337 }
16273 canonical_types.SetAt(index, *this); 16338 canonical_types.SetAt(index, *this);
16274 ASSERT(IsOld()); 16339 ASSERT(IsOld());
16275 ASSERT(type_args.IsNull() || type_args.IsOld()); 16340 ASSERT(type_args.IsNull() || type_args.IsOld());
16276 SetCanonical(); 16341 SetCanonical();
16277 return this->raw(); 16342 return this->raw();
16278 } 16343 }
16279 16344
16280 16345
16346 RawString* FunctionType::EnumerateURIs() const {
16347 Zone* zone = Thread::Current()->zone();
16348 // The scope class and type arguments do not appear explicitly in the user
16349 // visible name. The type arguments were used to instantiate the function type
16350 // prior to this call.
16351 const Function& sig_fun = Function::Handle(zone, signature());
16352 AbstractType& type = AbstractType::Handle(zone);
16353 const intptr_t num_params = sig_fun.NumParameters();
16354 GrowableHandlePtrArray<const String> pieces(zone, num_params + 1);
16355 for (intptr_t i = 0; i < num_params; i++) {
16356 type = sig_fun.ParameterTypeAt(i);
16357 pieces.Add(String::Handle(zone, type.EnumerateURIs()));
16358 }
16359 // Handle result type last, since it appears last in the user visible name.
16360 type = sig_fun.result_type();
16361 if (!type.IsDynamicType() && !type.IsVoidType()) {
16362 pieces.Add(String::Handle(zone, type.EnumerateURIs()));
16363 }
16364 return Symbols::FromConcatAll(pieces);
16365 }
16366
16367
16281 intptr_t FunctionType::Hash() const { 16368 intptr_t FunctionType::Hash() const {
16282 ASSERT(IsFinalized()); 16369 ASSERT(IsFinalized());
16283 uint32_t result = 1; 16370 uint32_t result = 1;
16284 if (IsMalformed()) return result; 16371 if (IsMalformed()) return result;
16285 result = CombineHashes(result, Class::Handle(scope_class()).id()); 16372 result = CombineHashes(result, Class::Handle(scope_class()).id());
16286 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash()); 16373 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash());
16287 const Function& sig_fun = Function::Handle(signature()); 16374 const Function& sig_fun = Function::Handle(signature());
16288 AbstractType& type = AbstractType::Handle(sig_fun.result_type()); 16375 AbstractType& type = AbstractType::Handle(sig_fun.result_type());
16289 result = CombineHashes(result, type.Hash()); 16376 result = CombineHashes(result, type.Hash());
16290 result = CombineHashes(result, sig_fun.NumOptionalPositionalParameters()); 16377 result = CombineHashes(result, sig_fun.NumOptionalPositionalParameters());
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
16474 } 16561 }
16475 // TODO(regis): Try to reduce the number of nodes required to represent the 16562 // TODO(regis): Try to reduce the number of nodes required to represent the
16476 // referenced recursive type. 16563 // referenced recursive type.
16477 AbstractType& ref_type = AbstractType::Handle(type()); 16564 AbstractType& ref_type = AbstractType::Handle(type());
16478 ref_type = ref_type.Canonicalize(trail); 16565 ref_type = ref_type.Canonicalize(trail);
16479 set_type(ref_type); 16566 set_type(ref_type);
16480 return raw(); 16567 return raw();
16481 } 16568 }
16482 16569
16483 16570
16571 RawString* TypeRef::EnumerateURIs() const {
16572 return Symbols::Empty().raw(); // Break cycle.
16573 }
16574
16575
16484 intptr_t TypeRef::Hash() const { 16576 intptr_t TypeRef::Hash() const {
16485 // Do not calculate the hash of the referenced type to avoid divergence. 16577 // Do not calculate the hash of the referenced type to avoid divergence.
16486 const uint32_t result = 16578 const uint32_t result =
16487 Class::Handle(AbstractType::Handle(type()).type_class()).id(); 16579 Class::Handle(AbstractType::Handle(type()).type_class()).id();
16488 return FinalizeHash(result); 16580 return FinalizeHash(result);
16489 } 16581 }
16490 16582
16491 16583
16492 RawTypeRef* TypeRef::New() { 16584 RawTypeRef* TypeRef::New() {
16493 RawObject* raw = Object::Allocate(TypeRef::kClassId, 16585 RawObject* raw = Object::Allocate(TypeRef::kClassId,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
16689 upper_bound, // Not cloned yet. 16781 upper_bound, // Not cloned yet.
16690 token_pos()); 16782 token_pos());
16691 clone.SetIsFinalized(); 16783 clone.SetIsFinalized();
16692 AddOnlyBuddyToTrail(&trail, clone); 16784 AddOnlyBuddyToTrail(&trail, clone);
16693 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail); 16785 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail);
16694 clone.set_bound(upper_bound); 16786 clone.set_bound(upper_bound);
16695 return clone.raw(); 16787 return clone.raw();
16696 } 16788 }
16697 16789
16698 16790
16791 RawString* TypeParameter::EnumerateURIs() const {
16792 Zone* zone = Thread::Current()->zone();
16793 GrowableHandlePtrArray<const String> pieces(zone, 4);
16794 pieces.Add(Symbols::TwoSpaces());
16795 pieces.Add(String::Handle(zone, name()));
16796 pieces.Add(Symbols::SpaceOfSpace());
16797 const Class& cls = Class::Handle(zone, parameterized_class());
16798 pieces.Add(String::Handle(zone, cls.UserVisibleName()));
16799 pieces.Add(Symbols::SpaceIsFromSpace());
16800 const Library& library = Library::Handle(zone, cls.library());
16801 pieces.Add(String::Handle(zone, library.url()));
16802 pieces.Add(Symbols::NewLine());
16803 return Symbols::FromConcatAll(pieces);
16804 }
16805
16806
16699 intptr_t TypeParameter::Hash() const { 16807 intptr_t TypeParameter::Hash() const {
16700 ASSERT(IsFinalized()); 16808 ASSERT(IsFinalized());
16701 uint32_t result = Class::Handle(parameterized_class()).id(); 16809 uint32_t result = Class::Handle(parameterized_class()).id();
16702 // No need to include the hash of the bound, since the type parameter is fully 16810 // No need to include the hash of the bound, since the type parameter is fully
16703 // identified by its class and index. 16811 // identified by its class and index.
16704 result = CombineHashes(result, index()); 16812 result = CombineHashes(result, index());
16705 return FinalizeHash(result); 16813 return FinalizeHash(result);
16706 } 16814 }
16707 16815
16708 16816
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
16941 AbstractType& bounded_type = AbstractType::Handle(type()); 17049 AbstractType& bounded_type = AbstractType::Handle(type());
16942 bounded_type = bounded_type.CloneUninstantiated(new_owner, trail); 17050 bounded_type = bounded_type.CloneUninstantiated(new_owner, trail);
16943 AbstractType& upper_bound = AbstractType::Handle(bound()); 17051 AbstractType& upper_bound = AbstractType::Handle(bound());
16944 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail); 17052 upper_bound = upper_bound.CloneUninstantiated(new_owner, trail);
16945 TypeParameter& type_param = TypeParameter::Handle(type_parameter()); 17053 TypeParameter& type_param = TypeParameter::Handle(type_parameter());
16946 type_param ^= type_param.CloneUninstantiated(new_owner, trail); 17054 type_param ^= type_param.CloneUninstantiated(new_owner, trail);
16947 return BoundedType::New(bounded_type, upper_bound, type_param); 17055 return BoundedType::New(bounded_type, upper_bound, type_param);
16948 } 17056 }
16949 17057
16950 17058
17059 RawString* BoundedType::EnumerateURIs() const {
17060 // The bound does not appear in the user visible name.
17061 return AbstractType::Handle(type()).EnumerateURIs();
17062 }
17063
17064
16951 intptr_t BoundedType::Hash() const { 17065 intptr_t BoundedType::Hash() const {
16952 uint32_t result = AbstractType::Handle(type()).Hash(); 17066 uint32_t result = AbstractType::Handle(type()).Hash();
16953 // No need to include the hash of the bound, since the bound is defined by the 17067 // No need to include the hash of the bound, since the bound is defined by the
16954 // type parameter (modulo instantiation state). 17068 // type parameter (modulo instantiation state).
16955 result = CombineHashes(result, 17069 result = CombineHashes(result,
16956 TypeParameter::Handle(type_parameter()).Hash()); 17070 TypeParameter::Handle(type_parameter()).Hash());
16957 return FinalizeHash(result); 17071 return FinalizeHash(result);
16958 } 17072 }
16959 17073
16960 17074
(...skipping 4644 matching lines...) Expand 10 before | Expand all | Expand 10 after
21605 return UserTag::null(); 21719 return UserTag::null();
21606 } 21720 }
21607 21721
21608 21722
21609 const char* UserTag::ToCString() const { 21723 const char* UserTag::ToCString() const {
21610 const String& tag_label = String::Handle(label()); 21724 const String& tag_label = String::Handle(label());
21611 return tag_label.ToCString(); 21725 return tag_label.ToCString();
21612 } 21726 }
21613 21727
21614 } // namespace dart 21728 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698