Revision: 12153
Author:   [email protected]
Date:     Fri Jul 20 02:39:27 2012
Log:      Cleaned up AST nodes a bit.

* Made AST IDs constant. Making this explicit helps understanding the code.

* Removed a few dead functions.

* Be honest by making node_type() pure virtual.

All these changes have been checked to be performance-neutral.

Review URL: https://chromiumcodereview.appspot.com/10796058
http://code.google.com/p/v8/source/detail?r=12153

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

=======================================
--- /branches/bleeding_edge/src/ast.cc  Fri Jul 13 02:29:43 2012
+++ /branches/bleeding_edge/src/ast.cc  Fri Jul 20 02:39:27 2012
@@ -125,7 +125,7 @@
       value_(value),
       pos_(pos),
       binary_operation_(NULL),
-      compound_load_id_(kNoNumber),
+      compound_load_id_(GetNextId(isolate)),
       assignment_id_(GetNextId(isolate)),
       block_start_(false),
       block_end_(false),
=======================================
--- /branches/bleeding_edge/src/ast.h   Thu Jul 19 11:58:23 2012
+++ /branches/bleeding_edge/src/ast.h   Fri Jul 20 02:39:27 2012
@@ -211,7 +211,7 @@
   virtual ~AstNode() { }

   virtual void Accept(AstVisitor* v) = 0;
-  virtual Type node_type() const { return kInvalid; }
+  virtual Type node_type() const = 0;

   // Type testing & conversion functions overridden by concrete subclasses.
 #define DECLARE_NODE_FUNCTIONS(type)                  \
@@ -220,9 +220,6 @@
   AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
 #undef DECLARE_NODE_FUNCTIONS

-  virtual Declaration* AsDeclaration() { return NULL; }
-  virtual Statement* AsStatement() { return NULL; }
-  virtual Expression* AsExpression() { return NULL; }
   virtual TargetCollector* AsTargetCollector() { return NULL; }
   virtual BreakableStatement* AsBreakableStatement() { return NULL; }
   virtual IterationStatement* AsIterationStatement() { return NULL; }
@@ -251,8 +248,6 @@
 class Statement: public AstNode {
  public:
   Statement() : statement_pos_(RelocInfo::kNoPosition) {}
-
-  virtual Statement* AsStatement()  { return this; }

   bool IsEmpty() { return AsEmptyStatement() != NULL; }

@@ -313,8 +308,6 @@
     UNREACHABLE();
     return 0;
   }
-
-  virtual Expression* AsExpression()  { return this; }

   virtual bool IsValidLeftHandSide() { return false; }

@@ -365,8 +358,8 @@
         test_id_(GetNextId(isolate)) {}

  private:
-  int id_;
-  int test_id_;
+  const int id_;
+  const int test_id_;
 };


@@ -408,8 +401,8 @@
   ZoneStringList* labels_;
   Type type_;
   Label break_target_;
-  int entry_id_;
-  int exit_id_;
+  const int entry_id_;
+  const int exit_id_;
 };


@@ -455,8 +448,6 @@
   Scope* scope() const { return scope_; }
   virtual InitializationFlag initialization() const = 0;
   virtual bool IsInlineable() const;
-
-  virtual Declaration* AsDeclaration() { return this; }

  protected:
   Declaration(VariableProxy* proxy,
@@ -707,7 +698,7 @@
  private:
   Statement* body_;
   Label continue_target_;
-  int osr_entry_id_;
+  const int osr_entry_id_;
 };


@@ -746,8 +737,8 @@
  private:
   Expression* cond_;
   int condition_position_;
-  int continue_id_;
-  int back_edge_id_;
+  const int continue_id_;
+  const int back_edge_id_;
 };


@@ -787,7 +778,7 @@
   Expression* cond_;
   // True if there is a function literal subexpression in the condition.
   bool may_have_function_literal_;
-  int body_id_;
+  const int body_id_;
 };


@@ -846,8 +837,8 @@
   // True if there is a function literal subexpression in the condition.
   bool may_have_function_literal_;
   Variable* loop_variable_;
-  int continue_id_;
-  int body_id_;
+  const int continue_id_;
+  const int body_id_;
 };


@@ -883,8 +874,8 @@
  private:
   Expression* each_;
   Expression* enumerable_;
-  int body_id_;
-  int prepare_id_;
+  const int body_id_;
+  const int prepare_id_;
 };


