Commit 6fe0b39b authored by nikolaos's avatar nikolaos Committed by Commit bot

[parser] Clean up (pre)parser traits

This patch removes 26 elements of the (pre)parser traits objects.
Some methods are removed completely and called directly from the
implementation objects:

- ParseAsyncFunctionExpression
- ParseClassLiteral
- ParseDoExpression
- ParseEagerFunctionBody
- ParseFunctionLiteral
- ParseV8Intrinsic

Some methods have to be moved to at least one implementation object:

- AddTemplateExpression
- AddTemplateSpan
- CheckConflictingVarDeclarations
- CloseTemplateLiteral
- MarkCollectedTailCallExpressions
- MarkTailPosition
- OpenTemplateLiteral
- ParseAsyncArrowSingleExpressionBody
- PrepareSpreadArguments
- QueueDestructuringAssignmentForRewriting
- QueueNonPatternForRewriting
- RewriteAssignExponentiation
- RewriteAwaitExpression
- RewriteDestructuringAssignments
- RewriteExponentiation
- RewriteNonPattern
- RewriteYieldStar
- SkipLazyFunctionBody
- SpreadCall
- SpreadCallNew

Also, the inner class/struct TemplateLiteralState is moved to the
implementation objects.

R=adamk@chromium.org, marja@chromium.org
BUG=
LOG=N

