Cleanup class parsing a bit

BUG=v8:3330
LOG=Y
R=marja@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24051 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
arv@chromium.org 2014-09-18 17:39:49 +00:00
parent 04a22c14d7
commit f28f6c17c9
4 changed files with 47 additions and 40 deletions

View File

@ -2510,27 +2510,23 @@ class ClassLiteral FINAL : public Expression {
Handle<String> name() const { return raw_name_->string(); }
const AstRawString* raw_name() const { return raw_name_; }
Expression* extends() const { return extends_; }
FunctionLiteral* constructor() const { return constructor_; }
Expression* constructor() const { return constructor_; }
ZoneList<Property*>* properties() const { return properties_; }
protected:
ClassLiteral(Zone* zone, const AstRawString* name, Expression* extends,
FunctionLiteral* constructor, ZoneList<Property*>* properties,
AstValueFactory* ast_value_factory, int position, IdGen* id_gen)
Expression* constructor, ZoneList<Property*>* properties,
int position, IdGen* id_gen)
: Expression(zone, position, id_gen),
raw_name_(name),
raw_inferred_name_(ast_value_factory->empty_string()),
extends_(extends),
constructor_(constructor),
properties_(properties) {}
private:
const AstRawString* raw_name_;
Handle<String> name_;
const AstString* raw_inferred_name_;
Handle<String> inferred_name_;
Expression* extends_;
FunctionLiteral* constructor_;
Expression* constructor_;
ZoneList<Property*>* properties_;
};
@ -3504,13 +3500,11 @@ class AstNodeFactory FINAL BASE_EMBEDDED {
}
ClassLiteral* NewClassLiteral(const AstRawString* name, Expression* extends,
FunctionLiteral* constructor,
Expression* constructor,
ZoneList<ObjectLiteral::Property*>* properties,
AstValueFactory* ast_value_factory,
int position) {
ClassLiteral* lit =
new (zone_) ClassLiteral(zone_, name, extends, constructor, properties,
ast_value_factory, position, id_gen_);
ClassLiteral* lit = new (zone_) ClassLiteral(
zone_, name, extends, constructor, properties, position, id_gen_);
VISIT_AND_RETURN(ClassLiteral, lit)
}

View File

