Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(838)

Unified Diff: src/parsing/parser-base.h

Issue 1567603005: Set up rewriting triggers (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Clean up and rename to RewriteNonPattern Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 35aee16b0a9b1f9b1f723d14acbe0808289dc590..a1ca30d4114d71bde6cc0cceebc5d7a403dee6ff 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -745,10 +745,9 @@ class ParserBase : public Traits {
bool* ok);
enum AssignmentExpressionFlags {
- kIsLeftHandSide = 0,
- kIsRightHandSide = 1 << 0,
- kIsPatternElement = 1 << 1,
- kIsPossibleArrowFormals = 1 << 2
+ kIsNormalAssignment = 0,
+ kIsPossiblePatternElement = 1 << 0,
+ kIsPossibleArrowFormals = 1 << 1
};
ExpressionT ParseAssignmentExpression(bool accept_IN, int flags,
@@ -757,7 +756,7 @@ class ParserBase : public Traits {
ExpressionT ParseAssignmentExpression(bool accept_IN,
ExpressionClassifier* classifier,
bool* ok) {
- return ParseAssignmentExpression(accept_IN, kIsLeftHandSide, classifier,
+ return ParseAssignmentExpression(accept_IN, kIsNormalAssignment, classifier,
ok);
}
ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok);
@@ -1036,11 +1035,6 @@ typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier(
if (!*ok) return Traits::EmptyIdentifier();
ValidateBindingPattern(&classifier, ok);
if (!*ok) return Traits::EmptyIdentifier();
- } else {
-#if 0 // TODO(nikolaos): is this needed?
- ValidateExpression(&classifier, ok);
- if (!*ok) return Traits::EmptyIdentifier();
-#endif
}
return result;
@@ -1356,9 +1350,6 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
classifier, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
if (peek() != Token::ARROW) {
-#if 0 // TODO(nikolaos): is this needed?
- ValidateExpression(classifier, CHECK_OK);
-#endif
expr->set_is_parenthesized();
}
return expr;
@@ -1423,7 +1414,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression(
bool accept_IN, bool* ok) {
ExpressionClassifier classifier;
ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK);
- result = Traits::RewriteExpression(result, &classifier, CHECK_OK);
+ result = Traits::RewriteNonPattern(result, &classifier, CHECK_OK);
return result;
}
@@ -1431,7 +1422,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression(
template <class Traits>
typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression(
bool accept_IN, ExpressionClassifier* classifier, bool* ok) {
- return ParseExpression(accept_IN, kIsLeftHandSide, classifier, ok);
+ return ParseExpression(accept_IN, kIsNormalAssignment, classifier, ok);
}
@@ -1532,7 +1523,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseArrayLiteral(
MessageTemplate::kElementAfterRest);
}
} else {
- elem = this->ParseAssignmentExpression(true, kIsPatternElement,
+ elem = this->ParseAssignmentExpression(true, kIsPossiblePatternElement,
classifier, CHECK_OK);
}
values->Add(elem, zone_);
@@ -1589,7 +1580,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
ExpressionClassifier computed_name_classifier;
ExpressionT expression =
ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK);
- expression = Traits::RewriteExpression(
+ expression = Traits::RewriteNonPattern(
expression, &computed_name_classifier, CHECK_OK);
classifier->Accumulate(computed_name_classifier,
ExpressionClassifier::ExpressionProductions);
@@ -1662,7 +1653,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
}
Consume(Token::COLON);
value = this->ParseAssignmentExpression(
- true, kIsPatternElement, classifier,
+ true, kIsPossiblePatternElement, classifier,
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
return factory()->NewObjectLiteralProperty(name_expression, value, false,
@@ -1704,7 +1695,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
ExpressionClassifier rhs_classifier;
ExpressionT rhs = this->ParseAssignmentExpression(
true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
- rhs = Traits::RewriteExpression(
+ rhs = Traits::RewriteNonPattern(
rhs, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
classifier->Accumulate(rhs_classifier,
ExpressionClassifier::ExpressionProductions);
@@ -1913,7 +1904,7 @@ typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments(
ExpressionT argument = this->ParseAssignmentExpression(
true, classifier, CHECK_OK_CUSTOM(NullExpressionList));
- argument = Traits::RewriteExpression(argument, classifier,
+ argument = Traits::RewriteNonPattern(argument, classifier,
CHECK_OK_CUSTOM(NullExpressionList));
if (is_spread) {
if (!spread_arg.IsValid()) {
@@ -1972,10 +1963,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
// ArrowFunction
// YieldExpression
// LeftHandSideExpression AssignmentOperator AssignmentExpression
- bool is_rhs = flags & kIsRightHandSide;
- bool is_pattern_element = flags & kIsPatternElement;
+ bool maybe_pattern_element = flags & kIsPossiblePatternElement;
+ bool maybe_arrow_formals = flags & kIsPossibleArrowFormals;
bool is_destructuring_assignment = false;
- bool is_arrow_formals = flags & kIsPossibleArrowFormals;
int lhs_beg_pos = peek_position();
if (peek() == Token::YIELD && is_generator()) {
@@ -2020,7 +2010,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
}
expression = this->ParseArrowFunctionLiteral(
accept_IN, parameters, arrow_formals_classifier, CHECK_OK);
- if (is_pattern_element) {
+ if (maybe_pattern_element) {
classifier->RecordPatternError(
Scanner::Location(lhs_beg_pos, scanner()->location().end_pos),
MessageTemplate::kInvalidDestructuringTarget);
@@ -2049,13 +2039,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
if (!Token::IsAssignmentOp(peek())) {
// Parsed conditional expression only (no assignment).
- if (is_pattern_element) {
+ if (maybe_pattern_element) {
CheckDestructuringElement(expression, classifier, lhs_beg_pos,
scanner()->location().end_pos);
- } else if (is_rhs && maybe_pattern) {
-#if 0 // TODO(nikolaos): is this needed?
- ValidateExpression(classifier, CHECK_OK);
-#endif
}
return expression;
}
@@ -2070,12 +2056,12 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
classifier->ForgiveCoverInitializedNameError();
ValidateAssignmentPattern(classifier, CHECK_OK);
is_destructuring_assignment = true;
- } else if (is_arrow_formals) {
+ } else if (maybe_arrow_formals) {
expression = this->ClassifyAndRewriteReferenceExpression(
classifier, expression, lhs_beg_pos, scanner()->location().end_pos,
MessageTemplate::kInvalidLhsInAssignment);
} else {
- if (is_pattern_element) {
+ if (maybe_pattern_element) {
CheckDestructuringElement(expression, classifier, lhs_beg_pos,
scanner()->location().end_pos);
}
@@ -2096,12 +2082,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
ExpressionClassifier rhs_classifier;
- int rhs_flags = flags;
- rhs_flags &= ~(kIsPatternElement | kIsPossibleArrowFormals);
- rhs_flags |= kIsRightHandSide;
- ExpressionT right = this->ParseAssignmentExpression(
- accept_IN, rhs_flags, &rhs_classifier, CHECK_OK);
- right = Traits::RewriteExpression(right, &rhs_classifier, CHECK_OK);
+ ExpressionT right =
+ this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK);
+ right = Traits::RewriteNonPattern(right, &rhs_classifier, CHECK_OK);
classifier->Accumulate(
rhs_classifier, ExpressionClassifier::ExpressionProductions |
ExpressionClassifier::CoverInitializedNameProduction);
@@ -2174,7 +2157,7 @@ ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier,
default:
expression = ParseAssignmentExpression(false, classifier, CHECK_OK);
expression =
- Traits::RewriteExpression(expression, classifier, CHECK_OK);
+ Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
break;
}
}
@@ -2207,7 +2190,7 @@ ParserBase<Traits>::ParseConditionalExpression(bool accept_IN,
ExpressionT expression =
this->ParseBinaryExpression(4, accept_IN, classifier, CHECK_OK);
if (peek() != Token::CONDITIONAL) return expression;
- expression = Traits::RewriteExpression(expression, classifier, CHECK_OK);
+ expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
ArrowFormalParametersUnexpectedToken(classifier);
BindingPatternUnexpectedToken(classifier);
Consume(Token::CONDITIONAL);
@@ -2215,11 +2198,11 @@ ParserBase<Traits>::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);
- left = Traits::RewriteExpression(left, classifier, CHECK_OK);
+ left = Traits::RewriteNonPattern(left, classifier, CHECK_OK);
Expect(Token::COLON, CHECK_OK);
ExpressionT right =
ParseAssignmentExpression(accept_IN, classifier, CHECK_OK);
- right = Traits::RewriteExpression(right, classifier, CHECK_OK);
+ right = Traits::RewriteNonPattern(right, classifier, CHECK_OK);
return factory()->NewConditional(expression, left, right, pos);
}
@@ -2235,7 +2218,7 @@ ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN,
for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) {
// prec1 >= 4
while (Precedence(peek(), accept_IN) == prec1) {
- x = Traits::RewriteExpression(x, classifier, CHECK_OK);
+ x = Traits::RewriteNonPattern(x, classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
Token::Value op = Next();
@@ -2243,7 +2226,7 @@ ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN,
int pos = position();
ExpressionT y =
ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK);
- y = Traits::RewriteExpression(y, classifier, CHECK_OK);
+ y = Traits::RewriteNonPattern(y, classifier, CHECK_OK);
if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos,
factory())) {
@@ -2306,7 +2289,7 @@ ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier,
op = Next();
int pos = position();
ExpressionT expression = ParseUnaryExpression(classifier, CHECK_OK);
- expression = Traits::RewriteExpression(expression, classifier, CHECK_OK);
+ expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
if (op == Token::DELETE && is_strict(language_mode())) {
if (is_strong(language_mode())) {
@@ -2333,7 +2316,7 @@ ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier,
expression, beg_pos, scanner()->location().end_pos,
MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK);
this->MarkExpressionAsAssigned(expression);
- expression = Traits::RewriteExpression(expression, classifier, CHECK_OK);
+ expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
return factory()->NewCountOperation(op,
true /* prefix */,
@@ -2365,7 +2348,7 @@ ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier,
expression, lhs_beg_pos, scanner()->location().end_pos,
MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK);
expression = this->MarkExpressionAsAssigned(expression);
- expression = Traits::RewriteExpression(expression, classifier, CHECK_OK);
+ expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
Token::Value next = Next();
expression =
@@ -2396,14 +2379,14 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
Consume(Token::LBRACK);
int pos = position();
ExpressionT index = ParseExpression(true, classifier, CHECK_OK);
- index = Traits::RewriteExpression(index, classifier, CHECK_OK);
+ index = Traits::RewriteNonPattern(index, classifier, CHECK_OK);
result = factory()->NewProperty(result, index, pos);
Expect(Token::RBRACK, CHECK_OK);
break;
}
case Token::LPAREN: {
- result = Traits::RewriteExpression(result, classifier, CHECK_OK);
+ result = Traits::RewriteNonPattern(result, classifier, CHECK_OK);
BindingPatternUnexpectedToken(classifier);
ArrowFormalParametersUnexpectedToken(classifier);
@@ -2531,7 +2514,7 @@ ParserBase<Traits>::ParseMemberWithNewPrefixesExpression(
} else {
result = this->ParseMemberWithNewPrefixesExpression(classifier, CHECK_OK);
}
- result = Traits::RewriteExpression(result, classifier, CHECK_OK);
+ result = Traits::RewriteNonPattern(result, classifier, CHECK_OK);
if (peek() == Token::LPAREN) {
// NewExpression with arguments.
Scanner::Location spread_pos;
@@ -2631,7 +2614,7 @@ ParserBase<Traits>::ParseStrongInitializationExpression(
Consume(Token::LBRACK);
int pos = position();
ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK);
- index = Traits::RewriteExpression(index, classifier, CHECK_OK);
+ index = Traits::RewriteNonPattern(index, classifier, CHECK_OK);
left = factory()->NewProperty(this_expr, index, pos);
if (fni_ != NULL) {
this->PushPropertyName(fni_, index);
@@ -2667,7 +2650,7 @@ ParserBase<Traits>::ParseStrongInitializationExpression(
ExpressionT right =
this->ParseAssignmentExpression(true, classifier, CHECK_OK);
- right = Traits::RewriteExpression(right, classifier, CHECK_OK);
+ right = Traits::RewriteNonPattern(right, classifier, CHECK_OK);
this->CheckAssigningFunctionLiteralToProperty(left, right);
function_state_->AddProperty();
if (fni_ != NULL) {
@@ -2824,7 +2807,7 @@ ParserBase<Traits>::ParseMemberExpressionContinuation(
Consume(Token::LBRACK);
int pos = position();
ExpressionT index = this->ParseExpression(true, classifier, CHECK_OK);
- index = Traits::RewriteExpression(index, classifier, CHECK_OK);
+ index = Traits::RewriteNonPattern(index, classifier, CHECK_OK);
expression = factory()->NewProperty(expression, index, pos);
if (fni_ != NULL) {
this->PushPropertyName(fni_, index);
@@ -2905,7 +2888,7 @@ void ParserBase<Traits>::ParseFormalParameter(
ExpressionClassifier init_classifier;
initializer = ParseAssignmentExpression(true, &init_classifier, ok);
if (!*ok) return;
- initializer = Traits::RewriteExpression(initializer, &init_classifier, ok);
+ initializer = Traits::RewriteNonPattern(initializer, &init_classifier, ok);
ValidateFormalParameterInitializer(&init_classifier, ok);
if (!*ok) return;
parameters->is_simple = false;
@@ -3079,7 +3062,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
ExpressionClassifier classifier;
ExpressionT expression =
ParseAssignmentExpression(accept_IN, &classifier, CHECK_OK);
- expression = Traits::RewriteExpression(expression, &classifier, CHECK_OK);
+ expression = Traits::RewriteNonPattern(expression, &classifier, CHECK_OK);
body = this->NewStatementList(1, zone());
this->AddParameterInitializationBlock(formal_parameters, body, CHECK_OK);
body->Add(factory()->NewReturnStatement(expression, pos), zone());
@@ -3185,7 +3168,7 @@ ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start,
int expr_pos = peek_position();
ExpressionT expression = this->ParseExpression(true, classifier, CHECK_OK);
- expression = Traits::RewriteExpression(expression, classifier, CHECK_OK);
+ expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK);
Traits::AddTemplateExpression(&ts, expression);
if (peek() != Token::RBRACE) {
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698