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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 // Forward declarations. | 23 // Forward declarations. |
24 #define DEFINE_FORWARD_DECLARATION(clazz) \ | 24 #define DEFINE_FORWARD_DECLARATION(clazz) \ |
25 class clazz; | 25 class clazz; |
26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) | 26 CLASS_LIST(DEFINE_FORWARD_DECLARATION) |
27 #undef DEFINE_FORWARD_DECLARATION | 27 #undef DEFINE_FORWARD_DECLARATION |
28 class Api; | 28 class Api; |
29 class Assembler; | 29 class Assembler; |
30 class Code; | 30 class Code; |
31 class LocalScope; | 31 class LocalScope; |
| 32 class Symbols; |
32 | 33 |
33 #define OBJECT_IMPLEMENTATION(object, super) \ | 34 #define OBJECT_IMPLEMENTATION(object, super) \ |
34 public: /* NOLINT */ \ | 35 public: /* NOLINT */ \ |
35 Raw##object* raw() const { return reinterpret_cast<Raw##object*>(raw_); } \ | 36 Raw##object* raw() const { return reinterpret_cast<Raw##object*>(raw_); } \ |
36 void operator=(Raw##object* value) { \ | 37 void operator=(Raw##object* value) { \ |
37 initializeHandle(this, value); \ | 38 initializeHandle(this, value); \ |
38 } \ | 39 } \ |
39 bool Is##object() const { return true; } \ | 40 bool Is##object() const { return true; } \ |
40 void operator^=(RawObject* value) { \ | 41 void operator^=(RawObject* value) { \ |
41 initializeHandle(this, value); \ | 42 initializeHandle(this, value); \ |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 365 |
365 uword raw_value() const { | 366 uword raw_value() const { |
366 return reinterpret_cast<uword>(raw()); | 367 return reinterpret_cast<uword>(raw()); |
367 } | 368 } |
368 | 369 |
369 inline void SetRaw(RawObject* value); | 370 inline void SetRaw(RawObject* value); |
370 | 371 |
371 cpp_vtable vtable() const { return bit_copy<cpp_vtable>(*this); } | 372 cpp_vtable vtable() const { return bit_copy<cpp_vtable>(*this); } |
372 void set_vtable(cpp_vtable value) { *vtable_address() = value; } | 373 void set_vtable(cpp_vtable value) { *vtable_address() = value; } |
373 | 374 |
374 static RawObject* Allocate(const Class& cls, | 375 static RawObject* Allocate(intptr_t cls_id, |
375 intptr_t size, | 376 intptr_t size, |
376 Heap::Space space); | 377 Heap::Space space); |
377 | 378 |
378 static intptr_t RoundedAllocationSize(intptr_t size) { | 379 static intptr_t RoundedAllocationSize(intptr_t size) { |
379 return Utils::RoundUp(size, kObjectAlignment); | 380 return Utils::RoundUp(size, kObjectAlignment); |
380 } | 381 } |
381 | 382 |
382 bool Contains(uword addr) const { | 383 bool Contains(uword addr) const { |
383 intptr_t this_size = raw()->Size(); | 384 intptr_t this_size = raw()->Size(); |
384 uword this_addr = RawObject::ToAddr(raw()); | 385 uword this_addr = RawObject::ToAddr(raw()); |
(...skipping 2936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3321 | 3322 |
3322 static RawString* Transform(int32_t (*mapping)(int32_t ch), | 3323 static RawString* Transform(int32_t (*mapping)(int32_t ch), |
3323 const String& str, | 3324 const String& str, |
3324 Heap::Space space = Heap::kNew); | 3325 Heap::Space space = Heap::kNew); |
3325 | 3326 |
3326 static RawString* ToUpperCase(const String& str, | 3327 static RawString* ToUpperCase(const String& str, |
3327 Heap::Space space = Heap::kNew); | 3328 Heap::Space space = Heap::kNew); |
3328 static RawString* ToLowerCase(const String& str, | 3329 static RawString* ToLowerCase(const String& str, |
3329 Heap::Space space = Heap::kNew); | 3330 Heap::Space space = Heap::kNew); |
3330 | 3331 |
3331 static RawString* NewSymbol(const char* str); | |
3332 template<typename T> | |
3333 static RawString* NewSymbol(const T* characters, intptr_t len); | |
3334 static RawString* NewSymbol(const String& str); | |
3335 static RawString* NewSymbol(const String& str, | |
3336 intptr_t begin_index, | |
3337 intptr_t length); | |
3338 | |
3339 static RawString* NewFormatted(const char* format, ...); | 3332 static RawString* NewFormatted(const char* format, ...); |
3340 | 3333 |
3341 protected: | 3334 protected: |
3342 bool HasHash() const { | 3335 bool HasHash() const { |
3343 ASSERT(Smi::New(0) == NULL); | 3336 ASSERT(Smi::New(0) == NULL); |
3344 return (raw_ptr()->hash_ != NULL); | 3337 return (raw_ptr()->hash_ != NULL); |
3345 } | 3338 } |
3346 | 3339 |
3347 void SetLength(intptr_t value) const { | 3340 void SetLength(intptr_t value) const { |
3348 // This is only safe because we create a new Smi, which does not cause | 3341 // This is only safe because we create a new Smi, which does not cause |
3349 // heap allocation. | 3342 // heap allocation. |
3350 raw_ptr()->length_ = Smi::New(value); | 3343 raw_ptr()->length_ = Smi::New(value); |
3351 } | 3344 } |
3352 | 3345 |
3353 void SetHash(intptr_t value) const { | 3346 void SetHash(intptr_t value) const { |
3354 // This is only safe because we create a new Smi, which does not cause | 3347 // This is only safe because we create a new Smi, which does not cause |
3355 // heap allocation. | 3348 // heap allocation. |
3356 raw_ptr()->hash_ = Smi::New(value); | 3349 raw_ptr()->hash_ = Smi::New(value); |
3357 } | 3350 } |
3358 | 3351 |
3359 template<typename HandleType, typename ElementType> | 3352 template<typename HandleType, typename ElementType> |
3360 static void ReadFromImpl(SnapshotReader* reader, | 3353 static void ReadFromImpl(SnapshotReader* reader, |
3361 HandleType* str_obj, | 3354 HandleType* str_obj, |
3362 intptr_t len, | 3355 intptr_t len, |
3363 intptr_t tags); | 3356 intptr_t tags); |
3364 | 3357 |
3365 HEAP_OBJECT_IMPLEMENTATION(String, Instance); | 3358 HEAP_OBJECT_IMPLEMENTATION(String, Instance); |
| 3359 |
| 3360 friend class Symbols; |
3366 }; | 3361 }; |
3367 | 3362 |
3368 | 3363 |
3369 class OneByteString : public String { | 3364 class OneByteString : public String { |
3370 public: | 3365 public: |
3371 virtual int32_t CharAt(intptr_t index) const { | 3366 virtual int32_t CharAt(intptr_t index) const { |
3372 return *CharAddr(index); | 3367 return *CharAddr(index); |
3373 } | 3368 } |
3374 | 3369 |
3375 virtual intptr_t CharSize() const { | 3370 virtual intptr_t CharSize() const { |
(...skipping 1834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5210 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5205 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
5211 return false; | 5206 return false; |
5212 } | 5207 } |
5213 } | 5208 } |
5214 return true; | 5209 return true; |
5215 } | 5210 } |
5216 | 5211 |
5217 } // namespace dart | 5212 } // namespace dart |
5218 | 5213 |
5219 #endif // VM_OBJECT_H_ | 5214 #endif // VM_OBJECT_H_ |
OLD | NEW |