Commit 17376b6d authored by marja's avatar marja Committed by Commit bot

FunctionState doesn't need to know AstNodeFactory.

It's anyway just the "same" AstNodeFactory (i.e., it's passed the same
AstValueFactory), so no need to have several of them for each
FunctionState.

R=verwaest@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2169823002
Cr-Commit-Position: refs/heads/master@{#37938}
parent b973a777
...@@ -3069,11 +3069,21 @@ class AstTraversalVisitor : public AstVisitor<AstTraversalVisitor> { ...@@ -3069,11 +3069,21 @@ class AstTraversalVisitor : public AstVisitor<AstTraversalVisitor> {
class AstNodeFactory final BASE_EMBEDDED { class AstNodeFactory final BASE_EMBEDDED {
public: public:
explicit AstNodeFactory(AstValueFactory* ast_value_factory) explicit AstNodeFactory(AstValueFactory* ast_value_factory)
: local_zone_(ast_value_factory->zone()), : local_zone_(nullptr),
parser_zone_(ast_value_factory->zone()), parser_zone_(nullptr),
ast_value_factory_(ast_value_factory) {} ast_value_factory_(ast_value_factory) {
if (ast_value_factory != nullptr) {
local_zone_ = ast_value_factory->zone();
parser_zone_ = ast_value_factory->zone();
}
}
AstValueFactory* ast_value_factory() const { return ast_value_factory_; } AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
void set_ast_value_factory(AstValueFactory* ast_value_factory) {
ast_value_factory_ = ast_value_factory;
local_zone_ = ast_value_factory->zone();
parser_zone_ = ast_value_factory->zone();
}
VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
VariableMode mode, Scope* scope, VariableMode mode, Scope* scope,
......
...@@ -206,6 +206,7 @@ class ParserBase : public Traits { ...@@ -206,6 +206,7 @@ class ParserBase : public Traits {
extension_(extension), extension_(extension),
fni_(nullptr), fni_(nullptr),
ast_value_factory_(ast_value_factory), ast_value_factory_(ast_value_factory),
ast_node_factory_(ast_value_factory),
log_(log), log_(log),
mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
parsing_module_(false), parsing_module_(false),
...@@ -372,8 +373,7 @@ class ParserBase : public Traits { ...@@ -372,8 +373,7 @@ class ParserBase : public Traits {
class FunctionState final : public ScopeState { class FunctionState final : public ScopeState {
public: public:
FunctionState(FunctionState** function_state_stack, FunctionState(FunctionState** function_state_stack,
ScopeState** scope_stack, Scope* scope, FunctionKind kind, ScopeState** scope_stack, Scope* scope, FunctionKind kind);
typename Traits::Type::Factory* factory);
~FunctionState(); ~FunctionState();
int NextMaterializedLiteralIndex() { int NextMaterializedLiteralIndex() {
...@@ -421,8 +421,6 @@ class ParserBase : public Traits { ...@@ -421,8 +421,6 @@ class ParserBase : public Traits {
return generator_object_variable_; return generator_object_variable_;
} }
typename Traits::Type::Factory* factory() { return factory_; }
const ZoneList<DestructuringAssignment>& const ZoneList<DestructuringAssignment>&
destructuring_assignments_to_rewrite() const { destructuring_assignments_to_rewrite() const {
return destructuring_assignments_to_rewrite_; return destructuring_assignments_to_rewrite_;
...@@ -514,8 +512,6 @@ class ParserBase : public Traits { ...@@ -514,8 +512,6 @@ class ParserBase : public Traits {
ZoneList<typename ExpressionClassifier::Error> reported_errors_; ZoneList<typename ExpressionClassifier::Error> reported_errors_;
typename Traits::Type::Factory* factory_;
// If true, the next (and immediately following) function literal is // If true, the next (and immediately following) function literal is
// preceded by a parenthesis. // preceded by a parenthesis.
bool next_function_is_parenthesized_; bool next_function_is_parenthesized_;
...@@ -839,9 +835,7 @@ class ParserBase : public Traits { ...@@ -839,9 +835,7 @@ class ParserBase : public Traits {
return Token::Precedence(token); return Token::Precedence(token);
} }
typename Traits::Type::Factory* factory() { typename Traits::Type::Factory* factory() { return &ast_node_factory_; }
return function_state_->factory();
}
LanguageMode language_mode() { return scope()->language_mode(); } LanguageMode language_mode() { return scope()->language_mode(); }
bool is_generator() const { return function_state_->is_generator(); } bool is_generator() const { return function_state_->is_generator(); }
...@@ -1227,6 +1221,7 @@ class ParserBase : public Traits { ...@@ -1227,6 +1221,7 @@ class ParserBase : public Traits {
v8::Extension* extension_; v8::Extension* extension_;
FuncNameInferrer* fni_; FuncNameInferrer* fni_;
AstValueFactory* ast_value_factory_; // Not owned. AstValueFactory* ast_value_factory_; // Not owned.
typename Traits::Type::Factory ast_node_factory_;
ParserRecorder* log_; ParserRecorder* log_;
Mode mode_; Mode mode_;
bool parsing_module_; bool parsing_module_;
...@@ -1253,7 +1248,7 @@ class ParserBase : public Traits { ...@@ -1253,7 +1248,7 @@ class ParserBase : public Traits {
template <class Traits> template <class Traits>
ParserBase<Traits>::FunctionState::FunctionState( ParserBase<Traits>::FunctionState::FunctionState(
FunctionState** function_state_stack, ScopeState** scope_stack, FunctionState** function_state_stack, ScopeState** scope_stack,
Scope* scope, FunctionKind kind, typename Traits::Type::Factory* factory) Scope* scope, FunctionKind kind)
: ScopeState(scope_stack, scope), : ScopeState(scope_stack, scope),
next_materialized_literal_index_(0), next_materialized_literal_index_(0),
expected_property_count_(0), expected_property_count_(0),
...@@ -1269,7 +1264,6 @@ ParserBase<Traits>::FunctionState::FunctionState( ...@@ -1269,7 +1264,6 @@ ParserBase<Traits>::FunctionState::FunctionState(
return_expr_context_(ReturnExprContext::kInsideValidBlock), return_expr_context_(ReturnExprContext::kInsideValidBlock),
non_patterns_to_rewrite_(0, scope->zone()), non_patterns_to_rewrite_(0, scope->zone()),
reported_errors_(16, scope->zone()), reported_errors_(16, scope->zone()),
factory_(factory),
next_function_is_parenthesized_(false), next_function_is_parenthesized_(false),
this_function_is_parenthesized_(false) { this_function_is_parenthesized_(false) {
*function_state_stack = this; *function_state_stack = this;
...@@ -3385,10 +3379,8 @@ ParserBase<Traits>::ParseArrowFunctionLiteral( ...@@ -3385,10 +3379,8 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction; FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
{ {
typename Traits::Type::Factory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_state_, FunctionState function_state(&function_state_, &scope_state_,
formal_parameters.scope, arrow_kind, formal_parameters.scope, arrow_kind);
&function_factory);
function_state.SkipMaterializedLiterals( function_state.SkipMaterializedLiterals(
formal_parameters.materialized_literals_count); formal_parameters.materialized_literals_count);
......
...@@ -219,9 +219,8 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, ...@@ -219,9 +219,8 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
ZoneList<Statement*>* body = NULL; ZoneList<Statement*>* body = NULL;
{ {
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_state_, FunctionState function_state(&function_state_, &scope_state_,
function_scope, kind, &function_factory); function_scope, kind);
body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone());
if (call_super) { if (call_super) {
...@@ -851,6 +850,7 @@ Parser::Parser(ParseInfo* info) ...@@ -851,6 +850,7 @@ Parser::Parser(ParseInfo* info)
info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed()));
info->set_ast_value_factory_owned(); info->set_ast_value_factory_owned();
ast_value_factory_ = info->ast_value_factory(); ast_value_factory_ = info->ast_value_factory();
ast_node_factory_.set_ast_value_factory(ast_value_factory_);
} }
} }
...@@ -966,9 +966,8 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) { ...@@ -966,9 +966,8 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
// Enter 'scope' with the given parsing mode. // Enter 'scope' with the given parsing mode.
ParsingModeScope parsing_mode_scope(this, parsing_mode); ParsingModeScope parsing_mode_scope(this, parsing_mode);
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_state_, scope, FunctionState function_state(&function_state_, &scope_state_, scope,
kNormalFunction, &function_factory); kNormalFunction);
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
bool ok = true; bool ok = true;
...@@ -1113,9 +1112,8 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, ...@@ -1113,9 +1112,8 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
scope, ast_value_factory()); scope, ast_value_factory());
} }
original_scope_ = scope; original_scope_ = scope;
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_state_, scope, FunctionState function_state(&function_state_, &scope_state_, scope,
shared_info->kind(), &function_factory); shared_info->kind());
DCHECK(is_sloppy(scope->language_mode()) || DCHECK(is_sloppy(scope->language_mode()) ||
is_strict(info->language_mode())); is_strict(info->language_mode()));
DCHECK(info->language_mode() == shared_info->language_mode()); DCHECK(info->language_mode() == shared_info->language_mode());
...@@ -4307,9 +4305,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4307,9 +4305,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Parse function. // Parse function.
{ {
AstNodeFactory function_factory(ast_value_factory()); FunctionState function_state(&function_state_, &scope_state_, scope, kind);
FunctionState function_state(&function_state_, &scope_state_, scope, kind,
&function_factory);
this->scope()->SetScopeName(function_name); this->scope()->SetScopeName(function_name);
ExpressionClassifier formals_classifier(this, &duplicate_finder); ExpressionClassifier formals_classifier(this, &duplicate_finder);
......
...@@ -132,15 +132,13 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction( ...@@ -132,15 +132,13 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
// Lazy functions always have trivial outer scopes (no with/catch scopes). // Lazy functions always have trivial outer scopes (no with/catch scopes).
DCHECK_NULL(scope_state_); DCHECK_NULL(scope_state_);
Scope* top_scope = NewScriptScope(); Scope* top_scope = NewScriptScope();
PreParserFactory top_factory(nullptr);
FunctionState top_state(&function_state_, &scope_state_, top_scope, FunctionState top_state(&function_state_, &scope_state_, top_scope,
kNormalFunction, &top_factory); kNormalFunction);
scope()->SetLanguageMode(language_mode); scope()->SetLanguageMode(language_mode);
Scope* function_scope = NewFunctionScope(kind); Scope* function_scope = NewFunctionScope(kind);
if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters();
PreParserFactory function_factory(nullptr);
FunctionState function_state(&function_state_, &scope_state_, function_scope, FunctionState function_state(&function_state_, &scope_state_, function_scope,
kind, &function_factory); kind);
DCHECK_EQ(Token::LBRACE, scanner()->current_token()); DCHECK_EQ(Token::LBRACE, scanner()->current_token());
bool ok = true; bool ok = true;
int start_position = peek_position(); int start_position = peek_position();
...@@ -1113,9 +1111,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral( ...@@ -1113,9 +1111,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
bool outer_is_script_scope = scope()->is_script_scope(); bool outer_is_script_scope = scope()->is_script_scope();
Scope* function_scope = NewFunctionScope(kind); Scope* function_scope = NewFunctionScope(kind);
function_scope->SetLanguageMode(language_mode); function_scope->SetLanguageMode(language_mode);
PreParserFactory factory(NULL);
FunctionState function_state(&function_state_, &scope_state_, function_scope, FunctionState function_state(&function_state_, &scope_state_, function_scope,
kind, &factory); kind);
DuplicateFinder duplicate_finder(scanner()->unicode_cache()); DuplicateFinder duplicate_finder(scanner()->unicode_cache());
ExpressionClassifier formals_classifier(this, &duplicate_finder); ExpressionClassifier formals_classifier(this, &duplicate_finder);
......
...@@ -1049,9 +1049,8 @@ class PreParser : public ParserBase<PreParserTraits> { ...@@ -1049,9 +1049,8 @@ class PreParser : public ParserBase<PreParserTraits> {
scope = NewScopeWithParent(scope, MODULE_SCOPE); scope = NewScopeWithParent(scope, MODULE_SCOPE);
} }
PreParserFactory factory(nullptr);
FunctionState top_scope(&function_state_, &scope_state_, scope, FunctionState top_scope(&function_state_, &scope_state_, scope,
kNormalFunction, &factory); kNormalFunction);
bool ok = true; bool ok = true;
int start_position = scanner()->peek_location().beg_pos; int start_position = scanner()->peek_location().beg_pos;
parsing_module_ = is_module; parsing_module_ = is_module;
......
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