OLD | NEW |
---|---|
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" |
11 #include "vm/bitmap.h" | 11 #include "vm/bitmap.h" |
12 #include "vm/dart.h" | 12 #include "vm/dart.h" |
13 #include "vm/globals.h" | 13 #include "vm/globals.h" |
14 #include "vm/handles.h" | 14 #include "vm/handles.h" |
15 #include "vm/heap.h" | 15 #include "vm/heap.h" |
16 #include "vm/isolate.h" | 16 #include "vm/isolate.h" |
17 #include "vm/os.h" | 17 #include "vm/os.h" |
18 #include "vm/raw_object.h" | 18 #include "vm/raw_object.h" |
19 #include "vm/scanner.h" | 19 #include "vm/scanner.h" |
20 #include "vm/unicode.h" | |
20 | 21 |
21 namespace dart { | 22 namespace dart { |
22 | 23 |
23 // Forward declarations. | 24 // Forward declarations. |
24 #define DEFINE_FORWARD_DECLARATION(clazz) \ | 25 #define DEFINE_FORWARD_DECLARATION(clazz) \ |
25 class clazz; | 26 class clazz; |
26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) | 27 CLASS_LIST(DEFINE_FORWARD_DECLARATION) |
27 #undef DEFINE_FORWARD_DECLARATION | 28 #undef DEFINE_FORWARD_DECLARATION |
28 class Api; | 29 class Api; |
29 class Assembler; | 30 class Assembler; |
(...skipping 3681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3711 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } | 3712 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } |
3712 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } | 3713 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } |
3713 | 3714 |
3714 virtual intptr_t Hash() const; | 3715 virtual intptr_t Hash() const; |
3715 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } | 3716 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } |
3716 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); | 3717 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); |
3717 static intptr_t Hash(const uint8_t* characters, intptr_t len); | 3718 static intptr_t Hash(const uint8_t* characters, intptr_t len); |
3718 static intptr_t Hash(const uint16_t* characters, intptr_t len); | 3719 static intptr_t Hash(const uint16_t* characters, intptr_t len); |
3719 static intptr_t Hash(const uint32_t* characters, intptr_t len); | 3720 static intptr_t Hash(const uint32_t* characters, intptr_t len); |
3720 | 3721 |
3721 int32_t CharAt(intptr_t index) const; | 3722 // Returns the UTF-16 code unit at an index. UTF-16 is a superset of ASCII |
3723 // so you can always use this if you are looking for ASCII. If you need to | |
3724 // support arbitrary Unicode characters then you should perhaps be using | |
3725 // Utf16::CharCodeAt(string, index) instead. | |
3726 uint32_t CodeUnitAt(intptr_t index) const; | |
3722 | 3727 |
3723 intptr_t CharSize() const; | 3728 intptr_t CharSize() const; |
3724 | 3729 |
3725 inline bool Equals(const String& str) const; | 3730 inline bool Equals(const String& str) const; |
3726 inline bool Equals(const String& str, | 3731 inline bool Equals(const String& str, |
3727 intptr_t begin_index, // begin index on 'str'. | 3732 intptr_t begin_index, // begin index on 'str'. |
3728 intptr_t len) const; // len on 'str'. | 3733 intptr_t len) const; // len on 'str'. |
3729 bool Equals(const char* str) const; | 3734 bool Equals(const char* str) const; |
3730 bool Equals(const uint8_t* characters, intptr_t len) const; | 3735 bool Equals(const uint8_t* characters, intptr_t len) const; |
3731 bool Equals(const uint16_t* characters, intptr_t len) const; | 3736 bool Equals(const uint16_t* characters, intptr_t len) const; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3877 friend class Symbols; | 3882 friend class Symbols; |
3878 friend class OneByteString; | 3883 friend class OneByteString; |
3879 friend class TwoByteString; | 3884 friend class TwoByteString; |
3880 friend class ExternalOneByteString; | 3885 friend class ExternalOneByteString; |
3881 friend class ExternalTwoByteString; | 3886 friend class ExternalTwoByteString; |
3882 }; | 3887 }; |
3883 | 3888 |
3884 | 3889 |
3885 class OneByteString : public AllStatic { | 3890 class OneByteString : public AllStatic { |
3886 public: | 3891 public: |
3887 static int32_t CharAt(const String& str, intptr_t index) { | 3892 static uint32_t CodeUnitAt(const String& str, intptr_t index) { |
cshapiro
2012/11/15 20:14:51
Why did the signedness of the return type change?
erikcorry
2012/11/15 23:47:05
There is a mixture in the VM of signed and unsigne
| |
3888 return *CharAddr(str, index); | 3893 return *CharAddr(str, index); |
3889 } | 3894 } |
3890 | 3895 |
3891 static RawOneByteString* EscapeSpecialCharacters(const String& str, | 3896 static RawOneByteString* EscapeSpecialCharacters(const String& str, |
3892 bool raw_str); | 3897 bool raw_str); |
3893 | 3898 |
3894 static bool EqualsIgnoringPrivateKey(const String& str1, | 3899 static bool EqualsIgnoringPrivateKey(const String& str1, |
3895 const String& str2); | 3900 const String& str2); |
3896 | 3901 |
3897 // We use the same maximum elements for all strings. | 3902 // We use the same maximum elements for all strings. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3934 | 3939 |
3935 static RawOneByteString* Concat(const String& str1, | 3940 static RawOneByteString* Concat(const String& str1, |
3936 const String& str2, | 3941 const String& str2, |
3937 Heap::Space space); | 3942 Heap::Space space); |
3938 static RawOneByteString* ConcatAll(const Array& strings, | 3943 static RawOneByteString* ConcatAll(const Array& strings, |
3939 intptr_t len, | 3944 intptr_t len, |
3940 Heap::Space space); | 3945 Heap::Space space); |
3941 | 3946 |
3942 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), | 3947 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), |
3943 const String& str, | 3948 const String& str, |
3949 int out_length, | |
3944 Heap::Space space); | 3950 Heap::Space space); |
3945 | 3951 |
3946 static const ClassId kClassId = kOneByteStringCid; | 3952 static const ClassId kClassId = kOneByteStringCid; |
3947 | 3953 |
3948 static RawOneByteString* null() { | 3954 static RawOneByteString* null() { |
3949 return reinterpret_cast<RawOneByteString*>(Object::null()); | 3955 return reinterpret_cast<RawOneByteString*>(Object::null()); |
3950 } | 3956 } |
3951 | 3957 |
3952 private: | 3958 private: |
3953 static RawOneByteString* raw(const String& str) { | 3959 static RawOneByteString* raw(const String& str) { |
(...skipping 17 matching lines...) Expand all Loading... | |
3971 Snapshot::Kind kind); | 3977 Snapshot::Kind kind); |
3972 | 3978 |
3973 friend class Class; | 3979 friend class Class; |
3974 friend class String; | 3980 friend class String; |
3975 friend class SnapshotReader; | 3981 friend class SnapshotReader; |
3976 }; | 3982 }; |
3977 | 3983 |
3978 | 3984 |
3979 class TwoByteString : public AllStatic { | 3985 class TwoByteString : public AllStatic { |
3980 public: | 3986 public: |
3981 static int32_t CharAt(const String& str, intptr_t index) { | 3987 static uint32_t CodeUnitAt(const String& str, intptr_t index) { |
3982 return *CharAddr(str, index); | 3988 return *CharAddr(str, index); |
3983 } | 3989 } |
3984 | 3990 |
3985 static RawTwoByteString* EscapeSpecialCharacters(const String& str, | 3991 static RawTwoByteString* EscapeSpecialCharacters(const String& str, |
3986 bool raw_str); | 3992 bool raw_str); |
3987 | 3993 |
3988 // We use the same maximum elements for all strings. | 3994 // We use the same maximum elements for all strings. |
3989 static const intptr_t kBytesPerElement = 2; | 3995 static const intptr_t kBytesPerElement = 2; |
3990 static const intptr_t kMaxElements = String::kMaxElements; | 3996 static const intptr_t kMaxElements = String::kMaxElements; |
3991 | 3997 |
(...skipping 25 matching lines...) Expand all Loading... | |
4017 | 4023 |
4018 static RawTwoByteString* Concat(const String& str1, | 4024 static RawTwoByteString* Concat(const String& str1, |
4019 const String& str2, | 4025 const String& str2, |
4020 Heap::Space space); | 4026 Heap::Space space); |
4021 static RawTwoByteString* ConcatAll(const Array& strings, | 4027 static RawTwoByteString* ConcatAll(const Array& strings, |
4022 intptr_t len, | 4028 intptr_t len, |
4023 Heap::Space space); | 4029 Heap::Space space); |
4024 | 4030 |
4025 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), | 4031 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), |
4026 const String& str, | 4032 const String& str, |
4033 int out_length, | |
4027 Heap::Space space); | 4034 Heap::Space space); |
4028 | 4035 |
4029 static RawTwoByteString* null() { | 4036 static RawTwoByteString* null() { |
4030 return reinterpret_cast<RawTwoByteString*>(Object::null()); | 4037 return reinterpret_cast<RawTwoByteString*>(Object::null()); |
4031 } | 4038 } |
4032 | 4039 |
4033 | 4040 |
4034 static const ClassId kClassId = kTwoByteStringCid; | 4041 static const ClassId kClassId = kTwoByteStringCid; |
4035 | 4042 |
4036 private: | 4043 private: |
(...skipping 18 matching lines...) Expand all Loading... | |
4055 Snapshot::Kind kind); | 4062 Snapshot::Kind kind); |
4056 | 4063 |
4057 friend class Class; | 4064 friend class Class; |
4058 friend class String; | 4065 friend class String; |
4059 friend class SnapshotReader; | 4066 friend class SnapshotReader; |
4060 }; | 4067 }; |
4061 | 4068 |
4062 | 4069 |
4063 class ExternalOneByteString : public AllStatic { | 4070 class ExternalOneByteString : public AllStatic { |
4064 public: | 4071 public: |
4065 static int32_t CharAt(const String& str, intptr_t index) { | 4072 static uint32_t CodeUnitAt(const String& str, intptr_t index) { |
4066 return *CharAddr(str, index); | 4073 return *CharAddr(str, index); |
4067 } | 4074 } |
4068 | 4075 |
4069 static void* GetPeer(const String& str) { | 4076 static void* GetPeer(const String& str) { |
4070 return raw_ptr(str)->external_data_->peer(); | 4077 return raw_ptr(str)->external_data_->peer(); |
4071 } | 4078 } |
4072 | 4079 |
4073 // We use the same maximum elements for all strings. | 4080 // We use the same maximum elements for all strings. |
4074 static const intptr_t kBytesPerElement = 1; | 4081 static const intptr_t kBytesPerElement = 1; |
4075 static const intptr_t kMaxElements = String::kMaxElements; | 4082 static const intptr_t kMaxElements = String::kMaxElements; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4121 Snapshot::Kind kind); | 4128 Snapshot::Kind kind); |
4122 | 4129 |
4123 friend class Class; | 4130 friend class Class; |
4124 friend class String; | 4131 friend class String; |
4125 friend class SnapshotReader; | 4132 friend class SnapshotReader; |
4126 }; | 4133 }; |
4127 | 4134 |
4128 | 4135 |
4129 class ExternalTwoByteString : public AllStatic { | 4136 class ExternalTwoByteString : public AllStatic { |
4130 public: | 4137 public: |
4131 static int32_t CharAt(const String& str, intptr_t index) { | 4138 static uint32_t CodeUnitAt(const String& str, intptr_t index) { |
4132 return *CharAddr(str, index); | 4139 return *CharAddr(str, index); |
4133 } | 4140 } |
4134 | 4141 |
4135 static void* GetPeer(const String& str) { | 4142 static void* GetPeer(const String& str) { |
4136 return raw_ptr(str)->external_data_->peer(); | 4143 return raw_ptr(str)->external_data_->peer(); |
4137 } | 4144 } |
4138 | 4145 |
4139 // We use the same maximum elements for all strings. | 4146 // We use the same maximum elements for all strings. |
4140 static const intptr_t kBytesPerElement = 2; | 4147 static const intptr_t kBytesPerElement = 2; |
4141 static const intptr_t kMaxElements = String::kMaxElements; | 4148 static const intptr_t kMaxElements = String::kMaxElements; |
(...skipping 1755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5897 intptr_t begin_index, | 5904 intptr_t begin_index, |
5898 intptr_t len) const { | 5905 intptr_t len) const { |
5899 ASSERT(begin_index >= 0); | 5906 ASSERT(begin_index >= 0); |
5900 ASSERT((begin_index == 0) || (begin_index < str.Length())); | 5907 ASSERT((begin_index == 0) || (begin_index < str.Length())); |
5901 ASSERT(len >= 0); | 5908 ASSERT(len >= 0); |
5902 ASSERT(len <= str.Length()); | 5909 ASSERT(len <= str.Length()); |
5903 if (len != this->Length()) { | 5910 if (len != this->Length()) { |
5904 return false; // Lengths don't match. | 5911 return false; // Lengths don't match. |
5905 } | 5912 } |
5906 for (intptr_t i = 0; i < len; i++) { | 5913 for (intptr_t i = 0; i < len; i++) { |
5907 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5914 if (this->CodeUnitAt(i) != str.CodeUnitAt(begin_index + i)) { |
5908 return false; | 5915 return false; |
5909 } | 5916 } |
5910 } | 5917 } |
5911 return true; | 5918 return true; |
5912 } | 5919 } |
5913 | 5920 |
5914 } // namespace dart | 5921 } // namespace dart |
5915 | 5922 |
5916 #endif // VM_OBJECT_H_ | 5923 #endif // VM_OBJECT_H_ |
OLD | NEW |