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

Side by Side Diff: src/scanner.h

Issue 185653004: Experimental parser: merge to r19637 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/sampler.cc ('k') | src/scanner.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // If c is not a legal hexadecimal character, returns a value < 0. 48 // If c is not a legal hexadecimal character, returns a value < 0.
49 inline int HexValue(uc32 c) { 49 inline int HexValue(uc32 c) {
50 c -= '0'; 50 c -= '0';
51 if (static_cast<unsigned>(c) <= 9) return c; 51 if (static_cast<unsigned>(c) <= 9) return c;
52 c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36. 52 c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36.
53 if (static_cast<unsigned>(c) <= 5) return c + 10; 53 if (static_cast<unsigned>(c) <= 5) return c + 10;
54 return -1; 54 return -1;
55 } 55 }
56 56
57 57
58 #ifndef V8_USE_GENERATED_LEXER
59
60
58 // --------------------------------------------------------------------- 61 // ---------------------------------------------------------------------
59 // Buffered stream of UTF-16 code units, using an internal UTF-16 buffer. 62 // Buffered stream of UTF-16 code units, using an internal UTF-16 buffer.
60 // A code unit is a 16 bit value representing either a 16 bit code point 63 // A code unit is a 16 bit value representing either a 16 bit code point
61 // or one part of a surrogate pair that make a single 21 bit code point. 64 // or one part of a surrogate pair that make a single 21 bit code point.
62 65
63 class Utf16CharacterStream { 66 class Utf16CharacterStream {
64 public: 67 public:
65 Utf16CharacterStream() : pos_(0) { } 68 Utf16CharacterStream() : pos_(0) { }
66 virtual ~Utf16CharacterStream() { } 69 virtual ~Utf16CharacterStream() { }
67 70
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // are more code_units available, return true. 119 // are more code_units available, return true.
117 virtual bool ReadBlock() = 0; 120 virtual bool ReadBlock() = 0;
118 virtual unsigned SlowSeekForward(unsigned code_unit_count) = 0; 121 virtual unsigned SlowSeekForward(unsigned code_unit_count) = 0;
119 122
120 const uc16* buffer_cursor_; 123 const uc16* buffer_cursor_;
121 const uc16* buffer_end_; 124 const uc16* buffer_end_;
122 unsigned pos_; 125 unsigned pos_;
123 }; 126 };
124 127
125 128
129 #else
130
131 class Utf16CharacterStream {
132 public:
133 enum StreamType {
134 kUtf8ToUtf16, kGenericStringUtf16, kExternalTwoByteStringUtf16
135 };
136
137 explicit Utf16CharacterStream(StreamType stream_type)
138 : stream_type_(stream_type) {}
139
140 const StreamType stream_type_;
141 };
142
143 #endif
144
145
126 // --------------------------------------------------------------------- 146 // ---------------------------------------------------------------------
127 // Caching predicates used by scanners. 147 // Caching predicates used by scanners.
128 148
129 class UnicodeCache { 149 class UnicodeCache {
130 public: 150 public:
131 UnicodeCache() {} 151 UnicodeCache() {}
132 typedef unibrow::Utf8Decoder<512> Utf8Decoder; 152 typedef unibrow::Utf8Decoder<512> Utf8Decoder;
133 153
134 StaticResource<Utf8Decoder>* utf8_decoder() { 154 StaticResource<Utf8Decoder>* utf8_decoder() {
135 return &utf8_decoder_; 155 return &utf8_decoder_;
136 } 156 }
137 157
138 bool IsIdentifierStart(unibrow::uchar c) { return kIsIdentifierStart.get(c); } 158 bool IsIdentifierStart(unibrow::uchar c) { return kIsIdentifierStart.get(c); }
139 bool IsIdentifierPart(unibrow::uchar c) { return kIsIdentifierPart.get(c); } 159 bool IsIdentifierPart(unibrow::uchar c) { return kIsIdentifierPart.get(c); }
140 bool IsLineTerminator(unibrow::uchar c) { return kIsLineTerminator.get(c); } 160 bool IsLineTerminator(unibrow::uchar c) { return kIsLineTerminator.get(c); }
141 bool IsWhiteSpace(unibrow::uchar c) { return kIsWhiteSpace.get(c); } 161 bool IsWhiteSpace(unibrow::uchar c) { return kIsWhiteSpace.get(c); }
162 bool IsWhiteSpaceOrLineTerminator(unibrow::uchar c) {
163 return kIsWhiteSpaceOrLineTerminator.get(c);
164 }
142 bool IsByteOrderMark(unibrow::uchar c) { return c == 0xfffe || c == 0xfeff; } 165 bool IsByteOrderMark(unibrow::uchar c) { return c == 0xfffe || c == 0xfeff; }
143 bool IsWhiteSpaceNotLineTerminator(unibrow::uchar c) { 166 bool IsWhiteSpaceNotLineTerminator(unibrow::uchar c) {
144 return (kIsWhiteSpace.get(c) && !kIsLineTerminator.get(c)) || 167 return (kIsWhiteSpace.get(c) && !kIsLineTerminator.get(c)) ||
145 IsByteOrderMark(c); 168 IsByteOrderMark(c);
146 } 169 }
147 bool IsLetter(unibrow::uchar c) { return kIsLetter.get(c); } 170 bool IsLetter(unibrow::uchar c) { return kIsLetter.get(c); }
148 bool IsIdentifierPartNotLetter(unibrow::uchar c) { 171 bool IsIdentifierPartNotLetter(unibrow::uchar c) {
149 return kIsIdentifierPartNotLetter.get(c); 172 return kIsIdentifierPartNotLetter.get(c);
150 } 173 }
151 174
152 private: 175 private:
153 unibrow::Predicate<IdentifierStart, 128> kIsIdentifierStart; 176 unibrow::Predicate<IdentifierStart, 128> kIsIdentifierStart;
154 unibrow::Predicate<IdentifierPart, 128> kIsIdentifierPart; 177 unibrow::Predicate<IdentifierPart, 128> kIsIdentifierPart;
155 unibrow::Predicate<unibrow::LineTerminator, 128> kIsLineTerminator; 178 unibrow::Predicate<unibrow::LineTerminator, 128> kIsLineTerminator;
156 unibrow::Predicate<unibrow::WhiteSpace, 128> kIsWhiteSpace; 179 unibrow::Predicate<WhiteSpace, 128> kIsWhiteSpace;
157 unibrow::Predicate<unibrow::Letter, 128> kIsLetter; 180 unibrow::Predicate<unibrow::Letter, 128> kIsLetter;
158 unibrow::Predicate<IdentifierPartNotLetter, 128> kIsIdentifierPartNotLetter; 181 unibrow::Predicate<IdentifierPartNotLetter, 128> kIsIdentifierPartNotLetter;
182 unibrow::Predicate<WhiteSpaceOrLineTerminator, 128>
183 kIsWhiteSpaceOrLineTerminator;
159 StaticResource<Utf8Decoder> utf8_decoder_; 184 StaticResource<Utf8Decoder> utf8_decoder_;
160 185
161 DISALLOW_COPY_AND_ASSIGN(UnicodeCache); 186 DISALLOW_COPY_AND_ASSIGN(UnicodeCache);
162 }; 187 };
163 188
164 189
165 // --------------------------------------------------------------------- 190 // ---------------------------------------------------------------------
166 // DuplicateFinder discovers duplicate symbols. 191 // DuplicateFinder discovers duplicate symbols.
167 192
168 class DuplicateFinder { 193 class DuplicateFinder {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 339 }
315 340
316 bool is_ascii_; 341 bool is_ascii_;
317 int position_; 342 int position_;
318 Vector<byte> backing_store_; 343 Vector<byte> backing_store_;
319 344
320 DISALLOW_COPY_AND_ASSIGN(LiteralBuffer); 345 DISALLOW_COPY_AND_ASSIGN(LiteralBuffer);
321 }; 346 };
322 347
323 348
349 #ifndef V8_USE_GENERATED_LEXER
350
351
324 // ---------------------------------------------------------------------------- 352 // ----------------------------------------------------------------------------
325 // JavaScript Scanner. 353 // JavaScript Scanner.
326 354
327 class Scanner { 355 class Scanner {
328 public: 356 public:
329 // Scoped helper for literal recording. Automatically drops the literal 357 // Scoped helper for literal recording. Automatically drops the literal
330 // if aborting the scanning before it's complete. 358 // if aborting the scanning before it's complete.
331 class LiteralScope { 359 class LiteralScope {
332 public: 360 public:
333 explicit LiteralScope(Scanner* self) 361 explicit LiteralScope(Scanner* self)
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 // line-terminator after the current token, and before the next. 651 // line-terminator after the current token, and before the next.
624 bool has_multiline_comment_before_next_; 652 bool has_multiline_comment_before_next_;
625 // Whether we scan 'let' as a keyword for harmony block-scoped let bindings. 653 // Whether we scan 'let' as a keyword for harmony block-scoped let bindings.
626 bool harmony_scoping_; 654 bool harmony_scoping_;
627 // Whether we scan 'module', 'import', 'export' as keywords. 655 // Whether we scan 'module', 'import', 'export' as keywords.
628 bool harmony_modules_; 656 bool harmony_modules_;
629 // Whether we scan 0o777 and 0b111 as numbers. 657 // Whether we scan 0o777 and 0b111 as numbers.
630 bool harmony_numeric_literals_; 658 bool harmony_numeric_literals_;
631 }; 659 };
632 660
661
662 #endif
663
664
633 } } // namespace v8::internal 665 } } // namespace v8::internal
634 666
635 #endif // V8_SCANNER_H_ 667 #endif // V8_SCANNER_H_
OLDNEW
« no previous file with comments | « src/sampler.cc ('k') | src/scanner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698