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 6136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6147 // For more informative error reporting, use the location of the other | 6147 // For more informative error reporting, use the location of the other |
6148 // function here, since the caller will use the location of this function. | 6148 // function here, since the caller will use the location of this function. |
6149 *bound_error = LanguageError::NewFormatted( | 6149 *bound_error = LanguageError::NewFormatted( |
6150 *bound_error, // A bound error if non null. | 6150 *bound_error, // A bound error if non null. |
6151 Script::Handle(other.script()), | 6151 Script::Handle(other.script()), |
6152 other.token_pos(), | 6152 other.token_pos(), |
6153 Report::AtLocation, | 6153 Report::AtLocation, |
6154 Report::kError, | 6154 Report::kError, |
6155 Heap::kNew, | 6155 Heap::kNew, |
6156 "signature type '%s' of function '%s' is not a subtype of signature " | 6156 "signature type '%s' of function '%s' is not a subtype of signature " |
6157 "type '%s' of function '%s'", | 6157 "type '%s' of function '%s' where\n%s%s", |
6158 String::Handle(UserVisibleSignature()).ToCString(), | 6158 String::Handle(UserVisibleSignature()).ToCString(), |
6159 String::Handle(UserVisibleName()).ToCString(), | 6159 String::Handle(UserVisibleName()).ToCString(), |
6160 String::Handle(other.UserVisibleSignature()).ToCString(), | 6160 String::Handle(other.UserVisibleSignature()).ToCString(), |
6161 String::Handle(other.UserVisibleName()).ToCString()); | 6161 String::Handle(other.UserVisibleName()).ToCString(), |
| 6162 String::Handle(FunctionType::Handle( |
| 6163 SignatureType()).EnumerateURIs()).ToCString(), |
| 6164 String::Handle(FunctionType::Handle( |
| 6165 other.SignatureType()).EnumerateURIs()).ToCString()); |
6162 return false; | 6166 return false; |
6163 } | 6167 } |
6164 // We should also check that if the other function explicitly specifies a | 6168 // We should also check that if the other function explicitly specifies a |
6165 // default value for a formal parameter, this function does not specify a | 6169 // default value for a formal parameter, this function does not specify a |
6166 // different default value for the same parameter. However, this check is not | 6170 // different default value for the same parameter. However, this check is not |
6167 // possible in the current implementation, because the default parameter | 6171 // possible in the current implementation, because the default parameter |
6168 // values are not stored in the Function object, but discarded after a | 6172 // values are not stored in the Function object, but discarded after a |
6169 // function is compiled. | 6173 // function is compiled. |
6170 return true; | 6174 return true; |
6171 } | 6175 } |
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7959 | 7963 |
7960 // Handle the current token. | 7964 // Handle the current token. |
7961 if (curr == Token::kSTRING) { | 7965 if (curr == Token::kSTRING) { |
7962 bool escape_characters = false; | 7966 bool escape_characters = false; |
7963 for (intptr_t i = 0; i < literal.Length(); i++) { | 7967 for (intptr_t i = 0; i < literal.Length(); i++) { |
7964 if (NeedsEscapeSequence(literal.CharAt(i))) { | 7968 if (NeedsEscapeSequence(literal.CharAt(i))) { |
7965 escape_characters = true; | 7969 escape_characters = true; |
7966 } | 7970 } |
7967 } | 7971 } |
7968 if ((prev != Token::kINTERPOL_VAR) && (prev != Token::kINTERPOL_END)) { | 7972 if ((prev != Token::kINTERPOL_VAR) && (prev != Token::kINTERPOL_END)) { |
7969 literals.Add(Symbols::DoubleQuotes()); | 7973 literals.Add(Symbols::DoubleQuote()); |
7970 } | 7974 } |
7971 if (escape_characters) { | 7975 if (escape_characters) { |
7972 literal = String::EscapeSpecialCharacters(literal); | 7976 literal = String::EscapeSpecialCharacters(literal); |
7973 literals.Add(literal); | 7977 literals.Add(literal); |
7974 } else { | 7978 } else { |
7975 literals.Add(literal); | 7979 literals.Add(literal); |
7976 } | 7980 } |
7977 if ((next != Token::kINTERPOL_VAR) && (next != Token::kINTERPOL_START)) { | 7981 if ((next != Token::kINTERPOL_VAR) && (next != Token::kINTERPOL_START)) { |
7978 literals.Add(Symbols::DoubleQuotes()); | 7982 literals.Add(Symbols::DoubleQuote()); |
7979 } | 7983 } |
7980 } else if (curr == Token::kINTERPOL_VAR) { | 7984 } else if (curr == Token::kINTERPOL_VAR) { |
7981 literals.Add(Symbols::Dollar()); | 7985 literals.Add(Symbols::Dollar()); |
7982 if (literal.CharAt(0) == Library::kPrivateIdentifierStart) { | 7986 if (literal.CharAt(0) == Library::kPrivateIdentifierStart) { |
7983 literal = String::SubString(literal, 0, literal.Length() - private_len); | 7987 literal = String::SubString(literal, 0, literal.Length() - private_len); |
7984 } | 7988 } |
7985 literals.Add(literal); | 7989 literals.Add(literal); |
7986 } else if (curr == Token::kIDENT) { | 7990 } else if (curr == Token::kIDENT) { |
7987 if (literal.CharAt(0) == Library::kPrivateIdentifierStart) { | 7991 if (literal.CharAt(0) == Library::kPrivateIdentifierStart) { |
7988 literal = String::SubString(literal, 0, literal.Length() - private_len); | 7992 literal = String::SubString(literal, 0, literal.Length() - private_len); |
(...skipping 7332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15321 // MyClass<dynamic, T> -> MyClass<dynamic, T> where | 15325 // MyClass<dynamic, T> -> MyClass<dynamic, T> where |
15322 // MyClass is from my_uri | 15326 // MyClass is from my_uri |
15323 // T of OtherClass is from other_uri | 15327 // T of OtherClass is from other_uri |
15324 // (MyClass) => int -> (MyClass) => int where | 15328 // (MyClass) => int -> (MyClass) => int where |
15325 // MyClass is from my_uri | 15329 // MyClass is from my_uri |
15326 // int is from dart:core | 15330 // int is from dart:core |
15327 RawString* AbstractType::UserVisibleNameWithURI() const { | 15331 RawString* AbstractType::UserVisibleNameWithURI() const { |
15328 Zone* zone = Thread::Current()->zone(); | 15332 Zone* zone = Thread::Current()->zone(); |
15329 GrowableHandlePtrArray<const String> pieces(zone, 3); | 15333 GrowableHandlePtrArray<const String> pieces(zone, 3); |
15330 pieces.Add(String::Handle(zone, BuildName(kUserVisibleName))); | 15334 pieces.Add(String::Handle(zone, BuildName(kUserVisibleName))); |
15331 pieces.Add(Symbols::SpaceWhereNewLine()); | 15335 if (!IsDynamicType() && !IsVoidType()) { |
15332 pieces.Add(String::Handle(zone, EnumerateURIs())); | 15336 pieces.Add(Symbols::SpaceWhereNewLine()); |
| 15337 pieces.Add(String::Handle(zone, EnumerateURIs())); |
| 15338 } |
15333 return Symbols::FromConcatAll(pieces); | 15339 return Symbols::FromConcatAll(pieces); |
15334 } | 15340 } |
15335 | 15341 |
15336 | 15342 |
15337 RawString* AbstractType::ClassName() const { | 15343 RawString* AbstractType::ClassName() const { |
15338 if (HasResolvedTypeClass()) { | 15344 if (HasResolvedTypeClass()) { |
15339 return Class::Handle(type_class()).Name(); | 15345 return Class::Handle(type_class()).Name(); |
15340 } else { | 15346 } else { |
15341 return UnresolvedClass::Handle(unresolved_class()).Name(); | 15347 return UnresolvedClass::Handle(unresolved_class()).Name(); |
15342 } | 15348 } |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16043 return this->raw(); | 16049 return this->raw(); |
16044 } | 16050 } |
16045 set_arguments(type_args); | 16051 set_arguments(type_args); |
16046 ASSERT(type_args.IsNull() || type_args.IsOld()); | 16052 ASSERT(type_args.IsNull() || type_args.IsOld()); |
16047 | 16053 |
16048 return cls.LookupOrAddCanonicalType(*this, index); | 16054 return cls.LookupOrAddCanonicalType(*this, index); |
16049 } | 16055 } |
16050 | 16056 |
16051 | 16057 |
16052 RawString* Type::EnumerateURIs() const { | 16058 RawString* Type::EnumerateURIs() const { |
16053 if (IsDynamicType()) { | 16059 if (IsDynamicType() || IsVoidType()) { |
16054 return Symbols::Empty().raw(); | 16060 return Symbols::Empty().raw(); |
16055 } | 16061 } |
16056 Zone* zone = Thread::Current()->zone(); | 16062 Zone* zone = Thread::Current()->zone(); |
16057 GrowableHandlePtrArray<const String> pieces(zone, 6); | 16063 GrowableHandlePtrArray<const String> pieces(zone, 6); |
16058 const Class& cls = Class::Handle(zone, type_class()); | 16064 const Class& cls = Class::Handle(zone, type_class()); |
16059 pieces.Add(Symbols::TwoSpaces()); | 16065 pieces.Add(Symbols::TwoSpaces()); |
16060 pieces.Add(String::Handle(zone, cls.UserVisibleName())); | 16066 pieces.Add(String::Handle(zone, cls.UserVisibleName())); |
16061 pieces.Add(Symbols::SpaceIsFromSpace()); | 16067 pieces.Add(Symbols::SpaceIsFromSpace()); |
16062 const Library& library = Library::Handle(zone, cls.library()); | 16068 const Library& library = Library::Handle(zone, cls.library()); |
16063 pieces.Add(String::Handle(zone, library.url())); | 16069 pieces.Add(String::Handle(zone, library.url())); |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16533 const Function& sig_fun = Function::Handle(zone, signature()); | 16539 const Function& sig_fun = Function::Handle(zone, signature()); |
16534 AbstractType& type = AbstractType::Handle(zone); | 16540 AbstractType& type = AbstractType::Handle(zone); |
16535 const intptr_t num_params = sig_fun.NumParameters(); | 16541 const intptr_t num_params = sig_fun.NumParameters(); |
16536 GrowableHandlePtrArray<const String> pieces(zone, num_params + 1); | 16542 GrowableHandlePtrArray<const String> pieces(zone, num_params + 1); |
16537 for (intptr_t i = 0; i < num_params; i++) { | 16543 for (intptr_t i = 0; i < num_params; i++) { |
16538 type = sig_fun.ParameterTypeAt(i); | 16544 type = sig_fun.ParameterTypeAt(i); |
16539 pieces.Add(String::Handle(zone, type.EnumerateURIs())); | 16545 pieces.Add(String::Handle(zone, type.EnumerateURIs())); |
16540 } | 16546 } |
16541 // Handle result type last, since it appears last in the user visible name. | 16547 // Handle result type last, since it appears last in the user visible name. |
16542 type = sig_fun.result_type(); | 16548 type = sig_fun.result_type(); |
16543 if (!type.IsDynamicType() && !type.IsVoidType()) { | 16549 pieces.Add(String::Handle(zone, type.EnumerateURIs())); |
16544 pieces.Add(String::Handle(zone, type.EnumerateURIs())); | |
16545 } | |
16546 return Symbols::FromConcatAll(pieces); | 16550 return Symbols::FromConcatAll(pieces); |
16547 } | 16551 } |
16548 | 16552 |
16549 | 16553 |
16550 intptr_t FunctionType::Hash() const { | 16554 intptr_t FunctionType::Hash() const { |
16551 ASSERT(IsFinalized()); | 16555 ASSERT(IsFinalized()); |
16552 uint32_t result = 1; | 16556 uint32_t result = 1; |
16553 if (IsMalformed()) return result; | 16557 if (IsMalformed()) return result; |
16554 result = CombineHashes(result, Class::Handle(scope_class()).id()); | 16558 result = CombineHashes(result, Class::Handle(scope_class()).id()); |
16555 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash()); | 16559 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash()); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16744 // TODO(regis): Try to reduce the number of nodes required to represent the | 16748 // TODO(regis): Try to reduce the number of nodes required to represent the |
16745 // referenced recursive type. | 16749 // referenced recursive type. |
16746 AbstractType& ref_type = AbstractType::Handle(type()); | 16750 AbstractType& ref_type = AbstractType::Handle(type()); |
16747 ref_type = ref_type.Canonicalize(trail); | 16751 ref_type = ref_type.Canonicalize(trail); |
16748 set_type(ref_type); | 16752 set_type(ref_type); |
16749 return raw(); | 16753 return raw(); |
16750 } | 16754 } |
16751 | 16755 |
16752 | 16756 |
16753 RawString* TypeRef::EnumerateURIs() const { | 16757 RawString* TypeRef::EnumerateURIs() const { |
16754 return Symbols::Empty().raw(); // Break cycle. | 16758 const AbstractType& ref_type = AbstractType::Handle(type()); |
| 16759 ASSERT(!ref_type.IsDynamicType() && !ref_type.IsVoidType()); |
| 16760 Zone* zone = Thread::Current()->zone(); |
| 16761 GrowableHandlePtrArray<const String> pieces(zone, 6); |
| 16762 const Class& cls = Class::Handle(zone, ref_type.type_class()); |
| 16763 pieces.Add(Symbols::TwoSpaces()); |
| 16764 pieces.Add(String::Handle(zone, cls.UserVisibleName())); |
| 16765 // Break cycle by not printing type arguments, but '<optimized out>' instead. |
| 16766 pieces.Add(Symbols::OptimizedOut()); |
| 16767 pieces.Add(Symbols::SpaceIsFromSpace()); |
| 16768 const Library& library = Library::Handle(zone, cls.library()); |
| 16769 pieces.Add(String::Handle(zone, library.url())); |
| 16770 pieces.Add(Symbols::NewLine()); |
| 16771 return Symbols::FromConcatAll(pieces); |
16755 } | 16772 } |
16756 | 16773 |
16757 | 16774 |
16758 intptr_t TypeRef::Hash() const { | 16775 intptr_t TypeRef::Hash() const { |
16759 // Do not calculate the hash of the referenced type to avoid divergence. | 16776 // Do not calculate the hash of the referenced type to avoid divergence. |
16760 const uint32_t result = | 16777 const uint32_t result = |
16761 Class::Handle(AbstractType::Handle(type()).type_class()).id(); | 16778 Class::Handle(AbstractType::Handle(type()).type_class()).id(); |
16762 return FinalizeHash(result); | 16779 return FinalizeHash(result); |
16763 } | 16780 } |
16764 | 16781 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16913 // Since the bound may have been canonicalized, its token index is | 16930 // Since the bound may have been canonicalized, its token index is |
16914 // meaningless, therefore use the token index of this type parameter. | 16931 // meaningless, therefore use the token index of this type parameter. |
16915 *bound_error = LanguageError::NewFormatted( | 16932 *bound_error = LanguageError::NewFormatted( |
16916 *bound_error, | 16933 *bound_error, |
16917 script, | 16934 script, |
16918 token_pos(), | 16935 token_pos(), |
16919 Report::AtLocation, | 16936 Report::AtLocation, |
16920 Report::kMalboundedType, | 16937 Report::kMalboundedType, |
16921 Heap::kNew, | 16938 Heap::kNew, |
16922 "type parameter '%s' of class '%s' must extend bound '%s', " | 16939 "type parameter '%s' of class '%s' must extend bound '%s', " |
16923 "but type argument '%s' is not a subtype of '%s'\n", | 16940 "but type argument '%s' is not a subtype of '%s' where\n%s%s", |
16924 type_param_name.ToCString(), | 16941 type_param_name.ToCString(), |
16925 class_name.ToCString(), | 16942 class_name.ToCString(), |
16926 declared_bound_name.ToCString(), | 16943 declared_bound_name.ToCString(), |
16927 bounded_type_name.ToCString(), | 16944 bounded_type_name.ToCString(), |
16928 upper_bound_name.ToCString()); | 16945 upper_bound_name.ToCString(), |
| 16946 String::Handle(bounded_type.EnumerateURIs()).ToCString(), |
| 16947 String::Handle(upper_bound.EnumerateURIs()).ToCString()); |
16929 } | 16948 } |
16930 } | 16949 } |
16931 return false; | 16950 return false; |
16932 } | 16951 } |
16933 | 16952 |
16934 | 16953 |
16935 RawAbstractType* TypeParameter::CloneUnfinalized() const { | 16954 RawAbstractType* TypeParameter::CloneUnfinalized() const { |
16936 if (IsFinalized()) { | 16955 if (IsFinalized()) { |
16937 return raw(); | 16956 return raw(); |
16938 } | 16957 } |
(...skipping 4937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21876 return UserTag::null(); | 21895 return UserTag::null(); |
21877 } | 21896 } |
21878 | 21897 |
21879 | 21898 |
21880 const char* UserTag::ToCString() const { | 21899 const char* UserTag::ToCString() const { |
21881 const String& tag_label = String::Handle(label()); | 21900 const String& tag_label = String::Handle(label()); |
21882 return tag_label.ToCString(); | 21901 return tag_label.ToCString(); |
21883 } | 21902 } |
21884 | 21903 |
21885 } // namespace dart | 21904 } // namespace dart |
OLD | NEW |