| 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 8281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14932 } | 14929 } |
| 14933 | 14930 |
| 14934 | 14931 |
| 14935 RawAbstractType* AbstractType::OnlyBuddyInTrail(TrailPtr trail) const { | 14932 RawAbstractType* AbstractType::OnlyBuddyInTrail(TrailPtr trail) const { |
| 14936 if (trail == NULL) { | 14933 if (trail == NULL) { |
| 14937 return AbstractType::null(); | 14934 return AbstractType::null(); |
| 14938 } | 14935 } |
| 14939 const intptr_t len = trail->length(); | 14936 const intptr_t len = trail->length(); |
| 14940 ASSERT((len % 2) == 0); | 14937 ASSERT((len % 2) == 0); |
| 14941 for (intptr_t i = 0; i < len; i += 2) { | 14938 for (intptr_t i = 0; i < len; i += 2) { |
| 14942 ASSERT(trail->At(i)->IsZoneHandle()); | 14939 ASSERT(trail->At(i).IsZoneHandle()); |
| 14943 ASSERT(trail->At(i + 1)->IsZoneHandle()); | 14940 ASSERT(trail->At(i + 1).IsZoneHandle()); |
| 14944 if (trail->At(i)->raw() == this->raw()) { | 14941 if (trail->At(i).raw() == this->raw()) { |
| 14945 ASSERT(!trail->At(i + 1)->IsNull()); | 14942 ASSERT(!trail->At(i + 1).IsNull()); |
| 14946 return trail->At(i + 1)->raw(); | 14943 return trail->At(i + 1).raw(); |
| 14947 } | 14944 } |
| 14948 } | 14945 } |
| 14949 return AbstractType::null(); | 14946 return AbstractType::null(); |
| 14950 } | 14947 } |
| 14951 | 14948 |
| 14952 | 14949 |
| 14953 void AbstractType::AddOnlyBuddyToTrail(TrailPtr* trail, | 14950 void AbstractType::AddOnlyBuddyToTrail(TrailPtr* trail, |
| 14954 const AbstractType& buddy) const { | 14951 const AbstractType& buddy) const { |
| 14955 if (*trail == NULL) { | 14952 if (*trail == NULL) { |
| 14956 *trail = new Trail(4); | 14953 *trail = new Trail(Thread::Current()->zone(), 4); |
| 14957 } else { | 14954 } else { |
| 14958 ASSERT(OnlyBuddyInTrail(*trail) == AbstractType::null()); | 14955 ASSERT(OnlyBuddyInTrail(*trail) == AbstractType::null()); |
| 14959 } | 14956 } |
| 14960 AbstractType& t = AbstractType::ZoneHandle(this->raw()); | 14957 (*trail)->Add(*this); |
| 14961 AbstractType& b = AbstractType::ZoneHandle(buddy.raw()); | 14958 (*trail)->Add(buddy); |
| 14962 (*trail)->Add(&t); | |
| 14963 (*trail)->Add(&b); | |
| 14964 } | 14959 } |
| 14965 | 14960 |
| 14966 | 14961 |
| 14967 RawString* AbstractType::BuildName(NameVisibility name_visibility) const { | 14962 RawString* AbstractType::BuildName(NameVisibility name_visibility) const { |
| 14963 Zone* zone = Thread::Current()->zone(); |
| 14968 if (IsBoundedType()) { | 14964 if (IsBoundedType()) { |
| 14969 const AbstractType& type = AbstractType::Handle( | 14965 const AbstractType& type = AbstractType::Handle( |
| 14970 BoundedType::Cast(*this).type()); | 14966 BoundedType::Cast(*this).type()); |
| 14971 if (name_visibility == kPrettyName) { | 14967 if (name_visibility == kPrettyName) { |
| 14972 return type.BuildName(kPrettyName); | 14968 return type.BuildName(kPrettyName); |
| 14973 } else if (name_visibility == kUserVisibleName) { | 14969 } else if (name_visibility == kUserVisibleName) { |
| 14974 return type.BuildName(kUserVisibleName); | 14970 return type.BuildName(kUserVisibleName); |
| 14975 } | 14971 } |
| 14976 String& type_name = String::Handle(type.BuildName(kInternalName)); | 14972 GrowableHandlePtrArray<const String> pieces(zone, 5); |
| 14977 type_name = String::Concat(type_name, Symbols::SpaceExtendsSpace()); | 14973 String& type_name = String::Handle(zone, type.BuildName(kInternalName)); |
| 14974 pieces.Add(type_name); |
| 14975 pieces.Add(Symbols::SpaceExtendsSpace()); |
| 14978 // Build the bound name without causing divergence. | 14976 // Build the bound name without causing divergence. |
| 14979 const AbstractType& bound = AbstractType::Handle( | 14977 const AbstractType& bound = AbstractType::Handle( |
| 14980 BoundedType::Cast(*this).bound()); | 14978 zone, BoundedType::Cast(*this).bound()); |
| 14981 String& bound_name = String::Handle(); | 14979 String& bound_name = String::Handle(zone); |
| 14982 if (bound.IsTypeParameter()) { | 14980 if (bound.IsTypeParameter()) { |
| 14983 bound_name = TypeParameter::Cast(bound).name(); | 14981 bound_name = TypeParameter::Cast(bound).name(); |
| 14982 pieces.Add(bound_name); |
| 14984 } else if (bound.IsType()) { | 14983 } else if (bound.IsType()) { |
| 14985 const Class& cls = Class::Handle(Type::Cast(bound).type_class()); | 14984 const Class& cls = Class::Handle(zone, Type::Cast(bound).type_class()); |
| 14986 bound_name = cls.Name(); | 14985 bound_name = cls.Name(); |
| 14987 if (Type::Cast(bound).arguments() != TypeArguments::null()) { | 14986 if (Type::Cast(bound).arguments() != TypeArguments::null()) { |
| 14988 bound_name = String::Concat(bound_name, Symbols::OptimizedOut()); | 14987 pieces.Add(bound_name); |
| 14988 pieces.Add(Symbols::OptimizedOut()); |
| 14989 } | 14989 } |
| 14990 } else { | 14990 } else { |
| 14991 bound_name = String::New(Symbols::OptimizedOut()); | 14991 pieces.Add(Symbols::OptimizedOut()); |
| 14992 } | 14992 } |
| 14993 return Symbols::FromConcat(type_name, bound_name); | 14993 return Symbols::FromConcatAll(pieces); |
| 14994 } | 14994 } |
| 14995 if (IsTypeParameter()) { | 14995 if (IsTypeParameter()) { |
| 14996 return TypeParameter::Cast(*this).name(); | 14996 return TypeParameter::Cast(*this).name(); |
| 14997 } | 14997 } |
| 14998 // If the type is still being finalized, we may be reporting an error about | 14998 // If the type is still being finalized, we may be reporting an error about |
| 14999 // a malformed type, so proceed with caution. | 14999 // a malformed type, so proceed with caution. |
| 15000 const TypeArguments& args = TypeArguments::Handle(arguments()); | 15000 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); |
| 15001 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); | 15001 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); |
| 15002 String& class_name = String::Handle(); | 15002 String& class_name = String::Handle(zone); |
| 15003 intptr_t first_type_param_index; | 15003 intptr_t first_type_param_index; |
| 15004 intptr_t num_type_params; // Number of type parameters to print. | 15004 intptr_t num_type_params; // Number of type parameters to print. |
| 15005 if (HasResolvedTypeClass()) { | 15005 if (HasResolvedTypeClass()) { |
| 15006 const Class& cls = Class::Handle(type_class()); | 15006 const Class& cls = Class::Handle(zone, type_class()); |
| 15007 if (IsResolved() || !cls.IsMixinApplication()) { | 15007 if (IsResolved() || !cls.IsMixinApplication()) { |
| 15008 // Do not print the full vector, but only the declared type parameters. | 15008 // Do not print the full vector, but only the declared type parameters. |
| 15009 num_type_params = cls.NumTypeParameters(); | 15009 num_type_params = cls.NumTypeParameters(); |
| 15010 } else { | 15010 } else { |
| 15011 // Do not print the type parameters of an unresolved mixin application, | 15011 // Do not print the type parameters of an unresolved mixin application, |
| 15012 // since it would prematurely trigger the application of the mixin type. | 15012 // since it would prematurely trigger the application of the mixin type. |
| 15013 num_type_params = 0; | 15013 num_type_params = 0; |
| 15014 } | 15014 } |
| 15015 if (name_visibility == kInternalName) { | 15015 if (name_visibility == kInternalName) { |
| 15016 class_name = cls.Name(); | 15016 class_name = cls.Name(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 15044 if (cls.IsSignatureClass()) { | 15044 if (cls.IsSignatureClass()) { |
| 15045 // We may be reporting an error about a malformed function type. In that | 15045 // We may be reporting an error about a malformed function type. In that |
| 15046 // case, avoid instantiating the signature, since it may cause divergence. | 15046 // case, avoid instantiating the signature, since it may cause divergence. |
| 15047 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { | 15047 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { |
| 15048 return class_name.raw(); | 15048 return class_name.raw(); |
| 15049 } | 15049 } |
| 15050 // To avoid divergence, print the name of a typedef (non-canonical | 15050 // To avoid divergence, print the name of a typedef (non-canonical |
| 15051 // signature class) as a regular, possibly parameterized, class. | 15051 // signature class) as a regular, possibly parameterized, class. |
| 15052 if (cls.IsCanonicalSignatureClass()) { | 15052 if (cls.IsCanonicalSignatureClass()) { |
| 15053 const Function& signature_function = Function::Handle( | 15053 const Function& signature_function = Function::Handle( |
| 15054 cls.signature_function()); | 15054 zone, cls.signature_function()); |
| 15055 // Signature classes have no super type, however, they take as many | 15055 // Signature classes have no super type, however, they take as many |
| 15056 // type arguments as the owner class of their signature function (if it | 15056 // type arguments as the owner class of their signature function (if it |
| 15057 // is non static and generic, see Class::NumTypeArguments()). Therefore, | 15057 // is non static and generic, see Class::NumTypeArguments()). Therefore, |
| 15058 // first_type_param_index may be greater than 0 here. | 15058 // first_type_param_index may be greater than 0 here. |
| 15059 return signature_function.InstantiatedSignatureFrom(args, | 15059 return signature_function.InstantiatedSignatureFrom(args, |
| 15060 name_visibility); | 15060 name_visibility); |
| 15061 } | 15061 } |
| 15062 } | 15062 } |
| 15063 } else { | 15063 } else { |
| 15064 const UnresolvedClass& cls = UnresolvedClass::Handle(unresolved_class()); | 15064 const UnresolvedClass& cls = |
| 15065 UnresolvedClass::Handle(zone, unresolved_class()); |
| 15065 class_name = cls.Name(); | 15066 class_name = cls.Name(); |
| 15066 num_type_params = num_args; | 15067 num_type_params = num_args; |
| 15067 first_type_param_index = 0; | 15068 first_type_param_index = 0; |
| 15068 } | 15069 } |
| 15069 String& type_name = String::Handle(); | 15070 GrowableHandlePtrArray<const String> pieces(zone, 4); |
| 15071 pieces.Add(class_name); |
| 15070 if ((num_type_params == 0) || | 15072 if ((num_type_params == 0) || |
| 15071 args.IsRaw(first_type_param_index, num_type_params)) { | 15073 args.IsRaw(first_type_param_index, num_type_params)) { |
| 15072 type_name = class_name.raw(); | 15074 // Do nothing. |
| 15073 } else { | 15075 } else { |
| 15074 const String& args_name = String::Handle( | 15076 const String& args_name = String::Handle(zone, |
| 15075 args.SubvectorName(first_type_param_index, | 15077 args.SubvectorName(first_type_param_index, |
| 15076 num_type_params, | 15078 num_type_params, |
| 15077 name_visibility)); | 15079 name_visibility)); |
| 15078 type_name = String::Concat(class_name, args_name); | 15080 pieces.Add(args_name); |
| 15079 } | 15081 } |
| 15080 // The name is only used for type checking and debugging purposes. | 15082 // The name is only used for type checking and debugging purposes. |
| 15081 // Unless profiling data shows otherwise, it is not worth caching the name in | 15083 // Unless profiling data shows otherwise, it is not worth caching the name in |
| 15082 // the type. | 15084 // the type. |
| 15083 return Symbols::New(type_name); | 15085 return Symbols::FromConcatAll(pieces); |
| 15084 } | 15086 } |
| 15085 | 15087 |
| 15086 | 15088 |
| 15087 RawString* AbstractType::ClassName() const { | 15089 RawString* AbstractType::ClassName() const { |
| 15088 if (HasResolvedTypeClass()) { | 15090 if (HasResolvedTypeClass()) { |
| 15089 return Class::Handle(type_class()).Name(); | 15091 return Class::Handle(type_class()).Name(); |
| 15090 } else { | 15092 } else { |
| 15091 return UnresolvedClass::Handle(unresolved_class()).Name(); | 15093 return UnresolvedClass::Handle(unresolved_class()).Name(); |
| 15092 } | 15094 } |
| 15093 } | 15095 } |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16003 intptr_t TypeRef::Hash() const { | 16005 intptr_t TypeRef::Hash() const { |
| 16004 // Do not calculate the hash of the referenced type to avoid divergence. | 16006 // Do not calculate the hash of the referenced type to avoid divergence. |
| 16005 const uint32_t result = | 16007 const uint32_t result = |
| 16006 Class::Handle(AbstractType::Handle(type()).type_class()).id(); | 16008 Class::Handle(AbstractType::Handle(type()).type_class()).id(); |
| 16007 return FinalizeHash(result); | 16009 return FinalizeHash(result); |
| 16008 } | 16010 } |
| 16009 | 16011 |
| 16010 | 16012 |
| 16011 bool TypeRef::TestAndAddToTrail(TrailPtr* trail) const { | 16013 bool TypeRef::TestAndAddToTrail(TrailPtr* trail) const { |
| 16012 if (*trail == NULL) { | 16014 if (*trail == NULL) { |
| 16013 *trail = new Trail(4); | 16015 *trail = new Trail(Thread::Current()->zone(), 4); |
| 16014 } else { | 16016 } else { |
| 16015 const intptr_t len = (*trail)->length(); | 16017 const intptr_t len = (*trail)->length(); |
| 16016 for (intptr_t i = 0; i < len; i++) { | 16018 for (intptr_t i = 0; i < len; i++) { |
| 16017 if ((*trail)->At(i)->raw() == this->raw()) { | 16019 if ((*trail)->At(i).raw() == this->raw()) { |
| 16018 return true; | 16020 return true; |
| 16019 } | 16021 } |
| 16020 } | 16022 } |
| 16021 } | 16023 } |
| 16022 AbstractType& t = AbstractType::ZoneHandle(this->raw()); | 16024 (*trail)->Add(*this); |
| 16023 (*trail)->Add(&t); | |
| 16024 return false; | 16025 return false; |
| 16025 } | 16026 } |
| 16026 | 16027 |
| 16027 | 16028 |
| 16028 bool TypeRef::TestAndAddBuddyToTrail(TrailPtr* trail, | 16029 bool TypeRef::TestAndAddBuddyToTrail(TrailPtr* trail, |
| 16029 const AbstractType& buddy) const { | 16030 const AbstractType& buddy) const { |
| 16030 if (*trail == NULL) { | 16031 if (*trail == NULL) { |
| 16031 *trail = new Trail(4); | 16032 *trail = new Trail(Thread::Current()->zone(), 4); |
| 16032 } else { | 16033 } else { |
| 16033 const intptr_t len = (*trail)->length(); | 16034 const intptr_t len = (*trail)->length(); |
| 16034 ASSERT((len % 2) == 0); | 16035 ASSERT((len % 2) == 0); |
| 16035 for (intptr_t i = 0; i < len; i += 2) { | 16036 for (intptr_t i = 0; i < len; i += 2) { |
| 16036 ASSERT((*trail)->At(i)->IsZoneHandle()); | 16037 if (((*trail)->At(i).raw() == this->raw()) && |
| 16037 ASSERT((*trail)->At(i + 1)->IsZoneHandle()); | 16038 ((*trail)->At(i + 1).raw() == buddy.raw())) { |
| 16038 if (((*trail)->At(i)->raw() == this->raw()) && | |
| 16039 ((*trail)->At(i + 1)->raw() == buddy.raw())) { | |
| 16040 return true; | 16039 return true; |
| 16041 } | 16040 } |
| 16042 } | 16041 } |
| 16043 } | 16042 } |
| 16044 AbstractType& t = AbstractType::ZoneHandle(this->raw()); | 16043 (*trail)->Add(*this); |
| 16045 AbstractType& b = AbstractType::ZoneHandle(buddy.raw()); | 16044 (*trail)->Add(buddy); |
| 16046 (*trail)->Add(&t); | |
| 16047 (*trail)->Add(&b); | |
| 16048 return false; | 16045 return false; |
| 16049 } | 16046 } |
| 16050 | 16047 |
| 16051 | 16048 |
| 16052 RawTypeRef* TypeRef::New() { | 16049 RawTypeRef* TypeRef::New() { |
| 16053 RawObject* raw = Object::Allocate(TypeRef::kClassId, | 16050 RawObject* raw = Object::Allocate(TypeRef::kClassId, |
| 16054 TypeRef::InstanceSize(), | 16051 TypeRef::InstanceSize(), |
| 16055 Heap::kOld); | 16052 Heap::kOld); |
| 16056 return reinterpret_cast<RawTypeRef*>(raw); | 16053 return reinterpret_cast<RawTypeRef*>(raw); |
| 16057 } | 16054 } |
| (...skipping 5403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21461 return tag_label.ToCString(); | 21458 return tag_label.ToCString(); |
| 21462 } | 21459 } |
| 21463 | 21460 |
| 21464 | 21461 |
| 21465 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21462 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 21466 Instance::PrintJSONImpl(stream, ref); | 21463 Instance::PrintJSONImpl(stream, ref); |
| 21467 } | 21464 } |
| 21468 | 21465 |
| 21469 | 21466 |
| 21470 } // namespace dart | 21467 } // namespace dart |
| OLD | NEW |