Commit a342aa03 authored by kasperl@chromium.org's avatar kasperl@chromium.org

Add position information for compares, binary ops, and count

operations.
Review URL: http://codereview.chromium.org/3120027

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5332 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 362d2199
......@@ -2702,6 +2702,8 @@ void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
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 @@ bool FullCodeGenerator::TryLiteralCompare(Token::Value op,
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.
......
......@@ -239,6 +239,16 @@ void Expression::CopyAnalysisResultsFrom(Expression* other) {
}
BinaryOperation::BinaryOperation(Assignment* assignment) {
ASSERT(assignment->is_compound());
op_ = assignment->binary_op();
left_ = assignment->target();
right_ = assignment->value();
pos_ = assignment->position();
CopyAnalysisResultsFrom(assignment);
}
// ----------------------------------------------------------------------------
// Implementation of AstVisitor
......
......@@ -1202,11 +1202,17 @@ class UnaryOperation: public Expression {
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);
// Type testing & conversion
......@@ -1241,11 +1247,13 @@ class BinaryOperation: public Expression {
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 @@ class IncrementOperation: public Expression {
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 @@ class CountOperation: public Expression {
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 @@ class CompareOperation: public Expression {
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 @@ class CompareOperation: public Expression {
Token::Value op_;
Expression* left_;
Expression* right_;
int pos_;
};
......
......@@ -500,6 +500,7 @@ void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) {
case Token::SAR:
VisitForValue(expr->left(), kStack);
VisitForValue(expr->right(), kAccumulator);
SetSourcePosition(expr->position());
EmitBinaryOp(expr->op(), context_);
break;
......
......@@ -5786,8 +5786,7 @@ void CodeGenerator::EmitSlotAssignment(Assignment* node) {
(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 @@ void CodeGenerator::EmitNamedPropertyAssignment(Assignment* node) {
(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 @@ void CodeGenerator::EmitKeyedPropertyAssignment(Assignment* node) {
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 {
......
......@@ -2701,6 +2701,8 @@ void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
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 @@ bool FullCodeGenerator::TryLiteralCompare(Token::Value op,
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.
......
......@@ -214,7 +214,10 @@ class Parser {
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* Parser::ParseExpression(bool accept_IN, bool* ok) {
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 @@ Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
// 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 @@ Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
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 @@ Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
} 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::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
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 @@ Expression* Parser::NewCompareNode(Token::Value op,
return NEW(CompareToNull(is_strict, x));
}
}
return NEW(CompareOperation(op, x, y));
return NEW(CompareOperation(op, x, y, position));
}
......@@ -3086,8 +3092,9 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
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* Parser::ParsePostfixExpression(bool* ok) {
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;
}
......
......@@ -5061,8 +5061,7 @@ void CodeGenerator::EmitSlotAssignment(Assignment* node) {
(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 @@ void CodeGenerator::EmitNamedPropertyAssignment(Assignment* node) {
(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 @@ void CodeGenerator::EmitKeyedPropertyAssignment(Assignment* node) {
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 {
......
......@@ -2696,6 +2696,7 @@ void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
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 @@ bool FullCodeGenerator::TryLiteralCompare(Token::Value op,
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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment