Commit a1995eca authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[scanner] Mark source_ and is_module as const and initialize in constructor

Change-Id: I692ce8dbe3169cfb912647c31a9e8121dc5eff5d
Reviewed-on: https://chromium-review.googlesource.com/1183306
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55268}
parent d9770a27
...@@ -412,7 +412,8 @@ Parser::Parser(ParseInfo* info) ...@@ -412,7 +412,8 @@ Parser::Parser(ParseInfo* info)
info->runtime_call_stats(), info->logger(), info->runtime_call_stats(), info->logger(),
info->script().is_null() ? -1 : info->script()->id(), info->script().is_null() ? -1 : info->script()->id(),
info->is_module(), true), info->is_module(), true),
scanner_(info->unicode_cache()), scanner_(info->unicode_cache(), info->character_stream(),
info->is_module()),
reusable_preparser_(nullptr), reusable_preparser_(nullptr),
mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
source_range_map_(info->source_range_map()), source_range_map_(info->source_range_map()),
...@@ -507,7 +508,7 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { ...@@ -507,7 +508,7 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
// Initialize parser state. // Initialize parser state.
DeserializeScopeChain(isolate, info, info->maybe_outer_scope_info()); DeserializeScopeChain(isolate, info, info->maybe_outer_scope_info());
scanner_.Initialize(info->character_stream(), info->is_module()); scanner_.Initialize();
FunctionLiteral* result = DoParseProgram(isolate, info); FunctionLiteral* result = DoParseProgram(isolate, info);
MaybeResetCharacterStream(info, result); MaybeResetCharacterStream(info, result);
...@@ -701,7 +702,7 @@ FunctionLiteral* Parser::ParseFunction(Isolate* isolate, ParseInfo* info, ...@@ -701,7 +702,7 @@ FunctionLiteral* Parser::ParseFunction(Isolate* isolate, ParseInfo* info,
// Initialize parser state. // Initialize parser state.
Handle<String> name(shared_info->Name(), isolate); Handle<String> name(shared_info->Name(), isolate);
info->set_function_name(ast_value_factory()->GetString(name)); info->set_function_name(ast_value_factory()->GetString(name));
scanner_.Initialize(info->character_stream(), info->is_module()); scanner_.Initialize();
FunctionLiteral* result = FunctionLiteral* result =
DoParseFunction(isolate, info, info->function_name()); DoParseFunction(isolate, info, info->function_name());
...@@ -3447,7 +3448,7 @@ void Parser::ParseOnBackground(ParseInfo* info) { ...@@ -3447,7 +3448,7 @@ void Parser::ParseOnBackground(ParseInfo* info) {
DCHECK_NULL(info->literal()); DCHECK_NULL(info->literal());
FunctionLiteral* result = nullptr; FunctionLiteral* result = nullptr;
scanner_.Initialize(info->character_stream(), info->is_module()); scanner_.Initialize();
DCHECK(info->maybe_outer_scope_info().is_null()); DCHECK(info->maybe_outer_scope_info().is_null());
DCHECK(original_scope_); DCHECK(original_scope_);
......
...@@ -170,8 +170,10 @@ bool Scanner::BookmarkScope::HasBeenApplied() { ...@@ -170,8 +170,10 @@ bool Scanner::BookmarkScope::HasBeenApplied() {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Scanner // Scanner
Scanner::Scanner(UnicodeCache* unicode_cache) Scanner::Scanner(UnicodeCache* unicode_cache, Utf16CharacterStream* source,
bool is_module)
: unicode_cache_(unicode_cache), : unicode_cache_(unicode_cache),
source_(source),
octal_pos_(Location::invalid()), octal_pos_(Location::invalid()),
octal_message_(MessageTemplate::kNone), octal_message_(MessageTemplate::kNone),
has_line_terminator_before_next_(false), has_line_terminator_before_next_(false),
...@@ -179,12 +181,12 @@ Scanner::Scanner(UnicodeCache* unicode_cache) ...@@ -179,12 +181,12 @@ Scanner::Scanner(UnicodeCache* unicode_cache)
has_line_terminator_after_next_(false), has_line_terminator_after_next_(false),
found_html_comment_(false), found_html_comment_(false),
allow_harmony_bigint_(false), allow_harmony_bigint_(false),
allow_harmony_numeric_separator_(false) {} allow_harmony_numeric_separator_(false),
is_module_(is_module) {
void Scanner::Initialize(Utf16CharacterStream* source, bool is_module) {
DCHECK_NOT_NULL(source); DCHECK_NOT_NULL(source);
source_ = source; }
is_module_ = is_module;
void Scanner::Initialize() {
// Need to capture identifiers in order to recognize "get" and "set" // Need to capture identifiers in order to recognize "get" and "set"
// in object literals. // in object literals.
Init(); Init();
......
...@@ -223,9 +223,10 @@ class Scanner { ...@@ -223,9 +223,10 @@ class Scanner {
static const int kNoOctalLocation = -1; static const int kNoOctalLocation = -1;
static const uc32 kEndOfInput = Utf16CharacterStream::kEndOfInput; static const uc32 kEndOfInput = Utf16CharacterStream::kEndOfInput;
explicit Scanner(UnicodeCache* scanner_contants); explicit Scanner(UnicodeCache* scanner_contants, Utf16CharacterStream* source,
bool is_module);
void Initialize(Utf16CharacterStream* source, bool is_module); void Initialize();
// Returns the next token and advances input. // Returns the next token and advances input.
Token::Value Next(); Token::Value Next();
...@@ -773,8 +774,6 @@ class Scanner { ...@@ -773,8 +774,6 @@ class Scanner {
template <bool capture_raw> template <bool capture_raw>
uc32 ScanUnicodeEscape(); uc32 ScanUnicodeEscape();
bool is_module_;
Token::Value ScanTemplateSpan(); Token::Value ScanTemplateSpan();
// Return the current source position. // Return the current source position.
...@@ -818,7 +817,7 @@ class Scanner { ...@@ -818,7 +817,7 @@ class Scanner {
TokenDesc next_next_; // desc for the token after next (after PeakAhead()) TokenDesc next_next_; // desc for the token after next (after PeakAhead())
// Input stream. Must be initialized to an Utf16CharacterStream. // Input stream. Must be initialized to an Utf16CharacterStream.
Utf16CharacterStream* source_; Utf16CharacterStream* const source_;
// Last-seen positions of potentially problematic tokens. // Last-seen positions of potentially problematic tokens.
Location octal_pos_; Location octal_pos_;
...@@ -844,6 +843,8 @@ class Scanner { ...@@ -844,6 +843,8 @@ class Scanner {
bool allow_harmony_private_fields_; bool allow_harmony_private_fields_;
bool allow_harmony_numeric_separator_; bool allow_harmony_numeric_separator_;
const bool is_module_;
MessageTemplate::Template scanner_error_; MessageTemplate::Template scanner_error_;
Location scanner_error_location_; Location scanner_error_location_;
}; };
......
...@@ -38,9 +38,9 @@ ScannerTestHelper make_scanner(const char* src) { ...@@ -38,9 +38,9 @@ ScannerTestHelper make_scanner(const char* src) {
ScannerTestHelper helper; ScannerTestHelper helper;
helper.unicode_cache = std::unique_ptr<UnicodeCache>(new UnicodeCache); helper.unicode_cache = std::unique_ptr<UnicodeCache>(new UnicodeCache);
helper.stream = ScannerStream::ForTesting(src); helper.stream = ScannerStream::ForTesting(src);
helper.scanner = helper.scanner = std::unique_ptr<Scanner>(
std::unique_ptr<Scanner>(new Scanner(helper.unicode_cache.get())); new Scanner(helper.unicode_cache.get(), helper.stream.get(), false));
helper.scanner->Initialize(helper.stream.get(), false); helper.scanner->Initialize();
return helper; return helper;
} }
......
...@@ -92,16 +92,16 @@ TEST(ScanKeywords) { ...@@ -92,16 +92,16 @@ TEST(ScanKeywords) {
CHECK(static_cast<int>(sizeof(buffer)) >= length); CHECK(static_cast<int>(sizeof(buffer)) >= length);
{ {
auto stream = i::ScannerStream::ForTesting(keyword, length); auto stream = i::ScannerStream::ForTesting(keyword, length);
i::Scanner scanner(&unicode_cache); i::Scanner scanner(&unicode_cache, stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
CHECK_EQ(key_token.token, scanner.Next()); CHECK_EQ(key_token.token, scanner.Next());
CHECK_EQ(i::Token::EOS, scanner.Next()); CHECK_EQ(i::Token::EOS, scanner.Next());
} }
// Removing characters will make keyword matching fail. // Removing characters will make keyword matching fail.
{ {
auto stream = i::ScannerStream::ForTesting(keyword, length - 1); auto stream = i::ScannerStream::ForTesting(keyword, length - 1);
i::Scanner scanner(&unicode_cache); i::Scanner scanner(&unicode_cache, stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
CHECK_EQ(i::Token::EOS, scanner.Next()); CHECK_EQ(i::Token::EOS, scanner.Next());
} }
...@@ -111,8 +111,8 @@ TEST(ScanKeywords) { ...@@ -111,8 +111,8 @@ TEST(ScanKeywords) {
i::MemMove(buffer, keyword, length); i::MemMove(buffer, keyword, length);
buffer[length] = chars_to_append[j]; buffer[length] = chars_to_append[j];
auto stream = i::ScannerStream::ForTesting(buffer, length + 1); auto stream = i::ScannerStream::ForTesting(buffer, length + 1);
i::Scanner scanner(&unicode_cache); i::Scanner scanner(&unicode_cache, stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
CHECK_EQ(i::Token::EOS, scanner.Next()); CHECK_EQ(i::Token::EOS, scanner.Next());
} }
...@@ -121,8 +121,8 @@ TEST(ScanKeywords) { ...@@ -121,8 +121,8 @@ TEST(ScanKeywords) {
i::MemMove(buffer, keyword, length); i::MemMove(buffer, keyword, length);
buffer[length - 1] = '_'; buffer[length - 1] = '_';
auto stream = i::ScannerStream::ForTesting(buffer, length); auto stream = i::ScannerStream::ForTesting(buffer, length);
i::Scanner scanner(&unicode_cache); i::Scanner scanner(&unicode_cache, stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
CHECK_EQ(i::Token::EOS, scanner.Next()); CHECK_EQ(i::Token::EOS, scanner.Next());
} }
...@@ -188,8 +188,8 @@ TEST(ScanHTMLEndComments) { ...@@ -188,8 +188,8 @@ TEST(ScanHTMLEndComments) {
for (int i = 0; tests[i]; i++) { for (int i = 0; tests[i]; i++) {
const char* source = tests[i]; const char* source = tests[i];
auto stream = i::ScannerStream::ForTesting(source); auto stream = i::ScannerStream::ForTesting(source);
i::Scanner scanner(i_isolate->unicode_cache()); i::Scanner scanner(i_isolate->unicode_cache(), stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
i::Zone zone(i_isolate->allocator(), ZONE_NAME); i::Zone zone(i_isolate->allocator(), ZONE_NAME);
i::AstValueFactory ast_value_factory(&zone, i::AstValueFactory ast_value_factory(&zone,
i_isolate->ast_string_constants(), i_isolate->ast_string_constants(),
...@@ -207,8 +207,8 @@ TEST(ScanHTMLEndComments) { ...@@ -207,8 +207,8 @@ TEST(ScanHTMLEndComments) {
for (int i = 0; fail_tests[i]; i++) { for (int i = 0; fail_tests[i]; i++) {
const char* source = fail_tests[i]; const char* source = fail_tests[i];
auto stream = i::ScannerStream::ForTesting(source); auto stream = i::ScannerStream::ForTesting(source);
i::Scanner scanner(i_isolate->unicode_cache()); i::Scanner scanner(i_isolate->unicode_cache(), stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
i::Zone zone(i_isolate->allocator(), ZONE_NAME); i::Zone zone(i_isolate->allocator(), ZONE_NAME);
i::AstValueFactory ast_value_factory(&zone, i::AstValueFactory ast_value_factory(&zone,
i_isolate->ast_string_constants(), i_isolate->ast_string_constants(),
...@@ -232,8 +232,8 @@ TEST(ScanHtmlComments) { ...@@ -232,8 +232,8 @@ TEST(ScanHtmlComments) {
// Disallow HTML comments. // Disallow HTML comments.
{ {
auto stream = i::ScannerStream::ForTesting(src); auto stream = i::ScannerStream::ForTesting(src);
i::Scanner scanner(&unicode_cache); i::Scanner scanner(&unicode_cache, stream.get(), true);
scanner.Initialize(stream.get(), true); scanner.Initialize();
CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
CHECK_EQ(i::Token::ILLEGAL, scanner.Next()); CHECK_EQ(i::Token::ILLEGAL, scanner.Next());
} }
...@@ -241,8 +241,8 @@ TEST(ScanHtmlComments) { ...@@ -241,8 +241,8 @@ TEST(ScanHtmlComments) {
// Skip HTML comments: // Skip HTML comments:
{ {
auto stream = i::ScannerStream::ForTesting(src); auto stream = i::ScannerStream::ForTesting(src);
i::Scanner scanner(&unicode_cache); i::Scanner scanner(&unicode_cache, stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); CHECK_EQ(i::Token::IDENTIFIER, scanner.Next());
CHECK_EQ(i::Token::EOS, scanner.Next()); CHECK_EQ(i::Token::EOS, scanner.Next());
} }
...@@ -280,8 +280,8 @@ TEST(StandAlonePreParser) { ...@@ -280,8 +280,8 @@ TEST(StandAlonePreParser) {
uintptr_t stack_limit = i_isolate->stack_guard()->real_climit(); uintptr_t stack_limit = i_isolate->stack_guard()->real_climit();
for (int i = 0; programs[i]; i++) { for (int i = 0; programs[i]; i++) {
auto stream = i::ScannerStream::ForTesting(programs[i]); auto stream = i::ScannerStream::ForTesting(programs[i]);
i::Scanner scanner(i_isolate->unicode_cache()); i::Scanner scanner(i_isolate->unicode_cache(), stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
i::Zone zone(i_isolate->allocator(), ZONE_NAME); i::Zone zone(i_isolate->allocator(), ZONE_NAME);
i::AstValueFactory ast_value_factory(&zone, i::AstValueFactory ast_value_factory(&zone,
...@@ -313,8 +313,8 @@ TEST(StandAlonePreParserNoNatives) { ...@@ -313,8 +313,8 @@ TEST(StandAlonePreParserNoNatives) {
uintptr_t stack_limit = isolate->stack_guard()->real_climit(); uintptr_t stack_limit = isolate->stack_guard()->real_climit();
for (int i = 0; programs[i]; i++) { for (int i = 0; programs[i]; i++) {
auto stream = i::ScannerStream::ForTesting(programs[i]); auto stream = i::ScannerStream::ForTesting(programs[i]);
i::Scanner scanner(isolate->unicode_cache()); i::Scanner scanner(isolate->unicode_cache(), stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
// Preparser defaults to disallowing natives syntax. // Preparser defaults to disallowing natives syntax.
i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
...@@ -348,8 +348,8 @@ TEST(RegressChromium62639) { ...@@ -348,8 +348,8 @@ TEST(RegressChromium62639) {
// failed in debug mode, and sometimes crashed in release mode. // failed in debug mode, and sometimes crashed in release mode.
auto stream = i::ScannerStream::ForTesting(program); auto stream = i::ScannerStream::ForTesting(program);
i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
i::AstValueFactory ast_value_factory( i::AstValueFactory ast_value_factory(
&zone, CcTest::i_isolate()->ast_string_constants(), &zone, CcTest::i_isolate()->ast_string_constants(),
...@@ -381,8 +381,8 @@ TEST(PreParseOverflow) { ...@@ -381,8 +381,8 @@ TEST(PreParseOverflow) {
uintptr_t stack_limit = isolate->stack_guard()->real_climit(); uintptr_t stack_limit = isolate->stack_guard()->real_climit();
auto stream = i::ScannerStream::ForTesting(program.get(), kProgramSize); auto stream = i::ScannerStream::ForTesting(program.get(), kProgramSize);
i::Scanner scanner(isolate->unicode_cache()); i::Scanner scanner(isolate->unicode_cache(), stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
i::AstValueFactory ast_value_factory( i::AstValueFactory ast_value_factory(
...@@ -400,8 +400,8 @@ void TestStreamScanner(i::Utf16CharacterStream* stream, ...@@ -400,8 +400,8 @@ void TestStreamScanner(i::Utf16CharacterStream* stream,
i::Token::Value* expected_tokens, i::Token::Value* expected_tokens,
int skip_pos = 0, // Zero means not skipping. int skip_pos = 0, // Zero means not skipping.
int skip_to = 0) { int skip_to = 0) {
i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), stream, false);
scanner.Initialize(stream, false); scanner.Initialize();
int i = 0; int i = 0;
do { do {
...@@ -478,8 +478,8 @@ TEST(StreamScanner) { ...@@ -478,8 +478,8 @@ TEST(StreamScanner) {
void TestScanRegExp(const char* re_source, const char* expected) { void TestScanRegExp(const char* re_source, const char* expected) {
auto stream = i::ScannerStream::ForTesting(re_source); auto stream = i::ScannerStream::ForTesting(re_source);
i::HandleScope scope(CcTest::i_isolate()); i::HandleScope scope(CcTest::i_isolate());
i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), stream.get(), false);
scanner.Initialize(stream.get(), false); scanner.Initialize();
i::Token::Value start = scanner.peek(); i::Token::Value start = scanner.peek();
CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV);
...@@ -1171,9 +1171,9 @@ void TestParserSyncWithFlags(i::Handle<i::String> source, ...@@ -1171,9 +1171,9 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
// Preparse the data. // Preparse the data.
i::PendingCompilationErrorHandler pending_error_handler; i::PendingCompilationErrorHandler pending_error_handler;
if (test_preparser) { if (test_preparser) {
i::Scanner scanner(isolate->unicode_cache());
std::unique_ptr<i::Utf16CharacterStream> stream( std::unique_ptr<i::Utf16CharacterStream> stream(
i::ScannerStream::For(isolate, source)); i::ScannerStream::For(isolate, source));
i::Scanner scanner(isolate->unicode_cache(), stream.get(), is_module);
i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
i::AstValueFactory ast_value_factory( i::AstValueFactory ast_value_factory(
&zone, CcTest::i_isolate()->ast_string_constants(), &zone, CcTest::i_isolate()->ast_string_constants(),
...@@ -1183,7 +1183,7 @@ void TestParserSyncWithFlags(i::Handle<i::String> source, ...@@ -1183,7 +1183,7 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
isolate->counters()->runtime_call_stats(), isolate->counters()->runtime_call_stats(),
isolate->logger(), -1, is_module); isolate->logger(), -1, is_module);
SetParserFlags(&preparser, flags); SetParserFlags(&preparser, flags);
scanner.Initialize(stream.get(), is_module); scanner.Initialize();
i::PreParser::PreParseResult result = preparser.PreParseProgram(); i::PreParser::PreParseResult result = preparser.PreParseProgram();
CHECK_EQ(i::PreParser::kPreParseSuccess, result); CHECK_EQ(i::PreParser::kPreParseSuccess, result);
} }
......
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