Review-Url: https://codereview.chromium.org/2267783002
Cr-Commit-Position: refs/heads/master@{#38837}
parent 9f4c8b74
......@@ -554,7 +554,7 @@ class ParserBase : public ParserBaseTraits<Impl> {
// to this function. Filled in by constructor.
bool this_function_is_parenthesized_;
friend class ParserBaseTraits<Impl>;
friend Impl;
friend class Checkpoint;
};
......@@ -1157,7 +1157,6 @@ class ParserBase : public ParserBaseTraits<Impl> {
bool* ok);
ExpressionT ParseTemplateLiteral(ExpressionT tag, int start,
ExpressionClassifier* classifier, bool* ok);
void AddTemplateExpression(ExpressionT);
ExpressionT ParseSuperExpression(bool is_new, bool* ok);
ExpressionT ParseNewTargetExpression(bool* ok);
......@@ -1597,7 +1596,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
!scanner()->HasAnyLineTerminatorAfterNext() &&
PeekAhead() == Token::FUNCTION) {
Consume(Token::ASYNC);
return this->ParseAsyncFunctionExpression(CHECK_OK);
return impl()->ParseAsyncFunctionExpression(CHECK_OK);
}
// CoverCallExpressionAndAsyncArrowHead
*is_async = true;
......@@ -1701,9 +1700,9 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
CHECK_OK);
class_name_location = scanner()->location();
}
return this->ParseClassLiteral(classifier, name, class_name_location,
is_strict_reserved_name,
class_token_position, ok);
return impl()->ParseClassLiteral(classifier, name, class_name_location,
is_strict_reserved_name,
class_token_position, ok);
}
case Token::TEMPLATE_SPAN:
......@@ -1715,14 +1714,14 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
case Token::MOD:
if (allow_natives() || extension_ != NULL) {
BindingPatternUnexpectedToken(classifier);
return this->ParseV8Intrinsic(ok);
return impl()->ParseV8Intrinsic(ok);
}
break;
case Token::DO:
if (allow_harmony_do_expressions()) {
BindingPatternUnexpectedToken(classifier);
return Traits::ParseDoExpression(ok);
return impl()->ParseDoExpression(ok);
}
break;
......@@ -1740,7 +1739,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseExpression(
bool accept_IN, bool* ok) {
ExpressionClassifier classifier(this);
ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK);
Traits::RewriteNonPattern(&classifier, CHECK_OK);
impl()->RewriteNonPattern(&classifier, CHECK_OK);
return result;
}
......@@ -1872,7 +1871,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseArrayLiteral(
literal_index, pos);
if (first_spread_index >= 0) {
result = factory()->NewRewritableExpression(result);
Traits::QueueNonPatternForRewriting(result, ok);
impl()->QueueNonPatternForRewriting(result, ok);
if (!*ok) {
// If the non-pattern rewriting mechanism is used in the future for
// rewriting other things than spreads, this error message will have
......@@ -1923,7 +1922,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
ExpressionClassifier computed_name_classifier(this);
ExpressionT expression =
ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK);
Traits::RewriteNonPattern(&computed_name_classifier, CHECK_OK);
impl()->RewriteNonPattern(&computed_name_classifier, CHECK_OK);
classifier->Accumulate(&computed_name_classifier,
ExpressionClassifier::ExpressionProductions);
Expect(Token::RBRACK, CHECK_OK);
......@@ -2037,7 +2036,7 @@ ParserBase<Impl>::ParsePropertyDefinition(
ExpressionClassifier rhs_classifier(this);
ExpressionT rhs = this->ParseAssignmentExpression(
true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
Traits::RewriteNonPattern(&rhs_classifier,
impl()->RewriteNonPattern(&rhs_classifier,
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
classifier->Accumulate(&rhs_classifier,
ExpressionClassifier::ExpressionProductions);
......@@ -2095,7 +2094,7 @@ ParserBase<Impl>::ParsePropertyDefinition(
: FunctionKind::kBaseConstructor;
}
ExpressionT value = this->ParseFunctionLiteral(
ExpressionT value = impl()->ParseFunctionLiteral(
*name, scanner()->location(), kSkipFunctionNameCheck, kind,
kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, language_mode(),
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
......@@ -2112,7 +2111,7 @@ ParserBase<Impl>::ParsePropertyDefinition(
ObjectLiteralPropertyT property = ParsePropertyDefinition(
checker, true, has_extends, MethodKind::kStatic, is_computed_name,
nullptr, classifier, name, ok);
Traits::RewriteNonPattern(classifier, ok);
impl()->RewriteNonPattern(classifier, ok);
return property;
}
......@@ -2134,7 +2133,7 @@ ParserBase<Impl>::ParsePropertyDefinition(
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
}
typename Traits::Type::FunctionLiteral value = this->ParseFunctionLiteral(
typename Traits::Type::FunctionLiteral value = impl()->ParseFunctionLiteral(
*name, scanner()->location(), kSkipFunctionNameCheck,
is_get ? FunctionKind::kGetterFunction : FunctionKind::kSetterFunction,
kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, language_mode(),
......@@ -2240,7 +2239,7 @@ ParserBase<Impl>::ParseArguments(Scanner::Location* first_spread_arg_loc,
true, classifier, CHECK_OK_CUSTOM(NullExpressionList));
CheckNoTailCallExpressions(classifier, CHECK_OK_CUSTOM(NullExpressionList));
if (!maybe_arrow) {
Traits::RewriteNonPattern(classifier,
impl()->RewriteNonPattern(classifier,
CHECK_OK_CUSTOM(NullExpressionList));
}
if (is_spread) {
......@@ -2285,7 +2284,7 @@ ParserBase<Impl>::ParseArguments(Scanner::Location* first_spread_arg_loc,
if (!maybe_arrow || peek() != Token::ARROW) {
if (maybe_arrow) {
Traits::RewriteNonPattern(classifier,
impl()->RewriteNonPattern(classifier,
CHECK_OK_CUSTOM(NullExpressionList));
}
if (spread_arg.IsValid()) {
......@@ -2458,7 +2457,7 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN,
ExpressionT right =
this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK);
CheckNoTailCallExpressions(&rhs_classifier, CHECK_OK);
Traits::RewriteNonPattern(&rhs_classifier, CHECK_OK);
impl()->RewriteNonPattern(&rhs_classifier, CHECK_OK);
classifier->Accumulate(
&rhs_classifier,
ExpressionClassifier::ExpressionProductions |
......@@ -2494,14 +2493,14 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN,
if (op == Token::ASSIGN_EXP) {
DCHECK(!is_destructuring_assignment);
return Traits::RewriteAssignExponentiation(expression, right, pos);
return impl()->RewriteAssignExponentiation(expression, right, pos);
}
ExpressionT result = factory()->NewAssignment(op, expression, right, pos);
if (is_destructuring_assignment) {
result = factory()->NewRewritableExpression(result);
Traits::QueueDestructuringAssignmentForRewriting(result);
impl()->QueueDestructuringAssignmentForRewriting(result);
}
return result;
......@@ -2541,13 +2540,13 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseYieldExpression(
// Delegating yields require an RHS; fall through.
default:
expression = ParseAssignmentExpression(accept_IN, classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
break;
}
}
if (delegating) {
return Traits::RewriteYieldStar(generator_object, expression, pos);
return impl()->RewriteYieldStar(generator_object, expression, pos);
}
expression = Traits::BuildIteratorResult(expression, false);
......@@ -2636,7 +2635,7 @@ ParserBase<Impl>::ParseConditionalExpression(bool accept_IN,
this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK);
if (peek() != Token::CONDITIONAL) return expression;
CheckNoTailCallExpressions(classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::CONDITIONAL);
......@@ -2644,11 +2643,11 @@ ParserBase<Impl>::ParseConditionalExpression(bool accept_IN,
// expressions we always accept the 'in' keyword; see ECMA-262,
// section 11.12, page 58.
ExpressionT left = ParseAssignmentExpression(true, classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
Expect(Token::COLON, CHECK_OK);
ExpressionT right =
ParseAssignmentExpression(accept_IN, classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
return factory()->NewConditional(expression, left, right, pos);
}
......@@ -2663,7 +2662,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBinaryExpression(
// prec1 >= 4
while (Precedence(peek(), accept_IN) == prec1) {
CheckNoTailCallExpressions(classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
Token::Value op = Next();
......@@ -2676,7 +2675,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBinaryExpression(
if (op != Token::OR && op != Token::AND) {
CheckNoTailCallExpressions(classifier, CHECK_OK);
}
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos,
factory())) {
......@@ -2700,7 +2699,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseBinaryExpression(
x = factory()->NewUnaryOperation(Token::NOT, x, pos);
}
} else if (op == Token::EXP) {
x = Traits::RewriteExponentiation(x, y, pos);
x = impl()->RewriteExponentiation(x, y, pos);
} else {
// We have a "normal" binary operation.
x = factory()->NewBinaryOperation(op, x, y, pos);
......@@ -2735,7 +2734,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseUnaryExpression(
int pos = position();
ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK);
CheckNoTailCallExpressions(classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
if (op == Token::DELETE && is_strict(language_mode())) {
if (this->IsIdentifier(expression)) {
......@@ -2765,7 +2764,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseUnaryExpression(
expression, beg_pos, scanner()->location().end_pos,
MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK);
this->MarkExpressionAsAssigned(expression);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
return factory()->NewCountOperation(op,
true /* prefix */,
......@@ -2782,7 +2781,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseUnaryExpression(
ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK);
return Traits::RewriteAwaitExpression(value, await_pos);
return impl()->RewriteAwaitExpression(value, await_pos);
} else {
return this->ParsePostfixExpression(classifier, ok);
}
......@@ -2807,7 +2806,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePostfixExpression(
expression, lhs_beg_pos, scanner()->location().end_pos,
MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK);
expression = this->MarkExpressionAsAssigned(expression);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
Token::Value next = Next();
expression =
......@@ -2838,13 +2837,13 @@ ParserBase<Impl>::ParseLeftHandSideExpression(ExpressionClassifier* classifier,
switch (peek()) {
case Token::LBRACK: {
CheckNoTailCallExpressions(classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::LBRACK);
int pos = position();
ExpressionT index = ParseExpression(true, classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
result = factory()->NewProperty(result, index, pos);
Expect(Token::RBRACK, CHECK_OK);
break;
......@@ -2853,7 +2852,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(ExpressionClassifier* classifier,
case Token::LPAREN: {
CheckNoTailCallExpressions(classifier, CHECK_OK);
int pos;
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
if (scanner()->current_token() == Token::IDENTIFIER ||
scanner()->current_token() == Token::SUPER ||
......@@ -2919,8 +2918,8 @@ ParserBase<Impl>::ParseLeftHandSideExpression(ExpressionClassifier* classifier,
bool is_super_call = result->IsSuperCallReference();
if (spread_pos.IsValid()) {
args = Traits::PrepareSpreadArguments(args);
result = Traits::SpreadCall(result, args, pos);
args = impl()->PrepareSpreadArguments(args);
result = impl()->SpreadCall(result, args, pos);
} else {
result = factory()->NewCall(result, args, pos, is_possibly_eval);
}
......@@ -2939,7 +2938,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(ExpressionClassifier* classifier,
case Token::PERIOD: {
CheckNoTailCallExpressions(classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::PERIOD);
......@@ -2954,7 +2953,7 @@ ParserBase<Impl>::ParseLeftHandSideExpression(ExpressionClassifier* classifier,
case Token::TEMPLATE_SPAN:
case Token::TEMPLATE_TAIL: {
CheckNoTailCallExpressions(classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
result = ParseTemplateLiteral(result, position(), classifier, CHECK_OK);
......@@ -3006,7 +3005,7 @@ ParserBase<Impl>::ParseMemberWithNewPrefixesExpression(
result = this->ParseMemberWithNewPrefixesExpression(classifier, is_async,
CHECK_OK);
}
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
if (peek() == Token::LPAREN) {
// NewExpression with arguments.
Scanner::Location spread_pos;
......@@ -3014,8 +3013,8 @@ ParserBase<Impl>::ParseMemberWithNewPrefixesExpression(
this->ParseArguments(&spread_pos, classifier, CHECK_OK);
if (spread_pos.IsValid()) {
args = Traits::PrepareSpreadArguments(args);
result = Traits::SpreadCallNew(result, args, new_pos);
args = impl()->PrepareSpreadArguments(args);
result = impl()->SpreadCallNew(result, args, new_pos);
} else {
result = factory()->NewCallNew(result, args, new_pos);
}
......@@ -3082,7 +3081,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseMemberExpression(
function_name_location = scanner()->location();
function_type = FunctionLiteral::kNamedExpression;
}
result = this->ParseFunctionLiteral(
result = impl()->ParseFunctionLiteral(
name, function_name_location,
is_strict_reserved_name ? kFunctionNameIsStrictReserved
: kFunctionNameValidityUnknown,
......@@ -3169,14 +3168,14 @@ ParserBase<Impl>::ParseMemberExpressionContinuation(
switch (peek()) {
case Token::LBRACK: {
*is_async = false;
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
Consume(Token::LBRACK);
int pos = position();
ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
expression = factory()->NewProperty(expression, index, pos);
if (fni_ != NULL) {
this->PushPropertyName(fni_, index);
......@@ -3186,7 +3185,7 @@ ParserBase<Impl>::ParseMemberExpressionContinuation(
}
case Token::PERIOD: {
*is_async = false;
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
......@@ -3203,7 +3202,7 @@ ParserBase<Impl>::ParseMemberExpressionContinuation(
case Token::TEMPLATE_SPAN:
case Token::TEMPLATE_TAIL: {
*is_async = false;
Traits::RewriteNonPattern(classifier, CHECK_OK);
impl()->RewriteNonPattern(classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
int pos;
......@@ -3257,7 +3256,7 @@ void ParserBase<Impl>::ParseFormalParameter(FormalParametersT* parameters,
ExpressionClassifier init_classifier(this);
initializer = ParseAssignmentExpression(true, &init_classifier,
CHECK_OK_CUSTOM(Void));
Traits::RewriteNonPattern(&init_classifier, CHECK_OK_CUSTOM(Void));
impl()->RewriteNonPattern(&init_classifier, CHECK_OK_CUSTOM(Void));
ValidateFormalParameterInitializer(&init_classifier, CHECK_OK_CUSTOM(Void));
parameters->is_simple = false;
init_classifier.Discard();
......@@ -3429,14 +3428,14 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
formal_parameters.scope->AllowsLazyParsing());
if (is_lazily_parsed) {
body = this->NewStatementList(0, zone());
this->SkipLazyFunctionBody(&materialized_literal_count,
&expected_property_count, CHECK_OK);
impl()->SkipLazyFunctionBody(&materialized_literal_count,
&expected_property_count, CHECK_OK);
if (formal_parameters.materialized_literals_count > 0) {
materialized_literal_count +=
formal_parameters.materialized_literals_count;
}
} else {
body = this->ParseEagerFunctionBody(
body = impl()->ParseEagerFunctionBody(
this->EmptyIdentifier(), kNoSourcePosition, formal_parameters,
arrow_kind, FunctionLiteral::kAnonymousExpression, CHECK_OK);
materialized_literal_count =
......@@ -3455,22 +3454,22 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
CHECK_OK);
ExpressionClassifier classifier(this);
if (is_async) {
this->ParseAsyncArrowSingleExpressionBody(body, accept_IN, &classifier,
pos, CHECK_OK);
Traits::RewriteNonPattern(&classifier, CHECK_OK);
impl()->ParseAsyncArrowSingleExpressionBody(body, accept_IN,
&classifier, pos, CHECK_OK);
impl()->RewriteNonPattern(&classifier, CHECK_OK);
} else {
ExpressionT expression =
ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK);
Traits::RewriteNonPattern(&classifier, CHECK_OK);
impl()->RewriteNonPattern(&classifier, CHECK_OK);
body->Add(factory()->NewReturnStatement(expression, pos), zone());
if (allow_tailcalls() && !is_sloppy(language_mode())) {
// ES6 14.6.1 Static Semantics: IsInTailPosition
this->MarkTailPosition(expression);
impl()->MarkTailPosition(expression);
}
}
materialized_literal_count = function_state.materialized_literal_count();
expected_property_count = function_state.expected_property_count();
this->MarkCollectedTailCallExpressions();
impl()->MarkCollectedTailCallExpressions();
}
formal_parameters.scope->set_end_position(scanner()->location().end_pos);
......@@ -3488,9 +3487,9 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
CheckStrictOctalLiteral(formal_parameters.scope->start_position(),
scanner()->location().end_pos, CHECK_OK);
}
this->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK);
impl()->CheckConflictingVarDeclarations(formal_parameters.scope, CHECK_OK);
Traits::RewriteDestructuringAssignments();
impl()->RewriteDestructuringAssignments();
}
FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
......@@ -3531,15 +3530,15 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
Consume(Token::TEMPLATE_TAIL);
int pos = position();
CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK);
typename Traits::TemplateLiteralState ts = Traits::OpenTemplateLiteral(pos);
Traits::AddTemplateSpan(&ts, true);
return Traits::CloseTemplateLiteral(&ts, start, tag);
typename Impl::TemplateLiteralState ts = impl()->OpenTemplateLiteral(pos);
impl()->AddTemplateSpan(&ts, true);
return impl()->CloseTemplateLiteral(&ts, start, tag);
}
Consume(Token::TEMPLATE_SPAN);
int pos = position();
typename Traits::TemplateLiteralState ts = Traits::OpenTemplateLiteral(pos);
Traits::AddTemplateSpan(&ts, false);
typename Impl::TemplateLiteralState ts = impl()->OpenTemplateLiteral(pos);
impl()->AddTemplateSpan(&ts, false);
Token::Value next;
// If we open with a TEMPLATE_SPAN, we must scan the subsequent expression,
......@@ -3565,8 +3564,8 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
int expr_pos = peek_position();
ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK);
CheckNoTailCallExpressions(classifier, CHECK_OK);
Traits::RewriteNonPattern(classifier, CHECK_OK);
Traits::AddTemplateExpression(&ts, expression);
impl()->RewriteNonPattern(classifier, CHECK_OK);
impl()->AddTemplateExpression(&ts, expression);
if (peek() != Token::RBRACE) {
ReportMessageAt(Scanner::Location(expr_pos, peek_position()),
......@@ -3594,13 +3593,13 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
return Traits::EmptyExpression();
}
Traits::AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL);
impl()->AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL);
} while (next == Token::TEMPLATE_SPAN);
DCHECK_EQ(next, Token::TEMPLATE_TAIL);
CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK);
// Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral.
return Traits::CloseTemplateLiteral(&ts, start, tag);
return impl()->CloseTemplateLiteral(&ts, start, tag);
}
template <typename Impl>
......
......@@ -678,36 +678,10 @@ Literal* ParserBaseTraits<Parser>::GetLiteralTheHole(
return factory->NewTheHoleLiteral(kNoSourcePosition);
}
Expression* ParserBaseTraits<Parser>::ParseV8Intrinsic(bool* ok) {
return delegate()->ParseV8Intrinsic(ok);
}
FunctionLiteral* ParserBaseTraits<Parser>::ParseFunctionLiteral(
const AstRawString* name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind,
int function_token_position, FunctionLiteral::FunctionType type,
LanguageMode language_mode, bool* ok) {
return delegate()->ParseFunctionLiteral(
name, function_name_location, function_name_validity, kind,
function_token_position, type, language_mode, ok);
}
Expression* ParserBaseTraits<Parser>::ParseClassLiteral(
Type::ExpressionClassifier* classifier, const AstRawString* name,
Scanner::Location class_name_location, bool name_is_strict_reserved,
int pos, bool* ok) {
return delegate()->ParseClassLiteral(classifier, name, class_name_location,
name_is_strict_reserved, pos, ok);
}
void ParserBaseTraits<Parser>::MarkTailPosition(Expression* expression) {
void Parser::MarkTailPosition(Expression* expression) {
expression->MarkTail();
}
void ParserBaseTraits<Parser>::MarkCollectedTailCallExpressions() {
delegate()->MarkCollectedTailCallExpressions();
}
Parser::Parser(ParseInfo* info)
: ParserBase<Parser>(info->zone(), &scanner_, info->stack_limit(),
info->extension(), info->ast_value_factory(), NULL),
......@@ -940,7 +914,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
}
if (ok) {
ParserBaseTraits<Parser>::RewriteDestructuringAssignments();
RewriteDestructuringAssignments();
result = factory()->NewScriptOrEvalFunctionLiteral(
scope, body, function_state.materialized_literal_count(),
function_state.expected_property_count());
......@@ -3984,15 +3958,6 @@ void Parser::ParseArrowFunctionFormalParameters(
AddFormalParameter(parameters, expr, initializer, end_pos, is_rest);
}
void ParserBaseTraits<Parser>::ParseAsyncArrowSingleExpressionBody(
ZoneList<Statement*>* body, bool accept_IN,
Type::ExpressionClassifier* classifier, int pos, bool* ok) {
delegate()->DesugarAsyncFunctionBody(
delegate()->ast_value_factory()->empty_string(), delegate()->scope(),
body, classifier, kAsyncArrowFunction,
Parser::FunctionBodyType::kSingleExpression, accept_IN, pos, ok);
}
void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name,
Scope* scope, ZoneList<Statement*>* body,
ExpressionClassifier* classifier,
......@@ -4030,7 +3995,7 @@ void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name,
} else {
return_value =
ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_VOID);
ParserBaseTraits<Parser>::RewriteNonPattern(classifier, CHECK_OK_VOID);
RewriteNonPattern(classifier, CHECK_OK_VOID);
}
return_value = BuildPromiseResolve(return_value, return_value->position());
......@@ -4334,7 +4299,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
if (body) {
// If body can be inspected, rewrite queued destructuring assignments
ParserBaseTraits<Parser>::RewriteDestructuringAssignments();
RewriteDestructuringAssignments();
}
has_duplicate_parameters =
!formals_classifier.is_valid_formal_parameter_list_without_duplicates();
......@@ -5354,9 +5319,8 @@ void Parser::ParseOnBackground(ParseInfo* info) {
}
}
ParserBaseTraits<Parser>::TemplateLiteralState Parser::OpenTemplateLiteral(
int pos) {
return new (zone()) ParserBaseTraits<Parser>::TemplateLiteral(zone(), pos);
Parser::TemplateLiteralState Parser::OpenTemplateLiteral(int pos) {
return new (zone()) TemplateLiteral(zone(), pos);
}
......@@ -5632,28 +5596,7 @@ Expression* ParserBaseTraits<Parser>::ExpressionListToExpression(
return expr;
}
void ParserBaseTraits<Parser>::RewriteDestructuringAssignments() {
delegate()->RewriteDestructuringAssignments();
}
Expression* ParserBaseTraits<Parser>::RewriteExponentiation(Expression* left,
Expression* right,
int pos) {
return delegate()->RewriteExponentiation(left, right, pos);
}
Expression* ParserBaseTraits<Parser>::RewriteAssignExponentiation(
Expression* left, Expression* right, int pos) {
return delegate()->RewriteAssignExponentiation(left, right, pos);
}
void ParserBaseTraits<Parser>::RewriteNonPattern(
Type::ExpressionClassifier* classifier, bool* ok) {
delegate()->RewriteNonPattern(classifier, ok);
}
Expression* ParserBaseTraits<Parser>::RewriteAwaitExpression(Expression* value,
int await_pos) {
Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) {
// yield %AsyncFunctionAwait(.generator_object, <operand>)
Variable* generator_object_variable =
delegate()->function_state_->generator_object_variable();
......@@ -5905,17 +5848,15 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
return factory()->NewDoExpression(do_block, result, lit->position());
}
void ParserBaseTraits<Parser>::QueueDestructuringAssignmentForRewriting(
Expression* expr) {
void Parser::QueueDestructuringAssignmentForRewriting(Expression* expr) {
DCHECK(expr->IsRewritableExpression());
delegate()->function_state_->AddDestructuringAssignment(
Parser::DestructuringAssignment(expr, delegate()->scope()));
function_state_->AddDestructuringAssignment(
DestructuringAssignment(expr, delegate()->scope()));
}
void ParserBaseTraits<Parser>::QueueNonPatternForRewriting(Expression* expr,
bool* ok) {
void Parser::QueueNonPatternForRewriting(Expression* expr, bool* ok) {
DCHECK(expr->IsRewritableExpression());
delegate()->function_state_->AddNonPatternForRewriting(expr, ok);
function_state_->AddNonPatternForRewriting(expr, ok);
}
void ParserBaseTraits<Parser>::SetFunctionNameFromPropertyName(
......
......@@ -336,10 +336,6 @@ class ParserBaseTraits<Parser> {
const ParserFormalParameters& parameters,
ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok);
void ParseAsyncArrowSingleExpressionBody(
ZoneList<Statement*>* body, bool accept_IN,
Type::ExpressionClassifier* classifier, int pos, bool* ok);
V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters,
Expression* pattern,
Expression* initializer,
......@@ -353,124 +349,28 @@ class ParserBaseTraits<Parser> {
const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
const Scope::Snapshot& scope_snapshot, bool* ok);
V8_INLINE Expression* ParseAsyncFunctionExpression(bool* ok);
V8_INLINE DoExpression* ParseDoExpression(bool* ok);
void ReindexLiterals(const ParserFormalParameters& parameters);
// Temporary glue; these functions will move to ParserBase.
Expression* ParseV8Intrinsic(bool* ok);
FunctionLiteral* ParseFunctionLiteral(
const AstRawString* name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind,
int function_token_position, FunctionLiteral::FunctionType type,
LanguageMode language_mode, bool* ok);
V8_INLINE void SkipLazyFunctionBody(
int* materialized_literal_count, int* expected_property_count, bool* ok,
Scanner::BookmarkScope* bookmark = nullptr);
V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody(
const AstRawString* name, int pos,
const ParserFormalParameters& parameters, FunctionKind kind,
FunctionLiteral::FunctionType function_type, bool* ok);
Expression* ParseClassLiteral(Type::ExpressionClassifier* classifier,
const AstRawString* name,
Scanner::Location class_name_location,
bool name_is_strict_reserved, int pos,
bool* ok);
V8_INLINE void MarkCollectedTailCallExpressions();
V8_INLINE void MarkTailPosition(Expression* expression);
V8_INLINE void CheckConflictingVarDeclarations(Scope* scope, bool* ok);
class TemplateLiteral : public ZoneObject {
public:
TemplateLiteral(Zone* zone, int pos)
: cooked_(8, zone), raw_(8, zone), expressions_(8, zone), pos_(pos) {}
const ZoneList<Expression*>* cooked() const { return &cooked_; }
const ZoneList<Expression*>* raw() const { return &raw_; }
const ZoneList<Expression*>* expressions() const { return &expressions_; }
int position() const { return pos_; }
void AddTemplateSpan(Literal* cooked, Literal* raw, int end, Zone* zone) {
DCHECK_NOT_NULL(cooked);
DCHECK_NOT_NULL(raw);
cooked_.Add(cooked, zone);
raw_.Add(raw, zone);
}
void AddExpression(Expression* expression, Zone* zone) {
DCHECK_NOT_NULL(expression);
expressions_.Add(expression, zone);
}
private:
ZoneList<Expression*> cooked_;
ZoneList<Expression*> raw_;
ZoneList<Expression*> expressions_;
int pos_;
};
typedef TemplateLiteral* TemplateLiteralState;
V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos);
V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail);
V8_INLINE void AddTemplateExpression(TemplateLiteralState* state,
Expression* expression);
V8_INLINE Expression* CloseTemplateLiteral(TemplateLiteralState* state,
int start, Expression* tag);
V8_INLINE Expression* NoTemplateTag() { return NULL; }
V8_INLINE static bool IsTaggedTemplate(const Expression* tag) {
return tag != NULL;
}
V8_INLINE ZoneList<v8::internal::Expression*>* PrepareSpreadArguments(
ZoneList<v8::internal::Expression*>* list);
V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {}
V8_INLINE Expression* SpreadCall(Expression* function,
ZoneList<v8::internal::Expression*>* args,
int pos);
V8_INLINE Expression* SpreadCallNew(Expression* function,
ZoneList<v8::internal::Expression*>* args,
int pos);
Expression* ExpressionListToExpression(ZoneList<Expression*>* args);
// Rewrite all DestructuringAssignments in the current FunctionState.
V8_INLINE void RewriteDestructuringAssignments();
V8_INLINE Expression* RewriteExponentiation(Expression* left,
Expression* right, int pos);
V8_INLINE Expression* RewriteAssignExponentiation(Expression* left,
Expression* right, int pos);
V8_INLINE Expression* RewriteAwaitExpression(Expression* value, int pos);
V8_INLINE void QueueDestructuringAssignmentForRewriting(
Expression* assignment);
V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok);
void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
const AstRawString* name);
void SetFunctionNameFromIdentifierRef(Expression* value,
Expression* identifier);
// Rewrite expressions that are not used as patterns
V8_INLINE void RewriteNonPattern(Type::ExpressionClassifier* classifier,
bool* ok);
V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>*
GetReportedErrorList() const;
V8_INLINE Zone* zone() const;
V8_INLINE ZoneList<Expression*>* GetNonPatternList() const;
V8_INLINE Expression* RewriteYieldStar(Expression* generator,
Expression* expression, int pos);
};
class Parser : public ParserBase<Parser> {
......@@ -499,6 +399,7 @@ class Parser : public ParserBase<Parser> {
void HandleSourceURLComments(Isolate* isolate, Handle<Script> script);
private:
friend class ParserBase<Parser>;
// TODO(nikolaos): This should not be necessary. It will be removed
// when the traits object stops delegating to the implementation object.
friend class ParserBaseTraits<Parser>;
......@@ -877,6 +778,37 @@ class Parser : public ParserBase<Parser> {
void ThrowPendingError(Isolate* isolate, Handle<Script> script);
class TemplateLiteral : public ZoneObject {
public:
TemplateLiteral(Zone* zone, int pos)
: cooked_(8, zone), raw_(8, zone), expressions_(8, zone), pos_(pos) {}
const ZoneList<Expression*>* cooked() const { return &cooked_; }
const ZoneList<Expression*>* raw() const { return &raw_; }
const ZoneList<Expression*>* expressions() const { return &expressions_; }
int position() const { return pos_; }
void AddTemplateSpan(Literal* cooked, Literal* raw, int end, Zone* zone) {
DCHECK_NOT_NULL(cooked);
DCHECK_NOT_NULL(raw);
cooked_.Add(cooked, zone);
raw_.Add(raw, zone);
}
void AddExpression(Expression* expression, Zone* zone) {
DCHECK_NOT_NULL(expression);
expressions_.Add(expression, zone);
}
private:
ZoneList<Expression*> cooked_;
ZoneList<Expression*> raw_;
ZoneList<Expression*> expressions_;
int pos_;
};
typedef TemplateLiteral* TemplateLiteralState;
TemplateLiteralState OpenTemplateLiteral(int pos);
void AddTemplateSpan(TemplateLiteralState* state, bool tail);
void AddTemplateExpression(TemplateLiteralState* state,
......@@ -885,6 +817,16 @@ class Parser : public ParserBase<Parser> {
Expression* tag);
uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit);
void ParseAsyncArrowSingleExpressionBody(ZoneList<Statement*>* body,
bool accept_IN,
ExpressionClassifier* classifier,
int pos, bool* ok) {
DesugarAsyncFunctionBody(ast_value_factory()->empty_string(), scope(), body,
classifier, kAsyncArrowFunction,
FunctionBodyType::kSingleExpression, accept_IN,
pos, ok);
}
ZoneList<v8::internal::Expression*>* PrepareSpreadArguments(
ZoneList<v8::internal::Expression*>* list);
Expression* SpreadCall(Expression* function,
......@@ -896,7 +838,9 @@ class Parser : public ParserBase<Parser> {
void RaiseLanguageMode(LanguageMode mode);
V8_INLINE void MarkCollectedTailCallExpressions();
V8_INLINE void MarkTailPosition(Expression* expression);
// Rewrite all DestructuringAssignments in the current FunctionState.
V8_INLINE void RewriteDestructuringAssignments();
V8_INLINE Expression* RewriteExponentiation(Expression* left,
......@@ -907,8 +851,13 @@ class Parser : public ParserBase<Parser> {
friend class NonPatternRewriter;
V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit);
// Rewrite expressions that are not used as patterns
V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok);
V8_INLINE void QueueDestructuringAssignmentForRewriting(
Expression* assignment);
V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok);
friend class InitializerRewriter;
void RewriteParameterInitializer(Expression* expr, Scope* scope);
......@@ -933,6 +882,8 @@ class Parser : public ParserBase<Parser> {
Expression* completion);
Statement* CheckCallable(Variable* var, Expression* error, int pos);
V8_INLINE Expression* RewriteAwaitExpression(Expression* value, int pos);
Expression* RewriteYieldStar(Expression* generator, Expression* expression,
int pos);
......@@ -972,25 +923,6 @@ const AstRawString* ParserBaseTraits<Parser>::EmptyIdentifierString() const {
return delegate()->ast_value_factory()->empty_string();
}
void ParserBaseTraits<Parser>::SkipLazyFunctionBody(
int* materialized_literal_count, int* expected_property_count, bool* ok,
Scanner::BookmarkScope* bookmark) {
return delegate()->SkipLazyFunctionBody(
materialized_literal_count, expected_property_count, ok, bookmark);
}
ZoneList<Statement*>* ParserBaseTraits<Parser>::ParseEagerFunctionBody(
const AstRawString* name, int pos, const ParserFormalParameters& parameters,
FunctionKind kind, FunctionLiteral::FunctionType function_type, bool* ok) {
return delegate()->ParseEagerFunctionBody(name, pos, parameters, kind,
function_type, ok);
}
void ParserBaseTraits<Parser>::CheckConflictingVarDeclarations(Scope* scope,
bool* ok) {
delegate()->CheckConflictingVarDeclarations(scope, ok);
}
// Support for handling complex values (array and object literals) that
// can be fully handled at compile time.
......@@ -1020,41 +952,6 @@ class CompileTimeValue: public AllStatic {
DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
};
ParserBaseTraits<Parser>::TemplateLiteralState
ParserBaseTraits<Parser>::OpenTemplateLiteral(int pos) {
return delegate()->OpenTemplateLiteral(pos);
}
void ParserBaseTraits<Parser>::AddTemplateSpan(TemplateLiteralState* state,
bool tail) {
delegate()->AddTemplateSpan(state, tail);
}
void ParserBaseTraits<Parser>::AddTemplateExpression(
TemplateLiteralState* state, Expression* expression) {
delegate()->AddTemplateExpression(state, expression);
}
Expression* ParserBaseTraits<Parser>::CloseTemplateLiteral(
TemplateLiteralState* state, int start, Expression* tag) {
return delegate()->CloseTemplateLiteral(state, start, tag);
}
ZoneList<v8::internal::Expression*>* ParserBaseTraits<
Parser>::PrepareSpreadArguments(ZoneList<v8::internal::Expression*>* list) {
return delegate()->PrepareSpreadArguments(list);
}
Expression* ParserBaseTraits<Parser>::SpreadCall(
Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) {
return delegate()->SpreadCall(function, args, pos);
}
Expression* ParserBaseTraits<Parser>::SpreadCallNew(
Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) {
return delegate()->SpreadCallNew(function, args, pos);
}
void ParserBaseTraits<Parser>::AddFormalParameter(
ParserFormalParameters* parameters, Expression* pattern,
Expression* initializer, int initializer_end_position, bool is_rest) {
......@@ -1112,20 +1009,6 @@ void ParserBaseTraits<Parser>::AddParameterInitializationBlock(
}
}
Expression* ParserBaseTraits<Parser>::ParseAsyncFunctionExpression(bool* ok) {
return delegate()->ParseAsyncFunctionExpression(ok);
}
DoExpression* ParserBaseTraits<Parser>::ParseDoExpression(bool* ok) {
return delegate()->ParseDoExpression(ok);
}
Expression* ParserBaseTraits<Parser>::RewriteYieldStar(Expression* generator,
Expression* iterable,
int pos) {
return delegate()->RewriteYieldStar(generator, iterable, pos);
}
} // namespace internal
} // namespace v8
......
......@@ -94,20 +94,6 @@ PreParserExpression ParserBaseTraits<PreParser>::ExpressionFromString(
return PreParserExpression::StringLiteral();
}
PreParserExpression ParserBaseTraits<PreParser>::ParseV8Intrinsic(bool* ok) {
return delegate()->ParseV8Intrinsic(ok);
}
PreParserExpression ParserBaseTraits<PreParser>::ParseFunctionLiteral(
PreParserIdentifier name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind,
int function_token_position, FunctionLiteral::FunctionType type,
LanguageMode language_mode, bool* ok) {
return delegate()->ParseFunctionLiteral(
name, function_name_location, function_name_validity, kind,
function_token_position, type, language_mode, ok);
}
PreParser::PreParseResult PreParser::PreParseLazyFunction(
LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters,
bool parsing_module, ParserRecorder* log, Scanner::BookmarkScope* bookmark,
......@@ -148,14 +134,6 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
return kPreParseSuccess;
}
PreParserExpression ParserBaseTraits<PreParser>::ParseClassLiteral(
Type::ExpressionClassifier* classifier, PreParserIdentifier name,
Scanner::Location class_name_location, bool name_is_strict_reserved,
int pos, bool* ok) {
return delegate()->ParseClassLiteral(classifier, name, class_name_location,
name_is_strict_reserved, pos, ok);
}
// Preparsing checks a JavaScript program and emits preparse-data that helps
// a later parsing to be faster.
......@@ -1276,14 +1254,13 @@ PreParserExpression PreParser::ParseDoExpression(bool* ok) {
return PreParserExpression::Default();
}
void ParserBaseTraits<PreParser>::ParseAsyncArrowSingleExpressionBody(
void PreParser::ParseAsyncArrowSingleExpressionBody(
PreParserStatementList body, bool accept_IN,
Type::ExpressionClassifier* classifier, int pos, bool* ok) {
Scope* scope = delegate()->scope();
scope->ForceContextAllocation();
ExpressionClassifier* classifier, int pos, bool* ok) {
scope()->ForceContextAllocation();
PreParserExpression return_value = delegate()->ParseAssignmentExpression(
accept_IN, classifier, CHECK_OK_CUSTOM(Void));
PreParserExpression return_value =
ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_CUSTOM(Void));
body->Add(PreParserStatement::ExpressionStatement(return_value), zone());
}
......
......@@ -862,11 +862,6 @@ class ParserBaseTraits<PreParser> {
const PreParserFormalParameters& parameters, PreParserStatementList body,
bool is_async, bool* ok) {}
void ParseAsyncArrowSingleExpressionBody(
PreParserStatementList body, bool accept_IN,
Type::ExpressionClassifier* classifier, int pos, bool* ok);
void AddFormalParameter(PreParserFormalParameters* parameters,
PreParserExpression pattern,
PreParserExpression initializer,
......@@ -887,52 +882,8 @@ class ParserBaseTraits<PreParser> {
const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
const Scope::Snapshot& scope_snapshot, bool* ok);
V8_INLINE PreParserExpression ParseAsyncFunctionExpression(bool* ok);
V8_INLINE PreParserExpression ParseDoExpression(bool* ok);
void ReindexLiterals(const PreParserFormalParameters& parameters) {}
// Temporary glue; these functions will move to ParserBase.
PreParserExpression ParseV8Intrinsic(bool* ok);
PreParserExpression ParseFunctionLiteral(
PreParserIdentifier name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind,
int function_token_position, FunctionLiteral::FunctionType type,
LanguageMode language_mode, bool* ok);
V8_INLINE void SkipLazyFunctionBody(
int* materialized_literal_count, int* expected_property_count, bool* ok,
Scanner::BookmarkScope* bookmark = nullptr) {
UNREACHABLE();
}
V8_INLINE PreParserStatementList ParseEagerFunctionBody(
PreParserIdentifier name, int pos,
const PreParserFormalParameters& parameters, FunctionKind kind,
FunctionLiteral::FunctionType function_type, bool* ok);
PreParserExpression ParseClassLiteral(Type::ExpressionClassifier* classifier,
PreParserIdentifier name,
Scanner::Location class_name_location,
bool name_is_strict_reserved, int pos,
bool* ok);
V8_INLINE void MarkCollectedTailCallExpressions() {}
V8_INLINE void MarkTailPosition(PreParserExpression expression) {}
void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {}
struct TemplateLiteralState {};
V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) {
return TemplateLiteralState();
}
V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {}
V8_INLINE void AddTemplateExpression(TemplateLiteralState* state,
PreParserExpression expression) {}
V8_INLINE PreParserExpression CloseTemplateLiteral(
TemplateLiteralState* state, int start, PreParserExpression tag);
V8_INLINE PreParserExpression NoTemplateTag() {
return PreParserExpression::NoTemplateTag();
}
......@@ -940,59 +891,22 @@ class ParserBaseTraits<PreParser> {
return !tag.IsNoTemplateTag();
}
V8_INLINE PreParserExpressionList
PrepareSpreadArguments(PreParserExpressionList list) {
return list;
}
inline void MaterializeUnspreadArgumentsLiterals(int count);
inline PreParserExpression SpreadCall(PreParserExpression function,
PreParserExpressionList args, int pos);
inline PreParserExpression SpreadCallNew(PreParserExpression function,
PreParserExpressionList args,
int pos);
inline PreParserExpression ExpressionListToExpression(
PreParserExpressionList args) {
return PreParserExpression::Default();
}
inline void RewriteDestructuringAssignments() {}
inline PreParserExpression RewriteExponentiation(PreParserExpression left,
PreParserExpression right,
int pos) {
return left;
}
inline PreParserExpression RewriteAssignExponentiation(
PreParserExpression left, PreParserExpression right, int pos) {
return left;
}
inline PreParserExpression RewriteAwaitExpression(PreParserExpression value,
int pos);
inline void QueueDestructuringAssignmentForRewriting(
PreParserExpression assignment) {}
inline void QueueNonPatternForRewriting(PreParserExpression expr, bool* ok) {}
void SetFunctionNameFromPropertyName(PreParserExpression property,
PreParserIdentifier name) {}
void SetFunctionNameFromIdentifierRef(PreParserExpression value,
PreParserExpression identifier) {}
inline void RewriteNonPattern(Type::ExpressionClassifier* classifier,
bool* ok);
V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>*
GetReportedErrorList() const;
V8_INLINE Zone* zone() const;
V8_INLINE ZoneList<PreParserExpression>* GetNonPatternList() const;
inline PreParserExpression RewriteYieldStar(PreParserExpression generator,
PreParserExpression expression,
int pos);
};
......@@ -1009,6 +923,7 @@ class ParserBaseTraits<PreParser> {
// That means that contextual checks (like a label being declared where
// it is used) are generally omitted.
class PreParser : public ParserBase<PreParser> {
friend class ParserBase<PreParser>;
// TODO(nikolaos): This should not be necessary. It will be removed
// when the traits object stops delegating to the implementation object.
friend class ParserBaseTraits<PreParser>;
......@@ -1139,6 +1054,11 @@ class PreParser : public ParserBase<PreParser> {
const PreParserFormalParameters& parameters, FunctionKind kind,
FunctionLiteral::FunctionType function_type, bool* ok);
V8_INLINE void SkipLazyFunctionBody(
int* materialized_literal_count, int* expected_property_count, bool* ok,
Scanner::BookmarkScope* bookmark = nullptr) {
UNREACHABLE();
}
Expression ParseFunctionLiteral(
Identifier name, Scanner::Location function_name_location,
FunctionNameValidity function_name_validity, FunctionKind kind,
......@@ -1153,6 +1073,69 @@ class PreParser : public ParserBase<PreParser> {
bool name_is_strict_reserved, int pos,
bool* ok);
struct TemplateLiteralState {};
V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) {
return TemplateLiteralState();
}
V8_INLINE void AddTemplateExpression(TemplateLiteralState* state,
PreParserExpression expression) {}
V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail) {}
V8_INLINE PreParserExpression CloseTemplateLiteral(
TemplateLiteralState* state, int start, PreParserExpression tag);
V8_INLINE void CheckConflictingVarDeclarations(Scope* scope, bool* ok) {}
V8_INLINE void MarkCollectedTailCallExpressions() {}
V8_INLINE void MarkTailPosition(PreParserExpression expression) {}
void ParseAsyncArrowSingleExpressionBody(PreParserStatementList body,
bool accept_IN,
ExpressionClassifier* classifier,
int pos, bool* ok);
V8_INLINE PreParserExpressionList
PrepareSpreadArguments(PreParserExpressionList list) {
return list;
}
V8_INLINE PreParserExpression SpreadCall(PreParserExpression function,
PreParserExpressionList args,
int pos);
V8_INLINE PreParserExpression SpreadCallNew(PreParserExpression function,
PreParserExpressionList args,
int pos);
V8_INLINE void RewriteDestructuringAssignments() {}
V8_INLINE PreParserExpression RewriteExponentiation(PreParserExpression left,
PreParserExpression right,
int pos) {
return left;
}
V8_INLINE PreParserExpression RewriteAssignExponentiation(
PreParserExpression left, PreParserExpression right, int pos) {
return left;
}
V8_INLINE PreParserExpression
RewriteAwaitExpression(PreParserExpression value, int pos) {
return value;
}
V8_INLINE PreParserExpression RewriteYieldStar(PreParserExpression generator,
PreParserExpression expression,
int pos) {
return PreParserExpression::Default();
}
V8_INLINE void RewriteNonPattern(Type::ExpressionClassifier* classifier,
bool* ok) {
ValidateExpression(classifier, ok);
}
V8_INLINE void QueueDestructuringAssignmentForRewriting(
PreParserExpression assignment) {}
V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr,
bool* ok) {}
int* use_counts_;
};
......@@ -1163,14 +1146,16 @@ void ParserBaseTraits<PreParser>::MaterializeUnspreadArgumentsLiterals(
}
}
PreParserExpression ParserBaseTraits<PreParser>::SpreadCall(
PreParserExpression function, PreParserExpressionList args, int pos) {
return delegate()->factory()->NewCall(function, args, pos);
PreParserExpression PreParser::SpreadCall(PreParserExpression function,
PreParserExpressionList args,
int pos) {
return factory()->NewCall(function, args, pos);
}
PreParserExpression ParserBaseTraits<PreParser>::SpreadCallNew(
PreParserExpression function, PreParserExpressionList args, int pos) {
return delegate()->factory()->NewCallNew(function, args, pos);
PreParserExpression PreParser::SpreadCallNew(PreParserExpression function,
PreParserExpressionList args,
int pos) {
return factory()->NewCallNew(function, args, pos);
}
void ParserBaseTraits<PreParser>::ParseArrowFunctionFormalParameterList(
......@@ -1181,25 +1166,6 @@ void ParserBaseTraits<PreParser>::ParseArrowFunctionFormalParameterList(
// lists that are too long.
}
PreParserExpression ParserBaseTraits<PreParser>::ParseAsyncFunctionExpression(
bool* ok) {
return delegate()->ParseAsyncFunctionExpression(ok);
}
PreParserExpression ParserBaseTraits<PreParser>::ParseDoExpression(bool* ok) {
return delegate()->ParseDoExpression(ok);
}
void ParserBaseTraits<PreParser>::RewriteNonPattern(
Type::ExpressionClassifier* classifier, bool* ok) {
delegate()->ValidateExpression(classifier, ok);
}
PreParserExpression ParserBaseTraits<PreParser>::RewriteAwaitExpression(
PreParserExpression value, int pos) {
return value;
}
ZoneList<PreParserExpression>* ParserBaseTraits<PreParser>::GetNonPatternList()
const {
return delegate()->function_state_->non_patterns_to_rewrite();
......@@ -1215,11 +1181,6 @@ Zone* ParserBaseTraits<PreParser>::zone() const {
return delegate()->function_state_->scope()->zone();
}
PreParserExpression ParserBaseTraits<PreParser>::RewriteYieldStar(
PreParserExpression generator, PreParserExpression expression, int pos) {
return PreParserExpression::Default();
}
PreParserStatementList PreParser::ParseEagerFunctionBody(
PreParserIdentifier function_name, int pos,
const PreParserFormalParameters& parameters, FunctionKind kind,
......@@ -1239,21 +1200,14 @@ PreParserStatementList PreParser::ParseEagerFunctionBody(
return PreParserStatementList();
}
PreParserStatementList ParserBaseTraits<PreParser>::ParseEagerFunctionBody(
PreParserIdentifier function_name, int pos,
const PreParserFormalParameters& parameters, FunctionKind kind,
FunctionLiteral::FunctionType function_type, bool* ok) {
return delegate()->ParseEagerFunctionBody(function_name, pos, parameters,
kind, function_type, ok);
}
PreParserExpression ParserBaseTraits<PreParser>::CloseTemplateLiteral(
TemplateLiteralState* state, int start, PreParserExpression tag) {
PreParserExpression PreParser::CloseTemplateLiteral(TemplateLiteralState* state,
int start,
PreParserExpression tag) {
if (IsTaggedTemplate(tag)) {
// Emulate generation of array literals for tag callsite
// 1st is array of cooked strings, second is array of raw strings
delegate()->function_state_->NextMaterializedLiteralIndex();
delegate()->function_state_->NextMaterializedLiteralIndex();
function_state_->NextMaterializedLiteralIndex();
function_state_->NextMaterializedLiteralIndex();
}
return EmptyExpression();
}
......
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