Revision: 5332
Author: [email protected]
Date: Tue Aug 24 06:51:23 2010
Log: Add position information for compares, binary ops, and count
operations.
Review URL: http://codereview.chromium.org/3120027
http://code.google.com/p/v8/source/detail?r=5332

Modified:
 /branches/bleeding_edge/src/arm/full-codegen-arm.cc
 /branches/bleeding_edge/src/ast.cc
 /branches/bleeding_edge/src/ast.h
 /branches/bleeding_edge/src/full-codegen.cc
 /branches/bleeding_edge/src/ia32/codegen-ia32.cc
 /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
 /branches/bleeding_edge/src/parser.cc
 /branches/bleeding_edge/src/x64/codegen-x64.cc
 /branches/bleeding_edge/src/x64/full-codegen-x64.cc

=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Tue Aug 24 04:41:26 2010 +++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Tue Aug 24 06:51:23 2010
@@ -2702,6 +2702,8 @@

 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
   Comment cmnt(masm_, "[ CountOperation");
+  SetSourcePosition(expr->position());
+
   // Invalid left-hand sides are rewritten to have a 'throw ReferenceError'
   // as the left-hand side.
   if (!expr->expression()->IsValidLeftHandSide()) {
@@ -2972,6 +2974,7 @@

 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
   Comment cmnt(masm_, "[ CompareOperation");
+  SetSourcePosition(expr->position());

   // Always perform the comparison for its control flow.  Pack the result
   // into the expression's context after the comparison is performed.
=======================================
--- /branches/bleeding_edge/src/ast.cc  Tue Aug 24 00:26:49 2010
+++ /branches/bleeding_edge/src/ast.cc  Tue Aug 24 06:51:23 2010
@@ -237,6 +237,16 @@
   bitfields_ = other->bitfields_;
   type_ = other->type_;
 }
+
+
+BinaryOperation::BinaryOperation(Assignment* assignment) {
+  ASSERT(assignment->is_compound());
+  op_ = assignment->binary_op();
+  left_ = assignment->target();
+  right_ = assignment->value();
+  pos_ = assignment->position();
+  CopyAnalysisResultsFrom(assignment);
+}


