Revision: 24051
Author:   [email protected]
Date:     Thu Sep 18 17:39:49 2014 UTC
Log:      Cleanup class parsing a bit

BUG=v8:3330
LOG=Y
[email protected]

Review URL: https://codereview.chromium.org/575083002
https://code.google.com/p/v8/source/detail?r=24051

Modified:
 /branches/bleeding_edge/src/ast.h
 /branches/bleeding_edge/src/parser.cc
 /branches/bleeding_edge/src/parser.h
 /branches/bleeding_edge/src/preparser.h

=======================================
--- /branches/bleeding_edge/src/ast.h   Tue Sep 16 22:15:39 2014 UTC
+++ /branches/bleeding_edge/src/ast.h   Thu Sep 18 17:39:49 2014 UTC
@@ -2510,27 +2510,23 @@
   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 @@
   }

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)
   }

=======================================
--- /branches/bleeding_edge/src/parser.cc       Tue Sep 16 22:15:39 2014 UTC
+++ /branches/bleeding_edge/src/parser.cc       Thu Sep 18 17:39:49 2014 UTC
@@ -663,6 +663,13 @@
       ThisExpression(scope, factory, pos)->AsVariableProxy(),
       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,
@@ -1962,8 +1969,8 @@
   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;
=======================================
--- /branches/bleeding_edge/src/parser.h        Wed Sep 17 12:34:46 2014 UTC
+++ /branches/bleeding_edge/src/parser.h        Thu Sep 18 17:39:49 2014 UTC
@@ -524,7 +524,6 @@
   }
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 @@
   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);
=======================================
--- /branches/bleeding_edge/src/preparser.h     Thu Sep 18 17:14:13 2014 UTC
+++ /branches/bleeding_edge/src/preparser.h     Thu Sep 18 17:39:49 2014 UTC
@@ -64,7 +64,6 @@
   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 @@
                                                 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 @@
                                       PreParserExpression extends,
                                       PreParserExpression constructor,
                                       PreParserExpressionList properties,
-                                      AstValueFactory* ast_value_factory,
                                       int position) {
     return PreParserExpression::Default();
   }
@@ -1287,9 +1285,6 @@
   static PreParserExpression EmptyFunctionLiteral() {
     return PreParserExpression::Default();
   }
-  static PreParserExpression EmptyClassLiteral() {
-    return PreParserExpression::Default();
-  }
   static PreParserExpressionList NullExpressionList() {
     return PreParserExpressionList();
   }
@@ -1317,6 +1312,15 @@
                                             PreParserFactory* factory) {
     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,
@@ -2713,21 +2717,19 @@


 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 @@

   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 @@
       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 @@
       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