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

Unified Diff: src/parsing/parser.cc

Issue 2289663002: [parser] Hide expression classifiers in parser implementation (Closed)
Patch Set: Created 4 years, 4 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
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index 1d26e77039d855a2be83214a2a186e200c498e5e..7fc6cebe198e67c363e2c30351995e5b15780d5f 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -881,7 +881,7 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
SetLanguageMode(scope, info->language_mode());
scope->set_start_position(info->start_position());
- ExpressionClassifier formals_classifier(this);
+ ExpressionClassifierWrapper wrap_formals_classifier(this);
ParserFormalParameters formals(scope);
Checkpoint checkpoint(this);
{
@@ -891,15 +891,12 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
BlockState block_state(&scope_state_, scope);
if (Check(Token::LPAREN)) {
// '(' StrictFormalParameters ')'
- ParseFormalParameterList(&formals, &formals_classifier, &ok);
+ ParseFormalParameterList(&formals, &ok);
if (ok) ok = Check(Token::RPAREN);
} else {
// BindingIdentifier
- ParseFormalParameter(&formals, &formals_classifier, &ok);
- if (ok) {
- DeclareFormalParameter(formals.scope, formals.at(0),
- &formals_classifier);
- }
+ ParseFormalParameter(&formals, &ok);
+ if (ok) DeclareFormalParameter(formals.scope, formals.at(0));
}
}
@@ -907,8 +904,8 @@ FunctionLiteral* Parser::DoParseLazy(ParseInfo* info,
checkpoint.Restore(&formals.materialized_literals_count);
// Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should
// not be observable, or else the preparser would have failed.
- Expression* expression = ParseArrowFunctionLiteral(
- true, formals, is_async, formals_classifier, &ok);
+ Expression* expression =
+ ParseArrowFunctionLiteral(true, formals, is_async, &ok);
if (ok) {
// Scanning must end at the same position that was recorded
// previously. If not, parsing has been interrupted due to a stack
@@ -1354,10 +1351,9 @@ Statement* Parser::ParseExportDefault(bool* ok) {
default: {
int pos = position();
- ExpressionClassifier classifier(this);
- Expression* value =
- ParseAssignmentExpression(true, &classifier, CHECK_OK);
- RewriteNonPattern(&classifier, CHECK_OK);
+ ExpressionClassifierWrapper wrap_classifier(this);
+ Expression* value = ParseAssignmentExpression(true, CHECK_OK);
+ RewriteNonPattern(CHECK_OK);
SetFunctionName(value, ast_value_factory()->default_string());
const AstRawString* local_name =
@@ -1947,7 +1943,8 @@ Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
variable_name = name;
}
- Expression* value = ParseClassLiteral(nullptr, name, scanner()->location(),
+ ExpressionClassifierWrapper wrap_no_classifier(this, nullptr, false);
+ Expression* value = ParseClassLiteral(name, scanner()->location(),
is_strict_reserved, pos, CHECK_OK);
Declaration* decl = DeclareVariable(variable_name, LET, pos, CHECK_OK);
@@ -2087,11 +2084,11 @@ Block* Parser::ParseVariableDeclarations(
Expression* pattern;
int decl_pos = peek_position();
{
- ExpressionClassifier pattern_classifier(this);
- pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
- ValidateBindingPattern(&pattern_classifier, CHECK_OK);
+ ExpressionClassifierWrapper wrap_pattern_classifier(this);
+ pattern = ParsePrimaryExpression(CHECK_OK);
+ ValidateBindingPattern(CHECK_OK);
if (IsLexicalVariableMode(parsing_result->descriptor.mode)) {
- ValidateLetPattern(&pattern_classifier, CHECK_OK);
+ ValidateLetPattern(CHECK_OK);
}
}
@@ -2106,10 +2103,9 @@ Block* Parser::ParseVariableDeclarations(
Expression* value = NULL;
int initializer_position = kNoSourcePosition;
if (Check(Token::ASSIGN)) {
- ExpressionClassifier classifier(this);
- value = ParseAssignmentExpression(var_context != kForStatement,
- &classifier, CHECK_OK);
- RewriteNonPattern(&classifier, CHECK_OK);
+ ExpressionClassifierWrapper wrap_classifier(this);
+ value = ParseAssignmentExpression(var_context != kForStatement, CHECK_OK);
+ RewriteNonPattern(CHECK_OK);
variable_loc.end_pos = scanner()->location().end_pos;
if (!parsing_result->first_initializer_loc.IsValid()) {
@@ -2702,9 +2698,9 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
if (peek_any_identifier()) {
name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK);
} else {
- ExpressionClassifier pattern_classifier(this);
- pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
- ValidateBindingPattern(&pattern_classifier, CHECK_OK);
+ ExpressionClassifierWrapper wrap_pattern_classifier(this);
+ pattern = ParsePrimaryExpression(CHECK_OK);
+ ValidateBindingPattern(CHECK_OK);
}
catch_variable = catch_scope->DeclareLocal(
name, VAR, kCreatedInitialized, Variable::NORMAL);
@@ -3426,9 +3422,9 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
Expression* enumerable;
if (mode == ForEachStatement::ITERATE) {
- ExpressionClassifier classifier(this);
- enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK);
- RewriteNonPattern(&classifier, CHECK_OK);
+ ExpressionClassifierWrapper wrap_classifier(this);
+ enumerable = ParseAssignmentExpression(true, CHECK_OK);
+ RewriteNonPattern(CHECK_OK);
} else {
enumerable = ParseExpression(true, CHECK_OK);
}
@@ -3541,8 +3537,8 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
}
} else {
int lhs_beg_pos = peek_position();
- ExpressionClassifier classifier(this);
- Expression* expression = ParseExpression(false, &classifier, CHECK_OK);
+ ExpressionClassifierWrapper wrap_classifier(this);
+ Expression* expression = ParseExpressionNoWrap(false, CHECK_OK);
int lhs_end_pos = scanner()->location().end_pos;
ForEachStatement::VisitMode mode = ForEachStatement::ENUMERATE;
@@ -3551,9 +3547,9 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
expression->IsObjectLiteral());
if (is_destructuring) {
- ValidateAssignmentPattern(&classifier, CHECK_OK);
+ ValidateAssignmentPattern(CHECK_OK);
} else {
- RewriteNonPattern(&classifier, CHECK_OK);
+ RewriteNonPattern(CHECK_OK);
}
if (is_for_each) {
@@ -3571,9 +3567,9 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
Expression* enumerable;
if (mode == ForEachStatement::ITERATE) {
- ExpressionClassifier classifier(this);
- enumerable = ParseAssignmentExpression(true, &classifier, CHECK_OK);
- RewriteNonPattern(&classifier, CHECK_OK);
+ ExpressionClassifierWrapper wrap_classifier(this);
+ enumerable = ParseAssignmentExpression(true, CHECK_OK);
+ RewriteNonPattern(CHECK_OK);
} else {
enumerable = ParseExpression(true, CHECK_OK);
}
@@ -3787,7 +3783,6 @@ void Parser::ParseArrowFunctionFormalParameters(
void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name,
Scope* scope, ZoneList<Statement*>* body,
- ExpressionClassifier* classifier,
FunctionKind kind,
FunctionBodyType body_type,
bool accept_IN, int pos, bool* ok) {
@@ -3817,9 +3812,8 @@ void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name,
ParseStatementList(block->statements(), Token::RBRACE, CHECK_OK_VOID);
return_value = factory()->NewUndefinedLiteral(kNoSourcePosition);
} else {
- return_value =
- ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_VOID);
- RewriteNonPattern(classifier, CHECK_OK_VOID);
+ return_value = ParseAssignmentExpression(accept_IN, CHECK_OK_VOID);
+ RewriteNonPattern(CHECK_OK_VOID);
}
return_value = BuildResolvePromise(return_value, return_value->position());
@@ -3864,15 +3858,16 @@ void Parser::ParseArrowFunctionFormalParameterList(
return;
}
- ExpressionClassifier classifier(this);
+ ExpressionClassifierWrapper wrap_classifier(this);
if (!parameters->is_simple) {
- classifier.RecordNonSimpleParameter();
+ classifier()->RecordNonSimpleParameter();
}
for (int i = 0; i < parameters->Arity(); ++i) {
auto parameter = parameters->at(i);
- DeclareFormalParameter(parameters->scope, parameter, &classifier);
+ DeclareFormalParameter(parameters->scope, parameter);
if (!duplicate_loc->IsValid()) {
- *duplicate_loc = classifier.duplicate_formal_parameter_error().location;
+ *duplicate_loc =
+ classifier()->duplicate_formal_parameter_error().location;
}
}
DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters());
@@ -4026,7 +4021,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
#ifdef DEBUG
scope->SetScopeName(function_name);
#endif
- ExpressionClassifier formals_classifier(this, &duplicate_finder);
+ ExpressionClassifierWrapper wrap_formals_classifier(this,
+ &duplicate_finder);
if (is_generator) {
// For generators, allocating variables in contexts is currently a win
@@ -4047,7 +4043,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
int start_position = scanner()->location().beg_pos;
this->scope()->set_start_position(start_position);
ParserFormalParameters formals(scope);
- ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
+ ParseFormalParameterList(&formals, CHECK_OK);
arity = formals.Arity();
Expect(Token::RPAREN, CHECK_OK);
int formals_end_position = scanner()->location().end_pos;
@@ -4109,8 +4105,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
function_name_location, CHECK_OK);
const bool allow_duplicate_parameters =
is_sloppy(language_mode) && formals.is_simple && !IsConciseMethod(kind);
- ValidateFormalParameters(&formals_classifier, language_mode,
- allow_duplicate_parameters, CHECK_OK);
+ ValidateFormalParameters(language_mode, allow_duplicate_parameters,
+ CHECK_OK);
if (is_strict(language_mode)) {
CheckStrictOctalLiteral(scope->start_position(), scope->end_position(),
@@ -4125,7 +4121,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
RewriteDestructuringAssignments();
}
has_duplicate_parameters =
- !formals_classifier.is_valid_formal_parameter_list_without_duplicates();
+ !classifier()->is_valid_formal_parameter_list_without_duplicates();
if (use_temp_zone) {
DCHECK(main_scope != scope);
@@ -4626,7 +4622,7 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
zone());
} else if (IsAsyncFunction(kind)) {
const bool accept_IN = true;
- DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind,
+ DesugarAsyncFunctionBody(function_name, inner_scope, body, kind,
FunctionBodyType::kNormal, accept_IN, pos,
CHECK_OK);
} else {
@@ -4733,8 +4729,7 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
return result;
}
-Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
- const AstRawString* name,
+Expression* Parser::ParseClassLiteral(const AstRawString* name,
Scanner::Location class_name_location,
bool name_is_strict_reserved, int pos,
bool* ok) {
@@ -4770,14 +4765,11 @@ Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
Expression* extends = nullptr;
if (Check(Token::EXTENDS)) {
block_state.set_start_position(scanner()->location().end_pos);
- ExpressionClassifier extends_classifier(this);
- extends = ParseLeftHandSideExpression(&extends_classifier, CHECK_OK);
- CheckNoTailCallExpressions(&extends_classifier, CHECK_OK);
- RewriteNonPattern(&extends_classifier, CHECK_OK);
- if (classifier != nullptr) {
- classifier->AccumulateFormalParameterContainmentErrors(
- &extends_classifier);
- }
+ ExpressionClassifierWrapper wrap_extends_classifier(this);
+ extends = ParseLeftHandSideExpression(CHECK_OK);
+ CheckNoTailCallExpressions(CHECK_OK);
+ RewriteNonPattern(CHECK_OK);
+ impl()->AccumulateFormalParameterContainmentErrors();
} else {
block_state.set_start_position(scanner()->location().end_pos);
}
@@ -4797,16 +4789,13 @@ Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
const bool in_class = true;
bool is_computed_name = false; // Classes do not care about computed
// property names here.
- ExpressionClassifier property_classifier(this);
+ ExpressionClassifierWrapper wrap_property_classifier(this);
const AstRawString* property_name = nullptr;
ObjectLiteral::Property* property = ParsePropertyDefinition(
&checker, in_class, has_extends, MethodKind::kNormal, &is_computed_name,
- &has_seen_constructor, &property_classifier, &property_name, CHECK_OK);
- RewriteNonPattern(&property_classifier, CHECK_OK);
- if (classifier != nullptr) {
- classifier->AccumulateFormalParameterContainmentErrors(
- &property_classifier);
- }
+ &has_seen_constructor, &property_name, CHECK_OK);
+ RewriteNonPattern(CHECK_OK);
+ impl()->AccumulateFormalParameterContainmentErrors();
if (has_seen_constructor && constructor == nullptr) {
constructor = GetPropertyValue(property)->AsFunctionLiteral();
@@ -4868,9 +4857,8 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
const AstRawString* name = ParseIdentifier(kAllowRestrictedIdentifiers,
CHECK_OK);
Scanner::Location spread_pos;
- ExpressionClassifier classifier(this);
- ZoneList<Expression*>* args =
- ParseArguments(&spread_pos, &classifier, CHECK_OK);
+ ExpressionClassifierWrapper wrap_classifier(this);
+ ZoneList<Expression*>* args = ParseArguments(&spread_pos, CHECK_OK);
DCHECK(!spread_pos.IsValid());
@@ -5589,11 +5577,10 @@ class NonPatternRewriter : public AstExpressionRewriter {
Parser* parser_;
};
-
-void Parser::RewriteNonPattern(ExpressionClassifier* classifier, bool* ok) {
- ValidateExpression(classifier, CHECK_OK_VOID);
+void Parser::RewriteNonPattern(bool* ok) {
+ ValidateExpression(CHECK_OK_VOID);
auto non_patterns_to_rewrite = function_state_->non_patterns_to_rewrite();
- int begin = classifier->GetNonPatternBegin();
+ int begin = classifier()->GetNonPatternBegin();
int end = non_patterns_to_rewrite->length();
if (begin < end) {
NonPatternRewriter rewriter(stack_limit_, this);
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | src/parsing/parser-base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698