Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: runtime/vm/object.h

Issue 9939003: Use null type argument vector instead of vector of Dynamic for a generic raw (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/flow_graph_compiler_x64.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 if (!HasResolvedTypeClass()) { 841 if (!HasResolvedTypeClass()) {
842 return false; 842 return false;
843 } 843 }
844 const Class& cls = Class::Handle(type_class()); 844 const Class& cls = Class::Handle(type_class());
845 return !cls.IsNull() && cls.is_interface(); 845 return !cls.IsNull() && cls.is_interface();
846 } 846 }
847 847
848 // Check the subtype relationship. 848 // Check the subtype relationship.
849 bool IsSubtypeOf(const AbstractType& other, Error* malformed_error) const; 849 bool IsSubtypeOf(const AbstractType& other, Error* malformed_error) const;
850 850
851 static RawAbstractType* NewTypeParameter(intptr_t index, 851 static RawAbstractType* NewTypeParameter(const Class& parameterized_class,
852 intptr_t index,
852 const String& name, 853 const String& name,
853 intptr_t token_index); 854 intptr_t token_index);
854 855
855 static RawAbstractType* NewInstantiatedType( 856 static RawAbstractType* NewInstantiatedType(
856 const AbstractType& uninstantiated_type, 857 const AbstractType& uninstantiated_type,
857 const AbstractTypeArguments& instantiator_type_arguments); 858 const AbstractTypeArguments& instantiator_type_arguments);
858 859
859 protected: 860 protected:
860 HEAP_OBJECT_IMPLEMENTATION(AbstractType, Object); 861 HEAP_OBJECT_IMPLEMENTATION(AbstractType, Object);
861 friend class Class; 862 friend class Class;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 void set_token_index(intptr_t token_index) const; 944 void set_token_index(intptr_t token_index) const;
944 void set_type_state(int8_t state) const; 945 void set_type_state(int8_t state) const;
945 946
946 static RawType* New(); 947 static RawType* New();
947 948
948 HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); 949 HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType);
949 friend class Class; 950 friend class Class;
950 }; 951 };
951 952
952 953
953 // A TypeParameter, in the context of a parameterized class, references a type 954 // A TypeParameter represents a type parameter of a parameterized class.
954 // parameter of a class by its index (and by its name for debugging purposes). 955 // It specifies its index (and its name for debugging purposes).
955 // For example, the type parameter 'V' is specified as index 1 in the context of 956 // For example, the type parameter 'V' is specified as index 1 in the context of
956 // the class HashMap<K, V>. At compile time, the TypeParameter is not 957 // the class HashMap<K, V>. At compile time, the TypeParameter is not
957 // instantiated yet, i.e. it is only a place holder. 958 // instantiated yet, i.e. it is only a place holder.
958 // Upon finalization, the TypeParameter index is changed to reflect its position 959 // Upon finalization, the TypeParameter index is changed to reflect its position
959 // as type argument (rather than type parameter) of the enclosing class. 960 // as type argument (rather than type parameter) of the parameterized class.
960 class TypeParameter : public AbstractType { 961 class TypeParameter : public AbstractType {
961 public: 962 public:
962 virtual bool IsFinalized() const { 963 virtual bool IsFinalized() const {
963 return raw_ptr()->type_state_ == RawTypeParameter::kFinalized; 964 return raw_ptr()->type_state_ == RawTypeParameter::kFinalized;
964 } 965 }
965 void set_is_finalized() const; 966 void set_is_finalized() const;
966 virtual bool IsBeingFinalized() const { return false; } 967 virtual bool IsBeingFinalized() const { return false; }
967 virtual bool IsMalformed() const { return false; } 968 virtual bool IsMalformed() const { return false; }
968 virtual bool IsResolved() const { return true; } 969 virtual bool IsResolved() const { return true; }
969 virtual bool HasResolvedTypeClass() const { return false; } 970 virtual bool HasResolvedTypeClass() const { return false; }
971 RawClass* parameterized_class() const {
972 return raw_ptr()->parameterized_class_;
973 }
970 virtual RawString* Name() const { return raw_ptr()->name_; } 974 virtual RawString* Name() const { return raw_ptr()->name_; }
971 virtual intptr_t Index() const { return raw_ptr()->index_; } 975 virtual intptr_t Index() const { return raw_ptr()->index_; }
972 void set_index(intptr_t value) const; 976 void set_index(intptr_t value) const;
973 virtual intptr_t token_index() const { return raw_ptr()->token_index_; } 977 virtual intptr_t token_index() const { return raw_ptr()->token_index_; }
974 virtual bool IsInstantiated() const { return false; } 978 virtual bool IsInstantiated() const { return false; }
975 virtual bool Equals(const AbstractType& other) const; 979 virtual bool Equals(const AbstractType& other) const;
976 virtual RawAbstractType* InstantiateFrom( 980 virtual RawAbstractType* InstantiateFrom(
977 const AbstractTypeArguments& instantiator_type_arguments) const; 981 const AbstractTypeArguments& instantiator_type_arguments) const;
978 virtual RawAbstractType* Canonicalize() const { return raw(); } 982 virtual RawAbstractType* Canonicalize() const { return raw(); }
979 983
980 static intptr_t InstanceSize() { 984 static intptr_t InstanceSize() {
981 return RoundedAllocationSize(sizeof(RawTypeParameter)); 985 return RoundedAllocationSize(sizeof(RawTypeParameter));
982 } 986 }
983 987
984 static RawTypeParameter* New(intptr_t index, 988 static RawTypeParameter* New(const Class& parameterized_class,
989 intptr_t index,
985 const String& name, 990 const String& name,
986 intptr_t token_index); 991 intptr_t token_index);
987 992
988 private: 993 private:
994 void set_parameterized_class(const Class& value) const;
989 void set_name(const String& value) const; 995 void set_name(const String& value) const;
990 void set_token_index(intptr_t token_index) const; 996 void set_token_index(intptr_t token_index) const;
991 void set_type_state(int8_t state) const; 997 void set_type_state(int8_t state) const;
992 static RawTypeParameter* New(); 998 static RawTypeParameter* New();
993 999
994 HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); 1000 HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType);
995 friend class Class; 1001 friend class Class;
996 }; 1002 };
997 1003
998 1004
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 1046
1041 HEAP_OBJECT_IMPLEMENTATION(InstantiatedType, AbstractType); 1047 HEAP_OBJECT_IMPLEMENTATION(InstantiatedType, AbstractType);
1042 friend class Class; 1048 friend class Class;
1043 }; 1049 };
1044 1050
1045 1051
1046 // AbstractTypeArguments is an abstract superclass. 1052 // AbstractTypeArguments is an abstract superclass.
1047 // Subclasses of AbstractTypeArguments are TypeArguments and InstantiatedTypes. 1053 // Subclasses of AbstractTypeArguments are TypeArguments and InstantiatedTypes.
1048 class AbstractTypeArguments : public Object { 1054 class AbstractTypeArguments : public Object {
1049 public: 1055 public:
1056 // Returns true if both arguments represent vectors of equal types.
1050 static bool AreEqual(const AbstractTypeArguments& arguments, 1057 static bool AreEqual(const AbstractTypeArguments& arguments,
1051 const AbstractTypeArguments& other_arguments); 1058 const AbstractTypeArguments& other_arguments);
1052 1059
1053 // Return 'this' if this type argument vector is instantiated, i.e. if it does 1060 // Return 'this' if this type argument vector is instantiated, i.e. if it does
1054 // not refer to type parameters. Otherwise, return a new type argument vector 1061 // not refer to type parameters. Otherwise, return a new type argument vector
1055 // where each reference to a type parameter is replaced with the corresponding 1062 // where each reference to a type parameter is replaced with the corresponding
1056 // type of the instantiator type argument vector. 1063 // type of the instantiator type argument vector.
1057 virtual RawAbstractTypeArguments* InstantiateFrom( 1064 virtual RawAbstractTypeArguments* InstantiateFrom(
1058 const AbstractTypeArguments& instantiator_type_arguments) const; 1065 const AbstractTypeArguments& instantiator_type_arguments) const;
1059 1066
1060 // Do not canonicalize InstantiatedTypeArguments or NULL objects 1067 // Do not canonicalize InstantiatedTypeArguments or NULL objects
1061 virtual RawAbstractTypeArguments* Canonicalize() const { return this->raw(); } 1068 virtual RawAbstractTypeArguments* Canonicalize() const { return this->raw(); }
1062 1069
1070 // The name of this type argument vector, e.g. "<T, Dynamic, List<T>, int>".
1071 virtual RawString* Name() const {
1072 return SubvectorName(0, Length());
1073 }
1074
1075 // The name of a subvector of this type argument vector, e.g. "<T, Dynamic>".
1076 virtual RawString* SubvectorName(intptr_t from_index, intptr_t len) const;
1077
1063 // Check if this type argument vector consists solely of DynamicType, 1078 // Check if this type argument vector consists solely of DynamicType,
1064 // considering only a prefix of length 'len'. 1079 // considering only a prefix of length 'len'.
1065 bool IsDynamicTypes(intptr_t len) const; 1080 bool IsRaw(intptr_t len) const {
1081 return IsDynamicTypes(false, len);
1082 }
1083
1084 // Check if this type argument vector would consist solely of DynamicType if
1085 // it was instantiated from a raw (null) instantiator, i.e. consider each type
1086 // parameter as it would be first instantiated from a vector of dynamic types.
1087 // Consider only a prefix of length 'len'.
1088 bool IsRawInstantiatedRaw(intptr_t len) const {
1089 return IsDynamicTypes(true, len);
1090 }
1066 1091
1067 // Check that this type argument vector is within the declared bounds of the 1092 // Check that this type argument vector is within the declared bounds of the
1068 // given class or interface. If not, set malformed_error (if not yet set). 1093 // given class or interface. If not, set malformed_error (if not yet set).
1069 bool IsWithinBoundsOf(const Class& cls, 1094 bool IsWithinBoundsOf(const Class& cls,
1070 const AbstractTypeArguments& bounds_instantiator, 1095 const AbstractTypeArguments& bounds_instantiator,
1071 Error* malformed_error) const; 1096 Error* malformed_error) const;
1072 1097
1073 // Check the subtype relationship, considering only a prefix of length 'len'. 1098 // Check the subtype relationship, considering only a prefix of length 'len'.
1074 bool IsSubtypeOf(const AbstractTypeArguments& other, 1099 bool IsSubtypeOf(const AbstractTypeArguments& other,
1075 intptr_t len, 1100 intptr_t len,
1076 Error* malformed_error) const; 1101 Error* malformed_error) const;
1077 1102
1078 bool Equals(const AbstractTypeArguments& other) const; 1103 bool Equals(const AbstractTypeArguments& other) const;
1079 1104
1080 // UNREACHABLEs as AbstractTypeArguments is an abstract class. 1105 // UNREACHABLEs as AbstractTypeArguments is an abstract class.
1081 virtual intptr_t Length() const; 1106 virtual intptr_t Length() const;
1082 virtual RawAbstractType* TypeAt(intptr_t index) const; 1107 virtual RawAbstractType* TypeAt(intptr_t index) const;
1083 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const; 1108 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const;
1084 virtual bool IsResolved() const; 1109 virtual bool IsResolved() const;
1085 virtual bool IsInstantiated() const; 1110 virtual bool IsInstantiated() const;
1086 virtual bool IsUninstantiatedIdentity() const; 1111 virtual bool IsUninstantiatedIdentity() const;
1087 1112
1113 private:
1114 // Check if this type argument vector consists solely of DynamicType,
1115 // considering only a prefix of length 'len'.
1116 // If raw_instantiated is true, consider each type parameter to be first
1117 // instantiated from a vector of dynamic types.
1118 bool IsDynamicTypes(bool raw_instantiated, intptr_t len) const;
1119
1088 protected: 1120 protected:
1089 HEAP_OBJECT_IMPLEMENTATION(AbstractTypeArguments, Object); 1121 HEAP_OBJECT_IMPLEMENTATION(AbstractTypeArguments, Object);
1090 friend class Class; 1122 friend class Class;
1091 }; 1123 };
1092 1124
1093 1125
1094 // A TypeArguments is an array of AbstractType. 1126 // A TypeArguments is an array of AbstractType.
1095 class TypeArguments : public AbstractTypeArguments { 1127 class TypeArguments : public AbstractTypeArguments {
1096 public: 1128 public:
1129 // Returns true if both arguments represent identical vectors of type
1130 // parameters, in number and names (but the type class may be different).
1131 static bool AreIdenticalTypeParameters(const TypeArguments& arguments,
1132 const TypeArguments& other_arguments);
1133
1097 virtual intptr_t Length() const; 1134 virtual intptr_t Length() const;
1098 virtual RawAbstractType* TypeAt(intptr_t index) const; 1135 virtual RawAbstractType* TypeAt(intptr_t index) const;
1099 static intptr_t type_at_offset(intptr_t index) { 1136 static intptr_t type_at_offset(intptr_t index) {
1100 return OFFSET_OF(RawTypeArguments, types_) + index * kWordSize; 1137 return OFFSET_OF(RawTypeArguments, types_) + index * kWordSize;
1101 } 1138 }
1102 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const; 1139 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const;
1103 virtual bool IsResolved() const; 1140 virtual bool IsResolved() const;
1104 virtual bool IsInstantiated() const; 1141 virtual bool IsInstantiated() const;
1105 virtual bool IsUninstantiatedIdentity() const; 1142 virtual bool IsUninstantiatedIdentity() const;
1106 // Canonicalize only if instantiated, otherwise returns 'this'. 1143 // Canonicalize only if instantiated, otherwise returns 'this'.
(...skipping 2807 matching lines...) Expand 10 before | Expand all | Expand 10 after
3914 } 3951 }
3915 3952
3916 3953
3917 intptr_t Stackmap::SizeInBits() const { 3954 intptr_t Stackmap::SizeInBits() const {
3918 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); 3955 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte);
3919 } 3956 }
3920 3957
3921 } // namespace dart 3958 } // namespace dart
3922 3959
3923 #endif // VM_OBJECT_H_ 3960 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_compiler_x64.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698