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

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

Issue 8372041: Canonicalize types. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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/code_generator_ia32.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) 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 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 void set_signature_function(const Function& value) const; 607 void set_signature_function(const Function& value) const;
608 void set_signature_type(const Type& value) const; 608 void set_signature_type(const Type& value) const;
609 void set_class_state(int8_t state) const; 609 void set_class_state(int8_t state) const;
610 610
611 void set_constants(const Array& value) const; 611 void set_constants(const Array& value) const;
612 RawArray* constants() const; 612 RawArray* constants() const;
613 613
614 void set_num_constants(intptr_t value) const; 614 void set_num_constants(intptr_t value) const;
615 intptr_t num_constants() const; 615 intptr_t num_constants() const;
616 616
617 void set_canonical_types(const Array& value) const;
618 RawArray* canonical_types() const;
619
620 void set_num_canonical_types(intptr_t value) const;
621 intptr_t num_canonical_types() const;
622
617 void CalculateFieldOffsets() const; 623 void CalculateFieldOffsets() const;
618 624
619 // Check the subtype or assignability relationship. 625 // Check the subtype or assignability relationship.
620 bool TestType(TypeTestKind test, 626 bool TestType(TypeTestKind test,
621 const TypeArguments& type_arguments, 627 const TypeArguments& type_arguments,
622 const Class& other, 628 const Class& other,
623 const TypeArguments& other_type_arguments) const; 629 const TypeArguments& other_type_arguments) const;
624 630
625 // Assigns empty array to all raw class array fields. 631 // Assigns empty array to all raw class array fields.
626 void InitEmptyFields(); 632 void InitEmptyFields();
627 633
628 HEAP_OBJECT_IMPLEMENTATION(Class, Object); 634 HEAP_OBJECT_IMPLEMENTATION(Class, Object);
629 friend class Object; 635 friend class Object;
630 friend class Instance; 636 friend class Instance;
637 friend class ParameterizedType;
631 }; 638 };
632 639
633 640
634 // Unresolved class is used for storing unresolved names which will be resolved 641 // Unresolved class is used for storing unresolved names which will be resolved
635 // to a class after all classes have been loaded and finalized. 642 // to a class after all classes have been loaded and finalized.
636 class UnresolvedClass : public Object { 643 class UnresolvedClass : public Object {
637 public: 644 public:
638 RawString* qualifier() const { return raw_ptr()->qualifier_; } 645 RawString* qualifier() const { return raw_ptr()->qualifier_; }
639 RawString* ident() const { return raw_ptr()->ident_; } 646 RawString* ident() const { return raw_ptr()->ident_; }
640 intptr_t token_index() const { return raw_ptr()->token_index_; } 647 intptr_t token_index() const { return raw_ptr()->token_index_; }
(...skipping 29 matching lines...) Expand all
670 class Type : public Object { 677 class Type : public Object {
671 public: 678 public:
672 virtual bool IsFinalized() const; 679 virtual bool IsFinalized() const;
673 virtual bool IsBeingFinalized() const; 680 virtual bool IsBeingFinalized() const;
674 virtual bool IsResolved() const; 681 virtual bool IsResolved() const;
675 virtual bool HasResolvedTypeClass() const; 682 virtual bool HasResolvedTypeClass() const;
676 virtual RawClass* type_class() const; 683 virtual RawClass* type_class() const;
677 virtual RawUnresolvedClass* unresolved_class() const; 684 virtual RawUnresolvedClass* unresolved_class() const;
678 virtual RawTypeArguments* arguments() const; 685 virtual RawTypeArguments* arguments() const;
679 virtual bool IsInstantiated() const; 686 virtual bool IsInstantiated() const;
687 virtual bool Equals(const Type& other) const;
680 688
681 // Instantiate this type using the given type argument vector starting at the 689 // Instantiate this type using the given type argument vector starting at the
682 // given offset. 690 // given offset.
683 // Return a new type, or return 'this' if it is already instantiated. 691 // Return a new type, or return 'this' if it is already instantiated.
684 virtual RawType* InstantiateFrom( 692 virtual RawType* InstantiateFrom(
685 const TypeArguments& instantiator_type_arguments, 693 const TypeArguments& instantiator_type_arguments,
686 intptr_t offset) const; 694 intptr_t offset) const;
687 695
696 // Return the canonical version of this type.
697 virtual RawType* Canonicalize() const;
698
688 // The name of this type, including the names of its type arguments, if any. 699 // The name of this type, including the names of its type arguments, if any.
689 virtual RawString* Name() const; 700 virtual RawString* Name() const;
690 701
691 // The index of this type parameter. Fail if not a type parameter. 702 // The index of this type parameter. Fail if not a type parameter.
692 virtual intptr_t Index() const; 703 virtual intptr_t Index() const;
693 704
694 // The name of this type's class, i.e. without the type argument names of this 705 // The name of this type's class, i.e. without the type argument names of this
695 // type. 706 // type.
696 RawString* ClassName() const; 707 RawString* ClassName() const;
697 708
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 // The 'num' interface type. 785 // The 'num' interface type.
775 static RawType* NumberInterface(); 786 static RawType* NumberInterface();
776 787
777 // The 'String' interface type. 788 // The 'String' interface type.
778 static RawType* StringInterface(); 789 static RawType* StringInterface();
779 790
780 // The 'Function' interface type. 791 // The 'Function' interface type.
781 static RawType* FunctionInterface(); 792 static RawType* FunctionInterface();
782 793
783 // The least specific valid raw type of the given class. 794 // The least specific valid raw type of the given class.
784 // For example, type A<DynamicType> would be returned for class A<T>, and type 795 // For example, type A<Dynamic> would be returned for class A<T>, and type
785 // B<DynamicType, A<DynamicType>> would be returned for B<U, V extends A>. 796 // B<Dynamic, A<Dynamic>> would be returned for B<U, V extends A>.
786 static RawType* NewRawType(const Class& type_class); 797 static RawType* NewRawType(const Class& type_class);
787 798
788 // The finalized type of the given non-parameterized class. 799 // The finalized type of the given non-parameterized class.
789 static RawType* NewNonParameterizedType(const Class& type_class); 800 static RawType* NewNonParameterizedType(const Class& type_class);
790 801
791 static RawType* NewParameterizedType(const Object& type_class, 802 static RawType* NewParameterizedType(const Object& type_class,
792 const TypeArguments& arguments); 803 const TypeArguments& arguments);
793 804
794 static RawType* NewTypeParameter(intptr_t index, const String& name); 805 static RawType* NewTypeParameter(intptr_t index, const String& name);
795 806
(...skipping 24 matching lines...) Expand all
820 } 831 }
821 void set_is_being_finalized() const; 832 void set_is_being_finalized() const;
822 virtual bool IsResolved() const; // Class and all arguments classes resolved. 833 virtual bool IsResolved() const; // Class and all arguments classes resolved.
823 virtual bool HasResolvedTypeClass() const; // Own type class resolved. 834 virtual bool HasResolvedTypeClass() const; // Own type class resolved.
824 virtual RawClass* type_class() const; 835 virtual RawClass* type_class() const;
825 void set_type_class(const Object& value) const; 836 void set_type_class(const Object& value) const;
826 virtual RawUnresolvedClass* unresolved_class() const; 837 virtual RawUnresolvedClass* unresolved_class() const;
827 virtual RawTypeArguments* arguments() const; 838 virtual RawTypeArguments* arguments() const;
828 void set_arguments(const TypeArguments& value) const; 839 void set_arguments(const TypeArguments& value) const;
829 virtual bool IsInstantiated() const; 840 virtual bool IsInstantiated() const;
841 virtual bool Equals(const Type& other) const;
830 virtual RawType* InstantiateFrom( 842 virtual RawType* InstantiateFrom(
831 const TypeArguments& instantiator_type_arguments, 843 const TypeArguments& instantiator_type_arguments,
832 intptr_t offset) const; 844 intptr_t offset) const;
845 virtual RawType* Canonicalize() const;
833 846
834 static intptr_t InstanceSize() { 847 static intptr_t InstanceSize() {
835 return RoundedAllocationSize(sizeof(RawParameterizedType)); 848 return RoundedAllocationSize(sizeof(RawParameterizedType));
836 } 849 }
837 850
838 static RawParameterizedType* New(const Object& clazz, 851 static RawParameterizedType* New(const Object& clazz,
839 const TypeArguments& arguments); 852 const TypeArguments& arguments);
840 853
841 private: 854 private:
842 void set_type_state(int8_t state) const; 855 void set_type_state(int8_t state) const;
(...skipping 12 matching lines...) Expand all
855 // instantiated yet, i.e. it is only a place holder. 868 // instantiated yet, i.e. it is only a place holder.
856 class TypeParameter : public Type { 869 class TypeParameter : public Type {
857 public: 870 public:
858 virtual bool IsFinalized() const { return true; } 871 virtual bool IsFinalized() const { return true; }
859 virtual bool IsBeingFinalized() const { return false; } 872 virtual bool IsBeingFinalized() const { return false; }
860 virtual bool IsResolved() const { return true; } 873 virtual bool IsResolved() const { return true; }
861 virtual bool HasResolvedTypeClass() const { return false; } 874 virtual bool HasResolvedTypeClass() const { return false; }
862 virtual RawString* Name() const { return raw_ptr()->name_; } 875 virtual RawString* Name() const { return raw_ptr()->name_; }
863 virtual intptr_t Index() const { return raw_ptr()->index_; } 876 virtual intptr_t Index() const { return raw_ptr()->index_; }
864 virtual bool IsInstantiated() const { return false; } 877 virtual bool IsInstantiated() const { return false; }
878 virtual bool Equals(const Type& other) const;
865 virtual RawType* InstantiateFrom( 879 virtual RawType* InstantiateFrom(
866 const TypeArguments& instantiator_type_arguments, 880 const TypeArguments& instantiator_type_arguments,
867 intptr_t offset) const; 881 intptr_t offset) const;
882 virtual RawType* Canonicalize() const { return raw(); }
868 883
869 static intptr_t InstanceSize() { 884 static intptr_t InstanceSize() {
870 return RoundedAllocationSize(sizeof(RawTypeParameter)); 885 return RoundedAllocationSize(sizeof(RawTypeParameter));
871 } 886 }
872 887
873 static RawTypeParameter* New(intptr_t index, const String& name); 888 static RawTypeParameter* New(intptr_t index, const String& name);
874 889
875 private: 890 private:
876 void set_index(intptr_t value) const; 891 void set_index(intptr_t value) const;
877 void set_name(const String& value) const; 892 void set_name(const String& value) const;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 // TypeArguments is an abstract superclass. 944 // TypeArguments is an abstract superclass.
930 // Subclasses of TypeArguments are TypeArray and InstantiatedTypes. 945 // Subclasses of TypeArguments are TypeArray and InstantiatedTypes.
931 class TypeArguments : public Object { 946 class TypeArguments : public Object {
932 public: 947 public:
933 virtual intptr_t Length() const; 948 virtual intptr_t Length() const;
934 virtual RawType* TypeAt(intptr_t index) const; 949 virtual RawType* TypeAt(intptr_t index) const;
935 virtual void SetTypeAt(intptr_t index, const Type& value) const; 950 virtual void SetTypeAt(intptr_t index, const Type& value) const;
936 virtual bool IsResolved() const; 951 virtual bool IsResolved() const;
937 virtual bool IsInstantiated() const; 952 virtual bool IsInstantiated() const;
938 virtual bool IsUninstantiatedIdentity() const; 953 virtual bool IsUninstantiatedIdentity() const;
954 virtual bool Equals(const TypeArguments& other) const;
955 static bool AreEqual(const TypeArguments& arguments,
956 const TypeArguments& other_arguments);
939 957
940 // Return 'this' if this type argument vector is instantiated, i.e. if it does 958 // Return 'this' if this type argument vector is instantiated, i.e. if it does
941 // not refer to type parameters. Otherwise, return a new type argument vector 959 // not refer to type parameters. Otherwise, return a new type argument vector
942 // where each reference to a type parameter is replaced with the corresponding 960 // where each reference to a type parameter is replaced with the corresponding
943 // type of the instantiator type argument vector starting at the given offset. 961 // type of the instantiator type argument vector starting at the given offset.
944 virtual RawTypeArguments* InstantiateFrom( 962 virtual RawTypeArguments* InstantiateFrom(
945 const TypeArguments& instantiator_type_arguments, 963 const TypeArguments& instantiator_type_arguments,
946 intptr_t offset) const; 964 intptr_t offset) const;
947 965
948 // Check if this type argument vector consists solely of DynamicType, 966 // Check if this type argument vector consists solely of DynamicType,
(...skipping 18 matching lines...) Expand all
967 985
968 // A TypeArray is simply an array of Types. 986 // A TypeArray is simply an array of Types.
969 class TypeArray : public TypeArguments { 987 class TypeArray : public TypeArguments {
970 public: 988 public:
971 virtual intptr_t Length() const; 989 virtual intptr_t Length() const;
972 virtual RawType* TypeAt(intptr_t index) const; 990 virtual RawType* TypeAt(intptr_t index) const;
973 virtual void SetTypeAt(intptr_t index, const Type& value) const; 991 virtual void SetTypeAt(intptr_t index, const Type& value) const;
974 virtual bool IsResolved() const; 992 virtual bool IsResolved() const;
975 virtual bool IsInstantiated() const; 993 virtual bool IsInstantiated() const;
976 virtual bool IsUninstantiatedIdentity() const; 994 virtual bool IsUninstantiatedIdentity() const;
995 virtual bool Equals(const TypeArguments& other) const;
996
977 virtual RawTypeArguments* InstantiateFrom( 997 virtual RawTypeArguments* InstantiateFrom(
978 const TypeArguments& instantiator_type_arguments, 998 const TypeArguments& instantiator_type_arguments,
979 intptr_t offset) const; 999 intptr_t offset) const;
980 1000
981 static intptr_t length_offset() { return OFFSET_OF(RawTypeArray, length_); } 1001 static intptr_t length_offset() { return OFFSET_OF(RawTypeArray, length_); }
982 1002
983 static intptr_t InstanceSize() { 1003 static intptr_t InstanceSize() {
984 ASSERT(sizeof(RawTypeArray) == OFFSET_OF(RawTypeArray, types_)); 1004 ASSERT(sizeof(RawTypeArray) == OFFSET_OF(RawTypeArray, types_));
985 return 0; 1005 return 0;
986 } 1006 }
(...skipping 1982 matching lines...) Expand 10 before | Expand all | Expand 10 after
2969 } 2989 }
2970 2990
2971 2991
2972 void Context::SetAt(intptr_t index, const Instance& value) const { 2992 void Context::SetAt(intptr_t index, const Instance& value) const {
2973 StorePointer(InstanceAddr(index), value.raw()); 2993 StorePointer(InstanceAddr(index), value.raw());
2974 } 2994 }
2975 2995
2976 } // namespace dart 2996 } // namespace dart
2977 2997
2978 #endif // VM_OBJECT_H_ 2998 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/code_generator_ia32.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698