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_SCANNER_H_ | 7 #ifndef V8_SCANNER_H_ |
8 #define V8_SCANNER_H_ | 8 #define V8_SCANNER_H_ |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
11 #include "src/base/logging.h" | 11 #include "src/base/logging.h" |
12 #include "src/char-predicates.h" | 12 #include "src/char-predicates.h" |
13 #include "src/globals.h" | 13 #include "src/globals.h" |
14 #include "src/hashmap.h" | 14 #include "src/hashmap.h" |
15 #include "src/list.h" | 15 #include "src/list.h" |
16 #include "src/token.h" | 16 #include "src/token.h" |
17 #include "src/unicode.h" | 17 #include "src/unicode.h" |
18 #include "src/unicode-decoder.h" | 18 #include "src/unicode-decoder.h" |
19 #include "src/utils.h" | 19 #include "src/utils.h" |
20 | 20 |
21 namespace v8 { | 21 namespace v8 { |
22 namespace internal { | 22 namespace internal { |
23 | 23 |
24 | 24 |
25 class AstRawString; | 25 class AstRawString; |
26 class AstValueFactory; | 26 class AstValueFactory; |
27 class ParserRecorder; | 27 class ParserRecorder; |
| 28 class UnicodeCache; |
28 | 29 |
29 | 30 |
30 // Returns the value (0 .. 15) of a hexadecimal character c. | 31 // Returns the value (0 .. 15) of a hexadecimal character c. |
31 // If c is not a legal hexadecimal character, returns a value < 0. | 32 // If c is not a legal hexadecimal character, returns a value < 0. |
32 inline int HexValue(uc32 c) { | 33 inline int HexValue(uc32 c) { |
33 c -= '0'; | 34 c -= '0'; |
34 if (static_cast<unsigned>(c) <= 9) return c; | 35 if (static_cast<unsigned>(c) <= 9) return c; |
35 c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36. | 36 c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36. |
36 if (static_cast<unsigned>(c) <= 5) return c + 10; | 37 if (static_cast<unsigned>(c) <= 5) return c + 10; |
37 return -1; | 38 return -1; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 virtual bool ReadBlock() = 0; | 103 virtual bool ReadBlock() = 0; |
103 virtual size_t SlowSeekForward(size_t code_unit_count) = 0; | 104 virtual size_t SlowSeekForward(size_t code_unit_count) = 0; |
104 | 105 |
105 const uint16_t* buffer_cursor_; | 106 const uint16_t* buffer_cursor_; |
106 const uint16_t* buffer_end_; | 107 const uint16_t* buffer_end_; |
107 size_t pos_; | 108 size_t pos_; |
108 }; | 109 }; |
109 | 110 |
110 | 111 |
111 // --------------------------------------------------------------------- | 112 // --------------------------------------------------------------------- |
112 // Caching predicates used by scanners. | |
113 | |
114 class UnicodeCache { | |
115 public: | |
116 UnicodeCache() {} | |
117 typedef unibrow::Utf8Decoder<512> Utf8Decoder; | |
118 | |
119 StaticResource<Utf8Decoder>* utf8_decoder() { | |
120 return &utf8_decoder_; | |
121 } | |
122 | |
123 bool IsIdentifierStart(unibrow::uchar c) { return kIsIdentifierStart.get(c); } | |
124 bool IsIdentifierPart(unibrow::uchar c) { return kIsIdentifierPart.get(c); } | |
125 bool IsLineTerminator(unibrow::uchar c) { return kIsLineTerminator.get(c); } | |
126 bool IsLineTerminatorSequence(unibrow::uchar c, unibrow::uchar next) { | |
127 if (!IsLineTerminator(c)) return false; | |
128 if (c == 0x000d && next == 0x000a) return false; // CR with following LF. | |
129 return true; | |
130 } | |
131 | |
132 bool IsWhiteSpace(unibrow::uchar c) { return kIsWhiteSpace.get(c); } | |
133 bool IsWhiteSpaceOrLineTerminator(unibrow::uchar c) { | |
134 return kIsWhiteSpaceOrLineTerminator.get(c); | |
135 } | |
136 | |
137 private: | |
138 unibrow::Predicate<IdentifierStart, 128> kIsIdentifierStart; | |
139 unibrow::Predicate<IdentifierPart, 128> kIsIdentifierPart; | |
140 unibrow::Predicate<unibrow::LineTerminator, 128> kIsLineTerminator; | |
141 unibrow::Predicate<WhiteSpace, 128> kIsWhiteSpace; | |
142 unibrow::Predicate<WhiteSpaceOrLineTerminator, 128> | |
143 kIsWhiteSpaceOrLineTerminator; | |
144 StaticResource<Utf8Decoder> utf8_decoder_; | |
145 | |
146 DISALLOW_COPY_AND_ASSIGN(UnicodeCache); | |
147 }; | |
148 | |
149 | |
150 // --------------------------------------------------------------------- | |
151 // DuplicateFinder discovers duplicate symbols. | 113 // DuplicateFinder discovers duplicate symbols. |
152 | 114 |
153 class DuplicateFinder { | 115 class DuplicateFinder { |
154 public: | 116 public: |
155 explicit DuplicateFinder(UnicodeCache* constants) | 117 explicit DuplicateFinder(UnicodeCache* constants) |
156 : unicode_constants_(constants), | 118 : unicode_constants_(constants), |
157 backing_store_(16), | 119 backing_store_(16), |
158 map_(&Match) { } | 120 map_(&Match) { } |
159 | 121 |
160 int AddOneByteSymbol(Vector<const uint8_t> key, int value); | 122 int AddOneByteSymbol(Vector<const uint8_t> key, int value); |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 // inside multiline comments. | 747 // inside multiline comments. |
786 bool has_line_terminator_before_next_; | 748 bool has_line_terminator_before_next_; |
787 // Whether there is a multi-line comment that contains a | 749 // Whether there is a multi-line comment that contains a |
788 // line-terminator after the current token, and before the next. | 750 // line-terminator after the current token, and before the next. |
789 bool has_multiline_comment_before_next_; | 751 bool has_multiline_comment_before_next_; |
790 }; | 752 }; |
791 | 753 |
792 } } // namespace v8::internal | 754 } } // namespace v8::internal |
793 | 755 |
794 #endif // V8_SCANNER_H_ | 756 #endif // V8_SCANNER_H_ |
OLD | NEW |