| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 class Object { | 112 class Object { |
| 113 public: | 113 public: |
| 114 // Index for Singleton internal VM classes, | 114 // Index for Singleton internal VM classes, |
| 115 // this index is used in snapshots to refer to these classes directly. | 115 // this index is used in snapshots to refer to these classes directly. |
| 116 enum { | 116 enum { |
| 117 kNullObject = 0, | 117 kNullObject = 0, |
| 118 kSentinelObject, | 118 kSentinelObject, |
| 119 kClassClass, | 119 kClassClass, |
| 120 kNullClass, | 120 kNullClass, |
| 121 kVarClass, | 121 kDynamicClass, |
| 122 kVoidClass, | 122 kVoidClass, |
| 123 kUnresolvedClassClass, | 123 kUnresolvedClassClass, |
| 124 kParameterizedTypeClass, | 124 kParameterizedTypeClass, |
| 125 kTypeParameterClass, | 125 kTypeParameterClass, |
| 126 kInstantiatedTypeClass, | 126 kInstantiatedTypeClass, |
| 127 kTypeArgumentsClass, | 127 kTypeArgumentsClass, |
| 128 kTypeArrayClass, | 128 kTypeArrayClass, |
| 129 kInstantiatedTypeArgumentsClass, | 129 kInstantiatedTypeArgumentsClass, |
| 130 kFunctionClass, | 130 kFunctionClass, |
| 131 kFieldClass, | 131 kFieldClass, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // The sentinel is a value that cannot be produced by Dart code. | 203 // The sentinel is a value that cannot be produced by Dart code. |
| 204 // It can be used to mark special values, for example to distinguish | 204 // It can be used to mark special values, for example to distinguish |
| 205 // "uninitialized" fields. | 205 // "uninitialized" fields. |
| 206 static RawInstance* sentinel() { return sentinel_; } | 206 static RawInstance* sentinel() { return sentinel_; } |
| 207 // Value marking that we are transitioning from sentinel, e.g., computing | 207 // Value marking that we are transitioning from sentinel, e.g., computing |
| 208 // a field value. Used to detect circular initialization. | 208 // a field value. Used to detect circular initialization. |
| 209 static RawInstance* transition_sentinel() { return transition_sentinel_; } | 209 static RawInstance* transition_sentinel() { return transition_sentinel_; } |
| 210 | 210 |
| 211 static RawClass* class_class() { return class_class_; } | 211 static RawClass* class_class() { return class_class_; } |
| 212 static RawClass* null_class() { return null_class_; } | 212 static RawClass* null_class() { return null_class_; } |
| 213 static RawClass* var_class() { return var_class_; } | 213 static RawClass* dynamic_class() { return dynamic_class_; } |
| 214 static RawClass* void_class() { return void_class_; } | 214 static RawClass* void_class() { return void_class_; } |
| 215 static RawClass* unresolved_class_class() { return unresolved_class_class_; } | 215 static RawClass* unresolved_class_class() { return unresolved_class_class_; } |
| 216 static RawClass* parameterized_type_class() { | 216 static RawClass* parameterized_type_class() { |
| 217 return parameterized_type_class_; | 217 return parameterized_type_class_; |
| 218 } | 218 } |
| 219 static RawClass* type_parameter_class() { return type_parameter_class_; } | 219 static RawClass* type_parameter_class() { return type_parameter_class_; } |
| 220 static RawClass* instantiated_type_class() { | 220 static RawClass* instantiated_type_class() { |
| 221 return instantiated_type_class_; | 221 return instantiated_type_class_; |
| 222 } | 222 } |
| 223 static RawClass* type_arguments_class() { return type_arguments_class_; } | 223 static RawClass* type_arguments_class() { return type_arguments_class_; } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 static cpp_vtable handle_vtable_; | 304 static cpp_vtable handle_vtable_; |
| 305 | 305 |
| 306 // The static values below are singletons shared between the different | 306 // The static values below are singletons shared between the different |
| 307 // isolates. They are all allocated in the non-GC'd Dart::vm_isolate_. | 307 // isolates. They are all allocated in the non-GC'd Dart::vm_isolate_. |
| 308 static RawObject* null_; | 308 static RawObject* null_; |
| 309 static RawInstance* sentinel_; | 309 static RawInstance* sentinel_; |
| 310 static RawInstance* transition_sentinel_; | 310 static RawInstance* transition_sentinel_; |
| 311 | 311 |
| 312 static RawClass* class_class_; // Class of the Class vm object. | 312 static RawClass* class_class_; // Class of the Class vm object. |
| 313 static RawClass* null_class_; // Class of the null object. | 313 static RawClass* null_class_; // Class of the null object. |
| 314 static RawClass* var_class_; // Class of the 'var' type. | 314 static RawClass* dynamic_class_; // Class of the 'Dynamic' type. |
| 315 static RawClass* void_class_; // Class of the 'void' type. | 315 static RawClass* void_class_; // Class of the 'void' type. |
| 316 static RawClass* unresolved_class_class_; // Class of UnresolvedClass. | 316 static RawClass* unresolved_class_class_; // Class of UnresolvedClass. |
| 317 static RawClass* parameterized_type_class_; // Class of ParameterizedType. | 317 static RawClass* parameterized_type_class_; // Class of ParameterizedType. |
| 318 static RawClass* type_parameter_class_; // Class of TypeParameter vm object. | 318 static RawClass* type_parameter_class_; // Class of TypeParameter vm object. |
| 319 static RawClass* instantiated_type_class_; // Class of InstantiatedType. | 319 static RawClass* instantiated_type_class_; // Class of InstantiatedType. |
| 320 static RawClass* type_arguments_class_; // Class of TypeArguments vm object. | 320 static RawClass* type_arguments_class_; // Class of TypeArguments vm object. |
| 321 static RawClass* type_array_class_; // Class of the TypeArray vm object. | 321 static RawClass* type_array_class_; // Class of the TypeArray vm object. |
| 322 static RawClass* instantiated_type_arguments_class_; // Class of Inst..ments. | 322 static RawClass* instantiated_type_arguments_class_; // Class of Inst..ments. |
| 323 static RawClass* function_class_; // Class of the Function vm object. | 323 static RawClass* function_class_; // Class of the Function vm object. |
| 324 static RawClass* field_class_; // Class of the Field vm object. | 324 static RawClass* field_class_; // Class of the Field vm object. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 RawType* SignatureType() const; | 402 RawType* SignatureType() const; |
| 403 | 403 |
| 404 RawLibrary* library() const { return raw_ptr()->library_; } | 404 RawLibrary* library() const { return raw_ptr()->library_; } |
| 405 void set_library(const Library& value) const; | 405 void set_library(const Library& value) const; |
| 406 | 406 |
| 407 // The type parameters are specified as an array of Strings. | 407 // The type parameters are specified as an array of Strings. |
| 408 RawArray* type_parameters() const { return raw_ptr()->type_parameters_; } | 408 RawArray* type_parameters() const { return raw_ptr()->type_parameters_; } |
| 409 void set_type_parameters(const Array& value) const; | 409 void set_type_parameters(const Array& value) const; |
| 410 intptr_t NumTypeParameters() const; | 410 intptr_t NumTypeParameters() const; |
| 411 | 411 |
| 412 // Type parameters may optionally extend a Type (VarType if no extends). | 412 // Type parameters may optionally extend a Type (DynamicType if no extends). |
| 413 RawTypeArray* type_parameter_extends() const { | 413 RawTypeArray* type_parameter_extends() const { |
| 414 return raw_ptr()->type_parameter_extends_; | 414 return raw_ptr()->type_parameter_extends_; |
| 415 } | 415 } |
| 416 void set_type_parameter_extends(const TypeArray& value) const; | 416 void set_type_parameter_extends(const TypeArray& value) const; |
| 417 | 417 |
| 418 // Return a TypeParameter if the type_name is a type parameter of this class. | 418 // Return a TypeParameter if the type_name is a type parameter of this class. |
| 419 // Return null otherwise. | 419 // Return null otherwise. |
| 420 RawTypeParameter* LookupTypeParameter(const String& type_name) const; | 420 RawTypeParameter* LookupTypeParameter(const String& type_name) const; |
| 421 | 421 |
| 422 // If this class is parameterized, each instance has a type_arguments field. | 422 // If this class is parameterized, each instance has a type_arguments field. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 RawArray* functions_cache() const { return raw_ptr()->functions_cache_; } | 460 RawArray* functions_cache() const { return raw_ptr()->functions_cache_; } |
| 461 void set_functions_cache(const Array& value) const; | 461 void set_functions_cache(const Array& value) const; |
| 462 | 462 |
| 463 static intptr_t functions_cache_offset() { | 463 static intptr_t functions_cache_offset() { |
| 464 return OFFSET_OF(RawClass, functions_cache_); | 464 return OFFSET_OF(RawClass, functions_cache_); |
| 465 } | 465 } |
| 466 | 466 |
| 467 // Check if this class represents the class of null. | 467 // Check if this class represents the class of null. |
| 468 bool IsNullClass() const { return raw() == Object::null_class(); } | 468 bool IsNullClass() const { return raw() == Object::null_class(); } |
| 469 | 469 |
| 470 // Check if this class represents the 'var' class. | 470 // Check if this class represents the 'Dynamic' class. |
| 471 bool IsVarClass() const { return raw() == Object::var_class(); } | 471 bool IsDynamicClass() const { return raw() == Object::dynamic_class(); } |
| 472 | 472 |
| 473 // Check if this class represents the 'void' class. | 473 // Check if this class represents the 'void' class. |
| 474 bool IsVoidClass() const { return raw() == Object::void_class(); } | 474 bool IsVoidClass() const { return raw() == Object::void_class(); } |
| 475 | 475 |
| 476 // Check if this class represents the 'Object' class. | 476 // Check if this class represents the 'Object' class. |
| 477 bool IsObjectClass() const; | 477 bool IsObjectClass() const; |
| 478 | 478 |
| 479 // Check if this class represents a signature class. | 479 // Check if this class represents a signature class. |
| 480 bool IsSignatureClass() const { | 480 bool IsSignatureClass() const { |
| 481 return signature_function() != Object::null(); | 481 return signature_function() != Object::null(); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 | 692 |
| 693 // The name of this type's class, i.e. without the type argument names of this | 693 // The name of this type's class, i.e. without the type argument names of this |
| 694 // type. | 694 // type. |
| 695 RawString* ClassName() const; | 695 RawString* ClassName() const; |
| 696 | 696 |
| 697 // Check if this type represents the 'null' type. | 697 // Check if this type represents the 'null' type. |
| 698 bool IsNullType() const { | 698 bool IsNullType() const { |
| 699 return HasResolvedTypeClass() && (type_class() == Object::null_class()); | 699 return HasResolvedTypeClass() && (type_class() == Object::null_class()); |
| 700 } | 700 } |
| 701 | 701 |
| 702 // Check if this type represents the 'var' type. | 702 // Check if this type represents the 'Dynamic' type. |
| 703 bool IsVarType() const { | 703 bool IsDynamicType() const { |
| 704 return HasResolvedTypeClass() && (type_class() == Object::var_class()); | 704 return HasResolvedTypeClass() && (type_class() == Object::dynamic_class()); |
| 705 } | 705 } |
| 706 | 706 |
| 707 // Check if this type represents the 'void' type. | 707 // Check if this type represents the 'void' type. |
| 708 bool IsVoidType() const { | 708 bool IsVoidType() const { |
| 709 return HasResolvedTypeClass() && (type_class() == Object::void_class()); | 709 return HasResolvedTypeClass() && (type_class() == Object::void_class()); |
| 710 } | 710 } |
| 711 | 711 |
| 712 // Check if this type represents the 'bool' interface. | 712 // Check if this type represents the 'bool' interface. |
| 713 bool IsBoolInterface() const; | 713 bool IsBoolInterface() const; |
| 714 | 714 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 745 } | 745 } |
| 746 | 746 |
| 747 // Check the assignability relationship. | 747 // Check the assignability relationship. |
| 748 bool IsAssignableTo(const Type& dst) const { | 748 bool IsAssignableTo(const Type& dst) const { |
| 749 return Test(kIsAssignableTo, dst); | 749 return Test(kIsAssignableTo, dst); |
| 750 } | 750 } |
| 751 | 751 |
| 752 // The type of the literal 'null'. | 752 // The type of the literal 'null'. |
| 753 static RawType* NullType(); | 753 static RawType* NullType(); |
| 754 | 754 |
| 755 // The 'var' type. | 755 // The 'Dynamic' type. |
| 756 static RawType* VarType(); | 756 static RawType* DynamicType(); |
| 757 | 757 |
| 758 // The 'void' type. | 758 // The 'void' type. |
| 759 static RawType* VoidType(); | 759 static RawType* VoidType(); |
| 760 | 760 |
| 761 // The 'Object' type. | 761 // The 'Object' type. |
| 762 static RawType* ObjectType(); | 762 static RawType* ObjectType(); |
| 763 | 763 |
| 764 // The 'bool' interface type. | 764 // The 'bool' interface type. |
| 765 static RawType* BoolInterface(); | 765 static RawType* BoolInterface(); |
| 766 | 766 |
| 767 // The 'int' interface type. | 767 // The 'int' interface type. |
| 768 static RawType* IntInterface(); | 768 static RawType* IntInterface(); |
| 769 | 769 |
| 770 // The 'double' interface type. | 770 // The 'double' interface type. |
| 771 static RawType* DoubleInterface(); | 771 static RawType* DoubleInterface(); |
| 772 | 772 |
| 773 // The 'num' interface type. | 773 // The 'num' interface type. |
| 774 static RawType* NumberInterface(); | 774 static RawType* NumberInterface(); |
| 775 | 775 |
| 776 // The 'String' interface type. | 776 // The 'String' interface type. |
| 777 static RawType* StringInterface(); | 777 static RawType* StringInterface(); |
| 778 | 778 |
| 779 // The 'Function' interface type. | 779 // The 'Function' interface type. |
| 780 static RawType* FunctionInterface(); | 780 static RawType* FunctionInterface(); |
| 781 | 781 |
| 782 // The least specific valid raw type of the given class. | 782 // The least specific valid raw type of the given class. |
| 783 // For example, type A<VarType> would be returned for class A<T>, and type | 783 // For example, type A<DynamicType> would be returned for class A<T>, and type |
| 784 // B<VarType, A<VarType>> would be returned for B<U, V extends A>. | 784 // B<DynamicType, A<DynamicType>> would be returned for B<U, V extends A>. |
| 785 static RawType* NewRawType(const Class& type_class); | 785 static RawType* NewRawType(const Class& type_class); |
| 786 | 786 |
| 787 // The finalized type of the given non-parameterized class. | 787 // The finalized type of the given non-parameterized class. |
| 788 static RawType* NewNonParameterizedType(const Class& type_class); | 788 static RawType* NewNonParameterizedType(const Class& type_class); |
| 789 | 789 |
| 790 static RawType* NewParameterizedType(const Object& type_class, | 790 static RawType* NewParameterizedType(const Object& type_class, |
| 791 const TypeArguments& arguments); | 791 const TypeArguments& arguments); |
| 792 | 792 |
| 793 static RawType* NewTypeParameter(intptr_t index, const String& name); | 793 static RawType* NewTypeParameter(intptr_t index, const String& name); |
| 794 | 794 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 virtual bool IsUninstantiatedIdentity() const; | 937 virtual bool IsUninstantiatedIdentity() const; |
| 938 | 938 |
| 939 // Return 'this' if this type argument vector is instantiated, i.e. if it does | 939 // Return 'this' if this type argument vector is instantiated, i.e. if it does |
| 940 // not refer to type parameters. Otherwise, return a new type argument vector | 940 // not refer to type parameters. Otherwise, return a new type argument vector |
| 941 // where each reference to a type parameter is replaced with the corresponding | 941 // where each reference to a type parameter is replaced with the corresponding |
| 942 // type of the instantiator type argument vector starting at the given offset. | 942 // type of the instantiator type argument vector starting at the given offset. |
| 943 virtual RawTypeArguments* InstantiateFrom( | 943 virtual RawTypeArguments* InstantiateFrom( |
| 944 const TypeArguments& instantiator_type_arguments, | 944 const TypeArguments& instantiator_type_arguments, |
| 945 intptr_t offset) const; | 945 intptr_t offset) const; |
| 946 | 946 |
| 947 // Check if this type argument vector consists solely of VarType, considering | 947 // Check if this type argument vector consists solely of DynamicType, |
| 948 // only a prefix of length 'len'. | 948 // considering only a prefix of length 'len'. |
| 949 bool IsVarTypes(intptr_t len) const; | 949 bool IsDynamicTypes(intptr_t len) const; |
| 950 | 950 |
| 951 // Check the "more specific than" relationship, considering only a prefix of | 951 // Check the "more specific than" relationship, considering only a prefix of |
| 952 // length 'len'. | 952 // length 'len'. |
| 953 bool IsMoreSpecificThan(const TypeArguments& other, intptr_t len) const; | 953 bool IsMoreSpecificThan(const TypeArguments& other, intptr_t len) const; |
| 954 | 954 |
| 955 static RawTypeArguments* NewTypeArray(intptr_t len); | 955 static RawTypeArguments* NewTypeArray(intptr_t len); |
| 956 | 956 |
| 957 static RawTypeArguments* NewInstantiatedTypeArguments( | 957 static RawTypeArguments* NewInstantiatedTypeArguments( |
| 958 const TypeArguments& uninstantiated_type_arguments, | 958 const TypeArguments& uninstantiated_type_arguments, |
| 959 const TypeArguments& instantiator_type_arguments); | 959 const TypeArguments& instantiator_type_arguments); |
| (...skipping 2008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2968 } | 2968 } |
| 2969 | 2969 |
| 2970 | 2970 |
| 2971 void Context::SetAt(intptr_t index, const Instance& value) const { | 2971 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 2972 StorePointer(InstanceAddr(index), value.raw()); | 2972 StorePointer(InstanceAddr(index), value.raw()); |
| 2973 } | 2973 } |
| 2974 | 2974 |
| 2975 } // namespace dart | 2975 } // namespace dart |
| 2976 | 2976 |
| 2977 #endif // VM_OBJECT_H_ | 2977 #endif // VM_OBJECT_H_ |
| OLD | NEW |