OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 RawString* Class::Name() const { | 689 RawString* Class::Name() const { |
690 if (raw_ptr()->name_ != String::null()) { | 690 if (raw_ptr()->name_ != String::null()) { |
691 return raw_ptr()->name_; | 691 return raw_ptr()->name_; |
692 } | 692 } |
693 ASSERT(class_class() != null_); // Or GetSingletonClassIndex will not work. | 693 ASSERT(class_class() != null_); // Or GetSingletonClassIndex will not work. |
694 intptr_t index = GetSingletonClassIndex(raw()); | 694 intptr_t index = GetSingletonClassIndex(raw()); |
695 return String::NewSymbol(GetSingletonClassName(index)); | 695 return String::NewSymbol(GetSingletonClassName(index)); |
696 } | 696 } |
697 | 697 |
698 | 698 |
| 699 RawType* Class::SignatureType() const { |
| 700 // Return the cached signature type if any. |
| 701 if (raw_ptr()->signature_type_ != Type::null()) { |
| 702 return raw_ptr()->signature_type_; |
| 703 } |
| 704 ASSERT(IsSignatureClass()); |
| 705 TypeArguments& signature_type_arguments = TypeArguments::Handle(); |
| 706 const intptr_t num_type_params = NumTypeParameters(); |
| 707 // If the signature class extends a parameterized class, the type arguments of |
| 708 // the super class will be prepended to the type argument vector during type |
| 709 // finalization. We only need to provide the type parameters of the signature |
| 710 // class here. |
| 711 if (num_type_params > 0) { |
| 712 const Array& type_params = Array::Handle(type_parameters()); |
| 713 signature_type_arguments = TypeArguments::NewTypeArray(num_type_params); |
| 714 String& type_param_name = String::Handle(); |
| 715 Type& type_param = Type::Handle(); |
| 716 for (int i = 0; i < num_type_params; i++) { |
| 717 type_param_name ^= type_params.At(i); |
| 718 type_param = Type::NewTypeParameter(i, type_param_name); |
| 719 signature_type_arguments.SetTypeAt(i, type_param); |
| 720 } |
| 721 } |
| 722 const ParameterizedType& signature_type = ParameterizedType::Handle( |
| 723 ParameterizedType::New(*this, signature_type_arguments)); |
| 724 |
| 725 // Cache and return the still unfinalized signature type. |
| 726 ASSERT(!signature_type.IsFinalized()); |
| 727 set_signature_type(signature_type); |
| 728 return signature_type.raw(); |
| 729 } |
| 730 |
| 731 |
699 template <class FakeObject> | 732 template <class FakeObject> |
700 RawClass* Class::New() { | 733 RawClass* Class::New() { |
701 Class& class_class = Class::Handle(Object::class_class()); | 734 Class& class_class = Class::Handle(Object::class_class()); |
702 Class& result = Class::Handle(); | 735 Class& result = Class::Handle(); |
703 { | 736 { |
704 RawObject* raw = Object::Allocate(class_class, | 737 RawObject* raw = Object::Allocate(class_class, |
705 Class::InstanceSize(), | 738 Class::InstanceSize(), |
706 Heap::kOld); | 739 Heap::kOld); |
707 NoGCScope no_gc; | 740 NoGCScope no_gc; |
708 if (class_class.IsNull()) { | 741 if (class_class.IsNull()) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 StorePointer(&raw_ptr()->functions_, value.raw()); | 792 StorePointer(&raw_ptr()->functions_, value.raw()); |
760 } | 793 } |
761 | 794 |
762 | 795 |
763 void Class::set_signature_function(const Function& value) const { | 796 void Class::set_signature_function(const Function& value) const { |
764 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); | 797 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); |
765 StorePointer(&raw_ptr()->signature_function_, value.raw()); | 798 StorePointer(&raw_ptr()->signature_function_, value.raw()); |
766 } | 799 } |
767 | 800 |
768 | 801 |
| 802 void Class::set_signature_type(const Type& value) const { |
| 803 StorePointer(&raw_ptr()->signature_type_, value.raw()); |
| 804 } |
| 805 |
| 806 |
769 void Class::set_class_state(int8_t state) const { | 807 void Class::set_class_state(int8_t state) const { |
770 ASSERT(state == RawClass::kAllocated || | 808 ASSERT(state == RawClass::kAllocated || |
771 state == RawClass::kPreFinalized || | 809 state == RawClass::kPreFinalized || |
772 state == RawClass::kFinalized); | 810 state == RawClass::kFinalized); |
773 raw_ptr()->class_state_ = state; | 811 raw_ptr()->class_state_ = state; |
774 } | 812 } |
775 | 813 |
776 | 814 |
777 void Class::set_library(const Library& value) const { | 815 void Class::set_library(const Library& value) const { |
778 StorePointer(&raw_ptr()->library_, value.raw()); | 816 StorePointer(&raw_ptr()->library_, value.raw()); |
(...skipping 16 matching lines...) Expand all Loading... |
795 return 0; | 833 return 0; |
796 } else { | 834 } else { |
797 return type_params.Length(); | 835 return type_params.Length(); |
798 } | 836 } |
799 } | 837 } |
800 | 838 |
801 | 839 |
802 intptr_t Class::NumTypeArguments() const { | 840 intptr_t Class::NumTypeArguments() const { |
803 intptr_t num_type_args = NumTypeParameters(); | 841 intptr_t num_type_args = NumTypeParameters(); |
804 const Class& superclass = Class::Handle(SuperClass()); | 842 const Class& superclass = Class::Handle(SuperClass()); |
805 if (!superclass.IsNull()) { | 843 // Object is its own super class during bootstrap. |
| 844 if (!superclass.IsNull() && (superclass.raw() != raw())) { |
806 num_type_args += superclass.NumTypeArguments(); | 845 num_type_args += superclass.NumTypeArguments(); |
807 } | 846 } |
808 return num_type_args; | 847 return num_type_args; |
809 } | 848 } |
810 | 849 |
811 | 850 |
812 RawClass* Class::SuperClass() const { | 851 RawClass* Class::SuperClass() const { |
813 const Type& sup_type = Type::Handle(super_type()); | 852 const Type& sup_type = Type::Handle(super_type()); |
814 if (sup_type.IsNull()) { | 853 if (sup_type.IsNull()) { |
815 return Class::null(); | 854 return Class::null(); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 return result.raw(); | 1009 return result.raw(); |
971 } | 1010 } |
972 | 1011 |
973 | 1012 |
974 RawClass* Class::NewSignatureClass(const String& name, | 1013 RawClass* Class::NewSignatureClass(const String& name, |
975 const Function& signature_function, | 1014 const Function& signature_function, |
976 const Script& script, | 1015 const Script& script, |
977 intptr_t token_index) { | 1016 intptr_t token_index) { |
978 ASSERT(!signature_function.IsNull()); | 1017 ASSERT(!signature_function.IsNull()); |
979 Type& super_type = Type::Handle(Type::ObjectType()); | 1018 Type& super_type = Type::Handle(Type::ObjectType()); |
| 1019 const Class& owner_class = Class::Handle(signature_function.owner()); |
| 1020 ASSERT(!owner_class.IsNull()); |
980 Array& type_parameters = Array::Handle(); | 1021 Array& type_parameters = Array::Handle(); |
981 TypeArray& type_parameter_extends = TypeArray::Handle(); | 1022 TypeArray& type_parameter_extends = TypeArray::Handle(); |
982 if (!signature_function.is_static()) { | 1023 if (!signature_function.is_static()) { |
983 const Class& owner_class = Class::Handle(signature_function.owner()); | 1024 if (owner_class.IsParameterized() && |
984 ASSERT(!owner_class.IsNull()); | 1025 !signature_function.HasInstantiatedSignature()) { |
985 ASSERT(!owner_class.is_interface()); | |
986 if (owner_class.IsParameterized()) { | |
987 // Share the function owner super class as the super class of the | 1026 // Share the function owner super class as the super class of the |
988 // signature class, so that the type argument vector of the closure at | 1027 // signature class, so that the type argument vector of the closure at |
989 // run time matches the type argument vector of the closure instantiator. | 1028 // run time matches the type argument vector of the closure instantiator. |
990 type_parameters = owner_class.type_parameters(); | 1029 type_parameters = owner_class.type_parameters(); |
991 type_parameter_extends = owner_class.type_parameter_extends(); | 1030 type_parameter_extends = owner_class.type_parameter_extends(); |
992 super_type = owner_class.super_type(); | 1031 if (!owner_class.is_interface()) { |
| 1032 super_type = owner_class.super_type(); |
| 1033 } |
993 } | 1034 } |
994 } | 1035 } |
995 Class& result = Class::Handle(New<Closure>(name, script)); | 1036 Class& result = Class::Handle(New<Closure>(name, script)); |
996 result.set_super_type(super_type); | 1037 result.set_super_type(super_type); |
997 result.set_signature_function(signature_function); | 1038 result.set_signature_function(signature_function); |
998 result.set_type_parameters(type_parameters); | 1039 result.set_type_parameters(type_parameters); |
999 result.set_type_parameter_extends(type_parameter_extends); | 1040 result.set_type_parameter_extends(type_parameter_extends); |
1000 result.SetFields(Array::Handle(Array::Empty())); | 1041 result.SetFields(Array::Handle(Array::Empty())); |
1001 result.SetFunctions(Array::Handle(Array::Empty())); | 1042 result.SetFunctions(Array::Handle(Array::Empty())); |
1002 // Implements interface Function. | 1043 // Implements interface Function. |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 } | 1620 } |
1580 | 1621 |
1581 | 1622 |
1582 bool Type::IsFinalized() const { | 1623 bool Type::IsFinalized() const { |
1583 // Type is an abstract class. | 1624 // Type is an abstract class. |
1584 UNREACHABLE(); | 1625 UNREACHABLE(); |
1585 return false; | 1626 return false; |
1586 } | 1627 } |
1587 | 1628 |
1588 | 1629 |
| 1630 bool Type::IsBeingFinalized() const { |
| 1631 // Type is an abstract class. |
| 1632 UNREACHABLE(); |
| 1633 return false; |
| 1634 } |
| 1635 |
| 1636 |
1589 RawType* Type::InstantiateFrom( | 1637 RawType* Type::InstantiateFrom( |
1590 const TypeArguments& instantiator_type_arguments, | 1638 const TypeArguments& instantiator_type_arguments, |
1591 intptr_t offset) const { | 1639 intptr_t offset) const { |
1592 // Type is an abstract class. | 1640 // Type is an abstract class. |
1593 UNREACHABLE(); | 1641 UNREACHABLE(); |
1594 return Type::null(); | 1642 return Type::null(); |
1595 } | 1643 } |
1596 | 1644 |
1597 | 1645 |
1598 RawString* Type::Name() const { | 1646 RawString* Type::Name() const { |
1599 const TypeArguments& args = TypeArguments::Handle(arguments()); | 1647 const TypeArguments& args = TypeArguments::Handle(arguments()); |
1600 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); | 1648 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); |
1601 String& class_name = String::Handle(); | 1649 String& class_name = String::Handle(); |
1602 intptr_t first_type_param_index; | 1650 intptr_t first_type_param_index; |
1603 intptr_t num_type_params; // Number of type parameters to print. | 1651 intptr_t num_type_params; // Number of type parameters to print. |
1604 if (HasResolvedTypeClass()) { | 1652 if (HasResolvedTypeClass()) { |
1605 const Class& cls = Class::Handle(type_class()); | 1653 const Class& cls = Class::Handle(type_class()); |
1606 class_name = cls.Name(); | 1654 class_name = cls.Name(); |
1607 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. | 1655 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. |
1608 if (num_type_params > num_args) { | 1656 if (num_type_params > num_args) { |
1609 ASSERT(!IsFinalized()); | 1657 ASSERT(num_args == 0); // Type is raw. |
1610 // We fill up with "var". | 1658 // We fill up with "var". |
1611 first_type_param_index = 0; | 1659 first_type_param_index = 0; |
1612 } else { | 1660 } else { |
1613 first_type_param_index = num_args - num_type_params; | 1661 first_type_param_index = num_args - num_type_params; |
1614 } | 1662 } |
| 1663 if (cls.IsSignatureClass()) { |
| 1664 const Function& signature_function = Function::Handle( |
| 1665 cls.signature_function()); |
| 1666 // We may be reporting an error about an illformed function type. In that |
| 1667 // case, avoid instantiating the signature, since it may lead to cycles. |
| 1668 if (IsBeingFinalized()) { |
| 1669 return class_name.raw(); |
| 1670 } |
| 1671 return signature_function.InstantiatedSignatureFrom( |
| 1672 args, first_type_param_index); |
| 1673 } |
1615 } else { | 1674 } else { |
1616 const UnresolvedClass& type = UnresolvedClass::Handle(unresolved_class()); | 1675 const UnresolvedClass& type = UnresolvedClass::Handle(unresolved_class()); |
1617 class_name = type.Name(); | 1676 class_name = type.Name(); |
1618 num_type_params = num_args; | 1677 num_type_params = num_args; |
1619 first_type_param_index = 0; | 1678 first_type_param_index = 0; |
1620 } | 1679 } |
1621 String& type_name = String::Handle(); | 1680 String& type_name = String::Handle(); |
1622 if (num_type_params == 0) { | 1681 if (num_type_params == 0) { |
1623 type_name = class_name.raw(); | 1682 type_name = class_name.raw(); |
1624 } else { | 1683 } else { |
(...skipping 13 matching lines...) Expand all Loading... |
1638 type_name = type.Name(); | 1697 type_name = type.Name(); |
1639 strings.SetAt(s++, type_name); | 1698 strings.SetAt(s++, type_name); |
1640 if (i < num_type_params - 1) { | 1699 if (i < num_type_params - 1) { |
1641 strings.SetAt(s++, kCommaSpace); | 1700 strings.SetAt(s++, kCommaSpace); |
1642 } | 1701 } |
1643 } | 1702 } |
1644 strings.SetAt(s++, String::Handle(String::NewSymbol(">"))); | 1703 strings.SetAt(s++, String::Handle(String::NewSymbol(">"))); |
1645 ASSERT(s == num_strings); | 1704 ASSERT(s == num_strings); |
1646 type_name = String::ConcatAll(strings); | 1705 type_name = String::ConcatAll(strings); |
1647 } | 1706 } |
1648 // The name is only used for naming function types and for debugging purposes. | 1707 // The name is only used for type checking and debugging purposes. |
1649 // Unless profiling data shows otherwise, it is not worth caching the name in | 1708 // Unless profiling data shows otherwise, it is not worth caching the name in |
1650 // the type. | 1709 // the type. |
1651 return String::NewSymbol(type_name); | 1710 return String::NewSymbol(type_name); |
1652 } | 1711 } |
1653 | 1712 |
1654 | 1713 |
1655 intptr_t Type::Index() const { | 1714 intptr_t Type::Index() const { |
1656 // Type is an abstract class. | 1715 // Type is an abstract class. |
1657 UNREACHABLE(); | 1716 UNREACHABLE(); |
1658 return -1; | 1717 return -1; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 } | 1894 } |
1836 | 1895 |
1837 | 1896 |
1838 void ParameterizedType::set_is_finalized() const { | 1897 void ParameterizedType::set_is_finalized() const { |
1839 ASSERT(!IsFinalized()); | 1898 ASSERT(!IsFinalized()); |
1840 set_type_state(RawParameterizedType::kFinalized); | 1899 set_type_state(RawParameterizedType::kFinalized); |
1841 } | 1900 } |
1842 | 1901 |
1843 | 1902 |
1844 void ParameterizedType::set_is_being_finalized() const { | 1903 void ParameterizedType::set_is_being_finalized() const { |
1845 ASSERT(!IsFinalized() && !is_being_finalized()); | 1904 ASSERT(!IsFinalized() && !IsBeingFinalized()); |
1846 set_type_state(RawParameterizedType::kBeingFinalized); | 1905 set_type_state(RawParameterizedType::kBeingFinalized); |
1847 } | 1906 } |
1848 | 1907 |
1849 | 1908 |
1850 bool ParameterizedType::IsResolved() const { | 1909 bool ParameterizedType::IsResolved() const { |
1851 if (!HasResolvedTypeClass()) { | 1910 if (!HasResolvedTypeClass()) { |
1852 return false; | 1911 return false; |
1853 } | 1912 } |
1854 const TypeArguments& args = TypeArguments::Handle(arguments()); | 1913 const TypeArguments& args = TypeArguments::Handle(arguments()); |
1855 return args.IsNull() || args.IsResolved(); | 1914 return args.IsNull() || args.IsResolved(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 const TypeArguments& instantiator_type_arguments, | 1953 const TypeArguments& instantiator_type_arguments, |
1895 intptr_t offset) const { | 1954 intptr_t offset) const { |
1896 ASSERT(IsFinalized()); | 1955 ASSERT(IsFinalized()); |
1897 ASSERT(!IsInstantiated()); | 1956 ASSERT(!IsInstantiated()); |
1898 TypeArguments& type_arguments = TypeArguments::Handle(); | 1957 TypeArguments& type_arguments = TypeArguments::Handle(); |
1899 if (!instantiator_type_arguments.IsNull()) { | 1958 if (!instantiator_type_arguments.IsNull()) { |
1900 type_arguments = arguments(); | 1959 type_arguments = arguments(); |
1901 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, | 1960 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, |
1902 offset); | 1961 offset); |
1903 } | 1962 } |
| 1963 const Class& cls = Class::Handle(type_class()); |
1904 ParameterizedType& instantiated_type = ParameterizedType::Handle( | 1964 ParameterizedType& instantiated_type = ParameterizedType::Handle( |
1905 ParameterizedType::New(Object::Handle(type_class()), type_arguments)); | 1965 ParameterizedType::New(cls, type_arguments)); |
| 1966 ASSERT(type_arguments.IsNull() || |
| 1967 (type_arguments.Length() == cls.NumTypeArguments())); |
1906 instantiated_type.set_is_finalized(); | 1968 instantiated_type.set_is_finalized(); |
1907 return instantiated_type.raw(); | 1969 return instantiated_type.raw(); |
1908 } | 1970 } |
1909 | 1971 |
1910 | 1972 |
1911 void ParameterizedType::set_type_class(const Object& value) const { | 1973 void ParameterizedType::set_type_class(const Object& value) const { |
1912 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); | 1974 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); |
1913 StorePointer(&raw_ptr()->type_class_, value.raw()); | 1975 StorePointer(&raw_ptr()->type_class_, value.raw()); |
1914 } | 1976 } |
1915 | 1977 |
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2903 template<typename T> | 2965 template<typename T> |
2904 static RawArray* NewArray(const GrowableArray<T*>& objs) { | 2966 static RawArray* NewArray(const GrowableArray<T*>& objs) { |
2905 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); | 2967 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); |
2906 for (int i = 0; i < objs.length(); i++) { | 2968 for (int i = 0; i < objs.length(); i++) { |
2907 a.SetAt(i, *objs[i]); | 2969 a.SetAt(i, *objs[i]); |
2908 } | 2970 } |
2909 return a.raw(); | 2971 return a.raw(); |
2910 } | 2972 } |
2911 | 2973 |
2912 | 2974 |
2913 // Build a string of the form '<T>(A, [b: B, c: C]) => R)' representing the | 2975 RawString* Function::BuildSignature(bool instantiate, |
2914 // signature of the given function. | 2976 const TypeArguments& instantiator, |
2915 RawString* Function::Signature() const { | 2977 intptr_t offset) const { |
2916 GrowableArray<const String*> pieces; | 2978 GrowableArray<const String*> pieces; |
2917 const String& kSpaceExtendsSpace = | |
2918 String::Handle(String::NewSymbol(" extends ")); | |
2919 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); | 2979 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); |
2920 const String& kColonSpace = String::Handle(String::NewSymbol(": ")); | 2980 const String& kColonSpace = String::Handle(String::NewSymbol(": ")); |
2921 const String& kLAngleBracket = String::Handle(String::NewSymbol("<")); | |
2922 const String& kRAngleBracket = String::Handle(String::NewSymbol(">")); | |
2923 const String& kLParen = String::Handle(String::NewSymbol("(")); | 2981 const String& kLParen = String::Handle(String::NewSymbol("(")); |
2924 const String& kRParen = String::Handle(String::NewSymbol(") => ")); | 2982 const String& kRParen = String::Handle(String::NewSymbol(") => ")); |
2925 const String& kLBracket = String::Handle(String::NewSymbol("[")); | 2983 const String& kLBracket = String::Handle(String::NewSymbol("[")); |
2926 const String& kRBracket = String::Handle(String::NewSymbol("]")); | 2984 const String& kRBracket = String::Handle(String::NewSymbol("]")); |
2927 if (!is_static()) { | 2985 if (!instantiate && !is_static()) { |
| 2986 const String& kSpaceExtendsSpace = |
| 2987 String::Handle(String::NewSymbol(" extends ")); |
| 2988 const String& kLAngleBracket = String::Handle(String::NewSymbol("<")); |
| 2989 const String& kRAngleBracket = String::Handle(String::NewSymbol(">")); |
2928 const Class& function_class = Class::Handle(owner()); | 2990 const Class& function_class = Class::Handle(owner()); |
2929 ASSERT(!function_class.IsNull()); | 2991 ASSERT(!function_class.IsNull()); |
2930 const Array& type_parameters = Array::Handle( | 2992 const Array& type_parameters = Array::Handle( |
2931 function_class.type_parameters()); | 2993 function_class.type_parameters()); |
2932 if (!type_parameters.IsNull()) { | 2994 if (!type_parameters.IsNull()) { |
2933 intptr_t num_type_parameters = type_parameters.Length(); | 2995 intptr_t num_type_parameters = type_parameters.Length(); |
2934 pieces.Add(&kLAngleBracket); | 2996 pieces.Add(&kLAngleBracket); |
2935 const TypeArray& type_parameter_extends = TypeArray::Handle( | 2997 const TypeArray& type_parameter_extends = TypeArray::Handle( |
2936 function_class.type_parameter_extends()); | 2998 function_class.type_parameter_extends()); |
2937 Type& parameter_extends = Type::Handle(); | 2999 Type& parameter_extends = Type::Handle(); |
(...skipping 15 matching lines...) Expand all Loading... |
2953 } | 3015 } |
2954 Type& param_type = Type::Handle(); | 3016 Type& param_type = Type::Handle(); |
2955 const intptr_t num_params = NumberOfParameters(); | 3017 const intptr_t num_params = NumberOfParameters(); |
2956 const intptr_t num_fixed_params = num_fixed_parameters(); | 3018 const intptr_t num_fixed_params = num_fixed_parameters(); |
2957 const intptr_t num_opt_params = num_optional_parameters(); | 3019 const intptr_t num_opt_params = num_optional_parameters(); |
2958 ASSERT((num_fixed_params + num_opt_params) == num_params); | 3020 ASSERT((num_fixed_params + num_opt_params) == num_params); |
2959 pieces.Add(&kLParen); | 3021 pieces.Add(&kLParen); |
2960 for (intptr_t i = 0; i < num_fixed_params; i++) { | 3022 for (intptr_t i = 0; i < num_fixed_params; i++) { |
2961 param_type = ParameterTypeAt(i); | 3023 param_type = ParameterTypeAt(i); |
2962 ASSERT(!param_type.IsNull()); | 3024 ASSERT(!param_type.IsNull()); |
| 3025 if (instantiate && !param_type.IsInstantiated()) { |
| 3026 param_type = param_type.InstantiateFrom(instantiator, offset); |
| 3027 } |
2963 pieces.Add(&String::ZoneHandle(param_type.Name())); | 3028 pieces.Add(&String::ZoneHandle(param_type.Name())); |
2964 if (i != (num_params - 1)) { | 3029 if (i != (num_params - 1)) { |
2965 pieces.Add(&kCommaSpace); | 3030 pieces.Add(&kCommaSpace); |
2966 } | 3031 } |
2967 } | 3032 } |
2968 if (num_opt_params > 0) { | 3033 if (num_opt_params > 0) { |
2969 pieces.Add(&kLBracket); | 3034 pieces.Add(&kLBracket); |
2970 for (intptr_t i = num_fixed_params; i < num_params; i++) { | 3035 for (intptr_t i = num_fixed_params; i < num_params; i++) { |
2971 pieces.Add(&String::ZoneHandle(ParameterNameAt(i))); | 3036 pieces.Add(&String::ZoneHandle(ParameterNameAt(i))); |
2972 pieces.Add(&kColonSpace); | 3037 pieces.Add(&kColonSpace); |
2973 param_type = ParameterTypeAt(i); | 3038 param_type = ParameterTypeAt(i); |
| 3039 if (instantiate && !param_type.IsInstantiated()) { |
| 3040 param_type = param_type.InstantiateFrom(instantiator, offset); |
| 3041 } |
2974 ASSERT(!param_type.IsNull()); | 3042 ASSERT(!param_type.IsNull()); |
2975 pieces.Add(&String::ZoneHandle(param_type.Name())); | 3043 pieces.Add(&String::ZoneHandle(param_type.Name())); |
2976 if (i != (num_params - 1)) { | 3044 if (i != (num_params - 1)) { |
2977 pieces.Add(&kCommaSpace); | 3045 pieces.Add(&kCommaSpace); |
2978 } | 3046 } |
2979 } | 3047 } |
2980 pieces.Add(&kRBracket); | 3048 pieces.Add(&kRBracket); |
2981 } | 3049 } |
2982 pieces.Add(&kRParen); | 3050 pieces.Add(&kRParen); |
2983 const Type& res_type = Type::Handle(result_type()); | 3051 Type& res_type = Type::Handle(result_type()); |
| 3052 if (instantiate && !res_type.IsInstantiated()) { |
| 3053 res_type = res_type.InstantiateFrom(instantiator, offset); |
| 3054 } |
2984 pieces.Add(&String::Handle(res_type.Name())); | 3055 pieces.Add(&String::Handle(res_type.Name())); |
2985 const Array& strings = Array::Handle(NewArray<const String>(pieces)); | 3056 const Array& strings = Array::Handle(NewArray<const String>(pieces)); |
2986 return String::NewSymbol(String::Handle(String::ConcatAll(strings))); | 3057 return String::NewSymbol(String::Handle(String::ConcatAll(strings))); |
2987 } | 3058 } |
2988 | 3059 |
2989 | 3060 |
| 3061 bool Function::HasInstantiatedSignature() const { |
| 3062 Type& type = Type::Handle(result_type()); |
| 3063 if (!type.IsInstantiated()) { |
| 3064 return false; |
| 3065 } |
| 3066 const intptr_t num_parameters = NumberOfParameters(); |
| 3067 for (intptr_t i = 0; i < num_parameters; i++) { |
| 3068 type = ParameterTypeAt(i); |
| 3069 if (!type.IsInstantiated()) { |
| 3070 return false; |
| 3071 } |
| 3072 } |
| 3073 return true; |
| 3074 } |
| 3075 |
| 3076 |
2990 const char* Function::ToCString() const { | 3077 const char* Function::ToCString() const { |
2991 const char* f0 = is_static() ? " static" : ""; | 3078 const char* f0 = is_static() ? " static" : ""; |
2992 const char* f1 = NULL; | 3079 const char* f1 = NULL; |
2993 const char* f2 = is_const() ? " const" : ""; | 3080 const char* f2 = is_const() ? " const" : ""; |
2994 switch (kind()) { | 3081 switch (kind()) { |
2995 case RawFunction::kFunction: | 3082 case RawFunction::kFunction: |
2996 case RawFunction::kClosureFunction: | 3083 case RawFunction::kClosureFunction: |
2997 case RawFunction::kGetterFunction: | 3084 case RawFunction::kGetterFunction: |
2998 case RawFunction::kSetterFunction: | 3085 case RawFunction::kSetterFunction: |
2999 f1 = ""; | 3086 f1 = ""; |
(...skipping 3358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6358 const String& str = String::Handle(pattern()); | 6445 const String& str = String::Handle(pattern()); |
6359 const char* format = "JSRegExp: pattern=%s flags=%s"; | 6446 const char* format = "JSRegExp: pattern=%s flags=%s"; |
6360 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 6447 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
6361 char* chars = reinterpret_cast<char*>( | 6448 char* chars = reinterpret_cast<char*>( |
6362 Isolate::Current()->current_zone()->Allocate(len + 1)); | 6449 Isolate::Current()->current_zone()->Allocate(len + 1)); |
6363 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 6450 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
6364 return chars; | 6451 return chars; |
6365 } | 6452 } |
6366 | 6453 |
6367 } // namespace dart | 6454 } // namespace dart |
OLD | NEW |