| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 static RawInstance* sentinel() { return sentinel_; } | 250 static RawInstance* sentinel() { return sentinel_; } |
| 251 // Value marking that we are transitioning from sentinel, e.g., computing | 251 // Value marking that we are transitioning from sentinel, e.g., computing |
| 252 // a field value. Used to detect circular initialization. | 252 // a field value. Used to detect circular initialization. |
| 253 static RawInstance* transition_sentinel() { return transition_sentinel_; } | 253 static RawInstance* transition_sentinel() { return transition_sentinel_; } |
| 254 | 254 |
| 255 static RawClass* class_class() { return class_class_; } | 255 static RawClass* class_class() { return class_class_; } |
| 256 static RawClass* null_class() { return null_class_; } | 256 static RawClass* null_class() { return null_class_; } |
| 257 static RawClass* dynamic_class() { return dynamic_class_; } | 257 static RawClass* dynamic_class() { return dynamic_class_; } |
| 258 static RawClass* void_class() { return void_class_; } | 258 static RawClass* void_class() { return void_class_; } |
| 259 static RawClass* unresolved_class_class() { return unresolved_class_class_; } | 259 static RawClass* unresolved_class_class() { return unresolved_class_class_; } |
| 260 static RawClass* type_class() { return type_class_; } | |
| 261 static RawClass* type_parameter_class() { return type_parameter_class_; } | |
| 262 static RawClass* type_arguments_class() { return type_arguments_class_; } | 260 static RawClass* type_arguments_class() { return type_arguments_class_; } |
| 263 static RawClass* instantiated_type_arguments_class() { | 261 static RawClass* instantiated_type_arguments_class() { |
| 264 return instantiated_type_arguments_class_; | 262 return instantiated_type_arguments_class_; |
| 265 } | 263 } |
| 266 static RawClass* patch_class_class() { return patch_class_class_; } | 264 static RawClass* patch_class_class() { return patch_class_class_; } |
| 267 static RawClass* function_class() { return function_class_; } | 265 static RawClass* function_class() { return function_class_; } |
| 268 static RawClass* closure_data_class() { return closure_data_class_; } | 266 static RawClass* closure_data_class() { return closure_data_class_; } |
| 269 static RawClass* redirection_data_class() { return redirection_data_class_; } | 267 static RawClass* redirection_data_class() { return redirection_data_class_; } |
| 270 static RawClass* field_class() { return field_class_; } | 268 static RawClass* field_class() { return field_class_; } |
| 271 static RawClass* literal_token_class() { return literal_token_class_; } | 269 static RawClass* literal_token_class() { return literal_token_class_; } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 static RawObject* null_; | 382 static RawObject* null_; |
| 385 static RawArray* empty_array_; | 383 static RawArray* empty_array_; |
| 386 static RawInstance* sentinel_; | 384 static RawInstance* sentinel_; |
| 387 static RawInstance* transition_sentinel_; | 385 static RawInstance* transition_sentinel_; |
| 388 | 386 |
| 389 static RawClass* class_class_; // Class of the Class vm object. | 387 static RawClass* class_class_; // Class of the Class vm object. |
| 390 static RawClass* null_class_; // Class of the null object. | 388 static RawClass* null_class_; // Class of the null object. |
| 391 static RawClass* dynamic_class_; // Class of the 'Dynamic' type. | 389 static RawClass* dynamic_class_; // Class of the 'Dynamic' type. |
| 392 static RawClass* void_class_; // Class of the 'void' type. | 390 static RawClass* void_class_; // Class of the 'void' type. |
| 393 static RawClass* unresolved_class_class_; // Class of UnresolvedClass. | 391 static RawClass* unresolved_class_class_; // Class of UnresolvedClass. |
| 394 static RawClass* type_class_; // Class of Type. | |
| 395 static RawClass* type_parameter_class_; // Class of TypeParameter vm object. | |
| 396 // Class of the TypeArguments vm object. | 392 // Class of the TypeArguments vm object. |
| 397 static RawClass* type_arguments_class_; | 393 static RawClass* type_arguments_class_; |
| 398 static RawClass* instantiated_type_arguments_class_; // Class of Inst..ments. | 394 static RawClass* instantiated_type_arguments_class_; // Class of Inst..ments. |
| 399 static RawClass* patch_class_class_; // Class of the PatchClass vm object. | 395 static RawClass* patch_class_class_; // Class of the PatchClass vm object. |
| 400 static RawClass* function_class_; // Class of the Function vm object. | 396 static RawClass* function_class_; // Class of the Function vm object. |
| 401 static RawClass* closure_data_class_; // Class of ClosureData vm obj. | 397 static RawClass* closure_data_class_; // Class of ClosureData vm obj. |
| 402 static RawClass* redirection_data_class_; // Class of RedirectionData vm obj. | 398 static RawClass* redirection_data_class_; // Class of RedirectionData vm obj. |
| 403 static RawClass* field_class_; // Class of the Field vm object. | 399 static RawClass* field_class_; // Class of the Field vm object. |
| 404 static RawClass* literal_token_class_; // Class of LiteralToken vm object. | 400 static RawClass* literal_token_class_; // Class of LiteralToken vm object. |
| 405 static RawClass* token_stream_class_; // Class of the TokenStream vm object. | 401 static RawClass* token_stream_class_; // Class of the TokenStream vm object. |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 void set_ident(const String& ident) const; | 812 void set_ident(const String& ident) const; |
| 817 void set_token_pos(intptr_t token_pos) const; | 813 void set_token_pos(intptr_t token_pos) const; |
| 818 | 814 |
| 819 static RawUnresolvedClass* New(); | 815 static RawUnresolvedClass* New(); |
| 820 | 816 |
| 821 HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); | 817 HEAP_OBJECT_IMPLEMENTATION(UnresolvedClass, Object); |
| 822 friend class Class; | 818 friend class Class; |
| 823 }; | 819 }; |
| 824 | 820 |
| 825 | 821 |
| 826 // AbstractType is an abstract superclass. | |
| 827 // Subclasses of AbstractType are Type and TypeParameter. | |
| 828 class AbstractType : public Object { | |
| 829 public: | |
| 830 virtual bool IsFinalized() const; | |
| 831 virtual bool IsBeingFinalized() const; | |
| 832 virtual bool IsMalformed() const; | |
| 833 virtual RawError* malformed_error() const; | |
| 834 virtual void set_malformed_error(const Error& value) const; | |
| 835 virtual bool IsResolved() const; | |
| 836 virtual bool HasResolvedTypeClass() const; | |
| 837 virtual RawClass* type_class() const; | |
| 838 virtual RawUnresolvedClass* unresolved_class() const; | |
| 839 virtual RawAbstractTypeArguments* arguments() const; | |
| 840 virtual intptr_t token_pos() const; | |
| 841 virtual bool IsInstantiated() const; | |
| 842 virtual bool Equals(const AbstractType& other) const; | |
| 843 virtual bool IsIdentical(const AbstractType& other, | |
| 844 bool check_type_parameter_bound) const; | |
| 845 | |
| 846 // Instantiate this type using the given type argument vector. | |
| 847 // Return a new type, or return 'this' if it is already instantiated. | |
| 848 virtual RawAbstractType* InstantiateFrom( | |
| 849 const AbstractTypeArguments& instantiator_type_arguments) const; | |
| 850 | |
| 851 // Return the canonical version of this type. | |
| 852 virtual RawAbstractType* Canonicalize() const; | |
| 853 | |
| 854 // The name of this type, including the names of its type arguments, if any. | |
| 855 virtual RawString* Name() const { | |
| 856 return BuildName(kInternalName); | |
| 857 } | |
| 858 | |
| 859 // The name of this type, including the names of its type arguments, if any. | |
| 860 // Names of internal classes are mapped to their public interfaces. | |
| 861 virtual RawString* UserVisibleName() const { | |
| 862 return BuildName(kUserVisibleName); | |
| 863 } | |
| 864 | |
| 865 // The name of this type's class, i.e. without the type argument names of this | |
| 866 // type. | |
| 867 RawString* ClassName() const; | |
| 868 | |
| 869 // Check if this type represents the 'Dynamic' type. | |
| 870 bool IsDynamicType() const { | |
| 871 return HasResolvedTypeClass() && (type_class() == Object::dynamic_class()); | |
| 872 } | |
| 873 | |
| 874 // Check if this type represents the 'Null' type. | |
| 875 bool IsNullType() const { | |
| 876 return HasResolvedTypeClass() && (type_class() == Object::null_class()); | |
| 877 } | |
| 878 | |
| 879 // Check if this type represents the 'void' type. | |
| 880 bool IsVoidType() const { | |
| 881 return HasResolvedTypeClass() && (type_class() == Object::void_class()); | |
| 882 } | |
| 883 | |
| 884 bool IsObjectType() const { | |
| 885 return HasResolvedTypeClass() && | |
| 886 Class::Handle(type_class()).IsObjectClass(); | |
| 887 } | |
| 888 | |
| 889 // Check if this type represents the 'bool' type. | |
| 890 bool IsBoolType() const; | |
| 891 | |
| 892 // Check if this type represents the 'int' type. | |
| 893 bool IsIntType() const; | |
| 894 | |
| 895 // Check if this type represents the 'double' type. | |
| 896 bool IsDoubleType() const; | |
| 897 | |
| 898 // Check if this type represents the 'num' type. | |
| 899 bool IsNumberType() const; | |
| 900 | |
| 901 // Check if this type represents the 'String' interface. | |
| 902 bool IsStringInterface() const; | |
| 903 | |
| 904 // Check if this type represents the 'Function' type. | |
| 905 bool IsFunctionType() const; | |
| 906 | |
| 907 // Check if this type represents the 'List' interface. | |
| 908 bool IsListInterface() const; | |
| 909 | |
| 910 // Check if this type is an interface type. | |
| 911 bool IsInterfaceType() const { | |
| 912 if (!HasResolvedTypeClass()) { | |
| 913 return false; | |
| 914 } | |
| 915 const Class& cls = Class::Handle(type_class()); | |
| 916 return !cls.IsNull() && cls.is_interface(); | |
| 917 } | |
| 918 | |
| 919 // Check the subtype relationship. | |
| 920 bool IsSubtypeOf(const AbstractType& other, Error* malformed_error) const { | |
| 921 return TypeTest(kIsSubtypeOf, other, malformed_error); | |
| 922 } | |
| 923 | |
| 924 // Check the 'more specific' relationship. | |
| 925 bool IsMoreSpecificThan(const AbstractType& other, | |
| 926 Error* malformed_error) const { | |
| 927 return TypeTest(kIsMoreSpecificThan, other, malformed_error); | |
| 928 } | |
| 929 | |
| 930 private: | |
| 931 // Check the subtype or 'more specific' relationship. | |
| 932 bool TypeTest(TypeTestKind test_kind, | |
| 933 const AbstractType& other, | |
| 934 Error* malformed_error) const; | |
| 935 | |
| 936 // Return the internal or public name of this type, including the names of its | |
| 937 // type arguments, if any. | |
| 938 RawString* BuildName(NameVisibility visibility) const; | |
| 939 | |
| 940 protected: | |
| 941 HEAP_OBJECT_IMPLEMENTATION(AbstractType, Object); | |
| 942 friend class AbstractTypeArguments; | |
| 943 friend class Class; | |
| 944 friend class Function; | |
| 945 }; | |
| 946 | |
| 947 | |
| 948 // A Type consists of a class, possibly parameterized with type | |
| 949 // arguments. Example: C<T1, T2>. | |
| 950 // An unresolved class is a String specifying the class name. | |
| 951 // | |
| 952 // Caution: 'RawType*' denotes a 'raw' pointer to a VM object of class Type, as | |
| 953 // opposed to 'Type' denoting a 'handle' to the same object. 'RawType' does not | |
| 954 // relate to a 'raw type', as opposed to a 'cooked type' or 'rare type'. | |
| 955 class Type : public AbstractType { | |
| 956 public: | |
| 957 static intptr_t type_class_offset() { | |
| 958 return OFFSET_OF(RawType, type_class_); | |
| 959 } | |
| 960 virtual bool IsFinalized() const { | |
| 961 return | |
| 962 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) || | |
| 963 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated); | |
| 964 } | |
| 965 void set_is_finalized_instantiated() const; | |
| 966 void set_is_finalized_uninstantiated() const; | |
| 967 virtual bool IsBeingFinalized() const { | |
| 968 return raw_ptr()->type_state_ == RawType::kBeingFinalized; | |
| 969 } | |
| 970 void set_is_being_finalized() const; | |
| 971 virtual bool IsMalformed() const; | |
| 972 virtual RawError* malformed_error() const; | |
| 973 virtual void set_malformed_error(const Error& value) const; | |
| 974 virtual bool IsResolved() const; // Class and all arguments classes resolved. | |
| 975 virtual bool HasResolvedTypeClass() const; // Own type class resolved. | |
| 976 virtual RawClass* type_class() const; | |
| 977 void set_type_class(const Object& value) const; | |
| 978 virtual RawUnresolvedClass* unresolved_class() const; | |
| 979 RawString* TypeClassName() const; | |
| 980 virtual RawAbstractTypeArguments* arguments() const; | |
| 981 void set_arguments(const AbstractTypeArguments& value) const; | |
| 982 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } | |
| 983 virtual bool IsInstantiated() const; | |
| 984 virtual bool Equals(const AbstractType& other) const; | |
| 985 virtual bool IsIdentical(const AbstractType& other, | |
| 986 bool check_type_parameter_bound) const; | |
| 987 virtual RawAbstractType* InstantiateFrom( | |
| 988 const AbstractTypeArguments& instantiator_type_arguments) const; | |
| 989 virtual RawAbstractType* Canonicalize() const; | |
| 990 | |
| 991 static intptr_t InstanceSize() { | |
| 992 return RoundedAllocationSize(sizeof(RawType)); | |
| 993 } | |
| 994 | |
| 995 // The type of the literal 'null'. | |
| 996 static RawType* NullType(); | |
| 997 | |
| 998 // The 'Dynamic' type. | |
| 999 static RawType* DynamicType(); | |
| 1000 | |
| 1001 // The 'void' type. | |
| 1002 static RawType* VoidType(); | |
| 1003 | |
| 1004 // The 'Object' type. | |
| 1005 static RawType* ObjectType(); | |
| 1006 | |
| 1007 // The 'bool' type. | |
| 1008 static RawType* BoolType(); | |
| 1009 | |
| 1010 // The 'int' type. | |
| 1011 static RawType* IntType(); | |
| 1012 | |
| 1013 // The 'Smi' type. | |
| 1014 static RawType* SmiType(); | |
| 1015 | |
| 1016 // The 'Mint' type. | |
| 1017 static RawType* MintType(); | |
| 1018 | |
| 1019 // The 'double' type. | |
| 1020 static RawType* Double(); | |
| 1021 | |
| 1022 // The 'num' interface type. | |
| 1023 static RawType* Number(); | |
| 1024 | |
| 1025 // The 'String' interface type. | |
| 1026 static RawType* StringInterface(); | |
| 1027 | |
| 1028 // The 'Function' interface type. | |
| 1029 static RawType* Function(); | |
| 1030 | |
| 1031 // The 'List' interface type. | |
| 1032 static RawType* ListInterface(); | |
| 1033 | |
| 1034 // The finalized type of the given non-parameterized class. | |
| 1035 static RawType* NewNonParameterizedType(const Class& type_class); | |
| 1036 | |
| 1037 static RawType* New(const Object& clazz, | |
| 1038 const AbstractTypeArguments& arguments, | |
| 1039 intptr_t token_pos, | |
| 1040 Heap::Space space = Heap::kOld); | |
| 1041 | |
| 1042 private: | |
| 1043 void set_token_pos(intptr_t token_pos) const; | |
| 1044 void set_type_state(int8_t state) const; | |
| 1045 | |
| 1046 static RawType* New(Heap::Space space = Heap::kOld); | |
| 1047 | |
| 1048 HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); | |
| 1049 friend class Class; | |
| 1050 }; | |
| 1051 | |
| 1052 | |
| 1053 // A TypeParameter represents a type parameter of a parameterized class. | |
| 1054 // It specifies its index (and its name for debugging purposes), as well as its | |
| 1055 // upper bound. | |
| 1056 // For example, the type parameter 'V' is specified as index 1 in the context of | |
| 1057 // the class HashMap<K, V>. At compile time, the TypeParameter is not | |
| 1058 // instantiated yet, i.e. it is only a place holder. | |
| 1059 // Upon finalization, the TypeParameter index is changed to reflect its position | |
| 1060 // as type argument (rather than type parameter) of the parameterized class. | |
| 1061 // If the type parameter is declared without an extends clause, its bound is set | |
| 1062 // to the DynamicType. | |
| 1063 class TypeParameter : public AbstractType { | |
| 1064 public: | |
| 1065 virtual bool IsFinalized() const { | |
| 1066 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated); | |
| 1067 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated; | |
| 1068 } | |
| 1069 void set_is_finalized() const; | |
| 1070 virtual bool IsBeingFinalized() const { return false; } | |
| 1071 virtual bool IsMalformed() const { return false; } | |
| 1072 virtual bool IsResolved() const { return true; } | |
| 1073 virtual bool HasResolvedTypeClass() const { return false; } | |
| 1074 RawClass* parameterized_class() const { | |
| 1075 return raw_ptr()->parameterized_class_; | |
| 1076 } | |
| 1077 RawString* name() const { return raw_ptr()->name_; } | |
| 1078 intptr_t index() const { return raw_ptr()->index_; } | |
| 1079 void set_index(intptr_t value) const; | |
| 1080 RawAbstractType* bound() const { return raw_ptr()->bound_; } | |
| 1081 void set_bound(const AbstractType& value) const; | |
| 1082 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } | |
| 1083 virtual bool IsInstantiated() const { return false; } | |
| 1084 virtual bool Equals(const AbstractType& other) const; | |
| 1085 virtual bool IsIdentical(const AbstractType& other, | |
| 1086 bool check_type_parameter_bound) const; | |
| 1087 virtual RawAbstractType* InstantiateFrom( | |
| 1088 const AbstractTypeArguments& instantiator_type_arguments) const; | |
| 1089 virtual RawAbstractType* Canonicalize() const { return raw(); } | |
| 1090 | |
| 1091 static intptr_t InstanceSize() { | |
| 1092 return RoundedAllocationSize(sizeof(RawTypeParameter)); | |
| 1093 } | |
| 1094 | |
| 1095 static RawTypeParameter* New(const Class& parameterized_class, | |
| 1096 intptr_t index, | |
| 1097 const String& name, | |
| 1098 const AbstractType& bound, | |
| 1099 intptr_t token_pos); | |
| 1100 | |
| 1101 private: | |
| 1102 void set_parameterized_class(const Class& value) const; | |
| 1103 void set_name(const String& value) const; | |
| 1104 void set_token_pos(intptr_t token_pos) const; | |
| 1105 void set_type_state(int8_t state) const; | |
| 1106 static RawTypeParameter* New(); | |
| 1107 | |
| 1108 HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); | |
| 1109 friend class Class; | |
| 1110 }; | |
| 1111 | |
| 1112 | |
| 1113 // AbstractTypeArguments is an abstract superclass. | 822 // AbstractTypeArguments is an abstract superclass. |
| 1114 // Subclasses of AbstractTypeArguments are TypeArguments and | 823 // Subclasses of AbstractTypeArguments are TypeArguments and |
| 1115 // InstantiatedTypeArguments. | 824 // InstantiatedTypeArguments. |
| 1116 class AbstractTypeArguments : public Object { | 825 class AbstractTypeArguments : public Object { |
| 1117 public: | 826 public: |
| 1118 // Returns true if both arguments represent vectors of equal types. | 827 // Returns true if both arguments represent vectors of equal types. |
| 1119 static bool AreEqual(const AbstractTypeArguments& arguments, | 828 static bool AreEqual(const AbstractTypeArguments& arguments, |
| 1120 const AbstractTypeArguments& other_arguments); | 829 const AbstractTypeArguments& other_arguments); |
| 1121 | 830 |
| 1122 // Returns true if both arguments represent vectors of possibly still | 831 // Returns true if both arguments represent vectors of possibly still |
| (...skipping 2180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3303 StorePointer(FieldAddrAtOffset(offset), value.raw()); | 3012 StorePointer(FieldAddrAtOffset(offset), value.raw()); |
| 3304 } | 3013 } |
| 3305 bool IsValidFieldOffset(int offset) const; | 3014 bool IsValidFieldOffset(int offset) const; |
| 3306 | 3015 |
| 3307 // TODO(iposva): Determine if this gets in the way of Smi. | 3016 // TODO(iposva): Determine if this gets in the way of Smi. |
| 3308 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); | 3017 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); |
| 3309 friend class Class; | 3018 friend class Class; |
| 3310 }; | 3019 }; |
| 3311 | 3020 |
| 3312 | 3021 |
| 3022 // AbstractType is an abstract superclass. |
| 3023 // Subclasses of AbstractType are Type and TypeParameter. |
| 3024 class AbstractType : public Instance { |
| 3025 public: |
| 3026 virtual bool IsFinalized() const; |
| 3027 virtual bool IsBeingFinalized() const; |
| 3028 virtual bool IsMalformed() const; |
| 3029 virtual RawError* malformed_error() const; |
| 3030 virtual void set_malformed_error(const Error& value) const; |
| 3031 virtual bool IsResolved() const; |
| 3032 virtual bool HasResolvedTypeClass() const; |
| 3033 virtual RawClass* type_class() const; |
| 3034 virtual RawUnresolvedClass* unresolved_class() const; |
| 3035 virtual RawAbstractTypeArguments* arguments() const; |
| 3036 virtual intptr_t token_pos() const; |
| 3037 virtual bool IsInstantiated() const; |
| 3038 virtual bool Equals(const Instance& other) const; |
| 3039 virtual bool IsIdentical(const AbstractType& other, |
| 3040 bool check_type_parameter_bound) const; |
| 3041 |
| 3042 // Instantiate this type using the given type argument vector. |
| 3043 // Return a new type, or return 'this' if it is already instantiated. |
| 3044 virtual RawAbstractType* InstantiateFrom( |
| 3045 const AbstractTypeArguments& instantiator_type_arguments) const; |
| 3046 |
| 3047 // Return the canonical version of this type. |
| 3048 virtual RawAbstractType* Canonicalize() const; |
| 3049 |
| 3050 // The name of this type, including the names of its type arguments, if any. |
| 3051 virtual RawString* Name() const { |
| 3052 return BuildName(kInternalName); |
| 3053 } |
| 3054 |
| 3055 // The name of this type, including the names of its type arguments, if any. |
| 3056 // Names of internal classes are mapped to their public interfaces. |
| 3057 virtual RawString* UserVisibleName() const { |
| 3058 return BuildName(kUserVisibleName); |
| 3059 } |
| 3060 |
| 3061 // The name of this type's class, i.e. without the type argument names of this |
| 3062 // type. |
| 3063 RawString* ClassName() const; |
| 3064 |
| 3065 // Check if this type represents the 'Dynamic' type. |
| 3066 bool IsDynamicType() const { |
| 3067 return HasResolvedTypeClass() && (type_class() == Object::dynamic_class()); |
| 3068 } |
| 3069 |
| 3070 // Check if this type represents the 'Null' type. |
| 3071 bool IsNullType() const { |
| 3072 return HasResolvedTypeClass() && (type_class() == Object::null_class()); |
| 3073 } |
| 3074 |
| 3075 // Check if this type represents the 'void' type. |
| 3076 bool IsVoidType() const { |
| 3077 return HasResolvedTypeClass() && (type_class() == Object::void_class()); |
| 3078 } |
| 3079 |
| 3080 bool IsObjectType() const { |
| 3081 return HasResolvedTypeClass() && |
| 3082 Class::Handle(type_class()).IsObjectClass(); |
| 3083 } |
| 3084 |
| 3085 // Check if this type represents the 'bool' type. |
| 3086 bool IsBoolType() const; |
| 3087 |
| 3088 // Check if this type represents the 'int' type. |
| 3089 bool IsIntType() const; |
| 3090 |
| 3091 // Check if this type represents the 'double' type. |
| 3092 bool IsDoubleType() const; |
| 3093 |
| 3094 // Check if this type represents the 'num' type. |
| 3095 bool IsNumberType() const; |
| 3096 |
| 3097 // Check if this type represents the 'String' interface. |
| 3098 bool IsStringInterface() const; |
| 3099 |
| 3100 // Check if this type represents the 'Function' type. |
| 3101 bool IsFunctionType() const; |
| 3102 |
| 3103 // Check if this type represents the 'List' interface. |
| 3104 bool IsListInterface() const; |
| 3105 |
| 3106 // Check if this type is an interface type. |
| 3107 bool IsInterfaceType() const { |
| 3108 if (!HasResolvedTypeClass()) { |
| 3109 return false; |
| 3110 } |
| 3111 const Class& cls = Class::Handle(type_class()); |
| 3112 return !cls.IsNull() && cls.is_interface(); |
| 3113 } |
| 3114 |
| 3115 // Check the subtype relationship. |
| 3116 bool IsSubtypeOf(const AbstractType& other, Error* malformed_error) const { |
| 3117 return TypeTest(kIsSubtypeOf, other, malformed_error); |
| 3118 } |
| 3119 |
| 3120 // Check the 'more specific' relationship. |
| 3121 bool IsMoreSpecificThan(const AbstractType& other, |
| 3122 Error* malformed_error) const { |
| 3123 return TypeTest(kIsMoreSpecificThan, other, malformed_error); |
| 3124 } |
| 3125 |
| 3126 private: |
| 3127 // Check the subtype or 'more specific' relationship. |
| 3128 bool TypeTest(TypeTestKind test_kind, |
| 3129 const AbstractType& other, |
| 3130 Error* malformed_error) const; |
| 3131 |
| 3132 // Return the internal or public name of this type, including the names of its |
| 3133 // type arguments, if any. |
| 3134 RawString* BuildName(NameVisibility visibility) const; |
| 3135 |
| 3136 protected: |
| 3137 HEAP_OBJECT_IMPLEMENTATION(AbstractType, Instance); |
| 3138 friend class AbstractTypeArguments; |
| 3139 friend class Class; |
| 3140 friend class Function; |
| 3141 }; |
| 3142 |
| 3143 |
| 3144 // A Type consists of a class, possibly parameterized with type |
| 3145 // arguments. Example: C<T1, T2>. |
| 3146 // An unresolved class is a String specifying the class name. |
| 3147 // |
| 3148 // Caution: 'RawType*' denotes a 'raw' pointer to a VM object of class Type, as |
| 3149 // opposed to 'Type' denoting a 'handle' to the same object. 'RawType' does not |
| 3150 // relate to a 'raw type', as opposed to a 'cooked type' or 'rare type'. |
| 3151 class Type : public AbstractType { |
| 3152 public: |
| 3153 static intptr_t type_class_offset() { |
| 3154 return OFFSET_OF(RawType, type_class_); |
| 3155 } |
| 3156 virtual bool IsFinalized() const { |
| 3157 return |
| 3158 (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) || |
| 3159 (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated); |
| 3160 } |
| 3161 void set_is_finalized_instantiated() const; |
| 3162 void set_is_finalized_uninstantiated() const; |
| 3163 virtual bool IsBeingFinalized() const { |
| 3164 return raw_ptr()->type_state_ == RawType::kBeingFinalized; |
| 3165 } |
| 3166 void set_is_being_finalized() const; |
| 3167 virtual bool IsMalformed() const; |
| 3168 virtual RawError* malformed_error() const; |
| 3169 virtual void set_malformed_error(const Error& value) const; |
| 3170 virtual bool IsResolved() const; // Class and all arguments classes resolved. |
| 3171 virtual bool HasResolvedTypeClass() const; // Own type class resolved. |
| 3172 virtual RawClass* type_class() const; |
| 3173 void set_type_class(const Object& value) const; |
| 3174 virtual RawUnresolvedClass* unresolved_class() const; |
| 3175 RawString* TypeClassName() const; |
| 3176 virtual RawAbstractTypeArguments* arguments() const; |
| 3177 void set_arguments(const AbstractTypeArguments& value) const; |
| 3178 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } |
| 3179 virtual bool IsInstantiated() const; |
| 3180 virtual bool Equals(const Instance& other) const; |
| 3181 virtual bool IsIdentical(const AbstractType& other, |
| 3182 bool check_type_parameter_bound) const; |
| 3183 virtual RawAbstractType* InstantiateFrom( |
| 3184 const AbstractTypeArguments& instantiator_type_arguments) const; |
| 3185 virtual RawAbstractType* Canonicalize() const; |
| 3186 |
| 3187 static intptr_t InstanceSize() { |
| 3188 return RoundedAllocationSize(sizeof(RawType)); |
| 3189 } |
| 3190 |
| 3191 // The type of the literal 'null'. |
| 3192 static RawType* NullType(); |
| 3193 |
| 3194 // The 'Dynamic' type. |
| 3195 static RawType* DynamicType(); |
| 3196 |
| 3197 // The 'void' type. |
| 3198 static RawType* VoidType(); |
| 3199 |
| 3200 // The 'Object' type. |
| 3201 static RawType* ObjectType(); |
| 3202 |
| 3203 // The 'bool' type. |
| 3204 static RawType* BoolType(); |
| 3205 |
| 3206 // The 'int' type. |
| 3207 static RawType* IntType(); |
| 3208 |
| 3209 // The 'Smi' type. |
| 3210 static RawType* SmiType(); |
| 3211 |
| 3212 // The 'Mint' type. |
| 3213 static RawType* MintType(); |
| 3214 |
| 3215 // The 'double' type. |
| 3216 static RawType* Double(); |
| 3217 |
| 3218 // The 'num' interface type. |
| 3219 static RawType* Number(); |
| 3220 |
| 3221 // The 'String' interface type. |
| 3222 static RawType* StringInterface(); |
| 3223 |
| 3224 // The 'Function' interface type. |
| 3225 static RawType* Function(); |
| 3226 |
| 3227 // The 'List' interface type. |
| 3228 static RawType* ListInterface(); |
| 3229 |
| 3230 // The finalized type of the given non-parameterized class. |
| 3231 static RawType* NewNonParameterizedType(const Class& type_class); |
| 3232 |
| 3233 static RawType* New(const Object& clazz, |
| 3234 const AbstractTypeArguments& arguments, |
| 3235 intptr_t token_pos, |
| 3236 Heap::Space space = Heap::kOld); |
| 3237 |
| 3238 private: |
| 3239 void set_token_pos(intptr_t token_pos) const; |
| 3240 void set_type_state(int8_t state) const; |
| 3241 |
| 3242 static RawType* New(Heap::Space space = Heap::kOld); |
| 3243 |
| 3244 HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); |
| 3245 friend class Class; |
| 3246 }; |
| 3247 |
| 3248 |
| 3249 // A TypeParameter represents a type parameter of a parameterized class. |
| 3250 // It specifies its index (and its name for debugging purposes), as well as its |
| 3251 // upper bound. |
| 3252 // For example, the type parameter 'V' is specified as index 1 in the context of |
| 3253 // the class HashMap<K, V>. At compile time, the TypeParameter is not |
| 3254 // instantiated yet, i.e. it is only a place holder. |
| 3255 // Upon finalization, the TypeParameter index is changed to reflect its position |
| 3256 // as type argument (rather than type parameter) of the parameterized class. |
| 3257 // If the type parameter is declared without an extends clause, its bound is set |
| 3258 // to the DynamicType. |
| 3259 class TypeParameter : public AbstractType { |
| 3260 public: |
| 3261 virtual bool IsFinalized() const { |
| 3262 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated); |
| 3263 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated; |
| 3264 } |
| 3265 void set_is_finalized() const; |
| 3266 virtual bool IsBeingFinalized() const { return false; } |
| 3267 virtual bool IsMalformed() const { return false; } |
| 3268 virtual bool IsResolved() const { return true; } |
| 3269 virtual bool HasResolvedTypeClass() const { return false; } |
| 3270 RawClass* parameterized_class() const { |
| 3271 return raw_ptr()->parameterized_class_; |
| 3272 } |
| 3273 RawString* name() const { return raw_ptr()->name_; } |
| 3274 intptr_t index() const { return raw_ptr()->index_; } |
| 3275 void set_index(intptr_t value) const; |
| 3276 RawAbstractType* bound() const { return raw_ptr()->bound_; } |
| 3277 void set_bound(const AbstractType& value) const; |
| 3278 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } |
| 3279 virtual bool IsInstantiated() const { return false; } |
| 3280 virtual bool Equals(const Instance& other) const; |
| 3281 virtual bool IsIdentical(const AbstractType& other, |
| 3282 bool check_type_parameter_bound) const; |
| 3283 virtual RawAbstractType* InstantiateFrom( |
| 3284 const AbstractTypeArguments& instantiator_type_arguments) const; |
| 3285 virtual RawAbstractType* Canonicalize() const { return raw(); } |
| 3286 |
| 3287 static intptr_t InstanceSize() { |
| 3288 return RoundedAllocationSize(sizeof(RawTypeParameter)); |
| 3289 } |
| 3290 |
| 3291 static RawTypeParameter* New(const Class& parameterized_class, |
| 3292 intptr_t index, |
| 3293 const String& name, |
| 3294 const AbstractType& bound, |
| 3295 intptr_t token_pos); |
| 3296 |
| 3297 private: |
| 3298 void set_parameterized_class(const Class& value) const; |
| 3299 void set_name(const String& value) const; |
| 3300 void set_token_pos(intptr_t token_pos) const; |
| 3301 void set_type_state(int8_t state) const; |
| 3302 static RawTypeParameter* New(); |
| 3303 |
| 3304 HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); |
| 3305 friend class Class; |
| 3306 }; |
| 3307 |
| 3308 |
| 3313 class Number : public Instance { | 3309 class Number : public Instance { |
| 3314 public: | 3310 public: |
| 3315 // TODO(iposva): Fill in a useful Number interface. | 3311 // TODO(iposva): Fill in a useful Number interface. |
| 3316 virtual bool IsZero() const { | 3312 virtual bool IsZero() const { |
| 3317 // Number is an abstract class. | 3313 // Number is an abstract class. |
| 3318 UNREACHABLE(); | 3314 UNREACHABLE(); |
| 3319 return false; | 3315 return false; |
| 3320 } | 3316 } |
| 3321 virtual bool IsNegative() const { | 3317 virtual bool IsNegative() const { |
| 3322 // Number is an abstract class. | 3318 // Number is an abstract class. |
| (...skipping 2401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5724 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5720 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
| 5725 return false; | 5721 return false; |
| 5726 } | 5722 } |
| 5727 } | 5723 } |
| 5728 return true; | 5724 return true; |
| 5729 } | 5725 } |
| 5730 | 5726 |
| 5731 } // namespace dart | 5727 } // namespace dart |
| 5732 | 5728 |
| 5733 #endif // VM_OBJECT_H_ | 5729 #endif // VM_OBJECT_H_ |
| OLD | NEW |