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 6459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6470 signature_class, signature_type, ClassFinalizer::kCanonicalize); | 6470 signature_class, signature_type, ClassFinalizer::kCanonicalize); |
6471 } | 6471 } |
6472 ASSERT(closure_function.signature_class() == signature_class.raw()); | 6472 ASSERT(closure_function.signature_class() == signature_class.raw()); |
6473 set_implicit_closure_function(closure_function); | 6473 set_implicit_closure_function(closure_function); |
6474 ASSERT(closure_function.IsImplicitClosureFunction()); | 6474 ASSERT(closure_function.IsImplicitClosureFunction()); |
6475 return closure_function.raw(); | 6475 return closure_function.raw(); |
6476 } | 6476 } |
6477 | 6477 |
6478 | 6478 |
6479 RawString* Function::UserVisibleFormalParameters() const { | 6479 RawString* Function::UserVisibleFormalParameters() const { |
6480 const GrowableObjectArray& pieces = | 6480 GrowableArray<const String*> pieces(4); |
koda
2015/08/26 17:37:06
Nit, but wouldn't 3 or 5 make more sense? E.g.,
{f
srdjan
2015/08/26 19:43:55
Set to 5 and added comment.
| |
6481 GrowableObjectArray::Handle(GrowableObjectArray::New()); | |
6482 const TypeArguments& instantiator = TypeArguments::Handle(); | 6481 const TypeArguments& instantiator = TypeArguments::Handle(); |
6483 BuildSignatureParameters(false, kUserVisibleName, instantiator, pieces); | 6482 BuildSignatureParameters(false, kUserVisibleName, instantiator, &pieces); |
6484 const Array& strings = Array::Handle(Array::MakeArray(pieces)); | 6483 return Symbols::FromConcatAll(pieces); |
6485 return String::ConcatAll(strings); | |
6486 } | 6484 } |
6487 | 6485 |
6488 | 6486 |
6489 void Function::BuildSignatureParameters( | 6487 void Function::BuildSignatureParameters( |
6490 bool instantiate, | 6488 bool instantiate, |
6491 NameVisibility name_visibility, | 6489 NameVisibility name_visibility, |
6492 const TypeArguments& instantiator, | 6490 const TypeArguments& instantiator, |
6493 const GrowableObjectArray& pieces) const { | 6491 GrowableArray<const String*>* pieces) const { |
6494 AbstractType& param_type = AbstractType::Handle(); | 6492 Thread* thread = Thread::Current(); |
6493 Zone* zone = thread->zone(); | |
6494 | |
6495 AbstractType& param_type = AbstractType::Handle(zone); | |
6495 const intptr_t num_params = NumParameters(); | 6496 const intptr_t num_params = NumParameters(); |
6496 const intptr_t num_fixed_params = num_fixed_parameters(); | 6497 const intptr_t num_fixed_params = num_fixed_parameters(); |
6497 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); | 6498 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); |
6498 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); | 6499 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); |
6499 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; | 6500 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; |
6500 ASSERT((num_fixed_params + num_opt_params) == num_params); | 6501 ASSERT((num_fixed_params + num_opt_params) == num_params); |
6501 String& name = String::Handle(); | |
6502 intptr_t i = 0; | 6502 intptr_t i = 0; |
6503 if (name_visibility == kUserVisibleName) { | 6503 if (name_visibility == kUserVisibleName) { |
6504 // Hide implicit parameters. | 6504 // Hide implicit parameters. |
6505 i = NumImplicitParameters(); | 6505 i = NumImplicitParameters(); |
6506 } | 6506 } |
6507 while (i < num_fixed_params) { | 6507 while (i < num_fixed_params) { |
6508 param_type = ParameterTypeAt(i); | 6508 param_type = ParameterTypeAt(i); |
6509 ASSERT(!param_type.IsNull()); | 6509 ASSERT(!param_type.IsNull()); |
6510 if (instantiate && !param_type.IsInstantiated()) { | 6510 if (instantiate && !param_type.IsInstantiated()) { |
6511 param_type = param_type.InstantiateFrom(instantiator, NULL); | 6511 param_type = param_type.InstantiateFrom(instantiator, NULL); |
6512 } | 6512 } |
6513 name = param_type.BuildName(name_visibility); | 6513 const String& name = |
6514 pieces.Add(name); | 6514 String::ZoneHandle(zone, param_type.BuildName(name_visibility)); |
6515 pieces->Add(&name); | |
6515 if (i != (num_params - 1)) { | 6516 if (i != (num_params - 1)) { |
6516 pieces.Add(Symbols::CommaSpace()); | 6517 pieces->Add(&Symbols::CommaSpace()); |
6517 } | 6518 } |
6518 i++; | 6519 i++; |
6519 } | 6520 } |
6520 if (num_opt_params > 0) { | 6521 if (num_opt_params > 0) { |
6521 if (num_opt_pos_params > 0) { | 6522 if (num_opt_pos_params > 0) { |
6522 pieces.Add(Symbols::LBracket()); | 6523 pieces->Add(&Symbols::LBracket()); |
6523 } else { | 6524 } else { |
6524 pieces.Add(Symbols::LBrace()); | 6525 pieces->Add(&Symbols::LBrace()); |
6525 } | 6526 } |
6526 for (intptr_t i = num_fixed_params; i < num_params; i++) { | 6527 for (intptr_t i = num_fixed_params; i < num_params; i++) { |
6527 // The parameter name of an optional positional parameter does not need | 6528 // The parameter name of an optional positional parameter does not need |
6528 // to be part of the signature, since it is not used. | 6529 // to be part of the signature, since it is not used. |
6529 if (num_opt_named_params > 0) { | 6530 if (num_opt_named_params > 0) { |
6530 name = ParameterNameAt(i); | 6531 const String& name = String::ZoneHandle(zone, ParameterNameAt(i)); |
6531 pieces.Add(name); | 6532 pieces->Add(&name); |
6532 pieces.Add(Symbols::ColonSpace()); | 6533 pieces->Add(&Symbols::ColonSpace()); |
6533 } | 6534 } |
6534 param_type = ParameterTypeAt(i); | 6535 param_type = ParameterTypeAt(i); |
6535 if (instantiate && !param_type.IsInstantiated()) { | 6536 if (instantiate && !param_type.IsInstantiated()) { |
6536 param_type = param_type.InstantiateFrom(instantiator, NULL); | 6537 param_type = param_type.InstantiateFrom(instantiator, NULL); |
6537 } | 6538 } |
6538 ASSERT(!param_type.IsNull()); | 6539 ASSERT(!param_type.IsNull()); |
6539 name = param_type.BuildName(name_visibility); | 6540 const String& name = |
6540 pieces.Add(name); | 6541 String::ZoneHandle(zone, param_type.BuildName(name_visibility)); |
6542 pieces->Add(&name); | |
6541 if (i != (num_params - 1)) { | 6543 if (i != (num_params - 1)) { |
6542 pieces.Add(Symbols::CommaSpace()); | 6544 pieces->Add(&Symbols::CommaSpace()); |
6543 } | 6545 } |
6544 } | 6546 } |
6545 if (num_opt_pos_params > 0) { | 6547 if (num_opt_pos_params > 0) { |
6546 pieces.Add(Symbols::RBracket()); | 6548 pieces->Add(&Symbols::RBracket()); |
6547 } else { | 6549 } else { |
6548 pieces.Add(Symbols::RBrace()); | 6550 pieces->Add(&Symbols::RBrace()); |
6549 } | 6551 } |
6550 } | 6552 } |
6551 } | 6553 } |
6552 | 6554 |
6553 | 6555 |
6554 RawInstance* Function::ImplicitStaticClosure() const { | 6556 RawInstance* Function::ImplicitStaticClosure() const { |
6555 if (implicit_static_closure() == Instance::null()) { | 6557 if (implicit_static_closure() == Instance::null()) { |
6556 Isolate* isolate = Isolate::Current(); | 6558 Isolate* isolate = Isolate::Current(); |
6557 ObjectStore* object_store = isolate->object_store(); | 6559 ObjectStore* object_store = isolate->object_store(); |
6558 const Context& context = | 6560 const Context& context = |
(...skipping 20 matching lines...) Expand all Loading... | |
6579 TypeArguments::Handle(receiver.GetTypeArguments()); | 6581 TypeArguments::Handle(receiver.GetTypeArguments()); |
6580 result.SetTypeArguments(type_arguments); | 6582 result.SetTypeArguments(type_arguments); |
6581 } | 6583 } |
6582 return result.raw(); | 6584 return result.raw(); |
6583 } | 6585 } |
6584 | 6586 |
6585 | 6587 |
6586 RawString* Function::BuildSignature(bool instantiate, | 6588 RawString* Function::BuildSignature(bool instantiate, |
6587 NameVisibility name_visibility, | 6589 NameVisibility name_visibility, |
6588 const TypeArguments& instantiator) const { | 6590 const TypeArguments& instantiator) const { |
6589 const GrowableObjectArray& pieces = | 6591 Thread* thread = Thread::Current(); |
6590 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 6592 Zone* zone = thread->zone(); |
6591 String& name = String::Handle(); | 6593 GrowableArray<const String*> pieces(zone, 4); |
koda
2015/08/26 17:37:06
Ditto about choosing most common case as default.
srdjan
2015/08/26 19:43:55
Here it is not that clear/typical ('(dynamic) => d
| |
6592 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { | 6594 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { |
6593 // Prefix the signature with its signature class and type parameters, if any | 6595 // Prefix the signature with its signature class and type parameters, if any |
6594 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the | 6596 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the |
6595 // signature class name is the alias name. | 6597 // signature class name is the alias name. |
6596 // The signature of static functions cannot be type parameterized. | 6598 // The signature of static functions cannot be type parameterized. |
6597 const Class& function_class = Class::Handle(Owner()); | 6599 const Class& function_class = Class::Handle(zone, Owner()); |
6598 ASSERT(!function_class.IsNull()); | 6600 ASSERT(!function_class.IsNull()); |
6599 const TypeArguments& type_parameters = TypeArguments::Handle( | 6601 const TypeArguments& type_parameters = TypeArguments::Handle( |
6600 function_class.type_parameters()); | 6602 zone, function_class.type_parameters()); |
6601 if (!type_parameters.IsNull()) { | 6603 if (!type_parameters.IsNull()) { |
6602 const String& function_class_name = String::Handle(function_class.Name()); | 6604 const String& function_class_name = |
6603 pieces.Add(function_class_name); | 6605 String::ZoneHandle(zone, function_class.Name()); |
6606 pieces.Add(&function_class_name); | |
6604 const intptr_t num_type_parameters = type_parameters.Length(); | 6607 const intptr_t num_type_parameters = type_parameters.Length(); |
6605 pieces.Add(Symbols::LAngleBracket()); | 6608 pieces.Add(&Symbols::LAngleBracket()); |
6606 TypeParameter& type_parameter = TypeParameter::Handle(); | 6609 TypeParameter& type_parameter = TypeParameter::Handle(zone); |
6607 AbstractType& bound = AbstractType::Handle(); | 6610 AbstractType& bound = AbstractType::Handle(zone); |
6608 for (intptr_t i = 0; i < num_type_parameters; i++) { | 6611 for (intptr_t i = 0; i < num_type_parameters; i++) { |
6609 type_parameter ^= type_parameters.TypeAt(i); | 6612 type_parameter ^= type_parameters.TypeAt(i); |
6610 name = type_parameter.name(); | 6613 const String& name = String::ZoneHandle(zone, type_parameter.name()); |
6611 pieces.Add(name); | 6614 pieces.Add(&name); |
6612 bound = type_parameter.bound(); | 6615 bound = type_parameter.bound(); |
6613 if (!bound.IsNull() && !bound.IsObjectType()) { | 6616 if (!bound.IsNull() && !bound.IsObjectType()) { |
6614 pieces.Add(Symbols::SpaceExtendsSpace()); | 6617 pieces.Add(&Symbols::SpaceExtendsSpace()); |
6615 name = bound.BuildName(name_visibility); | 6618 const String& name = |
6616 pieces.Add(name); | 6619 String::ZoneHandle(zone, bound.BuildName(name_visibility)); |
6620 pieces.Add(&name); | |
6617 } | 6621 } |
6618 if (i < num_type_parameters - 1) { | 6622 if (i < num_type_parameters - 1) { |
6619 pieces.Add(Symbols::CommaSpace()); | 6623 pieces.Add(&Symbols::CommaSpace()); |
6620 } | 6624 } |
6621 } | 6625 } |
6622 pieces.Add(Symbols::RAngleBracket()); | 6626 pieces.Add(&Symbols::RAngleBracket()); |
6623 } | 6627 } |
6624 } | 6628 } |
6625 pieces.Add(Symbols::LParen()); | 6629 pieces.Add(&Symbols::LParen()); |
6626 BuildSignatureParameters(instantiate, | 6630 BuildSignatureParameters(instantiate, |
6627 name_visibility, | 6631 name_visibility, |
6628 instantiator, | 6632 instantiator, |
6629 pieces); | 6633 &pieces); |
6630 pieces.Add(Symbols::RParenArrow()); | 6634 pieces.Add(&Symbols::RParenArrow()); |
6631 AbstractType& res_type = AbstractType::Handle(result_type()); | 6635 AbstractType& res_type = AbstractType::Handle(zone, result_type()); |
6632 if (instantiate && !res_type.IsInstantiated()) { | 6636 if (instantiate && !res_type.IsInstantiated()) { |
6633 res_type = res_type.InstantiateFrom(instantiator, NULL); | 6637 res_type = res_type.InstantiateFrom(instantiator, NULL); |
6634 } | 6638 } |
6635 name = res_type.BuildName(name_visibility); | 6639 const String& name = |
6636 pieces.Add(name); | 6640 String::ZoneHandle(zone, res_type.BuildName(name_visibility)); |
6637 const Array& strings = Array::Handle(Array::MakeArray(pieces)); | 6641 pieces.Add(&name); |
6638 return Symbols::New(String::Handle(String::ConcatAll(strings))); | 6642 return Symbols::FromConcatAll(pieces); |
6639 } | 6643 } |
6640 | 6644 |
6641 | 6645 |
6642 bool Function::HasInstantiatedSignature() const { | 6646 bool Function::HasInstantiatedSignature() const { |
6643 AbstractType& type = AbstractType::Handle(result_type()); | 6647 AbstractType& type = AbstractType::Handle(result_type()); |
6644 if (!type.IsInstantiated()) { | 6648 if (!type.IsInstantiated()) { |
6645 return false; | 6649 return false; |
6646 } | 6650 } |
6647 const intptr_t num_parameters = NumParameters(); | 6651 const intptr_t num_parameters = NumParameters(); |
6648 for (intptr_t i = 0; i < num_parameters; i++) { | 6652 for (intptr_t i = 0; i < num_parameters; i++) { |
(...skipping 14772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21421 return tag_label.ToCString(); | 21425 return tag_label.ToCString(); |
21422 } | 21426 } |
21423 | 21427 |
21424 | 21428 |
21425 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21429 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
21426 Instance::PrintJSONImpl(stream, ref); | 21430 Instance::PrintJSONImpl(stream, ref); |
21427 } | 21431 } |
21428 | 21432 |
21429 | 21433 |
21430 } // namespace dart | 21434 } // namespace dart |
OLD | NEW |