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" | |
21 | 20 |
22 namespace dart { | 21 namespace dart { |
23 | 22 |
24 // Forward declarations. | 23 // Forward declarations. |
25 #define DEFINE_FORWARD_DECLARATION(clazz) \ | 24 #define DEFINE_FORWARD_DECLARATION(clazz) \ |
26 class clazz; | 25 class clazz; |
27 CLASS_LIST(DEFINE_FORWARD_DECLARATION) | 26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) |
28 #undef DEFINE_FORWARD_DECLARATION | 27 #undef DEFINE_FORWARD_DECLARATION |
29 class Api; | 28 class Api; |
30 class Assembler; | 29 class Assembler; |
(...skipping 3714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3745 }; | 3744 }; |
3746 | 3745 |
3747 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } | 3746 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } |
3748 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } | 3747 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } |
3749 | 3748 |
3750 virtual intptr_t Hash() const; | 3749 virtual intptr_t Hash() const; |
3751 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } | 3750 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } |
3752 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); | 3751 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); |
3753 static intptr_t Hash(const uint8_t* characters, intptr_t len); | 3752 static intptr_t Hash(const uint8_t* characters, intptr_t len); |
3754 static intptr_t Hash(const uint16_t* characters, intptr_t len); | 3753 static intptr_t Hash(const uint16_t* characters, intptr_t len); |
3755 static intptr_t Hash(const int32_t* characters, intptr_t len); | 3754 static intptr_t Hash(const uint32_t* characters, intptr_t len); |
3756 | 3755 |
3757 // Despite the name, this does not return the character. It returns the | |
3758 // UTF-16 code unit at an index. UTF-16 is a superset of ASCII (and Latin1) | |
3759 // so you can always use this if you are looking for ASCII. If you need to | |
3760 // support arbitrary Unicode characters then you should perhaps be using | |
3761 // Utf16::CharCodeAt(string, index), which returns the full 21 bit code | |
3762 // point. | |
3763 int32_t CharAt(intptr_t index) const; | 3756 int32_t CharAt(intptr_t index) const; |
3764 | 3757 |
3765 intptr_t CharSize() const; | 3758 intptr_t CharSize() const; |
3766 | 3759 |
3767 inline bool Equals(const String& str) const; | 3760 inline bool Equals(const String& str) const; |
3768 inline bool Equals(const String& str, | 3761 inline bool Equals(const String& str, |
3769 intptr_t begin_index, // begin index on 'str'. | 3762 intptr_t begin_index, // begin index on 'str'. |
3770 intptr_t len) const; // len on 'str'. | 3763 intptr_t len) const; // len on 'str'. |
3771 bool Equals(const char* str) const; | 3764 bool Equals(const char* str) const; |
3772 bool Equals(const uint8_t* characters, intptr_t len) const; | 3765 bool Equals(const uint8_t* characters, intptr_t len) const; |
3773 bool Equals(const uint16_t* characters, intptr_t len) const; | 3766 bool Equals(const uint16_t* characters, intptr_t len) const; |
| 3767 bool Equals(const uint32_t* characters, intptr_t len) const; |
3774 | 3768 |
3775 virtual bool Equals(const Instance& other) const; | 3769 virtual bool Equals(const Instance& other) const; |
3776 | 3770 |
3777 intptr_t CompareTo(const String& other) const; | 3771 intptr_t CompareTo(const String& other) const; |
3778 | 3772 |
3779 bool StartsWith(const String& other) const; | 3773 bool StartsWith(const String& other) const; |
3780 | 3774 |
3781 virtual RawInstance* Canonicalize() const; | 3775 virtual RawInstance* Canonicalize() const; |
3782 | 3776 |
3783 bool IsSymbol() const { return raw()->IsCanonical(); } | 3777 bool IsSymbol() const { return raw()->IsCanonical(); } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3825 static RawString* New(const uint8_t* utf8_array, | 3819 static RawString* New(const uint8_t* utf8_array, |
3826 intptr_t array_len, | 3820 intptr_t array_len, |
3827 Heap::Space space = Heap::kNew); | 3821 Heap::Space space = Heap::kNew); |
3828 | 3822 |
3829 // Creates a new String object from an array of UTF-16 encoded characters. | 3823 // Creates a new String object from an array of UTF-16 encoded characters. |
3830 static RawString* New(const uint16_t* utf16_array, | 3824 static RawString* New(const uint16_t* utf16_array, |
3831 intptr_t array_len, | 3825 intptr_t array_len, |
3832 Heap::Space space = Heap::kNew); | 3826 Heap::Space space = Heap::kNew); |
3833 | 3827 |
3834 // Creates a new String object from an array of UTF-32 encoded characters. | 3828 // Creates a new String object from an array of UTF-32 encoded characters. |
3835 static RawString* New(const int32_t* utf32_array, | 3829 static RawString* New(const uint32_t* utf32_array, |
3836 intptr_t array_len, | 3830 intptr_t array_len, |
3837 Heap::Space space = Heap::kNew); | 3831 Heap::Space space = Heap::kNew); |
3838 | 3832 |
3839 // Create a new String object from another Dart String instance. | 3833 // Create a new String object from another Dart String instance. |
3840 static RawString* New(const String& str, Heap::Space space = Heap::kNew); | 3834 static RawString* New(const String& str, Heap::Space space = Heap::kNew); |
3841 | 3835 |
3842 // Creates a new External String object using the specified array of | 3836 // Creates a new External String object using the specified array of |
3843 // UTF-8 encoded characters as the external reference. | 3837 // UTF-8 encoded characters as the external reference. |
3844 static RawString* NewExternal(const uint8_t* utf8_array, | 3838 static RawString* NewExternal(const uint8_t* utf8_array, |
3845 intptr_t array_len, | 3839 intptr_t array_len, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3971 return New(reinterpret_cast<const uint8_t*>(c_string), | 3965 return New(reinterpret_cast<const uint8_t*>(c_string), |
3972 strlen(c_string), | 3966 strlen(c_string), |
3973 space); | 3967 space); |
3974 } | 3968 } |
3975 static RawOneByteString* New(const uint8_t* characters, | 3969 static RawOneByteString* New(const uint8_t* characters, |
3976 intptr_t len, | 3970 intptr_t len, |
3977 Heap::Space space); | 3971 Heap::Space space); |
3978 static RawOneByteString* New(const uint16_t* characters, | 3972 static RawOneByteString* New(const uint16_t* characters, |
3979 intptr_t len, | 3973 intptr_t len, |
3980 Heap::Space space); | 3974 Heap::Space space); |
3981 static RawOneByteString* New(const int32_t* characters, | 3975 static RawOneByteString* New(const uint32_t* characters, |
3982 intptr_t len, | 3976 intptr_t len, |
3983 Heap::Space space); | 3977 Heap::Space space); |
3984 static RawOneByteString* New(const String& str, | 3978 static RawOneByteString* New(const String& str, |
3985 Heap::Space space); | 3979 Heap::Space space); |
3986 | 3980 |
3987 static RawOneByteString* Concat(const String& str1, | 3981 static RawOneByteString* Concat(const String& str1, |
3988 const String& str2, | 3982 const String& str2, |
3989 Heap::Space space); | 3983 Heap::Space space); |
3990 static RawOneByteString* ConcatAll(const Array& strings, | 3984 static RawOneByteString* ConcatAll(const Array& strings, |
3991 intptr_t len, | 3985 intptr_t len, |
3992 Heap::Space space); | 3986 Heap::Space space); |
3993 | 3987 |
3994 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), | 3988 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), |
3995 const String& str, | 3989 const String& str, |
3996 intptr_t out_length, | |
3997 Heap::Space space); | 3990 Heap::Space space); |
3998 | 3991 |
3999 static const ClassId kClassId = kOneByteStringCid; | 3992 static const ClassId kClassId = kOneByteStringCid; |
4000 | 3993 |
4001 static RawOneByteString* null() { | 3994 static RawOneByteString* null() { |
4002 return reinterpret_cast<RawOneByteString*>(Object::null()); | 3995 return reinterpret_cast<RawOneByteString*>(Object::null()); |
4003 } | 3996 } |
4004 | 3997 |
4005 private: | 3998 private: |
4006 static RawOneByteString* raw(const String& str) { | 3999 static RawOneByteString* raw(const String& str) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4055 return String::RoundedAllocationSize( | 4048 return String::RoundedAllocationSize( |
4056 sizeof(RawTwoByteString) + (len * kBytesPerElement)); | 4049 sizeof(RawTwoByteString) + (len * kBytesPerElement)); |
4057 } | 4050 } |
4058 | 4051 |
4059 static RawTwoByteString* New(intptr_t len, | 4052 static RawTwoByteString* New(intptr_t len, |
4060 Heap::Space space); | 4053 Heap::Space space); |
4061 static RawTwoByteString* New(const uint16_t* characters, | 4054 static RawTwoByteString* New(const uint16_t* characters, |
4062 intptr_t len, | 4055 intptr_t len, |
4063 Heap::Space space); | 4056 Heap::Space space); |
4064 static RawTwoByteString* New(intptr_t utf16_len, | 4057 static RawTwoByteString* New(intptr_t utf16_len, |
4065 const int32_t* characters, | 4058 const uint32_t* characters, |
4066 intptr_t len, | 4059 intptr_t len, |
4067 Heap::Space space); | 4060 Heap::Space space); |
4068 static RawTwoByteString* New(const String& str, | 4061 static RawTwoByteString* New(const String& str, |
4069 Heap::Space space); | 4062 Heap::Space space); |
4070 | 4063 |
4071 static RawTwoByteString* Concat(const String& str1, | 4064 static RawTwoByteString* Concat(const String& str1, |
4072 const String& str2, | 4065 const String& str2, |
4073 Heap::Space space); | 4066 Heap::Space space); |
4074 static RawTwoByteString* ConcatAll(const Array& strings, | 4067 static RawTwoByteString* ConcatAll(const Array& strings, |
4075 intptr_t len, | 4068 intptr_t len, |
4076 Heap::Space space); | 4069 Heap::Space space); |
4077 | 4070 |
4078 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), | 4071 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), |
4079 const String& str, | 4072 const String& str, |
4080 intptr_t out_length, | |
4081 Heap::Space space); | 4073 Heap::Space space); |
4082 | 4074 |
4083 static RawTwoByteString* null() { | 4075 static RawTwoByteString* null() { |
4084 return reinterpret_cast<RawTwoByteString*>(Object::null()); | 4076 return reinterpret_cast<RawTwoByteString*>(Object::null()); |
4085 } | 4077 } |
4086 | 4078 |
4087 | 4079 |
4088 static const ClassId kClassId = kTwoByteStringCid; | 4080 static const ClassId kClassId = kTwoByteStringCid; |
4089 | 4081 |
4090 private: | 4082 private: |
(...skipping 1873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5964 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5956 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
5965 return false; | 5957 return false; |
5966 } | 5958 } |
5967 } | 5959 } |
5968 return true; | 5960 return true; |
5969 } | 5961 } |
5970 | 5962 |
5971 } // namespace dart | 5963 } // namespace dart |
5972 | 5964 |
5973 #endif // VM_OBJECT_H_ | 5965 #endif // VM_OBJECT_H_ |
OLD | NEW |