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