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 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
7 | 7 |
8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
9 #include "vm/dart.h" | 9 #include "vm/dart.h" |
10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 // The associated function may be a closure function (with code) or a | 384 // The associated function may be a closure function (with code) or a |
385 // signature function (without code) solely describing the result type and | 385 // signature function (without code) solely describing the result type and |
386 // parameter types of the signature. | 386 // parameter types of the signature. |
387 RawFunction* signature_function() const { | 387 RawFunction* signature_function() const { |
388 return raw_ptr()->signature_function_; | 388 return raw_ptr()->signature_function_; |
389 } | 389 } |
390 static intptr_t signature_function_offset() { | 390 static intptr_t signature_function_offset() { |
391 return OFFSET_OF(RawClass, signature_function_); | 391 return OFFSET_OF(RawClass, signature_function_); |
392 } | 392 } |
393 | 393 |
| 394 // Return the signature type of this signature class. |
| 395 // For example, if this class represents a signature of the form |
| 396 // '<T, R>(T, [b: B, c: C]) => R', then its signature type is a parameterized |
| 397 // type with this class as the type class and type parameters 'T' and 'R' |
| 398 // as its type argument vector. |
| 399 RawType* SignatureType() const; |
| 400 |
394 RawLibrary* library() const { return raw_ptr()->library_; } | 401 RawLibrary* library() const { return raw_ptr()->library_; } |
395 void set_library(const Library& value) const; | 402 void set_library(const Library& value) const; |
396 | 403 |
397 // The type parameters are specified as an array of Strings. | 404 // The type parameters are specified as an array of Strings. |
398 RawArray* type_parameters() const { return raw_ptr()->type_parameters_; } | 405 RawArray* type_parameters() const { return raw_ptr()->type_parameters_; } |
399 void set_type_parameters(const Array& value) const; | 406 void set_type_parameters(const Array& value) const; |
400 intptr_t NumTypeParameters() const; | 407 intptr_t NumTypeParameters() const; |
401 | 408 |
402 // Type parameters may optionally extend a Type (VarType if no extends). | 409 // Type parameters may optionally extend a Type (VarType if no extends). |
403 RawTypeArray* type_parameter_extends() const { | 410 RawTypeArray* type_parameter_extends() const { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 | 590 |
584 // Return a class object corresponding to the specified kind. If | 591 // Return a class object corresponding to the specified kind. If |
585 // a canonicalized version of it exists then that object is returned | 592 // a canonicalized version of it exists then that object is returned |
586 // otherwise a new object is allocated and returned. | 593 // otherwise a new object is allocated and returned. |
587 static RawClass* GetClass(ObjectKind kind); | 594 static RawClass* GetClass(ObjectKind kind); |
588 | 595 |
589 private: | 596 private: |
590 void set_name(const String& value) const; | 597 void set_name(const String& value) const; |
591 void set_script(const Script& value) const; | 598 void set_script(const Script& value) const; |
592 void set_signature_function(const Function& value) const; | 599 void set_signature_function(const Function& value) const; |
| 600 void set_signature_type(const Type& value) const; |
593 void set_class_state(int8_t state) const; | 601 void set_class_state(int8_t state) const; |
594 | 602 |
595 void set_constants(const Array& value) const; | 603 void set_constants(const Array& value) const; |
596 RawArray* constants() const; | 604 RawArray* constants() const; |
597 | 605 |
598 void set_num_constants(intptr_t value) const; | 606 void set_num_constants(intptr_t value) const; |
599 intptr_t num_constants() const; | 607 intptr_t num_constants() const; |
600 | 608 |
601 void CalculateFieldOffsets() const; | 609 void CalculateFieldOffsets() const; |
602 | 610 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 // Type is an abstract superclass. | 655 // Type is an abstract superclass. |
648 // Subclasses of Type are ParameterizedType, TypeParameter, and | 656 // Subclasses of Type are ParameterizedType, TypeParameter, and |
649 // InstantiatedType. | 657 // InstantiatedType. |
650 // | 658 // |
651 // Caution: 'RawType*' denotes a 'raw' pointer to a VM object of class Type, | 659 // Caution: 'RawType*' denotes a 'raw' pointer to a VM object of class Type, |
652 // as opposed to 'Type' denoting a 'handle' to the same object. 'RawType' does | 660 // as opposed to 'Type' denoting a 'handle' to the same object. 'RawType' does |
653 // not relate to a 'raw type', as opposed to a 'cooked type' or 'rare type'. | 661 // not relate to a 'raw type', as opposed to a 'cooked type' or 'rare type'. |
654 class Type : public Object { | 662 class Type : public Object { |
655 public: | 663 public: |
656 virtual bool IsFinalized() const; | 664 virtual bool IsFinalized() const; |
| 665 virtual bool IsBeingFinalized() const; |
657 virtual bool IsResolved() const; | 666 virtual bool IsResolved() const; |
658 virtual bool HasResolvedTypeClass() const; | 667 virtual bool HasResolvedTypeClass() const; |
659 virtual RawClass* type_class() const; | 668 virtual RawClass* type_class() const; |
660 virtual RawUnresolvedClass* unresolved_class() const; | 669 virtual RawUnresolvedClass* unresolved_class() const; |
661 virtual RawTypeArguments* arguments() const; | 670 virtual RawTypeArguments* arguments() const; |
662 virtual bool IsInstantiated() const; | 671 virtual bool IsInstantiated() const; |
663 | 672 |
664 // Instantiate this type using the given type argument vector starting at the | 673 // Instantiate this type using the given type argument vector starting at the |
665 // given offset. | 674 // given offset. |
666 // Return a new type, or return 'this' if it is already instantiated. | 675 // Return a new type, or return 'this' if it is already instantiated. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 | 800 |
792 // A ParameterizedType consists of a class, possibly parameterized with type | 801 // A ParameterizedType consists of a class, possibly parameterized with type |
793 // arguments. Example: C<T1, T2>. | 802 // arguments. Example: C<T1, T2>. |
794 // An unresolved class is a String specifying the class name. | 803 // An unresolved class is a String specifying the class name. |
795 class ParameterizedType : public Type { | 804 class ParameterizedType : public Type { |
796 public: | 805 public: |
797 virtual bool IsFinalized() const { | 806 virtual bool IsFinalized() const { |
798 return raw_ptr()->type_state_ == RawParameterizedType::kFinalized; | 807 return raw_ptr()->type_state_ == RawParameterizedType::kFinalized; |
799 } | 808 } |
800 void set_is_finalized() const; | 809 void set_is_finalized() const; |
801 bool is_being_finalized() const { | 810 virtual bool IsBeingFinalized() const { |
802 return raw_ptr()->type_state_ == RawParameterizedType::kBeingFinalized; | 811 return raw_ptr()->type_state_ == RawParameterizedType::kBeingFinalized; |
803 } | 812 } |
804 void set_is_being_finalized() const; | 813 void set_is_being_finalized() const; |
805 virtual bool IsResolved() const; // Class and all arguments classes resolved. | 814 virtual bool IsResolved() const; // Class and all arguments classes resolved. |
806 virtual bool HasResolvedTypeClass() const; // Own type class resolved. | 815 virtual bool HasResolvedTypeClass() const; // Own type class resolved. |
807 virtual RawClass* type_class() const; | 816 virtual RawClass* type_class() const; |
808 void set_type_class(const Object& value) const; | 817 void set_type_class(const Object& value) const; |
809 virtual RawUnresolvedClass* unresolved_class() const; | 818 virtual RawUnresolvedClass* unresolved_class() const; |
810 virtual RawTypeArguments* arguments() const; | 819 virtual RawTypeArguments* arguments() const; |
811 void set_arguments(const TypeArguments& value) const; | 820 void set_arguments(const TypeArguments& value) const; |
(...skipping 20 matching lines...) Expand all Loading... |
832 | 841 |
833 | 842 |
834 // A TypeParameter, in the context of a parameterized class, references a type | 843 // A TypeParameter, in the context of a parameterized class, references a type |
835 // parameter of a class by its index (and by its name for debugging purposes). | 844 // parameter of a class by its index (and by its name for debugging purposes). |
836 // For example, the type parameter 'V' is specified as index 1 in the context of | 845 // For example, the type parameter 'V' is specified as index 1 in the context of |
837 // the class HashMap<K, V>. At compile time, the TypeParameter is not | 846 // the class HashMap<K, V>. At compile time, the TypeParameter is not |
838 // instantiated yet, i.e. it is only a place holder. | 847 // instantiated yet, i.e. it is only a place holder. |
839 class TypeParameter : public Type { | 848 class TypeParameter : public Type { |
840 public: | 849 public: |
841 virtual bool IsFinalized() const { return true; } | 850 virtual bool IsFinalized() const { return true; } |
| 851 virtual bool IsBeingFinalized() const { return false; } |
842 virtual bool IsResolved() const { return true; } | 852 virtual bool IsResolved() const { return true; } |
843 virtual bool HasResolvedTypeClass() const { return false; } | 853 virtual bool HasResolvedTypeClass() const { return false; } |
844 virtual RawString* Name() const { return raw_ptr()->name_; } | 854 virtual RawString* Name() const { return raw_ptr()->name_; } |
845 virtual intptr_t Index() const { return raw_ptr()->index_; } | 855 virtual intptr_t Index() const { return raw_ptr()->index_; } |
846 virtual bool IsInstantiated() const { return false; } | 856 virtual bool IsInstantiated() const { return false; } |
847 virtual RawType* InstantiateFrom( | 857 virtual RawType* InstantiateFrom( |
848 const TypeArguments& instantiator_type_arguments, | 858 const TypeArguments& instantiator_type_arguments, |
849 intptr_t offset) const; | 859 intptr_t offset) const; |
850 | 860 |
851 static intptr_t InstanceSize() { | 861 static intptr_t InstanceSize() { |
(...skipping 17 matching lines...) Expand all Loading... |
869 // An instance of InstantiatedType consists of an uninstantiated Type object | 879 // An instance of InstantiatedType consists of an uninstantiated Type object |
870 // and of a TypeArguments object. The type is uninstantiated, because it | 880 // and of a TypeArguments object. The type is uninstantiated, because it |
871 // refers to at least one TypeParameter object, i.e. to a type that is not known | 881 // refers to at least one TypeParameter object, i.e. to a type that is not known |
872 // at compile time. | 882 // at compile time. |
873 // The type argument vector is the instantiator, because each type parameter | 883 // The type argument vector is the instantiator, because each type parameter |
874 // with index i in the uninstantiated type can be substituted (or | 884 // with index i in the uninstantiated type can be substituted (or |
875 // "instantiated") with the type at index i in the type argument vector. | 885 // "instantiated") with the type at index i in the type argument vector. |
876 class InstantiatedType : public Type { | 886 class InstantiatedType : public Type { |
877 public: | 887 public: |
878 virtual bool IsFinalized() const { return true; } | 888 virtual bool IsFinalized() const { return true; } |
| 889 virtual bool IsBeingFinalized() const { return false; } |
879 virtual bool IsResolved() const { return true; } | 890 virtual bool IsResolved() const { return true; } |
880 virtual bool HasResolvedTypeClass() const { return true; } | 891 virtual bool HasResolvedTypeClass() const { return true; } |
881 virtual RawClass* type_class() const; | 892 virtual RawClass* type_class() const; |
882 virtual RawTypeArguments* arguments() const; | 893 virtual RawTypeArguments* arguments() const; |
883 virtual bool IsInstantiated() const { return true; } | 894 virtual bool IsInstantiated() const { return true; } |
884 | 895 |
885 RawType* uninstantiated_type() const { | 896 RawType* uninstantiated_type() const { |
886 return raw_ptr()->uninstantiated_type_; | 897 return raw_ptr()->uninstantiated_type_; |
887 } | 898 } |
888 RawTypeArguments* instantiator_type_arguments() const { | 899 RawTypeArguments* instantiator_type_arguments() const { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 static RawInstantiatedTypeArguments* New(); | 1045 static RawInstantiatedTypeArguments* New(); |
1035 | 1046 |
1036 HEAP_OBJECT_IMPLEMENTATION(InstantiatedTypeArguments, TypeArguments); | 1047 HEAP_OBJECT_IMPLEMENTATION(InstantiatedTypeArguments, TypeArguments); |
1037 friend class Class; | 1048 friend class Class; |
1038 }; | 1049 }; |
1039 | 1050 |
1040 | 1051 |
1041 class Function : public Object { | 1052 class Function : public Object { |
1042 public: | 1053 public: |
1043 RawString* name() const { return raw_ptr()->name_; } | 1054 RawString* name() const { return raw_ptr()->name_; } |
1044 RawString* Signature() const; | 1055 |
| 1056 // Build a string of the form '<T, R>(T, [b: B, c: C]) => R' representing the |
| 1057 // signature of the given function. |
| 1058 RawString* Signature() const { |
| 1059 return BuildSignature(false, TypeArguments::Handle(), 0); |
| 1060 } |
| 1061 |
| 1062 // Build a string of the form '(A, [b: B, c: C]) => D' representing the |
| 1063 // signature of the given function, where all generic types (e.g. '<T, R>' in |
| 1064 // '<T, R>(T, [b: B, c: C]) => R') are instantiated using the given |
| 1065 // instantiator type argument vector (e.g. '<A, D>'). |
| 1066 RawString* InstantiatedSignatureFrom(const TypeArguments& instantiator, |
| 1067 intptr_t offset) const { |
| 1068 return BuildSignature(true, instantiator, offset); |
| 1069 } |
| 1070 |
| 1071 // Returns true if the signature of this function is instantiated, i.e. if it |
| 1072 // does not involve generic parameter types or generic result type. |
| 1073 bool HasInstantiatedSignature() const; |
1045 | 1074 |
1046 RawClass* owner() const { return raw_ptr()->owner_; } | 1075 RawClass* owner() const { return raw_ptr()->owner_; } |
1047 void set_owner(const Class& value) const; | 1076 void set_owner(const Class& value) const; |
1048 | 1077 |
1049 RawType* result_type() const { return raw_ptr()->result_type_; } | 1078 RawType* result_type() const { return raw_ptr()->result_type_; } |
1050 void set_result_type(const Type& value) const; | 1079 void set_result_type(const Type& value) const; |
1051 | 1080 |
1052 RawType* ParameterTypeAt(intptr_t index) const; | 1081 RawType* ParameterTypeAt(intptr_t index) const; |
1053 void SetParameterTypeAt(intptr_t index, const Type& value) const; | 1082 void SetParameterTypeAt(intptr_t index, const Type& value) const; |
1054 void set_parameter_types(const Array& value) const; | 1083 void set_parameter_types(const Array& value) const; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 private: | 1254 private: |
1226 void set_name(const String& value) const; | 1255 void set_name(const String& value) const; |
1227 void set_kind(RawFunction::Kind value) const; | 1256 void set_kind(RawFunction::Kind value) const; |
1228 void set_is_static(bool is_static) const; | 1257 void set_is_static(bool is_static) const; |
1229 void set_is_const(bool is_const) const; | 1258 void set_is_const(bool is_const) const; |
1230 void set_parent_function(const Function& value) const; | 1259 void set_parent_function(const Function& value) const; |
1231 void set_token_index(intptr_t value) const; | 1260 void set_token_index(intptr_t value) const; |
1232 void set_implicit_closure_function(const Function& value) const; | 1261 void set_implicit_closure_function(const Function& value) const; |
1233 static RawFunction* New(); | 1262 static RawFunction* New(); |
1234 | 1263 |
| 1264 RawString* BuildSignature(bool instantiate, |
| 1265 const TypeArguments& instantiator, |
| 1266 intptr_t offset) const; |
| 1267 |
1235 // Checks the subtype or assignability relationship between the type of this | 1268 // Checks the subtype or assignability relationship between the type of this |
1236 // function and the type of the other function. | 1269 // function and the type of the other function. |
1237 bool TestType(TypeTestKind test, const Function& other) const; | 1270 bool TestType(TypeTestKind test, const Function& other) const; |
1238 | 1271 |
1239 HEAP_OBJECT_IMPLEMENTATION(Function, Object); | 1272 HEAP_OBJECT_IMPLEMENTATION(Function, Object); |
1240 friend class Class; | 1273 friend class Class; |
1241 }; | 1274 }; |
1242 | 1275 |
1243 | 1276 |
1244 class Field : public Object { | 1277 class Field : public Object { |
(...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2843 } | 2876 } |
2844 | 2877 |
2845 | 2878 |
2846 void Context::SetAt(intptr_t index, const Instance& value) const { | 2879 void Context::SetAt(intptr_t index, const Instance& value) const { |
2847 StorePointer(InstanceAddr(index), value.raw()); | 2880 StorePointer(InstanceAddr(index), value.raw()); |
2848 } | 2881 } |
2849 | 2882 |
2850 } // namespace dart | 2883 } // namespace dart |
2851 | 2884 |
2852 #endif // VM_OBJECT_H_ | 2885 #endif // VM_OBJECT_H_ |
OLD | NEW |