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