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 #ifndef RUNTIME_VM_OBJECT_H_ | 5 #ifndef RUNTIME_VM_OBJECT_H_ |
6 #define RUNTIME_VM_OBJECT_H_ | 6 #define RUNTIME_VM_OBJECT_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
(...skipping 2182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2193 // For example, if this function has a signature of the form | 2193 // For example, if this function has a signature of the form |
2194 // '(T, [B, C]) => R', where 'T' and 'R' are type parameters of the | 2194 // '(T, [B, C]) => R', where 'T' and 'R' are type parameters of the |
2195 // owner class of this function, then its signature type is a parameterized | 2195 // owner class of this function, then its signature type is a parameterized |
2196 // function type with uninstantiated type arguments 'T' and 'R' as elements of | 2196 // function type with uninstantiated type arguments 'T' and 'R' as elements of |
2197 // its type argument vector. | 2197 // its type argument vector. |
2198 RawType* SignatureType() const; | 2198 RawType* SignatureType() const; |
2199 | 2199 |
2200 // Update the signature type (with a canonical version). | 2200 // Update the signature type (with a canonical version). |
2201 void SetSignatureType(const Type& value) const; | 2201 void SetSignatureType(const Type& value) const; |
2202 | 2202 |
2203 // Build a string of the form 'C<T, R>(T, {B b, C c}) => R' representing the | 2203 // Return a new function with instantiated result and parameter types. |
| 2204 RawFunction* InstantiateSignatureFrom( |
| 2205 const TypeArguments& instantiator_type_arguments, |
| 2206 Heap::Space space) const; |
| 2207 |
| 2208 // Build a string of the form '(T, {B b, C c}) => R' representing the |
2204 // internal signature of the given function. In this example, T and R are | 2209 // internal signature of the given function. In this example, T and R are |
2205 // type parameters of class C, the owner of the function. | 2210 // type parameters of class C, the owner of the function. |
2206 RawString* Signature() const { | 2211 RawString* Signature() const { return BuildSignature(kInternalName); } |
2207 const bool instantiate = false; | |
2208 return BuildSignature(instantiate, kInternalName, | |
2209 Object::null_type_arguments()); | |
2210 } | |
2211 | 2212 |
2212 // Build a string of the form '(T, {B b, C c}) => R' representing the | 2213 // Build a string of the form '(T, {B b, C c}) => R' representing the |
2213 // user visible signature of the given function. In this example, T and R are | 2214 // user visible signature of the given function. In this example, T and R are |
2214 // type parameters of class C, the owner of the function, also called the | 2215 // type parameters of class C, the owner of the function. |
2215 // scope class of the function type. | 2216 // Implicit parameters are hidden. |
2216 // Implicit parameters are hidden, as well as the prefix denoting the | |
2217 // scope class and its type parameters. | |
2218 RawString* UserVisibleSignature() const { | 2217 RawString* UserVisibleSignature() const { |
2219 const bool instantiate = false; | 2218 return BuildSignature(kUserVisibleName); |
2220 return BuildSignature(instantiate, kUserVisibleName, | |
2221 Object::null_type_arguments()); | |
2222 } | |
2223 | |
2224 // Build a string of the form '(A, {B b, C c}) => D' representing the | |
2225 // signature of the given function, where all generic types (e.g. '<T, R>' in | |
2226 // 'C<T, R>(T, {B b, C c}) => R') are instantiated using the given | |
2227 // instantiator type argument vector of a C instance (e.g. '<A, D>'). | |
2228 RawString* InstantiatedSignatureFrom(const TypeArguments& instantiator, | |
2229 NameVisibility name_visibility) const { | |
2230 const bool instantiate = true; | |
2231 return BuildSignature(instantiate, name_visibility, instantiator); | |
2232 } | 2219 } |
2233 | 2220 |
2234 // Returns true if the signature of this function is instantiated, i.e. if it | 2221 // Returns true if the signature of this function is instantiated, i.e. if it |
2235 // does not involve generic parameter types or generic result type. | 2222 // does not involve generic parameter types or generic result type. |
2236 bool HasInstantiatedSignature() const; | 2223 bool HasInstantiatedSignature(Genericity genericity = kAny, |
| 2224 TrailPtr trail = NULL) const; |
2237 | 2225 |
2238 // Build a string of the form 'T, {B b, C c}' representing the user | 2226 // Build a string of the form 'T, {B b, C c}' representing the user |
2239 // visible formal parameters of the function. | 2227 // visible formal parameters of the function. |
2240 RawString* UserVisibleFormalParameters() const; | 2228 RawString* UserVisibleFormalParameters() const; |
2241 | 2229 |
2242 // Reloading support: | 2230 // Reloading support: |
2243 void Reparent(const Class& new_cls) const; | 2231 void Reparent(const Class& new_cls) const; |
2244 void ZeroEdgeCounters() const; | 2232 void ZeroEdgeCounters() const; |
2245 | 2233 |
2246 RawClass* Owner() const; | 2234 RawClass* Owner() const; |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2659 const char* ToQualifiedCString() const; | 2647 const char* ToQualifiedCString() const; |
2660 | 2648 |
2661 // Returns true if this function has parameters that are compatible with the | 2649 // Returns true if this function has parameters that are compatible with the |
2662 // parameters of the other function in order for this function to override the | 2650 // parameters of the other function in order for this function to override the |
2663 // other function. | 2651 // other function. |
2664 bool HasCompatibleParametersWith(const Function& other, | 2652 bool HasCompatibleParametersWith(const Function& other, |
2665 Error* bound_error) const; | 2653 Error* bound_error) const; |
2666 | 2654 |
2667 // Returns true if the type of this function is a subtype of the type of | 2655 // Returns true if the type of this function is a subtype of the type of |
2668 // the other function. | 2656 // the other function. |
2669 bool IsSubtypeOf(const TypeArguments& type_arguments, | 2657 bool IsSubtypeOf(const Function& other, |
2670 const Function& other, | |
2671 const TypeArguments& other_type_arguments, | |
2672 Error* bound_error, | 2658 Error* bound_error, |
2673 Heap::Space space) const { | 2659 Heap::Space space) const { |
2674 return TypeTest(kIsSubtypeOf, type_arguments, other, other_type_arguments, | 2660 return TypeTest(kIsSubtypeOf, other, bound_error, space); |
2675 bound_error, space); | |
2676 } | 2661 } |
2677 | 2662 |
2678 // Returns true if the type of this function is more specific than the type of | 2663 // Returns true if the type of this function is more specific than the type of |
2679 // the other function. | 2664 // the other function. |
2680 bool IsMoreSpecificThan(const TypeArguments& type_arguments, | 2665 bool IsMoreSpecificThan(const Function& other, |
2681 const Function& other, | |
2682 const TypeArguments& other_type_arguments, | |
2683 Error* bound_error, | 2666 Error* bound_error, |
2684 Heap::Space space) const { | 2667 Heap::Space space) const { |
2685 return TypeTest(kIsMoreSpecificThan, type_arguments, other, | 2668 return TypeTest(kIsMoreSpecificThan, other, bound_error, space); |
2686 other_type_arguments, bound_error, space); | |
2687 } | 2669 } |
2688 | 2670 |
2689 // Check the subtype or 'more specific' relationship. | 2671 // Check the subtype or 'more specific' relationship. |
2690 bool TypeTest(TypeTestKind test_kind, | 2672 bool TypeTest(TypeTestKind test_kind, |
2691 const TypeArguments& type_arguments, | |
2692 const Function& other, | 2673 const Function& other, |
2693 const TypeArguments& other_type_arguments, | |
2694 Error* bound_error, | 2674 Error* bound_error, |
2695 Heap::Space space) const; | 2675 Heap::Space space) const; |
2696 | 2676 |
2697 bool IsDispatcherOrImplicitAccessor() const { | 2677 bool IsDispatcherOrImplicitAccessor() const { |
2698 switch (kind()) { | 2678 switch (kind()) { |
2699 case RawFunction::kImplicitGetter: | 2679 case RawFunction::kImplicitGetter: |
2700 case RawFunction::kImplicitSetter: | 2680 case RawFunction::kImplicitSetter: |
2701 case RawFunction::kNoSuchMethodDispatcher: | 2681 case RawFunction::kNoSuchMethodDispatcher: |
2702 case RawFunction::kInvokeFieldDispatcher: | 2682 case RawFunction::kInvokeFieldDispatcher: |
2703 return true; | 2683 return true; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2826 const Object& owner, | 2806 const Object& owner, |
2827 TokenPosition token_pos); | 2807 TokenPosition token_pos); |
2828 | 2808 |
2829 // Allocates a new Function object representing a closure function. | 2809 // Allocates a new Function object representing a closure function. |
2830 static RawFunction* NewClosureFunction(const String& name, | 2810 static RawFunction* NewClosureFunction(const String& name, |
2831 const Function& parent, | 2811 const Function& parent, |
2832 TokenPosition token_pos); | 2812 TokenPosition token_pos); |
2833 | 2813 |
2834 // Allocates a new Function object representing a signature function. | 2814 // Allocates a new Function object representing a signature function. |
2835 // The owner is the scope class of the function type. | 2815 // The owner is the scope class of the function type. |
2836 static RawFunction* NewSignatureFunction(const Class& owner, | 2816 static RawFunction* NewSignatureFunction(const Object& owner, |
2837 TokenPosition token_pos); | 2817 TokenPosition token_pos); |
2838 | 2818 |
2839 static RawFunction* NewEvalFunction(const Class& owner, | 2819 static RawFunction* NewEvalFunction(const Class& owner, |
2840 const Script& script, | 2820 const Script& script, |
2841 bool is_static); | 2821 bool is_static); |
2842 | 2822 |
2843 RawFunction* CreateMethodExtractor(const String& getter_name) const; | 2823 RawFunction* CreateMethodExtractor(const String& getter_name) const; |
2844 RawFunction* GetMethodExtractor(const String& getter_name) const; | 2824 RawFunction* GetMethodExtractor(const String& getter_name) const; |
2845 | 2825 |
2846 // Allocate new function object, clone values from this function. The | 2826 // Allocate new function object, clone values from this function. The |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2999 void set_kind_tag(uint32_t value) const; | 2979 void set_kind_tag(uint32_t value) const; |
3000 void set_data(const Object& value) const; | 2980 void set_data(const Object& value) const; |
3001 | 2981 |
3002 static RawFunction* New(); | 2982 static RawFunction* New(); |
3003 | 2983 |
3004 RawString* QualifiedName(NameVisibility name_visibility) const; | 2984 RawString* QualifiedName(NameVisibility name_visibility) const; |
3005 | 2985 |
3006 void BuildSignatureParameters( | 2986 void BuildSignatureParameters( |
3007 Thread* thread, | 2987 Thread* thread, |
3008 Zone* zone, | 2988 Zone* zone, |
3009 bool instantiate, | |
3010 NameVisibility name_visibility, | 2989 NameVisibility name_visibility, |
3011 const TypeArguments& instantiator, | |
3012 GrowableHandlePtrArray<const String>* pieces) const; | 2990 GrowableHandlePtrArray<const String>* pieces) const; |
3013 RawString* BuildSignature(bool instantiate, | 2991 RawString* BuildSignature(NameVisibility name_visibility) const; |
3014 NameVisibility name_visibility, | |
3015 const TypeArguments& instantiator) const; | |
3016 | 2992 |
3017 // Checks the type of the formal parameter at the given position for | 2993 // Checks the type of the formal parameter at the given position for |
3018 // subtyping or 'more specific' relationship between the type of this function | 2994 // subtyping or 'more specific' relationship between the type of this function |
3019 // and the type of the other function. | 2995 // and the type of the other function. |
3020 bool TestParameterType(TypeTestKind test_kind, | 2996 bool TestParameterType(TypeTestKind test_kind, |
3021 intptr_t parameter_position, | 2997 intptr_t parameter_position, |
3022 intptr_t other_parameter_position, | 2998 intptr_t other_parameter_position, |
3023 const TypeArguments& type_arguments, | |
3024 const Function& other, | 2999 const Function& other, |
3025 const TypeArguments& other_type_arguments, | |
3026 Error* bound_error, | 3000 Error* bound_error, |
3027 Heap::Space space) const; | 3001 Heap::Space space) const; |
3028 | 3002 |
3029 FINAL_HEAP_OBJECT_IMPLEMENTATION(Function, Object); | 3003 FINAL_HEAP_OBJECT_IMPLEMENTATION(Function, Object); |
3030 friend class Class; | 3004 friend class Class; |
3031 friend class SnapshotWriter; | 3005 friend class SnapshotWriter; |
3032 friend class Parser; // For set_eval_script. | 3006 friend class Parser; // For set_eval_script. |
3033 // RawFunction::VisitFunctionPointers accesses the private constructor of | 3007 // RawFunction::VisitFunctionPointers accesses the private constructor of |
3034 // Function. | 3008 // Function. |
3035 friend class RawFunction; | 3009 friend class RawFunction; |
(...skipping 2885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5921 void set_type_class(const Class& value) const; | 5895 void set_type_class(const Class& value) const; |
5922 void set_unresolved_class(const Object& value) const; | 5896 void set_unresolved_class(const Object& value) const; |
5923 virtual RawUnresolvedClass* unresolved_class() const; | 5897 virtual RawUnresolvedClass* unresolved_class() const; |
5924 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; } | 5898 virtual RawTypeArguments* arguments() const { return raw_ptr()->arguments_; } |
5925 virtual void set_arguments(const TypeArguments& value) const; | 5899 virtual void set_arguments(const TypeArguments& value) const; |
5926 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; } | 5900 virtual TokenPosition token_pos() const { return raw_ptr()->token_pos_; } |
5927 virtual bool IsInstantiated(Genericity genericity = kAny, | 5901 virtual bool IsInstantiated(Genericity genericity = kAny, |
5928 TrailPtr trail = NULL) const; | 5902 TrailPtr trail = NULL) const; |
5929 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; | 5903 virtual bool IsEquivalent(const Instance& other, TrailPtr trail = NULL) const; |
5930 virtual bool IsRecursive() const; | 5904 virtual bool IsRecursive() const; |
5931 // If signature is not null, this type represents a function type. | 5905 // If signature is not null, this type represents a function type. Note that |
| 5906 // the signature fully represents the type and type arguments can be ignored. |
| 5907 // However, in case of a generic typedef, they document how the typedef class |
| 5908 // was parameterized to obtain the actual signature. |
5932 RawFunction* signature() const; | 5909 RawFunction* signature() const; |
5933 void set_signature(const Function& value) const; | 5910 void set_signature(const Function& value) const; |
5934 virtual bool IsFunctionType() const { | 5911 virtual bool IsFunctionType() const { |
5935 return signature() != Function::null(); | 5912 return signature() != Function::null(); |
5936 } | 5913 } |
5937 virtual RawAbstractType* InstantiateFrom( | 5914 virtual RawAbstractType* InstantiateFrom( |
5938 const TypeArguments& instantiator_type_arguments, | 5915 const TypeArguments& instantiator_type_arguments, |
5939 Error* bound_error, | 5916 Error* bound_error, |
5940 TrailPtr instantiation_trail, | 5917 TrailPtr instantiation_trail, |
5941 TrailPtr bound_trail, | 5918 TrailPtr bound_trail, |
(...skipping 3025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8967 | 8944 |
8968 inline void TypeArguments::SetHash(intptr_t value) const { | 8945 inline void TypeArguments::SetHash(intptr_t value) const { |
8969 // This is only safe because we create a new Smi, which does not cause | 8946 // This is only safe because we create a new Smi, which does not cause |
8970 // heap allocation. | 8947 // heap allocation. |
8971 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); | 8948 StoreSmi(&raw_ptr()->hash_, Smi::New(value)); |
8972 } | 8949 } |
8973 | 8950 |
8974 } // namespace dart | 8951 } // namespace dart |
8975 | 8952 |
8976 #endif // RUNTIME_VM_OBJECT_H_ | 8953 #endif // RUNTIME_VM_OBJECT_H_ |
OLD | NEW |