// ----------------------------------------------------------------------------
=======================================
--- /branches/bleeding_edge/src/ast.h   Tue Aug 24 05:56:45 2010
+++ /branches/bleeding_edge/src/ast.h   Tue Aug 24 06:51:23 2010
@@ -1202,10 +1202,16 @@

 class BinaryOperation: public Expression {
  public:
-  BinaryOperation(Token::Value op, Expression* left, Expression* right)
-      : op_(op), left_(left), right_(right) {
+  BinaryOperation(Token::Value op,
+                  Expression* left,
+                  Expression* right,
+                  int pos)
+      : op_(op), left_(left), right_(right), pos_(pos) {
     ASSERT(Token::IsBinaryOp(op));
   }
+
+  // Create the binary operation corresponding to a compound assignment.
+  explicit BinaryOperation(Assignment* assignment);

   virtual void Accept(AstVisitor* v);

@@ -1241,11 +1247,13 @@
   Token::Value op() const { return op_; }
   Expression* left() const { return left_; }
   Expression* right() const { return right_; }
+  int position() const { return pos_; }

  private:
   Token::Value op_;
   Expression* left_;
   Expression* right_;
+  int pos_;
 };


@@ -1265,13 +1273,14 @@
  private:
   Token::Value op_;
   Expression* expression_;
+  int pos_;
 };


 class CountOperation: public Expression {
  public:
-  CountOperation(bool is_prefix, IncrementOperation* increment)
-      : is_prefix_(is_prefix), increment_(increment) { }
+  CountOperation(bool is_prefix, IncrementOperation* increment, int pos)
+      : is_prefix_(is_prefix), increment_(increment), pos_(pos) { }

   virtual void Accept(AstVisitor* v);

@@ -1287,19 +1296,24 @@

   Expression* expression() const { return increment_->expression(); }
   IncrementOperation* increment() const { return increment_; }
+  int position() const { return pos_; }

   virtual void MarkAsStatement() { is_prefix_ = true; }

  private:
   bool is_prefix_;
   IncrementOperation* increment_;
+  int pos_;
 };


 class CompareOperation: public Expression {
  public:
-  CompareOperation(Token::Value op, Expression* left, Expression* right)
-      : op_(op), left_(left), right_(right) {
+  CompareOperation(Token::Value op,
+                   Expression* left,
+                   Expression* right,
+                   int pos)
+      : op_(op), left_(left), right_(right), pos_(pos) {
     ASSERT(Token::IsCompareOp(op));
   }

@@ -1308,6 +1322,7 @@
   Token::Value op() const { return op_; }
   Expression* left() const { return left_; }
   Expression* right() const { return right_; }
+  int position() const { return pos_; }

   // Type testing & conversion
   virtual CompareOperation* AsCompareOperation() { return this; }
@@ -1316,6 +1331,7 @@
   Token::Value op_;
   Expression* left_;
   Expression* right_;
+  int pos_;
 };


=======================================
--- /branches/bleeding_edge/src/full-codegen.cc Tue Aug 24 05:56:45 2010
+++ /branches/bleeding_edge/src/full-codegen.cc Tue Aug 24 06:51:23 2010
@@ -500,6 +500,7 @@
     case Token::SAR:
       VisitForValue(expr->left(), kStack);
       VisitForValue(expr->right(), kAccumulator);
+      SetSourcePosition(expr->position());
       EmitBinaryOp(expr->op(), context_);
       break;

=======================================
--- /branches/bleeding_edge/src/ia32/codegen-ia32.cc Tue Aug 24 00:26:49 2010 +++ /branches/bleeding_edge/src/ia32/codegen-ia32.cc Tue Aug 24 06:51:23 2010
@@ -5786,8 +5786,7 @@
         (node->value()->AsBinaryOperation() != NULL &&
          node->value()->AsBinaryOperation()->ResultOverwriteAllowed());
     // Construct the implicit binary operation.
-    BinaryOperation expr(node->binary_op(), node->target(), node->value());
-    expr.CopyAnalysisResultsFrom(node);
+    BinaryOperation expr(node);
     GenericBinaryOperation(&expr,
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE);
   } else {
@@ -5878,8 +5877,7 @@
         (node->value()->AsBinaryOperation() != NULL &&
          node->value()->AsBinaryOperation()->ResultOverwriteAllowed());
     // Construct the implicit binary operation.
-    BinaryOperation expr(node->binary_op(), node->target(), node->value());
-    expr.CopyAnalysisResultsFrom(node);
+    BinaryOperation expr(node);
     GenericBinaryOperation(&expr,
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE);
   } else {
@@ -5980,8 +5978,7 @@
     bool overwrite_value =
         (node->value()->AsBinaryOperation() != NULL &&
          node->value()->AsBinaryOperation()->ResultOverwriteAllowed());
-    BinaryOperation expr(node->binary_op(), node->target(), node->value());
-    expr.CopyAnalysisResultsFrom(node);
+    BinaryOperation expr(node);
     GenericBinaryOperation(&expr,
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE);
   } else {
=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Tue Aug 24 04:41:26 2010 +++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Tue Aug 24 06:51:23 2010
@@ -2701,6 +2701,8 @@

 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
   Comment cmnt(masm_, "[ CountOperation");
+  SetSourcePosition(expr->position());
+
   // Invalid left-hand sides are rewritten to have a 'throw ReferenceError'
   // as the left-hand side.
   if (!expr->expression()->IsValidLeftHandSide()) {
@@ -2981,6 +2983,7 @@

 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
   Comment cmnt(masm_, "[ CompareOperation");
+  SetSourcePosition(expr->position());

   // Always perform the comparison for its control flow.  Pack the result
   // into the expression's context after the comparison is performed.
=======================================
--- /branches/bleeding_edge/src/parser.cc       Tue Aug 24 05:56:45 2010
+++ /branches/bleeding_edge/src/parser.cc       Tue Aug 24 06:51:23 2010
@@ -214,7 +214,10 @@
ObjectLiteral::Property* ParseObjectLiteralGetSet(bool is_getter, bool* ok);
   Expression* ParseRegExpLiteral(bool seen_equal, bool* ok);

- Expression* NewCompareNode(Token::Value op, Expression* x, Expression* y);
+  Expression* NewCompareNode(Token::Value op,
+                             Expression* x,
+                             Expression* y,
+                             int position);

   // Populate the constant properties fixed array for a materialized object
   // literal.
@@ -2817,8 +2820,9 @@
   Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK);
   while (peek() == Token::COMMA) {
     Expect(Token::COMMA, CHECK_OK);
+    int position = scanner().location().beg_pos;
     Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
-    result = NEW(BinaryOperation(Token::COMMA, result, right));
+    result = NEW(BinaryOperation(Token::COMMA, result, right, position));
   }
   return result;
 }
@@ -2921,6 +2925,7 @@
     // prec1 >= 4
     while (Precedence(peek(), accept_IN) == prec1) {
       Token::Value op = Next();
+      int position = scanner().location().beg_pos;
Expression* y = ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK);

       // Compute some expressions involving only number literals.
