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 #include "src/parsing/scanner.h" | 7 #include "src/parsing/scanner.h" |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 | 242 |
243 Token::Value Scanner::Next() { | 243 Token::Value Scanner::Next() { |
244 if (next_.token == Token::EOS) { | 244 if (next_.token == Token::EOS) { |
245 next_.location.beg_pos = current_.location.beg_pos; | 245 next_.location.beg_pos = current_.location.beg_pos; |
246 next_.location.end_pos = current_.location.end_pos; | 246 next_.location.end_pos = current_.location.end_pos; |
247 } | 247 } |
248 current_ = next_; | 248 current_ = next_; |
249 if (V8_UNLIKELY(next_next_.token != Token::UNINITIALIZED)) { | 249 if (V8_UNLIKELY(next_next_.token != Token::UNINITIALIZED)) { |
250 next_ = next_next_; | 250 next_ = next_next_; |
251 next_next_.token = Token::UNINITIALIZED; | 251 next_next_.token = Token::UNINITIALIZED; |
252 has_line_terminator_before_next_ = has_line_terminator_before_next2_; | |
253 has_multiline_comment_before_next_ = has_multiline_comment_before_next2_; | |
252 return current_.token; | 254 return current_.token; |
253 } | 255 } |
254 has_line_terminator_before_next_ = false; | 256 has_line_terminator_before_next_ = false; |
255 has_multiline_comment_before_next_ = false; | 257 has_multiline_comment_before_next_ = false; |
256 if (static_cast<unsigned>(c0_) <= 0x7f) { | 258 if (static_cast<unsigned>(c0_) <= 0x7f) { |
257 Token::Value token = static_cast<Token::Value>(one_char_tokens[c0_]); | 259 Token::Value token = static_cast<Token::Value>(one_char_tokens[c0_]); |
258 if (token != Token::ILLEGAL) { | 260 if (token != Token::ILLEGAL) { |
259 int pos = source_pos(); | 261 int pos = source_pos(); |
260 next_.token = token; | 262 next_.token = token; |
261 next_.location.beg_pos = pos; | 263 next_.location.beg_pos = pos; |
262 next_.location.end_pos = pos + 1; | 264 next_.location.end_pos = pos + 1; |
263 Advance(); | 265 Advance(); |
264 return current_.token; | 266 return current_.token; |
265 } | 267 } |
266 } | 268 } |
267 Scan(); | 269 Scan(); |
268 return current_.token; | 270 return current_.token; |
269 } | 271 } |
270 | 272 |
271 | 273 |
272 Token::Value Scanner::PeekAhead() { | 274 Token::Value Scanner::PeekAhead() { |
273 if (next_next_.token != Token::UNINITIALIZED) { | 275 if (next_next_.token != Token::UNINITIALIZED) { |
274 return next_next_.token; | 276 return next_next_.token; |
275 } | 277 } |
276 TokenDesc prev = current_; | 278 TokenDesc prev = current_; |
279 bool has_line_terminator_before_next = has_line_terminator_before_next_; | |
280 bool has_multiline_comment_before_next = has_multiline_comment_before_next_; | |
277 Next(); | 281 Next(); |
282 has_line_terminator_before_next2_ = has_line_terminator_before_next_; | |
283 has_multiline_comment_before_next2_ = has_multiline_comment_before_next_; | |
284 has_line_terminator_before_next_ = has_line_terminator_before_next; | |
285 has_multiline_comment_before_next_ = has_multiline_comment_before_next; | |
Dan Ehrenberg
2016/05/05 01:14:40
From my experience with let, I'd predict that main
caitp (gmail)
2016/05/05 01:36:57
Well, I've done this in the simplest way I could,
caitp (gmail)
2016/05/05 21:49:36
I've had a go at refactoring this --- I doubt it h
| |
278 Token::Value ret = next_.token; | 286 Token::Value ret = next_.token; |
279 next_next_ = next_; | 287 next_next_ = next_; |
280 next_ = current_; | 288 next_ = current_; |
281 current_ = prev; | 289 current_ = prev; |
282 return ret; | 290 return ret; |
283 } | 291 } |
284 | 292 |
285 | 293 |
286 // TODO(yangguo): check whether this is actually necessary. | 294 // TODO(yangguo): check whether this is actually necessary. |
287 static inline bool IsLittleEndianByteOrderMark(uc32 c) { | 295 static inline bool IsLittleEndianByteOrderMark(uc32 c) { |
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1462 } | 1470 } |
1463 | 1471 |
1464 | 1472 |
1465 const AstRawString* Scanner::NextSymbol(AstValueFactory* ast_value_factory) { | 1473 const AstRawString* Scanner::NextSymbol(AstValueFactory* ast_value_factory) { |
1466 if (is_next_literal_one_byte()) { | 1474 if (is_next_literal_one_byte()) { |
1467 return ast_value_factory->GetOneByteString(next_literal_one_byte_string()); | 1475 return ast_value_factory->GetOneByteString(next_literal_one_byte_string()); |
1468 } | 1476 } |
1469 return ast_value_factory->GetTwoByteString(next_literal_two_byte_string()); | 1477 return ast_value_factory->GetTwoByteString(next_literal_two_byte_string()); |
1470 } | 1478 } |
1471 | 1479 |
1480 const AstRawString* Scanner::NextNextSymbol( | |
1481 AstValueFactory* ast_value_factory) { | |
1482 DCHECK(next_next_.token != Token::UNINITIALIZED); | |
1483 LiteralBuffer* literal = next_next_.literal_chars; | |
1484 if (literal->is_one_byte()) { | |
1485 return ast_value_factory->GetOneByteString(literal->one_byte_literal()); | |
1486 } | |
1487 return ast_value_factory->GetTwoByteString(literal->two_byte_literal()); | |
1488 } | |
1472 | 1489 |
1473 const AstRawString* Scanner::CurrentRawSymbol( | 1490 const AstRawString* Scanner::CurrentRawSymbol( |
1474 AstValueFactory* ast_value_factory) { | 1491 AstValueFactory* ast_value_factory) { |
1475 if (is_raw_literal_one_byte()) { | 1492 if (is_raw_literal_one_byte()) { |
1476 return ast_value_factory->GetOneByteString(raw_literal_one_byte_string()); | 1493 return ast_value_factory->GetOneByteString(raw_literal_one_byte_string()); |
1477 } | 1494 } |
1478 return ast_value_factory->GetTwoByteString(raw_literal_two_byte_string()); | 1495 return ast_value_factory->GetTwoByteString(raw_literal_two_byte_string()); |
1479 } | 1496 } |
1480 | 1497 |
1481 | 1498 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1687 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1704 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
1688 } | 1705 } |
1689 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1706 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
1690 | 1707 |
1691 backing_store_.AddBlock(bytes); | 1708 backing_store_.AddBlock(bytes); |
1692 return backing_store_.EndSequence().start(); | 1709 return backing_store_.EndSequence().start(); |
1693 } | 1710 } |
1694 | 1711 |
1695 } // namespace internal | 1712 } // namespace internal |
1696 } // namespace v8 | 1713 } // namespace v8 |
OLD | NEW |