Reviewers: ,

Message:
Hi, can you take a look? Some refactoring/cleanup split apart from rewriting the destructuring assignment CL. Cleans up some small inconsistencies and provides
some extra data to the preparser, which is very helpful for my destructuring
assignment rewrite.


https://codereview.chromium.org/1291343005/diff/1/src/preparser.h
File src/preparser.h (right):

https://codereview.chromium.org/1291343005/diff/1/src/preparser.h#newcode924
src/preparser.h:924: return
PreParserExpression(TypeField::encode(kStringLiteral));
the `Expression` suffix wasn't really adding anything

https://codereview.chromium.org/1291343005/diff/1/src/preparser.h#newcode938
src/preparser.h:938: return
PreParserExpression(TypeField::encode(kNumberLiteral));
Just here for consistency --- might be useful for enabling the preparser
to discern between smi-able numbers and float-only numbers, but that's
speculating.

https://codereview.chromium.org/1291343005/diff/1/src/preparser.h#newcode942
src/preparser.h:942: return
PreParserExpression(TypeField::encode(kArrayLiteral));
I have uses for this in destructuring assignment, so that I can
centralize a lot of logic that was very distributed and convoluted in
the old CL. Not positive if it will work, but I'm going to try it on top
of this CL first anyhow.

https://codereview.chromium.org/1291343005/diff/1/src/preparser.h#newcode1103
src/preparser.h:1103: typedef BitField<Type, 0, 4> TypeField;
I guess this doesn't really need the extra bit --- revert this line?

Description:
[parser] PreParserExpression cleanup

Cleanup/refactoring CL:

- Previously dead code is no longer dead
- More information exposed to preparser about different literal kinds
  (should be useful for rewriting https://crrev.com/1168643005 in a
  simpler way)

BUG=
R=
LOG=N

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

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+40, -13 lines):
  M src/preparser.h


Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 18fc2330eedd7f646683035bba73e311d6f8d12a..15bef7c23529775f529ee789d09c3be1a984e027 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -921,19 +921,31 @@ class PreParserExpression {
   }

   static PreParserExpression StringLiteral() {
- return PreParserExpression(TypeField::encode(kStringLiteralExpression));
+    return PreParserExpression(TypeField::encode(kStringLiteral));
   }

   static PreParserExpression UseStrictStringLiteral() {
- return PreParserExpression(TypeField::encode(kStringLiteralExpression) |
+    return PreParserExpression(TypeField::encode(kStringLiteral) |
                                IsUseStrictField::encode(true));
   }

   static PreParserExpression UseStrongStringLiteral() {
- return PreParserExpression(TypeField::encode(kStringLiteralExpression) |
+    return PreParserExpression(TypeField::encode(kStringLiteral) |
                                IsUseStrongField::encode(true));
   }

+  static PreParserExpression NumberLiteral() {
+    return PreParserExpression(TypeField::encode(kNumberLiteral));
+  }
+
+  static PreParserExpression ArrayLiteral() {
+    return PreParserExpression(TypeField::encode(kArrayLiteral));
+  }
+
+  static PreParserExpression ObjectLiteral() {
+    return PreParserExpression(TypeField::encode(kObjectLiteral));
+  }
+
   static PreParserExpression This() {
     return PreParserExpression(TypeField::encode(kExpression) |
ExpressionTypeField::encode(kThisExpression));
@@ -978,19 +990,31 @@ class PreParserExpression {
   }

   bool IsStringLiteral() const {
-    return TypeField::decode(code_) == kStringLiteralExpression;
+    return TypeField::decode(code_) == kStringLiteral;
   }

   bool IsUseStrictLiteral() const {
-    return TypeField::decode(code_) == kStringLiteralExpression &&
+    return TypeField::decode(code_) == kStringLiteral &&
            IsUseStrictField::decode(code_);
   }

   bool IsUseStrongLiteral() const {
-    return TypeField::decode(code_) == kStringLiteralExpression &&
+    return TypeField::decode(code_) == kStringLiteral &&
            IsUseStrongField::decode(code_);
   }

+  bool IsNumberLiteral() const {
+    return TypeField::decode(code_) == kNumberLiteral;
+  }
+
+  bool IsArrayLiteral() const {
+    return TypeField::decode(code_) == kArrayLiteral;
+  }
+
+  bool IsObjectLiteral() const {
+    return TypeField::decode(code_) == kObjectLiteral;
+  }
+
   bool IsThis() const {
     return TypeField::decode(code_) == kExpression &&
            ExpressionTypeField::decode(code_) == kThisExpression;
@@ -1055,7 +1079,10 @@ class PreParserExpression {
   enum Type {
     kExpression,
     kIdentifierExpression,
-    kStringLiteralExpression,
+    kStringLiteral,
+    kNumberLiteral,
+    kArrayLiteral,
+    kObjectLiteral,
     kBinaryOperationExpression,
     kSpreadExpression
   };
@@ -1073,7 +1100,7 @@ class PreParserExpression {
       : code_(expression_code) {}

   // The first three bits are for the Type.
-  typedef BitField<Type, 0, 3> TypeField;
+  typedef BitField<Type, 0, 4> TypeField;

   // The rest of the bits are interpreted depending on the value
   // of the Type field, so they can share the storage.
@@ -1177,11 +1204,11 @@ class PreParserFactory {
   explicit PreParserFactory(void* unused_value_factory) {}
   PreParserExpression NewStringLiteral(PreParserIdentifier identifier,
                                        int pos) {
-    return PreParserExpression::Default();
+    return PreParserExpression::StringLiteral();
   }
   PreParserExpression NewNumberLiteral(double number,
                                        int pos) {
-    return PreParserExpression::Default();
+    return PreParserExpression::NumberLiteral();
   }
   PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern,
                                        PreParserIdentifier js_flags,
@@ -1194,12 +1221,12 @@ class PreParserFactory {
                                       int literal_index,
                                       bool is_strong,
                                       int pos) {
-    return PreParserExpression::Default();
+    return PreParserExpression::ArrayLiteral();
   }
   PreParserExpression NewArrayLiteral(PreParserExpressionList values,
int first_spread_index, int literal_index,
                                       bool is_strong, int pos) {
-    return PreParserExpression::Default();
+    return PreParserExpression::ArrayLiteral();
   }
   PreParserExpression NewObjectLiteralProperty(PreParserExpression key,
                                                PreParserExpression value,
@@ -1220,7 +1247,7 @@ class PreParserFactory {
                                        bool has_function,
                                        bool is_strong,
                                        int pos) {
-    return PreParserExpression::Default();
+    return PreParserExpression::ObjectLiteral();
   }
   PreParserExpression NewVariableProxy(void* variable) {
     return PreParserExpression::Default();


--
--
v8-dev mailing list
v8-dev@googlegroups.com
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 v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to