Commit 503eb3cd authored by marja@chromium.org's avatar marja@chromium.org

Parser cleanup: less member variables.

Parser had unnecessary member pointers to stuff stored in the
CompilationInfo (which Parser also points to).

As we add more parsing code paths (in particular, script streaming), this gets
confusing and Parser and CompilationInfo can get out of sync.

BUG=
R=jochen@chromium.org, rossberg@chromium.org

Review URL: https://codereview.chromium.org/527233003

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23861 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a311c26d
...@@ -266,9 +266,9 @@ void Parser::SetCachedData() { ...@@ -266,9 +266,9 @@ void Parser::SetCachedData() {
Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) {
DCHECK(ast_value_factory_); DCHECK(ast_value_factory());
Scope* result = Scope* result =
new (zone()) Scope(parent, scope_type, ast_value_factory_, zone()); new (zone()) Scope(parent, scope_type, ast_value_factory(), zone());
result->Initialize(); result->Initialize();
return result; return result;
} }
...@@ -361,8 +361,8 @@ class ParserTraits::Checkpoint ...@@ -361,8 +361,8 @@ class ParserTraits::Checkpoint
bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const {
return identifier == parser_->ast_value_factory_->eval_string() || return identifier == parser_->ast_value_factory()->eval_string() ||
identifier == parser_->ast_value_factory_->arguments_string(); identifier == parser_->ast_value_factory()->arguments_string();
} }
...@@ -387,7 +387,7 @@ void ParserTraits::PushPropertyName(FuncNameInferrer* fni, ...@@ -387,7 +387,7 @@ void ParserTraits::PushPropertyName(FuncNameInferrer* fni,
fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName());
} else { } else {
fni->PushLiteralName( fni->PushLiteralName(
parser_->ast_value_factory_->anonymous_function_string()); parser_->ast_value_factory()->anonymous_function_string());
} }
} }
...@@ -406,7 +406,7 @@ void ParserTraits::CheckPossibleEvalCall(Expression* expression, ...@@ -406,7 +406,7 @@ void ParserTraits::CheckPossibleEvalCall(Expression* expression,
Scope* scope) { Scope* scope) {
VariableProxy* callee = expression->AsVariableProxy(); VariableProxy* callee = expression->AsVariableProxy();
if (callee != NULL && if (callee != NULL &&
callee->raw_name() == parser_->ast_value_factory_->eval_string()) { callee->raw_name() == parser_->ast_value_factory()->eval_string()) {
scope->DeclarationScope()->RecordEvalCall(); scope->DeclarationScope()->RecordEvalCall();
} }
} }
...@@ -526,21 +526,21 @@ Expression* ParserTraits::BuildUnaryExpression( ...@@ -526,21 +526,21 @@ Expression* ParserTraits::BuildUnaryExpression(
Expression* ParserTraits::NewThrowReferenceError(const char* message, int pos) { Expression* ParserTraits::NewThrowReferenceError(const char* message, int pos) {
return NewThrowError( return NewThrowError(
parser_->ast_value_factory_->make_reference_error_string(), message, NULL, parser_->ast_value_factory()->make_reference_error_string(), message,
pos); NULL, pos);
} }
Expression* ParserTraits::NewThrowSyntaxError( Expression* ParserTraits::NewThrowSyntaxError(
const char* message, const AstRawString* arg, int pos) { const char* message, const AstRawString* arg, int pos) {
return NewThrowError(parser_->ast_value_factory_->make_syntax_error_string(), return NewThrowError(parser_->ast_value_factory()->make_syntax_error_string(),
message, arg, pos); message, arg, pos);
} }
Expression* ParserTraits::NewThrowTypeError( Expression* ParserTraits::NewThrowTypeError(
const char* message, const AstRawString* arg, int pos) { const char* message, const AstRawString* arg, int pos) {
return NewThrowError(parser_->ast_value_factory_->make_type_error_string(), return NewThrowError(parser_->ast_value_factory()->make_type_error_string(),
message, arg, pos); message, arg, pos);
} }
...@@ -551,7 +551,7 @@ Expression* ParserTraits::NewThrowError( ...@@ -551,7 +551,7 @@ Expression* ParserTraits::NewThrowError(
Zone* zone = parser_->zone(); Zone* zone = parser_->zone();
int argc = arg != NULL ? 1 : 0; int argc = arg != NULL ? 1 : 0;
const AstRawString* type = const AstRawString* type =
parser_->ast_value_factory_->GetOneByteString(message); parser_->ast_value_factory()->GetOneByteString(message);
ZoneList<const AstRawString*>* array = ZoneList<const AstRawString*>* array =
new (zone) ZoneList<const AstRawString*>(argc, zone); new (zone) ZoneList<const AstRawString*>(argc, zone);
if (arg != NULL) { if (arg != NULL) {
...@@ -622,7 +622,7 @@ void ParserTraits::ReportMessageAt(Scanner::Location source_location, ...@@ -622,7 +622,7 @@ void ParserTraits::ReportMessageAt(Scanner::Location source_location,
const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) { const AstRawString* ParserTraits::GetSymbol(Scanner* scanner) {
const AstRawString* result = const AstRawString* result =
parser_->scanner()->CurrentSymbol(parser_->ast_value_factory_); parser_->scanner()->CurrentSymbol(parser_->ast_value_factory());
DCHECK(result != NULL); DCHECK(result != NULL);
return result; return result;
} }
...@@ -638,7 +638,7 @@ const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) { ...@@ -638,7 +638,7 @@ const AstRawString* ParserTraits::GetNumberAsSymbol(Scanner* scanner) {
const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) {
return parser_->scanner()->NextSymbol(parser_->ast_value_factory_); return parser_->scanner()->NextSymbol(parser_->ast_value_factory());
} }
...@@ -738,14 +738,11 @@ Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) ...@@ -738,14 +738,11 @@ Parser::Parser(CompilationInfo* info, ParseInfo* parse_info)
: ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit, : ParserBase<ParserTraits>(&scanner_, parse_info->stack_limit,
info->extension(), NULL, info->zone(), info->extension(), NULL, info->zone(),
info->ast_node_id_gen(), this), info->ast_node_id_gen(), this),
isolate_(info->isolate()),
script_(info->script()),
scanner_(parse_info->unicode_cache), scanner_(parse_info->unicode_cache),
reusable_preparser_(NULL), reusable_preparser_(NULL),
original_scope_(NULL), original_scope_(NULL),
target_stack_(NULL), target_stack_(NULL),
cached_parse_data_(NULL), cached_parse_data_(NULL),
ast_value_factory_(info->ast_value_factory()),
info_(info), info_(info),
has_pending_error_(false), has_pending_error_(false),
pending_error_message_(NULL), pending_error_message_(NULL),
...@@ -753,7 +750,7 @@ Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) ...@@ -753,7 +750,7 @@ Parser::Parser(CompilationInfo* info, ParseInfo* parse_info)
pending_error_char_arg_(NULL), pending_error_char_arg_(NULL),
total_preparse_skipped_(0), total_preparse_skipped_(0),
pre_parse_timer_(NULL) { pre_parse_timer_(NULL) {
DCHECK(!script_.is_null()); DCHECK(!script().is_null());
set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
set_allow_modules(!info->is_native() && FLAG_harmony_modules); set_allow_modules(!info->is_native() && FLAG_harmony_modules);
set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
...@@ -767,8 +764,10 @@ Parser::Parser(CompilationInfo* info, ParseInfo* parse_info) ...@@ -767,8 +764,10 @@ Parser::Parser(CompilationInfo* info, ParseInfo* parse_info)
++feature) { ++feature) {
use_counts_[feature] = 0; use_counts_[feature] = 0;
} }
if (ast_value_factory_ == NULL) { if (info->ast_value_factory() == NULL) {
ast_value_factory_ = new AstValueFactory(zone(), parse_info->hash_seed); // info takes ownership of AstValueFactory.
info->SetAstValueFactory(
new AstValueFactory(zone(), parse_info->hash_seed));
} }
} }
...@@ -780,13 +779,13 @@ FunctionLiteral* Parser::ParseProgram() { ...@@ -780,13 +779,13 @@ FunctionLiteral* Parser::ParseProgram() {
// It's OK to use the counters here, since this function is only called in // It's OK to use the counters here, since this function is only called in
// the main thread. // the main thread.
HistogramTimerScope timer_scope(isolate()->counters()->parse(), true); HistogramTimerScope timer_scope(isolate()->counters()->parse(), true);
Handle<String> source(String::cast(script_->source())); Handle<String> source(String::cast(script()->source()));
isolate()->counters()->total_parse_size()->Increment(source->length()); isolate()->counters()->total_parse_size()->Increment(source->length());
base::ElapsedTimer timer; base::ElapsedTimer timer;
if (FLAG_trace_parse) { if (FLAG_trace_parse) {
timer.Start(); timer.Start();
} }
fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone()); fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone());
// Initialize parser state. // Initialize parser state.
CompleteParserRecorder recorder; CompleteParserRecorder recorder;
...@@ -849,7 +848,7 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, ...@@ -849,7 +848,7 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
// means the Parser cannot operate independent of the V8 heap. Tell the // means the Parser cannot operate independent of the V8 heap. Tell the
// string table to internalize strings and values right after they're // string table to internalize strings and values right after they're
// created. // created.
ast_value_factory_->Internalize(isolate()); ast_value_factory()->Internalize(isolate());
} }
original_scope_ = scope; original_scope_ = scope;
if (info->is_eval()) { if (info->is_eval()) {
...@@ -873,7 +872,7 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, ...@@ -873,7 +872,7 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
// Enters 'scope'. // Enters 'scope'.
FunctionState function_state(&function_state_, &scope_, scope, zone(), FunctionState function_state(&function_state_, &scope_, scope, zone(),
ast_value_factory_, info->ast_node_id_gen()); ast_value_factory(), info->ast_node_id_gen());
scope_->SetStrictMode(info->strict_mode()); scope_->SetStrictMode(info->strict_mode());
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
...@@ -901,8 +900,8 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, ...@@ -901,8 +900,8 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
if (ok) { if (ok) {
result = factory()->NewFunctionLiteral( result = factory()->NewFunctionLiteral(
ast_value_factory_->empty_string(), ast_value_factory_, scope_, body, ast_value_factory()->empty_string(), ast_value_factory(), scope_,
function_state.materialized_literal_count(), body, function_state.materialized_literal_count(),
function_state.expected_property_count(), function_state.expected_property_count(),
function_state.handler_count(), 0, function_state.handler_count(), 0,
FunctionLiteral::kNoDuplicateParameters, FunctionLiteral::kNoDuplicateParameters,
...@@ -925,7 +924,7 @@ FunctionLiteral* Parser::ParseLazy() { ...@@ -925,7 +924,7 @@ FunctionLiteral* Parser::ParseLazy() {
// It's OK to use the counters here, since this function is only called in // It's OK to use the counters here, since this function is only called in
// the main thread. // the main thread.
HistogramTimerScope timer_scope(isolate()->counters()->parse_lazy()); HistogramTimerScope timer_scope(isolate()->counters()->parse_lazy());
Handle<String> source(String::cast(script_->source())); Handle<String> source(String::cast(script()->source()));
isolate()->counters()->total_parse_size()->Increment(source->length()); isolate()->counters()->total_parse_size()->Increment(source->length());
base::ElapsedTimer timer; base::ElapsedTimer timer;
if (FLAG_trace_parse) { if (FLAG_trace_parse) {
...@@ -965,9 +964,9 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { ...@@ -965,9 +964,9 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
DCHECK(target_stack_ == NULL); DCHECK(target_stack_ == NULL);
Handle<String> name(String::cast(shared_info->name())); Handle<String> name(String::cast(shared_info->name()));
DCHECK(ast_value_factory_); DCHECK(ast_value_factory());
fni_ = new(zone()) FuncNameInferrer(ast_value_factory_, zone()); fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone());
const AstRawString* raw_name = ast_value_factory_->GetString(name); const AstRawString* raw_name = ast_value_factory()->GetString(name);
fni_->PushEnclosingName(raw_name); fni_->PushEnclosingName(raw_name);
ParsingModeScope parsing_mode(this, PARSE_EAGERLY); ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
...@@ -985,7 +984,8 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { ...@@ -985,7 +984,8 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
} }
original_scope_ = scope; original_scope_ = scope;
FunctionState function_state(&function_state_, &scope_, scope, zone(), FunctionState function_state(&function_state_, &scope_, scope, zone(),
ast_value_factory_, info()->ast_node_id_gen()); ast_value_factory(),
info()->ast_node_id_gen());
DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT);
DCHECK(info()->strict_mode() == shared_info->strict_mode()); DCHECK(info()->strict_mode() == shared_info->strict_mode());
scope->SetStrictMode(shared_info->strict_mode()); scope->SetStrictMode(shared_info->strict_mode());
...@@ -1068,9 +1068,9 @@ void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, ...@@ -1068,9 +1068,9 @@ void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
// one can be present. // one can be present.
if (strict_mode() == SLOPPY && if (strict_mode() == SLOPPY &&
literal->raw_value()->AsString() == literal->raw_value()->AsString() ==
ast_value_factory_->use_strict_string() && ast_value_factory()->use_strict_string() &&
token_loc.end_pos - token_loc.beg_pos == token_loc.end_pos - token_loc.beg_pos ==
ast_value_factory_->use_strict_string()->length() + 2) { ast_value_factory()->use_strict_string()->length() + 2) {
// TODO(mstarzinger): Global strict eval calls, need their own scope // TODO(mstarzinger): Global strict eval calls, need their own scope
// as specified in ES5 10.4.2(3). The correct fix would be to always // as specified in ES5 10.4.2(3). The correct fix would be to always
// add this scope in DoParseProgram(), but that requires adaptations // add this scope in DoParseProgram(), but that requires adaptations
...@@ -1088,9 +1088,9 @@ void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, ...@@ -1088,9 +1088,9 @@ void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
// "use strict" is the only directive for now. // "use strict" is the only directive for now.
directive_prologue = false; directive_prologue = false;
} else if (literal->raw_value()->AsString() == } else if (literal->raw_value()->AsString() ==
ast_value_factory_->use_asm_string() && ast_value_factory()->use_asm_string() &&
token_loc.end_pos - token_loc.beg_pos == token_loc.end_pos - token_loc.beg_pos ==
ast_value_factory_->use_asm_string()->length() + 2) { ast_value_factory()->use_asm_string()->length() + 2) {
// Store the usage count; The actual use counter on the isolate is // Store the usage count; The actual use counter on the isolate is
// incremented after parsing is done. // incremented after parsing is done.
++use_counts_[v8::Isolate::kUseAsm]; ++use_counts_[v8::Isolate::kUseAsm];
...@@ -1149,7 +1149,7 @@ Statement* Parser::ParseModuleElement(ZoneList<const AstRawString*>* labels, ...@@ -1149,7 +1149,7 @@ Statement* Parser::ParseModuleElement(ZoneList<const AstRawString*>* labels,
ExpressionStatement* estmt = stmt->AsExpressionStatement(); ExpressionStatement* estmt = stmt->AsExpressionStatement();
if (estmt != NULL && estmt->expression()->AsVariableProxy() != NULL && if (estmt != NULL && estmt->expression()->AsVariableProxy() != NULL &&
estmt->expression()->AsVariableProxy()->raw_name() == estmt->expression()->AsVariableProxy()->raw_name() ==
ast_value_factory_->module_string() && ast_value_factory()->module_string() &&
!scanner()->literal_contains_escapes()) { !scanner()->literal_contains_escapes()) {
return ParseModuleDeclaration(NULL, ok); return ParseModuleDeclaration(NULL, ok);
} }
...@@ -1447,7 +1447,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { ...@@ -1447,7 +1447,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
const AstRawString* name = const AstRawString* name =
ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK);
// Handle 'module' as a context-sensitive keyword. // Handle 'module' as a context-sensitive keyword.
if (name != ast_value_factory_->module_string()) { if (name != ast_value_factory()->module_string()) {
names.Add(name, zone()); names.Add(name, zone());
while (peek() == Token::COMMA) { while (peek() == Token::COMMA) {
Consume(Token::COMMA); Consume(Token::COMMA);
...@@ -2222,9 +2222,9 @@ Block* Parser::ParseVariableDeclarations( ...@@ -2222,9 +2222,9 @@ Block* Parser::ParseVariableDeclarations(
// Note that the function does different things depending on // Note that the function does different things depending on
// the number of arguments (1 or 2). // the number of arguments (1 or 2).
initialize = factory()->NewCallRuntime( initialize = factory()->NewCallRuntime(
ast_value_factory_->initialize_const_global_string(), ast_value_factory()->initialize_const_global_string(),
Runtime::FunctionForId(Runtime::kInitializeConstGlobal), Runtime::FunctionForId(Runtime::kInitializeConstGlobal), arguments,
arguments, pos); pos);
} else { } else {
// Add strict mode. // Add strict mode.
// We may want to pass singleton to avoid Literal allocations. // We may want to pass singleton to avoid Literal allocations.
...@@ -2241,7 +2241,7 @@ Block* Parser::ParseVariableDeclarations( ...@@ -2241,7 +2241,7 @@ Block* Parser::ParseVariableDeclarations(
// Construct the call to Runtime_InitializeVarGlobal // Construct the call to Runtime_InitializeVarGlobal
// and add it to the initialization statement block. // and add it to the initialization statement block.
initialize = factory()->NewCallRuntime( initialize = factory()->NewCallRuntime(
ast_value_factory_->initialize_var_global_string(), ast_value_factory()->initialize_var_global_string(),
Runtime::FunctionForId(Runtime::kInitializeVarGlobal), arguments, Runtime::FunctionForId(Runtime::kInitializeVarGlobal), arguments,
pos); pos);
} else { } else {
...@@ -2356,25 +2356,22 @@ Statement* Parser::ParseExpressionOrLabelledStatement( ...@@ -2356,25 +2356,22 @@ Statement* Parser::ParseExpressionOrLabelledStatement(
// If we have an extension, we allow a native function declaration. // If we have an extension, we allow a native function declaration.
// A native function declaration starts with "native function" with // A native function declaration starts with "native function" with
// no line-terminator between the two words. // no line-terminator between the two words.
if (extension_ != NULL && if (extension_ != NULL && peek() == Token::FUNCTION &&
peek() == Token::FUNCTION && !scanner()->HasAnyLineTerminatorBeforeNext() && expr != NULL &&
!scanner()->HasAnyLineTerminatorBeforeNext() &&
expr != NULL &&
expr->AsVariableProxy() != NULL && expr->AsVariableProxy() != NULL &&
expr->AsVariableProxy()->raw_name() == expr->AsVariableProxy()->raw_name() ==
ast_value_factory_->native_string() && ast_value_factory()->native_string() &&
!scanner()->literal_contains_escapes()) { !scanner()->literal_contains_escapes()) {
return ParseNativeDeclaration(ok); return ParseNativeDeclaration(ok);
} }
// Parsed expression statement, or the context-sensitive 'module' keyword. // Parsed expression statement, or the context-sensitive 'module' keyword.
// Only expect semicolon in the former case. // Only expect semicolon in the former case.
if (!FLAG_harmony_modules || if (!FLAG_harmony_modules || peek() != Token::IDENTIFIER ||
peek() != Token::IDENTIFIER ||
scanner()->HasAnyLineTerminatorBeforeNext() || scanner()->HasAnyLineTerminatorBeforeNext() ||
expr->AsVariableProxy() == NULL || expr->AsVariableProxy() == NULL ||
expr->AsVariableProxy()->raw_name() != expr->AsVariableProxy()->raw_name() !=
ast_value_factory_->module_string() || ast_value_factory()->module_string() ||
scanner()->literal_contains_escapes()) { scanner()->literal_contains_escapes()) {
ExpectSemicolon(CHECK_OK); ExpectSemicolon(CHECK_OK);
} }
...@@ -2796,9 +2793,9 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, ...@@ -2796,9 +2793,9 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
if (for_of != NULL) { if (for_of != NULL) {
Variable* iterator = scope_->DeclarationScope()->NewTemporary( Variable* iterator = scope_->DeclarationScope()->NewTemporary(
ast_value_factory_->dot_iterator_string()); ast_value_factory()->dot_iterator_string());
Variable* result = scope_->DeclarationScope()->NewTemporary( Variable* result = scope_->DeclarationScope()->NewTemporary(
ast_value_factory_->dot_result_string()); ast_value_factory()->dot_result_string());
Expression* assign_iterator; Expression* assign_iterator;
Expression* next_result; Expression* next_result;
...@@ -2814,7 +2811,7 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, ...@@ -2814,7 +2811,7 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
{ {
Expression* iterator_proxy = factory()->NewVariableProxy(iterator); Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
Expression* next_literal = factory()->NewStringLiteral( Expression* next_literal = factory()->NewStringLiteral(
ast_value_factory_->next_string(), RelocInfo::kNoPosition); ast_value_factory()->next_string(), RelocInfo::kNoPosition);
Expression* next_property = factory()->NewProperty( Expression* next_property = factory()->NewProperty(
iterator_proxy, next_literal, RelocInfo::kNoPosition); iterator_proxy, next_literal, RelocInfo::kNoPosition);
ZoneList<Expression*>* next_arguments = ZoneList<Expression*>* next_arguments =
...@@ -2829,7 +2826,7 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, ...@@ -2829,7 +2826,7 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
// result.done // result.done
{ {
Expression* done_literal = factory()->NewStringLiteral( Expression* done_literal = factory()->NewStringLiteral(
ast_value_factory_->done_string(), RelocInfo::kNoPosition); ast_value_factory()->done_string(), RelocInfo::kNoPosition);
Expression* result_proxy = factory()->NewVariableProxy(result); Expression* result_proxy = factory()->NewVariableProxy(result);
result_done = factory()->NewProperty( result_done = factory()->NewProperty(
result_proxy, done_literal, RelocInfo::kNoPosition); result_proxy, done_literal, RelocInfo::kNoPosition);
...@@ -2838,7 +2835,7 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, ...@@ -2838,7 +2835,7 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
// each = result.value // each = result.value
{ {
Expression* value_literal = factory()->NewStringLiteral( Expression* value_literal = factory()->NewStringLiteral(
ast_value_factory_->value_string(), RelocInfo::kNoPosition); ast_value_factory()->value_string(), RelocInfo::kNoPosition);
Expression* result_proxy = factory()->NewVariableProxy(result); Expression* result_proxy = factory()->NewVariableProxy(result);
Expression* result_value = factory()->NewProperty( Expression* result_value = factory()->NewProperty(
result_proxy, value_literal, RelocInfo::kNoPosition); result_proxy, value_literal, RelocInfo::kNoPosition);
...@@ -2901,7 +2898,7 @@ Statement* Parser::DesugarLetBindingsInForStatement( ...@@ -2901,7 +2898,7 @@ Statement* Parser::DesugarLetBindingsInForStatement(
RelocInfo::kNoPosition); RelocInfo::kNoPosition);
outer_block->AddStatement(init, zone()); outer_block->AddStatement(init, zone());
const AstRawString* temp_name = ast_value_factory_->dot_for_string(); const AstRawString* temp_name = ast_value_factory()->dot_for_string();
// For each let variable x: // For each let variable x:
// make statement: temp_x = x. // make statement: temp_x = x.
...@@ -3099,7 +3096,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, ...@@ -3099,7 +3096,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// TODO(keuchel): Move the temporary variable to the block scope, after // TODO(keuchel): Move the temporary variable to the block scope, after
// implementing stack allocated block scoped variables. // implementing stack allocated block scoped variables.
Variable* temp = scope_->DeclarationScope()->NewTemporary( Variable* temp = scope_->DeclarationScope()->NewTemporary(
ast_value_factory_->dot_for_string()); ast_value_factory()->dot_for_string());
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
ForEachStatement* loop = ForEachStatement* loop =
factory()->NewForEachStatement(mode, labels, pos); factory()->NewForEachStatement(mode, labels, pos);
...@@ -3381,7 +3378,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -3381,7 +3378,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// We want a non-null handle as the function name. // We want a non-null handle as the function name.
if (should_infer_name) { if (should_infer_name) {
function_name = ast_value_factory_->empty_string(); function_name = ast_value_factory()->empty_string();
} }
int num_parameters = 0; int num_parameters = 0;
...@@ -3435,7 +3432,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -3435,7 +3432,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Parse function body. // Parse function body.
{ {
FunctionState function_state(&function_state_, &scope_, scope, zone(), FunctionState function_state(&function_state_, &scope_, scope, zone(),
ast_value_factory_, info()->ast_node_id_gen()); ast_value_factory(),
info()->ast_node_id_gen());
scope_->SetScopeName(function_name); scope_->SetScopeName(function_name);
if (is_generator) { if (is_generator) {
...@@ -3448,7 +3446,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -3448,7 +3446,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// in a temporary variable, a definition that is used by "yield" // in a temporary variable, a definition that is used by "yield"
// expressions. This also marks the FunctionState as a generator. // expressions. This also marks the FunctionState as a generator.
Variable* temp = scope_->DeclarationScope()->NewTemporary( Variable* temp = scope_->DeclarationScope()->NewTemporary(
ast_value_factory_->dot_generator_object_string()); ast_value_factory()->dot_generator_object_string());
function_state.set_generator_object_variable(temp); function_state.set_generator_object_variable(temp);
} }
...@@ -3606,7 +3604,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -3606,7 +3604,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
} }
FunctionLiteral* function_literal = factory()->NewFunctionLiteral( FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
function_name, ast_value_factory_, scope, body, function_name, ast_value_factory(), scope, body,
materialized_literal_count, expected_property_count, handler_count, materialized_literal_count, expected_property_count, handler_count,
num_parameters, duplicate_parameters, function_type, num_parameters, duplicate_parameters, function_type,
FunctionLiteral::kIsFunction, parenthesized, kind, pos); FunctionLiteral::kIsFunction, parenthesized, kind, pos);
...@@ -3709,9 +3707,9 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody( ...@@ -3709,9 +3707,9 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
ZoneList<Expression*>* arguments = ZoneList<Expression*>* arguments =
new(zone()) ZoneList<Expression*>(0, zone()); new(zone()) ZoneList<Expression*>(0, zone());
CallRuntime* allocation = factory()->NewCallRuntime( CallRuntime* allocation = factory()->NewCallRuntime(
ast_value_factory_->empty_string(), ast_value_factory()->empty_string(),
Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject), Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject), arguments,
arguments, pos); pos);
VariableProxy* init_proxy = factory()->NewVariableProxy( VariableProxy* init_proxy = factory()->NewVariableProxy(
function_state_->generator_object_variable()); function_state_->generator_object_variable());
Assignment* assignment = factory()->NewAssignment( Assignment* assignment = factory()->NewAssignment(
...@@ -3926,10 +3924,9 @@ void Parser::HandleSourceURLComments() { ...@@ -3926,10 +3924,9 @@ void Parser::HandleSourceURLComments() {
void Parser::ThrowPendingError() { void Parser::ThrowPendingError() {
DCHECK(ast_value_factory_->IsInternalized()); DCHECK(ast_value_factory()->IsInternalized());
if (has_pending_error_) { if (has_pending_error_) {
MessageLocation location(script_, MessageLocation location(script(), pending_error_location_.beg_pos,
pending_error_location_.beg_pos,
pending_error_location_.end_pos); pending_error_location_.end_pos);
Factory* factory = isolate()->factory(); Factory* factory = isolate()->factory();
bool has_arg = bool has_arg =
...@@ -3944,7 +3941,7 @@ void Parser::ThrowPendingError() { ...@@ -3944,7 +3941,7 @@ void Parser::ThrowPendingError() {
.ToHandleChecked(); .ToHandleChecked();
elements->set(0, *arg_string); elements->set(0, *arg_string);
} }
isolate()->debug()->OnCompileError(script_); isolate()->debug()->OnCompileError(script());
Handle<JSArray> array = factory->NewJSArrayWithElements(elements); Handle<JSArray> array = factory->NewJSArrayWithElements(elements);
Handle<Object> error; Handle<Object> error;
...@@ -3959,7 +3956,7 @@ void Parser::ThrowPendingError() { ...@@ -3959,7 +3956,7 @@ void Parser::ThrowPendingError() {
void Parser::Internalize() { void Parser::Internalize() {
// Internalize strings. // Internalize strings.
ast_value_factory_->Internalize(isolate()); ast_value_factory()->Internalize(isolate());
// Error processing. // Error processing.
if (info()->function() == NULL) { if (info()->function() == NULL) {
...@@ -4821,7 +4818,7 @@ bool Parser::Parse() { ...@@ -4821,7 +4818,7 @@ bool Parser::Parse() {
// If intrinsics are allowed, the Parser cannot operate independent of the // If intrinsics are allowed, the Parser cannot operate independent of the
// V8 heap because of Runtime. Tell the string table to internalize strings // V8 heap because of Runtime. Tell the string table to internalize strings
// and values right after they're created. // and values right after they're created.
ast_value_factory_->Internalize(isolate()); ast_value_factory()->Internalize(isolate());
} }
if (info()->is_lazy()) { if (info()->is_lazy()) {
...@@ -4838,12 +4835,7 @@ bool Parser::Parse() { ...@@ -4838,12 +4835,7 @@ bool Parser::Parse() {
info()->SetFunction(result); info()->SetFunction(result);
Internalize(); Internalize();
DCHECK(ast_value_factory_->IsInternalized()); DCHECK(ast_value_factory()->IsInternalized());
// info takes ownership of ast_value_factory_.
if (info()->ast_value_factory() == NULL) {
info()->SetAstValueFactory(ast_value_factory_);
}
ast_value_factory_ = NULL;
return (result != NULL); return (result != NULL);
} }
......
...@@ -655,8 +655,12 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -655,8 +655,12 @@ class Parser : public ParserBase<ParserTraits> {
FunctionLiteral* ParseLazy(); FunctionLiteral* ParseLazy();
FunctionLiteral* ParseLazy(Utf16CharacterStream* source); FunctionLiteral* ParseLazy(Utf16CharacterStream* source);
Isolate* isolate() { return isolate_; } Isolate* isolate() { return info_->isolate(); }
CompilationInfo* info() const { return info_; } CompilationInfo* info() const { return info_; }
Handle<Script> script() const { return info_->script(); }
AstValueFactory* ast_value_factory() const {
return info_->ast_value_factory();
}
// Called by ParseProgram after setting up the scanner. // Called by ParseProgram after setting up the scanner.
FunctionLiteral* DoParseProgram(CompilationInfo* info, FunctionLiteral* DoParseProgram(CompilationInfo* info,
...@@ -805,15 +809,11 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -805,15 +809,11 @@ class Parser : public ParserBase<ParserTraits> {
// internalize strings (move them to the heap). // internalize strings (move them to the heap).
void Internalize(); void Internalize();
Isolate* isolate_;
Handle<Script> script_;
Scanner scanner_; Scanner scanner_;
PreParser* reusable_preparser_; PreParser* reusable_preparser_;
Scope* original_scope_; // for ES5 function declarations in sloppy eval Scope* original_scope_; // for ES5 function declarations in sloppy eval
Target* target_stack_; // for break, continue statements Target* target_stack_; // for break, continue statements
ParseData* cached_parse_data_; ParseData* cached_parse_data_;
AstValueFactory* ast_value_factory_;
CompilationInfo* info_; CompilationInfo* info_;
...@@ -846,7 +846,7 @@ Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) { ...@@ -846,7 +846,7 @@ Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) {
const AstRawString* ParserTraits::EmptyIdentifierString() { const AstRawString* ParserTraits::EmptyIdentifierString() {
return parser_->ast_value_factory_->empty_string(); return parser_->ast_value_factory()->empty_string();
} }
...@@ -873,7 +873,7 @@ void ParserTraits::CheckConflictingVarDeclarations(v8::internal::Scope* scope, ...@@ -873,7 +873,7 @@ void ParserTraits::CheckConflictingVarDeclarations(v8::internal::Scope* scope,
AstValueFactory* ParserTraits::ast_value_factory() { AstValueFactory* ParserTraits::ast_value_factory() {
return parser_->ast_value_factory_; return parser_->ast_value_factory();
} }
......
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