Reviewers: marja,

https://codereview.chromium.org/575083002/diff/1/src/ast.h
File src/ast.h (left):

https://codereview.chromium.org/575083002/diff/1/src/ast.h#oldcode2529
src/ast.h:2529: Handle<String> name_;
These are not used. We can add them back if we ever need them.

Description:
Cleanup class parsing a bit

BUG=v8:3330
LOG=Y

Please review this at https://codereview.chromium.org/575083002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+47, -40 lines):
  M src/ast.h
  M src/parser.h
  M src/parser.cc
  M src/preparser.h


Index: src/ast.h
diff --git a/src/ast.h b/src/ast.h
index 394e7f974a0742c2ea81e71377b693e38da2463f..03f1adf5ae086f6e4e73ddc09ca2cbe904b36b5c 100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -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)
   }

Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 2e552e10f3b1256ab9b8bf6b0c87bd070900515e..9d10d308b24252a419b2362d944142bad3b81f7d 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -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;
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index d73075a42ad6b7cd15a6083f7139783c353893f4..40886f669d828eca47abfa81a808bd310cec3c63 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -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);
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 0147caf5d134e312bc5fd49754d7c57c8d19f866..a6aab5a28095728cf439dafe31632671ae60a4d8 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -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) {
@@ -2703,21 +2707,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.
@@ -2732,8 +2734,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);
@@ -2741,15 +2742,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());

@@ -2758,10 +2759,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());
 }




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to