| 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 VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
| 6 #define VM_OBJECT_H_ | 6 #define 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 enum { | 140 enum { |
| 141 kNullObject = 0, | 141 kNullObject = 0, |
| 142 kSentinelObject, | 142 kSentinelObject, |
| 143 kClassClass, | 143 kClassClass, |
| 144 kNullClass, | 144 kNullClass, |
| 145 kDynamicClass, | 145 kDynamicClass, |
| 146 kVoidClass, | 146 kVoidClass, |
| 147 kUnresolvedClassClass, | 147 kUnresolvedClassClass, |
| 148 kTypeClass, | 148 kTypeClass, |
| 149 kTypeParameterClass, | 149 kTypeParameterClass, |
| 150 kInstantiatedTypeClass, | |
| 151 kAbstractTypeArgumentsClass, | |
| 152 kTypeArgumentsClass, | 150 kTypeArgumentsClass, |
| 153 kInstantiatedTypeArgumentsClass, | 151 kInstantiatedTypeArgumentsClass, |
| 154 kFunctionClass, | 152 kFunctionClass, |
| 155 kFieldClass, | 153 kFieldClass, |
| 156 kLiteralTokenClass, | 154 kLiteralTokenClass, |
| 157 kTokenStreamClass, | 155 kTokenStreamClass, |
| 158 kScriptClass, | 156 kScriptClass, |
| 159 kLibraryClass, | 157 kLibraryClass, |
| 160 kLibraryPrefixClass, | 158 kLibraryPrefixClass, |
| 161 kCodeClass, | 159 kCodeClass, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 274 |
| 277 static RawClass* class_class() { return class_class_; } | 275 static RawClass* class_class() { return class_class_; } |
| 278 static RawClass* null_class() { return null_class_; } | 276 static RawClass* null_class() { return null_class_; } |
| 279 static RawClass* dynamic_class() { return dynamic_class_; } | 277 static RawClass* dynamic_class() { return dynamic_class_; } |
| 280 static RawClass* void_class() { return void_class_; } | 278 static RawClass* void_class() { return void_class_; } |
| 281 static RawClass* unresolved_class_class() { return unresolved_class_class_; } | 279 static RawClass* unresolved_class_class() { return unresolved_class_class_; } |
| 282 static RawClass* type_class() { | 280 static RawClass* type_class() { |
| 283 return type_class_; | 281 return type_class_; |
| 284 } | 282 } |
| 285 static RawClass* type_parameter_class() { return type_parameter_class_; } | 283 static RawClass* type_parameter_class() { return type_parameter_class_; } |
| 286 static RawClass* instantiated_type_class() { | |
| 287 return instantiated_type_class_; | |
| 288 } | |
| 289 static RawClass* abstract_type_arguments_class() { | |
| 290 return abstract_type_arguments_class_; | |
| 291 } | |
| 292 static RawClass* type_arguments_class() { return type_arguments_class_; } | 284 static RawClass* type_arguments_class() { return type_arguments_class_; } |
| 293 static RawClass* instantiated_type_arguments_class() { | 285 static RawClass* instantiated_type_arguments_class() { |
| 294 return instantiated_type_arguments_class_; | 286 return instantiated_type_arguments_class_; |
| 295 } | 287 } |
| 296 static RawClass* function_class() { return function_class_; } | 288 static RawClass* function_class() { return function_class_; } |
| 297 static RawClass* field_class() { return field_class_; } | 289 static RawClass* field_class() { return field_class_; } |
| 298 static RawClass* literal_token_class() { return literal_token_class_; } | 290 static RawClass* literal_token_class() { return literal_token_class_; } |
| 299 static RawClass* token_stream_class() { return token_stream_class_; } | 291 static RawClass* token_stream_class() { return token_stream_class_; } |
| 300 static RawClass* script_class() { return script_class_; } | 292 static RawClass* script_class() { return script_class_; } |
| 301 static RawClass* library_class() { return library_class_; } | 293 static RawClass* library_class() { return library_class_; } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 static RawInstance* sentinel_; | 387 static RawInstance* sentinel_; |
| 396 static RawInstance* transition_sentinel_; | 388 static RawInstance* transition_sentinel_; |
| 397 | 389 |
| 398 static RawClass* class_class_; // Class of the Class vm object. | 390 static RawClass* class_class_; // Class of the Class vm object. |
| 399 static RawClass* null_class_; // Class of the null object. | 391 static RawClass* null_class_; // Class of the null object. |
| 400 static RawClass* dynamic_class_; // Class of the 'Dynamic' type. | 392 static RawClass* dynamic_class_; // Class of the 'Dynamic' type. |
| 401 static RawClass* void_class_; // Class of the 'void' type. | 393 static RawClass* void_class_; // Class of the 'void' type. |
| 402 static RawClass* unresolved_class_class_; // Class of UnresolvedClass. | 394 static RawClass* unresolved_class_class_; // Class of UnresolvedClass. |
| 403 static RawClass* type_class_; // Class of Type. | 395 static RawClass* type_class_; // Class of Type. |
| 404 static RawClass* type_parameter_class_; // Class of TypeParameter vm object. | 396 static RawClass* type_parameter_class_; // Class of TypeParameter vm object. |
| 405 static RawClass* instantiated_type_class_; // Class of InstantiatedType. | |
| 406 // Class of AbstractTypeArguments vm object. | |
| 407 static RawClass* abstract_type_arguments_class_; | |
| 408 // Class of the TypeArguments vm object. | 397 // Class of the TypeArguments vm object. |
| 409 static RawClass* type_arguments_class_; | 398 static RawClass* type_arguments_class_; |
| 410 static RawClass* instantiated_type_arguments_class_; // Class of Inst..ments. | 399 static RawClass* instantiated_type_arguments_class_; // Class of Inst..ments. |
| 411 static RawClass* function_class_; // Class of the Function vm object. | 400 static RawClass* function_class_; // Class of the Function vm object. |
| 412 static RawClass* field_class_; // Class of the Field vm object. | 401 static RawClass* field_class_; // Class of the Field vm object. |
| 413 static RawClass* literal_token_class_; // Class of LiteralToken vm object. | 402 static RawClass* literal_token_class_; // Class of LiteralToken vm object. |
| 414 static RawClass* token_stream_class_; // Class of the TokenStream vm object. | 403 static RawClass* token_stream_class_; // Class of the TokenStream vm object. |
| 415 static RawClass* script_class_; // Class of the Script vm object. | 404 static RawClass* script_class_; // Class of the Script vm object. |
| 416 static RawClass* library_class_; // Class of the Library vm object. | 405 static RawClass* library_class_; // Class of the Library vm object. |
| 417 static RawClass* library_prefix_class_; // Class of Library prefix vm object. | 406 static RawClass* library_prefix_class_; // Class of Library prefix vm object. |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 void set_token_index(intptr_t token_index) const; | 773 void set_token_index(intptr_t token_index) const; |
| 785 | 774 |
| 786 static RawUnresolvedClass* New(); | 775 static RawUnresolvedClass* New(); |
| 787 | 776 |
| 788 HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); | 777 HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); |
| 789 friend class Class; | 778 friend class Class; |
| 790 }; | 779 }; |
| 791 | 780 |
| 792 | 781 |
| 793 // AbstractType is an abstract superclass. | 782 // AbstractType is an abstract superclass. |
| 794 // Subclasses of AbstractType are Type, TypeParameter, and | 783 // Subclasses of AbstractType are Type and TypeParameter. |
| 795 // InstantiatedType. | |
| 796 // | |
| 797 // Caution: 'RawAbstractType*' denotes a 'raw' pointer to a VM object of class | |
| 798 // AbstractType, as opposed to 'AbstractType' denoting a 'handle' to the same | |
| 799 // object. 'RawAbstractType' does not relate to a 'raw type', as opposed to a | |
| 800 // 'cooked type' or 'rare type'. | |
| 801 class AbstractType : public Object { | 784 class AbstractType : public Object { |
| 802 public: | 785 public: |
| 803 virtual bool IsFinalized() const; | 786 virtual bool IsFinalized() const; |
| 804 virtual bool IsBeingFinalized() const; | 787 virtual bool IsBeingFinalized() const; |
| 805 virtual bool IsMalformed() const; | 788 virtual bool IsMalformed() const; |
| 806 virtual RawError* malformed_error() const; | 789 virtual RawError* malformed_error() const; |
| 807 virtual void set_malformed_error(const Error& value) const; | 790 virtual void set_malformed_error(const Error& value) const; |
| 808 virtual bool IsResolved() const; | 791 virtual bool IsResolved() const; |
| 809 virtual bool HasResolvedTypeClass() const; | 792 virtual bool HasResolvedTypeClass() const; |
| 810 virtual RawClass* type_class() const; | 793 virtual RawClass* type_class() const; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 } | 862 } |
| 880 | 863 |
| 881 // Check the subtype relationship. | 864 // Check the subtype relationship. |
| 882 bool IsSubtypeOf(const AbstractType& other, Error* malformed_error) const; | 865 bool IsSubtypeOf(const AbstractType& other, Error* malformed_error) const; |
| 883 | 866 |
| 884 static RawAbstractType* NewTypeParameter(const Class& parameterized_class, | 867 static RawAbstractType* NewTypeParameter(const Class& parameterized_class, |
| 885 intptr_t index, | 868 intptr_t index, |
| 886 const String& name, | 869 const String& name, |
| 887 intptr_t token_index); | 870 intptr_t token_index); |
| 888 | 871 |
| 889 static RawAbstractType* NewInstantiatedType( | |
| 890 const AbstractType& uninstantiated_type, | |
| 891 const AbstractTypeArguments& instantiator_type_arguments); | |
| 892 | |
| 893 protected: | 872 protected: |
| 894 HEAP_OBJECT_IMPLEMENTATION(AbstractType, Object); | 873 HEAP_OBJECT_IMPLEMENTATION(AbstractType, Object); |
| 895 friend class Class; | 874 friend class Class; |
| 896 }; | 875 }; |
| 897 | 876 |
| 898 | 877 |
| 899 // A Type consists of a class, possibly parameterized with type | 878 // A Type consists of a class, possibly parameterized with type |
| 900 // arguments. Example: C<T1, T2>. | 879 // arguments. Example: C<T1, T2>. |
| 901 // An unresolved class is a String specifying the class name. | 880 // An unresolved class is a String specifying the class name. |
| 881 // |
| 882 // Caution: 'RawType*' denotes a 'raw' pointer to a VM object of class Type, as |
| 883 // opposed to 'Type' denoting a 'handle' to the same object. 'RawType' does not |
| 884 // relate to a 'raw type', as opposed to a 'cooked type' or 'rare type'. |
| 902 class Type : public AbstractType { | 885 class Type : public AbstractType { |
| 903 public: | 886 public: |
| 904 static intptr_t type_class_offset() { | 887 static intptr_t type_class_offset() { |
| 905 return OFFSET_OF(RawType, type_class_); | 888 return OFFSET_OF(RawType, type_class_); |
| 906 } | 889 } |
| 907 virtual bool IsFinalized() const { | 890 virtual bool IsFinalized() const { |
| 908 return | 891 return |
| 909 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) || | 892 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) || |
| 910 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated); | 893 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated); |
| 911 } | 894 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 void set_name(const String& value) const; | 1018 void set_name(const String& value) const; |
| 1036 void set_token_index(intptr_t token_index) const; | 1019 void set_token_index(intptr_t token_index) const; |
| 1037 void set_type_state(int8_t state) const; | 1020 void set_type_state(int8_t state) const; |
| 1038 static RawTypeParameter* New(); | 1021 static RawTypeParameter* New(); |
| 1039 | 1022 |
| 1040 HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); | 1023 HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); |
| 1041 friend class Class; | 1024 friend class Class; |
| 1042 }; | 1025 }; |
| 1043 | 1026 |
| 1044 | 1027 |
| 1045 // An instance of InstantiatedType is never encountered at compile time, but | |
| 1046 // only at run time, when type parameters can be matched to actual types. | |
| 1047 // An instance of InstantiatedType consists of an uninstantiated AbstractType | |
| 1048 // object and of a AbstractTypeArguments object. The type is uninstantiated, | |
| 1049 // because it refers to at least one TypeParameter object, i.e. to a type that | |
| 1050 // is not known at compile time. | |
| 1051 // The type argument vector is the instantiator, because each type parameter | |
| 1052 // with index i in the uninstantiated type can be substituted (or | |
| 1053 // "instantiated") with the type at index i in the type argument vector. | |
| 1054 class InstantiatedType : public AbstractType { | |
| 1055 public: | |
| 1056 virtual bool IsFinalized() const { return true; } | |
| 1057 virtual bool IsBeingFinalized() const { return false; } | |
| 1058 virtual bool IsMalformed() const { return false; } | |
| 1059 virtual bool IsResolved() const { return true; } | |
| 1060 virtual bool HasResolvedTypeClass() const { return true; } | |
| 1061 virtual RawClass* type_class() const; | |
| 1062 virtual RawAbstractTypeArguments* arguments() const; | |
| 1063 virtual intptr_t token_index() const; | |
| 1064 virtual bool IsInstantiated() const { return true; } | |
| 1065 virtual bool Equals(const AbstractType& other) const; | |
| 1066 | |
| 1067 RawAbstractType* uninstantiated_type() const { | |
| 1068 return raw_ptr()->uninstantiated_type_; | |
| 1069 } | |
| 1070 RawAbstractTypeArguments* instantiator_type_arguments() const { | |
| 1071 return raw_ptr()->instantiator_type_arguments_; | |
| 1072 } | |
| 1073 | |
| 1074 static intptr_t InstanceSize() { | |
| 1075 return RoundedAllocationSize(sizeof(RawInstantiatedType)); | |
| 1076 } | |
| 1077 | |
| 1078 static RawInstantiatedType* New( | |
| 1079 const AbstractType& uninstantiated_type, | |
| 1080 const AbstractTypeArguments& instantiator_type_arguments); | |
| 1081 | |
| 1082 private: | |
| 1083 void set_uninstantiated_type(const AbstractType& value) const; | |
| 1084 void set_instantiator_type_arguments( | |
| 1085 const AbstractTypeArguments& value) const; | |
| 1086 static RawInstantiatedType* New(); | |
| 1087 | |
| 1088 HEAP_OBJECT_IMPLEMENTATION(InstantiatedType, AbstractType); | |
| 1089 friend class Class; | |
| 1090 }; | |
| 1091 | |
| 1092 | |
| 1093 // AbstractTypeArguments is an abstract superclass. | 1028 // AbstractTypeArguments is an abstract superclass. |
| 1094 // Subclasses of AbstractTypeArguments are TypeArguments and InstantiatedTypes. | 1029 // Subclasses of AbstractTypeArguments are TypeArguments and |
| 1030 // InstantiatedTypeArguments. |
| 1095 class AbstractTypeArguments : public Object { | 1031 class AbstractTypeArguments : public Object { |
| 1096 public: | 1032 public: |
| 1097 // Returns true if both arguments represent vectors of equal types. | 1033 // Returns true if both arguments represent vectors of equal types. |
| 1098 static bool AreEqual(const AbstractTypeArguments& arguments, | 1034 static bool AreEqual(const AbstractTypeArguments& arguments, |
| 1099 const AbstractTypeArguments& other_arguments); | 1035 const AbstractTypeArguments& other_arguments); |
| 1100 | 1036 |
| 1101 // Returns true if both arguments represent vectors of possibly still | 1037 // Returns true if both arguments represent vectors of possibly still |
| 1102 // unresolved identical types. | 1038 // unresolved identical types. |
| 1103 static bool AreIdentical(const AbstractTypeArguments& arguments, | 1039 static bool AreIdentical(const AbstractTypeArguments& arguments, |
| 1104 const AbstractTypeArguments& other_arguments); | 1040 const AbstractTypeArguments& other_arguments); |
| (...skipping 3849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4954 } | 4890 } |
| 4955 | 4891 |
| 4956 | 4892 |
| 4957 intptr_t Stackmap::SizeInBits() const { | 4893 intptr_t Stackmap::SizeInBits() const { |
| 4958 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); | 4894 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); |
| 4959 } | 4895 } |
| 4960 | 4896 |
| 4961 } // namespace dart | 4897 } // namespace dart |
| 4962 | 4898 |
| 4963 #endif // VM_OBJECT_H_ | 4899 #endif // VM_OBJECT_H_ |
| OLD | NEW |