@@ -1018,8 +1009,8 @@
     OBJECT_ONLY
   };
   CompareTypeFeedback compare_type_;
-  int compare_id_;
-  int entry_id_;
+  const int compare_id_;
+  const int entry_id_;
 };


@@ -1088,9 +1079,9 @@
   Expression* condition_;
   Statement* then_statement_;
   Statement* else_statement_;
-  int if_id_;
-  int then_id_;
-  int else_id_;
+  const int if_id_;
+  const int then_id_;
+  const int else_id_;
 };


@@ -1107,6 +1098,7 @@

   // Virtual behaviour. TargetCollectors are never part of the AST.
   virtual void Accept(AstVisitor* v) { UNREACHABLE(); }
+  virtual Type node_type() const { return kInvalid; }
   virtual TargetCollector* AsTargetCollector() { return this; }

   ZoneList<Label*>* targets() { return &targets_; }
@@ -1453,7 +1445,7 @@
  private:
   Handle<FixedArray> constant_elements_;
   ZoneList<Expression*>* values_;
-  int first_element_id_;
+  const int first_element_id_;
 };


@@ -1625,7 +1617,7 @@
   Handle<JSObject> holder_;
   Handle<JSGlobalPropertyCell> cell_;

-  int return_id_;
+  const int return_id_;
 };


@@ -1666,7 +1658,7 @@
   bool is_monomorphic_;
   Handle<JSFunction> target_;

-  int return_id_;
+  const int return_id_;
 };


@@ -1726,13 +1718,9 @@
         op_(op),
         expression_(expression),
         pos_(pos),
-        materialize_true_id_(AstNode::kNoNumber),
-        materialize_false_id_(AstNode::kNoNumber) {
+        materialize_true_id_(GetNextId(isolate)),
+        materialize_false_id_(GetNextId(isolate)) {
     ASSERT(Token::IsUnaryOp(op));
-    if (op == Token::NOT) {
-      materialize_true_id_ = GetNextId(isolate);
-      materialize_false_id_ = GetNextId(isolate);
-    }
   }

  private:
@@ -1742,8 +1730,8 @@

   // For unary not (Token::NOT), the AST ids where true and false will
   // actually be materialized, respectively.
-  int materialize_true_id_;
-  int materialize_false_id_;
+  const int materialize_true_id_;
+  const int materialize_false_id_;
 };


@@ -1769,11 +1757,13 @@
                   Expression* left,
                   Expression* right,
                   int pos)
- : Expression(isolate), op_(op), left_(left), right_(right), pos_(pos) {
+      : Expression(isolate),
+        op_(op),
+        left_(left),
+        right_(right),
+        pos_(pos),
+        right_id_(GetNextId(isolate)) {
     ASSERT(Token::IsBinaryOp(op));
-    right_id_ = (op == Token::AND || op == Token::OR)
-        ? GetNextId(isolate)
-        : AstNode::kNoNumber;
   }

  private:
@@ -1781,9 +1771,9 @@
   Expression* left_;
   Expression* right_;
   int pos_;
-  // The short-circuit logical operations have an AST ID for their
+  // The short-circuit logical operations need an AST ID for their
   // right-hand subexpression.
-  int right_id_;
+  const int right_id_;
 };


@@ -1834,8 +1824,8 @@
   bool is_monomorphic_;
   Expression* expression_;
   int pos_;
-  int assignment_id_;
-  int count_id_;
+  const int assignment_id_;
+  const int count_id_;
   SmallMapList receiver_types_;
 };

@@ -1925,8 +1915,8 @@
   Expression* else_expression_;
   int then_expression_position_;
   int else_expression_position_;
-  int then_id_;
-  int else_id_;
+  const int then_id_;
+  const int else_id_;
 };


@@ -1980,7 +1970,6 @@
     if (is_compound()) {
       binary_operation_ =
factory->NewBinaryOperation(binary_op(), target_, value_, pos_ + 1);
-      compound_load_id_ = GetNextId(isolate);
     }
   }

@@ -1990,8 +1979,8 @@
   Expression* value_;
   int pos_;
   BinaryOperation* binary_operation_;
-  int compound_load_id_;
-  int assignment_id_;
+  const int compound_load_id_;
+  const int assignment_id_;

   bool block_start_;
   bool block_end_;

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to