Commit 530109c7 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Unify handling of position info in AST, part 2

* Eliminate Conditional::then/else_position and WhileStatement::condition_position.

R=yangguo@chromium.org
BUG=

Review URL: https://codereview.chromium.org/23597037

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17184 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 19d71698
...@@ -255,7 +255,6 @@ class AstNode: public ZoneObject { ...@@ -255,7 +255,6 @@ class AstNode: public ZoneObject {
class Statement : public AstNode { class Statement : public AstNode {
public: public:
// TODO(rossberg)
explicit Statement(int position) : AstNode(position) {} explicit Statement(int position) : AstNode(position) {}
bool IsEmpty() { return AsEmptyStatement() != NULL; } bool IsEmpty() { return AsEmptyStatement() != NULL; }
...@@ -765,12 +764,6 @@ class DoWhileStatement V8_FINAL : public IterationStatement { ...@@ -765,12 +764,6 @@ class DoWhileStatement V8_FINAL : public IterationStatement {
Expression* cond() const { return cond_; } Expression* cond() const { return cond_; }
// TODO(rossberg): get rid of this.
// Position where condition expression starts. We need it to make
// the loop's condition a breakable location.
int condition_position() { return condition_position_; }
void set_condition_position(int pos) { condition_position_ = pos; }
virtual BailoutId ContinueId() const V8_OVERRIDE { return continue_id_; } virtual BailoutId ContinueId() const V8_OVERRIDE { return continue_id_; }
virtual BailoutId StackCheckId() const V8_OVERRIDE { return back_edge_id_; } virtual BailoutId StackCheckId() const V8_OVERRIDE { return back_edge_id_; }
BailoutId BackEdgeId() const { return back_edge_id_; } BailoutId BackEdgeId() const { return back_edge_id_; }
...@@ -779,7 +772,6 @@ class DoWhileStatement V8_FINAL : public IterationStatement { ...@@ -779,7 +772,6 @@ class DoWhileStatement V8_FINAL : public IterationStatement {
DoWhileStatement(Isolate* isolate, ZoneStringList* labels, int pos) DoWhileStatement(Isolate* isolate, ZoneStringList* labels, int pos)
: IterationStatement(isolate, labels, pos), : IterationStatement(isolate, labels, pos),
cond_(NULL), cond_(NULL),
condition_position_(-1),
continue_id_(GetNextId(isolate)), continue_id_(GetNextId(isolate)),
back_edge_id_(GetNextId(isolate)) { back_edge_id_(GetNextId(isolate)) {
} }
...@@ -787,8 +779,6 @@ class DoWhileStatement V8_FINAL : public IterationStatement { ...@@ -787,8 +779,6 @@ class DoWhileStatement V8_FINAL : public IterationStatement {
private: private:
Expression* cond_; Expression* cond_;
int condition_position_;
const BailoutId continue_id_; const BailoutId continue_id_;
const BailoutId back_edge_id_; const BailoutId back_edge_id_;
}; };
...@@ -2058,10 +2048,6 @@ class Conditional V8_FINAL : public Expression { ...@@ -2058,10 +2048,6 @@ class Conditional V8_FINAL : public Expression {
Expression* then_expression() const { return then_expression_; } Expression* then_expression() const { return then_expression_; }
Expression* else_expression() const { return else_expression_; } Expression* else_expression() const { return else_expression_; }
// TODO(rossberg): get rid of this.
int then_expression_position() const { return then_expression_position_; }
int else_expression_position() const { return else_expression_position_; }
BailoutId ThenId() const { return then_id_; } BailoutId ThenId() const { return then_id_; }
BailoutId ElseId() const { return else_id_; } BailoutId ElseId() const { return else_id_; }
...@@ -2070,15 +2056,11 @@ class Conditional V8_FINAL : public Expression { ...@@ -2070,15 +2056,11 @@ class Conditional V8_FINAL : public Expression {
Expression* condition, Expression* condition,
Expression* then_expression, Expression* then_expression,
Expression* else_expression, Expression* else_expression,
int then_expression_position,
int else_expression_position,
int position) int position)
: Expression(isolate, position), : Expression(isolate, position),
condition_(condition), condition_(condition),
then_expression_(then_expression), then_expression_(then_expression),
else_expression_(else_expression), else_expression_(else_expression),
then_expression_position_(then_expression_position),
else_expression_position_(else_expression_position),
then_id_(GetNextId(isolate)), then_id_(GetNextId(isolate)),
else_id_(GetNextId(isolate)) { } else_id_(GetNextId(isolate)) { }
...@@ -2086,8 +2068,6 @@ class Conditional V8_FINAL : public Expression { ...@@ -2086,8 +2068,6 @@ class Conditional V8_FINAL : public Expression {
Expression* condition_; Expression* condition_;
Expression* then_expression_; Expression* then_expression_;
Expression* else_expression_; Expression* else_expression_;
int then_expression_position_;
int else_expression_position_;
const BailoutId then_id_; const BailoutId then_id_;
const BailoutId else_id_; const BailoutId else_id_;
}; };
...@@ -3192,12 +3172,9 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -3192,12 +3172,9 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
Conditional* NewConditional(Expression* condition, Conditional* NewConditional(Expression* condition,
Expression* then_expression, Expression* then_expression,
Expression* else_expression, Expression* else_expression,
int then_expression_position,
int else_expression_position,
int position) { int position) {
Conditional* cond = new(zone_) Conditional( Conditional* cond = new(zone_) Conditional(
isolate_, condition, then_expression, else_expression, isolate_, condition, then_expression, else_expression, position);
then_expression_position, else_expression_position, position);
VISIT_AND_RETURN(Conditional, cond) VISIT_AND_RETURN(Conditional, cond)
} }
...@@ -3251,9 +3228,8 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -3251,9 +3228,8 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
return lit; return lit;
} }
NativeFunctionLiteral* NewNativeFunctionLiteral(Handle<String> name, NativeFunctionLiteral* NewNativeFunctionLiteral(
v8::Extension* extension, Handle<String> name, v8::Extension* extension, int pos) {
int pos) {
NativeFunctionLiteral* lit = NativeFunctionLiteral* lit =
new(zone_) NativeFunctionLiteral(isolate_, name, extension, pos); new(zone_) NativeFunctionLiteral(isolate_, name, extension, pos);
VISIT_AND_RETURN(NativeFunctionLiteral, lit) VISIT_AND_RETURN(NativeFunctionLiteral, lit)
......
...@@ -849,10 +849,10 @@ void FullCodeGenerator::SetStatementPosition(Statement* stmt) { ...@@ -849,10 +849,10 @@ void FullCodeGenerator::SetStatementPosition(Statement* stmt) {
} }
void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) { void FullCodeGenerator::SetExpressionPosition(Expression* expr) {
#ifdef ENABLE_DEBUGGER_SUPPORT #ifdef ENABLE_DEBUGGER_SUPPORT
if (!isolate()->debugger()->IsDebuggerActive()) { if (!isolate()->debugger()->IsDebuggerActive()) {
CodeGenerator::RecordPositions(masm_, pos); CodeGenerator::RecordPositions(masm_, expr->position());
} else { } else {
// Check if the expression will be breakable without adding a debug break // Check if the expression will be breakable without adding a debug break
// slot. // slot.
...@@ -866,7 +866,7 @@ void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) { ...@@ -866,7 +866,7 @@ void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) {
// statement positions this is used for e.g. the condition expression of // statement positions this is used for e.g. the condition expression of
// a do while loop. // a do while loop.
bool position_recorded = CodeGenerator::RecordPositions( bool position_recorded = CodeGenerator::RecordPositions(
masm_, pos, !checker.is_breakable()); masm_, expr->position(), !checker.is_breakable());
// If the position recording did record a new position generate a debug // If the position recording did record a new position generate a debug
// break slot to make the statement breakable. // break slot to make the statement breakable.
if (position_recorded) { if (position_recorded) {
...@@ -1293,7 +1293,7 @@ void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) { ...@@ -1293,7 +1293,7 @@ void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
// possible to break on the condition. // possible to break on the condition.
__ bind(loop_statement.continue_label()); __ bind(loop_statement.continue_label());
PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS); PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS);
SetExpressionPosition(stmt->cond(), stmt->condition_position()); SetExpressionPosition(stmt->cond());
VisitForControl(stmt->cond(), VisitForControl(stmt->cond(),
&book_keeping, &book_keeping,
loop_statement.break_label(), loop_statement.break_label(),
...@@ -1522,8 +1522,7 @@ void FullCodeGenerator::VisitConditional(Conditional* expr) { ...@@ -1522,8 +1522,7 @@ void FullCodeGenerator::VisitConditional(Conditional* expr) {
PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS); PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS);
__ bind(&true_case); __ bind(&true_case);
SetExpressionPosition(expr->then_expression(), SetExpressionPosition(expr->then_expression());
expr->then_expression_position());
if (context()->IsTest()) { if (context()->IsTest()) {
const TestContext* for_test = TestContext::cast(context()); const TestContext* for_test = TestContext::cast(context());
VisitForControl(expr->then_expression(), VisitForControl(expr->then_expression(),
...@@ -1537,8 +1536,7 @@ void FullCodeGenerator::VisitConditional(Conditional* expr) { ...@@ -1537,8 +1536,7 @@ void FullCodeGenerator::VisitConditional(Conditional* expr) {
PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS); PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS);
__ bind(&false_case); __ bind(&false_case);
SetExpressionPosition(expr->else_expression(), SetExpressionPosition(expr->else_expression());
expr->else_expression_position());
VisitInDuplicateContext(expr->else_expression()); VisitInDuplicateContext(expr->else_expression());
// If control flow falls through Visit, merge it with true case here. // If control flow falls through Visit, merge it with true case here.
if (!context()->IsTest()) { if (!context()->IsTest()) {
......
...@@ -576,7 +576,7 @@ class FullCodeGenerator: public AstVisitor { ...@@ -576,7 +576,7 @@ class FullCodeGenerator: public AstVisitor {
void SetFunctionPosition(FunctionLiteral* fun); void SetFunctionPosition(FunctionLiteral* fun);
void SetReturnPosition(FunctionLiteral* fun); void SetReturnPosition(FunctionLiteral* fun);
void SetStatementPosition(Statement* stmt); void SetStatementPosition(Statement* stmt);
void SetExpressionPosition(Expression* expr, int pos); void SetExpressionPosition(Expression* expr);
void SetStatementPosition(int pos); void SetStatementPosition(int pos);
void SetSourcePosition(int pos); void SetSourcePosition(int pos);
......
...@@ -2571,8 +2571,6 @@ DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, ...@@ -2571,8 +2571,6 @@ DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels,
Expect(Token::WHILE, CHECK_OK); Expect(Token::WHILE, CHECK_OK);
Expect(Token::LPAREN, CHECK_OK); Expect(Token::LPAREN, CHECK_OK);
if (loop != NULL) loop->set_condition_position(position());
Expression* cond = ParseExpression(true, CHECK_OK); Expression* cond = ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
...@@ -3024,13 +3022,10 @@ Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { ...@@ -3024,13 +3022,10 @@ Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) {
// In parsing the first assignment expression in conditional // In parsing the first assignment expression in conditional
// expressions we always accept the 'in' keyword; see ECMA-262, // expressions we always accept the 'in' keyword; see ECMA-262,
// section 11.12, page 58. // section 11.12, page 58.
int left_position = peek_position();
Expression* left = ParseAssignmentExpression(true, CHECK_OK); Expression* left = ParseAssignmentExpression(true, CHECK_OK);
Expect(Token::COLON, CHECK_OK); Expect(Token::COLON, CHECK_OK);
int right_position = peek_position();
Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
return factory()->NewConditional( return factory()->NewConditional(expression, left, right, pos);
expression, left, right, left_position, right_position, pos);
} }
......
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