Commit 85363049 authored by whesse@chromium.org's avatar whesse@chromium.org

Restart AST node numbering when we enter a function.

BUG=
TEST=

Review URL: http://codereview.chromium.org/6691058

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7543 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 95c76ed4
......@@ -245,7 +245,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
}
{ Comment cmnt(masm_, "[ Stack check");
PrepareForBailout(info->function(), NO_REGISTERS);
PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS);
Label ok;
__ LoadRoot(ip, Heap::kStackLimitRootIndex);
__ cmp(sp, Operand(ip));
......
......@@ -132,6 +132,7 @@ class AstNode: public ZoneObject {
#undef DECLARE_TYPE_ENUM
static const int kNoNumber = -1;
static const int kFunctionEntryId = 2; // Using 0 could disguise errors.
AstNode() : id_(GetNextId()) {
Isolate* isolate = Isolate::Current();
......@@ -1661,8 +1662,7 @@ class FunctionLiteral: public Expression {
int num_parameters,
int start_position,
int end_position,
bool is_expression,
bool contains_loops)
bool is_expression)
: name_(name),
scope_(scope),
body_(body),
......@@ -1675,7 +1675,6 @@ class FunctionLiteral: public Expression {
start_position_(start_position),
end_position_(end_position),
is_expression_(is_expression),
contains_loops_(contains_loops),
function_token_position_(RelocInfo::kNoPosition),
inferred_name_(HEAP->empty_string()),
pretenure_(false) { }
......@@ -1690,7 +1689,6 @@ class FunctionLiteral: public Expression {
int start_position() const { return start_position_; }
int end_position() const { return end_position_; }
bool is_expression() const { return is_expression_; }
bool contains_loops() const { return contains_loops_; }
bool strict_mode() const;
int materialized_literal_count() { return materialized_literal_count_; }
......@@ -1730,7 +1728,6 @@ class FunctionLiteral: public Expression {
int start_position_;
int end_position_;
bool is_expression_;
bool contains_loops_;
bool strict_mode_;
int function_token_position_;
Handle<String> inferred_name_;
......
......@@ -582,7 +582,7 @@ HGraph::HGraph(CompilationInfo* info)
phi_list_(NULL) {
start_environment_ =
new(zone()) HEnvironment(NULL, info->scope(), info->closure());
start_environment_->set_ast_id(info->function()->id());
start_environment_->set_ast_id(AstNode::kFunctionEntryId);
entry_block_ = CreateBasicBlock();
entry_block_->SetInitialEnvironment(start_environment_);
}
......@@ -2203,7 +2203,7 @@ HGraph* HGraphBuilder::CreateGraph() {
HEnvironment* initial_env = environment()->CopyWithoutHistory();
HBasicBlock* body_entry = CreateBasicBlock(initial_env);
current_block()->Goto(body_entry);
body_entry->SetJoinId(info()->function()->id());
body_entry->SetJoinId(AstNode::kFunctionEntryId);
set_current_block(body_entry);
VisitStatements(info()->function()->body());
if (HasStackOverflow()) return NULL;
......@@ -5663,7 +5663,7 @@ HEnvironment* HEnvironment::CopyForInlining(Handle<JSFunction> target,
inner->SetValueAt(local_base + i, undefined);
}
inner->set_ast_id(function->id());
inner->set_ast_id(AstNode::kFunctionEntryId);
return inner;
}
......
......@@ -231,7 +231,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
}
{ Comment cmnt(masm_, "[ Stack check");
PrepareForBailout(info->function(), NO_REGISTERS);
PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS);
NearLabel ok;
ExternalReference stack_limit =
ExternalReference::address_of_stack_limit(isolate());
......
......@@ -462,7 +462,7 @@ class TargetScope BASE_EMBEDDED {
// Parser's scope stack. The constructor sets the parser's top scope
// to the incoming scope, and the destructor resets it.
//
// Additionlaly, it stores transient information used during parsing.
// Additionally, it stores transient information used during parsing.
// These scopes are not kept around after parsing or referenced by syntax
// trees so they can be stack-allocated and hence used by the pre-parser.
......@@ -496,9 +496,6 @@ class LexicalScope BASE_EMBEDDED {
void AddProperty() { expected_property_count_++; }
int expected_property_count() { return expected_property_count_; }
void AddLoop() { loop_count_++; }
bool ContainsLoops() const { return loop_count_ > 0; }
private:
// Captures the number of literals that need materialization in the
// function. Includes regexp literals, and boilerplate for object
......@@ -513,15 +510,13 @@ class LexicalScope BASE_EMBEDDED {
bool only_simple_this_property_assignments_;
Handle<FixedArray> this_property_assignments_;
// Captures the number of loops inside the scope.
int loop_count_;
// Bookkeeping
Parser* parser_;
// Previous values
LexicalScope* lexical_scope_parent_;
Scope* previous_scope_;
int previous_with_nesting_level_;
unsigned previous_ast_node_id_;
};
......@@ -530,14 +525,15 @@ LexicalScope::LexicalScope(Parser* parser, Scope* scope, Isolate* isolate)
expected_property_count_(0),
only_simple_this_property_assignments_(false),
this_property_assignments_(isolate->factory()->empty_fixed_array()),
loop_count_(0),
parser_(parser),
lexical_scope_parent_(parser->lexical_scope_),
previous_scope_(parser->top_scope_),
previous_with_nesting_level_(parser->with_nesting_level_) {
previous_with_nesting_level_(parser->with_nesting_level_),
previous_ast_node_id_(isolate->ast_node_id()) {
parser->top_scope_ = scope;
parser->lexical_scope_ = this;
parser->with_nesting_level_ = 0;
isolate->set_ast_node_id(AstNode::kRootAstId + 1);
}
......@@ -546,6 +542,7 @@ LexicalScope::~LexicalScope() {
parser_->top_scope_ = previous_scope_;
parser_->lexical_scope_ = lexical_scope_parent_;
parser_->with_nesting_level_ = previous_with_nesting_level_;
parser_->isolate()->set_ast_node_id(previous_ast_node_id_);
}
......@@ -663,8 +660,7 @@ FunctionLiteral* Parser::DoParseProgram(Handle<String> source,
0,
0,
source->length(),
false,
lexical_scope.ContainsLoops());
false);
} else if (stack_overflow_) {
isolate()->StackOverflow();
}
......@@ -2162,7 +2158,6 @@ DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels,
// DoStatement ::
// 'do' Statement 'while' '(' Expression ')' ';'
lexical_scope_->AddLoop();
DoWhileStatement* loop = new(zone()) DoWhileStatement(labels);
Target target(&this->target_stack_, loop);
......@@ -2194,7 +2189,6 @@ WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) {
// WhileStatement ::
// 'while' '(' Expression ')' Statement
lexical_scope_->AddLoop();
WhileStatement* loop = new(zone()) WhileStatement(labels);
Target target(&this->target_stack_, loop);
......@@ -2213,7 +2207,6 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
// ForStatement ::
// 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
lexical_scope_->AddLoop();
Statement* init = NULL;
Expect(Token::FOR, CHECK_OK);
......@@ -3530,16 +3523,22 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
}
int num_parameters = 0;
Scope* scope = NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with());
ZoneList<Statement*>* body = new ZoneList<Statement*>(8);
int materialized_literal_count;
int expected_property_count;
int start_pos;
int end_pos;
bool only_simple_this_property_assignments;
Handle<FixedArray> this_property_assignments;
// Parse function body.
{ Scope* scope =
NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with());
LexicalScope lexical_scope(this, scope, isolate());
{ LexicalScope lexical_scope(this, scope, isolate());
top_scope_->SetScopeName(name);
// FormalParameterList ::
// '(' (Identifier)*[','] ')'
Expect(Token::LPAREN, CHECK_OK);
int start_pos = scanner().location().beg_pos;
start_pos = scanner().location().beg_pos;
Scanner::Location name_loc = Scanner::NoLocation();
Scanner::Location dupe_loc = Scanner::NoLocation();
Scanner::Location reserved_loc = Scanner::NoLocation();
......@@ -3576,7 +3575,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
Expect(Token::RPAREN, CHECK_OK);
Expect(Token::LBRACE, CHECK_OK);
ZoneList<Statement*>* body = new ZoneList<Statement*>(8);
// If we have a named function expression, we add a local variable
// declaration to the body of the function with the name of the
......@@ -3604,11 +3602,6 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
parenthesized_function_ = false; // The bit was set for this function only.
int function_block_pos = scanner().location().beg_pos;
int materialized_literal_count;
int expected_property_count;
int end_pos;
bool only_simple_this_property_assignments;
Handle<FixedArray> this_property_assignments;
if (is_lazily_compiled && pre_data() != NULL) {
FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos);
if (!entry.is_valid()) {
......@@ -3683,10 +3676,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
}
CheckOctalLiteral(start_pos, end_pos, CHECK_OK);
}
}
FunctionLiteral* function_literal =
new(zone()) FunctionLiteral(name,
top_scope_,
scope,
body,
materialized_literal_count,
expected_property_count,
......@@ -3695,13 +3689,11 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
num_parameters,
start_pos,
end_pos,
function_name->length() > 0,
lexical_scope.ContainsLoops());
(function_name->length() > 0));
function_literal->set_function_token_position(function_token_position);
if (fni_ != NULL && !is_named) fni_->AddFunction(function_literal);
return function_literal;
}
}
......
......@@ -232,7 +232,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) {
}
{ Comment cmnt(masm_, "[ Stack check");
PrepareForBailout(info->function(), NO_REGISTERS);
PrepareForBailoutForId(AstNode::kFunctionEntryId, NO_REGISTERS);
NearLabel ok;
__ CompareRoot(rsp, Heap::kStackLimitRootIndex);
__ j(above_equal, &ok);
......
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