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()) {
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.
}
+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
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
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_;
};
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);
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));
}
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; }
Token::Value op_;
Expression* left_;
Expression* right_;
+ int pos_;
};
case Token::SAR:
VisitForValue(expr->left(), kStack);
VisitForValue(expr->right(), kAccumulator);
+ SetSourcePosition(expr->position());
EmitBinaryOp(expr->op(), context_);
break;
(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 {
(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 {
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 {
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()) {
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.
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.
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;
}
// 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.
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));
} else {
// We have a "normal" binary operation.
- x = NEW(BinaryOperation(op, x, y));
+ x = NEW(BinaryOperation(op, x, y, position));
}
}
}
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);
return NEW(CompareToNull(is_strict, x));
}
}
- return NEW(CompareOperation(op, x, y));
+ return NEW(CompareOperation(op, x, y, position));
}
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);
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;
}
(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 {
(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 {
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 {
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.
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.