| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 // Features shared by parsing and pre-parsing scanners. | 5 // Features shared by parsing and pre-parsing scanners. |
| 6 | 6 |
| 7 #ifndef V8_PARSING_SCANNER_H_ | 7 #ifndef V8_PARSING_SCANNER_H_ |
| 8 #define V8_PARSING_SCANNER_H_ | 8 #define V8_PARSING_SCANNER_H_ |
| 9 | 9 |
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
| 11 #include "src/base/hashmap.h" | |
| 12 #include "src/base/logging.h" | 11 #include "src/base/logging.h" |
| 13 #include "src/char-predicates.h" | 12 #include "src/char-predicates.h" |
| 14 #include "src/collector.h" | |
| 15 #include "src/globals.h" | 13 #include "src/globals.h" |
| 16 #include "src/list.h" | |
| 17 #include "src/messages.h" | 14 #include "src/messages.h" |
| 18 #include "src/parsing/token.h" | 15 #include "src/parsing/token.h" |
| 19 #include "src/unicode-decoder.h" | 16 #include "src/unicode-decoder.h" |
| 20 #include "src/unicode.h" | 17 #include "src/unicode.h" |
| 21 | 18 |
| 22 namespace v8 { | 19 namespace v8 { |
| 23 namespace internal { | 20 namespace internal { |
| 24 | 21 |
| 25 | 22 |
| 26 class AstRawString; | 23 class AstRawString; |
| 27 class AstValueFactory; | 24 class AstValueFactory; |
| 25 class DuplicateFinder; |
| 28 class ParserRecorder; | 26 class ParserRecorder; |
| 29 class UnicodeCache; | 27 class UnicodeCache; |
| 30 | 28 |
| 31 | 29 |
| 32 // --------------------------------------------------------------------- | 30 // --------------------------------------------------------------------- |
| 33 // Buffered stream of UTF-16 code units, using an internal UTF-16 buffer. | 31 // Buffered stream of UTF-16 code units, using an internal UTF-16 buffer. |
| 34 // A code unit is a 16 bit value representing either a 16 bit code point | 32 // A code unit is a 16 bit value representing either a 16 bit code point |
| 35 // or one part of a surrogate pair that make a single 21 bit code point. | 33 // or one part of a surrogate pair that make a single 21 bit code point. |
| 36 | 34 |
| 37 class Utf16CharacterStream { | 35 class Utf16CharacterStream { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // are more code_units available, return true. | 90 // are more code_units available, return true. |
| 93 virtual bool ReadBlock() = 0; | 91 virtual bool ReadBlock() = 0; |
| 94 virtual size_t SlowSeekForward(size_t code_unit_count) = 0; | 92 virtual size_t SlowSeekForward(size_t code_unit_count) = 0; |
| 95 | 93 |
| 96 const uint16_t* buffer_cursor_; | 94 const uint16_t* buffer_cursor_; |
| 97 const uint16_t* buffer_end_; | 95 const uint16_t* buffer_end_; |
| 98 size_t pos_; | 96 size_t pos_; |
| 99 }; | 97 }; |
| 100 | 98 |
| 101 | 99 |
| 102 // --------------------------------------------------------------------- | |
| 103 // DuplicateFinder discovers duplicate symbols. | |
| 104 | |
| 105 class DuplicateFinder { | |
| 106 public: | |
| 107 explicit DuplicateFinder(UnicodeCache* constants) | |
| 108 : unicode_constants_(constants), | |
| 109 backing_store_(16), | |
| 110 map_(&Match) { } | |
| 111 | |
| 112 int AddOneByteSymbol(Vector<const uint8_t> key, int value); | |
| 113 int AddTwoByteSymbol(Vector<const uint16_t> key, int value); | |
| 114 // Add a a number literal by converting it (if necessary) | |
| 115 // to the string that ToString(ToNumber(literal)) would generate. | |
| 116 // and then adding that string with AddOneByteSymbol. | |
| 117 // This string is the actual value used as key in an object literal, | |
| 118 // and the one that must be different from the other keys. | |
| 119 int AddNumber(Vector<const uint8_t> key, int value); | |
| 120 | |
| 121 private: | |
| 122 int AddSymbol(Vector<const uint8_t> key, bool is_one_byte, int value); | |
| 123 // Backs up the key and its length in the backing store. | |
| 124 // The backup is stored with a base 127 encoding of the | |
| 125 // length (plus a bit saying whether the string is one byte), | |
| 126 // followed by the bytes of the key. | |
| 127 uint8_t* BackupKey(Vector<const uint8_t> key, bool is_one_byte); | |
| 128 | |
| 129 // Compare two encoded keys (both pointing into the backing store) | |
| 130 // for having the same base-127 encoded lengths and representation. | |
| 131 // and then having the same 'length' bytes following. | |
| 132 static bool Match(void* first, void* second); | |
| 133 // Creates a hash from a sequence of bytes. | |
| 134 static uint32_t Hash(Vector<const uint8_t> key, bool is_one_byte); | |
| 135 // Checks whether a string containing a JS number is its canonical | |
| 136 // form. | |
| 137 static bool IsNumberCanonical(Vector<const uint8_t> key); | |
| 138 | |
| 139 // Size of buffer. Sufficient for using it to call DoubleToCString in | |
| 140 // from conversions.h. | |
| 141 static const int kBufferSize = 100; | |
| 142 | |
| 143 UnicodeCache* unicode_constants_; | |
| 144 // Backing store used to store strings used as hashmap keys. | |
| 145 SequenceCollector<unsigned char> backing_store_; | |
| 146 base::HashMap map_; | |
| 147 // Buffer used for string->number->canonical string conversions. | |
| 148 char number_buffer_[kBufferSize]; | |
| 149 }; | |
| 150 | |
| 151 | |
| 152 // ---------------------------------------------------------------------------- | 100 // ---------------------------------------------------------------------------- |
| 153 // JavaScript Scanner. | 101 // JavaScript Scanner. |
| 154 | 102 |
| 155 class Scanner { | 103 class Scanner { |
| 156 public: | 104 public: |
| 157 // Scoped helper for a re-settable bookmark. | 105 // Scoped helper for a re-settable bookmark. |
| 158 class BookmarkScope { | 106 class BookmarkScope { |
| 159 public: | 107 public: |
| 160 explicit BookmarkScope(Scanner* scanner) : scanner_(scanner) { | 108 explicit BookmarkScope(Scanner* scanner) : scanner_(scanner) { |
| 161 DCHECK_NOT_NULL(scanner_); | 109 DCHECK_NOT_NULL(scanner_); |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 bool found_html_comment_; | 792 bool found_html_comment_; |
| 845 | 793 |
| 846 MessageTemplate::Template scanner_error_; | 794 MessageTemplate::Template scanner_error_; |
| 847 Location scanner_error_location_; | 795 Location scanner_error_location_; |
| 848 }; | 796 }; |
| 849 | 797 |
| 850 } // namespace internal | 798 } // namespace internal |
| 851 } // namespace v8 | 799 } // namespace v8 |
| 852 | 800 |
| 853 #endif // V8_PARSING_SCANNER_H_ | 801 #endif // V8_PARSING_SCANNER_H_ |
| OLD | NEW |