| 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/scanner.h" | 7 #include "src/scanner.h" |
| 8 | 8 |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 Token::ILLEGAL | 230 Token::ILLEGAL |
| 231 }; | 231 }; |
| 232 | 232 |
| 233 | 233 |
| 234 Token::Value Scanner::Next() { | 234 Token::Value Scanner::Next() { |
| 235 if (next_.token == Token::EOS) { | 235 if (next_.token == Token::EOS) { |
| 236 next_.location.beg_pos = current_.location.beg_pos; | 236 next_.location.beg_pos = current_.location.beg_pos; |
| 237 next_.location.end_pos = current_.location.end_pos; | 237 next_.location.end_pos = current_.location.end_pos; |
| 238 } | 238 } |
| 239 current_ = next_; | 239 current_ = next_; |
| 240 if (V8_UNLIKELY(next_next_.token != Token::UNINITIALIZED)) { |
| 241 next_ = next_next_; |
| 242 next_next_.token = Token::UNINITIALIZED; |
| 243 return current_.token; |
| 244 } |
| 240 has_line_terminator_before_next_ = false; | 245 has_line_terminator_before_next_ = false; |
| 241 has_multiline_comment_before_next_ = false; | 246 has_multiline_comment_before_next_ = false; |
| 242 if (static_cast<unsigned>(c0_) <= 0x7f) { | 247 if (static_cast<unsigned>(c0_) <= 0x7f) { |
| 243 Token::Value token = static_cast<Token::Value>(one_char_tokens[c0_]); | 248 Token::Value token = static_cast<Token::Value>(one_char_tokens[c0_]); |
| 244 if (token != Token::ILLEGAL) { | 249 if (token != Token::ILLEGAL) { |
| 245 int pos = source_pos(); | 250 int pos = source_pos(); |
| 246 next_.token = token; | 251 next_.token = token; |
| 247 next_.location.beg_pos = pos; | 252 next_.location.beg_pos = pos; |
| 248 next_.location.end_pos = pos + 1; | 253 next_.location.end_pos = pos + 1; |
| 249 Advance(); | 254 Advance(); |
| 250 return current_.token; | 255 return current_.token; |
| 251 } | 256 } |
| 252 } | 257 } |
| 253 Scan(); | 258 Scan(); |
| 254 return current_.token; | 259 return current_.token; |
| 255 } | 260 } |
| 256 | 261 |
| 257 | 262 |
| 263 Token::Value Scanner::PeekAhead() { |
| 264 if (next_next_.token != Token::UNINITIALIZED) { |
| 265 return next_next_.token; |
| 266 } |
| 267 TokenDesc prev = current_; |
| 268 Next(); |
| 269 Token::Value ret = next_.token; |
| 270 next_next_ = next_; |
| 271 next_ = current_; |
| 272 current_ = prev; |
| 273 return ret; |
| 274 } |
| 275 |
| 276 |
| 258 // TODO(yangguo): check whether this is actually necessary. | 277 // TODO(yangguo): check whether this is actually necessary. |
| 259 static inline bool IsLittleEndianByteOrderMark(uc32 c) { | 278 static inline bool IsLittleEndianByteOrderMark(uc32 c) { |
| 260 // The Unicode value U+FFFE is guaranteed never to be assigned as a | 279 // The Unicode value U+FFFE is guaranteed never to be assigned as a |
| 261 // Unicode character; this implies that in a Unicode context the | 280 // Unicode character; this implies that in a Unicode context the |
| 262 // 0xFF, 0xFE byte pattern can only be interpreted as the U+FEFF | 281 // 0xFF, 0xFE byte pattern can only be interpreted as the U+FEFF |
| 263 // character expressed in little-endian byte order (since it could | 282 // character expressed in little-endian byte order (since it could |
| 264 // not be a U+FFFE character expressed in big-endian byte | 283 // not be a U+FFFE character expressed in big-endian byte |
| 265 // order). Nevertheless, we check for it to be compatible with | 284 // order). Nevertheless, we check for it to be compatible with |
| 266 // Spidermonkey. | 285 // Spidermonkey. |
| 267 return c == 0xFFFE; | 286 return c == 0xFFFE; |
| (...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 int Scanner::FindSymbol(DuplicateFinder* finder, int value) { | 1444 int Scanner::FindSymbol(DuplicateFinder* finder, int value) { |
| 1426 if (is_literal_one_byte()) { | 1445 if (is_literal_one_byte()) { |
| 1427 return finder->AddOneByteSymbol(literal_one_byte_string(), value); | 1446 return finder->AddOneByteSymbol(literal_one_byte_string(), value); |
| 1428 } | 1447 } |
| 1429 return finder->AddTwoByteSymbol(literal_two_byte_string(), value); | 1448 return finder->AddTwoByteSymbol(literal_two_byte_string(), value); |
| 1430 } | 1449 } |
| 1431 | 1450 |
| 1432 | 1451 |
| 1433 bool Scanner::SetBookmark() { | 1452 bool Scanner::SetBookmark() { |
| 1434 if (c0_ != kNoBookmark && bookmark_c0_ == kNoBookmark && | 1453 if (c0_ != kNoBookmark && bookmark_c0_ == kNoBookmark && |
| 1435 source_->SetBookmark()) { | 1454 next_next_.token == Token::UNINITIALIZED && source_->SetBookmark()) { |
| 1436 bookmark_c0_ = c0_; | 1455 bookmark_c0_ = c0_; |
| 1437 CopyTokenDesc(&bookmark_current_, ¤t_); | 1456 CopyTokenDesc(&bookmark_current_, ¤t_); |
| 1438 CopyTokenDesc(&bookmark_next_, &next_); | 1457 CopyTokenDesc(&bookmark_next_, &next_); |
| 1439 return true; | 1458 return true; |
| 1440 } | 1459 } |
| 1441 return false; | 1460 return false; |
| 1442 } | 1461 } |
| 1443 | 1462 |
| 1444 | 1463 |
| 1445 void Scanner::ResetToBookmark() { | 1464 void Scanner::ResetToBookmark() { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1633 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
| 1615 } | 1634 } |
| 1616 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1635 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
| 1617 | 1636 |
| 1618 backing_store_.AddBlock(bytes); | 1637 backing_store_.AddBlock(bytes); |
| 1619 return backing_store_.EndSequence().start(); | 1638 return backing_store_.EndSequence().start(); |
| 1620 } | 1639 } |
| 1621 | 1640 |
| 1622 } // namespace internal | 1641 } // namespace internal |
| 1623 } // namespace v8 | 1642 } // namespace v8 |
| OLD | NEW |