Don't track function-kind through FunctionState, always read from underlying scope

BUG=

Review-Url: https://codereview.chromium.org/2367383002
Cr-Commit-Position: refs/heads/master@{#39763}
This commit is contained in:
verwaest 2016-09-27 04:41:00 -07:00 committed by Commit bot
parent c176b26fee
commit 1c758066f1
4 changed files with 26 additions and 37 deletions

View File

@ -381,8 +381,7 @@ class ParserBase {
class FunctionState final : public ScopeState {
public:
FunctionState(FunctionState** function_state_stack,
ScopeState** scope_stack, DeclarationScope* scope,
FunctionKind kind);
ScopeState** scope_stack, DeclarationScope* scope);
~FunctionState();
DeclarationScope* scope() const {
@ -403,11 +402,11 @@ class ParserBase {
void AddProperty() { expected_property_count_++; }
int expected_property_count() { return expected_property_count_; }
bool is_generator() const { return IsGeneratorFunction(kind_); }
bool is_async_function() const { return IsAsyncFunction(kind_); }
bool is_generator() const { return IsGeneratorFunction(kind()); }
bool is_async_function() const { return IsAsyncFunction(kind()); }
bool is_resumable() const { return is_generator() || is_async_function(); }
FunctionKind kind() const { return kind_; }
FunctionKind kind() const { return scope()->function_kind(); }
FunctionState* outer() const { return outer_function_state_; }
void set_generator_object_variable(typename Types::Variable* variable) {
@ -498,7 +497,6 @@ class ParserBase {
// Properties count estimation.
int expected_property_count_;
FunctionKind kind_;
// For generators, this variable may hold the generator object. It variable
// is used by yield expressions and return statements. It is not necessary
// for generator functions to have this variable set.
@ -1192,7 +1190,6 @@ class ParserBase {
bool* is_async, bool* ok);
ExpressionT ParseArrowFunctionLiteral(bool accept_IN,
const FormalParametersT& parameters,
bool is_async,
bool* ok);
ExpressionT ParseTemplateLiteral(ExpressionT tag, int start, bool* ok);
ExpressionT ParseSuperExpression(bool is_new, bool* ok);
@ -1454,11 +1451,10 @@ class ParserBase {
template <typename Impl>
ParserBase<Impl>::FunctionState::FunctionState(
FunctionState** function_state_stack, ScopeState** scope_stack,
DeclarationScope* scope, FunctionKind kind)
DeclarationScope* scope)
: ScopeState(scope_stack, scope),
next_materialized_literal_index_(0),
expected_property_count_(0),
kind_(kind),
generator_object_variable_(nullptr),
promise_variable_(nullptr),
function_state_stack_(function_state_stack),
@ -2265,7 +2261,7 @@ ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer,
DeclarationScope* initializer_scope = NewFunctionScope(kind);
initializer_scope->set_start_position(scanner()->location().end_pos);
FunctionState initializer_state(&function_state_, &scope_state_,
initializer_scope, kind);
initializer_scope);
DCHECK(scope() == initializer_scope);
scope()->SetLanguageMode(STRICT);
ExpressionClassifier expression_classifier(this);
@ -2686,8 +2682,7 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN, bool* ok) {
if (duplicate_loc.IsValid()) {
classifier()->RecordDuplicateFormalParameterError(duplicate_loc);
}
expression =
ParseArrowFunctionLiteral(accept_IN, parameters, is_async, CHECK_OK);
expression = ParseArrowFunctionLiteral(accept_IN, parameters, CHECK_OK);
impl()->Discard();
classifier()->RecordPatternError(arrow_loc,
MessageTemplate::kUnexpectedToken,
@ -3885,8 +3880,7 @@ bool ParserBase<Impl>::IsTrivialExpression() {
template <typename Impl>
typename ParserBase<Impl>::ExpressionT
ParserBase<Impl>::ParseArrowFunctionLiteral(
bool accept_IN, const FormalParametersT& formal_parameters, bool is_async,
bool* ok) {
bool accept_IN, const FormalParametersT& formal_parameters, bool* ok) {
if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) {
// ASI inserts `;` after arrow parameters if a line terminator is found.
// `=> ...` is never a valid expression, so report as syntax error.
@ -3901,13 +3895,13 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
int materialized_literal_count = -1;
int expected_property_count = -1;
FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
FunctionKind kind = formal_parameters.scope->function_kind();
FunctionLiteral::EagerCompileHint eager_compile_hint =
FunctionLiteral::kShouldLazyCompile;
bool should_be_used_once_hint = false;
{
FunctionState function_state(&function_state_, &scope_state_,
formal_parameters.scope, arrow_kind);
formal_parameters.scope);
function_state.SkipMaterializedLiterals(
formal_parameters.materialized_literals_count);
@ -3953,7 +3947,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
if (!is_lazily_parsed) {
body = impl()->ParseEagerFunctionBody(
impl()->EmptyIdentifier(), kNoSourcePosition, formal_parameters,
arrow_kind, FunctionLiteral::kAnonymousExpression, CHECK_OK);
kind, FunctionLiteral::kAnonymousExpression, CHECK_OK);
materialized_literal_count =
function_state.materialized_literal_count();
expected_property_count = function_state.expected_property_count();
@ -3966,10 +3960,10 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
ReturnExprScope allow_tail_calls(
function_state_, ReturnExprContext::kInsideValidReturnStatement);
body = impl()->NewStatementList(1);
impl()->AddParameterInitializationBlock(formal_parameters, body, is_async,
CHECK_OK);
impl()->AddParameterInitializationBlock(
formal_parameters, body, kind == kAsyncArrowFunction, CHECK_OK);
ExpressionClassifier classifier(this);
if (is_async) {
if (kind == kAsyncArrowFunction) {
impl()->ParseAsyncArrowSingleExpressionBody(body, accept_IN, pos,
CHECK_OK);
impl()->RewriteNonPattern(CHECK_OK);
@ -4011,7 +4005,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
impl()->EmptyIdentifierString(), formal_parameters.scope, body,
materialized_literal_count, expected_property_count, num_parameters,
FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression, eager_compile_hint, arrow_kind,
FunctionLiteral::kAnonymousExpression, eager_compile_hint, kind,
formal_parameters.scope->start_position());
function_literal->set_function_token_position(

View File

@ -232,7 +232,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
{
FunctionState function_state(&function_state_, &scope_state_,
function_scope, kind);
function_scope);
body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone());
if (call_super) {
@ -786,8 +786,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
// Enter 'scope' with the given parsing mode.
ParsingModeScope parsing_mode_scope(this, parsing_mode);
FunctionState function_state(&function_state_, &scope_state_, scope,
kNormalFunction);
FunctionState function_state(&function_state_, &scope_state_, scope);
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
bool ok = true;
@ -936,8 +935,7 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
DeclarationScope* outer_function = outer->GetClosureScope();
DCHECK(outer);
FunctionState function_state(&function_state_, &scope_state_,
outer_function,
outer_function->function_kind());
outer_function);
BlockState block_state(&scope_state_, outer);
DCHECK(is_sloppy(outer->language_mode()) ||
is_strict(info->language_mode()));
@ -959,7 +957,8 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
}
// TODO(adamk): We should construct this scope from the ScopeInfo.
DeclarationScope* scope = NewFunctionScope(FunctionKind::kArrowFunction);
FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
DeclarationScope* scope = NewFunctionScope(arrow_kind);
// These two bits only need to be explicitly set because we're
// not passing the ScopeInfo to the Scope constructor.
@ -994,8 +993,7 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
checkpoint.Restore(&formals.materialized_literals_count);
// Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should
// not be observable, or else the preparser would have failed.
Expression* expression =
ParseArrowFunctionLiteral(true, formals, is_async, &ok);
Expression* expression = ParseArrowFunctionLiteral(true, formals, &ok);
if (ok) {
// Scanning must end at the same position that was recorded
// previously. If not, parsing has been interrupted due to a stack
@ -2783,7 +2781,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
DCHECK(main_scope->zone() != scope->zone());
}
FunctionState function_state(&function_state_, &scope_state_, scope, kind);
FunctionState function_state(&function_state_, &scope_state_, scope);
#ifdef DEBUG
scope->SetScopeName(function_name);
#endif
@ -3552,7 +3550,7 @@ FunctionLiteral* Parser::SynthesizeClassFieldInitializer(int count) {
initializer_scope->set_start_position(scanner()->location().end_pos);
initializer_scope->set_end_position(scanner()->location().end_pos);
FunctionState initializer_state(&function_state_, &scope_state_,
initializer_scope, kind);
initializer_scope);
ZoneList<Statement*>* body = new (zone()) ZoneList<Statement*>(count, zone());
for (int i = 0; i < count; ++i) {
const AstRawString* name =

View File

@ -97,8 +97,7 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
// scope_state_. All scopes above the function_scope are ignored by the
// PreParser.
DCHECK_NULL(scope_state_);
FunctionState function_state(&function_state_, &scope_state_, function_scope,
function_scope->function_kind());
FunctionState function_state(&function_state_, &scope_state_, function_scope);
DCHECK_EQ(Token::LBRACE, scanner()->current_token());
bool ok = true;
int start_position = peek_position();
@ -196,8 +195,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
bool outer_is_script_scope = scope()->is_script_scope();
DeclarationScope* function_scope = NewFunctionScope(kind);
function_scope->SetLanguageMode(language_mode);
FunctionState function_state(&function_state_, &scope_state_, function_scope,
kind);
FunctionState function_state(&function_state_, &scope_state_, function_scope);
DuplicateFinder duplicate_finder(scanner()->unicode_cache());
ExpressionClassifier formals_classifier(this, &duplicate_finder);

View File

@ -793,8 +793,7 @@ class PreParser : public ParserBase<PreParser> {
// the global scope.
if (is_module) scope = NewModuleScope(scope);
FunctionState top_scope(&function_state_, &scope_state_, scope,
kNormalFunction);
FunctionState top_scope(&function_state_, &scope_state_, scope);
bool ok = true;
int start_position = scanner()->peek_location().beg_pos;
parsing_module_ = is_module;