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

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

Issue 10368004: Properly set the element type of literal lists. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 2429 matching lines...) Expand 10 before | Expand all | Expand 10 after
2440 instantiated_type.set_is_finalized_instantiated(); 2440 instantiated_type.set_is_finalized_instantiated();
2441 return instantiated_type.raw(); 2441 return instantiated_type.raw();
2442 } 2442 }
2443 2443
2444 2444
2445 bool Type::Equals(const AbstractType& other) const { 2445 bool Type::Equals(const AbstractType& other) const {
2446 ASSERT(IsFinalized() && other.IsFinalized()); 2446 ASSERT(IsFinalized() && other.IsFinalized());
2447 if (raw() == other.raw()) { 2447 if (raw() == other.raw()) {
2448 return true; 2448 return true;
2449 } 2449 }
2450 if (IsMalformed() || !other.IsType() || other.IsMalformed()) { 2450 if (IsMalformed() || other.IsMalformed() ||
2451 (!other.IsType() && !other.IsInstantiatedType())) {
2451 return false; 2452 return false;
2452 } 2453 }
2453 Type& other_type = Type::Handle(); 2454 if (type_class() != other.type_class()) {
2454 other_type ^= other.raw();
2455 if (type_class() != other_type.type_class()) {
2456 return false; 2455 return false;
2457 } 2456 }
2458 return AbstractTypeArguments::AreEqual( 2457 return AbstractTypeArguments::AreEqual(
2459 AbstractTypeArguments::Handle(arguments()), 2458 AbstractTypeArguments::Handle(arguments()),
2460 AbstractTypeArguments::Handle(other.arguments())); 2459 AbstractTypeArguments::Handle(other.arguments()));
2461 } 2460 }
2462 2461
2463 2462
2464 bool Type::IsIdentical(const AbstractType& other) const { 2463 bool Type::IsIdentical(const AbstractType& other) const {
2465 if (raw() == other.raw()) { 2464 if (raw() == other.raw()) {
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2780 const AbstractType& uninstantiated_type, 2779 const AbstractType& uninstantiated_type,
2781 const AbstractTypeArguments& instantiator_type_arguments) { 2780 const AbstractTypeArguments& instantiator_type_arguments) {
2782 const InstantiatedType& result = 2781 const InstantiatedType& result =
2783 InstantiatedType::Handle(InstantiatedType::New()); 2782 InstantiatedType::Handle(InstantiatedType::New());
2784 result.set_uninstantiated_type(uninstantiated_type); 2783 result.set_uninstantiated_type(uninstantiated_type);
2785 result.set_instantiator_type_arguments(instantiator_type_arguments); 2784 result.set_instantiator_type_arguments(instantiator_type_arguments);
2786 return result.raw(); 2785 return result.raw();
2787 } 2786 }
2788 2787
2789 2788
2789 bool InstantiatedType::Equals(const AbstractType& other) const {
2790 ASSERT(IsFinalized() && other.IsFinalized());
2791 if (raw() == other.raw()) {
2792 return true;
2793 }
2794 if (IsMalformed() || other.IsMalformed() ||
2795 (!other.IsType() && !other.IsInstantiatedType())) {
2796 return false;
2797 }
2798 if (type_class() != other.type_class()) {
2799 return false;
2800 }
2801 return AbstractTypeArguments::AreEqual(
2802 AbstractTypeArguments::Handle(arguments()),
2803 AbstractTypeArguments::Handle(other.arguments()));
2804 }
2805
2806
2790 const char* InstantiatedType::ToCString() const { 2807 const char* InstantiatedType::ToCString() const {
2791 return "InstantiatedType"; 2808 return "InstantiatedType";
2792 } 2809 }
2793 2810
2794 2811
2795 intptr_t AbstractTypeArguments::Length() const { 2812 intptr_t AbstractTypeArguments::Length() const {
2796 // AbstractTypeArguments is an abstract class. 2813 // AbstractTypeArguments is an abstract class.
2797 UNREACHABLE(); 2814 UNREACHABLE();
2798 return -1; 2815 return -1;
2799 } 2816 }
(...skipping 5904 matching lines...) Expand 10 before | Expand all | Expand 10 after
8704 } 8721 }
8705 } 8722 }
8706 8723
8707 8724
8708 const char* Array::ToCString() const { 8725 const char* Array::ToCString() const {
8709 return "Array"; 8726 return "Array";
8710 } 8727 }
8711 8728
8712 8729
8713 RawArray* Array::Grow(const Array& source, int new_length, Heap::Space space) { 8730 RawArray* Array::Grow(const Array& source, int new_length, Heap::Space space) {
8714 intptr_t len = source.IsNull() ? 0 : source.Length(); 8731 const Array& result = Array::Handle(Array::New(new_length, space));
8732 intptr_t len = 0;
8733 if (!source.IsNull()) {
8734 len = source.Length();
8735 result.SetTypeArguments(
8736 AbstractTypeArguments::Handle(source.GetTypeArguments()));
8737 }
8715 ASSERT(new_length >= len); // Cannot copy 'source' into new array. 8738 ASSERT(new_length >= len); // Cannot copy 'source' into new array.
8716 ASSERT(new_length != len); // Unnecessary copying of array. 8739 ASSERT(new_length != len); // Unnecessary copying of array.
8717 const Array& result = Array::Handle(Array::New(new_length, space));
8718 Object& obj = Object::Handle(); 8740 Object& obj = Object::Handle();
8719 for (int i = 0; i < len; i++) { 8741 for (int i = 0; i < len; i++) {
8720 obj = source.At(i); 8742 obj = source.At(i);
8721 result.SetAt(i, obj); 8743 result.SetAt(i, obj);
8722 } 8744 }
8723 return result.raw(); 8745 return result.raw();
8724 } 8746 }
8725 8747
8726 8748
8727 RawArray* Array::Empty() { 8749 RawArray* Array::Empty() {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
8824 contents.SetAt(index, value); 8846 contents.SetAt(index, value);
8825 } 8847 }
8826 8848
8827 8849
8828 void GrowableObjectArray::Grow(intptr_t new_capacity, Heap::Space space) const { 8850 void GrowableObjectArray::Grow(intptr_t new_capacity, Heap::Space space) const {
8829 ASSERT(new_capacity > Capacity()); 8851 ASSERT(new_capacity > Capacity());
8830 const Array& contents = Array::Handle(data()); 8852 const Array& contents = Array::Handle(data());
8831 const Array& new_contents = 8853 const Array& new_contents =
8832 Array::Handle(Array::Grow(contents, new_capacity, space)); 8854 Array::Handle(Array::Grow(contents, new_capacity, space));
8833 StorePointer(&(raw_ptr()->data_), new_contents.raw()); 8855 StorePointer(&(raw_ptr()->data_), new_contents.raw());
8856 ASSERT(AbstractTypeArguments::AreEqual(
8857 AbstractTypeArguments::Handle(new_contents.GetTypeArguments()),
8858 AbstractTypeArguments::Handle(raw_ptr()->type_arguments_)));
8834 } 8859 }
8835 8860
8836 8861
8837 RawObject* GrowableObjectArray::RemoveLast() const { 8862 RawObject* GrowableObjectArray::RemoveLast() const {
8838 ASSERT(!IsNull()); 8863 ASSERT(!IsNull());
8839 ASSERT(Length() > 0); 8864 ASSERT(Length() > 0);
8840 intptr_t index = Length() - 1; 8865 intptr_t index = Length() - 1;
8841 const Array& contents = Array::Handle(data()); 8866 const Array& contents = Array::Handle(data());
8842 const Object& obj = Object::Handle(contents.At(index)); 8867 const Object& obj = Object::Handle(contents.At(index));
8843 contents.SetAt(index, Object::Handle()); 8868 contents.SetAt(index, Object::Handle());
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
9368 const String& str = String::Handle(pattern()); 9393 const String& str = String::Handle(pattern());
9369 const char* format = "JSRegExp: pattern=%s flags=%s"; 9394 const char* format = "JSRegExp: pattern=%s flags=%s";
9370 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 9395 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
9371 char* chars = reinterpret_cast<char*>( 9396 char* chars = reinterpret_cast<char*>(
9372 Isolate::Current()->current_zone()->Allocate(len + 1)); 9397 Isolate::Current()->current_zone()->Allocate(len + 1));
9373 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 9398 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
9374 return chars; 9399 return chars;
9375 } 9400 }
9376 9401
9377 } // namespace dart 9402 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698