Commit b36c60cc authored by vogelheim's avatar vogelheim Committed by Commit bot

Remove legacy API on Utf16CharacterStream.

BUG=v8:4947

Review-Url: https://codereview.chromium.org/2347883002
Cr-Commit-Position: refs/heads/master@{#39533}
parent df9d8c01
...@@ -3893,9 +3893,9 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( ...@@ -3893,9 +3893,9 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
formal_parameters.scope->AllowsLazyParsing()); formal_parameters.scope->AllowsLazyParsing());
if (is_lazily_parsed) { if (is_lazily_parsed) {
Scanner::BookmarkScope bookmark(scanner()); Scanner::BookmarkScope bookmark(scanner());
bool may_abort = bookmark.Set(); bookmark.Set();
LazyParsingResult result = impl()->SkipLazyFunctionBody( LazyParsingResult result = impl()->SkipLazyFunctionBody(
&materialized_literal_count, &expected_property_count, may_abort, &materialized_literal_count, &expected_property_count, true,
CHECK_OK); CHECK_OK);
if (formal_parameters.materialized_literals_count > 0) { if (formal_parameters.materialized_literals_count > 0) {
......
...@@ -3032,10 +3032,10 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -3032,10 +3032,10 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// eagerly. // eagerly.
if (is_lazily_parsed) { if (is_lazily_parsed) {
Scanner::BookmarkScope bookmark(scanner()); Scanner::BookmarkScope bookmark(scanner());
bool may_abort = bookmark.Set(); bookmark.Set();
LazyParsingResult result = LazyParsingResult result =
SkipLazyFunctionBody(&materialized_literal_count, SkipLazyFunctionBody(&materialized_literal_count,
&expected_property_count, may_abort, CHECK_OK); &expected_property_count, true, CHECK_OK);
materialized_literal_count += formals.materialized_literals_count + materialized_literal_count += formals.materialized_literals_count +
function_state.materialized_literal_count(); function_state.materialized_literal_count();
......
...@@ -19,9 +19,6 @@ ...@@ -19,9 +19,6 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
const size_t Utf16CharacterStream::kNoBookmark =
std::numeric_limits<size_t>::max();
Handle<String> Scanner::LiteralBuffer::Internalize(Isolate* isolate) const { Handle<String> Scanner::LiteralBuffer::Internalize(Isolate* isolate) const {
if (is_one_byte()) { if (is_one_byte()) {
return isolate->factory()->InternalizeOneByteString(one_byte_literal()); return isolate->factory()->InternalizeOneByteString(one_byte_literal());
...@@ -30,13 +27,13 @@ Handle<String> Scanner::LiteralBuffer::Internalize(Isolate* isolate) const { ...@@ -30,13 +27,13 @@ Handle<String> Scanner::LiteralBuffer::Internalize(Isolate* isolate) const {
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Scanner // Scanner
Scanner::Scanner(UnicodeCache* unicode_cache) Scanner::Scanner(UnicodeCache* unicode_cache)
: unicode_cache_(unicode_cache), : unicode_cache_(unicode_cache),
bookmark_c0_(kNoBookmark), bookmark_c0_(kNoBookmark),
bookmark_position_(0),
octal_pos_(Location::invalid()), octal_pos_(Location::invalid()),
decimal_with_leading_zero_pos_(Location::invalid()), decimal_with_leading_zero_pos_(Location::invalid()),
found_html_comment_(false) { found_html_comment_(false) {
...@@ -789,7 +786,7 @@ void Scanner::SeekForward(int pos) { ...@@ -789,7 +786,7 @@ void Scanner::SeekForward(int pos) {
// Positions inside the lookahead token aren't supported. // Positions inside the lookahead token aren't supported.
DCHECK(pos >= current_pos); DCHECK(pos >= current_pos);
if (pos != current_pos) { if (pos != current_pos) {
source_->SeekForward(pos - source_->pos()); source_->Seek(pos);
Advance(); Advance();
// This function is only called to seek to the location // This function is only called to seek to the location
// of the end of a function (at the "}" token). It doesn't matter // of the end of a function (at the "}" token). It doesn't matter
...@@ -1584,23 +1581,20 @@ int Scanner::FindSymbol(DuplicateFinder* finder, int value) { ...@@ -1584,23 +1581,20 @@ int Scanner::FindSymbol(DuplicateFinder* finder, int value) {
return finder->AddTwoByteSymbol(literal_two_byte_string(), value); return finder->AddTwoByteSymbol(literal_two_byte_string(), value);
} }
void Scanner::SetBookmark() {
bool Scanner::SetBookmark() { DCHECK_EQ(bookmark_c0_, kNoBookmark);
if (c0_ != kNoBookmark && bookmark_c0_ == kNoBookmark && DCHECK_EQ(next_next_.token, Token::UNINITIALIZED);
next_next_.token == Token::UNINITIALIZED && source_->SetBookmark()) { bookmark_c0_ = c0_;
bookmark_c0_ = c0_; bookmark_position_ = source_->pos();
CopyTokenDesc(&bookmark_current_, &current_); CopyTokenDesc(&bookmark_current_, &current_);
CopyTokenDesc(&bookmark_next_, &next_); CopyTokenDesc(&bookmark_next_, &next_);
return true;
}
return false;
} }
void Scanner::ResetToBookmark() { void Scanner::ResetToBookmark() {
DCHECK(BookmarkHasBeenSet()); // Caller hasn't called SetBookmark. DCHECK(BookmarkHasBeenSet()); // Caller hasn't called SetBookmark.
source_->ResetToBookmark(); source_->Seek(bookmark_position_);
c0_ = bookmark_c0_; c0_ = bookmark_c0_;
CopyToNextTokenDesc(&bookmark_current_); CopyToNextTokenDesc(&bookmark_current_);
current_ = next_; current_ = next_;
......
...@@ -92,44 +92,14 @@ class Utf16CharacterStream { ...@@ -92,44 +92,14 @@ class Utf16CharacterStream {
} }
} }
// Legacy API:
void SeekForward(size_t code_unit_count) { Seek(pos() + code_unit_count); }
void PushBack(int32_t code_unit) {
Back();
#ifdef DEBUG
uc32 t = Advance();
DCHECK_EQ(t, code_unit);
Back();
#endif // DEBUG
}
void PushBack2(int32_t code_unit_back_1, int32_t code_unit_back_2) {
Back2();
#ifdef DEBUG
DCHECK_EQ(Advance(), code_unit_back_2);
DCHECK_EQ(Advance(), code_unit_back_1);
Back2();
#endif // DEBUG
}
bool SetBookmark() {
bookmark_ = pos();
return true;
}
void ResetToBookmark() {
DCHECK_NE(bookmark_, kNoBookmark);
Seek(bookmark_);
}
protected: protected:
static const size_t kNoBookmark;
Utf16CharacterStream(const uint16_t* buffer_start, Utf16CharacterStream(const uint16_t* buffer_start,
const uint16_t* buffer_cursor, const uint16_t* buffer_cursor,
const uint16_t* buffer_end, size_t buffer_pos) const uint16_t* buffer_end, size_t buffer_pos)
: buffer_start_(buffer_start), : buffer_start_(buffer_start),
buffer_cursor_(buffer_cursor), buffer_cursor_(buffer_cursor),
buffer_end_(buffer_end), buffer_end_(buffer_end),
buffer_pos_(buffer_pos), buffer_pos_(buffer_pos) {}
bookmark_(kNoBookmark) {}
Utf16CharacterStream() : Utf16CharacterStream(nullptr, nullptr, nullptr, 0) {} Utf16CharacterStream() : Utf16CharacterStream(nullptr, nullptr, nullptr, 0) {}
void ReadBlockAt(size_t new_pos) { void ReadBlockAt(size_t new_pos) {
...@@ -173,7 +143,6 @@ class Utf16CharacterStream { ...@@ -173,7 +143,6 @@ class Utf16CharacterStream {
const uint16_t* buffer_cursor_; const uint16_t* buffer_cursor_;
const uint16_t* buffer_end_; const uint16_t* buffer_end_;
size_t buffer_pos_; size_t buffer_pos_;
size_t bookmark_;
}; };
...@@ -190,7 +159,7 @@ class Scanner { ...@@ -190,7 +159,7 @@ class Scanner {
} }
~BookmarkScope() { scanner_->DropBookmark(); } ~BookmarkScope() { scanner_->DropBookmark(); }
bool Set() { return scanner_->SetBookmark(); } void Set() { scanner_->SetBookmark(); }
void Reset() { scanner_->ResetToBookmark(); } void Reset() { scanner_->ResetToBookmark(); }
bool HasBeenSet() { return scanner_->BookmarkHasBeenSet(); } bool HasBeenSet() { return scanner_->BookmarkHasBeenSet(); }
bool HasBeenReset() { return scanner_->BookmarkHasBeenReset(); } bool HasBeenReset() { return scanner_->BookmarkHasBeenReset(); }
...@@ -560,7 +529,7 @@ class Scanner { ...@@ -560,7 +529,7 @@ class Scanner {
} }
// Support BookmarkScope functionality. // Support BookmarkScope functionality.
bool SetBookmark(); void SetBookmark();
void ResetToBookmark(); void ResetToBookmark();
bool BookmarkHasBeenSet(); bool BookmarkHasBeenSet();
bool BookmarkHasBeenReset(); bool BookmarkHasBeenReset();
...@@ -649,7 +618,7 @@ class Scanner { ...@@ -649,7 +618,7 @@ class Scanner {
if (unibrow::Utf16::IsLeadSurrogate(c0_)) { if (unibrow::Utf16::IsLeadSurrogate(c0_)) {
uc32 c1 = source_->Advance(); uc32 c1 = source_->Advance();
if (!unibrow::Utf16::IsTrailSurrogate(c1)) { if (!unibrow::Utf16::IsTrailSurrogate(c1)) {
source_->PushBack(c1); source_->Back();
} else { } else {
c0_ = unibrow::Utf16::CombineSurrogatePair(c0_, c1); c0_ = unibrow::Utf16::CombineSurrogatePair(c0_, c1);
} }
...@@ -658,10 +627,9 @@ class Scanner { ...@@ -658,10 +627,9 @@ class Scanner {
void PushBack(uc32 ch) { void PushBack(uc32 ch) {
if (c0_ > static_cast<uc32>(unibrow::Utf16::kMaxNonSurrogateCharCode)) { if (c0_ > static_cast<uc32>(unibrow::Utf16::kMaxNonSurrogateCharCode)) {
source_->PushBack(unibrow::Utf16::TrailSurrogate(c0_)); source_->Back2();
source_->PushBack(unibrow::Utf16::LeadSurrogate(c0_));
} else { } else {
source_->PushBack(c0_); source_->Back();
} }
c0_ = ch; c0_ = ch;
} }
...@@ -845,6 +813,7 @@ class Scanner { ...@@ -845,6 +813,7 @@ class Scanner {
static const uc32 kNoBookmark = -2; static const uc32 kNoBookmark = -2;
static const uc32 kBookmarkWasApplied = -3; static const uc32 kBookmarkWasApplied = -3;
uc32 bookmark_c0_; uc32 bookmark_c0_;
size_t bookmark_position_;
TokenDesc bookmark_current_; TokenDesc bookmark_current_;
TokenDesc bookmark_next_; TokenDesc bookmark_next_;
LiteralBuffer bookmark_current_literal_; LiteralBuffer bookmark_current_literal_;
......
...@@ -184,21 +184,21 @@ void TestCharacterStream(const char* reference, i::Utf16CharacterStream* stream, ...@@ -184,21 +184,21 @@ void TestCharacterStream(const char* reference, i::Utf16CharacterStream* stream,
while (i > end / 4) { while (i > end / 4) {
int32_t c0 = reference[i - 1]; int32_t c0 = reference[i - 1];
CHECK_EQU(i, stream->pos()); CHECK_EQU(i, stream->pos());
stream->PushBack(c0); stream->Back();
i--; i--;
CHECK_EQU(i, stream->pos()); CHECK_EQU(i, stream->pos());
int32_t c1 = stream->Advance(); int32_t c1 = stream->Advance();
i++; i++;
CHECK_EQU(i, stream->pos()); CHECK_EQU(i, stream->pos());
CHECK_EQ(c0, c1); CHECK_EQ(c0, c1);
stream->PushBack(c0); stream->Back();
i--; i--;
CHECK_EQU(i, stream->pos()); CHECK_EQU(i, stream->pos());
} }
// Seek + read streams one char at a time. // Seek + read streams one char at a time.
unsigned halfway = end / 2; unsigned halfway = end / 2;
stream->SeekForward(halfway - i); stream->Seek(stream->pos() + halfway - i);
for (i = halfway; i < end; i++) { for (i = halfway; i < end; i++) {
CHECK_EQU(i, stream->pos()); CHECK_EQU(i, stream->pos());
CHECK_EQU(reference[i], stream->Advance()); CHECK_EQU(reference[i], stream->Advance());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment