| 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 4414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4425 // purposes only) while a type argument is still temporarily null. | 4425 // purposes only) while a type argument is still temporarily null. |
| 4426 result = CombineHashes(result, type.IsNull() ? 0 : type.Hash()); | 4426 result = CombineHashes(result, type.IsNull() ? 0 : type.Hash()); |
| 4427 } | 4427 } |
| 4428 return FinalizeHash(result); | 4428 return FinalizeHash(result); |
| 4429 } | 4429 } |
| 4430 | 4430 |
| 4431 | 4431 |
| 4432 RawString* TypeArguments::SubvectorName(intptr_t from_index, | 4432 RawString* TypeArguments::SubvectorName(intptr_t from_index, |
| 4433 intptr_t len, | 4433 intptr_t len, |
| 4434 NameVisibility name_visibility) const { | 4434 NameVisibility name_visibility) const { |
| 4435 Zone* zone = Thread::Current()->zone(); |
| 4435 ASSERT(from_index + len <= Length()); | 4436 ASSERT(from_index + len <= Length()); |
| 4436 String& name = String::Handle(); | 4437 String& name = String::Handle(zone); |
| 4437 const intptr_t num_strings = (len == 0) ? 2 : 2*len + 1; // "<""T"", ""T"">". | 4438 const intptr_t num_strings = (len == 0) ? 2 : 2*len + 1; // "<""T"", ""T"">". |
| 4438 const Array& strings = Array::Handle(Array::New(num_strings)); | 4439 GrowableHandlePtrArray<const String> pieces(zone, num_strings); |
| 4439 intptr_t s = 0; | 4440 pieces.Add(Symbols::LAngleBracket()); |
| 4440 strings.SetAt(s++, Symbols::LAngleBracket()); | |
| 4441 AbstractType& type = AbstractType::Handle(); | 4441 AbstractType& type = AbstractType::Handle(); |
| 4442 for (intptr_t i = 0; i < len; i++) { | 4442 for (intptr_t i = 0; i < len; i++) { |
| 4443 type = TypeAt(from_index + i); | 4443 type = TypeAt(from_index + i); |
| 4444 name = type.BuildName(name_visibility); | 4444 name = type.BuildName(name_visibility); |
| 4445 strings.SetAt(s++, name); | 4445 pieces.Add(name); |
| 4446 if (i < len - 1) { | 4446 if (i < len - 1) { |
| 4447 strings.SetAt(s++, Symbols::CommaSpace()); | 4447 pieces.Add(Symbols::CommaSpace()); |
| 4448 } | 4448 } |
| 4449 } | 4449 } |
| 4450 strings.SetAt(s++, Symbols::RAngleBracket()); | 4450 pieces.Add(Symbols::RAngleBracket()); |
| 4451 ASSERT(s == num_strings); | 4451 ASSERT(pieces.length() == num_strings); |
| 4452 name = String::ConcatAll(strings); | 4452 return Symbols::FromConcatAll(pieces); |
| 4453 return Symbols::New(name); | |
| 4454 } | 4453 } |
| 4455 | 4454 |
| 4456 | 4455 |
| 4457 bool TypeArguments::IsSubvectorEquivalent(const TypeArguments& other, | 4456 bool TypeArguments::IsSubvectorEquivalent(const TypeArguments& other, |
| 4458 intptr_t from_index, | 4457 intptr_t from_index, |
| 4459 intptr_t len, | 4458 intptr_t len, |
| 4460 TrailPtr trail) const { | 4459 TrailPtr trail) const { |
| 4461 if (this->raw() == other.raw()) { | 4460 if (this->raw() == other.raw()) { |
| 4462 return true; | 4461 return true; |
| 4463 } | 4462 } |
| (...skipping 2005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6469 ASSERT(closure_function.signature_class() == signature_class.raw()); | 6468 ASSERT(closure_function.signature_class() == signature_class.raw()); |
| 6470 set_implicit_closure_function(closure_function); | 6469 set_implicit_closure_function(closure_function); |
| 6471 ASSERT(closure_function.IsImplicitClosureFunction()); | 6470 ASSERT(closure_function.IsImplicitClosureFunction()); |
| 6472 return closure_function.raw(); | 6471 return closure_function.raw(); |
| 6473 } | 6472 } |
| 6474 | 6473 |
| 6475 | 6474 |
| 6476 RawString* Function::UserVisibleFormalParameters() const { | 6475 RawString* Function::UserVisibleFormalParameters() const { |
| 6477 // Typically 3, 5,.. elements in 'pieces', e.g.: | 6476 // Typically 3, 5,.. elements in 'pieces', e.g.: |
| 6478 // '_LoadRequest', CommaSpace, '_LoadError'. | 6477 // '_LoadRequest', CommaSpace, '_LoadError'. |
| 6479 GrowableArray<const String*> pieces(5); | 6478 GrowableHandlePtrArray<const String> pieces(Thread::Current()->zone(), 5); |
| 6480 const TypeArguments& instantiator = TypeArguments::Handle(); | 6479 const TypeArguments& instantiator = TypeArguments::Handle(); |
| 6481 BuildSignatureParameters(false, kUserVisibleName, instantiator, &pieces); | 6480 BuildSignatureParameters(false, kUserVisibleName, instantiator, &pieces); |
| 6482 return Symbols::FromConcatAll(pieces); | 6481 return Symbols::FromConcatAll(pieces); |
| 6483 } | 6482 } |
| 6484 | 6483 |
| 6485 | 6484 |
| 6486 void Function::BuildSignatureParameters( | 6485 void Function::BuildSignatureParameters( |
| 6487 bool instantiate, | 6486 bool instantiate, |
| 6488 NameVisibility name_visibility, | 6487 NameVisibility name_visibility, |
| 6489 const TypeArguments& instantiator, | 6488 const TypeArguments& instantiator, |
| 6490 GrowableArray<const String*>* pieces) const { | 6489 GrowableHandlePtrArray<const String>* pieces) const { |
| 6491 Thread* thread = Thread::Current(); | 6490 Thread* thread = Thread::Current(); |
| 6492 Zone* zone = thread->zone(); | 6491 Zone* zone = thread->zone(); |
| 6493 | 6492 |
| 6494 AbstractType& param_type = AbstractType::Handle(zone); | 6493 AbstractType& param_type = AbstractType::Handle(zone); |
| 6495 const intptr_t num_params = NumParameters(); | 6494 const intptr_t num_params = NumParameters(); |
| 6496 const intptr_t num_fixed_params = num_fixed_parameters(); | 6495 const intptr_t num_fixed_params = num_fixed_parameters(); |
| 6497 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); | 6496 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); |
| 6498 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); | 6497 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); |
| 6499 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; | 6498 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; |
| 6500 ASSERT((num_fixed_params + num_opt_params) == num_params); | 6499 ASSERT((num_fixed_params + num_opt_params) == num_params); |
| 6501 intptr_t i = 0; | 6500 intptr_t i = 0; |
| 6502 if (name_visibility == kUserVisibleName) { | 6501 if (name_visibility == kUserVisibleName) { |
| 6503 // Hide implicit parameters. | 6502 // Hide implicit parameters. |
| 6504 i = NumImplicitParameters(); | 6503 i = NumImplicitParameters(); |
| 6505 } | 6504 } |
| 6505 String& name = String::Handle(zone); |
| 6506 while (i < num_fixed_params) { | 6506 while (i < num_fixed_params) { |
| 6507 param_type = ParameterTypeAt(i); | 6507 param_type = ParameterTypeAt(i); |
| 6508 ASSERT(!param_type.IsNull()); | 6508 ASSERT(!param_type.IsNull()); |
| 6509 if (instantiate && !param_type.IsInstantiated()) { | 6509 if (instantiate && !param_type.IsInstantiated()) { |
| 6510 param_type = param_type.InstantiateFrom(instantiator, NULL); | 6510 param_type = param_type.InstantiateFrom(instantiator, NULL); |
| 6511 } | 6511 } |
| 6512 const String& name = | 6512 name = param_type.BuildName(name_visibility); |
| 6513 String::ZoneHandle(zone, param_type.BuildName(name_visibility)); | 6513 pieces->Add(name); |
| 6514 pieces->Add(&name); | |
| 6515 if (i != (num_params - 1)) { | 6514 if (i != (num_params - 1)) { |
| 6516 pieces->Add(&Symbols::CommaSpace()); | 6515 pieces->Add(Symbols::CommaSpace()); |
| 6517 } | 6516 } |
| 6518 i++; | 6517 i++; |
| 6519 } | 6518 } |
| 6520 if (num_opt_params > 0) { | 6519 if (num_opt_params > 0) { |
| 6521 if (num_opt_pos_params > 0) { | 6520 if (num_opt_pos_params > 0) { |
| 6522 pieces->Add(&Symbols::LBracket()); | 6521 pieces->Add(Symbols::LBracket()); |
| 6523 } else { | 6522 } else { |
| 6524 pieces->Add(&Symbols::LBrace()); | 6523 pieces->Add(Symbols::LBrace()); |
| 6525 } | 6524 } |
| 6526 for (intptr_t i = num_fixed_params; i < num_params; i++) { | 6525 for (intptr_t i = num_fixed_params; i < num_params; i++) { |
| 6527 // The parameter name of an optional positional parameter does not need | 6526 // The parameter name of an optional positional parameter does not need |
| 6528 // to be part of the signature, since it is not used. | 6527 // to be part of the signature, since it is not used. |
| 6529 if (num_opt_named_params > 0) { | 6528 if (num_opt_named_params > 0) { |
| 6530 const String& name = String::ZoneHandle(zone, ParameterNameAt(i)); | 6529 name = ParameterNameAt(i); |
| 6531 pieces->Add(&name); | 6530 pieces->Add(name); |
| 6532 pieces->Add(&Symbols::ColonSpace()); | 6531 pieces->Add(Symbols::ColonSpace()); |
| 6533 } | 6532 } |
| 6534 param_type = ParameterTypeAt(i); | 6533 param_type = ParameterTypeAt(i); |
| 6535 if (instantiate && !param_type.IsInstantiated()) { | 6534 if (instantiate && !param_type.IsInstantiated()) { |
| 6536 param_type = param_type.InstantiateFrom(instantiator, NULL); | 6535 param_type = param_type.InstantiateFrom(instantiator, NULL); |
| 6537 } | 6536 } |
| 6538 ASSERT(!param_type.IsNull()); | 6537 ASSERT(!param_type.IsNull()); |
| 6539 const String& name = | 6538 name = param_type.BuildName(name_visibility); |
| 6540 String::ZoneHandle(zone, param_type.BuildName(name_visibility)); | 6539 pieces->Add(name); |
| 6541 pieces->Add(&name); | |
| 6542 if (i != (num_params - 1)) { | 6540 if (i != (num_params - 1)) { |
| 6543 pieces->Add(&Symbols::CommaSpace()); | 6541 pieces->Add(Symbols::CommaSpace()); |
| 6544 } | 6542 } |
| 6545 } | 6543 } |
| 6546 if (num_opt_pos_params > 0) { | 6544 if (num_opt_pos_params > 0) { |
| 6547 pieces->Add(&Symbols::RBracket()); | 6545 pieces->Add(Symbols::RBracket()); |
| 6548 } else { | 6546 } else { |
| 6549 pieces->Add(&Symbols::RBrace()); | 6547 pieces->Add(Symbols::RBrace()); |
| 6550 } | 6548 } |
| 6551 } | 6549 } |
| 6552 } | 6550 } |
| 6553 | 6551 |
| 6554 | 6552 |
| 6555 RawInstance* Function::ImplicitStaticClosure() const { | 6553 RawInstance* Function::ImplicitStaticClosure() const { |
| 6556 if (implicit_static_closure() == Instance::null()) { | 6554 if (implicit_static_closure() == Instance::null()) { |
| 6557 Isolate* isolate = Isolate::Current(); | 6555 Isolate* isolate = Isolate::Current(); |
| 6558 ObjectStore* object_store = isolate->object_store(); | 6556 ObjectStore* object_store = isolate->object_store(); |
| 6559 const Context& context = | 6557 const Context& context = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 6582 } | 6580 } |
| 6583 return result.raw(); | 6581 return result.raw(); |
| 6584 } | 6582 } |
| 6585 | 6583 |
| 6586 | 6584 |
| 6587 RawString* Function::BuildSignature(bool instantiate, | 6585 RawString* Function::BuildSignature(bool instantiate, |
| 6588 NameVisibility name_visibility, | 6586 NameVisibility name_visibility, |
| 6589 const TypeArguments& instantiator) const { | 6587 const TypeArguments& instantiator) const { |
| 6590 Thread* thread = Thread::Current(); | 6588 Thread* thread = Thread::Current(); |
| 6591 Zone* zone = thread->zone(); | 6589 Zone* zone = thread->zone(); |
| 6592 GrowableArray<const String*> pieces(zone, 4); | 6590 GrowableHandlePtrArray<const String> pieces(zone, 4); |
| 6591 String& name = String::Handle(zone); |
| 6593 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { | 6592 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { |
| 6594 // Prefix the signature with its signature class and type parameters, if any | 6593 // Prefix the signature with its signature class and type parameters, if any |
| 6595 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the | 6594 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the |
| 6596 // signature class name is the alias name. | 6595 // signature class name is the alias name. |
| 6597 // The signature of static functions cannot be type parameterized. | 6596 // The signature of static functions cannot be type parameterized. |
| 6598 const Class& function_class = Class::Handle(zone, Owner()); | 6597 const Class& function_class = Class::Handle(zone, Owner()); |
| 6599 ASSERT(!function_class.IsNull()); | 6598 ASSERT(!function_class.IsNull()); |
| 6600 const TypeArguments& type_parameters = TypeArguments::Handle( | 6599 const TypeArguments& type_parameters = TypeArguments::Handle( |
| 6601 zone, function_class.type_parameters()); | 6600 zone, function_class.type_parameters()); |
| 6602 if (!type_parameters.IsNull()) { | 6601 if (!type_parameters.IsNull()) { |
| 6603 const String& function_class_name = | 6602 const String& function_class_name = |
| 6604 String::ZoneHandle(zone, function_class.Name()); | 6603 String::Handle(zone, function_class.Name()); |
| 6605 pieces.Add(&function_class_name); | 6604 pieces.Add(function_class_name); |
| 6606 const intptr_t num_type_parameters = type_parameters.Length(); | 6605 const intptr_t num_type_parameters = type_parameters.Length(); |
| 6607 pieces.Add(&Symbols::LAngleBracket()); | 6606 pieces.Add(Symbols::LAngleBracket()); |
| 6608 TypeParameter& type_parameter = TypeParameter::Handle(zone); | 6607 TypeParameter& type_parameter = TypeParameter::Handle(zone); |
| 6609 AbstractType& bound = AbstractType::Handle(zone); | 6608 AbstractType& bound = AbstractType::Handle(zone); |
| 6610 for (intptr_t i = 0; i < num_type_parameters; i++) { | 6609 for (intptr_t i = 0; i < num_type_parameters; i++) { |
| 6611 type_parameter ^= type_parameters.TypeAt(i); | 6610 type_parameter ^= type_parameters.TypeAt(i); |
| 6612 const String& name = String::ZoneHandle(zone, type_parameter.name()); | 6611 name = type_parameter.name(); |
| 6613 pieces.Add(&name); | 6612 pieces.Add(name); |
| 6614 bound = type_parameter.bound(); | 6613 bound = type_parameter.bound(); |
| 6615 if (!bound.IsNull() && !bound.IsObjectType()) { | 6614 if (!bound.IsNull() && !bound.IsObjectType()) { |
| 6616 pieces.Add(&Symbols::SpaceExtendsSpace()); | 6615 pieces.Add(Symbols::SpaceExtendsSpace()); |
| 6617 const String& name = | 6616 name = bound.BuildName(name_visibility); |
| 6618 String::ZoneHandle(zone, bound.BuildName(name_visibility)); | 6617 pieces.Add(name); |
| 6619 pieces.Add(&name); | |
| 6620 } | 6618 } |
| 6621 if (i < num_type_parameters - 1) { | 6619 if (i < num_type_parameters - 1) { |
| 6622 pieces.Add(&Symbols::CommaSpace()); | 6620 pieces.Add(Symbols::CommaSpace()); |
| 6623 } | 6621 } |
| 6624 } | 6622 } |
| 6625 pieces.Add(&Symbols::RAngleBracket()); | 6623 pieces.Add(Symbols::RAngleBracket()); |
| 6626 } | 6624 } |
| 6627 } | 6625 } |
| 6628 pieces.Add(&Symbols::LParen()); | 6626 pieces.Add(Symbols::LParen()); |
| 6629 BuildSignatureParameters(instantiate, | 6627 BuildSignatureParameters(instantiate, |
| 6630 name_visibility, | 6628 name_visibility, |
| 6631 instantiator, | 6629 instantiator, |
| 6632 &pieces); | 6630 &pieces); |
| 6633 pieces.Add(&Symbols::RParenArrow()); | 6631 pieces.Add(Symbols::RParenArrow()); |
| 6634 AbstractType& res_type = AbstractType::Handle(zone, result_type()); | 6632 AbstractType& res_type = AbstractType::Handle(zone, result_type()); |
| 6635 if (instantiate && !res_type.IsInstantiated()) { | 6633 if (instantiate && !res_type.IsInstantiated()) { |
| 6636 res_type = res_type.InstantiateFrom(instantiator, NULL); | 6634 res_type = res_type.InstantiateFrom(instantiator, NULL); |
| 6637 } | 6635 } |
| 6638 const String& name = | 6636 name = res_type.BuildName(name_visibility); |
| 6639 String::ZoneHandle(zone, res_type.BuildName(name_visibility)); | 6637 pieces.Add(name); |
| 6640 pieces.Add(&name); | |
| 6641 return Symbols::FromConcatAll(pieces); | 6638 return Symbols::FromConcatAll(pieces); |
| 6642 } | 6639 } |
| 6643 | 6640 |
| 6644 | 6641 |
| 6645 bool Function::HasInstantiatedSignature() const { | 6642 bool Function::HasInstantiatedSignature() const { |
| 6646 AbstractType& type = AbstractType::Handle(result_type()); | 6643 AbstractType& type = AbstractType::Handle(result_type()); |
| 6647 if (!type.IsInstantiated()) { | 6644 if (!type.IsInstantiated()) { |
| 6648 return false; | 6645 return false; |
| 6649 } | 6646 } |
| 6650 const intptr_t num_parameters = NumParameters(); | 6647 const intptr_t num_parameters = NumParameters(); |
| (...skipping 8253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14904 } | 14901 } |
| 14905 | 14902 |
| 14906 | 14903 |
| 14907 RawAbstractType* AbstractType::OnlyBuddyInTrail(TrailPtr trail) const { | 14904 RawAbstractType* AbstractType::OnlyBuddyInTrail(TrailPtr trail) const { |
| 14908 if (trail == NULL) { | 14905 if (trail == NULL) { |
| 14909 return AbstractType::null(); | 14906 return AbstractType::null(); |
| 14910 } | 14907 } |
| 14911 const intptr_t len = trail->length(); | 14908 const intptr_t len = trail->length(); |
| 14912 ASSERT((len % 2) == 0); | 14909 ASSERT((len % 2) == 0); |
| 14913 for (intptr_t i = 0; i < len; i += 2) { | 14910 for (intptr_t i = 0; i < len; i += 2) { |
| 14914 ASSERT(trail->At(i)->IsZoneHandle()); | 14911 ASSERT(trail->At(i).IsZoneHandle()); |
| 14915 ASSERT(trail->At(i + 1)->IsZoneHandle()); | 14912 ASSERT(trail->At(i + 1).IsZoneHandle()); |
| 14916 if (trail->At(i)->raw() == this->raw()) { | 14913 if (trail->At(i).raw() == this->raw()) { |
| 14917 ASSERT(!trail->At(i + 1)->IsNull()); | 14914 ASSERT(!trail->At(i + 1).IsNull()); |
| 14918 return trail->At(i + 1)->raw(); | 14915 return trail->At(i + 1).raw(); |
| 14919 } | 14916 } |
| 14920 } | 14917 } |
| 14921 return AbstractType::null(); | 14918 return AbstractType::null(); |
| 14922 } | 14919 } |
| 14923 | 14920 |
| 14924 | 14921 |
| 14925 void AbstractType::AddOnlyBuddyToTrail(TrailPtr* trail, | 14922 void AbstractType::AddOnlyBuddyToTrail(TrailPtr* trail, |
| 14926 const AbstractType& buddy) const { | 14923 const AbstractType& buddy) const { |
| 14927 if (*trail == NULL) { | 14924 if (*trail == NULL) { |
| 14928 *trail = new Trail(4); | 14925 *trail = new Trail(Thread::Current()->zone(), 4); |
| 14929 } else { | 14926 } else { |
| 14930 ASSERT(OnlyBuddyInTrail(*trail) == AbstractType::null()); | 14927 ASSERT(OnlyBuddyInTrail(*trail) == AbstractType::null()); |
| 14931 } | 14928 } |
| 14932 AbstractType& t = AbstractType::ZoneHandle(this->raw()); | 14929 (*trail)->Add(*this); |
| 14933 AbstractType& b = AbstractType::ZoneHandle(buddy.raw()); | 14930 (*trail)->Add(buddy); |
| 14934 (*trail)->Add(&t); | |
| 14935 (*trail)->Add(&b); | |
| 14936 } | 14931 } |
| 14937 | 14932 |
| 14938 | 14933 |
| 14939 RawString* AbstractType::BuildName(NameVisibility name_visibility) const { | 14934 RawString* AbstractType::BuildName(NameVisibility name_visibility) const { |
| 14935 Zone* zone = Thread::Current()->zone(); |
| 14940 if (IsBoundedType()) { | 14936 if (IsBoundedType()) { |
| 14941 const AbstractType& type = AbstractType::Handle( | 14937 const AbstractType& type = AbstractType::Handle( |
| 14942 BoundedType::Cast(*this).type()); | 14938 BoundedType::Cast(*this).type()); |
| 14943 if (name_visibility == kPrettyName) { | 14939 if (name_visibility == kPrettyName) { |
| 14944 return type.BuildName(kPrettyName); | 14940 return type.BuildName(kPrettyName); |
| 14945 } else if (name_visibility == kUserVisibleName) { | 14941 } else if (name_visibility == kUserVisibleName) { |
| 14946 return type.BuildName(kUserVisibleName); | 14942 return type.BuildName(kUserVisibleName); |
| 14947 } | 14943 } |
| 14948 String& type_name = String::Handle(type.BuildName(kInternalName)); | 14944 GrowableHandlePtrArray<const String> pieces(zone, 5); |
| 14949 type_name = String::Concat(type_name, Symbols::SpaceExtendsSpace()); | 14945 String& type_name = String::Handle(zone, type.BuildName(kInternalName)); |
| 14946 pieces.Add(type_name); |
| 14947 pieces.Add(Symbols::SpaceExtendsSpace()); |
| 14950 // Build the bound name without causing divergence. | 14948 // Build the bound name without causing divergence. |
| 14951 const AbstractType& bound = AbstractType::Handle( | 14949 const AbstractType& bound = AbstractType::Handle( |
| 14952 BoundedType::Cast(*this).bound()); | 14950 zone, BoundedType::Cast(*this).bound()); |
| 14953 String& bound_name = String::Handle(); | 14951 String& bound_name = String::Handle(zone); |
| 14954 if (bound.IsTypeParameter()) { | 14952 if (bound.IsTypeParameter()) { |
| 14955 bound_name = TypeParameter::Cast(bound).name(); | 14953 bound_name = TypeParameter::Cast(bound).name(); |
| 14954 pieces.Add(bound_name); |
| 14956 } else if (bound.IsType()) { | 14955 } else if (bound.IsType()) { |
| 14957 const Class& cls = Class::Handle(Type::Cast(bound).type_class()); | 14956 const Class& cls = Class::Handle(zone, Type::Cast(bound).type_class()); |
| 14958 bound_name = cls.Name(); | 14957 bound_name = cls.Name(); |
| 14959 if (Type::Cast(bound).arguments() != TypeArguments::null()) { | 14958 if (Type::Cast(bound).arguments() != TypeArguments::null()) { |
| 14960 bound_name = String::Concat(bound_name, Symbols::OptimizedOut()); | 14959 pieces.Add(bound_name); |
| 14960 pieces.Add(Symbols::OptimizedOut()); |
| 14961 } | 14961 } |
| 14962 } else { | 14962 } else { |
| 14963 bound_name = String::New(Symbols::OptimizedOut()); | 14963 pieces.Add(Symbols::OptimizedOut()); |
| 14964 } | 14964 } |
| 14965 return Symbols::FromConcat(type_name, bound_name); | 14965 return Symbols::FromConcatAll(pieces); |
| 14966 } | 14966 } |
| 14967 if (IsTypeParameter()) { | 14967 if (IsTypeParameter()) { |
| 14968 return TypeParameter::Cast(*this).name(); | 14968 return TypeParameter::Cast(*this).name(); |
| 14969 } | 14969 } |
| 14970 // If the type is still being finalized, we may be reporting an error about | 14970 // If the type is still being finalized, we may be reporting an error about |
| 14971 // a malformed type, so proceed with caution. | 14971 // a malformed type, so proceed with caution. |
| 14972 const TypeArguments& args = TypeArguments::Handle(arguments()); | 14972 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); |
| 14973 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); | 14973 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); |
| 14974 String& class_name = String::Handle(); | 14974 String& class_name = String::Handle(zone); |
| 14975 intptr_t first_type_param_index; | 14975 intptr_t first_type_param_index; |
| 14976 intptr_t num_type_params; // Number of type parameters to print. | 14976 intptr_t num_type_params; // Number of type parameters to print. |
| 14977 if (HasResolvedTypeClass()) { | 14977 if (HasResolvedTypeClass()) { |
| 14978 const Class& cls = Class::Handle(type_class()); | 14978 const Class& cls = Class::Handle(zone, type_class()); |
| 14979 if (IsResolved() || !cls.IsMixinApplication()) { | 14979 if (IsResolved() || !cls.IsMixinApplication()) { |
| 14980 // Do not print the full vector, but only the declared type parameters. | 14980 // Do not print the full vector, but only the declared type parameters. |
| 14981 num_type_params = cls.NumTypeParameters(); | 14981 num_type_params = cls.NumTypeParameters(); |
| 14982 } else { | 14982 } else { |
| 14983 // Do not print the type parameters of an unresolved mixin application, | 14983 // Do not print the type parameters of an unresolved mixin application, |
| 14984 // since it would prematurely trigger the application of the mixin type. | 14984 // since it would prematurely trigger the application of the mixin type. |
| 14985 num_type_params = 0; | 14985 num_type_params = 0; |
| 14986 } | 14986 } |
| 14987 if (name_visibility == kInternalName) { | 14987 if (name_visibility == kInternalName) { |
| 14988 class_name = cls.Name(); | 14988 class_name = cls.Name(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 15016 if (cls.IsSignatureClass()) { | 15016 if (cls.IsSignatureClass()) { |
| 15017 // We may be reporting an error about a malformed function type. In that | 15017 // We may be reporting an error about a malformed function type. In that |
| 15018 // case, avoid instantiating the signature, since it may cause divergence. | 15018 // case, avoid instantiating the signature, since it may cause divergence. |
| 15019 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { | 15019 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { |
| 15020 return class_name.raw(); | 15020 return class_name.raw(); |
| 15021 } | 15021 } |
| 15022 // To avoid divergence, print the name of a typedef (non-canonical | 15022 // To avoid divergence, print the name of a typedef (non-canonical |
| 15023 // signature class) as a regular, possibly parameterized, class. | 15023 // signature class) as a regular, possibly parameterized, class. |
| 15024 if (cls.IsCanonicalSignatureClass()) { | 15024 if (cls.IsCanonicalSignatureClass()) { |
| 15025 const Function& signature_function = Function::Handle( | 15025 const Function& signature_function = Function::Handle( |
| 15026 cls.signature_function()); | 15026 zone, cls.signature_function()); |
| 15027 // Signature classes have no super type, however, they take as many | 15027 // Signature classes have no super type, however, they take as many |
| 15028 // type arguments as the owner class of their signature function (if it | 15028 // type arguments as the owner class of their signature function (if it |
| 15029 // is non static and generic, see Class::NumTypeArguments()). Therefore, | 15029 // is non static and generic, see Class::NumTypeArguments()). Therefore, |
| 15030 // first_type_param_index may be greater than 0 here. | 15030 // first_type_param_index may be greater than 0 here. |
| 15031 return signature_function.InstantiatedSignatureFrom(args, | 15031 return signature_function.InstantiatedSignatureFrom(args, |
| 15032 name_visibility); | 15032 name_visibility); |
| 15033 } | 15033 } |
| 15034 } | 15034 } |
| 15035 } else { | 15035 } else { |
| 15036 const UnresolvedClass& cls = UnresolvedClass::Handle(unresolved_class()); | 15036 const UnresolvedClass& cls = |
| 15037 UnresolvedClass::Handle(zone, unresolved_class()); |
| 15037 class_name = cls.Name(); | 15038 class_name = cls.Name(); |
| 15038 num_type_params = num_args; | 15039 num_type_params = num_args; |
| 15039 first_type_param_index = 0; | 15040 first_type_param_index = 0; |
| 15040 } | 15041 } |
| 15041 String& type_name = String::Handle(); | 15042 GrowableHandlePtrArray<const String> pieces(zone, 4); |
| 15043 pieces.Add(class_name); |
| 15042 if ((num_type_params == 0) || | 15044 if ((num_type_params == 0) || |
| 15043 args.IsRaw(first_type_param_index, num_type_params)) { | 15045 args.IsRaw(first_type_param_index, num_type_params)) { |
| 15044 type_name = class_name.raw(); | 15046 // Do nothing. |
| 15045 } else { | 15047 } else { |
| 15046 const String& args_name = String::Handle( | 15048 const String& args_name = String::Handle(zone, |
| 15047 args.SubvectorName(first_type_param_index, | 15049 args.SubvectorName(first_type_param_index, |
| 15048 num_type_params, | 15050 num_type_params, |
| 15049 name_visibility)); | 15051 name_visibility)); |
| 15050 type_name = String::Concat(class_name, args_name); | 15052 pieces.Add(args_name); |
| 15051 } | 15053 } |
| 15052 // The name is only used for type checking and debugging purposes. | 15054 // The name is only used for type checking and debugging purposes. |
| 15053 // Unless profiling data shows otherwise, it is not worth caching the name in | 15055 // Unless profiling data shows otherwise, it is not worth caching the name in |
| 15054 // the type. | 15056 // the type. |
| 15055 return Symbols::New(type_name); | 15057 return Symbols::FromConcatAll(pieces); |
| 15056 } | 15058 } |
| 15057 | 15059 |
| 15058 | 15060 |
| 15059 RawString* AbstractType::ClassName() const { | 15061 RawString* AbstractType::ClassName() const { |
| 15060 if (HasResolvedTypeClass()) { | 15062 if (HasResolvedTypeClass()) { |
| 15061 return Class::Handle(type_class()).Name(); | 15063 return Class::Handle(type_class()).Name(); |
| 15062 } else { | 15064 } else { |
| 15063 return UnresolvedClass::Handle(unresolved_class()).Name(); | 15065 return UnresolvedClass::Handle(unresolved_class()).Name(); |
| 15064 } | 15066 } |
| 15065 } | 15067 } |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15975 intptr_t TypeRef::Hash() const { | 15977 intptr_t TypeRef::Hash() const { |
| 15976 // Do not calculate the hash of the referenced type to avoid divergence. | 15978 // Do not calculate the hash of the referenced type to avoid divergence. |
| 15977 const uint32_t result = | 15979 const uint32_t result = |
| 15978 Class::Handle(AbstractType::Handle(type()).type_class()).id(); | 15980 Class::Handle(AbstractType::Handle(type()).type_class()).id(); |
| 15979 return FinalizeHash(result); | 15981 return FinalizeHash(result); |
| 15980 } | 15982 } |
| 15981 | 15983 |
| 15982 | 15984 |
| 15983 bool TypeRef::TestAndAddToTrail(TrailPtr* trail) const { | 15985 bool TypeRef::TestAndAddToTrail(TrailPtr* trail) const { |
| 15984 if (*trail == NULL) { | 15986 if (*trail == NULL) { |
| 15985 *trail = new Trail(4); | 15987 *trail = new Trail(Thread::Current()->zone(), 4); |
| 15986 } else { | 15988 } else { |
| 15987 const intptr_t len = (*trail)->length(); | 15989 const intptr_t len = (*trail)->length(); |
| 15988 for (intptr_t i = 0; i < len; i++) { | 15990 for (intptr_t i = 0; i < len; i++) { |
| 15989 if ((*trail)->At(i)->raw() == this->raw()) { | 15991 if ((*trail)->At(i).raw() == this->raw()) { |
| 15990 return true; | 15992 return true; |
| 15991 } | 15993 } |
| 15992 } | 15994 } |
| 15993 } | 15995 } |
| 15994 AbstractType& t = AbstractType::ZoneHandle(this->raw()); | 15996 (*trail)->Add(*this); |
| 15995 (*trail)->Add(&t); | |
| 15996 return false; | 15997 return false; |
| 15997 } | 15998 } |
| 15998 | 15999 |
| 15999 | 16000 |
| 16000 bool TypeRef::TestAndAddBuddyToTrail(TrailPtr* trail, | 16001 bool TypeRef::TestAndAddBuddyToTrail(TrailPtr* trail, |
| 16001 const AbstractType& buddy) const { | 16002 const AbstractType& buddy) const { |
| 16002 if (*trail == NULL) { | 16003 if (*trail == NULL) { |
| 16003 *trail = new Trail(4); | 16004 *trail = new Trail(Thread::Current()->zone(), 4); |
| 16004 } else { | 16005 } else { |
| 16005 const intptr_t len = (*trail)->length(); | 16006 const intptr_t len = (*trail)->length(); |
| 16006 ASSERT((len % 2) == 0); | 16007 ASSERT((len % 2) == 0); |
| 16007 for (intptr_t i = 0; i < len; i += 2) { | 16008 for (intptr_t i = 0; i < len; i += 2) { |
| 16008 ASSERT((*trail)->At(i)->IsZoneHandle()); | 16009 if (((*trail)->At(i).raw() == this->raw()) && |
| 16009 ASSERT((*trail)->At(i + 1)->IsZoneHandle()); | 16010 ((*trail)->At(i + 1).raw() == buddy.raw())) { |
| 16010 if (((*trail)->At(i)->raw() == this->raw()) && | |
| 16011 ((*trail)->At(i + 1)->raw() == buddy.raw())) { | |
| 16012 return true; | 16011 return true; |
| 16013 } | 16012 } |
| 16014 } | 16013 } |
| 16015 } | 16014 } |
| 16016 AbstractType& t = AbstractType::ZoneHandle(this->raw()); | 16015 (*trail)->Add(*this); |
| 16017 AbstractType& b = AbstractType::ZoneHandle(buddy.raw()); | 16016 (*trail)->Add(buddy); |
| 16018 (*trail)->Add(&t); | |
| 16019 (*trail)->Add(&b); | |
| 16020 return false; | 16017 return false; |
| 16021 } | 16018 } |
| 16022 | 16019 |
| 16023 | 16020 |
| 16024 RawTypeRef* TypeRef::New() { | 16021 RawTypeRef* TypeRef::New() { |
| 16025 RawObject* raw = Object::Allocate(TypeRef::kClassId, | 16022 RawObject* raw = Object::Allocate(TypeRef::kClassId, |
| 16026 TypeRef::InstanceSize(), | 16023 TypeRef::InstanceSize(), |
| 16027 Heap::kOld); | 16024 Heap::kOld); |
| 16028 return reinterpret_cast<RawTypeRef*>(raw); | 16025 return reinterpret_cast<RawTypeRef*>(raw); |
| 16029 } | 16026 } |
| (...skipping 5403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21433 return tag_label.ToCString(); | 21430 return tag_label.ToCString(); |
| 21434 } | 21431 } |
| 21435 | 21432 |
| 21436 | 21433 |
| 21437 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21434 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 21438 Instance::PrintJSONImpl(stream, ref); | 21435 Instance::PrintJSONImpl(stream, ref); |
| 21439 } | 21436 } |
| 21440 | 21437 |
| 21441 | 21438 |
| 21442 } // namespace dart | 21439 } // namespace dart |
| OLD | NEW |