Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
| 6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
| 7 | 7 |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/dart.h" | 9 #include "vm/dart.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| (...skipping 2347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2358 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } | 2358 intptr_t Length() const { return Smi::Value(raw_ptr()->length_); } |
| 2359 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } | 2359 static intptr_t length_offset() { return OFFSET_OF(RawString, length_); } |
| 2360 | 2360 |
| 2361 virtual intptr_t Hash() const; | 2361 virtual intptr_t Hash() const; |
| 2362 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } | 2362 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } |
| 2363 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); | 2363 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); |
| 2364 static intptr_t Hash(const uint8_t* characters, intptr_t len); | 2364 static intptr_t Hash(const uint8_t* characters, intptr_t len); |
| 2365 static intptr_t Hash(const uint16_t* characters, intptr_t len); | 2365 static intptr_t Hash(const uint16_t* characters, intptr_t len); |
| 2366 static intptr_t Hash(const uint32_t* characters, intptr_t len); | 2366 static intptr_t Hash(const uint32_t* characters, intptr_t len); |
| 2367 | 2367 |
| 2368 bool HasOneByteChar() const { | |
| 2369 return IsOneByteString() || IsExternalOneByteString(); | |
| 2370 } | |
| 2371 | |
| 2372 bool HasTwoByteChar() const { | |
| 2373 return IsTwoByteString() || IsExternalTwoByteString(); | |
| 2374 } | |
| 2375 | |
| 2376 bool HasFourByteChar() const { | |
| 2377 return IsFourByteString() || IsExternalFourByteString(); | |
| 2378 } | |
|
turnidge
2011/10/25 18:07:20
Passing thought... Would it make sense to add a vi
cshapiro
2011/10/25 20:42:47
Sounds like a good idea. This will show up in my
| |
| 2379 | |
| 2368 virtual int32_t CharAt(intptr_t index) const; | 2380 virtual int32_t CharAt(intptr_t index) const; |
| 2369 | 2381 |
| 2370 bool Equals(const String& str, intptr_t begin_index, intptr_t len) const; | 2382 bool Equals(const String& str, intptr_t begin_index, intptr_t len) const; |
| 2371 bool Equals(const char* str) const; | 2383 bool Equals(const char* str) const; |
| 2372 bool Equals(const uint8_t* characters, intptr_t len) const; | 2384 bool Equals(const uint8_t* characters, intptr_t len) const; |
| 2373 bool Equals(const uint16_t* characters, intptr_t len) const; | 2385 bool Equals(const uint16_t* characters, intptr_t len) const; |
| 2374 bool Equals(const uint32_t* characters, intptr_t len) const; | 2386 bool Equals(const uint32_t* characters, intptr_t len) const; |
| 2375 | 2387 |
| 2376 virtual bool Equals(const Instance& other) const; | 2388 virtual bool Equals(const Instance& other) const; |
| 2377 | 2389 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2495 static RawOneByteString* New(const OneByteString& str, | 2507 static RawOneByteString* New(const OneByteString& str, |
| 2496 Heap::Space space); | 2508 Heap::Space space); |
| 2497 | 2509 |
| 2498 static RawOneByteString* Concat(const String& str1, | 2510 static RawOneByteString* Concat(const String& str1, |
| 2499 const String& str2, | 2511 const String& str2, |
| 2500 Heap::Space space); | 2512 Heap::Space space); |
| 2501 static RawOneByteString* ConcatAll(const Array& strings, | 2513 static RawOneByteString* ConcatAll(const Array& strings, |
| 2502 intptr_t len, | 2514 intptr_t len, |
| 2503 Heap::Space space); | 2515 Heap::Space space); |
| 2504 | 2516 |
| 2505 static RawString* SubString(const OneByteString& str, | |
| 2506 intptr_t begin_index, | |
| 2507 intptr_t length, | |
| 2508 Heap::Space space); | |
| 2509 | |
| 2510 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), | 2517 static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch), |
| 2511 const String& str, | 2518 const String& str, |
| 2512 Heap::Space space); | 2519 Heap::Space space); |
| 2513 | 2520 |
| 2514 private: | 2521 private: |
| 2515 uint8_t* CharAddr(intptr_t index) const { | 2522 uint8_t* CharAddr(intptr_t index) const { |
| 2516 // TODO(iposva): Determine if we should throw an exception here. | 2523 // TODO(iposva): Determine if we should throw an exception here. |
| 2517 ASSERT((index >= 0) && (index < Length())); | 2524 ASSERT((index >= 0) && (index < Length())); |
| 2518 return &raw_ptr()->data_[index]; | 2525 return &raw_ptr()->data_[index]; |
| 2519 } | 2526 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2550 static RawTwoByteString* New(const TwoByteString& str, | 2557 static RawTwoByteString* New(const TwoByteString& str, |
| 2551 Heap::Space space); | 2558 Heap::Space space); |
| 2552 | 2559 |
| 2553 static RawTwoByteString* Concat(const String& str1, | 2560 static RawTwoByteString* Concat(const String& str1, |
| 2554 const String& str2, | 2561 const String& str2, |
| 2555 Heap::Space space); | 2562 Heap::Space space); |
| 2556 static RawTwoByteString* ConcatAll(const Array& strings, | 2563 static RawTwoByteString* ConcatAll(const Array& strings, |
| 2557 intptr_t len, | 2564 intptr_t len, |
| 2558 Heap::Space space); | 2565 Heap::Space space); |
| 2559 | 2566 |
| 2560 static RawString* SubString(const TwoByteString& str, | |
| 2561 intptr_t begin_index, | |
| 2562 intptr_t length, | |
| 2563 Heap::Space space); | |
| 2564 | |
| 2565 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), | 2567 static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch), |
| 2566 const String& str, | 2568 const String& str, |
| 2567 Heap::Space space); | 2569 Heap::Space space); |
| 2568 | 2570 |
| 2569 private: | 2571 private: |
| 2570 uint16_t* CharAddr(intptr_t index) const { | 2572 uint16_t* CharAddr(intptr_t index) const { |
| 2571 ASSERT((index >= 0) && (index < Length())); | 2573 ASSERT((index >= 0) && (index < Length())); |
| 2572 return &raw_ptr()->data_[index]; | 2574 return &raw_ptr()->data_[index]; |
| 2573 } | 2575 } |
| 2574 | 2576 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 2601 static RawFourByteString* New(const FourByteString& str, | 2603 static RawFourByteString* New(const FourByteString& str, |
| 2602 Heap::Space space); | 2604 Heap::Space space); |
| 2603 | 2605 |
| 2604 static RawFourByteString* Concat(const String& str1, | 2606 static RawFourByteString* Concat(const String& str1, |
| 2605 const String& str2, | 2607 const String& str2, |
| 2606 Heap::Space space); | 2608 Heap::Space space); |
| 2607 static RawFourByteString* ConcatAll(const Array& strings, | 2609 static RawFourByteString* ConcatAll(const Array& strings, |
| 2608 intptr_t len, | 2610 intptr_t len, |
| 2609 Heap::Space space); | 2611 Heap::Space space); |
| 2610 | 2612 |
| 2611 static RawString* SubString(const FourByteString& str, | |
| 2612 intptr_t begin_index, | |
| 2613 intptr_t length, | |
| 2614 Heap::Space space); | |
| 2615 | |
| 2616 static RawFourByteString* Transform(int32_t (*mapping)(int32_t ch), | 2613 static RawFourByteString* Transform(int32_t (*mapping)(int32_t ch), |
| 2617 const String& str, | 2614 const String& str, |
| 2618 Heap::Space space); | 2615 Heap::Space space); |
| 2619 | 2616 |
| 2620 private: | 2617 private: |
| 2621 uint32_t* CharAddr(intptr_t index) const { | 2618 uint32_t* CharAddr(intptr_t index) const { |
| 2622 ASSERT((index >= 0) && (index < Length())); | 2619 ASSERT((index >= 0) && (index < Length())); |
| 2623 return &raw_ptr()->data_[index]; | 2620 return &raw_ptr()->data_[index]; |
| 2624 } | 2621 } |
| 2625 | 2622 |
| 2626 HEAP_OBJECT_IMPLEMENTATION(FourByteString, String); | 2623 HEAP_OBJECT_IMPLEMENTATION(FourByteString, String); |
| 2627 friend class Class; | 2624 friend class Class; |
| 2628 friend class String; | 2625 friend class String; |
| 2629 }; | 2626 }; |
| 2630 | 2627 |
| 2631 | 2628 |
| 2629 class ExternalOneByteString : public String { | |
| 2630 public: | |
| 2631 typedef void (*Finalizer)(uint8_t* characters); | |
| 2632 | |
| 2633 virtual int32_t CharAt(intptr_t index) const { | |
| 2634 return *CharAddr(index); | |
| 2635 } | |
| 2636 | |
| 2637 static intptr_t InstanceSize() { | |
| 2638 return RoundedAllocationSize(sizeof(RawExternalOneByteString)); | |
| 2639 } | |
| 2640 | |
| 2641 static RawExternalOneByteString* New(const uint8_t* characters, | |
| 2642 intptr_t len, | |
| 2643 Finalizer finalizer, | |
| 2644 Heap::Space space = Heap::kNew); | |
| 2645 | |
| 2646 private: | |
| 2647 uint8_t* CharAddr(intptr_t index) const { | |
| 2648 // TODO(iposva): Determine if we should throw an exception here. | |
| 2649 ASSERT((index >= 0) && (index < Length())); | |
| 2650 return &raw_ptr()->data_[index]; | |
| 2651 } | |
| 2652 | |
| 2653 void SetData(const uint8_t* characters) { | |
| 2654 raw_ptr()->data_ = const_cast<uint8_t*>(characters); | |
| 2655 } | |
| 2656 | |
| 2657 HEAP_OBJECT_IMPLEMENTATION(ExternalOneByteString, String); | |
| 2658 friend class Class; | |
| 2659 friend class String; | |
| 2660 }; | |
| 2661 | |
| 2662 | |
| 2663 class ExternalTwoByteString : public String { | |
| 2664 public: | |
| 2665 typedef void (*Finalizer)(uint16_t* characters); | |
| 2666 | |
| 2667 virtual int32_t CharAt(intptr_t index) const { | |
| 2668 return *CharAddr(index); | |
| 2669 } | |
| 2670 | |
| 2671 static intptr_t InstanceSize() { | |
| 2672 return RoundedAllocationSize(sizeof(RawExternalTwoByteString)); | |
| 2673 } | |
| 2674 | |
| 2675 static RawExternalTwoByteString* New(const uint16_t* characters, | |
| 2676 intptr_t len, | |
| 2677 Finalizer finalizer, | |
| 2678 Heap::Space space = Heap::kNew); | |
| 2679 | |
| 2680 private: | |
| 2681 uint16_t* CharAddr(intptr_t index) const { | |
| 2682 // TODO(iposva): Determine if we should throw an exception here. | |
| 2683 ASSERT((index >= 0) && (index < Length())); | |
| 2684 return &raw_ptr()->data_[index]; | |
| 2685 } | |
| 2686 | |
| 2687 void SetData(const uint16_t* characters) { | |
| 2688 raw_ptr()->data_ = const_cast<uint16_t*>(characters); | |
| 2689 } | |
| 2690 | |
| 2691 HEAP_OBJECT_IMPLEMENTATION(ExternalTwoByteString, String); | |
| 2692 friend class Class; | |
| 2693 friend class String; | |
| 2694 }; | |
| 2695 | |
| 2696 | |
| 2697 class ExternalFourByteString : public String { | |
| 2698 public: | |
| 2699 typedef void (*Finalizer)(uint32_t* characters); | |
| 2700 | |
| 2701 virtual int32_t CharAt(intptr_t index) const { | |
| 2702 return *CharAddr(index); | |
| 2703 } | |
| 2704 | |
| 2705 static intptr_t InstanceSize() { | |
| 2706 return RoundedAllocationSize(sizeof(RawExternalFourByteString)); | |
| 2707 } | |
| 2708 | |
| 2709 static RawExternalFourByteString* New(const uint32_t* characters, | |
| 2710 intptr_t len, | |
| 2711 Finalizer finalizer, | |
| 2712 Heap::Space space = Heap::kNew); | |
| 2713 | |
| 2714 private: | |
| 2715 uint32_t* CharAddr(intptr_t index) const { | |
| 2716 // TODO(iposva): Determine if we should throw an exception here. | |
| 2717 ASSERT((index >= 0) && (index < Length())); | |
| 2718 return &raw_ptr()->data_[index]; | |
| 2719 } | |
| 2720 | |
| 2721 void SetData(const uint32_t* characters) { | |
| 2722 raw_ptr()->data_ = const_cast<uint32_t*>(characters); | |
| 2723 } | |
| 2724 | |
| 2725 HEAP_OBJECT_IMPLEMENTATION(ExternalFourByteString, String); | |
| 2726 friend class Class; | |
| 2727 friend class String; | |
| 2728 }; | |
| 2729 | |
| 2730 | |
| 2632 class Bool : public Instance { | 2731 class Bool : public Instance { |
| 2633 public: | 2732 public: |
| 2634 bool value() const { | 2733 bool value() const { |
| 2635 return raw_ptr()->value_; | 2734 return raw_ptr()->value_; |
| 2636 } | 2735 } |
| 2637 | 2736 |
| 2638 static intptr_t InstanceSize() { | 2737 static intptr_t InstanceSize() { |
| 2639 return RoundedAllocationSize(sizeof(RawBool)); | 2738 return RoundedAllocationSize(sizeof(RawBool)); |
| 2640 } | 2739 } |
| 2641 | 2740 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2960 } | 3059 } |
| 2961 | 3060 |
| 2962 | 3061 |
| 2963 void Context::SetAt(intptr_t index, const Instance& value) const { | 3062 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 2964 StorePointer(InstanceAddr(index), value.raw()); | 3063 StorePointer(InstanceAddr(index), value.raw()); |
| 2965 } | 3064 } |
| 2966 | 3065 |
| 2967 } // namespace dart | 3066 } // namespace dart |
| 2968 | 3067 |
| 2969 #endif // VM_OBJECT_H_ | 3068 #endif // VM_OBJECT_H_ |
| OLD | NEW |