Commit da33b67a authored by nikolaos's avatar nikolaos Committed by Commit bot

[parser] Refactor of ParseClass* and ParseNativeDeclaration

This patch moves the following parsing method to ParserBase:

- ParseClassDeclaration
- ParseClassLiteral
- ParseNativeDeclaration

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

Committed: https://crrev.com/7818355363b7a66ff7709e33c72bfdef5eb21450
Review-Url: https://codereview.chromium.org/2368083002
Cr-Original-Commit-Position: refs/heads/master@{#39814}
Cr-Commit-Position: refs/heads/master@{#39829}
parent 669719d5
This diff is collapsed.
This diff is collapsed.
......@@ -152,7 +152,8 @@ struct ParserTypes<Parser> {
typedef ObjectLiteral::Property* ObjectLiteralProperty;
typedef ClassLiteral::Property* ClassLiteralProperty;
typedef ZoneList<v8::internal::Expression*>* ExpressionList;
typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
typedef ZoneList<ObjectLiteral::Property*>* ObjectPropertyList;
typedef ZoneList<ClassLiteral::Property*>* ClassPropertyList;
typedef ParserFormalParameters FormalParameters;
typedef v8::internal::Statement* Statement;
typedef ZoneList<v8::internal::Statement*>* StatementList;
......@@ -269,9 +270,6 @@ class Parser : public ParserBase<Parser> {
};
ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok);
Statement* ParseFunctionDeclaration(bool* ok);
Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names,
bool default_export, bool* ok);
Statement* ParseNativeDeclaration(bool* ok);
Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result,
ZoneList<const AstRawString*>* names,
bool* ok);
......@@ -297,6 +295,21 @@ class Parser : public ParserBase<Parser> {
FunctionLiteral* function, int pos,
bool is_generator, bool is_async,
ZoneList<const AstRawString*>* names, bool* ok);
V8_INLINE Statement* DeclareClass(const AstRawString* variable_name,
Expression* value,
ZoneList<const AstRawString*>* names,
int class_token_pos, int end_pos, bool* ok);
V8_INLINE void DeclareClassVariable(const AstRawString* name,
Scope* block_scope, ClassInfo* class_info,
int class_token_pos, bool* ok);
V8_INLINE void DeclareClassProperty(const AstRawString* class_name,
ClassLiteralProperty* property,
ClassInfo* class_info, bool* ok);
V8_INLINE Expression* RewriteClassLiteral(const AstRawString* name,
ClassInfo* class_info, int pos,
bool* ok);
V8_INLINE Statement* DeclareNative(const AstRawString* name, int pos,
bool* ok);
Expression* ParseYieldStarExpression(bool* ok);
......@@ -419,11 +432,6 @@ class Parser : public ParserBase<Parser> {
FunctionLiteral* SynthesizeClassFieldInitializer(int count);
FunctionLiteral* InsertClassFieldInitializer(FunctionLiteral* constructor);
Expression* ParseClassLiteral(const AstRawString* name,
Scanner::Location class_name_location,
bool name_is_strict_reserved, int pos,
bool* ok);
// Get odd-ball literals.
Literal* GetLiteralUndefined(int position);
......@@ -739,10 +747,16 @@ class Parser : public ParserBase<Parser> {
fni_->PushEnclosingName(name);
}
V8_INLINE void InferFunctionName(FunctionLiteral* func_to_infer) {
V8_INLINE void AddFunctionForNameInference(FunctionLiteral* func_to_infer) {
DCHECK_NOT_NULL(fni_);
fni_->AddFunction(func_to_infer);
}
V8_INLINE void InferFunctionName() {
DCHECK_NOT_NULL(fni_);
fni_->Infer();
}
// If we assign a function literal to a property we pretenure the
// literal so it can be added as a constant function property.
V8_INLINE static void CheckAssigningFunctionLiteralToProperty(
......@@ -936,7 +950,7 @@ class Parser : public ParserBase<Parser> {
V8_INLINE ZoneList<Expression*>* NewExpressionList(int size) const {
return new (zone()) ZoneList<Expression*>(size, zone());
}
V8_INLINE ZoneList<ObjectLiteral::Property*>* NewPropertyList(
V8_INLINE ZoneList<ObjectLiteral::Property*>* NewObjectPropertyList(
int size) const {
return new (zone()) ZoneList<ObjectLiteral::Property*>(size, zone());
}
......
......@@ -135,18 +135,6 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
// That means that contextual checks (like a label being declared where
// it is used) are generally omitted.
PreParser::Statement PreParser::ParseClassDeclaration(
ZoneList<const AstRawString*>* names, bool default_export, bool* ok) {
int pos = position();
bool is_strict_reserved = false;
Identifier name =
ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
ExpressionClassifier no_classifier(this);
ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos,
CHECK_OK);
return Statement::Default();
}
PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
Consume(Token::FUNCTION);
int pos = position();
......@@ -251,57 +239,6 @@ PreParser::LazyParsingResult PreParser::ParseLazyFunctionLiteralBody(
return kLazyParsingComplete;
}
PreParserExpression PreParser::ParseClassLiteral(
PreParserIdentifier name, Scanner::Location class_name_location,
bool name_is_strict_reserved, int pos, bool* ok) {
// All parts of a ClassDeclaration and ClassExpression are strict code.
if (name_is_strict_reserved) {
ReportMessageAt(class_name_location,
MessageTemplate::kUnexpectedStrictReserved);
*ok = false;
return EmptyExpression();
}
if (IsEvalOrArguments(name)) {
ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments);
*ok = false;
return EmptyExpression();
}
LanguageMode class_language_mode = language_mode();
BlockState block_state(zone(), &scope_state_);
scope()->SetLanguageMode(
static_cast<LanguageMode>(class_language_mode | STRICT));
// TODO(marja): Make PreParser use scope names too.
// this->scope()->SetScopeName(name);
bool has_extends = Check(Token::EXTENDS);
if (has_extends) {
ExpressionClassifier extends_classifier(this);
ParseLeftHandSideExpression(CHECK_OK);
ValidateExpression(CHECK_OK);
impl()->AccumulateFormalParameterContainmentErrors();
}
ClassLiteralChecker checker(this);
bool has_seen_constructor = false;
Expect(Token::LBRACE, CHECK_OK);
while (peek() != Token::RBRACE) {
if (Check(Token::SEMICOLON)) continue;
bool is_computed_name = false; // Classes do not care about computed
// property names here.
ExpressionClassifier property_classifier(this);
ParseClassPropertyDefinition(&checker, has_extends, &is_computed_name,
&has_seen_constructor, CHECK_OK);
ValidateExpression(CHECK_OK);
impl()->AccumulateFormalParameterContainmentErrors();
}
Expect(Token::RBRACE, CHECK_OK);
return Expression::Default();
}
PreParserExpression PreParser::ExpressionFromIdentifier(
PreParserIdentifier name, int start_position, int end_position,
InferName infer) {
......
......@@ -728,7 +728,8 @@ struct ParserTypes<PreParser> {
typedef PreParserExpression ObjectLiteralProperty;
typedef PreParserExpression ClassLiteralProperty;
typedef PreParserExpressionList ExpressionList;
typedef PreParserExpressionList PropertyList;
typedef PreParserExpressionList ObjectPropertyList;
typedef PreParserExpressionList ClassPropertyList;
typedef PreParserFormalParameters FormalParameters;
typedef PreParserStatement Statement;
typedef PreParserStatementList StatementList;
......@@ -837,8 +838,6 @@ class PreParser : public ParserBase<PreParser> {
// By making the 'exception handling' explicit, we are forced to check
// for failure at the call sites.
Statement ParseFunctionDeclaration(bool* ok);
Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names,
bool default_export, bool* ok);
Expression ParseConditionalExpression(bool accept_IN, bool* ok);
Expression ParseObjectLiteral(bool* ok);
......@@ -860,11 +859,6 @@ class PreParser : public ParserBase<PreParser> {
LanguageMode language_mode, bool* ok);
LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok);
PreParserExpression ParseClassLiteral(PreParserIdentifier name,
Scanner::Location class_name_location,
bool name_is_strict_reserved, int pos,
bool* ok);
struct TemplateLiteralState {};
V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos) {
......@@ -946,11 +940,6 @@ class PreParser : public ParserBase<PreParser> {
return labels;
}
V8_INLINE PreParserStatement ParseNativeDeclaration(bool* ok) {
UNREACHABLE();
return PreParserStatement::Default();
}
// TODO(nikolaos): The preparser currently does not keep track of labels.
V8_INLINE bool ContainsLabel(ZoneList<const AstRawString*>* labels,
PreParserIdentifier label) {
......@@ -997,6 +986,29 @@ class PreParser : public ParserBase<PreParser> {
return Statement::Default();
}
V8_INLINE PreParserStatement
DeclareClass(PreParserIdentifier variable_name, PreParserExpression value,
ZoneList<const AstRawString*>* names, int class_token_pos,
int end_pos, bool* ok) {
return PreParserStatement::Default();
}
V8_INLINE void DeclareClassVariable(PreParserIdentifier name,
Scope* block_scope, ClassInfo* class_info,
int class_token_pos, bool* ok) {}
V8_INLINE void DeclareClassProperty(PreParserIdentifier class_name,
PreParserExpression property,
ClassInfo* class_info, bool* ok) {}
V8_INLINE PreParserExpression RewriteClassLiteral(PreParserIdentifier name,
ClassInfo* class_info,
int pos, bool* ok) {
return PreParserExpression::Default();
}
V8_INLINE PreParserStatement DeclareNative(PreParserIdentifier name, int pos,
bool* ok) {
return PreParserStatement::Default();
}
V8_INLINE void QueueDestructuringAssignmentForRewriting(
PreParserExpression assignment) {}
V8_INLINE void QueueNonPatternForRewriting(PreParserExpression expr,
......@@ -1103,7 +1115,9 @@ class PreParser : public ParserBase<PreParser> {
V8_INLINE static void PushVariableName(PreParserIdentifier id) {}
V8_INLINE void PushPropertyName(PreParserExpression expression) {}
V8_INLINE void PushEnclosingName(PreParserIdentifier name) {}
V8_INLINE static void InferFunctionName(PreParserExpression expression) {}
V8_INLINE static void AddFunctionForNameInference(
PreParserExpression expression) {}
V8_INLINE static void InferFunctionName() {}
V8_INLINE static void CheckAssigningFunctionLiteralToProperty(
PreParserExpression left, PreParserExpression right) {}
......@@ -1318,7 +1332,11 @@ class PreParser : public ParserBase<PreParser> {
return PreParserExpressionList();
}
V8_INLINE PreParserExpressionList NewPropertyList(int size) const {
V8_INLINE PreParserExpressionList NewObjectPropertyList(int size) const {
return PreParserExpressionList();
}
V8_INLINE PreParserExpressionList NewClassPropertyList(int size) const {
return PreParserExpressionList();
}
......
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