Commit a804e9b0 authored by marja's avatar marja Committed by Commit bot

ParserBase: Simplify FuncNameInferrer handling.

BUG=

Review-Url: https://codereview.chromium.org/2301923002
Cr-Commit-Position: refs/heads/master@{#39130}
parent 19039efa
......@@ -1954,9 +1954,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
token = peek();
if (SetPropertyKindFromToken(token, kind)) {
*name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'async'
if (fni_ != nullptr) {
impl()->PushLiteralName(fni_, *name);
}
impl()->PushLiteralName(*name);
return factory()->NewStringLiteral(*name, pos);
}
*kind = PropertyKind::kMethodProperty;
......@@ -1972,9 +1970,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
token = peek();
if (SetPropertyKindFromToken(token, kind)) {
*name = impl()->GetSymbol();
if (fni_ != nullptr) {
impl()->PushLiteralName(fni_, *name);
}
impl()->PushLiteralName(*name);
return factory()->NewStringLiteral(*name, pos);
}
scanner()->IsGetOrSet(is_get, is_set);
......@@ -2048,9 +2044,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
return expression;
}
if (fni_ != nullptr) {
impl()->PushLiteralName(fni_, *name);
}
impl()->PushLiteralName(*name);
uint32_t index;
return impl()->IsArrayIndex(*name, &index)
......@@ -3044,7 +3038,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(bool* ok) {
IdentifierT name = ParseIdentifierName(CHECK_OK);
result = factory()->NewProperty(
result, factory()->NewStringLiteral(name, pos), pos);
if (fni_ != NULL) impl()->PushLiteralName(fni_, name);
impl()->PushLiteralName(name);
break;
}
......@@ -3270,9 +3264,7 @@ ParserBase<Impl>::ParseMemberExpressionContinuation(ExpressionT expression,
ExpressionT index = ParseExpressionCoverGrammar(true, CHECK_OK);
impl()->RewriteNonPattern(CHECK_OK);
expression = factory()->NewProperty(expression, index, pos);
if (fni_ != NULL) {
impl()->PushPropertyName(fni_, index);
}
impl()->PushPropertyName(index);
Expect(Token::RBRACK, CHECK_OK);
break;
}
......@@ -3287,9 +3279,7 @@ ParserBase<Impl>::ParseMemberExpressionContinuation(ExpressionT expression,
IdentifierT name = ParseIdentifierName(CHECK_OK);
expression = factory()->NewProperty(
expression, factory()->NewStringLiteral(name, pos), pos);
if (fni_ != NULL) {
impl()->PushLiteralName(fni_, name);
}
impl()->PushLiteralName(name);
break;
}
case Token::TEMPLATE_SPAN:
......@@ -3482,8 +3472,8 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations(
Scanner::Location variable_loc = scanner()->location();
bool single_name = impl()->IsIdentifier(pattern);
if (single_name && fni_ != nullptr) {
impl()->PushVariableName(fni_, impl()->AsIdentifier(pattern));
if (single_name) {
impl()->PushVariableName(impl()->AsIdentifier(pattern));
}
ExpressionT value = impl()->EmptyExpression();
......@@ -3763,7 +3753,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
function_literal->set_should_be_used_once_hint();
}
if (fni_ != NULL) impl()->InferFunctionName(fni_, function_literal);
impl()->InferFunctionName(function_literal);
return function_literal;
}
......
......@@ -1779,7 +1779,8 @@ Statement* Parser::ParseHoistableDeclaration(
}
FuncNameInferrer::State fni_state(fni_);
if (fni_ != NULL) fni_->PushEnclosingName(name);
DCHECK_NOT_NULL(fni_);
fni_->PushEnclosingName(name);
FunctionLiteral* fun = ParseFunctionLiteral(
name, scanner()->location(), name_validity,
is_generator ? FunctionKind::kGeneratorFunction
......@@ -3905,7 +3906,10 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
if (should_be_used_once_hint)
function_literal->set_should_be_used_once_hint();
if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
if (should_infer_name) {
DCHECK_NOT_NULL(fni_);
fni_->AddFunction(function_literal);
}
return function_literal;
}
......@@ -4568,7 +4572,8 @@ Expression* Parser::ParseClassLiteral(const AstRawString* name,
properties->Add(property, zone());
}
if (fni_ != nullptr) fni_->Infer();
DCHECK_NOT_NULL(fni_);
fni_->Infer();
if (property_name != ast_value_factory()->constructor_string()) {
SetFunctionNameFromPropertyName(property, property_name);
......
......@@ -709,28 +709,27 @@ class Parser : public ParserBase<Parser> {
// Functions for encapsulating the differences between parsing and preparsing;
// operations interleaved with the recursive descent.
V8_INLINE static void PushLiteralName(FuncNameInferrer* fni,
const AstRawString* id) {
fni->PushLiteralName(id);
V8_INLINE void PushLiteralName(const AstRawString* id) {
DCHECK_NOT_NULL(fni_);
fni_->PushLiteralName(id);
}
V8_INLINE static void PushVariableName(FuncNameInferrer* fni,
const AstRawString* id) {
fni->PushVariableName(id);
V8_INLINE void PushVariableName(const AstRawString* id) {
DCHECK_NOT_NULL(fni_);
fni_->PushVariableName(id);
}
V8_INLINE void PushPropertyName(FuncNameInferrer* fni,
Expression* expression) {
V8_INLINE void PushPropertyName(Expression* expression) {
DCHECK_NOT_NULL(fni_);
if (expression->IsPropertyName()) {
fni->PushLiteralName(expression->AsLiteral()->AsRawPropertyName());
fni_->PushLiteralName(expression->AsLiteral()->AsRawPropertyName());
} else {
fni->PushLiteralName(ast_value_factory()->anonymous_function_string());
fni_->PushLiteralName(ast_value_factory()->anonymous_function_string());
}
}
V8_INLINE static void InferFunctionName(FuncNameInferrer* fni,
FunctionLiteral* func_to_infer) {
fni->AddFunction(func_to_infer);
V8_INLINE void InferFunctionName(FunctionLiteral* func_to_infer) {
fni_->AddFunction(func_to_infer);
}
// If we assign a function literal to a property we pretenure the
......@@ -893,7 +892,7 @@ class Parser : public ParserBase<Parser> {
V8_INLINE Expression* ExpressionFromIdentifier(
const AstRawString* name, int start_position, int end_position,
InferName infer = InferName::kYes) {
if (infer == InferName::kYes && fni_ != NULL) {
if (infer == InferName::kYes) {
fni_->PushVariableName(name);
}
return NewUnresolved(name, start_position, end_position);
......@@ -901,7 +900,7 @@ class Parser : public ParserBase<Parser> {
V8_INLINE Expression* ExpressionFromString(int pos) {
const AstRawString* symbol = GetSymbol();
if (fni_ != NULL) fni_->PushLiteralName(symbol);
fni_->PushLiteralName(symbol);
return factory()->NewStringLiteral(symbol, pos);
}
......
......@@ -906,29 +906,10 @@ class PreParser : public ParserBase<PreParser> {
// Functions for encapsulating the differences between parsing and preparsing;
// operations interleaved with the recursive descent.
V8_INLINE static void PushLiteralName(FuncNameInferrer* fni,
PreParserIdentifier id) {
// PreParser should not use FuncNameInferrer.
UNREACHABLE();
}
V8_INLINE static void PushVariableName(FuncNameInferrer* fni,
PreParserIdentifier id) {
// PreParser should not use FuncNameInferrer.
UNREACHABLE();
}
V8_INLINE void PushPropertyName(FuncNameInferrer* fni,
PreParserExpression expression) {
// PreParser should not use FuncNameInferrer.
UNREACHABLE();
}
V8_INLINE static void InferFunctionName(FuncNameInferrer* fni,
PreParserExpression expression) {
// PreParser should not use FuncNameInferrer.
UNREACHABLE();
}
V8_INLINE static void PushLiteralName(PreParserIdentifier id) {}
V8_INLINE static void PushVariableName(PreParserIdentifier id) {}
V8_INLINE void PushPropertyName(PreParserExpression expression) {}
V8_INLINE static void InferFunctionName(PreParserExpression expression) {}
V8_INLINE static void CheckAssigningFunctionLiteralToProperty(
PreParserExpression left, PreParserExpression right) {}
......
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