Commit 671ac25c authored by dslomov's avatar dslomov Committed by Commit bot

Use ExpressionClassifier for bindings.

Just a refactoring, real pattern parsing comes in a later CL.

R=rossberg@chromium.org,marja@chromium.org
BUG=v8:811
LOG=N

Review URL: https://codereview.chromium.org/1066933005

Cr-Commit-Position: refs/heads/master@{#28084}
parent 44350b3d
......@@ -1146,7 +1146,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
ExpressionClassifier classifier;
Expression* expression = ParseArrowFunctionLiteral(
scope, error_locs, has_rest, &classifier, &ok);
// TODO(dslomov): report error if not a valid expression.
ValidateExpression(&classifier, &ok);
if (ok) {
// Scanning must end at the same position that was recorded
// previously. If not, parsing has been interrupted due to a stack
......@@ -1616,7 +1616,7 @@ Statement* Parser::ParseExportDefault(bool* ok) {
int pos = peek_position();
ExpressionClassifier classifier;
Expression* expr = ParseAssignmentExpression(true, &classifier, CHECK_OK);
// TODO(dslomov): report error if not a valid expression.
ValidateExpression(&classifier, CHECK_OK);
ExpectSemicolon(CHECK_OK);
result = factory()->NewExpressionStatement(expr, pos);
......@@ -2376,7 +2376,24 @@ Block* Parser::ParseVariableDeclarations(
// Parse variable name.
if (nvars > 0) Consume(Token::COMMA);
name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
{
ExpressionClassifier pattern_classifier;
Token::Value next = peek();
Expression* pattern =
ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
ValidateBindingPattern(&pattern_classifier, CHECK_OK);
if (pattern->IsVariableProxy() &&
pattern->AsVariableProxy()->IsValidReferenceExpression()) {
scope_->RemoveUnresolved(pattern->AsVariableProxy());
name = pattern->AsVariableProxy()->raw_name();
} else {
ReportUnexpectedToken(next);
*ok = false;
return nullptr;
}
}
if (!first_name) first_name = name;
Scanner::Location variable_loc = scanner()->location();
if (fni_ != NULL) fni_->PushVariableName(name);
......@@ -2455,7 +2472,7 @@ Block* Parser::ParseVariableDeclarations(
ExpressionClassifier classifier;
value = ParseAssignmentExpression(var_context != kForStatement,
&classifier, CHECK_OK);
// TODO(dslomov): check that expression is valid.
ValidateExpression(&classifier, CHECK_OK);
variable_loc.end_pos = scanner()->location().end_pos;
if (first_initializer_loc && !first_initializer_loc->IsValid()) {
......@@ -2646,7 +2663,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement(
} else {
expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK);
}
// TODO(dslomov): report error if not a valid expression.
ValidateExpression(&classifier, CHECK_OK);
switch (peek()) {
case Token::SEMICOLON:
Consume(Token::SEMICOLON);
......@@ -4375,7 +4392,7 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name,
block_scope->set_start_position(scanner()->location().end_pos);
ExpressionClassifier classifier;
extends = ParseLeftHandSideExpression(&classifier, CHECK_OK);
// TODO(dslomov): report error if not a valid expression.
ValidateExpression(&classifier, CHECK_OK);
} else {
block_scope->set_start_position(scanner()->location().end_pos);
}
......@@ -4400,7 +4417,7 @@ ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name,
ObjectLiteral::Property* property = ParsePropertyDefinition(
&checker, in_class, has_extends, is_static, &is_computed_name,
&has_seen_constructor, &classifier, CHECK_OK);
// TODO(dslomov): report error if not a valid expression.
ValidateExpression(&classifier, CHECK_OK);
if (has_seen_constructor && constructor == NULL) {
constructor = GetPropertyValue(property)->AsFunctionLiteral();
......@@ -4452,7 +4469,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
ExpressionClassifier classifier;
ZoneList<Expression*>* args =
ParseArguments(&spread_pos, &classifier, CHECK_OK);
// TODO(dslomov): report error if not a valid expression.
ValidateExpression(&classifier, CHECK_OK);
DCHECK(!spread_pos.IsValid());
......
......@@ -513,7 +513,19 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
do {
// Parse variable name.
if (nvars > 0) Consume(Token::COMMA);
ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
{
ExpressionClassifier pattern_classifier;
Token::Value next = peek();
PreParserExpression pattern =
ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
ValidateBindingPattern(&pattern_classifier, CHECK_OK);
if (!pattern.IsIdentifier()) {
ReportUnexpectedToken(next);
*ok = false;
return Statement::Default();
}
}
Scanner::Location variable_loc = scanner()->location();
nvars++;
if (peek() == Token::ASSIGN || require_initializer ||
......@@ -523,7 +535,7 @@ PreParser::Statement PreParser::ParseVariableDeclarations(
ExpressionClassifier classifier;
ParseAssignmentExpression(var_context != kForStatement, &classifier,
CHECK_OK);
// TODO(dslomov): report error if not valid expression.
ValidateExpression(&classifier, CHECK_OK);
variable_loc.end_pos = scanner()->location().end_pos;
if (first_initializer_loc && !first_initializer_loc->IsValid()) {
......@@ -568,7 +580,7 @@ PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
} else {
expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK);
}
// TODO(dslomov): report error if not a valid expression.
ValidateExpression(&classifier, CHECK_OK);
switch (peek()) {
case Token::SEMICOLON:
Consume(Token::SEMICOLON);
......@@ -599,7 +611,7 @@ PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
bool starts_with_identifier = peek_any_identifier();
ExpressionClassifier classifier;
Expression expr = ParseExpression(true, &classifier, CHECK_OK);
// TODO(dslomov): report error if not a valid expression.
ValidateExpression(&classifier, CHECK_OK);
// Even if the expression starts with an identifier, it is not necessarily an
// identifier. For example, "foo + bar" starts with an identifier but is not
......@@ -1091,7 +1103,7 @@ PreParserExpression PreParser::ParseClassLiteral(
if (has_extends) {
ExpressionClassifier classifier;
ParseLeftHandSideExpression(&classifier, CHECK_OK);
// TODO(dslomov): report error if not a valid expression.
ValidateExpression(&classifier, CHECK_OK);
}
ClassLiteralChecker checker(this);
......@@ -1108,7 +1120,7 @@ PreParserExpression PreParser::ParseClassLiteral(
ParsePropertyDefinition(&checker, in_class, has_extends, is_static,
&is_computed_name, &has_seen_constructor,
&classifier, CHECK_OK);
// TODO(dslomov): report error if not a valid expression.
ValidateExpression(&classifier, CHECK_OK);
}
Expect(Token::RBRACE, CHECK_OK);
......@@ -1130,7 +1142,7 @@ PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) {
Scanner::Location spread_pos;
ExpressionClassifier classifier;
ParseArguments(&spread_pos, &classifier, ok);
// TODO(dslomov): report error if not a valid expression.
ValidateExpression(&classifier, CHECK_OK);
DCHECK(!spread_pos.IsValid());
......
This diff is collapsed.
......@@ -355,14 +355,6 @@ class Scanner {
int beg_pos;
int end_pos;
bool inline operator==(const Location& other) const {
return beg_pos == other.beg_pos && end_pos == other.end_pos;
}
bool inline operator!=(const Location& other) const {
return !(*this == other);
}
};
// -1 is outside of the range of any real source code.
......
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