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

Side by Side Diff: src/objects/string.h

Issue 2961253002: [objects] Rename macros from DECLARE_ to DECL_ for consistency. (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « src/objects/shared-function-info.h ('k') | src/objects/string-table.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 the V8 project authors. All rights reserved. 1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_OBJECTS_STRING_H_ 5 #ifndef V8_OBJECTS_STRING_H_
6 #define V8_OBJECTS_STRING_H_ 6 #define V8_OBJECTS_STRING_H_
7 7
8 #include "src/objects/name.h" 8 #include "src/objects/name.h"
9 9
10 // Has to be the last include (doesn't have include guards): 10 // Has to be the last include (doesn't have include guards):
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 bool MakeExternal(v8::String::ExternalOneByteStringResource* resource); 307 bool MakeExternal(v8::String::ExternalOneByteStringResource* resource);
308 308
309 // Conversion. 309 // Conversion.
310 inline bool AsArrayIndex(uint32_t* index); 310 inline bool AsArrayIndex(uint32_t* index);
311 uint32_t inline ToValidIndex(Object* number); 311 uint32_t inline ToValidIndex(Object* number);
312 312
313 // Trimming. 313 // Trimming.
314 enum TrimMode { kTrim, kTrimLeft, kTrimRight }; 314 enum TrimMode { kTrim, kTrimLeft, kTrimRight };
315 static Handle<String> Trim(Handle<String> string, TrimMode mode); 315 static Handle<String> Trim(Handle<String> string, TrimMode mode);
316 316
317 DECLARE_CAST(String) 317 DECL_CAST(String)
318 318
319 void PrintOn(FILE* out); 319 void PrintOn(FILE* out);
320 320
321 // For use during stack traces. Performs rudimentary sanity check. 321 // For use during stack traces. Performs rudimentary sanity check.
322 bool LooksValid(); 322 bool LooksValid();
323 323
324 // Dispatched behavior. 324 // Dispatched behavior.
325 void StringShortPrint(StringStream* accumulator, bool show_details = true); 325 void StringShortPrint(StringStream* accumulator, bool show_details = true);
326 void PrintUC16(std::ostream& os, int start = 0, int end = -1); // NOLINT 326 void PrintUC16(std::ostream& os, int start = 0, int end = -1); // NOLINT
327 #if defined(DEBUG) || defined(OBJECT_PRINT) 327 #if defined(DEBUG) || defined(OBJECT_PRINT)
328 char* ToAsciiArray(); 328 char* ToAsciiArray();
329 #endif 329 #endif
330 DECLARE_PRINTER(String) 330 DECL_PRINTER(String)
331 DECLARE_VERIFIER(String) 331 DECL_VERIFIER(String)
332 332
333 inline bool IsFlat(); 333 inline bool IsFlat();
334 334
335 // Layout description. 335 // Layout description.
336 static const int kLengthOffset = Name::kSize; 336 static const int kLengthOffset = Name::kSize;
337 static const int kSize = kLengthOffset + kPointerSize; 337 static const int kSize = kLengthOffset + kPointerSize;
338 338
339 // Max char codes. 339 // Max char codes.
340 static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar; 340 static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar;
341 static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar; 341 static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 451
452 // Compute and set the hash code. 452 // Compute and set the hash code.
453 uint32_t ComputeAndSetHash(); 453 uint32_t ComputeAndSetHash();
454 454
455 DISALLOW_IMPLICIT_CONSTRUCTORS(String); 455 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
456 }; 456 };
457 457
458 // The SeqString abstract class captures sequential string values. 458 // The SeqString abstract class captures sequential string values.
459 class SeqString : public String { 459 class SeqString : public String {
460 public: 460 public:
461 DECLARE_CAST(SeqString) 461 DECL_CAST(SeqString)
462 462
463 // Layout description. 463 // Layout description.
464 static const int kHeaderSize = String::kSize; 464 static const int kHeaderSize = String::kSize;
465 465
466 // Truncate the string in-place if possible and return the result. 466 // Truncate the string in-place if possible and return the result.
467 // In case of new_length == 0, the empty string is returned without 467 // In case of new_length == 0, the empty string is returned without
468 // truncating the original string. 468 // truncating the original string.
469 MUST_USE_RESULT static Handle<String> Truncate(Handle<SeqString> string, 469 MUST_USE_RESULT static Handle<String> Truncate(Handle<SeqString> string,
470 int new_length); 470 int new_length);
471 471
472 private: 472 private:
473 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); 473 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString);
474 }; 474 };
475 475
476 // The OneByteString class captures sequential one-byte string objects. 476 // The OneByteString class captures sequential one-byte string objects.
477 // Each character in the OneByteString is an one-byte character. 477 // Each character in the OneByteString is an one-byte character.
478 class SeqOneByteString : public SeqString { 478 class SeqOneByteString : public SeqString {
479 public: 479 public:
480 static const bool kHasOneByteEncoding = true; 480 static const bool kHasOneByteEncoding = true;
481 481
482 // Dispatched behavior. 482 // Dispatched behavior.
483 inline uint16_t SeqOneByteStringGet(int index); 483 inline uint16_t SeqOneByteStringGet(int index);
484 inline void SeqOneByteStringSet(int index, uint16_t value); 484 inline void SeqOneByteStringSet(int index, uint16_t value);
485 485
486 // Get the address of the characters in this string. 486 // Get the address of the characters in this string.
487 inline Address GetCharsAddress(); 487 inline Address GetCharsAddress();
488 488
489 inline uint8_t* GetChars(); 489 inline uint8_t* GetChars();
490 490
491 DECLARE_CAST(SeqOneByteString) 491 DECL_CAST(SeqOneByteString)
492 492
493 // Garbage collection support. This method is called by the 493 // Garbage collection support. This method is called by the
494 // garbage collector to compute the actual size of an OneByteString 494 // garbage collector to compute the actual size of an OneByteString
495 // instance. 495 // instance.
496 inline int SeqOneByteStringSize(InstanceType instance_type); 496 inline int SeqOneByteStringSize(InstanceType instance_type);
497 497
498 // Computes the size for an OneByteString instance of a given length. 498 // Computes the size for an OneByteString instance of a given length.
499 static int SizeFor(int length) { 499 static int SizeFor(int length) {
500 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); 500 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize);
501 } 501 }
(...skipping 21 matching lines...) Expand all
523 inline void SeqTwoByteStringSet(int index, uint16_t value); 523 inline void SeqTwoByteStringSet(int index, uint16_t value);
524 524
525 // Get the address of the characters in this string. 525 // Get the address of the characters in this string.
526 inline Address GetCharsAddress(); 526 inline Address GetCharsAddress();
527 527
528 inline uc16* GetChars(); 528 inline uc16* GetChars();
529 529
530 // For regexp code. 530 // For regexp code.
531 const uint16_t* SeqTwoByteStringGetData(unsigned start); 531 const uint16_t* SeqTwoByteStringGetData(unsigned start);
532 532
533 DECLARE_CAST(SeqTwoByteString) 533 DECL_CAST(SeqTwoByteString)
534 534
535 // Garbage collection support. This method is called by the 535 // Garbage collection support. This method is called by the
536 // garbage collector to compute the actual size of a TwoByteString 536 // garbage collector to compute the actual size of a TwoByteString
537 // instance. 537 // instance.
538 inline int SeqTwoByteStringSize(InstanceType instance_type); 538 inline int SeqTwoByteStringSize(InstanceType instance_type);
539 539
540 // Computes the size for a TwoByteString instance of a given length. 540 // Computes the size for a TwoByteString instance of a given length.
541 static int SizeFor(int length) { 541 static int SizeFor(int length) {
542 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); 542 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize);
543 } 543 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 inline String* second(); 577 inline String* second();
578 // Doesn't check that the result is a string, even in debug mode. This is 578 // Doesn't check that the result is a string, even in debug mode. This is
579 // useful during GC where the mark bits confuse the checks. 579 // useful during GC where the mark bits confuse the checks.
580 inline Object* unchecked_second(); 580 inline Object* unchecked_second();
581 inline void set_second(String* second, 581 inline void set_second(String* second,
582 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); 582 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
583 583
584 // Dispatched behavior. 584 // Dispatched behavior.
585 V8_EXPORT_PRIVATE uint16_t ConsStringGet(int index); 585 V8_EXPORT_PRIVATE uint16_t ConsStringGet(int index);
586 586
587 DECLARE_CAST(ConsString) 587 DECL_CAST(ConsString)
588 588
589 // Layout description. 589 // Layout description.
590 static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); 590 static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize);
591 static const int kSecondOffset = kFirstOffset + kPointerSize; 591 static const int kSecondOffset = kFirstOffset + kPointerSize;
592 static const int kSize = kSecondOffset + kPointerSize; 592 static const int kSize = kSecondOffset + kPointerSize;
593 593
594 // Minimum length for a cons string. 594 // Minimum length for a cons string.
595 static const int kMinLength = 13; 595 static const int kMinLength = 13;
596 596
597 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> 597 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize>
598 BodyDescriptor; 598 BodyDescriptor;
599 // No weak fields. 599 // No weak fields.
600 typedef BodyDescriptor BodyDescriptorWeak; 600 typedef BodyDescriptor BodyDescriptorWeak;
601 601
602 DECLARE_VERIFIER(ConsString) 602 DECL_VERIFIER(ConsString)
603 603
604 private: 604 private:
605 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); 605 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
606 }; 606 };
607 607
608 // The ThinString class describes string objects that are just references 608 // The ThinString class describes string objects that are just references
609 // to another string object. They are used for in-place internalization when 609 // to another string object. They are used for in-place internalization when
610 // the original string cannot actually be internalized in-place: in these 610 // the original string cannot actually be internalized in-place: in these
611 // cases, the original string is converted to a ThinString pointing at its 611 // cases, the original string is converted to a ThinString pointing at its
612 // internalized version (which is allocated as a new object). 612 // internalized version (which is allocated as a new object).
613 // In terms of memory layout and most algorithms operating on strings, 613 // In terms of memory layout and most algorithms operating on strings,
614 // ThinStrings can be thought of as "one-part cons strings". 614 // ThinStrings can be thought of as "one-part cons strings".
615 class ThinString : public String { 615 class ThinString : public String {
616 public: 616 public:
617 // Actual string that this ThinString refers to. 617 // Actual string that this ThinString refers to.
618 inline String* actual() const; 618 inline String* actual() const;
619 inline void set_actual(String* s, 619 inline void set_actual(String* s,
620 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); 620 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
621 621
622 V8_EXPORT_PRIVATE uint16_t ThinStringGet(int index); 622 V8_EXPORT_PRIVATE uint16_t ThinStringGet(int index);
623 623
624 DECLARE_CAST(ThinString) 624 DECL_CAST(ThinString)
625 DECLARE_VERIFIER(ThinString) 625 DECL_VERIFIER(ThinString)
626 626
627 // Layout description. 627 // Layout description.
628 static const int kActualOffset = String::kSize; 628 static const int kActualOffset = String::kSize;
629 static const int kSize = kActualOffset + kPointerSize; 629 static const int kSize = kActualOffset + kPointerSize;
630 630
631 typedef FixedBodyDescriptor<kActualOffset, kSize, kSize> BodyDescriptor; 631 typedef FixedBodyDescriptor<kActualOffset, kSize, kSize> BodyDescriptor;
632 // No weak fields. 632 // No weak fields.
633 typedef BodyDescriptor BodyDescriptorWeak; 633 typedef BodyDescriptor BodyDescriptorWeak;
634 634
635 private: 635 private:
(...skipping 16 matching lines...) Expand all
652 public: 652 public:
653 inline String* parent(); 653 inline String* parent();
654 inline void set_parent(String* parent, 654 inline void set_parent(String* parent,
655 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); 655 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
656 inline int offset() const; 656 inline int offset() const;
657 inline void set_offset(int offset); 657 inline void set_offset(int offset);
658 658
659 // Dispatched behavior. 659 // Dispatched behavior.
660 V8_EXPORT_PRIVATE uint16_t SlicedStringGet(int index); 660 V8_EXPORT_PRIVATE uint16_t SlicedStringGet(int index);
661 661
662 DECLARE_CAST(SlicedString) 662 DECL_CAST(SlicedString)
663 663
664 // Layout description. 664 // Layout description.
665 static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize); 665 static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize);
666 static const int kOffsetOffset = kParentOffset + kPointerSize; 666 static const int kOffsetOffset = kParentOffset + kPointerSize;
667 static const int kSize = kOffsetOffset + kPointerSize; 667 static const int kSize = kOffsetOffset + kPointerSize;
668 668
669 // Minimum length for a sliced string. 669 // Minimum length for a sliced string.
670 static const int kMinLength = 13; 670 static const int kMinLength = 13;
671 671
672 typedef FixedBodyDescriptor<kParentOffset, kOffsetOffset + kPointerSize, 672 typedef FixedBodyDescriptor<kParentOffset, kOffsetOffset + kPointerSize,
673 kSize> 673 kSize>
674 BodyDescriptor; 674 BodyDescriptor;
675 // No weak fields. 675 // No weak fields.
676 typedef BodyDescriptor BodyDescriptorWeak; 676 typedef BodyDescriptor BodyDescriptorWeak;
677 677
678 DECLARE_VERIFIER(SlicedString) 678 DECL_VERIFIER(SlicedString)
679 679
680 private: 680 private:
681 DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString); 681 DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString);
682 }; 682 };
683 683
684 // The ExternalString class describes string values that are backed by 684 // The ExternalString class describes string values that are backed by
685 // a string resource that lies outside the V8 heap. ExternalStrings 685 // a string resource that lies outside the V8 heap. ExternalStrings
686 // consist of the length field common to all strings, a pointer to the 686 // consist of the length field common to all strings, a pointer to the
687 // external resource. It is important to ensure (externally) that the 687 // external resource. It is important to ensure (externally) that the
688 // resource is not deallocated while the ExternalString is live in the 688 // resource is not deallocated while the ExternalString is live in the
689 // V8 heap. 689 // V8 heap.
690 // 690 //
691 // The API expects that all ExternalStrings are created through the 691 // The API expects that all ExternalStrings are created through the
692 // API. Therefore, ExternalStrings should not be used internally. 692 // API. Therefore, ExternalStrings should not be used internally.
693 class ExternalString : public String { 693 class ExternalString : public String {
694 public: 694 public:
695 DECLARE_CAST(ExternalString) 695 DECL_CAST(ExternalString)
696 696
697 // Layout description. 697 // Layout description.
698 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); 698 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
699 static const int kShortSize = kResourceOffset + kPointerSize; 699 static const int kShortSize = kResourceOffset + kPointerSize;
700 static const int kResourceDataOffset = kResourceOffset + kPointerSize; 700 static const int kResourceDataOffset = kResourceOffset + kPointerSize;
701 static const int kSize = kResourceDataOffset + kPointerSize; 701 static const int kSize = kResourceDataOffset + kPointerSize;
702 702
703 // Return whether external string is short (data pointer is not cached). 703 // Return whether external string is short (data pointer is not cached).
704 inline bool is_short(); 704 inline bool is_short();
705 705
(...skipping 19 matching lines...) Expand all
725 // The cached pointer is always valid, as the external character array does = 725 // The cached pointer is always valid, as the external character array does =
726 // not move during lifetime. Deserialization is the only exception, after 726 // not move during lifetime. Deserialization is the only exception, after
727 // which the pointer cache has to be refreshed. 727 // which the pointer cache has to be refreshed.
728 inline void update_data_cache(); 728 inline void update_data_cache();
729 729
730 inline const uint8_t* GetChars(); 730 inline const uint8_t* GetChars();
731 731
732 // Dispatched behavior. 732 // Dispatched behavior.
733 inline uint16_t ExternalOneByteStringGet(int index); 733 inline uint16_t ExternalOneByteStringGet(int index);
734 734
735 DECLARE_CAST(ExternalOneByteString) 735 DECL_CAST(ExternalOneByteString)
736 736
737 class BodyDescriptor; 737 class BodyDescriptor;
738 // No weak fields. 738 // No weak fields.
739 typedef BodyDescriptor BodyDescriptorWeak; 739 typedef BodyDescriptor BodyDescriptorWeak;
740 740
741 private: 741 private:
742 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalOneByteString); 742 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalOneByteString);
743 }; 743 };
744 744
745 // The ExternalTwoByteString class is an external string backed by a UTF-16 745 // The ExternalTwoByteString class is an external string backed by a UTF-16
(...skipping 15 matching lines...) Expand all
761 inline void update_data_cache(); 761 inline void update_data_cache();
762 762
763 inline const uint16_t* GetChars(); 763 inline const uint16_t* GetChars();
764 764
765 // Dispatched behavior. 765 // Dispatched behavior.
766 inline uint16_t ExternalTwoByteStringGet(int index); 766 inline uint16_t ExternalTwoByteStringGet(int index);
767 767
768 // For regexp code. 768 // For regexp code.
769 inline const uint16_t* ExternalTwoByteStringGetData(unsigned start); 769 inline const uint16_t* ExternalTwoByteStringGetData(unsigned start);
770 770
771 DECLARE_CAST(ExternalTwoByteString) 771 DECL_CAST(ExternalTwoByteString)
772 772
773 class BodyDescriptor; 773 class BodyDescriptor;
774 // No weak fields. 774 // No weak fields.
775 typedef BodyDescriptor BodyDescriptorWeak; 775 typedef BodyDescriptor BodyDescriptorWeak;
776 776
777 private: 777 private:
778 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); 778 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString);
779 }; 779 };
780 780
781 // A flat string reader provides random access to the contents of a 781 // A flat string reader provides random access to the contents of a
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 const uint8_t* end_; 866 const uint8_t* end_;
867 DISALLOW_COPY_AND_ASSIGN(StringCharacterStream); 867 DISALLOW_COPY_AND_ASSIGN(StringCharacterStream);
868 }; 868 };
869 869
870 } // namespace internal 870 } // namespace internal
871 } // namespace v8 871 } // namespace v8
872 872
873 #include "src/objects/object-macros-undef.h" 873 #include "src/objects/object-macros-undef.h"
874 874
875 #endif // V8_OBJECTS_STRING_H_ 875 #endif // V8_OBJECTS_STRING_H_
OLDNEW
« no previous file with comments | « src/objects/shared-function-info.h ('k') | src/objects/string-table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698