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