Commit 19d71698 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Unify handling of position info in AST, part 1

* AstNode now has a position info.
* Removed various ad-hoc position infos from subclasses (most of which had it).
* Position is always set with the constructor, instead of later.
* Take care to use kNoPosition in the right spots, to not crash the debugger.

Still to do:

* Eliminate Conditional::then/else_position and WhileStatement::condition_position.
* Make CaseClause a proper AstNode and eliminate its custom position.
* If possible, eliminate all uses of kNoPosition.

R=yangguo@chromium.org
BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17183 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9724f062
...@@ -82,14 +82,13 @@ bool Expression::IsUndefinedLiteral(Isolate* isolate) { ...@@ -82,14 +82,13 @@ bool Expression::IsUndefinedLiteral(Isolate* isolate) {
} }
VariableProxy::VariableProxy(Isolate* isolate, Variable* var) VariableProxy::VariableProxy(Isolate* isolate, Variable* var, int position)
: Expression(isolate), : Expression(isolate, position),
name_(var->name()), name_(var->name()),
var_(NULL), // Will be set by the call to BindTo. var_(NULL), // Will be set by the call to BindTo.
is_this_(var->is_this()), is_this_(var->is_this()),
is_trivial_(false), is_trivial_(false),
is_lvalue_(false), is_lvalue_(false),
position_(RelocInfo::kNoPosition),
interface_(var->interface()) { interface_(var->interface()) {
BindTo(var); BindTo(var);
} }
...@@ -100,13 +99,12 @@ VariableProxy::VariableProxy(Isolate* isolate, ...@@ -100,13 +99,12 @@ VariableProxy::VariableProxy(Isolate* isolate,
bool is_this, bool is_this,
Interface* interface, Interface* interface,
int position) int position)
: Expression(isolate), : Expression(isolate, position),
name_(name), name_(name),
var_(NULL), var_(NULL),
is_this_(is_this), is_this_(is_this),
is_trivial_(false), is_trivial_(false),
is_lvalue_(false), is_lvalue_(false),
position_(position),
interface_(interface) { interface_(interface) {
// Names must be canonicalized for fast equality checks. // Names must be canonicalized for fast equality checks.
ASSERT(name->IsInternalizedString()); ASSERT(name->IsInternalizedString());
...@@ -133,11 +131,10 @@ Assignment::Assignment(Isolate* isolate, ...@@ -133,11 +131,10 @@ Assignment::Assignment(Isolate* isolate,
Expression* target, Expression* target,
Expression* value, Expression* value,
int pos) int pos)
: Expression(isolate), : Expression(isolate, pos),
op_(op), op_(op),
target_(target), target_(target),
value_(value), value_(value),
pos_(pos),
binary_operation_(NULL), binary_operation_(NULL),
assignment_id_(GetNextId(isolate)), assignment_id_(GetNextId(isolate)),
is_monomorphic_(false), is_monomorphic_(false),
......
This diff is collapsed.
...@@ -826,7 +826,7 @@ void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) { ...@@ -826,7 +826,7 @@ void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) {
void FullCodeGenerator::SetStatementPosition(Statement* stmt) { void FullCodeGenerator::SetStatementPosition(Statement* stmt) {
#ifdef ENABLE_DEBUGGER_SUPPORT #ifdef ENABLE_DEBUGGER_SUPPORT
if (!isolate()->debugger()->IsDebuggerActive()) { if (!isolate()->debugger()->IsDebuggerActive()) {
CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); CodeGenerator::RecordPositions(masm_, stmt->position());
} else { } else {
// Check if the statement will be breakable without adding a debug break // Check if the statement will be breakable without adding a debug break
// slot. // slot.
...@@ -836,7 +836,7 @@ void FullCodeGenerator::SetStatementPosition(Statement* stmt) { ...@@ -836,7 +836,7 @@ void FullCodeGenerator::SetStatementPosition(Statement* stmt) {
// breakable. For breakable statements the actual recording of the // breakable. For breakable statements the actual recording of the
// position will be postponed to the breakable code (typically an IC). // position will be postponed to the breakable code (typically an IC).
bool position_recorded = CodeGenerator::RecordPositions( bool position_recorded = CodeGenerator::RecordPositions(
masm_, stmt->statement_pos(), !checker.is_breakable()); masm_, stmt->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) {
...@@ -844,7 +844,7 @@ void FullCodeGenerator::SetStatementPosition(Statement* stmt) { ...@@ -844,7 +844,7 @@ void FullCodeGenerator::SetStatementPosition(Statement* stmt) {
} }
} }
#else #else
CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); CodeGenerator::RecordPositions(masm_, stmt->position());
#endif #endif
} }
......
This diff is collapsed.
...@@ -592,6 +592,8 @@ class Parser BASE_EMBEDDED { ...@@ -592,6 +592,8 @@ class Parser BASE_EMBEDDED {
bool inside_with() const { return top_scope_->inside_with(); } bool inside_with() const { return top_scope_->inside_with(); }
Scanner& scanner() { return scanner_; } Scanner& scanner() { return scanner_; }
int position() { return scanner_.location().beg_pos; }
int peek_position() { return scanner_.peek_location().beg_pos; }
Mode mode() const { return mode_; } Mode mode() const { return mode_; }
ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
bool is_extended_mode() { bool is_extended_mode() {
...@@ -767,8 +769,8 @@ class Parser BASE_EMBEDDED { ...@@ -767,8 +769,8 @@ class Parser BASE_EMBEDDED {
Handle<String> GetSymbol(); Handle<String> GetSymbol();
// Get odd-ball literals. // Get odd-ball literals.
Literal* GetLiteralUndefined(); Literal* GetLiteralUndefined(int position);
Literal* GetLiteralTheHole(); Literal* GetLiteralTheHole(int position);
Handle<String> ParseIdentifier(bool* ok); Handle<String> ParseIdentifier(bool* ok);
Handle<String> ParseIdentifierOrStrictReservedWord( Handle<String> ParseIdentifierOrStrictReservedWord(
......
...@@ -271,13 +271,12 @@ bool Rewriter::Rewrite(CompilationInfo* info) { ...@@ -271,13 +271,12 @@ bool Rewriter::Rewrite(CompilationInfo* info) {
// eval('with ({x:1}) x = 1'); // eval('with ({x:1}) x = 1');
// the end position of the function generated for executing the eval code // the end position of the function generated for executing the eval code
// coincides with the end of the with scope which is the position of '1'. // coincides with the end of the with scope which is the position of '1'.
int position = function->end_position(); int pos = function->end_position();
VariableProxy* result_proxy = processor.factory()->NewVariableProxy( VariableProxy* result_proxy = processor.factory()->NewVariableProxy(
result->name(), false, result->interface(), position); result->name(), false, result->interface(), pos);
result_proxy->BindTo(result); result_proxy->BindTo(result);
Statement* result_statement = Statement* result_statement =
processor.factory()->NewReturnStatement(result_proxy); processor.factory()->NewReturnStatement(result_proxy, pos);
result_statement->set_statement_pos(position);
body->Add(result_statement, info->zone()); body->Add(result_statement, info->zone());
} }
} }
......
...@@ -437,8 +437,8 @@ Variable* Scope::LookupFunctionVar(Handle<String> name, ...@@ -437,8 +437,8 @@ Variable* Scope::LookupFunctionVar(Handle<String> name,
this, name, mode, true /* is valid LHS */, this, name, mode, true /* is valid LHS */,
Variable::NORMAL, kCreatedInitialized); Variable::NORMAL, kCreatedInitialized);
VariableProxy* proxy = factory->NewVariableProxy(var); VariableProxy* proxy = factory->NewVariableProxy(var);
VariableDeclaration* declaration = VariableDeclaration* declaration = factory->NewVariableDeclaration(
factory->NewVariableDeclaration(proxy, mode, this); proxy, mode, this, RelocInfo::kNoPosition);
DeclareFunctionVar(declaration); DeclareFunctionVar(declaration);
var->AllocateTo(Variable::CONTEXT, index); var->AllocateTo(Variable::CONTEXT, index);
return var; return var;
......
...@@ -42,7 +42,7 @@ TEST(List) { ...@@ -42,7 +42,7 @@ TEST(List) {
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
Zone zone(isolate); Zone zone(isolate);
AstNodeFactory<AstNullVisitor> factory(isolate, &zone); AstNodeFactory<AstNullVisitor> factory(isolate, &zone);
AstNode* node = factory.NewEmptyStatement(); AstNode* node = factory.NewEmptyStatement(RelocInfo::kNoPosition);
list->Add(node); list->Add(node);
CHECK_EQ(1, list->length()); CHECK_EQ(1, list->length());
CHECK_EQ(node, list->at(0)); CHECK_EQ(node, list->at(0));
......
...@@ -2850,7 +2850,7 @@ TEST(DebugStepKeyedLoadLoop) { ...@@ -2850,7 +2850,7 @@ TEST(DebugStepKeyedLoadLoop) {
foo->Call(env->Global(), kArgc, args); foo->Call(env->Global(), kArgc, args);
// With stepping all break locations are hit. // With stepping all break locations are hit.
CHECK_EQ(34, break_point_hit_count); CHECK_EQ(35, break_point_hit_count);
v8::Debug::SetDebugEventListener2(NULL); v8::Debug::SetDebugEventListener2(NULL);
CheckDebuggerUnloaded(); CheckDebuggerUnloaded();
...@@ -2897,7 +2897,7 @@ TEST(DebugStepKeyedStoreLoop) { ...@@ -2897,7 +2897,7 @@ TEST(DebugStepKeyedStoreLoop) {
foo->Call(env->Global(), kArgc, args); foo->Call(env->Global(), kArgc, args);
// With stepping all break locations are hit. // With stepping all break locations are hit.
CHECK_EQ(33, break_point_hit_count); CHECK_EQ(34, break_point_hit_count);
v8::Debug::SetDebugEventListener2(NULL); v8::Debug::SetDebugEventListener2(NULL);
CheckDebuggerUnloaded(); CheckDebuggerUnloaded();
...@@ -2941,7 +2941,7 @@ TEST(DebugStepNamedLoadLoop) { ...@@ -2941,7 +2941,7 @@ TEST(DebugStepNamedLoadLoop) {
foo->Call(env->Global(), 0, NULL); foo->Call(env->Global(), 0, NULL);
// With stepping all break locations are hit. // With stepping all break locations are hit.
CHECK_EQ(54, break_point_hit_count); CHECK_EQ(55, break_point_hit_count);
v8::Debug::SetDebugEventListener2(NULL); v8::Debug::SetDebugEventListener2(NULL);
CheckDebuggerUnloaded(); CheckDebuggerUnloaded();
...@@ -2985,7 +2985,7 @@ static void DoDebugStepNamedStoreLoop(int expected) { ...@@ -2985,7 +2985,7 @@ static void DoDebugStepNamedStoreLoop(int expected) {
// Test of the stepping mechanism for named load in a loop. // Test of the stepping mechanism for named load in a loop.
TEST(DebugStepNamedStoreLoop) { TEST(DebugStepNamedStoreLoop) {
DoDebugStepNamedStoreLoop(23); DoDebugStepNamedStoreLoop(24);
} }
...@@ -3358,7 +3358,7 @@ TEST(DebugStepForContinue) { ...@@ -3358,7 +3358,7 @@ TEST(DebugStepForContinue) {
v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) }; v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
result = foo->Call(env->Global(), argc, argv_10); result = foo->Call(env->Global(), argc, argv_10);
CHECK_EQ(5, result->Int32Value()); CHECK_EQ(5, result->Int32Value());
CHECK_EQ(51, break_point_hit_count); CHECK_EQ(52, break_point_hit_count);
// Looping 100 times. // Looping 100 times.
step_action = StepIn; step_action = StepIn;
...@@ -3366,7 +3366,7 @@ TEST(DebugStepForContinue) { ...@@ -3366,7 +3366,7 @@ TEST(DebugStepForContinue) {
v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
result = foo->Call(env->Global(), argc, argv_100); result = foo->Call(env->Global(), argc, argv_100);
CHECK_EQ(50, result->Int32Value()); CHECK_EQ(50, result->Int32Value());
CHECK_EQ(456, break_point_hit_count); CHECK_EQ(457, break_point_hit_count);
// Get rid of the debug event listener. // Get rid of the debug event listener.
v8::Debug::SetDebugEventListener2(NULL); v8::Debug::SetDebugEventListener2(NULL);
...@@ -3410,7 +3410,7 @@ TEST(DebugStepForBreak) { ...@@ -3410,7 +3410,7 @@ TEST(DebugStepForBreak) {
v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) }; v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(10) };
result = foo->Call(env->Global(), argc, argv_10); result = foo->Call(env->Global(), argc, argv_10);
CHECK_EQ(9, result->Int32Value()); CHECK_EQ(9, result->Int32Value());
CHECK_EQ(54, break_point_hit_count); CHECK_EQ(55, break_point_hit_count);
// Looping 100 times. // Looping 100 times.
step_action = StepIn; step_action = StepIn;
...@@ -3418,7 +3418,7 @@ TEST(DebugStepForBreak) { ...@@ -3418,7 +3418,7 @@ TEST(DebugStepForBreak) {
v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) }; v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(100) };
result = foo->Call(env->Global(), argc, argv_100); result = foo->Call(env->Global(), argc, argv_100);
CHECK_EQ(99, result->Int32Value()); CHECK_EQ(99, result->Int32Value());
CHECK_EQ(504, break_point_hit_count); CHECK_EQ(505, break_point_hit_count);
// Get rid of the debug event listener. // Get rid of the debug event listener.
v8::Debug::SetDebugEventListener2(NULL); v8::Debug::SetDebugEventListener2(NULL);
......
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