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

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

Issue 8437028: Perform type canonicalization as part of type finalization. (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/class_finalizer.cc ('k') | runtime/vm/raw_object.h » ('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 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/assert.h" 8 #include "vm/assert.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 if (raw_ptr()->name_ != String::null()) { 706 if (raw_ptr()->name_ != String::null()) {
707 return raw_ptr()->name_; 707 return raw_ptr()->name_;
708 } 708 }
709 ASSERT(class_class() != null_); // Or GetSingletonClassIndex will not work. 709 ASSERT(class_class() != null_); // Or GetSingletonClassIndex will not work.
710 intptr_t index = GetSingletonClassIndex(raw()); 710 intptr_t index = GetSingletonClassIndex(raw());
711 return String::NewSymbol(GetSingletonClassName(index)); 711 return String::NewSymbol(GetSingletonClassName(index));
712 } 712 }
713 713
714 714
715 RawType* Class::SignatureType() const { 715 RawType* Class::SignatureType() const {
716 // Return the cached signature type if any. 716 // Return the only canonical signature type if already computed.
717 if (raw_ptr()->signature_type_ != Type::null()) { 717 const Array& signature_types = Array::Handle(canonical_types());
718 return raw_ptr()->signature_type_; 718 if (signature_types.Length() > 0) {
719 Type& signature_type = Type::Handle();
720 signature_type ^= signature_types.At(0);
721 if (!signature_type.IsNull()) {
722 // A signature class has a unique canonical signature type.
723 ASSERT((signature_types.Length() == 1) ||
724 signature_types.At(1) == Object::null());
725 return signature_type.raw();
726 }
719 } 727 }
720 ASSERT(IsSignatureClass()); 728 ASSERT(IsSignatureClass());
721 TypeArguments& signature_type_arguments = TypeArguments::Handle(); 729 TypeArguments& signature_type_arguments = TypeArguments::Handle();
722 const intptr_t num_type_params = NumTypeParameters(); 730 const intptr_t num_type_params = NumTypeParameters();
723 // If the signature class extends a parameterized class, the type arguments of 731 // If the signature class extends a parameterized class, the type arguments of
724 // the super class will be prepended to the type argument vector during type 732 // the super class will be prepended to the type argument vector during type
725 // finalization. We only need to provide the type parameters of the signature 733 // finalization. We only need to provide the type parameters of the signature
726 // class here. 734 // class here.
727 if (num_type_params > 0) { 735 if (num_type_params > 0) {
728 const Array& type_params = Array::Handle(type_parameters()); 736 const Array& type_params = Array::Handle(type_parameters());
729 signature_type_arguments = TypeArguments::NewTypeArray(num_type_params); 737 signature_type_arguments = TypeArguments::NewTypeArray(num_type_params);
730 String& type_param_name = String::Handle(); 738 String& type_param_name = String::Handle();
731 Type& type_param = Type::Handle(); 739 Type& type_param = Type::Handle();
732 for (int i = 0; i < num_type_params; i++) { 740 for (int i = 0; i < num_type_params; i++) {
733 type_param_name ^= type_params.At(i); 741 type_param_name ^= type_params.At(i);
734 type_param = Type::NewTypeParameter(i, type_param_name); 742 type_param = Type::NewTypeParameter(i, type_param_name);
735 signature_type_arguments.SetTypeAt(i, type_param); 743 signature_type_arguments.SetTypeAt(i, type_param);
736 } 744 }
737 } 745 }
738 const ParameterizedType& signature_type = ParameterizedType::Handle( 746 const ParameterizedType& signature_type = ParameterizedType::Handle(
739 ParameterizedType::New(*this, signature_type_arguments)); 747 ParameterizedType::New(*this, signature_type_arguments));
740 748
741 // Cache and return the still unfinalized signature type. 749 // Return the still unfinalized signature type.
742 ASSERT(!signature_type.IsFinalized()); 750 ASSERT(!signature_type.IsFinalized());
743 set_signature_type(signature_type);
744 return signature_type.raw(); 751 return signature_type.raw();
745 } 752 }
746 753
747 754
748 template <class FakeObject> 755 template <class FakeObject>
749 RawClass* Class::New() { 756 RawClass* Class::New() {
750 Class& class_class = Class::Handle(Object::class_class()); 757 Class& class_class = Class::Handle(Object::class_class());
751 Class& result = Class::Handle(); 758 Class& result = Class::Handle();
752 { 759 {
753 RawObject* raw = Object::Allocate(class_class, 760 RawObject* raw = Object::Allocate(class_class,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 StorePointer(&raw_ptr()->functions_, value.raw()); 815 StorePointer(&raw_ptr()->functions_, value.raw());
809 } 816 }
810 817
811 818
812 void Class::set_signature_function(const Function& value) const { 819 void Class::set_signature_function(const Function& value) const {
813 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); 820 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction());
814 StorePointer(&raw_ptr()->signature_function_, value.raw()); 821 StorePointer(&raw_ptr()->signature_function_, value.raw());
815 } 822 }
816 823
817 824
818 void Class::set_signature_type(const Type& value) const {
819 StorePointer(&raw_ptr()->signature_type_, value.raw());
820 }
821
822
823 void Class::set_class_state(int8_t state) const { 825 void Class::set_class_state(int8_t state) const {
824 ASSERT(state == RawClass::kAllocated || 826 ASSERT(state == RawClass::kAllocated ||
825 state == RawClass::kPreFinalized || 827 state == RawClass::kPreFinalized ||
826 state == RawClass::kFinalized); 828 state == RawClass::kFinalized);
827 raw_ptr()->class_state_ = state; 829 raw_ptr()->class_state_ = state;
828 } 830 }
829 831
830 832
831 void Class::set_library(const Library& value) const { 833 void Class::set_library(const Library& value) const {
832 StorePointer(&raw_ptr()->library_, value.raw()); 834 StorePointer(&raw_ptr()->library_, value.raw());
(...skipping 6106 matching lines...) Expand 10 before | Expand all | Expand 10 after
6939 const String& str = String::Handle(pattern()); 6941 const String& str = String::Handle(pattern());
6940 const char* format = "JSRegExp: pattern=%s flags=%s"; 6942 const char* format = "JSRegExp: pattern=%s flags=%s";
6941 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 6943 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
6942 char* chars = reinterpret_cast<char*>( 6944 char* chars = reinterpret_cast<char*>(
6943 Isolate::Current()->current_zone()->Allocate(len + 1)); 6945 Isolate::Current()->current_zone()->Allocate(len + 1));
6944 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 6946 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
6945 return chars; 6947 return chars;
6946 } 6948 }
6947 6949
6948 } // namespace dart 6950 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698