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

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

Issue 10696013: Consider upper bounds of type parameters in type checks. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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
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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 // Return the signature type of this signature class. 497 // Return the signature type of this signature class.
498 // For example, if this class represents a signature of the form 498 // For example, if this class represents a signature of the form
499 // '<T, R>(T, [b: B, c: C]) => R', then its signature type is a parameterized 499 // '<T, R>(T, [b: B, c: C]) => R', then its signature type is a parameterized
500 // type with this class as the type class and type parameters 'T' and 'R' 500 // type with this class as the type class and type parameters 'T' and 'R'
501 // as its type argument vector. 501 // as its type argument vector.
502 RawType* SignatureType() const; 502 RawType* SignatureType() const;
503 503
504 RawLibrary* library() const { return raw_ptr()->library_; } 504 RawLibrary* library() const { return raw_ptr()->library_; }
505 void set_library(const Library& value) const; 505 void set_library(const Library& value) const;
506 506
507 // The type parameters are specified as an array of TypeParameter. 507 // The type parameters (and their bounds) are specified as an array of
508 // TypeParameter.
508 RawTypeArguments* type_parameters() const { 509 RawTypeArguments* type_parameters() const {
509 return raw_ptr()->type_parameters_; 510 return raw_ptr()->type_parameters_;
510 } 511 }
511 void set_type_parameters(const TypeArguments& value) const; 512 void set_type_parameters(const TypeArguments& value) const;
512 intptr_t NumTypeParameters() const; 513 intptr_t NumTypeParameters() const;
513 static intptr_t type_parameters_offset() { 514 static intptr_t type_parameters_offset() {
514 return OFFSET_OF(RawClass, type_parameters_); 515 return OFFSET_OF(RawClass, type_parameters_);
515 } 516 }
516 517
517 // Type parameter bounds (implicitly Dynamic if not explicitly specified) as
518 // an array of AbstractType.
519 RawTypeArguments* type_parameter_bounds() const {
520 return raw_ptr()->type_parameter_bounds_;
521 }
522 void set_type_parameter_bounds(const TypeArguments& value) const;
523
524 // Return a TypeParameter if the type_name is a type parameter of this class. 518 // Return a TypeParameter if the type_name is a type parameter of this class.
525 // Return null otherwise. 519 // Return null otherwise.
526 RawTypeParameter* LookupTypeParameter(const String& type_name, 520 RawTypeParameter* LookupTypeParameter(const String& type_name,
527 intptr_t token_pos) const; 521 intptr_t token_pos) const;
528 522
529 // The type argument vector is flattened and includes the type arguments of 523 // The type argument vector is flattened and includes the type arguments of
530 // the super class. 524 // the super class.
531 bool HasTypeArguments() const; 525 bool HasTypeArguments() const;
532 intptr_t NumTypeArguments() const; 526 intptr_t NumTypeArguments() const;
533 527
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 virtual RawError* malformed_error() const; 818 virtual RawError* malformed_error() const;
825 virtual void set_malformed_error(const Error& value) const; 819 virtual void set_malformed_error(const Error& value) const;
826 virtual bool IsResolved() const; 820 virtual bool IsResolved() const;
827 virtual bool HasResolvedTypeClass() const; 821 virtual bool HasResolvedTypeClass() const;
828 virtual RawClass* type_class() const; 822 virtual RawClass* type_class() const;
829 virtual RawUnresolvedClass* unresolved_class() const; 823 virtual RawUnresolvedClass* unresolved_class() const;
830 virtual RawAbstractTypeArguments* arguments() const; 824 virtual RawAbstractTypeArguments* arguments() const;
831 virtual intptr_t token_pos() const; 825 virtual intptr_t token_pos() const;
832 virtual bool IsInstantiated() const; 826 virtual bool IsInstantiated() const;
833 virtual bool Equals(const AbstractType& other) const; 827 virtual bool Equals(const AbstractType& other) const;
834 virtual bool IsIdentical(const AbstractType& other) const; 828 virtual bool IsIdentical(const AbstractType& other,
829 bool check_type_parameter_bound) const;
835 830
836 // Instantiate this type using the given type argument vector. 831 // Instantiate this type using the given type argument vector.
837 // Return a new type, or return 'this' if it is already instantiated. 832 // Return a new type, or return 'this' if it is already instantiated.
838 virtual RawAbstractType* InstantiateFrom( 833 virtual RawAbstractType* InstantiateFrom(
839 const AbstractTypeArguments& instantiator_type_arguments) const; 834 const AbstractTypeArguments& instantiator_type_arguments) const;
840 835
841 // Return the canonical version of this type. 836 // Return the canonical version of this type.
842 virtual RawAbstractType* Canonicalize() const; 837 virtual RawAbstractType* Canonicalize() const;
843 838
844 // The name of this type, including the names of its type arguments, if any. 839 // The name of this type, including the names of its type arguments, if any.
845 virtual RawString* Name() const; 840 virtual RawString* Name() const;
846 841
847 // The index of this type parameter. Fail if not a type parameter.
848 virtual intptr_t Index() const;
849
850 // The name of this type's class, i.e. without the type argument names of this 842 // The name of this type's class, i.e. without the type argument names of this
851 // type. 843 // type.
852 RawString* ClassName() const; 844 RawString* ClassName() const;
853 845
854 // Check if this type represents the 'Dynamic' type. 846 // Check if this type represents the 'Dynamic' type.
855 bool IsDynamicType() const { 847 bool IsDynamicType() const {
856 return HasResolvedTypeClass() && (type_class() == Object::dynamic_class()); 848 return HasResolvedTypeClass() && (type_class() == Object::dynamic_class());
857 } 849 }
858 850
859 // Check if this type represents the 'Null' type. 851 // Check if this type represents the 'Null' type.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 virtual bool HasResolvedTypeClass() const; // Own type class resolved. 947 virtual bool HasResolvedTypeClass() const; // Own type class resolved.
956 virtual RawClass* type_class() const; 948 virtual RawClass* type_class() const;
957 void set_type_class(const Object& value) const; 949 void set_type_class(const Object& value) const;
958 virtual RawUnresolvedClass* unresolved_class() const; 950 virtual RawUnresolvedClass* unresolved_class() const;
959 RawString* TypeClassName() const; 951 RawString* TypeClassName() const;
960 virtual RawAbstractTypeArguments* arguments() const; 952 virtual RawAbstractTypeArguments* arguments() const;
961 void set_arguments(const AbstractTypeArguments& value) const; 953 void set_arguments(const AbstractTypeArguments& value) const;
962 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } 954 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; }
963 virtual bool IsInstantiated() const; 955 virtual bool IsInstantiated() const;
964 virtual bool Equals(const AbstractType& other) const; 956 virtual bool Equals(const AbstractType& other) const;
965 virtual bool IsIdentical(const AbstractType& other) const; 957 virtual bool IsIdentical(const AbstractType& other,
958 bool check_type_parameter_bound) const;
966 virtual RawAbstractType* InstantiateFrom( 959 virtual RawAbstractType* InstantiateFrom(
967 const AbstractTypeArguments& instantiator_type_arguments) const; 960 const AbstractTypeArguments& instantiator_type_arguments) const;
968 virtual RawAbstractType* Canonicalize() const; 961 virtual RawAbstractType* Canonicalize() const;
969 962
970 static intptr_t InstanceSize() { 963 static intptr_t InstanceSize() {
971 return RoundedAllocationSize(sizeof(RawType)); 964 return RoundedAllocationSize(sizeof(RawType));
972 } 965 }
973 966
974 // The type of the literal 'null'. 967 // The type of the literal 'null'.
975 static RawType* NullType(); 968 static RawType* NullType();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 void set_type_state(int8_t state) const; 1009 void set_type_state(int8_t state) const;
1017 1010
1018 static RawType* New(); 1011 static RawType* New();
1019 1012
1020 HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType); 1013 HEAP_OBJECT_IMPLEMENTATION(Type, AbstractType);
1021 friend class Class; 1014 friend class Class;
1022 }; 1015 };
1023 1016
1024 1017
1025 // A TypeParameter represents a type parameter of a parameterized class. 1018 // A TypeParameter represents a type parameter of a parameterized class.
1026 // It specifies its index (and its name for debugging purposes). 1019 // It specifies its index (and its name for debugging purposes), as well as its
1020 // upper bound.
1027 // For example, the type parameter 'V' is specified as index 1 in the context of 1021 // For example, the type parameter 'V' is specified as index 1 in the context of
1028 // the class HashMap<K, V>. At compile time, the TypeParameter is not 1022 // the class HashMap<K, V>. At compile time, the TypeParameter is not
1029 // instantiated yet, i.e. it is only a place holder. 1023 // instantiated yet, i.e. it is only a place holder.
1030 // Upon finalization, the TypeParameter index is changed to reflect its position 1024 // Upon finalization, the TypeParameter index is changed to reflect its position
1031 // as type argument (rather than type parameter) of the parameterized class. 1025 // as type argument (rather than type parameter) of the parameterized class.
1026 // If the type parameter is declared without an extends clause, its bound is set
1027 // to the DynamicType.
1032 class TypeParameter : public AbstractType { 1028 class TypeParameter : public AbstractType {
1033 public: 1029 public:
1034 virtual bool IsFinalized() const { 1030 virtual bool IsFinalized() const {
1035 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated); 1031 ASSERT(raw_ptr()->type_state_ != RawTypeParameter::kFinalizedInstantiated);
1036 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated; 1032 return raw_ptr()->type_state_ == RawTypeParameter::kFinalizedUninstantiated;
1037 } 1033 }
1038 void set_is_finalized() const; 1034 void set_is_finalized() const;
1039 virtual bool IsBeingFinalized() const { return false; } 1035 virtual bool IsBeingFinalized() const { return false; }
1040 virtual bool IsMalformed() const { return false; } 1036 virtual bool IsMalformed() const { return false; }
1041 virtual bool IsResolved() const { return true; } 1037 virtual bool IsResolved() const { return true; }
1042 virtual bool HasResolvedTypeClass() const { return false; } 1038 virtual bool HasResolvedTypeClass() const { return false; }
1043 RawClass* parameterized_class() const { 1039 RawClass* parameterized_class() const {
1044 return raw_ptr()->parameterized_class_; 1040 return raw_ptr()->parameterized_class_;
1045 } 1041 }
1046 virtual RawString* Name() const { return raw_ptr()->name_; } 1042 virtual RawString* Name() const { return raw_ptr()->name_; }
1047 virtual intptr_t Index() const { return raw_ptr()->index_; } 1043 intptr_t index() const { return raw_ptr()->index_; }
1048 void set_index(intptr_t value) const; 1044 void set_index(intptr_t value) const;
1045 RawAbstractType* bound() const { return raw_ptr()->bound_; }
1046 void set_bound(const AbstractType& value) const;
1049 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; } 1047 virtual intptr_t token_pos() const { return raw_ptr()->token_pos_; }
1050 virtual bool IsInstantiated() const { return false; } 1048 virtual bool IsInstantiated() const { return false; }
1051 virtual bool Equals(const AbstractType& other) const; 1049 virtual bool Equals(const AbstractType& other) const;
1052 virtual bool IsIdentical(const AbstractType& other) const; 1050 virtual bool IsIdentical(const AbstractType& other,
1051 bool check_type_parameter_bound) const;
1053 virtual RawAbstractType* InstantiateFrom( 1052 virtual RawAbstractType* InstantiateFrom(
1054 const AbstractTypeArguments& instantiator_type_arguments) const; 1053 const AbstractTypeArguments& instantiator_type_arguments) const;
1055 virtual RawAbstractType* Canonicalize() const { return raw(); } 1054 virtual RawAbstractType* Canonicalize() const { return raw(); }
1056 1055
1057 static intptr_t InstanceSize() { 1056 static intptr_t InstanceSize() {
1058 return RoundedAllocationSize(sizeof(RawTypeParameter)); 1057 return RoundedAllocationSize(sizeof(RawTypeParameter));
1059 } 1058 }
1060 1059
1061 static RawTypeParameter* New(const Class& parameterized_class, 1060 static RawTypeParameter* New(const Class& parameterized_class,
1062 intptr_t index, 1061 intptr_t index,
1063 const String& name, 1062 const String& name,
1063 const AbstractType& bound,
1064 intptr_t token_pos); 1064 intptr_t token_pos);
1065 1065
1066 private: 1066 private:
1067 void set_parameterized_class(const Class& value) const; 1067 void set_parameterized_class(const Class& value) const;
1068 void set_name(const String& value) const; 1068 void set_name(const String& value) const;
1069 void set_token_pos(intptr_t token_pos) const; 1069 void set_token_pos(intptr_t token_pos) const;
1070 void set_type_state(int8_t state) const; 1070 void set_type_state(int8_t state) const;
1071 static RawTypeParameter* New(); 1071 static RawTypeParameter* New();
1072 1072
1073 HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType); 1073 HEAP_OBJECT_IMPLEMENTATION(TypeParameter, AbstractType);
1074 friend class Class; 1074 friend class Class;
1075 }; 1075 };
1076 1076
1077 1077
1078 // AbstractTypeArguments is an abstract superclass. 1078 // AbstractTypeArguments is an abstract superclass.
1079 // Subclasses of AbstractTypeArguments are TypeArguments and 1079 // Subclasses of AbstractTypeArguments are TypeArguments and
1080 // InstantiatedTypeArguments. 1080 // InstantiatedTypeArguments.
1081 class AbstractTypeArguments : public Object { 1081 class AbstractTypeArguments : public Object {
1082 public: 1082 public:
1083 // Returns true if both arguments represent vectors of equal types. 1083 // Returns true if both arguments represent vectors of equal types.
1084 static bool AreEqual(const AbstractTypeArguments& arguments, 1084 static bool AreEqual(const AbstractTypeArguments& arguments,
1085 const AbstractTypeArguments& other_arguments); 1085 const AbstractTypeArguments& other_arguments);
1086 1086
1087 // Returns true if both arguments represent vectors of possibly still 1087 // Returns true if both arguments represent vectors of possibly still
1088 // unresolved identical types. 1088 // unresolved identical types.
1089 static bool AreIdentical(const AbstractTypeArguments& arguments, 1089 static bool AreIdentical(const AbstractTypeArguments& arguments,
1090 const AbstractTypeArguments& other_arguments); 1090 const AbstractTypeArguments& other_arguments,
1091 bool check_type_parameter_bounds);
1091 1092
1092 // Return 'this' if this type argument vector is instantiated, i.e. if it does 1093 // Return 'this' if this type argument vector is instantiated, i.e. if it does
1093 // not refer to type parameters. Otherwise, return a new type argument vector 1094 // not refer to type parameters. Otherwise, return a new type argument vector
1094 // where each reference to a type parameter is replaced with the corresponding 1095 // where each reference to a type parameter is replaced with the corresponding
1095 // type of the instantiator type argument vector. 1096 // type of the instantiator type argument vector.
1096 virtual RawAbstractTypeArguments* InstantiateFrom( 1097 virtual RawAbstractTypeArguments* InstantiateFrom(
1097 const AbstractTypeArguments& instantiator_type_arguments) const; 1098 const AbstractTypeArguments& instantiator_type_arguments) const;
1098 1099
1099 // Do not canonicalize InstantiatedTypeArguments or NULL objects 1100 // Do not canonicalize InstantiatedTypeArguments or NULL objects
1100 virtual RawAbstractTypeArguments* Canonicalize() const { return this->raw(); } 1101 virtual RawAbstractTypeArguments* Canonicalize() const { return this->raw(); }
(...skipping 3985 matching lines...) Expand 10 before | Expand all | Expand 10 after
5086 } 5087 }
5087 5088
5088 5089
5089 intptr_t Stackmap::SizeInBits() const { 5090 intptr_t Stackmap::SizeInBits() const {
5090 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); 5091 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte);
5091 } 5092 }
5092 5093
5093 } // namespace dart 5094 } // namespace dart
5094 5095
5095 #endif // VM_OBJECT_H_ 5096 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698