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),
......
...@@ -206,12 +206,12 @@ class AstNode: public ZoneObject { ...@@ -206,12 +206,12 @@ class AstNode: public ZoneObject {
return zone->New(static_cast<int>(size)); return zone->New(static_cast<int>(size));
} }
AstNode() {} explicit AstNode(int position): position_(position) {}
virtual ~AstNode() {} virtual ~AstNode() {}
virtual void Accept(AstVisitor* v) = 0; virtual void Accept(AstVisitor* v) = 0;
virtual NodeType node_type() const = 0; virtual NodeType node_type() const = 0;
int position() const { return position_; }
// Type testing & conversion functions overridden by concrete subclasses. // Type testing & conversion functions overridden by concrete subclasses.
#define DECLARE_NODE_FUNCTIONS(type) \ #define DECLARE_NODE_FUNCTIONS(type) \
...@@ -248,21 +248,18 @@ class AstNode: public ZoneObject { ...@@ -248,21 +248,18 @@ class AstNode: public ZoneObject {
void* operator new(size_t size); void* operator new(size_t size);
friend class CaseClause; // Generates AST IDs. friend class CaseClause; // Generates AST IDs.
int position_;
}; };
class Statement : public AstNode { class Statement : public AstNode {
public: public:
Statement() : statement_pos_(RelocInfo::kNoPosition) {} // TODO(rossberg)
explicit Statement(int position) : AstNode(position) {}
bool IsEmpty() { return AsEmptyStatement() != NULL; } bool IsEmpty() { return AsEmptyStatement() != NULL; }
virtual bool IsJump() const { return false; } virtual bool IsJump() const { return false; }
void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; }
int statement_pos() const { return statement_pos_; }
private:
int statement_pos_;
}; };
...@@ -329,11 +326,6 @@ class Expression : public AstNode { ...@@ -329,11 +326,6 @@ class Expression : public AstNode {
kTest kTest
}; };
virtual int position() const {
UNREACHABLE();
return 0;
}
virtual bool IsValidLeftHandSide() { return false; } virtual bool IsValidLeftHandSide() { return false; }
// Helpers for ToBoolean conversion. // Helpers for ToBoolean conversion.
...@@ -387,8 +379,9 @@ class Expression : public AstNode { ...@@ -387,8 +379,9 @@ class Expression : public AstNode {
TypeFeedbackId test_id() const { return test_id_; } TypeFeedbackId test_id() const { return test_id_; }
protected: protected:
explicit Expression(Isolate* isolate) Expression(Isolate* isolate, int pos)
: bounds_(Bounds::Unbounded(isolate)), : AstNode(pos),
bounds_(Bounds::Unbounded(isolate)),
id_(GetNextId(isolate)), id_(GetNextId(isolate)),
test_id_(GetNextId(isolate)) {} test_id_(GetNextId(isolate)) {}
void set_to_boolean_types(byte types) { to_boolean_types_ = types; } void set_to_boolean_types(byte types) { to_boolean_types_ = types; }
...@@ -431,8 +424,10 @@ class BreakableStatement : public Statement { ...@@ -431,8 +424,10 @@ class BreakableStatement : public Statement {
protected: protected:
BreakableStatement( BreakableStatement(
Isolate* isolate, ZoneStringList* labels, BreakableType breakable_type) Isolate* isolate, ZoneStringList* labels,
: labels_(labels), BreakableType breakable_type, int position)
: Statement(position),
labels_(labels),
breakable_type_(breakable_type), breakable_type_(breakable_type),
entry_id_(GetNextId(isolate)), entry_id_(GetNextId(isolate)),
exit_id_(GetNextId(isolate)) { exit_id_(GetNextId(isolate)) {
...@@ -473,8 +468,9 @@ class Block V8_FINAL : public BreakableStatement { ...@@ -473,8 +468,9 @@ class Block V8_FINAL : public BreakableStatement {
ZoneStringList* labels, ZoneStringList* labels,
int capacity, int capacity,
bool is_initializer_block, bool is_initializer_block,
int pos,
Zone* zone) Zone* zone)
: BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY), : BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY, pos),
statements_(capacity, zone), statements_(capacity, zone),
is_initializer_block_(is_initializer_block), is_initializer_block_(is_initializer_block),
scope_(NULL) { scope_(NULL) {
...@@ -498,8 +494,10 @@ class Declaration : public AstNode { ...@@ -498,8 +494,10 @@ class Declaration : public AstNode {
protected: protected:
Declaration(VariableProxy* proxy, Declaration(VariableProxy* proxy,
VariableMode mode, VariableMode mode,
Scope* scope) Scope* scope,
: proxy_(proxy), int pos)
: AstNode(pos),
proxy_(proxy),
mode_(mode), mode_(mode),
scope_(scope) { scope_(scope) {
ASSERT(IsDeclaredVariableMode(mode)); ASSERT(IsDeclaredVariableMode(mode));
...@@ -525,8 +523,9 @@ class VariableDeclaration V8_FINAL : public Declaration { ...@@ -525,8 +523,9 @@ class VariableDeclaration V8_FINAL : public Declaration {
protected: protected:
VariableDeclaration(VariableProxy* proxy, VariableDeclaration(VariableProxy* proxy,
VariableMode mode, VariableMode mode,
Scope* scope) Scope* scope,
: Declaration(proxy, mode, scope) { int pos)
: Declaration(proxy, mode, scope, pos) {
} }
}; };
...@@ -545,8 +544,9 @@ class FunctionDeclaration V8_FINAL : public Declaration { ...@@ -545,8 +544,9 @@ class FunctionDeclaration V8_FINAL : public Declaration {
FunctionDeclaration(VariableProxy* proxy, FunctionDeclaration(VariableProxy* proxy,
VariableMode mode, VariableMode mode,
FunctionLiteral* fun, FunctionLiteral* fun,
Scope* scope) Scope* scope,
: Declaration(proxy, mode, scope), int pos)
: Declaration(proxy, mode, scope, pos),
fun_(fun) { fun_(fun) {
// At the moment there are no "const functions" in JavaScript... // At the moment there are no "const functions" in JavaScript...
ASSERT(mode == VAR || mode == LET); ASSERT(mode == VAR || mode == LET);
...@@ -570,8 +570,9 @@ class ModuleDeclaration V8_FINAL : public Declaration { ...@@ -570,8 +570,9 @@ class ModuleDeclaration V8_FINAL : public Declaration {
protected: protected:
ModuleDeclaration(VariableProxy* proxy, ModuleDeclaration(VariableProxy* proxy,
Module* module, Module* module,
Scope* scope) Scope* scope,
: Declaration(proxy, MODULE, scope), int pos)
: Declaration(proxy, MODULE, scope, pos),
module_(module) { module_(module) {
} }
...@@ -592,8 +593,9 @@ class ImportDeclaration V8_FINAL : public Declaration { ...@@ -592,8 +593,9 @@ class ImportDeclaration V8_FINAL : public Declaration {
protected: protected:
ImportDeclaration(VariableProxy* proxy, ImportDeclaration(VariableProxy* proxy,
Module* module, Module* module,
Scope* scope) Scope* scope,
: Declaration(proxy, LET, scope), int pos)
: Declaration(proxy, LET, scope, pos),
module_(module) { module_(module) {
} }
...@@ -611,8 +613,8 @@ class ExportDeclaration V8_FINAL : public Declaration { ...@@ -611,8 +613,8 @@ class ExportDeclaration V8_FINAL : public Declaration {
} }
protected: protected:
ExportDeclaration(VariableProxy* proxy, Scope* scope) ExportDeclaration(VariableProxy* proxy, Scope* scope, int pos)
: Declaration(proxy, LET, scope) {} : Declaration(proxy, LET, scope, pos) {}
}; };
...@@ -622,11 +624,13 @@ class Module : public AstNode { ...@@ -622,11 +624,13 @@ class Module : public AstNode {
Block* body() const { return body_; } Block* body() const { return body_; }
protected: protected:
explicit Module(Zone* zone) Module(Zone* zone, int pos)
: interface_(Interface::NewModule(zone)), : AstNode(pos),
interface_(Interface::NewModule(zone)),
body_(NULL) {} body_(NULL) {}
explicit Module(Interface* interface, Block* body = NULL) Module(Interface* interface, int pos, Block* body = NULL)
: interface_(interface), : AstNode(pos),
interface_(interface),
body_(body) {} body_(body) {}
private: private:
...@@ -640,7 +644,8 @@ class ModuleLiteral V8_FINAL : public Module { ...@@ -640,7 +644,8 @@ class ModuleLiteral V8_FINAL : public Module {
DECLARE_NODE_TYPE(ModuleLiteral) DECLARE_NODE_TYPE(ModuleLiteral)
protected: protected:
ModuleLiteral(Block* body, Interface* interface) : Module(interface, body) {} ModuleLiteral(Block* body, Interface* interface, int pos)
: Module(interface, pos, body) {}
}; };
...@@ -651,7 +656,7 @@ class ModuleVariable V8_FINAL : public Module { ...@@ -651,7 +656,7 @@ class ModuleVariable V8_FINAL : public Module {
VariableProxy* proxy() const { return proxy_; } VariableProxy* proxy() const { return proxy_; }
protected: protected:
inline explicit ModuleVariable(VariableProxy* proxy); inline ModuleVariable(VariableProxy* proxy, int pos);
private: private:
VariableProxy* proxy_; VariableProxy* proxy_;
...@@ -666,8 +671,8 @@ class ModulePath V8_FINAL : public Module { ...@@ -666,8 +671,8 @@ class ModulePath V8_FINAL : public Module {
Handle<String> name() const { return name_; } Handle<String> name() const { return name_; }
protected: protected:
ModulePath(Module* module, Handle<String> name, Zone* zone) ModulePath(Module* module, Handle<String> name, Zone* zone, int pos)
: Module(zone), : Module(zone, pos),
module_(module), module_(module),
name_(name) { name_(name) {
} }
...@@ -685,8 +690,8 @@ class ModuleUrl V8_FINAL : public Module { ...@@ -685,8 +690,8 @@ class ModuleUrl V8_FINAL : public Module {
Handle<String> url() const { return url_; } Handle<String> url() const { return url_; }
protected: protected:
ModuleUrl(Handle<String> url, Zone* zone) ModuleUrl(Handle<String> url, Zone* zone, int pos)
: Module(zone), url_(url) { : Module(zone, pos), url_(url) {
} }
private: private:
...@@ -702,8 +707,9 @@ class ModuleStatement V8_FINAL : public Statement { ...@@ -702,8 +707,9 @@ class ModuleStatement V8_FINAL : public Statement {
Block* body() const { return body_; } Block* body() const { return body_; }
protected: protected:
ModuleStatement(VariableProxy* proxy, Block* body) ModuleStatement(VariableProxy* proxy, Block* body, int pos)
: proxy_(proxy), : Statement(pos),
proxy_(proxy),
body_(body) { body_(body) {
} }
...@@ -730,8 +736,8 @@ class IterationStatement : public BreakableStatement { ...@@ -730,8 +736,8 @@ class IterationStatement : public BreakableStatement {
Label* continue_target() { return &continue_target_; } Label* continue_target() { return &continue_target_; }
protected: protected:
IterationStatement(Isolate* isolate, ZoneStringList* labels) IterationStatement(Isolate* isolate, ZoneStringList* labels, int pos)
: BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS), : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS, pos),
body_(NULL), body_(NULL),
osr_entry_id_(GetNextId(isolate)) { osr_entry_id_(GetNextId(isolate)) {
} }
...@@ -759,6 +765,7 @@ class DoWhileStatement V8_FINAL : public IterationStatement { ...@@ -759,6 +765,7 @@ 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 // Position where condition expression starts. We need it to make
// the loop's condition a breakable location. // the loop's condition a breakable location.
int condition_position() { return condition_position_; } int condition_position() { return condition_position_; }
...@@ -769,8 +776,8 @@ class DoWhileStatement V8_FINAL : public IterationStatement { ...@@ -769,8 +776,8 @@ class DoWhileStatement V8_FINAL : public IterationStatement {
BailoutId BackEdgeId() const { return back_edge_id_; } BailoutId BackEdgeId() const { return back_edge_id_; }
protected: protected:
DoWhileStatement(Isolate* isolate, ZoneStringList* labels) DoWhileStatement(Isolate* isolate, ZoneStringList* labels, int pos)
: IterationStatement(isolate, labels), : IterationStatement(isolate, labels, pos),
cond_(NULL), cond_(NULL),
condition_position_(-1), condition_position_(-1),
continue_id_(GetNextId(isolate)), continue_id_(GetNextId(isolate)),
...@@ -809,8 +816,8 @@ class WhileStatement V8_FINAL : public IterationStatement { ...@@ -809,8 +816,8 @@ class WhileStatement V8_FINAL : public IterationStatement {
BailoutId BodyId() const { return body_id_; } BailoutId BodyId() const { return body_id_; }
protected: protected:
WhileStatement(Isolate* isolate, ZoneStringList* labels) WhileStatement(Isolate* isolate, ZoneStringList* labels, int pos)
: IterationStatement(isolate, labels), : IterationStatement(isolate, labels, pos),
cond_(NULL), cond_(NULL),
may_have_function_literal_(true), may_have_function_literal_(true),
body_id_(GetNextId(isolate)) { body_id_(GetNextId(isolate)) {
...@@ -860,8 +867,8 @@ class ForStatement V8_FINAL : public IterationStatement { ...@@ -860,8 +867,8 @@ class ForStatement V8_FINAL : public IterationStatement {
void set_loop_variable(Variable* var) { loop_variable_ = var; } void set_loop_variable(Variable* var) { loop_variable_ = var; }
protected: protected:
ForStatement(Isolate* isolate, ZoneStringList* labels) ForStatement(Isolate* isolate, ZoneStringList* labels, int pos)
: IterationStatement(isolate, labels), : IterationStatement(isolate, labels, pos),
init_(NULL), init_(NULL),
cond_(NULL), cond_(NULL),
next_(NULL), next_(NULL),
...@@ -902,8 +909,8 @@ class ForEachStatement : public IterationStatement { ...@@ -902,8 +909,8 @@ class ForEachStatement : public IterationStatement {
Expression* subject() const { return subject_; } Expression* subject() const { return subject_; }
protected: protected:
ForEachStatement(Isolate* isolate, ZoneStringList* labels) ForEachStatement(Isolate* isolate, ZoneStringList* labels, int pos)
: IterationStatement(isolate, labels), : IterationStatement(isolate, labels, pos),
each_(NULL), each_(NULL),
subject_(NULL) { subject_(NULL) {
} }
...@@ -933,8 +940,8 @@ class ForInStatement V8_FINAL : public ForEachStatement { ...@@ -933,8 +940,8 @@ class ForInStatement V8_FINAL : public ForEachStatement {
virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; } virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; }
protected: protected:
ForInStatement(Isolate* isolate, ZoneStringList* labels) ForInStatement(Isolate* isolate, ZoneStringList* labels, int pos)
: ForEachStatement(isolate, labels), : ForEachStatement(isolate, labels, pos),
for_in_type_(SLOW_FOR_IN), for_in_type_(SLOW_FOR_IN),
body_id_(GetNextId(isolate)), body_id_(GetNextId(isolate)),
prepare_id_(GetNextId(isolate)) { prepare_id_(GetNextId(isolate)) {
...@@ -994,8 +1001,8 @@ class ForOfStatement V8_FINAL : public ForEachStatement { ...@@ -994,8 +1001,8 @@ class ForOfStatement V8_FINAL : public ForEachStatement {
BailoutId BackEdgeId() const { return back_edge_id_; } BailoutId BackEdgeId() const { return back_edge_id_; }
protected: protected:
ForOfStatement(Isolate* isolate, ZoneStringList* labels) ForOfStatement(Isolate* isolate, ZoneStringList* labels, int pos)
: ForEachStatement(isolate, labels), : ForEachStatement(isolate, labels, pos),
assign_iterator_(NULL), assign_iterator_(NULL),
next_result_(NULL), next_result_(NULL),
result_done_(NULL), result_done_(NULL),
...@@ -1020,8 +1027,8 @@ class ExpressionStatement V8_FINAL : public Statement { ...@@ -1020,8 +1027,8 @@ class ExpressionStatement V8_FINAL : public Statement {
virtual bool IsJump() const V8_OVERRIDE { return expression_->IsThrow(); } virtual bool IsJump() const V8_OVERRIDE { return expression_->IsThrow(); }
protected: protected:
explicit ExpressionStatement(Expression* expression) ExpressionStatement(Expression* expression, int pos)
: expression_(expression) { } : Statement(pos), expression_(expression) { }
private: private:
Expression* expression_; Expression* expression_;
...@@ -1033,7 +1040,7 @@ class JumpStatement : public Statement { ...@@ -1033,7 +1040,7 @@ class JumpStatement : public Statement {
virtual bool IsJump() const V8_FINAL V8_OVERRIDE { return true; } virtual bool IsJump() const V8_FINAL V8_OVERRIDE { return true; }
protected: protected:
JumpStatement() {} explicit JumpStatement(int pos) : Statement(pos) {}
}; };
...@@ -1044,8 +1051,8 @@ class ContinueStatement V8_FINAL : public JumpStatement { ...@@ -1044,8 +1051,8 @@ class ContinueStatement V8_FINAL : public JumpStatement {
IterationStatement* target() const { return target_; } IterationStatement* target() const { return target_; }
protected: protected:
explicit ContinueStatement(IterationStatement* target) explicit ContinueStatement(IterationStatement* target, int pos)
: target_(target) { } : JumpStatement(pos), target_(target) { }
private: private:
IterationStatement* target_; IterationStatement* target_;
...@@ -1059,8 +1066,8 @@ class BreakStatement V8_FINAL : public JumpStatement { ...@@ -1059,8 +1066,8 @@ class BreakStatement V8_FINAL : public JumpStatement {
BreakableStatement* target() const { return target_; } BreakableStatement* target() const { return target_; }
protected: protected:
explicit BreakStatement(BreakableStatement* target) explicit BreakStatement(BreakableStatement* target, int pos)
: target_(target) { } : JumpStatement(pos), target_(target) { }
private: private:
BreakableStatement* target_; BreakableStatement* target_;
...@@ -1074,8 +1081,8 @@ class ReturnStatement V8_FINAL : public JumpStatement { ...@@ -1074,8 +1081,8 @@ class ReturnStatement V8_FINAL : public JumpStatement {
Expression* expression() const { return expression_; } Expression* expression() const { return expression_; }
protected: protected:
explicit ReturnStatement(Expression* expression) explicit ReturnStatement(Expression* expression, int pos)
: expression_(expression) { } : JumpStatement(pos), expression_(expression) { }
private: private:
Expression* expression_; Expression* expression_;
...@@ -1091,8 +1098,10 @@ class WithStatement V8_FINAL : public Statement { ...@@ -1091,8 +1098,10 @@ class WithStatement V8_FINAL : public Statement {
Statement* statement() const { return statement_; } Statement* statement() const { return statement_; }
protected: protected:
WithStatement(Scope* scope, Expression* expression, Statement* statement) WithStatement(
: scope_(scope), Scope* scope, Expression* expression, Statement* statement, int pos)
: Statement(pos),
scope_(scope),
expression_(expression), expression_(expression),
statement_(statement) { } statement_(statement) { }
...@@ -1158,8 +1167,8 @@ class SwitchStatement V8_FINAL : public BreakableStatement { ...@@ -1158,8 +1167,8 @@ class SwitchStatement V8_FINAL : public BreakableStatement {
void set_switch_type(SwitchType switch_type) { switch_type_ = switch_type; } void set_switch_type(SwitchType switch_type) { switch_type_ = switch_type; }
protected: protected:
SwitchStatement(Isolate* isolate, ZoneStringList* labels) SwitchStatement(Isolate* isolate, ZoneStringList* labels, int pos)
: BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS), : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS, pos),
tag_(NULL), tag_(NULL),
cases_(NULL) { } cases_(NULL) { }
...@@ -1199,8 +1208,10 @@ class IfStatement V8_FINAL : public Statement { ...@@ -1199,8 +1208,10 @@ class IfStatement V8_FINAL : public Statement {
IfStatement(Isolate* isolate, IfStatement(Isolate* isolate,
Expression* condition, Expression* condition,
Statement* then_statement, Statement* then_statement,
Statement* else_statement) Statement* else_statement,
: condition_(condition), int pos)
: Statement(pos),
condition_(condition),
then_statement_(then_statement), then_statement_(then_statement),
else_statement_(else_statement), else_statement_(else_statement),
if_id_(GetNextId(isolate)), if_id_(GetNextId(isolate)),
...@@ -1222,7 +1233,8 @@ class IfStatement V8_FINAL : public Statement { ...@@ -1222,7 +1233,8 @@ class IfStatement V8_FINAL : public Statement {
// stack in the compiler; this should probably be reworked. // stack in the compiler; this should probably be reworked.
class TargetCollector V8_FINAL : public AstNode { class TargetCollector V8_FINAL : public AstNode {
public: public:
explicit TargetCollector(Zone* zone) : targets_(0, zone) { } explicit TargetCollector(Zone* zone)
: AstNode(RelocInfo::kNoPosition), targets_(0, zone) { }
// Adds a jump target to the collector. The collector stores a pointer not // Adds a jump target to the collector. The collector stores a pointer not
// a copy of the target to make binding work, so make sure not to pass in // a copy of the target to make binding work, so make sure not to pass in
...@@ -1252,8 +1264,9 @@ class TryStatement : public Statement { ...@@ -1252,8 +1264,9 @@ class TryStatement : public Statement {
ZoneList<Label*>* escaping_targets() const { return escaping_targets_; } ZoneList<Label*>* escaping_targets() const { return escaping_targets_; }
protected: protected:
TryStatement(int index, Block* try_block) TryStatement(int index, Block* try_block, int pos)
: index_(index), : Statement(pos),
index_(index),
try_block_(try_block), try_block_(try_block),
escaping_targets_(NULL) { } escaping_targets_(NULL) { }
...@@ -1279,8 +1292,9 @@ class TryCatchStatement V8_FINAL : public TryStatement { ...@@ -1279,8 +1292,9 @@ class TryCatchStatement V8_FINAL : public TryStatement {
Block* try_block, Block* try_block,
Scope* scope, Scope* scope,
Variable* variable, Variable* variable,
Block* catch_block) Block* catch_block,
: TryStatement(index, try_block), int pos)
: TryStatement(index, try_block, pos),
scope_(scope), scope_(scope),
variable_(variable), variable_(variable),
catch_block_(catch_block) { catch_block_(catch_block) {
...@@ -1300,8 +1314,9 @@ class TryFinallyStatement V8_FINAL : public TryStatement { ...@@ -1300,8 +1314,9 @@ class TryFinallyStatement V8_FINAL : public TryStatement {
Block* finally_block() const { return finally_block_; } Block* finally_block() const { return finally_block_; }
protected: protected:
TryFinallyStatement(int index, Block* try_block, Block* finally_block) TryFinallyStatement(
: TryStatement(index, try_block), int index, Block* try_block, Block* finally_block, int pos)
: TryStatement(index, try_block, pos),
finally_block_(finally_block) { } finally_block_(finally_block) { }
private: private:
...@@ -1314,7 +1329,7 @@ class DebuggerStatement V8_FINAL : public Statement { ...@@ -1314,7 +1329,7 @@ class DebuggerStatement V8_FINAL : public Statement {
DECLARE_NODE_TYPE(DebuggerStatement) DECLARE_NODE_TYPE(DebuggerStatement)
protected: protected:
DebuggerStatement() {} explicit DebuggerStatement(int pos): Statement(pos) {}
}; };
...@@ -1323,7 +1338,7 @@ class EmptyStatement V8_FINAL : public Statement { ...@@ -1323,7 +1338,7 @@ class EmptyStatement V8_FINAL : public Statement {
DECLARE_NODE_TYPE(EmptyStatement) DECLARE_NODE_TYPE(EmptyStatement)
protected: protected:
EmptyStatement() {} explicit EmptyStatement(int pos): Statement(pos) {}
}; };
...@@ -1380,8 +1395,9 @@ class Literal V8_FINAL : public Expression { ...@@ -1380,8 +1395,9 @@ class Literal V8_FINAL : public Expression {
TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); } TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); }
protected: protected:
Literal(Isolate* isolate, Handle<Object> value) Literal(
: Expression(isolate), Isolate* isolate, Handle<Object> value, int position)
: Expression(isolate, position),
value_(value), value_(value),
isolate_(isolate) { } isolate_(isolate) { }
...@@ -1411,8 +1427,9 @@ class MaterializedLiteral : public Expression { ...@@ -1411,8 +1427,9 @@ class MaterializedLiteral : public Expression {
MaterializedLiteral(Isolate* isolate, MaterializedLiteral(Isolate* isolate,
int literal_index, int literal_index,
bool is_simple, bool is_simple,
int depth) int depth,
: Expression(isolate), int pos)
: Expression(isolate, pos),
literal_index_(literal_index), literal_index_(literal_index),
is_simple_(is_simple), is_simple_(is_simple),
depth_(depth) {} depth_(depth) {}
...@@ -1510,8 +1527,9 @@ class ObjectLiteral V8_FINAL : public MaterializedLiteral { ...@@ -1510,8 +1527,9 @@ class ObjectLiteral V8_FINAL : public MaterializedLiteral {
bool fast_elements, bool fast_elements,
int depth, int depth,
bool may_store_doubles, bool may_store_doubles,
bool has_function) bool has_function,
: MaterializedLiteral(isolate, literal_index, is_simple, depth), int pos)
: MaterializedLiteral(isolate, literal_index, is_simple, depth, pos),
constant_properties_(constant_properties), constant_properties_(constant_properties),
properties_(properties), properties_(properties),
fast_elements_(fast_elements), fast_elements_(fast_elements),
...@@ -1539,8 +1557,9 @@ class RegExpLiteral V8_FINAL : public MaterializedLiteral { ...@@ -1539,8 +1557,9 @@ class RegExpLiteral V8_FINAL : public MaterializedLiteral {
RegExpLiteral(Isolate* isolate, RegExpLiteral(Isolate* isolate,
Handle<String> pattern, Handle<String> pattern,
Handle<String> flags, Handle<String> flags,
int literal_index) int literal_index,
: MaterializedLiteral(isolate, literal_index, false, 1), int pos)
: MaterializedLiteral(isolate, literal_index, false, 1, pos),
pattern_(pattern), pattern_(pattern),
flags_(flags) {} flags_(flags) {}
...@@ -1549,6 +1568,7 @@ class RegExpLiteral V8_FINAL : public MaterializedLiteral { ...@@ -1549,6 +1568,7 @@ class RegExpLiteral V8_FINAL : public MaterializedLiteral {
Handle<String> flags_; Handle<String> flags_;
}; };
// An array literal has a literals object that is used // An array literal has a literals object that is used
// for minimizing the work when constructing it at runtime. // for minimizing the work when constructing it at runtime.
class ArrayLiteral V8_FINAL : public MaterializedLiteral { class ArrayLiteral V8_FINAL : public MaterializedLiteral {
...@@ -1569,8 +1589,9 @@ class ArrayLiteral V8_FINAL : public MaterializedLiteral { ...@@ -1569,8 +1589,9 @@ class ArrayLiteral V8_FINAL : public MaterializedLiteral {
ZoneList<Expression*>* values, ZoneList<Expression*>* values,
int literal_index, int literal_index,
bool is_simple, bool is_simple,
int depth) int depth,
: MaterializedLiteral(isolate, literal_index, is_simple, depth), int pos)
: MaterializedLiteral(isolate, literal_index, is_simple, depth, pos),
constant_elements_(constant_elements), constant_elements_(constant_elements),
values_(values), values_(values),
first_element_id_(ReserveIdRange(isolate, values->length())) {} first_element_id_(ReserveIdRange(isolate, values->length())) {}
...@@ -1603,7 +1624,6 @@ class VariableProxy V8_FINAL : public Expression { ...@@ -1603,7 +1624,6 @@ class VariableProxy V8_FINAL : public Expression {
Handle<String> name() const { return name_; } Handle<String> name() const { return name_; }
Variable* var() const { return var_; } Variable* var() const { return var_; }
bool is_this() const { return is_this_; } bool is_this() const { return is_this_; }
int position() const { return position_; }
Interface* interface() const { return interface_; } Interface* interface() const { return interface_; }
...@@ -1614,7 +1634,7 @@ class VariableProxy V8_FINAL : public Expression { ...@@ -1614,7 +1634,7 @@ class VariableProxy V8_FINAL : public Expression {
void BindTo(Variable* var); void BindTo(Variable* var);
protected: protected:
VariableProxy(Isolate* isolate, Variable* var); VariableProxy(Isolate* isolate, Variable* var, int position);
VariableProxy(Isolate* isolate, VariableProxy(Isolate* isolate,
Handle<String> name, Handle<String> name,
...@@ -1629,7 +1649,6 @@ class VariableProxy V8_FINAL : public Expression { ...@@ -1629,7 +1649,6 @@ class VariableProxy V8_FINAL : public Expression {
// True if this variable proxy is being used in an assignment // True if this variable proxy is being used in an assignment
// or with a increment/decrement operator. // or with a increment/decrement operator.
bool is_lvalue_; bool is_lvalue_;
int position_;
Interface* interface_; Interface* interface_;
}; };
...@@ -1642,7 +1661,6 @@ class Property V8_FINAL : public Expression { ...@@ -1642,7 +1661,6 @@ class Property V8_FINAL : public Expression {
Expression* obj() const { return obj_; } Expression* obj() const { return obj_; }
Expression* key() const { return key_; } Expression* key() const { return key_; }
virtual int position() const V8_OVERRIDE { return pos_; }
BailoutId LoadId() const { return load_id_; } BailoutId LoadId() const { return load_id_; }
...@@ -1666,10 +1684,9 @@ class Property V8_FINAL : public Expression { ...@@ -1666,10 +1684,9 @@ class Property V8_FINAL : public Expression {
Expression* obj, Expression* obj,
Expression* key, Expression* key,
int pos) int pos)
: Expression(isolate), : Expression(isolate, pos),
obj_(obj), obj_(obj),
key_(key), key_(key),
pos_(pos),
load_id_(GetNextId(isolate)), load_id_(GetNextId(isolate)),
is_monomorphic_(false), is_monomorphic_(false),
is_uninitialized_(false), is_uninitialized_(false),
...@@ -1679,7 +1696,6 @@ class Property V8_FINAL : public Expression { ...@@ -1679,7 +1696,6 @@ class Property V8_FINAL : public Expression {
private: private:
Expression* obj_; Expression* obj_;
Expression* key_; Expression* key_;
int pos_;
const BailoutId load_id_; const BailoutId load_id_;
SmallMapList receiver_types_; SmallMapList receiver_types_;
...@@ -1696,7 +1712,6 @@ class Call V8_FINAL : public Expression { ...@@ -1696,7 +1712,6 @@ class Call V8_FINAL : public Expression {
Expression* expression() const { return expression_; } Expression* expression() const { return expression_; }
ZoneList<Expression*>* arguments() const { return arguments_; } ZoneList<Expression*>* arguments() const { return arguments_; }
virtual int position() const V8_FINAL { return pos_; }
// Type feedback information. // Type feedback information.
TypeFeedbackId CallFeedbackId() const { return reuse(id()); } TypeFeedbackId CallFeedbackId() const { return reuse(id()); }
...@@ -1751,10 +1766,9 @@ class Call V8_FINAL : public Expression { ...@@ -1751,10 +1766,9 @@ class Call V8_FINAL : public Expression {
Expression* expression, Expression* expression,
ZoneList<Expression*>* arguments, ZoneList<Expression*>* arguments,
int pos) int pos)
: Expression(isolate), : Expression(isolate, pos),
expression_(expression), expression_(expression),
arguments_(arguments), arguments_(arguments),
pos_(pos),
is_monomorphic_(false), is_monomorphic_(false),
check_type_(RECEIVER_MAP_CHECK), check_type_(RECEIVER_MAP_CHECK),
return_id_(GetNextId(isolate)) { } return_id_(GetNextId(isolate)) { }
...@@ -1762,7 +1776,6 @@ class Call V8_FINAL : public Expression { ...@@ -1762,7 +1776,6 @@ class Call V8_FINAL : public Expression {
private: private:
Expression* expression_; Expression* expression_;
ZoneList<Expression*>* arguments_; ZoneList<Expression*>* arguments_;
int pos_;
bool is_monomorphic_; bool is_monomorphic_;
CheckType check_type_; CheckType check_type_;
...@@ -1781,7 +1794,6 @@ class CallNew V8_FINAL : public Expression { ...@@ -1781,7 +1794,6 @@ class CallNew V8_FINAL : public Expression {
Expression* expression() const { return expression_; } Expression* expression() const { return expression_; }
ZoneList<Expression*>* arguments() const { return arguments_; } ZoneList<Expression*>* arguments() const { return arguments_; }
virtual int position() const V8_OVERRIDE { return pos_; }
// Type feedback information. // Type feedback information.
TypeFeedbackId CallNewFeedbackId() const { return reuse(id()); } TypeFeedbackId CallNewFeedbackId() const { return reuse(id()); }
...@@ -1800,10 +1812,9 @@ class CallNew V8_FINAL : public Expression { ...@@ -1800,10 +1812,9 @@ class CallNew V8_FINAL : public Expression {
Expression* expression, Expression* expression,
ZoneList<Expression*>* arguments, ZoneList<Expression*>* arguments,
int pos) int pos)
: Expression(isolate), : Expression(isolate, pos),
expression_(expression), expression_(expression),
arguments_(arguments), arguments_(arguments),
pos_(pos),
is_monomorphic_(false), is_monomorphic_(false),
elements_kind_(GetInitialFastElementsKind()), elements_kind_(GetInitialFastElementsKind()),
return_id_(GetNextId(isolate)) { } return_id_(GetNextId(isolate)) { }
...@@ -1811,7 +1822,6 @@ class CallNew V8_FINAL : public Expression { ...@@ -1811,7 +1822,6 @@ class CallNew V8_FINAL : public Expression {
private: private:
Expression* expression_; Expression* expression_;
ZoneList<Expression*>* arguments_; ZoneList<Expression*>* arguments_;
int pos_;
bool is_monomorphic_; bool is_monomorphic_;
Handle<JSFunction> target_; Handle<JSFunction> target_;
...@@ -1841,8 +1851,9 @@ class CallRuntime V8_FINAL : public Expression { ...@@ -1841,8 +1851,9 @@ class CallRuntime V8_FINAL : public Expression {
CallRuntime(Isolate* isolate, CallRuntime(Isolate* isolate,
Handle<String> name, Handle<String> name,
const Runtime::Function* function, const Runtime::Function* function,
ZoneList<Expression*>* arguments) ZoneList<Expression*>* arguments,
: Expression(isolate), int pos)
: Expression(isolate, pos),
name_(name), name_(name),
function_(function), function_(function),
arguments_(arguments) { } arguments_(arguments) { }
...@@ -1860,7 +1871,6 @@ class UnaryOperation V8_FINAL : public Expression { ...@@ -1860,7 +1871,6 @@ class UnaryOperation V8_FINAL : public Expression {
Token::Value op() const { return op_; } Token::Value op() const { return op_; }
Expression* expression() const { return expression_; } Expression* expression() const { return expression_; }
virtual int position() const V8_OVERRIDE { return pos_; }
BailoutId MaterializeTrueId() { return materialize_true_id_; } BailoutId MaterializeTrueId() { return materialize_true_id_; }
BailoutId MaterializeFalseId() { return materialize_false_id_; } BailoutId MaterializeFalseId() { return materialize_false_id_; }
...@@ -1873,10 +1883,9 @@ class UnaryOperation V8_FINAL : public Expression { ...@@ -1873,10 +1883,9 @@ class UnaryOperation V8_FINAL : public Expression {
Token::Value op, Token::Value op,
Expression* expression, Expression* expression,
int pos) int pos)
: Expression(isolate), : Expression(isolate, pos),
op_(op), op_(op),
expression_(expression), expression_(expression),
pos_(pos),
materialize_true_id_(GetNextId(isolate)), materialize_true_id_(GetNextId(isolate)),
materialize_false_id_(GetNextId(isolate)) { materialize_false_id_(GetNextId(isolate)) {
ASSERT(Token::IsUnaryOp(op)); ASSERT(Token::IsUnaryOp(op));
...@@ -1885,7 +1894,6 @@ class UnaryOperation V8_FINAL : public Expression { ...@@ -1885,7 +1894,6 @@ class UnaryOperation V8_FINAL : public Expression {
private: private:
Token::Value op_; Token::Value op_;
Expression* expression_; Expression* expression_;
int pos_;
// For unary not (Token::NOT), the AST ids where true and false will // For unary not (Token::NOT), the AST ids where true and false will
// actually be materialized, respectively. // actually be materialized, respectively.
...@@ -1903,7 +1911,6 @@ class BinaryOperation V8_FINAL : public Expression { ...@@ -1903,7 +1911,6 @@ class BinaryOperation V8_FINAL : public Expression {
Token::Value op() const { return op_; } Token::Value op() const { return op_; }
Expression* left() const { return left_; } Expression* left() const { return left_; }
Expression* right() const { return right_; } Expression* right() const { return right_; }
virtual int position() const V8_OVERRIDE { return pos_; }
BailoutId RightId() const { return right_id_; } BailoutId RightId() const { return right_id_; }
...@@ -1920,11 +1927,10 @@ class BinaryOperation V8_FINAL : public Expression { ...@@ -1920,11 +1927,10 @@ class BinaryOperation V8_FINAL : public Expression {
Expression* left, Expression* left,
Expression* right, Expression* right,
int pos) int pos)
: Expression(isolate), : Expression(isolate, pos),
op_(op), op_(op),
left_(left), left_(left),
right_(right), right_(right),
pos_(pos),
right_id_(GetNextId(isolate)) { right_id_(GetNextId(isolate)) {
ASSERT(Token::IsBinaryOp(op)); ASSERT(Token::IsBinaryOp(op));
} }
...@@ -1933,7 +1939,6 @@ class BinaryOperation V8_FINAL : public Expression { ...@@ -1933,7 +1939,6 @@ class BinaryOperation V8_FINAL : public Expression {
Token::Value op_; Token::Value op_;
Expression* left_; Expression* left_;
Expression* right_; Expression* right_;
int pos_;
// TODO(rossberg): the fixed arg should probably be represented as a Constant // TODO(rossberg): the fixed arg should probably be represented as a Constant
// type for the RHS. // type for the RHS.
...@@ -1958,7 +1963,6 @@ class CountOperation V8_FINAL : public Expression { ...@@ -1958,7 +1963,6 @@ class CountOperation V8_FINAL : public Expression {
} }
Expression* expression() const { return expression_; } Expression* expression() const { return expression_; }
virtual int position() const V8_OVERRIDE { return pos_; }
void RecordTypeFeedback(TypeFeedbackOracle* oracle, Zone* zone); void RecordTypeFeedback(TypeFeedbackOracle* oracle, Zone* zone);
virtual bool IsMonomorphic() V8_OVERRIDE { return is_monomorphic_; } virtual bool IsMonomorphic() V8_OVERRIDE { return is_monomorphic_; }
...@@ -1981,13 +1985,12 @@ class CountOperation V8_FINAL : public Expression { ...@@ -1981,13 +1985,12 @@ class CountOperation V8_FINAL : public Expression {
bool is_prefix, bool is_prefix,
Expression* expr, Expression* expr,
int pos) int pos)
: Expression(isolate), : Expression(isolate, pos),
op_(op), op_(op),
is_prefix_(is_prefix), is_prefix_(is_prefix),
is_monomorphic_(false), is_monomorphic_(false),
store_mode_(STANDARD_STORE), store_mode_(STANDARD_STORE),
expression_(expr), expression_(expr),
pos_(pos),
assignment_id_(GetNextId(isolate)), assignment_id_(GetNextId(isolate)),
count_id_(GetNextId(isolate)) {} count_id_(GetNextId(isolate)) {}
...@@ -2000,7 +2003,6 @@ class CountOperation V8_FINAL : public Expression { ...@@ -2000,7 +2003,6 @@ class CountOperation V8_FINAL : public Expression {
Handle<Type> type_; Handle<Type> type_;
Expression* expression_; Expression* expression_;
int pos_;
const BailoutId assignment_id_; const BailoutId assignment_id_;
const TypeFeedbackId count_id_; const TypeFeedbackId count_id_;
SmallMapList receiver_types_; SmallMapList receiver_types_;
...@@ -2014,7 +2016,6 @@ class CompareOperation V8_FINAL : public Expression { ...@@ -2014,7 +2016,6 @@ class CompareOperation V8_FINAL : public Expression {
Token::Value op() const { return op_; } Token::Value op() const { return op_; }
Expression* left() const { return left_; } Expression* left() const { return left_; }
Expression* right() const { return right_; } Expression* right() const { return right_; }
virtual int position() const V8_OVERRIDE { return pos_; }
// Type feedback information. // Type feedback information.
TypeFeedbackId CompareOperationFeedbackId() const { return reuse(id()); } TypeFeedbackId CompareOperationFeedbackId() const { return reuse(id()); }
...@@ -2032,11 +2033,10 @@ class CompareOperation V8_FINAL : public Expression { ...@@ -2032,11 +2033,10 @@ class CompareOperation V8_FINAL : public Expression {
Expression* left, Expression* left,
Expression* right, Expression* right,
int pos) int pos)
: Expression(isolate), : Expression(isolate, pos),
op_(op), op_(op),
left_(left), left_(left),
right_(right), right_(right),
pos_(pos),
combined_type_(Type::Null(), isolate) { combined_type_(Type::Null(), isolate) {
ASSERT(Token::IsCompareOp(op)); ASSERT(Token::IsCompareOp(op));
} }
...@@ -2045,7 +2045,6 @@ class CompareOperation V8_FINAL : public Expression { ...@@ -2045,7 +2045,6 @@ class CompareOperation V8_FINAL : public Expression {
Token::Value op_; Token::Value op_;
Expression* left_; Expression* left_;
Expression* right_; Expression* right_;
int pos_;
Handle<Type> combined_type_; Handle<Type> combined_type_;
}; };
...@@ -2059,6 +2058,7 @@ class Conditional V8_FINAL : public Expression { ...@@ -2059,6 +2058,7 @@ 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 then_expression_position() const { return then_expression_position_; }
int else_expression_position() const { return else_expression_position_; } int else_expression_position() const { return else_expression_position_; }
...@@ -2071,8 +2071,9 @@ class Conditional V8_FINAL : public Expression { ...@@ -2071,8 +2071,9 @@ class Conditional V8_FINAL : public Expression {
Expression* then_expression, Expression* then_expression,
Expression* else_expression, Expression* else_expression,
int then_expression_position, int then_expression_position,
int else_expression_position) int else_expression_position,
: Expression(isolate), int position)
: Expression(isolate, position),
condition_(condition), condition_(condition),
then_expression_(then_expression), then_expression_(then_expression),
else_expression_(else_expression), else_expression_(else_expression),
...@@ -2103,7 +2104,6 @@ class Assignment V8_FINAL : public Expression { ...@@ -2103,7 +2104,6 @@ class Assignment V8_FINAL : public Expression {
Token::Value op() const { return op_; } Token::Value op() const { return op_; }
Expression* target() const { return target_; } Expression* target() const { return target_; }
Expression* value() const { return value_; } Expression* value() const { return value_; }
virtual int position() const V8_OVERRIDE { return pos_; }
BinaryOperation* binary_operation() const { return binary_operation_; } BinaryOperation* binary_operation() const { return binary_operation_; }
// This check relies on the definition order of token in token.h. // This check relies on the definition order of token in token.h.
...@@ -2134,8 +2134,8 @@ class Assignment V8_FINAL : public Expression { ...@@ -2134,8 +2134,8 @@ class Assignment V8_FINAL : public Expression {
void Init(Isolate* isolate, AstNodeFactory<Visitor>* factory) { void Init(Isolate* isolate, AstNodeFactory<Visitor>* factory) {
ASSERT(Token::IsAssignmentOp(op_)); ASSERT(Token::IsAssignmentOp(op_));
if (is_compound()) { if (is_compound()) {
binary_operation_ = binary_operation_ = factory->NewBinaryOperation(
factory->NewBinaryOperation(binary_op(), target_, value_, pos_ + 1); binary_op(), target_, value_, position() + 1);
} }
} }
...@@ -2143,7 +2143,6 @@ class Assignment V8_FINAL : public Expression { ...@@ -2143,7 +2143,6 @@ class Assignment V8_FINAL : public Expression {
Token::Value op_; Token::Value op_;
Expression* target_; Expression* target_;
Expression* value_; Expression* value_;
int pos_;
BinaryOperation* binary_operation_; BinaryOperation* binary_operation_;
const BailoutId assignment_id_; const BailoutId assignment_id_;
...@@ -2169,7 +2168,6 @@ class Yield V8_FINAL : public Expression { ...@@ -2169,7 +2168,6 @@ class Yield V8_FINAL : public Expression {
Expression* generator_object() const { return generator_object_; } Expression* generator_object() const { return generator_object_; }
Expression* expression() const { return expression_; } Expression* expression() const { return expression_; }
Kind yield_kind() const { return yield_kind_; } Kind yield_kind() const { return yield_kind_; }
virtual int position() const V8_OVERRIDE { return pos_; }
// Delegating yield surrounds the "yield" in a "try/catch". This index // Delegating yield surrounds the "yield" in a "try/catch". This index
// locates the catch handler in the handler table, and is equivalent to // locates the catch handler in the handler table, and is equivalent to
...@@ -2189,19 +2187,17 @@ class Yield V8_FINAL : public Expression { ...@@ -2189,19 +2187,17 @@ class Yield V8_FINAL : public Expression {
Expression* expression, Expression* expression,
Kind yield_kind, Kind yield_kind,
int pos) int pos)
: Expression(isolate), : Expression(isolate, pos),
generator_object_(generator_object), generator_object_(generator_object),
expression_(expression), expression_(expression),
yield_kind_(yield_kind), yield_kind_(yield_kind),
index_(-1), index_(-1) { }
pos_(pos) { }
private: private:
Expression* generator_object_; Expression* generator_object_;
Expression* expression_; Expression* expression_;
Kind yield_kind_; Kind yield_kind_;
int index_; int index_;
int pos_;
}; };
...@@ -2210,15 +2206,13 @@ class Throw V8_FINAL : public Expression { ...@@ -2210,15 +2206,13 @@ class Throw V8_FINAL : public Expression {
DECLARE_NODE_TYPE(Throw) DECLARE_NODE_TYPE(Throw)
Expression* exception() const { return exception_; } Expression* exception() const { return exception_; }
virtual int position() const V8_OVERRIDE { return pos_; }
protected: protected:
Throw(Isolate* isolate, Expression* exception, int pos) Throw(Isolate* isolate, Expression* exception, int pos)
: Expression(isolate), exception_(exception), pos_(pos) {} : Expression(isolate, pos), exception_(exception) {}
private: private:
Expression* exception_; Expression* exception_;
int pos_;
}; };
...@@ -2333,8 +2327,9 @@ class FunctionLiteral V8_FINAL : public Expression { ...@@ -2333,8 +2327,9 @@ class FunctionLiteral V8_FINAL : public Expression {
ParameterFlag has_duplicate_parameters, ParameterFlag has_duplicate_parameters,
IsFunctionFlag is_function, IsFunctionFlag is_function,
IsParenthesizedFlag is_parenthesized, IsParenthesizedFlag is_parenthesized,
IsGeneratorFlag is_generator) IsGeneratorFlag is_generator,
: Expression(isolate), int position)
: Expression(isolate, position),
name_(name), name_(name),
scope_(scope), scope_(scope),
body_(body), body_(body),
...@@ -2389,8 +2384,8 @@ class NativeFunctionLiteral V8_FINAL : public Expression { ...@@ -2389,8 +2384,8 @@ class NativeFunctionLiteral V8_FINAL : public Expression {
protected: protected:
NativeFunctionLiteral( NativeFunctionLiteral(
Isolate* isolate, Handle<String> name, v8::Extension* extension) Isolate* isolate, Handle<String> name, v8::Extension* extension, int pos)
: Expression(isolate), name_(name), extension_(extension) { } : Expression(isolate, pos), name_(name), extension_(extension) {}
private: private:
Handle<String> name_; Handle<String> name_;
...@@ -2403,7 +2398,7 @@ class ThisFunction V8_FINAL : public Expression { ...@@ -2403,7 +2398,7 @@ class ThisFunction V8_FINAL : public Expression {
DECLARE_NODE_TYPE(ThisFunction) DECLARE_NODE_TYPE(ThisFunction)
protected: protected:
explicit ThisFunction(Isolate* isolate): Expression(isolate) {} explicit ThisFunction(Isolate* isolate, int pos): Expression(isolate, pos) {}
}; };
#undef DECLARE_NODE_TYPE #undef DECLARE_NODE_TYPE
...@@ -2770,8 +2765,8 @@ class RegExpEmpty V8_FINAL : public RegExpTree { ...@@ -2770,8 +2765,8 @@ class RegExpEmpty V8_FINAL : public RegExpTree {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Out-of-line inline constructors (to side-step cyclic dependencies). // Out-of-line inline constructors (to side-step cyclic dependencies).
inline ModuleVariable::ModuleVariable(VariableProxy* proxy) inline ModuleVariable::ModuleVariable(VariableProxy* proxy, int pos)
: Module(proxy->interface()), : Module(proxy->interface(), pos),
proxy_(proxy) { proxy_(proxy) {
} }
...@@ -2888,75 +2883,81 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -2888,75 +2883,81 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
VariableMode mode, VariableMode mode,
Scope* scope) { Scope* scope,
int pos) {
VariableDeclaration* decl = VariableDeclaration* decl =
new(zone_) VariableDeclaration(proxy, mode, scope); new(zone_) VariableDeclaration(proxy, mode, scope, pos);
VISIT_AND_RETURN(VariableDeclaration, decl) VISIT_AND_RETURN(VariableDeclaration, decl)
} }
FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy, FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
VariableMode mode, VariableMode mode,
FunctionLiteral* fun, FunctionLiteral* fun,
Scope* scope) { Scope* scope,
int pos) {
FunctionDeclaration* decl = FunctionDeclaration* decl =
new(zone_) FunctionDeclaration(proxy, mode, fun, scope); new(zone_) FunctionDeclaration(proxy, mode, fun, scope, pos);
VISIT_AND_RETURN(FunctionDeclaration, decl) VISIT_AND_RETURN(FunctionDeclaration, decl)
} }
ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy, ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy,
Module* module, Module* module,
Scope* scope) { Scope* scope,
int pos) {
ModuleDeclaration* decl = ModuleDeclaration* decl =
new(zone_) ModuleDeclaration(proxy, module, scope); new(zone_) ModuleDeclaration(proxy, module, scope, pos);
VISIT_AND_RETURN(ModuleDeclaration, decl) VISIT_AND_RETURN(ModuleDeclaration, decl)
} }
ImportDeclaration* NewImportDeclaration(VariableProxy* proxy, ImportDeclaration* NewImportDeclaration(VariableProxy* proxy,
Module* module, Module* module,
Scope* scope) { Scope* scope,
int pos) {
ImportDeclaration* decl = ImportDeclaration* decl =
new(zone_) ImportDeclaration(proxy, module, scope); new(zone_) ImportDeclaration(proxy, module, scope, pos);
VISIT_AND_RETURN(ImportDeclaration, decl) VISIT_AND_RETURN(ImportDeclaration, decl)
} }
ExportDeclaration* NewExportDeclaration(VariableProxy* proxy, ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
Scope* scope) { Scope* scope,
int pos) {
ExportDeclaration* decl = ExportDeclaration* decl =
new(zone_) ExportDeclaration(proxy, scope); new(zone_) ExportDeclaration(proxy, scope, pos);
VISIT_AND_RETURN(ExportDeclaration, decl) VISIT_AND_RETURN(ExportDeclaration, decl)
} }
ModuleLiteral* NewModuleLiteral(Block* body, Interface* interface) { ModuleLiteral* NewModuleLiteral(Block* body, Interface* interface, int pos) {
ModuleLiteral* module = new(zone_) ModuleLiteral(body, interface); ModuleLiteral* module = new(zone_) ModuleLiteral(body, interface, pos);
VISIT_AND_RETURN(ModuleLiteral, module) VISIT_AND_RETURN(ModuleLiteral, module)
} }
ModuleVariable* NewModuleVariable(VariableProxy* proxy) { ModuleVariable* NewModuleVariable(VariableProxy* proxy, int pos) {
ModuleVariable* module = new(zone_) ModuleVariable(proxy); ModuleVariable* module = new(zone_) ModuleVariable(proxy, pos);
VISIT_AND_RETURN(ModuleVariable, module) VISIT_AND_RETURN(ModuleVariable, module)
} }
ModulePath* NewModulePath(Module* origin, Handle<String> name) { ModulePath* NewModulePath(Module* origin, Handle<String> name, int pos) {
ModulePath* module = new(zone_) ModulePath(origin, name, zone_); ModulePath* module = new(zone_) ModulePath(origin, name, zone_, pos);
VISIT_AND_RETURN(ModulePath, module) VISIT_AND_RETURN(ModulePath, module)
} }
ModuleUrl* NewModuleUrl(Handle<String> url) { ModuleUrl* NewModuleUrl(Handle<String> url, int pos) {
ModuleUrl* module = new(zone_) ModuleUrl(url, zone_); ModuleUrl* module = new(zone_) ModuleUrl(url, zone_, pos);
VISIT_AND_RETURN(ModuleUrl, module) VISIT_AND_RETURN(ModuleUrl, module)
} }
Block* NewBlock(ZoneStringList* labels, Block* NewBlock(ZoneStringList* labels,
int capacity, int capacity,
bool is_initializer_block) { bool is_initializer_block,
int pos) {
Block* block = new(zone_) Block( Block* block = new(zone_) Block(
isolate_, labels, capacity, is_initializer_block, zone_); isolate_, labels, capacity, is_initializer_block, pos, zone_);
VISIT_AND_RETURN(Block, block) VISIT_AND_RETURN(Block, block)
} }
#define STATEMENT_WITH_LABELS(NodeType) \ #define STATEMENT_WITH_LABELS(NodeType) \
NodeType* New##NodeType(ZoneStringList* labels) { \ NodeType* New##NodeType(ZoneStringList* labels, int pos) { \
NodeType* stmt = new(zone_) NodeType(isolate_, labels); \ NodeType* stmt = new(zone_) NodeType(isolate_, labels, pos); \
VISIT_AND_RETURN(NodeType, stmt); \ VISIT_AND_RETURN(NodeType, stmt); \
} }
STATEMENT_WITH_LABELS(DoWhileStatement) STATEMENT_WITH_LABELS(DoWhileStatement)
...@@ -2966,14 +2967,15 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -2966,14 +2967,15 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
#undef STATEMENT_WITH_LABELS #undef STATEMENT_WITH_LABELS
ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
ZoneStringList* labels) { ZoneStringList* labels,
int pos) {
switch (visit_mode) { switch (visit_mode) {
case ForEachStatement::ENUMERATE: { case ForEachStatement::ENUMERATE: {
ForInStatement* stmt = new(zone_) ForInStatement(isolate_, labels); ForInStatement* stmt = new(zone_) ForInStatement(isolate_, labels, pos);
VISIT_AND_RETURN(ForInStatement, stmt); VISIT_AND_RETURN(ForInStatement, stmt);
} }
case ForEachStatement::ITERATE: { case ForEachStatement::ITERATE: {
ForOfStatement* stmt = new(zone_) ForOfStatement(isolate_, labels); ForOfStatement* stmt = new(zone_) ForOfStatement(isolate_, labels, pos);
VISIT_AND_RETURN(ForOfStatement, stmt); VISIT_AND_RETURN(ForOfStatement, stmt);
} }
} }
...@@ -2981,44 +2983,47 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -2981,44 +2983,47 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
return NULL; return NULL;
} }
ModuleStatement* NewModuleStatement(VariableProxy* proxy, Block* body) { ModuleStatement* NewModuleStatement(
ModuleStatement* stmt = new(zone_) ModuleStatement(proxy, body); VariableProxy* proxy, Block* body, int pos) {
ModuleStatement* stmt = new(zone_) ModuleStatement(proxy, body, pos);
VISIT_AND_RETURN(ModuleStatement, stmt) VISIT_AND_RETURN(ModuleStatement, stmt)
} }
ExpressionStatement* NewExpressionStatement(Expression* expression) { ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
ExpressionStatement* stmt = new(zone_) ExpressionStatement(expression); ExpressionStatement* stmt = new(zone_) ExpressionStatement(expression, pos);
VISIT_AND_RETURN(ExpressionStatement, stmt) VISIT_AND_RETURN(ExpressionStatement, stmt)
} }
ContinueStatement* NewContinueStatement(IterationStatement* target) { ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) {
ContinueStatement* stmt = new(zone_) ContinueStatement(target); ContinueStatement* stmt = new(zone_) ContinueStatement(target, pos);
VISIT_AND_RETURN(ContinueStatement, stmt) VISIT_AND_RETURN(ContinueStatement, stmt)
} }
BreakStatement* NewBreakStatement(BreakableStatement* target) { BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) {
BreakStatement* stmt = new(zone_) BreakStatement(target); BreakStatement* stmt = new(zone_) BreakStatement(target, pos);
VISIT_AND_RETURN(BreakStatement, stmt) VISIT_AND_RETURN(BreakStatement, stmt)
} }
ReturnStatement* NewReturnStatement(Expression* expression) { ReturnStatement* NewReturnStatement(Expression* expression, int pos) {
ReturnStatement* stmt = new(zone_) ReturnStatement(expression); ReturnStatement* stmt = new(zone_) ReturnStatement(expression, pos);
VISIT_AND_RETURN(ReturnStatement, stmt) VISIT_AND_RETURN(ReturnStatement, stmt)
} }
WithStatement* NewWithStatement(Scope* scope, WithStatement* NewWithStatement(Scope* scope,
Expression* expression, Expression* expression,
Statement* statement) { Statement* statement,
int pos) {
WithStatement* stmt = new(zone_) WithStatement( WithStatement* stmt = new(zone_) WithStatement(
scope, expression, statement); scope, expression, statement, pos);
VISIT_AND_RETURN(WithStatement, stmt) VISIT_AND_RETURN(WithStatement, stmt)
} }
IfStatement* NewIfStatement(Expression* condition, IfStatement* NewIfStatement(Expression* condition,
Statement* then_statement, Statement* then_statement,
Statement* else_statement) { Statement* else_statement,
int pos) {
IfStatement* stmt = new(zone_) IfStatement( IfStatement* stmt = new(zone_) IfStatement(
isolate_, condition, then_statement, else_statement); isolate_, condition, then_statement, else_statement, pos);
VISIT_AND_RETURN(IfStatement, stmt) VISIT_AND_RETURN(IfStatement, stmt)
} }
...@@ -3026,36 +3031,38 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -3026,36 +3031,38 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
Block* try_block, Block* try_block,
Scope* scope, Scope* scope,
Variable* variable, Variable* variable,
Block* catch_block) { Block* catch_block,
int pos) {
TryCatchStatement* stmt = new(zone_) TryCatchStatement( TryCatchStatement* stmt = new(zone_) TryCatchStatement(
index, try_block, scope, variable, catch_block); index, try_block, scope, variable, catch_block, pos);
VISIT_AND_RETURN(TryCatchStatement, stmt) VISIT_AND_RETURN(TryCatchStatement, stmt)
} }
TryFinallyStatement* NewTryFinallyStatement(int index, TryFinallyStatement* NewTryFinallyStatement(int index,
Block* try_block, Block* try_block,
Block* finally_block) { Block* finally_block,
int pos) {
TryFinallyStatement* stmt = TryFinallyStatement* stmt =
new(zone_) TryFinallyStatement(index, try_block, finally_block); new(zone_) TryFinallyStatement(index, try_block, finally_block, pos);
VISIT_AND_RETURN(TryFinallyStatement, stmt) VISIT_AND_RETURN(TryFinallyStatement, stmt)
} }
DebuggerStatement* NewDebuggerStatement() { DebuggerStatement* NewDebuggerStatement(int pos) {
DebuggerStatement* stmt = new(zone_) DebuggerStatement(); DebuggerStatement* stmt = new(zone_) DebuggerStatement(pos);
VISIT_AND_RETURN(DebuggerStatement, stmt) VISIT_AND_RETURN(DebuggerStatement, stmt)
} }
EmptyStatement* NewEmptyStatement() { EmptyStatement* NewEmptyStatement(int pos) {
return new(zone_) EmptyStatement(); return new(zone_) EmptyStatement(pos);
} }
Literal* NewLiteral(Handle<Object> handle) { Literal* NewLiteral(Handle<Object> handle, int pos) {
Literal* lit = new(zone_) Literal(isolate_, handle); Literal* lit = new(zone_) Literal(isolate_, handle, pos);
VISIT_AND_RETURN(Literal, lit) VISIT_AND_RETURN(Literal, lit)
} }
Literal* NewNumberLiteral(double number) { Literal* NewNumberLiteral(double number, int pos) {
return NewLiteral(isolate_->factory()->NewNumber(number, TENURED)); return NewLiteral(isolate_->factory()->NewNumber(number, TENURED), pos);
} }
ObjectLiteral* NewObjectLiteral( ObjectLiteral* NewObjectLiteral(
...@@ -3066,26 +3073,29 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -3066,26 +3073,29 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
bool fast_elements, bool fast_elements,
int depth, int depth,
bool may_store_doubles, bool may_store_doubles,
bool has_function) { bool has_function,
int pos) {
ObjectLiteral* lit = new(zone_) ObjectLiteral( ObjectLiteral* lit = new(zone_) ObjectLiteral(
isolate_, constant_properties, properties, literal_index, isolate_, constant_properties, properties, literal_index,
is_simple, fast_elements, depth, may_store_doubles, has_function); is_simple, fast_elements, depth, may_store_doubles, has_function, pos);
VISIT_AND_RETURN(ObjectLiteral, lit) VISIT_AND_RETURN(ObjectLiteral, lit)
} }
ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter, ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter,
FunctionLiteral* value) { FunctionLiteral* value,
int pos) {
ObjectLiteral::Property* prop = ObjectLiteral::Property* prop =
new(zone_) ObjectLiteral::Property(is_getter, value); new(zone_) ObjectLiteral::Property(is_getter, value);
prop->set_key(NewLiteral(value->name())); prop->set_key(NewLiteral(value->name(), pos));
return prop; // Not an AST node, will not be visited. return prop; // Not an AST node, will not be visited.
} }
RegExpLiteral* NewRegExpLiteral(Handle<String> pattern, RegExpLiteral* NewRegExpLiteral(Handle<String> pattern,
Handle<String> flags, Handle<String> flags,
int literal_index) { int literal_index,
int pos) {
RegExpLiteral* lit = RegExpLiteral* lit =
new(zone_) RegExpLiteral(isolate_, pattern, flags, literal_index); new(zone_) RegExpLiteral(isolate_, pattern, flags, literal_index, pos);
VISIT_AND_RETURN(RegExpLiteral, lit); VISIT_AND_RETURN(RegExpLiteral, lit);
} }
...@@ -3093,14 +3103,17 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -3093,14 +3103,17 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
ZoneList<Expression*>* values, ZoneList<Expression*>* values,
int literal_index, int literal_index,
bool is_simple, bool is_simple,
int depth) { int depth,
int pos) {
ArrayLiteral* lit = new(zone_) ArrayLiteral( ArrayLiteral* lit = new(zone_) ArrayLiteral(
isolate_, constant_elements, values, literal_index, is_simple, depth); isolate_, constant_elements, values, literal_index, is_simple,
depth, pos);
VISIT_AND_RETURN(ArrayLiteral, lit) VISIT_AND_RETURN(ArrayLiteral, lit)
} }
VariableProxy* NewVariableProxy(Variable* var) { VariableProxy* NewVariableProxy(Variable* var,
VariableProxy* proxy = new(zone_) VariableProxy(isolate_, var); int pos = RelocInfo::kNoPosition) {
VariableProxy* proxy = new(zone_) VariableProxy(isolate_, var, pos);
VISIT_AND_RETURN(VariableProxy, proxy) VISIT_AND_RETURN(VariableProxy, proxy)
} }
...@@ -3134,9 +3147,10 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -3134,9 +3147,10 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
CallRuntime* NewCallRuntime(Handle<String> name, CallRuntime* NewCallRuntime(Handle<String> name,
const Runtime::Function* function, const Runtime::Function* function,
ZoneList<Expression*>* arguments) { ZoneList<Expression*>* arguments,
int pos) {
CallRuntime* call = CallRuntime* call =
new(zone_) CallRuntime(isolate_, name, function, arguments); new(zone_) CallRuntime(isolate_, name, function, arguments, pos);
VISIT_AND_RETURN(CallRuntime, call) VISIT_AND_RETURN(CallRuntime, call)
} }
...@@ -3179,10 +3193,11 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -3179,10 +3193,11 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
Expression* then_expression, Expression* then_expression,
Expression* else_expression, Expression* else_expression,
int then_expression_position, int then_expression_position,
int else_expression_position) { int else_expression_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,
then_expression_position, else_expression_position); then_expression_position, else_expression_position, position);
VISIT_AND_RETURN(Conditional, cond) VISIT_AND_RETURN(Conditional, cond)
} }
...@@ -3222,12 +3237,13 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -3222,12 +3237,13 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
FunctionLiteral::FunctionType function_type, FunctionLiteral::FunctionType function_type,
FunctionLiteral::IsFunctionFlag is_function, FunctionLiteral::IsFunctionFlag is_function,
FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionLiteral::IsParenthesizedFlag is_parenthesized,
FunctionLiteral::IsGeneratorFlag is_generator) { FunctionLiteral::IsGeneratorFlag is_generator,
int position) {
FunctionLiteral* lit = new(zone_) FunctionLiteral( FunctionLiteral* lit = new(zone_) FunctionLiteral(
isolate_, name, scope, body, isolate_, name, scope, body,
materialized_literal_count, expected_property_count, handler_count, materialized_literal_count, expected_property_count, handler_count,
parameter_count, function_type, has_duplicate_parameters, is_function, parameter_count, function_type, has_duplicate_parameters, is_function,
is_parenthesized, is_generator); is_parenthesized, is_generator, position);
// Top-level literal doesn't count for the AST's properties. // Top-level literal doesn't count for the AST's properties.
if (is_function == FunctionLiteral::kIsFunction) { if (is_function == FunctionLiteral::kIsFunction) {
visitor_.VisitFunctionLiteral(lit); visitor_.VisitFunctionLiteral(lit);
...@@ -3236,14 +3252,15 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED { ...@@ -3236,14 +3252,15 @@ class AstNodeFactory V8_FINAL BASE_EMBEDDED {
} }
NativeFunctionLiteral* NewNativeFunctionLiteral(Handle<String> name, NativeFunctionLiteral* NewNativeFunctionLiteral(Handle<String> name,
v8::Extension* extension) { v8::Extension* extension,
int pos) {
NativeFunctionLiteral* lit = NativeFunctionLiteral* lit =
new(zone_) NativeFunctionLiteral(isolate_, name, extension); new(zone_) NativeFunctionLiteral(isolate_, name, extension, pos);
VISIT_AND_RETURN(NativeFunctionLiteral, lit) VISIT_AND_RETURN(NativeFunctionLiteral, lit)
} }
ThisFunction* NewThisFunction() { ThisFunction* NewThisFunction(int pos) {
ThisFunction* fun = new(zone_) ThisFunction(isolate_); ThisFunction* fun = new(zone_) ThisFunction(isolate_, pos);
VISIT_AND_RETURN(ThisFunction, fun) VISIT_AND_RETURN(ThisFunction, fun)
} }
......
...@@ -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
} }
......
...@@ -652,10 +652,10 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, ...@@ -652,10 +652,10 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
top_scope_->SetLanguageMode(info->language_mode()); top_scope_->SetLanguageMode(info->language_mode());
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
bool ok = true; bool ok = true;
int beg_loc = scanner().location().beg_pos; int beg_pos = scanner().location().beg_pos;
ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok);
if (ok && !top_scope_->is_classic_mode()) { if (ok && !top_scope_->is_classic_mode()) {
CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); CheckOctalLiteral(beg_pos, scanner().location().end_pos, &ok);
} }
if (ok && is_extended_mode()) { if (ok && is_extended_mode()) {
...@@ -685,7 +685,8 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, ...@@ -685,7 +685,8 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::ANONYMOUS_EXPRESSION,
FunctionLiteral::kGlobalOrEval, FunctionLiteral::kGlobalOrEval,
FunctionLiteral::kNotParenthesized, FunctionLiteral::kNotParenthesized,
FunctionLiteral::kNotGenerator); FunctionLiteral::kNotGenerator,
0);
result->set_ast_properties(factory()->visitor()->ast_properties()); result->set_ast_properties(factory()->visitor()->ast_properties());
result->set_dont_optimize_reason( result->set_dont_optimize_reason(
factory()->visitor()->dont_optimize_reason()); factory()->visitor()->dont_optimize_reason());
...@@ -984,6 +985,7 @@ Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { ...@@ -984,6 +985,7 @@ Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) {
// ModuleDeclaration: // ModuleDeclaration:
// 'module' Identifier Module // 'module' Identifier Module
int pos = peek_position();
Handle<String> name = ParseIdentifier(CHECK_OK); Handle<String> name = ParseIdentifier(CHECK_OK);
#ifdef DEBUG #ifdef DEBUG
...@@ -994,7 +996,7 @@ Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { ...@@ -994,7 +996,7 @@ Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) {
Module* module = ParseModule(CHECK_OK); Module* module = ParseModule(CHECK_OK);
VariableProxy* proxy = NewUnresolved(name, MODULE, module->interface()); VariableProxy* proxy = NewUnresolved(name, MODULE, module->interface());
Declaration* declaration = Declaration* declaration =
factory()->NewModuleDeclaration(proxy, module, top_scope_); factory()->NewModuleDeclaration(proxy, module, top_scope_, pos);
Declare(declaration, true, CHECK_OK); Declare(declaration, true, CHECK_OK);
#ifdef DEBUG #ifdef DEBUG
...@@ -1009,9 +1011,9 @@ Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { ...@@ -1009,9 +1011,9 @@ Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) {
if (names) names->Add(name, zone()); if (names) names->Add(name, zone());
if (module->body() == NULL) if (module->body() == NULL)
return factory()->NewEmptyStatement(); return factory()->NewEmptyStatement(pos);
else else
return factory()->NewModuleStatement(proxy, module->body()); return factory()->NewModuleStatement(proxy, module->body(), pos);
} }
...@@ -1046,8 +1048,9 @@ Module* Parser::ParseModuleLiteral(bool* ok) { ...@@ -1046,8 +1048,9 @@ Module* Parser::ParseModuleLiteral(bool* ok) {
// Module: // Module:
// '{' ModuleElement '}' // '{' ModuleElement '}'
int pos = peek_position();
// Construct block expecting 16 statements. // Construct block expecting 16 statements.
Block* body = factory()->NewBlock(NULL, 16, false); Block* body = factory()->NewBlock(NULL, 16, false, RelocInfo::kNoPosition);
#ifdef DEBUG #ifdef DEBUG
if (FLAG_print_interface_details) PrintF("# Literal "); if (FLAG_print_interface_details) PrintF("# Literal ");
#endif #endif
...@@ -1092,7 +1095,7 @@ Module* Parser::ParseModuleLiteral(bool* ok) { ...@@ -1092,7 +1095,7 @@ Module* Parser::ParseModuleLiteral(bool* ok) {
ASSERT(*ok); ASSERT(*ok);
interface->Freeze(ok); interface->Freeze(ok);
ASSERT(*ok); ASSERT(*ok);
return factory()->NewModuleLiteral(body, interface); return factory()->NewModuleLiteral(body, interface, pos);
} }
...@@ -1101,6 +1104,7 @@ Module* Parser::ParseModulePath(bool* ok) { ...@@ -1101,6 +1104,7 @@ Module* Parser::ParseModulePath(bool* ok) {
// Identifier // Identifier
// ModulePath '.' Identifier // ModulePath '.' Identifier
int pos = peek_position();
Module* result = ParseModuleVariable(CHECK_OK); Module* result = ParseModuleVariable(CHECK_OK);
while (Check(Token::PERIOD)) { while (Check(Token::PERIOD)) {
Handle<String> name = ParseIdentifierName(CHECK_OK); Handle<String> name = ParseIdentifierName(CHECK_OK);
...@@ -1108,7 +1112,7 @@ Module* Parser::ParseModulePath(bool* ok) { ...@@ -1108,7 +1112,7 @@ Module* Parser::ParseModulePath(bool* ok) {
if (FLAG_print_interface_details) if (FLAG_print_interface_details)
PrintF("# Path .%s ", name->ToAsciiArray()); PrintF("# Path .%s ", name->ToAsciiArray());
#endif #endif
Module* member = factory()->NewModulePath(result, name); Module* member = factory()->NewModulePath(result, name, pos);
result->interface()->Add(name, member->interface(), zone(), ok); result->interface()->Add(name, member->interface(), zone(), ok);
if (!*ok) { if (!*ok) {
#ifdef DEBUG #ifdef DEBUG
...@@ -1134,6 +1138,7 @@ Module* Parser::ParseModuleVariable(bool* ok) { ...@@ -1134,6 +1138,7 @@ Module* Parser::ParseModuleVariable(bool* ok) {
// ModulePath: // ModulePath:
// Identifier // Identifier
int pos = peek_position();
Handle<String> name = ParseIdentifier(CHECK_OK); Handle<String> name = ParseIdentifier(CHECK_OK);
#ifdef DEBUG #ifdef DEBUG
if (FLAG_print_interface_details) if (FLAG_print_interface_details)
...@@ -1143,7 +1148,7 @@ Module* Parser::ParseModuleVariable(bool* ok) { ...@@ -1143,7 +1148,7 @@ Module* Parser::ParseModuleVariable(bool* ok) {
factory(), name, Interface::NewModule(zone()), factory(), name, Interface::NewModule(zone()),
scanner().location().beg_pos); scanner().location().beg_pos);
return factory()->NewModuleVariable(proxy); return factory()->NewModuleVariable(proxy, pos);
} }
...@@ -1151,6 +1156,7 @@ Module* Parser::ParseModuleUrl(bool* ok) { ...@@ -1151,6 +1156,7 @@ Module* Parser::ParseModuleUrl(bool* ok) {
// Module: // Module:
// String // String
int pos = peek_position();
Expect(Token::STRING, CHECK_OK); Expect(Token::STRING, CHECK_OK);
Handle<String> symbol = GetSymbol(); Handle<String> symbol = GetSymbol();
...@@ -1163,10 +1169,10 @@ Module* Parser::ParseModuleUrl(bool* ok) { ...@@ -1163,10 +1169,10 @@ Module* Parser::ParseModuleUrl(bool* ok) {
// Create an empty literal as long as the feature isn't finished. // Create an empty literal as long as the feature isn't finished.
USE(symbol); USE(symbol);
Scope* scope = NewScope(top_scope_, MODULE_SCOPE); Scope* scope = NewScope(top_scope_, MODULE_SCOPE);
Block* body = factory()->NewBlock(NULL, 1, false); Block* body = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition);
body->set_scope(scope); body->set_scope(scope);
Interface* interface = scope->interface(); Interface* interface = scope->interface();
Module* result = factory()->NewModuleLiteral(body, interface); Module* result = factory()->NewModuleLiteral(body, interface, pos);
interface->Freeze(ok); interface->Freeze(ok);
ASSERT(*ok); ASSERT(*ok);
interface->Unify(scope->interface(), zone(), ok); interface->Unify(scope->interface(), zone(), ok);
...@@ -1194,6 +1200,7 @@ Block* Parser::ParseImportDeclaration(bool* ok) { ...@@ -1194,6 +1200,7 @@ Block* Parser::ParseImportDeclaration(bool* ok) {
// //
// TODO(ES6): implement destructuring ImportSpecifiers // TODO(ES6): implement destructuring ImportSpecifiers
int pos = peek_position();
Expect(Token::IMPORT, CHECK_OK); Expect(Token::IMPORT, CHECK_OK);
ZoneStringList names(1, zone()); ZoneStringList names(1, zone());
...@@ -1211,7 +1218,7 @@ Block* Parser::ParseImportDeclaration(bool* ok) { ...@@ -1211,7 +1218,7 @@ Block* Parser::ParseImportDeclaration(bool* ok) {
// Generate a separate declaration for each identifier. // Generate a separate declaration for each identifier.
// TODO(ES6): once we implement destructuring, make that one declaration. // TODO(ES6): once we implement destructuring, make that one declaration.
Block* block = factory()->NewBlock(NULL, 1, true); Block* block = factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition);
for (int i = 0; i < names.length(); ++i) { for (int i = 0; i < names.length(); ++i) {
#ifdef DEBUG #ifdef DEBUG
if (FLAG_print_interface_details) if (FLAG_print_interface_details)
...@@ -1232,7 +1239,7 @@ Block* Parser::ParseImportDeclaration(bool* ok) { ...@@ -1232,7 +1239,7 @@ Block* Parser::ParseImportDeclaration(bool* ok) {
} }
VariableProxy* proxy = NewUnresolved(names[i], LET, interface); VariableProxy* proxy = NewUnresolved(names[i], LET, interface);
Declaration* declaration = Declaration* declaration =
factory()->NewImportDeclaration(proxy, module, top_scope_); factory()->NewImportDeclaration(proxy, module, top_scope_, pos);
Declare(declaration, true, CHECK_OK); Declare(declaration, true, CHECK_OK);
} }
...@@ -1256,6 +1263,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { ...@@ -1256,6 +1263,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
ZoneStringList names(1, zone()); ZoneStringList names(1, zone());
switch (peek()) { switch (peek()) {
case Token::IDENTIFIER: { case Token::IDENTIFIER: {
int pos = position();
Handle<String> name = ParseIdentifier(CHECK_OK); Handle<String> name = ParseIdentifier(CHECK_OK);
// Handle 'module' as a context-sensitive keyword. // Handle 'module' as a context-sensitive keyword.
if (!name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("module"))) { if (!name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("module"))) {
...@@ -1266,7 +1274,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { ...@@ -1266,7 +1274,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
names.Add(name, zone()); names.Add(name, zone());
} }
ExpectSemicolon(CHECK_OK); ExpectSemicolon(CHECK_OK);
result = factory()->NewEmptyStatement(); result = factory()->NewEmptyStatement(pos);
} else { } else {
result = ParseModuleDeclaration(&names, CHECK_OK); result = ParseModuleDeclaration(&names, CHECK_OK);
} }
...@@ -1305,7 +1313,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) { ...@@ -1305,7 +1313,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
// TODO(rossberg): Rethink whether we actually need to store export // TODO(rossberg): Rethink whether we actually need to store export
// declarations (for compilation?). // declarations (for compilation?).
// ExportDeclaration* declaration = // ExportDeclaration* declaration =
// factory()->NewExportDeclaration(proxy, top_scope_); // factory()->NewExportDeclaration(proxy, top_scope_, position);
// top_scope_->AddDeclaration(declaration); // top_scope_->AddDeclaration(declaration);
} }
...@@ -1363,10 +1371,6 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) { ...@@ -1363,10 +1371,6 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) {
// labels can be simply ignored in all other cases; except for // labels can be simply ignored in all other cases; except for
// trivial labeled break statements 'label: break label' which is // trivial labeled break statements 'label: break label' which is
// parsed into an empty statement. // parsed into an empty statement.
// Keep the source position of the statement
int statement_pos = scanner().peek_location().beg_pos;
Statement* stmt = NULL;
switch (peek()) { switch (peek()) {
case Token::LBRACE: case Token::LBRACE:
return ParseBlock(labels, ok); return ParseBlock(labels, ok);
...@@ -1374,52 +1378,41 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) { ...@@ -1374,52 +1378,41 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) {
case Token::CONST: // fall through case Token::CONST: // fall through
case Token::LET: case Token::LET:
case Token::VAR: case Token::VAR:
stmt = ParseVariableStatement(kStatement, NULL, ok); return ParseVariableStatement(kStatement, NULL, ok);
break;
case Token::SEMICOLON: case Token::SEMICOLON:
Next(); Next();
return factory()->NewEmptyStatement(); return factory()->NewEmptyStatement(RelocInfo::kNoPosition);
case Token::IF: case Token::IF:
stmt = ParseIfStatement(labels, ok); return ParseIfStatement(labels, ok);
break;
case Token::DO: case Token::DO:
stmt = ParseDoWhileStatement(labels, ok); return ParseDoWhileStatement(labels, ok);
break;
case Token::WHILE: case Token::WHILE:
stmt = ParseWhileStatement(labels, ok); return ParseWhileStatement(labels, ok);
break;
case Token::FOR: case Token::FOR:
stmt = ParseForStatement(labels, ok); return ParseForStatement(labels, ok);
break;
case Token::CONTINUE: case Token::CONTINUE:
stmt = ParseContinueStatement(ok); return ParseContinueStatement(ok);
break;
case Token::BREAK: case Token::BREAK:
stmt = ParseBreakStatement(labels, ok); return ParseBreakStatement(labels, ok);
break;
case Token::RETURN: case Token::RETURN:
stmt = ParseReturnStatement(ok); return ParseReturnStatement(ok);
break;
case Token::WITH: case Token::WITH:
stmt = ParseWithStatement(labels, ok); return ParseWithStatement(labels, ok);
break;
case Token::SWITCH: case Token::SWITCH:
stmt = ParseSwitchStatement(labels, ok); return ParseSwitchStatement(labels, ok);
break;
case Token::THROW: case Token::THROW:
stmt = ParseThrowStatement(ok); return ParseThrowStatement(ok);
break;
case Token::TRY: { case Token::TRY: {
// NOTE: It is somewhat complicated to have labels on // NOTE: It is somewhat complicated to have labels on
...@@ -1427,12 +1420,10 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) { ...@@ -1427,12 +1420,10 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) {
// one must take great care not to treat it as a // one must take great care not to treat it as a
// fall-through. It is much easier just to wrap the entire // fall-through. It is much easier just to wrap the entire
// try-statement in a statement block and put the labels there // try-statement in a statement block and put the labels there
Block* result = factory()->NewBlock(labels, 1, false); Block* result =
factory()->NewBlock(labels, 1, false, RelocInfo::kNoPosition);
Target target(&this->target_stack_, result); Target target(&this->target_stack_, result);
TryStatement* statement = ParseTryStatement(CHECK_OK); TryStatement* statement = ParseTryStatement(CHECK_OK);
if (statement) {
statement->set_statement_pos(statement_pos);
}
if (result) result->AddStatement(statement, zone()); if (result) result->AddStatement(statement, zone());
return result; return result;
} }
...@@ -1459,16 +1450,11 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) { ...@@ -1459,16 +1450,11 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) {
} }
case Token::DEBUGGER: case Token::DEBUGGER:
stmt = ParseDebuggerStatement(ok); return ParseDebuggerStatement(ok);
break;
default: default:
stmt = ParseExpressionOrLabelledStatement(labels, ok); return ParseExpressionOrLabelledStatement(labels, ok);
} }
// Store the source position of the statement
if (stmt != NULL) stmt->set_statement_pos(statement_pos);
return stmt;
} }
...@@ -1480,7 +1466,7 @@ VariableProxy* Parser::NewUnresolved( ...@@ -1480,7 +1466,7 @@ VariableProxy* Parser::NewUnresolved(
// Let/const variables in harmony mode are always added to the immediately // Let/const variables in harmony mode are always added to the immediately
// enclosing scope. // enclosing scope.
return DeclarationScope(mode)->NewUnresolved( return DeclarationScope(mode)->NewUnresolved(
factory(), name, interface, scanner().location().beg_pos); factory(), name, interface, position());
} }
...@@ -1647,6 +1633,7 @@ void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { ...@@ -1647,6 +1633,7 @@ void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) {
// declaration is resolved by looking up the function through a // declaration is resolved by looking up the function through a
// callback provided by the extension. // callback provided by the extension.
Statement* Parser::ParseNativeDeclaration(bool* ok) { Statement* Parser::ParseNativeDeclaration(bool* ok) {
int pos = peek_position();
Expect(Token::FUNCTION, CHECK_OK); Expect(Token::FUNCTION, CHECK_OK);
Handle<String> name = ParseIdentifier(CHECK_OK); Handle<String> name = ParseIdentifier(CHECK_OK);
Expect(Token::LPAREN, CHECK_OK); Expect(Token::LPAREN, CHECK_OK);
...@@ -1672,13 +1659,14 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) { ...@@ -1672,13 +1659,14 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) {
// other functions are set up when entering the surrounding scope. // other functions are set up when entering the surrounding scope.
VariableProxy* proxy = NewUnresolved(name, VAR, Interface::NewValue()); VariableProxy* proxy = NewUnresolved(name, VAR, Interface::NewValue());
Declaration* declaration = Declaration* declaration =
factory()->NewVariableDeclaration(proxy, VAR, top_scope_); factory()->NewVariableDeclaration(proxy, VAR, top_scope_, pos);
Declare(declaration, true, CHECK_OK); Declare(declaration, true, CHECK_OK);
NativeFunctionLiteral* lit = NativeFunctionLiteral* lit = factory()->NewNativeFunctionLiteral(
factory()->NewNativeFunctionLiteral(name, extension_); name, extension_, RelocInfo::kNoPosition);
return factory()->NewExpressionStatement( return factory()->NewExpressionStatement(
factory()->NewAssignment( factory()->NewAssignment(
Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition)); Token::INIT_VAR, proxy, lit, RelocInfo::kNoPosition),
pos);
} }
...@@ -1689,7 +1677,7 @@ Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) { ...@@ -1689,7 +1677,7 @@ Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) {
// 'function' '*' Identifier '(' FormalParameterListopt ')' // 'function' '*' Identifier '(' FormalParameterListopt ')'
// '{' FunctionBody '}' // '{' FunctionBody '}'
Expect(Token::FUNCTION, CHECK_OK); Expect(Token::FUNCTION, CHECK_OK);
int function_token_position = scanner().location().beg_pos; int pos = position();
bool is_generator = allow_generators() && Check(Token::MUL); bool is_generator = allow_generators() && Check(Token::MUL);
bool is_strict_reserved = false; bool is_strict_reserved = false;
Handle<String> name = ParseIdentifierOrStrictReservedWord( Handle<String> name = ParseIdentifierOrStrictReservedWord(
...@@ -1697,7 +1685,7 @@ Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) { ...@@ -1697,7 +1685,7 @@ Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) {
FunctionLiteral* fun = ParseFunctionLiteral(name, FunctionLiteral* fun = ParseFunctionLiteral(name,
is_strict_reserved, is_strict_reserved,
is_generator, is_generator,
function_token_position, pos,
FunctionLiteral::DECLARATION, FunctionLiteral::DECLARATION,
CHECK_OK); CHECK_OK);
// Even if we're not at the top-level of the global or a function // Even if we're not at the top-level of the global or a function
...@@ -1709,10 +1697,10 @@ Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) { ...@@ -1709,10 +1697,10 @@ Statement* Parser::ParseFunctionDeclaration(ZoneStringList* names, bool* ok) {
is_extended_mode() && !top_scope_->is_global_scope() ? LET : VAR; is_extended_mode() && !top_scope_->is_global_scope() ? LET : VAR;
VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue()); VariableProxy* proxy = NewUnresolved(name, mode, Interface::NewValue());
Declaration* declaration = Declaration* declaration =
factory()->NewFunctionDeclaration(proxy, mode, fun, top_scope_); factory()->NewFunctionDeclaration(proxy, mode, fun, top_scope_, pos);
Declare(declaration, true, CHECK_OK); Declare(declaration, true, CHECK_OK);
if (names) names->Add(name, zone()); if (names) names->Add(name, zone());
return factory()->NewEmptyStatement(); return factory()->NewEmptyStatement(RelocInfo::kNoPosition);
} }
...@@ -1726,7 +1714,8 @@ Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { ...@@ -1726,7 +1714,8 @@ Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) {
// (ECMA-262, 3rd, 12.2) // (ECMA-262, 3rd, 12.2)
// //
// Construct block expecting 16 statements. // Construct block expecting 16 statements.
Block* result = factory()->NewBlock(labels, 16, false); Block* result =
factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition);
Target target(&this->target_stack_, result); Target target(&this->target_stack_, result);
Expect(Token::LBRACE, CHECK_OK); Expect(Token::LBRACE, CHECK_OK);
while (peek() != Token::RBRACE) { while (peek() != Token::RBRACE) {
...@@ -1747,7 +1736,8 @@ Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { ...@@ -1747,7 +1736,8 @@ Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) {
// '{' BlockElement* '}' // '{' BlockElement* '}'
// Construct block expecting 16 statements. // Construct block expecting 16 statements.
Block* body = factory()->NewBlock(labels, 16, false); Block* body =
factory()->NewBlock(labels, 16, false, RelocInfo::kNoPosition);
Scope* block_scope = NewScope(top_scope_, BLOCK_SCOPE); Scope* block_scope = NewScope(top_scope_, BLOCK_SCOPE);
// Parse the statements and collect escaping labels. // Parse the statements and collect escaping labels.
...@@ -1817,6 +1807,8 @@ Block* Parser::ParseVariableDeclarations( ...@@ -1817,6 +1807,8 @@ Block* Parser::ParseVariableDeclarations(
// TODO(ES6): // TODO(ES6):
// ConstBinding :: // ConstBinding ::
// BindingPattern '=' AssignmentExpression // BindingPattern '=' AssignmentExpression
int pos = peek_position();
VariableMode mode = VAR; VariableMode mode = VAR;
// True if the binding needs initialization. 'let' and 'const' declared // True if the binding needs initialization. 'let' and 'const' declared
// bindings are created uninitialized by their declaration nodes and // bindings are created uninitialized by their declaration nodes and
...@@ -1902,7 +1894,7 @@ Block* Parser::ParseVariableDeclarations( ...@@ -1902,7 +1894,7 @@ Block* Parser::ParseVariableDeclarations(
// is inside an initializer block, it is ignored. // is inside an initializer block, it is ignored.
// //
// Create new block with one expected declaration. // Create new block with one expected declaration.
Block* block = factory()->NewBlock(NULL, 1, true); Block* block = factory()->NewBlock(NULL, 1, true, pos);
int nvars = 0; // the number of variables declared int nvars = 0; // the number of variables declared
Handle<String> name; Handle<String> name;
do { do {
...@@ -1939,7 +1931,7 @@ Block* Parser::ParseVariableDeclarations( ...@@ -1939,7 +1931,7 @@ Block* Parser::ParseVariableDeclarations(
is_const ? Interface::NewConst() : Interface::NewValue(); is_const ? Interface::NewConst() : Interface::NewValue();
VariableProxy* proxy = NewUnresolved(name, mode, interface); VariableProxy* proxy = NewUnresolved(name, mode, interface);
Declaration* declaration = Declaration* declaration =
factory()->NewVariableDeclaration(proxy, mode, top_scope_); factory()->NewVariableDeclaration(proxy, mode, top_scope_, pos);
Declare(declaration, mode != VAR, CHECK_OK); Declare(declaration, mode != VAR, CHECK_OK);
nvars++; nvars++;
if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) {
...@@ -1979,11 +1971,11 @@ Block* Parser::ParseVariableDeclarations( ...@@ -1979,11 +1971,11 @@ Block* Parser::ParseVariableDeclarations(
Scope* initialization_scope = is_const ? declaration_scope : top_scope_; Scope* initialization_scope = is_const ? declaration_scope : top_scope_;
Expression* value = NULL; Expression* value = NULL;
int position = -1; int pos = -1;
// Harmony consts have non-optional initializers. // Harmony consts have non-optional initializers.
if (peek() == Token::ASSIGN || mode == CONST_HARMONY) { if (peek() == Token::ASSIGN || mode == CONST_HARMONY) {
Expect(Token::ASSIGN, CHECK_OK); Expect(Token::ASSIGN, CHECK_OK);
position = scanner().location().beg_pos; pos = position();
value = ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); value = ParseAssignmentExpression(var_context != kForStatement, CHECK_OK);
// Don't infer if it is "a = function(){...}();"-like expression. // Don't infer if it is "a = function(){...}();"-like expression.
if (fni_ != NULL && if (fni_ != NULL &&
...@@ -1998,12 +1990,12 @@ Block* Parser::ParseVariableDeclarations( ...@@ -1998,12 +1990,12 @@ Block* Parser::ParseVariableDeclarations(
// Record the end position of the initializer. // Record the end position of the initializer.
if (proxy->var() != NULL) { if (proxy->var() != NULL) {
proxy->var()->set_initializer_position(scanner().location().end_pos); proxy->var()->set_initializer_position(position());
} }
// Make sure that 'const x' and 'let x' initialize 'x' to undefined. // Make sure that 'const x' and 'let x' initialize 'x' to undefined.
if (value == NULL && needs_init) { if (value == NULL && needs_init) {
value = GetLiteralUndefined(); value = GetLiteralUndefined(position());
} }
// Global variable declarations must be compiled in a specific // Global variable declarations must be compiled in a specific
...@@ -2031,7 +2023,7 @@ Block* Parser::ParseVariableDeclarations( ...@@ -2031,7 +2023,7 @@ Block* Parser::ParseVariableDeclarations(
ZoneList<Expression*>* arguments = ZoneList<Expression*>* arguments =
new(zone()) ZoneList<Expression*>(3, zone()); new(zone()) ZoneList<Expression*>(3, zone());
// We have at least 1 parameter. // We have at least 1 parameter.
arguments->Add(factory()->NewLiteral(name), zone()); arguments->Add(factory()->NewLiteral(name, pos), zone());
CallRuntime* initialize; CallRuntime* initialize;
if (is_const) { if (is_const) {
...@@ -2045,12 +2037,12 @@ Block* Parser::ParseVariableDeclarations( ...@@ -2045,12 +2037,12 @@ Block* Parser::ParseVariableDeclarations(
initialize = factory()->NewCallRuntime( initialize = factory()->NewCallRuntime(
isolate()->factory()->InitializeConstGlobal_string(), isolate()->factory()->InitializeConstGlobal_string(),
Runtime::FunctionForId(Runtime::kInitializeConstGlobal), Runtime::FunctionForId(Runtime::kInitializeConstGlobal),
arguments); arguments, pos);
} else { } else {
// Add strict mode. // Add strict mode.
// We may want to pass singleton to avoid Literal allocations. // We may want to pass singleton to avoid Literal allocations.
LanguageMode language_mode = initialization_scope->language_mode(); LanguageMode language_mode = initialization_scope->language_mode();
arguments->Add(factory()->NewNumberLiteral(language_mode), zone()); arguments->Add(factory()->NewNumberLiteral(language_mode, pos), zone());
// Be careful not to assign a value to the global variable if // Be careful not to assign a value to the global variable if
// we're in a with. The initialization value should not // we're in a with. The initialization value should not
...@@ -2068,10 +2060,11 @@ Block* Parser::ParseVariableDeclarations( ...@@ -2068,10 +2060,11 @@ Block* Parser::ParseVariableDeclarations(
initialize = factory()->NewCallRuntime( initialize = factory()->NewCallRuntime(
isolate()->factory()->InitializeVarGlobal_string(), isolate()->factory()->InitializeVarGlobal_string(),
Runtime::FunctionForId(Runtime::kInitializeVarGlobal), Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
arguments); arguments, pos);
} }
block->AddStatement(factory()->NewExpressionStatement(initialize), block->AddStatement(
factory()->NewExpressionStatement(initialize, RelocInfo::kNoPosition),
zone()); zone());
} else if (needs_init) { } else if (needs_init) {
// Constant initializations always assign to the declared constant which // Constant initializations always assign to the declared constant which
...@@ -2085,8 +2078,9 @@ Block* Parser::ParseVariableDeclarations( ...@@ -2085,8 +2078,9 @@ Block* Parser::ParseVariableDeclarations(
ASSERT(proxy->var() != NULL); ASSERT(proxy->var() != NULL);
ASSERT(value != NULL); ASSERT(value != NULL);
Assignment* assignment = Assignment* assignment =
factory()->NewAssignment(init_op, proxy, value, position); factory()->NewAssignment(init_op, proxy, value, pos);
block->AddStatement(factory()->NewExpressionStatement(assignment), block->AddStatement(
factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition),
zone()); zone());
value = NULL; value = NULL;
} }
...@@ -2101,8 +2095,9 @@ Block* Parser::ParseVariableDeclarations( ...@@ -2101,8 +2095,9 @@ Block* Parser::ParseVariableDeclarations(
VariableProxy* proxy = VariableProxy* proxy =
initialization_scope->NewUnresolved(factory(), name, interface); initialization_scope->NewUnresolved(factory(), name, interface);
Assignment* assignment = Assignment* assignment =
factory()->NewAssignment(init_op, proxy, value, position); factory()->NewAssignment(init_op, proxy, value, pos);
block->AddStatement(factory()->NewExpressionStatement(assignment), block->AddStatement(
factory()->NewExpressionStatement(assignment, RelocInfo::kNoPosition),
zone()); zone());
} }
...@@ -2135,6 +2130,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, ...@@ -2135,6 +2130,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels,
// ExpressionStatement | LabelledStatement :: // ExpressionStatement | LabelledStatement ::
// Expression ';' // Expression ';'
// Identifier ':' Statement // Identifier ':' Statement
int pos = peek_position();
bool starts_with_idenfifier = peek_any_identifier(); bool starts_with_idenfifier = peek_any_identifier();
Expression* expr = ParseExpression(true, CHECK_OK); Expression* expr = ParseExpression(true, CHECK_OK);
if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL && if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL &&
...@@ -2194,7 +2190,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, ...@@ -2194,7 +2190,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels,
scanner().literal_contains_escapes()) { scanner().literal_contains_escapes()) {
ExpectSemicolon(CHECK_OK); ExpectSemicolon(CHECK_OK);
} }
return factory()->NewExpressionStatement(expr); return factory()->NewExpressionStatement(expr, pos);
} }
...@@ -2202,6 +2198,7 @@ IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { ...@@ -2202,6 +2198,7 @@ IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) {
// IfStatement :: // IfStatement ::
// 'if' '(' Expression ')' Statement ('else' Statement)? // 'if' '(' Expression ')' Statement ('else' Statement)?
int pos = peek_position();
Expect(Token::IF, CHECK_OK); Expect(Token::IF, CHECK_OK);
Expect(Token::LPAREN, CHECK_OK); Expect(Token::LPAREN, CHECK_OK);
Expression* condition = ParseExpression(true, CHECK_OK); Expression* condition = ParseExpression(true, CHECK_OK);
...@@ -2212,9 +2209,10 @@ IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { ...@@ -2212,9 +2209,10 @@ IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) {
Next(); Next();
else_statement = ParseStatement(labels, CHECK_OK); else_statement = ParseStatement(labels, CHECK_OK);
} else { } else {
else_statement = factory()->NewEmptyStatement(); else_statement = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
} }
return factory()->NewIfStatement(condition, then_statement, else_statement); return factory()->NewIfStatement(
condition, then_statement, else_statement, pos);
} }
...@@ -2222,6 +2220,7 @@ Statement* Parser::ParseContinueStatement(bool* ok) { ...@@ -2222,6 +2220,7 @@ Statement* Parser::ParseContinueStatement(bool* ok) {
// ContinueStatement :: // ContinueStatement ::
// 'continue' Identifier? ';' // 'continue' Identifier? ';'
int pos = peek_position();
Expect(Token::CONTINUE, CHECK_OK); Expect(Token::CONTINUE, CHECK_OK);
Handle<String> label = Handle<String>::null(); Handle<String> label = Handle<String>::null();
Token::Value tok = peek(); Token::Value tok = peek();
...@@ -2244,7 +2243,7 @@ Statement* Parser::ParseContinueStatement(bool* ok) { ...@@ -2244,7 +2243,7 @@ Statement* Parser::ParseContinueStatement(bool* ok) {
return NULL; return NULL;
} }
ExpectSemicolon(CHECK_OK); ExpectSemicolon(CHECK_OK);
return factory()->NewContinueStatement(target); return factory()->NewContinueStatement(target, pos);
} }
...@@ -2252,6 +2251,7 @@ Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { ...@@ -2252,6 +2251,7 @@ Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) {
// BreakStatement :: // BreakStatement ::
// 'break' Identifier? ';' // 'break' Identifier? ';'
int pos = peek_position();
Expect(Token::BREAK, CHECK_OK); Expect(Token::BREAK, CHECK_OK);
Handle<String> label; Handle<String> label;
Token::Value tok = peek(); Token::Value tok = peek();
...@@ -2263,7 +2263,7 @@ Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { ...@@ -2263,7 +2263,7 @@ Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) {
// empty statements, e.g. 'l1: l2: l3: break l2;' // empty statements, e.g. 'l1: l2: l3: break l2;'
if (!label.is_null() && ContainsLabel(labels, label)) { if (!label.is_null() && ContainsLabel(labels, label)) {
ExpectSemicolon(CHECK_OK); ExpectSemicolon(CHECK_OK);
return factory()->NewEmptyStatement(); return factory()->NewEmptyStatement(pos);
} }
BreakableStatement* target = NULL; BreakableStatement* target = NULL;
target = LookupBreakTarget(label, CHECK_OK); target = LookupBreakTarget(label, CHECK_OK);
...@@ -2280,7 +2280,7 @@ Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { ...@@ -2280,7 +2280,7 @@ Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) {
return NULL; return NULL;
} }
ExpectSemicolon(CHECK_OK); ExpectSemicolon(CHECK_OK);
return factory()->NewBreakStatement(target); return factory()->NewBreakStatement(target, pos);
} }
...@@ -2288,10 +2288,11 @@ Statement* Parser::ParseReturnStatement(bool* ok) { ...@@ -2288,10 +2288,11 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
// ReturnStatement :: // ReturnStatement ::
// 'return' Expression? ';' // 'return' Expression? ';'
// Consume the return token. It is necessary to do the before // Consume the return token. It is necessary to do that before
// reporting any errors on it, because of the way errors are // reporting any errors on it, because of the way errors are
// reported (underlining). // reported (underlining).
Expect(Token::RETURN, CHECK_OK); Expect(Token::RETURN, CHECK_OK);
int pos = position();
Token::Value tok = peek(); Token::Value tok = peek();
Statement* result; Statement* result;
...@@ -2300,7 +2301,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) { ...@@ -2300,7 +2301,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
tok == Token::SEMICOLON || tok == Token::SEMICOLON ||
tok == Token::RBRACE || tok == Token::RBRACE ||
tok == Token::EOS) { tok == Token::EOS) {
return_value = GetLiteralUndefined(); return_value = GetLiteralUndefined(position());
} else { } else {
return_value = ParseExpression(true, CHECK_OK); return_value = ParseExpression(true, CHECK_OK);
} }
...@@ -2309,10 +2310,10 @@ Statement* Parser::ParseReturnStatement(bool* ok) { ...@@ -2309,10 +2310,10 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
Expression* generator = factory()->NewVariableProxy( Expression* generator = factory()->NewVariableProxy(
current_function_state_->generator_object_variable()); current_function_state_->generator_object_variable());
Expression* yield = factory()->NewYield( Expression* yield = factory()->NewYield(
generator, return_value, Yield::FINAL, RelocInfo::kNoPosition); generator, return_value, Yield::FINAL, pos);
result = factory()->NewExpressionStatement(yield); result = factory()->NewExpressionStatement(yield, pos);
} else { } else {
result = factory()->NewReturnStatement(return_value); result = factory()->NewReturnStatement(return_value, pos);
} }
// An ECMAScript program is considered syntactically incorrect if it // An ECMAScript program is considered syntactically incorrect if it
...@@ -2326,7 +2327,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) { ...@@ -2326,7 +2327,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
Handle<String> message = isolate()->factory()->illegal_return_string(); Handle<String> message = isolate()->factory()->illegal_return_string();
Expression* throw_error = Expression* throw_error =
NewThrowSyntaxError(message, Handle<Object>::null()); NewThrowSyntaxError(message, Handle<Object>::null());
return factory()->NewExpressionStatement(throw_error); return factory()->NewExpressionStatement(throw_error, pos);
} }
return result; return result;
} }
...@@ -2337,6 +2338,7 @@ Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { ...@@ -2337,6 +2338,7 @@ Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) {
// 'with' '(' Expression ')' Statement // 'with' '(' Expression ')' Statement
Expect(Token::WITH, CHECK_OK); Expect(Token::WITH, CHECK_OK);
int pos = position();
if (!top_scope_->is_classic_mode()) { if (!top_scope_->is_classic_mode()) {
ReportMessage("strict_mode_with", Vector<const char*>::empty()); ReportMessage("strict_mode_with", Vector<const char*>::empty());
...@@ -2356,7 +2358,7 @@ Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { ...@@ -2356,7 +2358,7 @@ Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) {
stmt = ParseStatement(labels, CHECK_OK); stmt = ParseStatement(labels, CHECK_OK);
with_scope->set_end_position(scanner().location().end_pos); with_scope->set_end_position(scanner().location().end_pos);
} }
return factory()->NewWithStatement(with_scope, expr, stmt); return factory()->NewWithStatement(with_scope, expr, stmt, pos);
} }
...@@ -2380,7 +2382,7 @@ CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) { ...@@ -2380,7 +2382,7 @@ CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) {
*default_seen_ptr = true; *default_seen_ptr = true;
} }
Expect(Token::COLON, CHECK_OK); Expect(Token::COLON, CHECK_OK);
int pos = scanner().location().beg_pos; int pos = position();
ZoneList<Statement*>* statements = ZoneList<Statement*>* statements =
new(zone()) ZoneList<Statement*>(5, zone()); new(zone()) ZoneList<Statement*>(5, zone());
while (peek() != Token::CASE && while (peek() != Token::CASE &&
...@@ -2399,7 +2401,8 @@ SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, ...@@ -2399,7 +2401,8 @@ SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels,
// SwitchStatement :: // SwitchStatement ::
// 'switch' '(' Expression ')' '{' CaseClause* '}' // 'switch' '(' Expression ')' '{' CaseClause* '}'
SwitchStatement* statement = factory()->NewSwitchStatement(labels); SwitchStatement* statement =
factory()->NewSwitchStatement(labels, peek_position());
Target target(&this->target_stack_, statement); Target target(&this->target_stack_, statement);
Expect(Token::SWITCH, CHECK_OK); Expect(Token::SWITCH, CHECK_OK);
...@@ -2426,7 +2429,7 @@ Statement* Parser::ParseThrowStatement(bool* ok) { ...@@ -2426,7 +2429,7 @@ Statement* Parser::ParseThrowStatement(bool* ok) {
// 'throw' Expression ';' // 'throw' Expression ';'
Expect(Token::THROW, CHECK_OK); Expect(Token::THROW, CHECK_OK);
int pos = scanner().location().beg_pos; int pos = position();
if (scanner().HasAnyLineTerminatorBeforeNext()) { if (scanner().HasAnyLineTerminatorBeforeNext()) {
ReportMessage("newline_after_throw", Vector<const char*>::empty()); ReportMessage("newline_after_throw", Vector<const char*>::empty());
*ok = false; *ok = false;
...@@ -2435,7 +2438,8 @@ Statement* Parser::ParseThrowStatement(bool* ok) { ...@@ -2435,7 +2438,8 @@ Statement* Parser::ParseThrowStatement(bool* ok) {
Expression* exception = ParseExpression(true, CHECK_OK); Expression* exception = ParseExpression(true, CHECK_OK);
ExpectSemicolon(CHECK_OK); ExpectSemicolon(CHECK_OK);
return factory()->NewExpressionStatement(factory()->NewThrow(exception, pos)); return factory()->NewExpressionStatement(
factory()->NewThrow(exception, pos), pos);
} }
...@@ -2452,6 +2456,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { ...@@ -2452,6 +2456,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
// 'finally' Block // 'finally' Block
Expect(Token::TRY, CHECK_OK); Expect(Token::TRY, CHECK_OK);
int pos = position();
TargetCollector try_collector(zone()); TargetCollector try_collector(zone());
Block* try_block; Block* try_block;
...@@ -2523,9 +2528,10 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { ...@@ -2523,9 +2528,10 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
ASSERT(catch_scope != NULL && catch_variable != NULL); ASSERT(catch_scope != NULL && catch_variable != NULL);
int index = current_function_state_->NextHandlerIndex(); int index = current_function_state_->NextHandlerIndex();
TryCatchStatement* statement = factory()->NewTryCatchStatement( TryCatchStatement* statement = factory()->NewTryCatchStatement(
index, try_block, catch_scope, catch_variable, catch_block); index, try_block, catch_scope, catch_variable, catch_block,
RelocInfo::kNoPosition);
statement->set_escaping_targets(try_collector.targets()); statement->set_escaping_targets(try_collector.targets());
try_block = factory()->NewBlock(NULL, 1, false); try_block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition);
try_block->AddStatement(statement, zone()); try_block->AddStatement(statement, zone());
catch_block = NULL; // Clear to indicate it's been handled. catch_block = NULL; // Clear to indicate it's been handled.
} }
...@@ -2536,11 +2542,12 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { ...@@ -2536,11 +2542,12 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
ASSERT(catch_scope != NULL && catch_variable != NULL); ASSERT(catch_scope != NULL && catch_variable != NULL);
int index = current_function_state_->NextHandlerIndex(); int index = current_function_state_->NextHandlerIndex();
result = factory()->NewTryCatchStatement( result = factory()->NewTryCatchStatement(
index, try_block, catch_scope, catch_variable, catch_block); index, try_block, catch_scope, catch_variable, catch_block, pos);
} else { } else {
ASSERT(finally_block != NULL); ASSERT(finally_block != NULL);
int index = current_function_state_->NextHandlerIndex(); int index = current_function_state_->NextHandlerIndex();
result = factory()->NewTryFinallyStatement(index, try_block, finally_block); result = factory()->NewTryFinallyStatement(
index, try_block, finally_block, pos);
// Combine the jump targets of the try block and the possible catch block. // Combine the jump targets of the try block and the possible catch block.
try_collector.targets()->AddAll(*catch_collector.targets(), zone()); try_collector.targets()->AddAll(*catch_collector.targets(), zone());
} }
...@@ -2555,7 +2562,8 @@ DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, ...@@ -2555,7 +2562,8 @@ DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels,
// DoStatement :: // DoStatement ::
// 'do' Statement 'while' '(' Expression ')' ';' // 'do' Statement 'while' '(' Expression ')' ';'
DoWhileStatement* loop = factory()->NewDoWhileStatement(labels); DoWhileStatement* loop =
factory()->NewDoWhileStatement(labels, peek_position());
Target target(&this->target_stack_, loop); Target target(&this->target_stack_, loop);
Expect(Token::DO, CHECK_OK); Expect(Token::DO, CHECK_OK);
...@@ -2563,10 +2571,7 @@ DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, ...@@ -2563,10 +2571,7 @@ 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) { if (loop != NULL) loop->set_condition_position(position());
int position = scanner().location().beg_pos;
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);
...@@ -2586,7 +2591,7 @@ WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { ...@@ -2586,7 +2591,7 @@ WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) {
// WhileStatement :: // WhileStatement ::
// 'while' '(' Expression ')' Statement // 'while' '(' Expression ')' Statement
WhileStatement* loop = factory()->NewWhileStatement(labels); WhileStatement* loop = factory()->NewWhileStatement(labels, peek_position());
Target target(&this->target_stack_, loop); Target target(&this->target_stack_, loop);
Expect(Token::WHILE, CHECK_OK); Expect(Token::WHILE, CHECK_OK);
...@@ -2645,8 +2650,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, ...@@ -2645,8 +2650,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
// var result = iterator.next(); // var result = iterator.next();
{ {
Expression* iterator_proxy = factory()->NewVariableProxy(iterator); Expression* iterator_proxy = factory()->NewVariableProxy(iterator);
Expression* next_literal = Expression* next_literal = factory()->NewLiteral(
factory()->NewLiteral(heap_factory->next_string()); heap_factory->next_string(), RelocInfo::kNoPosition);
Expression* next_property = factory()->NewProperty( Expression* next_property = factory()->NewProperty(
iterator_proxy, next_literal, RelocInfo::kNoPosition); iterator_proxy, next_literal, RelocInfo::kNoPosition);
ZoneList<Expression*>* next_arguments = ZoneList<Expression*>* next_arguments =
...@@ -2660,8 +2665,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, ...@@ -2660,8 +2665,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
// result.done // result.done
{ {
Expression* done_literal = Expression* done_literal = factory()->NewLiteral(
factory()->NewLiteral(heap_factory->done_string()); heap_factory->done_string(), RelocInfo::kNoPosition);
Expression* result_proxy = factory()->NewVariableProxy(result); Expression* result_proxy = factory()->NewVariableProxy(result);
result_done = factory()->NewProperty( result_done = factory()->NewProperty(
result_proxy, done_literal, RelocInfo::kNoPosition); result_proxy, done_literal, RelocInfo::kNoPosition);
...@@ -2669,8 +2674,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt, ...@@ -2669,8 +2674,8 @@ void Parser::InitializeForEachStatement(ForEachStatement* stmt,
// each = result.value // each = result.value
{ {
Expression* value_literal = Expression* value_literal = factory()->NewLiteral(
factory()->NewLiteral(heap_factory->value_string()); heap_factory->value_string(), RelocInfo::kNoPosition);
Expression* result_proxy = factory()->NewVariableProxy(result); Expression* result_proxy = factory()->NewVariableProxy(result);
Expression* result_value = factory()->NewProperty( Expression* result_value = factory()->NewProperty(
result_proxy, value_literal, RelocInfo::kNoPosition); result_proxy, value_literal, RelocInfo::kNoPosition);
...@@ -2690,6 +2695,7 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2690,6 +2695,7 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
// ForStatement :: // ForStatement ::
// 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
int pos = peek_position();
Statement* init = NULL; Statement* init = NULL;
// Create an in-between scope for let-bound iteration variables. // Create an in-between scope for let-bound iteration variables.
...@@ -2714,7 +2720,8 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2714,7 +2720,8 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
if (!name.is_null() && CheckInOrOf(accept_OF, &mode)) { if (!name.is_null() && CheckInOrOf(accept_OF, &mode)) {
Interface* interface = Interface* interface =
is_const ? Interface::NewConst() : Interface::NewValue(); is_const ? Interface::NewConst() : Interface::NewValue();
ForEachStatement* loop = factory()->NewForEachStatement(mode, labels); ForEachStatement* loop =
factory()->NewForEachStatement(mode, labels, pos);
Target target(&this->target_stack_, loop); Target target(&this->target_stack_, loop);
Expression* enumerable = ParseExpression(true, CHECK_OK); Expression* enumerable = ParseExpression(true, CHECK_OK);
...@@ -2724,7 +2731,8 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2724,7 +2731,8 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
top_scope_->NewUnresolved(factory(), name, interface); top_scope_->NewUnresolved(factory(), name, interface);
Statement* body = ParseStatement(NULL, CHECK_OK); Statement* body = ParseStatement(NULL, CHECK_OK);
InitializeForEachStatement(loop, each, enumerable, body); InitializeForEachStatement(loop, each, enumerable, body);
Block* result = factory()->NewBlock(NULL, 2, false); Block* result =
factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
result->AddStatement(variable_statement, zone()); result->AddStatement(variable_statement, zone());
result->AddStatement(loop, zone()); result->AddStatement(loop, zone());
top_scope_ = saved_scope; top_scope_ = saved_scope;
...@@ -2768,7 +2776,8 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2768,7 +2776,8 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
Handle<String> tempname = heap_factory->InternalizeString(tempstr); Handle<String> tempname = heap_factory->InternalizeString(tempstr);
Variable* temp = top_scope_->DeclarationScope()->NewTemporary(tempname); Variable* temp = top_scope_->DeclarationScope()->NewTemporary(tempname);
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
ForEachStatement* loop = factory()->NewForEachStatement(mode, labels); ForEachStatement* loop =
factory()->NewForEachStatement(mode, labels, pos);
Target target(&this->target_stack_, loop); Target target(&this->target_stack_, loop);
// The expression does not see the loop variable. // The expression does not see the loop variable.
...@@ -2780,11 +2789,12 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2780,11 +2789,12 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
VariableProxy* each = VariableProxy* each =
top_scope_->NewUnresolved(factory(), name, Interface::NewValue()); top_scope_->NewUnresolved(factory(), name, Interface::NewValue());
Statement* body = ParseStatement(NULL, CHECK_OK); Statement* body = ParseStatement(NULL, CHECK_OK);
Block* body_block = factory()->NewBlock(NULL, 3, false); Block* body_block =
factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition);
Assignment* assignment = factory()->NewAssignment( Assignment* assignment = factory()->NewAssignment(
Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition);
Statement* assignment_statement = Statement* assignment_statement = factory()->NewExpressionStatement(
factory()->NewExpressionStatement(assignment); assignment, RelocInfo::kNoPosition);
body_block->AddStatement(variable_statement, zone()); body_block->AddStatement(variable_statement, zone());
body_block->AddStatement(assignment_statement, zone()); body_block->AddStatement(assignment_statement, zone());
body_block->AddStatement(body, zone()); body_block->AddStatement(body, zone());
...@@ -2814,7 +2824,8 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2814,7 +2824,8 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
isolate()->factory()->invalid_lhs_in_for_in_string(); isolate()->factory()->invalid_lhs_in_for_in_string();
expression = NewThrowReferenceError(message); expression = NewThrowReferenceError(message);
} }
ForEachStatement* loop = factory()->NewForEachStatement(mode, labels); ForEachStatement* loop =
factory()->NewForEachStatement(mode, labels, pos);
Target target(&this->target_stack_, loop); Target target(&this->target_stack_, loop);
Expression* enumerable = ParseExpression(true, CHECK_OK); Expression* enumerable = ParseExpression(true, CHECK_OK);
...@@ -2830,13 +2841,14 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2830,13 +2841,14 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
return loop; return loop;
} else { } else {
init = factory()->NewExpressionStatement(expression); init = factory()->NewExpressionStatement(
expression, RelocInfo::kNoPosition);
} }
} }
} }
// Standard 'for' loop // Standard 'for' loop
ForStatement* loop = factory()->NewForStatement(labels); ForStatement* loop = factory()->NewForStatement(labels, pos);
Target target(&this->target_stack_, loop); Target target(&this->target_stack_, loop);
// Parsed initializer at this point. // Parsed initializer at this point.
...@@ -2851,7 +2863,7 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2851,7 +2863,7 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
Statement* next = NULL; Statement* next = NULL;
if (peek() != Token::RPAREN) { if (peek() != Token::RPAREN) {
Expression* exp = ParseExpression(true, CHECK_OK); Expression* exp = ParseExpression(true, CHECK_OK);
next = factory()->NewExpressionStatement(exp); next = factory()->NewExpressionStatement(exp, RelocInfo::kNoPosition);
} }
Expect(Token::RPAREN, CHECK_OK); Expect(Token::RPAREN, CHECK_OK);
...@@ -2871,7 +2883,7 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2871,7 +2883,7 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
// for (; c; n) b // for (; c; n) b
// } // }
ASSERT(init != NULL); ASSERT(init != NULL);
Block* result = factory()->NewBlock(NULL, 2, false); Block* result = factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
result->AddStatement(init, zone()); result->AddStatement(init, zone());
result->AddStatement(loop, zone()); result->AddStatement(loop, zone());
result->set_scope(for_scope); result->set_scope(for_scope);
...@@ -2893,10 +2905,9 @@ Expression* Parser::ParseExpression(bool accept_IN, bool* ok) { ...@@ -2893,10 +2905,9 @@ Expression* Parser::ParseExpression(bool accept_IN, bool* ok) {
Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK); Expression* result = ParseAssignmentExpression(accept_IN, CHECK_OK);
while (peek() == Token::COMMA) { while (peek() == Token::COMMA) {
Expect(Token::COMMA, CHECK_OK); Expect(Token::COMMA, CHECK_OK);
int position = scanner().location().beg_pos; int pos = position();
Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
result = result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos);
factory()->NewBinaryOperation(Token::COMMA, result, right, position);
} }
return result; return result;
} }
...@@ -2940,7 +2951,7 @@ Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) { ...@@ -2940,7 +2951,7 @@ Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) {
MarkAsLValue(expression); MarkAsLValue(expression);
Token::Value op = Next(); // Get assignment operator. Token::Value op = Next(); // Get assignment operator.
int pos = scanner().location().beg_pos; int pos = position();
Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
// TODO(1231235): We try to estimate the set of properties set by // TODO(1231235): We try to estimate the set of properties set by
...@@ -2984,15 +2995,14 @@ Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) { ...@@ -2984,15 +2995,14 @@ Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) {
Expression* Parser::ParseYieldExpression(bool* ok) { Expression* Parser::ParseYieldExpression(bool* ok) {
// YieldExpression :: // YieldExpression ::
// 'yield' '*'? AssignmentExpression // 'yield' '*'? AssignmentExpression
int position = scanner().peek_location().beg_pos; int pos = peek_position();
Expect(Token::YIELD, CHECK_OK); Expect(Token::YIELD, CHECK_OK);
Yield::Kind kind = Yield::Kind kind =
Check(Token::MUL) ? Yield::DELEGATING : Yield::SUSPEND; Check(Token::MUL) ? Yield::DELEGATING : Yield::SUSPEND;
Expression* generator_object = factory()->NewVariableProxy( Expression* generator_object = factory()->NewVariableProxy(
current_function_state_->generator_object_variable()); current_function_state_->generator_object_variable());
Expression* expression = ParseAssignmentExpression(false, CHECK_OK); Expression* expression = ParseAssignmentExpression(false, CHECK_OK);
Yield* yield = Yield* yield = factory()->NewYield(generator_object, expression, kind, pos);
factory()->NewYield(generator_object, expression, kind, position);
if (kind == Yield::DELEGATING) { if (kind == Yield::DELEGATING) {
yield->set_index(current_function_state_->NextHandlerIndex()); yield->set_index(current_function_state_->NextHandlerIndex());
} }
...@@ -3006,6 +3016,7 @@ Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { ...@@ -3006,6 +3016,7 @@ Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) {
// LogicalOrExpression // LogicalOrExpression
// LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
int pos = peek_position();
// We start using the binary expression parser for prec >= 4 only! // We start using the binary expression parser for prec >= 4 only!
Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK); Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK);
if (peek() != Token::CONDITIONAL) return expression; if (peek() != Token::CONDITIONAL) return expression;
...@@ -3013,13 +3024,13 @@ Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { ...@@ -3013,13 +3024,13 @@ 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 = scanner().peek_location().beg_pos; 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 = scanner().peek_location().beg_pos; 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, left_position, right_position); expression, left, right, left_position, right_position, pos);
} }
...@@ -3039,7 +3050,7 @@ Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { ...@@ -3039,7 +3050,7 @@ Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
// prec1 >= 4 // prec1 >= 4
while (Precedence(peek(), accept_IN) == prec1) { while (Precedence(peek(), accept_IN) == prec1) {
Token::Value op = Next(); Token::Value op = Next();
int position = scanner().location().beg_pos; int pos = position();
Expression* y = ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK); Expression* y = ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK);
// Compute some expressions involving only number literals. // Compute some expressions involving only number literals.
...@@ -3050,47 +3061,47 @@ Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { ...@@ -3050,47 +3061,47 @@ Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
switch (op) { switch (op) {
case Token::ADD: case Token::ADD:
x = factory()->NewNumberLiteral(x_val + y_val); x = factory()->NewNumberLiteral(x_val + y_val, pos);
continue; continue;
case Token::SUB: case Token::SUB:
x = factory()->NewNumberLiteral(x_val - y_val); x = factory()->NewNumberLiteral(x_val - y_val, pos);
continue; continue;
case Token::MUL: case Token::MUL:
x = factory()->NewNumberLiteral(x_val * y_val); x = factory()->NewNumberLiteral(x_val * y_val, pos);
continue; continue;
case Token::DIV: case Token::DIV:
x = factory()->NewNumberLiteral(x_val / y_val); x = factory()->NewNumberLiteral(x_val / y_val, pos);
continue; continue;
case Token::BIT_OR: { case Token::BIT_OR: {
int value = DoubleToInt32(x_val) | DoubleToInt32(y_val); int value = DoubleToInt32(x_val) | DoubleToInt32(y_val);
x = factory()->NewNumberLiteral(value); x = factory()->NewNumberLiteral(value, pos);
continue; continue;
} }
case Token::BIT_AND: { case Token::BIT_AND: {
int value = DoubleToInt32(x_val) & DoubleToInt32(y_val); int value = DoubleToInt32(x_val) & DoubleToInt32(y_val);
x = factory()->NewNumberLiteral(value); x = factory()->NewNumberLiteral(value, pos);
continue; continue;
} }
case Token::BIT_XOR: { case Token::BIT_XOR: {
int value = DoubleToInt32(x_val) ^ DoubleToInt32(y_val); int value = DoubleToInt32(x_val) ^ DoubleToInt32(y_val);
x = factory()->NewNumberLiteral(value); x = factory()->NewNumberLiteral(value, pos);
continue; continue;
} }
case Token::SHL: { case Token::SHL: {
int value = DoubleToInt32(x_val) << (DoubleToInt32(y_val) & 0x1f); int value = DoubleToInt32(x_val) << (DoubleToInt32(y_val) & 0x1f);
x = factory()->NewNumberLiteral(value); x = factory()->NewNumberLiteral(value, pos);
continue; continue;
} }
case Token::SHR: { case Token::SHR: {
uint32_t shift = DoubleToInt32(y_val) & 0x1f; uint32_t shift = DoubleToInt32(y_val) & 0x1f;
uint32_t value = DoubleToUint32(x_val) >> shift; uint32_t value = DoubleToUint32(x_val) >> shift;
x = factory()->NewNumberLiteral(value); x = factory()->NewNumberLiteral(value, pos);
continue; continue;
} }
case Token::SAR: { case Token::SAR: {
uint32_t shift = DoubleToInt32(y_val) & 0x1f; uint32_t shift = DoubleToInt32(y_val) & 0x1f;
int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift); int value = ArithmeticShiftRight(DoubleToInt32(x_val), shift);
x = factory()->NewNumberLiteral(value); x = factory()->NewNumberLiteral(value, pos);
continue; continue;
} }
default: default:
...@@ -3109,15 +3120,15 @@ Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { ...@@ -3109,15 +3120,15 @@ Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; case Token::NE_STRICT: cmp = Token::EQ_STRICT; break;
default: break; default: break;
} }
x = factory()->NewCompareOperation(cmp, x, y, position); x = factory()->NewCompareOperation(cmp, x, y, pos);
if (cmp != op) { if (cmp != op) {
// The comparison was negated - add a NOT. // The comparison was negated - add a NOT.
x = factory()->NewUnaryOperation(Token::NOT, x, position); x = factory()->NewUnaryOperation(Token::NOT, x, pos);
} }
} else { } else {
// We have a "normal" binary operation. // We have a "normal" binary operation.
x = factory()->NewBinaryOperation(op, x, y, position); x = factory()->NewBinaryOperation(op, x, y, pos);
} }
} }
} }
...@@ -3141,7 +3152,7 @@ Expression* Parser::ParseUnaryExpression(bool* ok) { ...@@ -3141,7 +3152,7 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
Token::Value op = peek(); Token::Value op = peek();
if (Token::IsUnaryOp(op)) { if (Token::IsUnaryOp(op)) {
op = Next(); op = Next();
int position = scanner().location().beg_pos; int pos = position();
Expression* expression = ParseUnaryExpression(CHECK_OK); Expression* expression = ParseUnaryExpression(CHECK_OK);
if (expression != NULL && (expression->AsLiteral() != NULL)) { if (expression != NULL && (expression->AsLiteral() != NULL)) {
...@@ -3150,7 +3161,7 @@ Expression* Parser::ParseUnaryExpression(bool* ok) { ...@@ -3150,7 +3161,7 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
// Convert the literal to a boolean condition and negate it. // Convert the literal to a boolean condition and negate it.
bool condition = literal->BooleanValue(); bool condition = literal->BooleanValue();
Handle<Object> result = isolate()->factory()->ToBoolean(!condition); Handle<Object> result = isolate()->factory()->ToBoolean(!condition);
return factory()->NewLiteral(result); return factory()->NewLiteral(result, pos);
} else if (literal->IsNumber()) { } else if (literal->IsNumber()) {
// Compute some expressions involving only number literals. // Compute some expressions involving only number literals.
double value = literal->Number(); double value = literal->Number();
...@@ -3158,9 +3169,9 @@ Expression* Parser::ParseUnaryExpression(bool* ok) { ...@@ -3158,9 +3169,9 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
case Token::ADD: case Token::ADD:
return expression; return expression;
case Token::SUB: case Token::SUB:
return factory()->NewNumberLiteral(-value); return factory()->NewNumberLiteral(-value, pos);
case Token::BIT_NOT: case Token::BIT_NOT:
return factory()->NewNumberLiteral(~DoubleToInt32(value)); return factory()->NewNumberLiteral(~DoubleToInt32(value), pos);
default: default:
break; break;
} }
...@@ -3183,25 +3194,25 @@ Expression* Parser::ParseUnaryExpression(bool* ok) { ...@@ -3183,25 +3194,25 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
if (op == Token::ADD) { if (op == Token::ADD) {
return factory()->NewBinaryOperation(Token::MUL, return factory()->NewBinaryOperation(Token::MUL,
expression, expression,
factory()->NewNumberLiteral(1), factory()->NewNumberLiteral(1, pos),
position); pos);
} }
// The same idea for '-foo' => 'foo*(-1)'. // The same idea for '-foo' => 'foo*(-1)'.
if (op == Token::SUB) { if (op == Token::SUB) {
return factory()->NewBinaryOperation(Token::MUL, return factory()->NewBinaryOperation(Token::MUL,
expression, expression,
factory()->NewNumberLiteral(-1), factory()->NewNumberLiteral(-1, pos),
position); pos);
} }
// ...and one more time for '~foo' => 'foo^(~0)'. // ...and one more time for '~foo' => 'foo^(~0)'.
if (op == Token::BIT_NOT) { if (op == Token::BIT_NOT) {
return factory()->NewBinaryOperation(Token::BIT_XOR, return factory()->NewBinaryOperation(Token::BIT_XOR,
expression, expression,
factory()->NewNumberLiteral(~0), factory()->NewNumberLiteral(~0, pos),
position); pos);
} }
return factory()->NewUnaryOperation(op, expression, position); return factory()->NewUnaryOperation(op, expression, pos);
} else if (Token::IsCountOp(op)) { } else if (Token::IsCountOp(op)) {
op = Next(); op = Next();
...@@ -3222,11 +3233,10 @@ Expression* Parser::ParseUnaryExpression(bool* ok) { ...@@ -3222,11 +3233,10 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
} }
MarkAsLValue(expression); MarkAsLValue(expression);
int position = scanner().location().beg_pos;
return factory()->NewCountOperation(op, return factory()->NewCountOperation(op,
true /* prefix */, true /* prefix */,
expression, expression,
position); position()); // TODO(rossberg): ???
} else { } else {
return ParsePostfixExpression(ok); return ParsePostfixExpression(ok);
...@@ -3258,12 +3268,11 @@ Expression* Parser::ParsePostfixExpression(bool* ok) { ...@@ -3258,12 +3268,11 @@ Expression* Parser::ParsePostfixExpression(bool* ok) {
MarkAsLValue(expression); MarkAsLValue(expression);
Token::Value next = Next(); Token::Value next = Next();
int position = scanner().location().beg_pos;
expression = expression =
factory()->NewCountOperation(next, factory()->NewCountOperation(next,
false /* postfix */, false /* postfix */,
expression, expression,
position); position()); // TODO(rossberg): ???
} }
return expression; return expression;
} }
...@@ -3284,7 +3293,7 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) { ...@@ -3284,7 +3293,7 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
switch (peek()) { switch (peek()) {
case Token::LBRACK: { case Token::LBRACK: {
Consume(Token::LBRACK); Consume(Token::LBRACK);
int pos = scanner().location().beg_pos; int pos = position();
Expression* index = ParseExpression(true, CHECK_OK); Expression* index = ParseExpression(true, CHECK_OK);
result = factory()->NewProperty(result, index, pos); result = factory()->NewProperty(result, index, pos);
Expect(Token::RBRACK, CHECK_OK); Expect(Token::RBRACK, CHECK_OK);
...@@ -3296,14 +3305,14 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) { ...@@ -3296,14 +3305,14 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
if (scanner().current_token() == Token::IDENTIFIER) { if (scanner().current_token() == Token::IDENTIFIER) {
// For call of an identifier we want to report position of // For call of an identifier we want to report position of
// the identifier as position of the call in the stack trace. // the identifier as position of the call in the stack trace.
pos = scanner().location().beg_pos; pos = position();
} else { } else {
// For other kinds of calls we record position of the parenthesis as // For other kinds of calls we record position of the parenthesis as
// position of the call. Note that this is extremely important for // position of the call. Note that this is extremely important for
// expressions of the form function(){...}() for which call position // expressions of the form function(){...}() for which call position
// should not point to the closing brace otherwise it will intersect // should not point to the closing brace otherwise it will intersect
// with positions recorded for function literal and confuse debugger. // with positions recorded for function literal and confuse debugger.
pos = scanner().peek_location().beg_pos; pos = peek_position();
// Also the trailing parenthesis are a hint that the function will // Also the trailing parenthesis are a hint that the function will
// be called immediately. If we happen to have parsed a preceding // be called immediately. If we happen to have parsed a preceding
// function literal eagerly, we can also compile it eagerly. // function literal eagerly, we can also compile it eagerly.
...@@ -3332,10 +3341,10 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) { ...@@ -3332,10 +3341,10 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
case Token::PERIOD: { case Token::PERIOD: {
Consume(Token::PERIOD); Consume(Token::PERIOD);
int pos = scanner().location().beg_pos; int pos = position();
Handle<String> name = ParseIdentifierName(CHECK_OK); Handle<String> name = ParseIdentifierName(CHECK_OK);
result = result = factory()->NewProperty(
factory()->NewProperty(result, factory()->NewLiteral(name), pos); result, factory()->NewLiteral(name, pos), pos);
if (fni_ != NULL) fni_->PushLiteralName(name); if (fni_ != NULL) fni_->PushLiteralName(name);
break; break;
} }
...@@ -3360,7 +3369,7 @@ Expression* Parser::ParseNewPrefix(PositionStack* stack, bool* ok) { ...@@ -3360,7 +3369,7 @@ Expression* Parser::ParseNewPrefix(PositionStack* stack, bool* ok) {
// member expression parser, which is only allowed to match argument // member expression parser, which is only allowed to match argument
// lists as long as it has 'new' prefixes left // lists as long as it has 'new' prefixes left
Expect(Token::NEW, CHECK_OK); Expect(Token::NEW, CHECK_OK);
PositionStack::Element pos(stack, scanner().location().beg_pos); PositionStack::Element pos(stack, position());
Expression* result; Expression* result;
if (peek() == Token::NEW) { if (peek() == Token::NEW) {
...@@ -3399,7 +3408,7 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack, ...@@ -3399,7 +3408,7 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack,
Expression* result = NULL; Expression* result = NULL;
if (peek() == Token::FUNCTION) { if (peek() == Token::FUNCTION) {
Expect(Token::FUNCTION, CHECK_OK); Expect(Token::FUNCTION, CHECK_OK);
int function_token_position = scanner().location().beg_pos; int function_token_position = position();
bool is_generator = allow_generators() && Check(Token::MUL); bool is_generator = allow_generators() && Check(Token::MUL);
Handle<String> name; Handle<String> name;
bool is_strict_reserved_name = false; bool is_strict_reserved_name = false;
...@@ -3424,7 +3433,7 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack, ...@@ -3424,7 +3433,7 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack,
switch (peek()) { switch (peek()) {
case Token::LBRACK: { case Token::LBRACK: {
Consume(Token::LBRACK); Consume(Token::LBRACK);
int pos = scanner().location().beg_pos; int pos = position();
Expression* index = ParseExpression(true, CHECK_OK); Expression* index = ParseExpression(true, CHECK_OK);
result = factory()->NewProperty(result, index, pos); result = factory()->NewProperty(result, index, pos);
if (fni_ != NULL) { if (fni_ != NULL) {
...@@ -3440,10 +3449,10 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack, ...@@ -3440,10 +3449,10 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack,
} }
case Token::PERIOD: { case Token::PERIOD: {
Consume(Token::PERIOD); Consume(Token::PERIOD);
int pos = scanner().location().beg_pos; int pos = position();
Handle<String> name = ParseIdentifierName(CHECK_OK); Handle<String> name = ParseIdentifierName(CHECK_OK);
result = result = factory()->NewProperty(
factory()->NewProperty(result, factory()->NewLiteral(name), pos); result, factory()->NewLiteral(name, pos), pos);
if (fni_ != NULL) fni_->PushLiteralName(name); if (fni_ != NULL) fni_->PushLiteralName(name);
break; break;
} }
...@@ -3451,8 +3460,8 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack, ...@@ -3451,8 +3460,8 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack,
if ((stack == NULL) || stack->is_empty()) return result; if ((stack == NULL) || stack->is_empty()) return result;
// Consume one of the new prefixes (already parsed). // Consume one of the new prefixes (already parsed).
ZoneList<Expression*>* args = ParseArguments(CHECK_OK); ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
int last = stack->pop(); int pos = stack->pop();
result = factory()->NewCallNew(result, args, last); result = factory()->NewCallNew(result, args, pos);
break; break;
} }
default: default:
...@@ -3469,9 +3478,10 @@ DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) { ...@@ -3469,9 +3478,10 @@ DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) {
// DebuggerStatement :: // DebuggerStatement ::
// 'debugger' ';' // 'debugger' ';'
int pos = peek_position();
Expect(Token::DEBUGGER, CHECK_OK); Expect(Token::DEBUGGER, CHECK_OK);
ExpectSemicolon(CHECK_OK); ExpectSemicolon(CHECK_OK);
return factory()->NewDebuggerStatement(); return factory()->NewDebuggerStatement(pos);
} }
...@@ -3533,6 +3543,7 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) { ...@@ -3533,6 +3543,7 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) {
// RegExpLiteral // RegExpLiteral
// '(' Expression ')' // '(' Expression ')'
int pos = peek_position();
Expression* result = NULL; Expression* result = NULL;
switch (peek()) { switch (peek()) {
case Token::THIS: { case Token::THIS: {
...@@ -3543,17 +3554,17 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) { ...@@ -3543,17 +3554,17 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) {
case Token::NULL_LITERAL: case Token::NULL_LITERAL:
Consume(Token::NULL_LITERAL); Consume(Token::NULL_LITERAL);
result = factory()->NewLiteral(isolate()->factory()->null_value()); result = factory()->NewLiteral(isolate()->factory()->null_value(), pos);
break; break;
case Token::TRUE_LITERAL: case Token::TRUE_LITERAL:
Consume(Token::TRUE_LITERAL); Consume(Token::TRUE_LITERAL);
result = factory()->NewLiteral(isolate()->factory()->true_value()); result = factory()->NewLiteral(isolate()->factory()->true_value(), pos);
break; break;
case Token::FALSE_LITERAL: case Token::FALSE_LITERAL:
Consume(Token::FALSE_LITERAL); Consume(Token::FALSE_LITERAL);
result = factory()->NewLiteral(isolate()->factory()->false_value()); result = factory()->NewLiteral(isolate()->factory()->false_value(), pos);
break; break;
case Token::IDENTIFIER: case Token::IDENTIFIER:
...@@ -3567,8 +3578,7 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) { ...@@ -3567,8 +3578,7 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) {
PrintF("# Variable %s ", name->ToAsciiArray()); PrintF("# Variable %s ", name->ToAsciiArray());
#endif #endif
Interface* interface = Interface::NewUnknown(zone()); Interface* interface = Interface::NewUnknown(zone());
result = top_scope_->NewUnresolved( result = top_scope_->NewUnresolved(factory(), name, interface, pos);
factory(), name, interface, scanner().location().beg_pos);
break; break;
} }
...@@ -3579,14 +3589,14 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) { ...@@ -3579,14 +3589,14 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) {
scanner().literal_ascii_string(), scanner().literal_ascii_string(),
ALLOW_HEX | ALLOW_OCTAL | ALLOW_HEX | ALLOW_OCTAL |
ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY);
result = factory()->NewNumberLiteral(value); result = factory()->NewNumberLiteral(value, pos);
break; break;
} }
case Token::STRING: { case Token::STRING: {
Consume(Token::STRING); Consume(Token::STRING);
Handle<String> symbol = GetSymbol(); Handle<String> symbol = GetSymbol();
result = factory()->NewLiteral(symbol); result = factory()->NewLiteral(symbol, pos);
if (fni_ != NULL) fni_->PushLiteralName(symbol); if (fni_ != NULL) fni_->PushLiteralName(symbol);
break; break;
} }
...@@ -3640,12 +3650,13 @@ Expression* Parser::ParseArrayLiteral(bool* ok) { ...@@ -3640,12 +3650,13 @@ Expression* Parser::ParseArrayLiteral(bool* ok) {
// ArrayLiteral :: // ArrayLiteral ::
// '[' Expression? (',' Expression?)* ']' // '[' Expression? (',' Expression?)* ']'
int pos = peek_position();
ZoneList<Expression*>* values = new(zone()) ZoneList<Expression*>(4, zone()); ZoneList<Expression*>* values = new(zone()) ZoneList<Expression*>(4, zone());
Expect(Token::LBRACK, CHECK_OK); Expect(Token::LBRACK, CHECK_OK);
while (peek() != Token::RBRACK) { while (peek() != Token::RBRACK) {
Expression* elem; Expression* elem;
if (peek() == Token::COMMA) { if (peek() == Token::COMMA) {
elem = GetLiteralTheHole(); elem = GetLiteralTheHole(peek_position());
} else { } else {
elem = ParseAssignmentExpression(true, CHECK_OK); elem = ParseAssignmentExpression(true, CHECK_OK);
} }
...@@ -3707,7 +3718,7 @@ Expression* Parser::ParseArrayLiteral(bool* ok) { ...@@ -3707,7 +3718,7 @@ Expression* Parser::ParseArrayLiteral(bool* ok) {
literals->set(1, *element_values); literals->set(1, *element_values);
return factory()->NewArrayLiteral( return factory()->NewArrayLiteral(
literals, values, literal_index, is_simple, depth); literals, values, literal_index, is_simple, depth, pos);
} }
...@@ -3855,6 +3866,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) { ...@@ -3855,6 +3866,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
// | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)
// )*[','] '}' // )*[','] '}'
int pos = peek_position();
ZoneList<ObjectLiteral::Property*>* properties = ZoneList<ObjectLiteral::Property*>* properties =
new(zone()) ZoneList<ObjectLiteral::Property*>(4, zone()); new(zone()) ZoneList<ObjectLiteral::Property*>(4, zone());
int number_of_boilerplate_properties = 0; int number_of_boilerplate_properties = 0;
...@@ -3870,6 +3882,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) { ...@@ -3870,6 +3882,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
Literal* key = NULL; Literal* key = NULL;
Token::Value next = peek(); Token::Value next = peek();
int next_pos = peek_position();
switch (next) { switch (next) {
case Token::FUTURE_RESERVED_WORD: case Token::FUTURE_RESERVED_WORD:
...@@ -3914,7 +3927,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) { ...@@ -3914,7 +3927,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
// Allow any number of parameters for compatibilty with JSC. // Allow any number of parameters for compatibilty with JSC.
// Specification only allows zero parameters for get and one for set. // Specification only allows zero parameters for get and one for set.
ObjectLiteral::Property* property = ObjectLiteral::Property* property =
factory()->NewObjectLiteralProperty(is_getter, value); factory()->NewObjectLiteralProperty(is_getter, value, next_pos);
if (IsBoilerplateProperty(property)) { if (IsBoilerplateProperty(property)) {
number_of_boilerplate_properties++; number_of_boilerplate_properties++;
} }
...@@ -3929,7 +3942,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) { ...@@ -3929,7 +3942,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
} }
// Failed to parse as get/set property, so it's just a property // Failed to parse as get/set property, so it's just a property
// called "get" or "set". // called "get" or "set".
key = factory()->NewLiteral(id); key = factory()->NewLiteral(id, next_pos);
break; break;
} }
case Token::STRING: { case Token::STRING: {
...@@ -3938,10 +3951,10 @@ Expression* Parser::ParseObjectLiteral(bool* ok) { ...@@ -3938,10 +3951,10 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
if (fni_ != NULL) fni_->PushLiteralName(string); if (fni_ != NULL) fni_->PushLiteralName(string);
uint32_t index; uint32_t index;
if (!string.is_null() && string->AsArrayIndex(&index)) { if (!string.is_null() && string->AsArrayIndex(&index)) {
key = factory()->NewNumberLiteral(index); key = factory()->NewNumberLiteral(index, next_pos);
break; break;
} }
key = factory()->NewLiteral(string); key = factory()->NewLiteral(string, next_pos);
break; break;
} }
case Token::NUMBER: { case Token::NUMBER: {
...@@ -3951,14 +3964,14 @@ Expression* Parser::ParseObjectLiteral(bool* ok) { ...@@ -3951,14 +3964,14 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
scanner().literal_ascii_string(), scanner().literal_ascii_string(),
ALLOW_HEX | ALLOW_OCTAL | ALLOW_HEX | ALLOW_OCTAL |
ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY); ALLOW_IMPLICIT_OCTAL | ALLOW_BINARY);
key = factory()->NewNumberLiteral(value); key = factory()->NewNumberLiteral(value, next_pos);
break; break;
} }
default: default:
if (Token::IsKeyword(next)) { if (Token::IsKeyword(next)) {
Consume(next); Consume(next);
Handle<String> string = GetSymbol(); Handle<String> string = GetSymbol();
key = factory()->NewLiteral(string); key = factory()->NewLiteral(string, next_pos);
} else { } else {
// Unexpected token. // Unexpected token.
Token::Value next = Next(); Token::Value next = Next();
...@@ -4023,11 +4036,13 @@ Expression* Parser::ParseObjectLiteral(bool* ok) { ...@@ -4023,11 +4036,13 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
fast_elements, fast_elements,
depth, depth,
may_store_doubles, may_store_doubles,
has_function); has_function,
pos);
} }
Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) {
int pos = peek_position();
if (!scanner().ScanRegExpPattern(seen_equal)) { if (!scanner().ScanRegExpPattern(seen_equal)) {
Next(); Next();
ReportMessage("unterminated_regexp", Vector<const char*>::empty()); ReportMessage("unterminated_regexp", Vector<const char*>::empty());
...@@ -4042,7 +4057,7 @@ Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { ...@@ -4042,7 +4057,7 @@ Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) {
Handle<String> js_flags = NextLiteralString(TENURED); Handle<String> js_flags = NextLiteralString(TENURED);
Next(); Next();
return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index); return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos);
} }
...@@ -4167,12 +4182,15 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4167,12 +4182,15 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
Handle<String> function_name, Handle<String> function_name,
bool name_is_strict_reserved, bool name_is_strict_reserved,
bool is_generator, bool is_generator,
int function_token_position, int function_token_pos,
FunctionLiteral::FunctionType function_type, FunctionLiteral::FunctionType function_type,
bool* ok) { bool* ok) {
// Function :: // Function ::
// '(' FormalParameterList? ')' '{' FunctionBody '}' // '(' FormalParameterList? ')' '{' FunctionBody '}'
int pos = function_token_pos == RelocInfo::kNoPosition
? peek_position() : function_token_pos;
// Anonymous functions were passed either the empty symbol or a null // Anonymous functions were passed either the empty symbol or a null
// handle as the function name. Remember if we were passed a non-empty // handle as the function name. Remember if we were passed a non-empty
// handle to decide whether to invoke function name inference. // handle to decide whether to invoke function name inference.
...@@ -4310,8 +4328,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4310,8 +4328,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
function_name, fvar_mode, true /* is valid LHS */, function_name, fvar_mode, true /* is valid LHS */,
Variable::NORMAL, kCreatedInitialized, Interface::NewConst()); Variable::NORMAL, kCreatedInitialized, Interface::NewConst());
VariableProxy* proxy = factory()->NewVariableProxy(fvar); VariableProxy* proxy = factory()->NewVariableProxy(fvar);
VariableDeclaration* fvar_declaration = VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration(
factory()->NewVariableDeclaration(proxy, fvar_mode, top_scope_); proxy, fvar_mode, top_scope_, RelocInfo::kNoPosition);
top_scope_->DeclareFunctionVar(fvar_declaration); top_scope_->DeclareFunctionVar(fvar_declaration);
} }
...@@ -4332,7 +4350,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4332,7 +4350,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
parenthesized_function_ = false; // The bit was set for this function only. parenthesized_function_ = false; // The bit was set for this function only.
if (is_lazily_compiled) { if (is_lazily_compiled) {
int function_block_pos = scanner().location().beg_pos; int function_block_pos = position();
FunctionEntry entry; FunctionEntry entry;
if (pre_parse_data_ != NULL) { if (pre_parse_data_ != NULL) {
// If we have pre_parse_data_, we use it to skip parsing the function // If we have pre_parse_data_, we use it to skip parsing the function
...@@ -4401,9 +4419,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4401,9 +4419,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
body->Add(factory()->NewExpressionStatement( body->Add(factory()->NewExpressionStatement(
factory()->NewAssignment(fvar_init_op, factory()->NewAssignment(fvar_init_op,
fproxy, fproxy,
factory()->NewThisFunction(), factory()->NewThisFunction(pos),
RelocInfo::kNoPosition)), RelocInfo::kNoPosition),
zone()); RelocInfo::kNoPosition), zone());
} }
// For generators, allocate and yield an iterator on function entry. // For generators, allocate and yield an iterator on function entry.
...@@ -4413,7 +4431,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4413,7 +4431,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
CallRuntime* allocation = factory()->NewCallRuntime( CallRuntime* allocation = factory()->NewCallRuntime(
isolate()->factory()->empty_string(), isolate()->factory()->empty_string(),
Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject), Runtime::FunctionForId(Runtime::kCreateJSGeneratorObject),
arguments); arguments, pos);
VariableProxy* init_proxy = factory()->NewVariableProxy( VariableProxy* init_proxy = factory()->NewVariableProxy(
current_function_state_->generator_object_variable()); current_function_state_->generator_object_variable());
Assignment* assignment = factory()->NewAssignment( Assignment* assignment = factory()->NewAssignment(
...@@ -4422,7 +4440,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4422,7 +4440,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
current_function_state_->generator_object_variable()); current_function_state_->generator_object_variable());
Yield* yield = factory()->NewYield( Yield* yield = factory()->NewYield(
get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition); get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition);
body->Add(factory()->NewExpressionStatement(yield), zone()); body->Add(factory()->NewExpressionStatement(
yield, RelocInfo::kNoPosition), zone());
} }
ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK); ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK);
...@@ -4431,10 +4450,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4431,10 +4450,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
VariableProxy* get_proxy = factory()->NewVariableProxy( VariableProxy* get_proxy = factory()->NewVariableProxy(
current_function_state_->generator_object_variable()); current_function_state_->generator_object_variable());
Expression *undefined = factory()->NewLiteral( Expression *undefined = factory()->NewLiteral(
isolate()->factory()->undefined_value()); isolate()->factory()->undefined_value(), RelocInfo::kNoPosition);
Yield* yield = factory()->NewYield( Yield* yield = factory()->NewYield(
get_proxy, undefined, Yield::FINAL, RelocInfo::kNoPosition); get_proxy, undefined, Yield::FINAL, RelocInfo::kNoPosition);
body->Add(factory()->NewExpressionStatement(yield), zone()); body->Add(factory()->NewExpressionStatement(
yield, RelocInfo::kNoPosition), zone());
} }
materialized_literal_count = function_state.materialized_literal_count(); materialized_literal_count = function_state.materialized_literal_count();
...@@ -4449,9 +4469,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4449,9 +4469,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
if (!top_scope_->is_classic_mode()) { if (!top_scope_->is_classic_mode()) {
if (IsEvalOrArguments(function_name)) { if (IsEvalOrArguments(function_name)) {
int start_pos = scope->start_position(); int start_pos = scope->start_position();
int position = function_token_position != RelocInfo::kNoPosition int position = function_token_pos != RelocInfo::kNoPosition
? function_token_position ? function_token_pos : (start_pos > 0 ? start_pos - 1 : start_pos);
: (start_pos > 0 ? start_pos - 1 : start_pos);
Scanner::Location location = Scanner::Location(position, start_pos); Scanner::Location location = Scanner::Location(position, start_pos);
ReportMessageAt(location, ReportMessageAt(location,
"strict_function_name", Vector<const char*>::empty()); "strict_function_name", Vector<const char*>::empty());
...@@ -4472,9 +4491,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4472,9 +4491,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
} }
if (name_is_strict_reserved) { if (name_is_strict_reserved) {
int start_pos = scope->start_position(); int start_pos = scope->start_position();
int position = function_token_position != RelocInfo::kNoPosition int position = function_token_pos != RelocInfo::kNoPosition
? function_token_position ? function_token_pos : (start_pos > 0 ? start_pos - 1 : start_pos);
: (start_pos > 0 ? start_pos - 1 : start_pos);
Scanner::Location location = Scanner::Location(position, start_pos); Scanner::Location location = Scanner::Location(position, start_pos);
ReportMessageAt(location, "strict_reserved_word", ReportMessageAt(location, "strict_reserved_word",
Vector<const char*>::empty()); Vector<const char*>::empty());
...@@ -4511,8 +4529,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -4511,8 +4529,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
function_type, function_type,
FunctionLiteral::kIsFunction, FunctionLiteral::kIsFunction,
parenthesized, parenthesized,
generator); generator,
function_literal->set_function_token_position(function_token_position); pos);
function_literal->set_function_token_position(function_token_pos);
function_literal->set_ast_properties(&ast_properties); function_literal->set_ast_properties(&ast_properties);
function_literal->set_dont_optimize_reason(dont_optimize_reason); function_literal->set_dont_optimize_reason(dont_optimize_reason);
...@@ -4552,6 +4571,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) { ...@@ -4552,6 +4571,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
// CallRuntime :: // CallRuntime ::
// '%' Identifier Arguments // '%' Identifier Arguments
int pos = peek_position();
Expect(Token::MOD, CHECK_OK); Expect(Token::MOD, CHECK_OK);
Handle<String> name = ParseIdentifier(CHECK_OK); Handle<String> name = ParseIdentifier(CHECK_OK);
ZoneList<Expression*>* args = ParseArguments(CHECK_OK); ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
...@@ -4597,7 +4617,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) { ...@@ -4597,7 +4617,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
} }
// We have a valid intrinsics call or a call to a builtin. // We have a valid intrinsics call or a call to a builtin.
return factory()->NewCallRuntime(name, function, args); return factory()->NewCallRuntime(name, function, args, pos);
} }
...@@ -4673,13 +4693,15 @@ void Parser::ExpectContextualKeyword(Vector<const char> keyword, bool* ok) { ...@@ -4673,13 +4693,15 @@ void Parser::ExpectContextualKeyword(Vector<const char> keyword, bool* ok) {
} }
Literal* Parser::GetLiteralUndefined() { Literal* Parser::GetLiteralUndefined(int position) {
return factory()->NewLiteral(isolate()->factory()->undefined_value()); return factory()->NewLiteral(
isolate()->factory()->undefined_value(), position);
} }
Literal* Parser::GetLiteralTheHole() { Literal* Parser::GetLiteralTheHole(int position) {
return factory()->NewLiteral(isolate()->factory()->the_hole_value()); return factory()->NewLiteral(
isolate()->factory()->the_hole_value(), RelocInfo::kNoPosition);
} }
...@@ -4908,12 +4930,13 @@ Expression* Parser::NewThrowError(Handle<String> constructor, ...@@ -4908,12 +4930,13 @@ Expression* Parser::NewThrowError(Handle<String> constructor,
Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements( Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements(
elements, FAST_ELEMENTS, TENURED); elements, FAST_ELEMENTS, TENURED);
int pos = position();
ZoneList<Expression*>* args = new(zone()) ZoneList<Expression*>(2, zone()); ZoneList<Expression*>* args = new(zone()) ZoneList<Expression*>(2, zone());
args->Add(factory()->NewLiteral(message), zone()); args->Add(factory()->NewLiteral(message, pos), zone());
args->Add(factory()->NewLiteral(array), zone()); args->Add(factory()->NewLiteral(array, pos), zone());
CallRuntime* call_constructor = CallRuntime* call_constructor =
factory()->NewCallRuntime(constructor, NULL, args); factory()->NewCallRuntime(constructor, NULL, args, pos);
return factory()->NewThrow(call_constructor, scanner().location().beg_pos); return factory()->NewThrow(call_constructor, pos);
} }
......
...@@ -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