Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 | 23 |
| 24 Handle<String> LiteralBuffer::Internalize(Isolate* isolate) const { | 24 Handle<String> LiteralBuffer::Internalize(Isolate* isolate) const { |
| 25 if (is_one_byte()) { | 25 if (is_one_byte()) { |
| 26 return isolate->factory()->InternalizeOneByteString(one_byte_literal()); | 26 return isolate->factory()->InternalizeOneByteString(one_byte_literal()); |
| 27 } | 27 } |
| 28 return isolate->factory()->InternalizeTwoByteString(two_byte_literal()); | 28 return isolate->factory()->InternalizeTwoByteString(two_byte_literal()); |
| 29 } | 29 } |
| 30 | 30 |
| 31 | 31 |
| 32 // 'Safe' default implementation for streams that do not support bookmarks. | |
| 33 bool Utf16CharacterStream::SetBookmark() { return false; } | |
| 34 bool Utf16CharacterStream::CanResetToBookmark() { return false; } | |
|
marja
2015/04/22 16:40:56
I don't get why we need CanResetToBookmark; if Set
| |
| 35 bool Utf16CharacterStream::ResetToBookmark() { return false; } | |
|
marja
2015/04/22 16:40:56
Also here, if we successfully set a bookmark, I'd
| |
| 36 | |
| 37 | |
|
marja
2015/04/22 16:40:56
... or is there some logic here like "this bookmar
vogelheim
2015/04/22 17:08:35
(answered elsewhere:) The idea is to support a str
| |
| 32 // ---------------------------------------------------------------------------- | 38 // ---------------------------------------------------------------------------- |
| 33 // Scanner | 39 // Scanner |
| 34 | 40 |
| 35 Scanner::Scanner(UnicodeCache* unicode_cache) | 41 Scanner::Scanner(UnicodeCache* unicode_cache) |
| 36 : unicode_cache_(unicode_cache), | 42 : unicode_cache_(unicode_cache), |
| 43 bookmark_c0_(-1), | |
| 37 octal_pos_(Location::invalid()), | 44 octal_pos_(Location::invalid()), |
| 38 harmony_modules_(false), | 45 harmony_modules_(false), |
| 39 harmony_classes_(false), | 46 harmony_classes_(false), |
| 40 harmony_unicode_(false) {} | 47 harmony_unicode_(false) {} |
| 41 | 48 |
| 42 | 49 |
| 43 void Scanner::Initialize(Utf16CharacterStream* source) { | 50 void Scanner::Initialize(Utf16CharacterStream* source) { |
| 44 source_ = source; | 51 source_ = source; |
| 45 // Need to capture identifiers in order to recognize "get" and "set" | 52 // Need to capture identifiers in order to recognize "get" and "set" |
| 46 // in object literals. | 53 // in object literals. |
| (...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1419 | 1426 |
| 1420 | 1427 |
| 1421 int Scanner::FindSymbol(DuplicateFinder* finder, int value) { | 1428 int Scanner::FindSymbol(DuplicateFinder* finder, int value) { |
| 1422 if (is_literal_one_byte()) { | 1429 if (is_literal_one_byte()) { |
| 1423 return finder->AddOneByteSymbol(literal_one_byte_string(), value); | 1430 return finder->AddOneByteSymbol(literal_one_byte_string(), value); |
| 1424 } | 1431 } |
| 1425 return finder->AddTwoByteSymbol(literal_two_byte_string(), value); | 1432 return finder->AddTwoByteSymbol(literal_two_byte_string(), value); |
| 1426 } | 1433 } |
| 1427 | 1434 |
| 1428 | 1435 |
| 1436 bool Scanner::SetBookmark() { | |
| 1437 bool can_bookmark = (bookmark_c0_ == -1) && source_->SetBookmark(); | |
| 1438 if (can_bookmark) { | |
| 1439 bookmark_c0_ = c0_; | |
| 1440 bookmark_current_ = current_; | |
| 1441 bookmark_current_.literal_chars = nullptr; | |
| 1442 bookmark_current_.raw_literal_chars = nullptr; | |
| 1443 bookmark_next_ = next_; | |
| 1444 bookmark_next_.literal_chars = nullptr; | |
| 1445 bookmark_next_.raw_literal_chars = nullptr; | |
| 1446 bookmark_literal_.CopyFrom(next_.literal_chars); | |
| 1447 bookmark_raw_literal_.CopyFrom(next_.raw_literal_chars); | |
| 1448 } | |
| 1449 return can_bookmark; | |
| 1450 } | |
| 1451 | |
| 1452 | |
| 1453 bool Scanner::ResetToBookmark() { | |
| 1454 DCHECK(bookmark_c0_ >= 0); // Caller hasn't called SetBookmark. | |
| 1455 bool can_reset = CanResetBookmark(); | |
| 1456 if (can_reset) { | |
| 1457 source_->ResetToBookmark(); | |
| 1458 next_ = bookmark_next_; | |
| 1459 current_ = bookmark_current_; | |
| 1460 c0_ = bookmark_c0_; | |
| 1461 | |
| 1462 next_.literal_chars = &literal_buffer1_; | |
| 1463 next_.literal_chars->CopyFrom(&bookmark_literal_); | |
| 1464 next_.raw_literal_chars = &raw_literal_buffer1_; | |
| 1465 next_.raw_literal_chars->CopyFrom(&bookmark_raw_literal_); | |
| 1466 | |
| 1467 bookmark_c0_ = -2; | |
| 1468 } | |
| 1469 | |
| 1470 return can_reset; | |
| 1471 } | |
| 1472 | |
| 1473 | |
| 1474 bool Scanner::CanResetBookmark() { | |
| 1475 return source_->CanResetToBookmark() && BookmarkHasBeenSet(); | |
| 1476 } | |
| 1477 | |
| 1478 | |
| 1479 bool Scanner::BookmarkHasBeenSet() { return bookmark_c0_ >= 0; } | |
| 1480 | |
| 1481 | |
| 1482 bool Scanner::BookmarkHasBeenReset() { return bookmark_c0_ == -2; } | |
| 1483 | |
| 1484 | |
| 1485 void Scanner::DropBookmark() { bookmark_c0_ = -1; } | |
| 1486 | |
| 1487 | |
| 1429 int DuplicateFinder::AddOneByteSymbol(Vector<const uint8_t> key, int value) { | 1488 int DuplicateFinder::AddOneByteSymbol(Vector<const uint8_t> key, int value) { |
| 1430 return AddSymbol(key, true, value); | 1489 return AddSymbol(key, true, value); |
| 1431 } | 1490 } |
| 1432 | 1491 |
| 1433 | 1492 |
| 1434 int DuplicateFinder::AddTwoByteSymbol(Vector<const uint16_t> key, int value) { | 1493 int DuplicateFinder::AddTwoByteSymbol(Vector<const uint16_t> key, int value) { |
| 1435 return AddSymbol(Vector<const uint8_t>::cast(key), false, value); | 1494 return AddSymbol(Vector<const uint8_t>::cast(key), false, value); |
| 1436 } | 1495 } |
| 1437 | 1496 |
| 1438 | 1497 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1559 } | 1618 } |
| 1560 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1619 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
| 1561 } | 1620 } |
| 1562 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1621 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
| 1563 | 1622 |
| 1564 backing_store_.AddBlock(bytes); | 1623 backing_store_.AddBlock(bytes); |
| 1565 return backing_store_.EndSequence().start(); | 1624 return backing_store_.EndSequence().start(); |
| 1566 } | 1625 } |
| 1567 | 1626 |
| 1568 } } // namespace v8::internal | 1627 } } // namespace v8::internal |
| OLD | NEW |