@@ -3004,7 +3009,7 @@
           case Token::NE_STRICT: cmp = Token::EQ_STRICT; break;
           default: break;
         }
-        x = NewCompareNode(cmp, x, y);
+        x = NewCompareNode(cmp, x, y, position);
         if (cmp != op) {
           // The comparison was negated - add a NOT.
           x = NEW(UnaryOperation(Token::NOT, x));
@@ -3012,7 +3017,7 @@

       } else {
         // We have a "normal" binary operation.
-        x = NEW(BinaryOperation(op, x, y));
+        x = NEW(BinaryOperation(op, x, y, position));
       }
     }
   }
@@ -3022,7 +3027,8 @@

 Expression* Parser::NewCompareNode(Token::Value op,
                                    Expression* x,
-                                   Expression* y) {
+                                   Expression* y,
+                                   int position) {
   ASSERT(op != Token::NE && op != Token::NE_STRICT);
   if (!is_pre_parsing_ && (op == Token::EQ || op == Token::EQ_STRICT)) {
     bool is_strict = (op == Token::EQ_STRICT);
@@ -3036,7 +3042,7 @@
       return NEW(CompareToNull(is_strict, x));
     }
   }
-  return NEW(CompareOperation(op, x, y));
+  return NEW(CompareOperation(op, x, y, position));
 }


@@ -3086,8 +3092,9 @@
       Handle<String> type = Factory::invalid_lhs_in_prefix_op_symbol();
       expression = NewThrowReferenceError(type);
     }
+    int position = scanner().location().beg_pos;
IncrementOperation* increment = NEW(IncrementOperation(op, expression));
-    return NEW(CountOperation(true /* prefix */, increment));
+    return NEW(CountOperation(true /* prefix */, increment, position));

   } else {
     return ParsePostfixExpression(ok);
@@ -3110,8 +3117,9 @@
       expression = NewThrowReferenceError(type);
     }
     Token::Value next = Next();
+    int position = scanner().location().beg_pos;
IncrementOperation* increment = NEW(IncrementOperation(next, expression));
-    expression = NEW(CountOperation(false /* postfix */, increment));
+ expression = NEW(CountOperation(false /* postfix */, increment, position));
   }
   return expression;
 }
=======================================
--- /branches/bleeding_edge/src/x64/codegen-x64.cc      Tue Aug 24 00:26:49 2010
+++ /branches/bleeding_edge/src/x64/codegen-x64.cc      Tue Aug 24 06:51:23 2010
@@ -5061,8 +5061,7 @@
         (node->value()->AsBinaryOperation() != NULL &&
          node->value()->AsBinaryOperation()->ResultOverwriteAllowed());
     // Construct the implicit binary operation.
-    BinaryOperation expr(node->binary_op(), node->target(), node->value());
-    expr.CopyAnalysisResultsFrom(node);
+    BinaryOperation expr(node);
     GenericBinaryOperation(&expr,
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE);
   } else {
@@ -5153,8 +5152,7 @@
         (node->value()->AsBinaryOperation() != NULL &&
          node->value()->AsBinaryOperation()->ResultOverwriteAllowed());
     // Construct the implicit binary operation.
-    BinaryOperation expr(node->binary_op(), node->target(), node->value());
-    expr.CopyAnalysisResultsFrom(node);
+    BinaryOperation expr(node);
     GenericBinaryOperation(&expr,
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE);
   } else {
@@ -5255,8 +5253,7 @@
     bool overwrite_value =
         (node->value()->AsBinaryOperation() != NULL &&
          node->value()->AsBinaryOperation()->ResultOverwriteAllowed());
-    BinaryOperation expr(node->binary_op(), node->target(), node->value());
-    expr.CopyAnalysisResultsFrom(node);
+    BinaryOperation expr(node);
     GenericBinaryOperation(&expr,
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE);
   } else {
=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Tue Aug 24 04:41:26 2010 +++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Tue Aug 24 06:51:23 2010
@@ -2696,6 +2696,7 @@

 void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
   Comment cmnt(masm_, "[ CountOperation");
+  SetSourcePosition(expr->position());

   // Invalid left-hand-sides are rewritten to have a 'throw
   // ReferenceError' as the left-hand side.
@@ -2974,6 +2975,7 @@

 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
   Comment cmnt(masm_, "[ CompareOperation");
+  SetSourcePosition(expr->position());

   // Always perform the comparison for its control flow.  Pack the result
   // into the expression's context after the comparison is performed.

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

Reply via email to