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}
This commit is contained in:
marja 2016-07-21 04:02:54 -07:00 committed by Commit bot
parent b973a77775
commit 17376b6d85
5 changed files with 28 additions and 34 deletions

View File

@ -3069,11 +3069,21 @@ class AstTraversalVisitor : public AstVisitor<AstTraversalVisitor> {
class AstNodeFactory final BASE_EMBEDDED {
public:
explicit AstNodeFactory(AstValueFactory* ast_value_factory)
: local_zone_(ast_value_factory->zone()),
parser_zone_(ast_value_factory->zone()),
ast_value_factory_(ast_value_factory) {}
: local_zone_(nullptr),
parser_zone_(nullptr),
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_; }
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,
VariableMode mode, Scope* scope,

View File

@ -206,6 +206,7 @@ class ParserBase : public Traits {
extension_(extension),
fni_(nullptr),
ast_value_factory_(ast_value_factory),
ast_node_factory_(ast_value_factory),
log_(log),
mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
parsing_module_(false),
@ -372,8 +373,7 @@ class ParserBase : public Traits {
class FunctionState final : public ScopeState {
public:
FunctionState(FunctionState** function_state_stack,
ScopeState** scope_stack, Scope* scope, FunctionKind kind,
typename Traits::Type::Factory* factory);
ScopeState** scope_stack, Scope* scope, FunctionKind kind);
~FunctionState();
int NextMaterializedLiteralIndex() {
@ -421,8 +421,6 @@ class ParserBase : public Traits {
return generator_object_variable_;
}
typename Traits::Type::Factory* factory() { return factory_; }
const ZoneList<DestructuringAssignment>&
destructuring_assignments_to_rewrite() const {
return destructuring_assignments_to_rewrite_;
@ -514,8 +512,6 @@ class ParserBase : public Traits {
ZoneList<typename ExpressionClassifier::Error> reported_errors_;
typename Traits::Type::Factory* factory_;
// If true, the next (and immediately following) function literal is
// preceded by a parenthesis.
bool next_function_is_parenthesized_;
@ -839,9 +835,7 @@ class ParserBase : public Traits {
return Token::Precedence(token);
}
typename Traits::Type::Factory* factory() {
return function_state_->factory();
}
typename Traits::Type::Factory* factory() { return &ast_node_factory_; }
LanguageMode language_mode() { return scope()->language_mode(); }
bool is_generator() const { return function_state_->is_generator(); }
@ -1227,6 +1221,7 @@ class ParserBase : public Traits {
v8::Extension* extension_;
FuncNameInferrer* fni_;
AstValueFactory* ast_value_factory_; // Not owned.
typename Traits::Type::Factory ast_node_factory_;
ParserRecorder* log_;
Mode mode_;
bool parsing_module_;
@ -1253,7 +1248,7 @@ class ParserBase : public Traits {
template <class Traits>
ParserBase<Traits>::FunctionState::FunctionState(
FunctionState** function_state_stack, ScopeState** scope_stack,
Scope* scope, FunctionKind kind, typename Traits::Type::Factory* factory)
Scope* scope, FunctionKind kind)
: ScopeState(scope_stack, scope),
next_materialized_literal_index_(0),
expected_property_count_(0),
@ -1269,7 +1264,6 @@ ParserBase<Traits>::FunctionState::FunctionState(
return_expr_context_(ReturnExprContext::kInsideValidBlock),
non_patterns_to_rewrite_(0, scope->zone()),
reported_errors_(16, scope->zone()),
factory_(factory),
next_function_is_parenthesized_(false),
this_function_is_parenthesized_(false) {
*function_state_stack = this;
@ -3385,10 +3379,8 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
{
typename Traits::Type::Factory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_state_,
formal_parameters.scope, arrow_kind,
&function_factory);
formal_parameters.scope, arrow_kind);
function_state.SkipMaterializedLiterals(
formal_parameters.materialized_literals_count);

View File

@ -219,9 +219,8 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
ZoneList<Statement*>* body = NULL;
{
AstNodeFactory function_factory(ast_value_factory());
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());
if (call_super) {
@ -851,6 +850,7 @@ Parser::Parser(ParseInfo* info)
info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed()));
info->set_ast_value_factory_owned();
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) {
// Enter 'scope' with the given parsing mode.
ParsingModeScope parsing_mode_scope(this, parsing_mode);
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_state_, scope,
kNormalFunction, &function_factory);
kNormalFunction);
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
bool ok = true;
@ -1113,9 +1112,8 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
scope, ast_value_factory());
}
original_scope_ = scope;
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_state_, scope,
shared_info->kind(), &function_factory);
shared_info->kind());
DCHECK(is_sloppy(scope->language_mode()) ||
is_strict(info->language_mode()));
DCHECK(info->language_mode() == shared_info->language_mode());
@ -4307,9 +4305,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Parse function.
{
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_state_, scope, kind,
&function_factory);
FunctionState function_state(&function_state_, &scope_state_, scope, kind);
this->scope()->SetScopeName(function_name);
ExpressionClassifier formals_classifier(this, &duplicate_finder);

View File

@ -132,15 +132,13 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
// Lazy functions always have trivial outer scopes (no with/catch scopes).
DCHECK_NULL(scope_state_);
Scope* top_scope = NewScriptScope();
PreParserFactory top_factory(nullptr);
FunctionState top_state(&function_state_, &scope_state_, top_scope,
kNormalFunction, &top_factory);
kNormalFunction);
scope()->SetLanguageMode(language_mode);
Scope* function_scope = NewFunctionScope(kind);
if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters();
PreParserFactory function_factory(nullptr);
FunctionState function_state(&function_state_, &scope_state_, function_scope,
kind, &function_factory);
kind);
DCHECK_EQ(Token::LBRACE, scanner()->current_token());
bool ok = true;
int start_position = peek_position();
@ -1113,9 +1111,8 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
bool outer_is_script_scope = scope()->is_script_scope();
Scope* function_scope = NewFunctionScope(kind);
function_scope->SetLanguageMode(language_mode);
PreParserFactory factory(NULL);
FunctionState function_state(&function_state_, &scope_state_, function_scope,
kind, &factory);
kind);
DuplicateFinder duplicate_finder(scanner()->unicode_cache());
ExpressionClassifier formals_classifier(this, &duplicate_finder);

View File

@ -1049,9 +1049,8 @@ class PreParser : public ParserBase<PreParserTraits> {
scope = NewScopeWithParent(scope, MODULE_SCOPE);
}
PreParserFactory factory(nullptr);
FunctionState top_scope(&function_state_, &scope_state_, scope,
kNormalFunction, &factory);
kNormalFunction);
bool ok = true;
int start_position = scanner()->peek_location().beg_pos;
parsing_module_ = is_module;