@ -664,6 +664,13 @@ Expression* ParserTraits::SuperReference(
pos);
}
Expression* ParserTraits::ClassLiteral(
const AstRawString* name, Expression* extends, Expression* constructor,
ZoneList<ObjectLiteral::Property*>* properties, int pos,
AstNodeFactory<AstConstructionVisitor>* factory) {
return factory->NewClassLiteral(name, extends, constructor, properties, pos);
}
Literal* ParserTraits::ExpressionFromLiteral(
Token::Value token, int pos,
Scanner* scanner,
@ -1962,8 +1969,8 @@ Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
bool is_strict_reserved = false;
const AstRawString* name =
ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
ClassLiteral* value = ParseClassLiteral(name, scanner()->location(),
is_strict_reserved, pos, CHECK_OK);
Expression* value = ParseClassLiteral(name, scanner()->location(),
is_strict_reserved, pos, CHECK_OK);
Block* block = factory()->NewBlock(NULL, 1, true, pos);
VariableMode mode = LET;

View File

@ -524,7 +524,6 @@ class ParserTraits {
}
static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return NULL; }
static FunctionLiteral* EmptyFunctionLiteral() { return NULL; }
static ClassLiteral* EmptyClassLiteral() { return NULL; }
// Used in error return values.
static ZoneList<Expression*>* NullExpressionList() {
@ -549,6 +548,12 @@ class ParserTraits {
Expression* SuperReference(Scope* scope,
AstNodeFactory<AstConstructionVisitor>* factory,
int pos = RelocInfo::kNoPosition);
Expression* ClassLiteral(const AstRawString* name, Expression* extends,
Expression* constructor,
ZoneList<ObjectLiteral::Property*>* properties,
int pos,
AstNodeFactory<AstConstructionVisitor>* factory);
Literal* ExpressionFromLiteral(
Token::Value token, int pos, Scanner* scanner,
AstNodeFactory<AstConstructionVisitor>* factory);

View File

@ -64,7 +64,6 @@ class ParserBase : public Traits {
typedef typename Traits::Type::Expression ExpressionT;
typedef typename Traits::Type::Identifier IdentifierT;
typedef typename Traits::Type::FunctionLiteral FunctionLiteralT;
typedef typename Traits::Type::ClassLiteral ClassLiteralT;
typedef typename Traits::Type::Literal LiteralT;
typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT;
@ -502,10 +501,10 @@ class ParserBase : public Traits {
bool* ok);
ExpressionT ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast,
bool* ok);
ClassLiteralT ParseClassLiteral(IdentifierT name,
Scanner::Location function_name_location,
bool name_is_strict_reserved, int pos,
bool* ok);
ExpressionT ParseClassLiteral(IdentifierT name,
Scanner::Location function_name_location,
bool name_is_strict_reserved, int pos,
bool* ok);
// Checks if the expression is a valid reference expression (e.g., on the
// left-hand side of assignments). Although ruled out by ECMA as early errors,
@ -1087,7 +1086,6 @@ class PreParserFactory {
PreParserExpression extends,
PreParserExpression constructor,
PreParserExpressionList properties,
AstValueFactory* ast_value_factory,
int position) {
return PreParserExpression::Default();
}
@ -1287,9 +1285,6 @@ class PreParserTraits {
static PreParserExpression EmptyFunctionLiteral() {
return PreParserExpression::Default();
}
static PreParserExpression EmptyClassLiteral() {
return PreParserExpression::Default();
}
static PreParserExpressionList NullExpressionList() {
return PreParserExpressionList();
}
@ -1318,6 +1313,15 @@ class PreParserTraits {
return PreParserExpression::Super();
}
static PreParserExpression ClassLiteral(PreParserIdentifier name,
PreParserExpression extends,
PreParserExpression constructor,
PreParserExpressionList properties,
int position,
PreParserFactory* factory) {
return PreParserExpression::Default();
}
static PreParserExpression ExpressionFromLiteral(
Token::Value token, int pos, Scanner* scanner,
PreParserFactory* factory) {
@ -2713,21 +2717,19 @@ typename ParserBase<Traits>::ExpressionT ParserBase<
template <class Traits>
typename ParserBase<Traits>::ClassLiteralT
ParserBase<Traits>::ParseClassLiteral(IdentifierT name,
Scanner::Location class_name_location,
bool name_is_strict_reserved, int pos,
bool* ok) {
typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseClassLiteral(
IdentifierT name, Scanner::Location class_name_location,
bool name_is_strict_reserved, int pos, bool* ok) {
// All parts of a ClassDeclaration or a ClassExpression are strict code.
if (name_is_strict_reserved) {
ReportMessageAt(class_name_location, "unexpected_strict_reserved");
*ok = false;
return this->EmptyClassLiteral();
return this->EmptyExpression();
}
if (this->IsEvalOrArguments(name)) {
ReportMessageAt(class_name_location, "strict_eval_arguments");
*ok = false;
return this->EmptyClassLiteral();
return this->EmptyExpression();
}
// TODO(arv): Implement scopes and name binding in class body only.
@ -2742,8 +2744,7 @@ ParserBase<Traits>::ParseClassLiteral(IdentifierT name,
ExpressionT extends = this->EmptyExpression();
if (Check(Token::EXTENDS)) {
extends =
this->ParseLeftHandSideExpression(CHECK_OK_CUSTOM(EmptyClassLiteral));
extends = this->ParseLeftHandSideExpression(CHECK_OK);
}
ObjectLiteralChecker checker(this, STRICT);
@ -2751,15 +2752,15 @@ ParserBase<Traits>::ParseClassLiteral(IdentifierT name,
this->NewPropertyList(4, zone_);
FunctionLiteralT constructor = this->EmptyFunctionLiteral();
Expect(Token::LBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral));
Expect(Token::LBRACE, CHECK_OK);
while (peek() != Token::RBRACE) {
if (Check(Token::SEMICOLON)) continue;
if (fni_ != NULL) fni_->Enter();
const bool in_class = true;
const bool is_static = false;
ObjectLiteralPropertyT property = this->ParsePropertyDefinition(
&checker, in_class, is_static, CHECK_OK_CUSTOM(EmptyClassLiteral));
ObjectLiteralPropertyT property =
this->ParsePropertyDefinition(&checker, in_class, is_static, CHECK_OK);
properties->Add(property, zone());
@ -2768,10 +2769,10 @@ ParserBase<Traits>::ParseClassLiteral(IdentifierT name,
fni_->Leave();
}
}
Expect(Token::RBRACE, CHECK_OK_CUSTOM(EmptyClassLiteral));
Expect(Token::RBRACE, CHECK_OK);
return factory()->NewClassLiteral(name, extends, constructor, properties,
this->ast_value_factory(), pos);
return this->ClassLiteral(name, extends, constructor, properties, pos,
factory());
}