Simplify AST ID generation.

Every CompilationInfo has an ID generator now, and it is never
reset/copied/assigned. Simplified FunctionState.

R=mstarzinger@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24481 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0fae280e
...@@ -184,7 +184,7 @@ class AstNode: public ZoneObject { ...@@ -184,7 +184,7 @@ class AstNode: public ZoneObject {
// For generating IDs for AstNodes. // For generating IDs for AstNodes.
class IdGen { class IdGen {
public: public:
explicit IdGen(int id = 0) : id_(id) {} IdGen() : id_(BailoutId::FirstUsable().ToInt()) {}
int GetNextId() { return ReserveIdRange(1); } int GetNextId() { return ReserveIdRange(1); }
int ReserveIdRange(int n) { int ReserveIdRange(int n) {
...@@ -195,6 +195,8 @@ class AstNode: public ZoneObject { ...@@ -195,6 +195,8 @@ class AstNode: public ZoneObject {
private: private:
int id_; int id_;
DISALLOW_COPY_AND_ASSIGN(IdGen);
}; };
#define DECLARE_TYPE_ENUM(type) k##type, #define DECLARE_TYPE_ENUM(type) k##type,
......
...@@ -878,8 +878,10 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, Scope** scope, ...@@ -878,8 +878,10 @@ FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, Scope** scope,
ParsingModeScope parsing_mode(this, mode); ParsingModeScope parsing_mode(this, mode);
// Enters 'scope'. // Enters 'scope'.
FunctionState function_state(&function_state_, &scope_, *scope, zone(), AstNodeFactory<AstConstructionVisitor> function_factory(
ast_value_factory(), info->ast_node_id_gen()); zone(), ast_value_factory(), info->ast_node_id_gen());
FunctionState function_state(&function_state_, &scope_, *scope,
&function_factory);
scope_->SetStrictMode(info->strict_mode()); scope_->SetStrictMode(info->strict_mode());
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
...@@ -991,9 +993,10 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) { ...@@ -991,9 +993,10 @@ FunctionLiteral* Parser::ParseLazy(Utf16CharacterStream* source) {
zone()); zone());
} }
original_scope_ = scope; original_scope_ = scope;
FunctionState function_state(&function_state_, &scope_, scope, zone(), AstNodeFactory<AstConstructionVisitor> function_factory(
ast_value_factory(), zone(), ast_value_factory(), info()->ast_node_id_gen());
info()->ast_node_id_gen()); FunctionState function_state(&function_state_, &scope_, scope,
&function_factory);
DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT);
DCHECK(info()->strict_mode() == shared_info->strict_mode()); DCHECK(info()->strict_mode() == shared_info->strict_mode());
scope->SetStrictMode(shared_info->strict_mode()); scope->SetStrictMode(shared_info->strict_mode());
...@@ -3492,9 +3495,10 @@ FunctionLiteral* Parser::ParseFunctionLiteral( ...@@ -3492,9 +3495,10 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
BailoutReason dont_optimize_reason = kNoReason; BailoutReason dont_optimize_reason = kNoReason;
// Parse function body. // Parse function body.
{ {
FunctionState function_state(&function_state_, &scope_, scope, zone(), AstNodeFactory<AstConstructionVisitor> function_factory(
ast_value_factory(), zone(), ast_value_factory(), info()->ast_node_id_gen());
info()->ast_node_id_gen()); FunctionState function_state(&function_state_, &scope_, scope,
&function_factory);
scope_->SetScopeName(function_name); scope_->SetScopeName(function_name);
if (is_generator) { if (is_generator) {
......
...@@ -376,21 +376,6 @@ class ParserTraits { ...@@ -376,21 +376,6 @@ class ParserTraits {
explicit ParserTraits(Parser* parser) : parser_(parser) {} explicit ParserTraits(Parser* parser) : parser_(parser) {}
// Custom operations executed when FunctionStates are created and destructed.
template <typename FunctionState>
static void SetUpFunctionState(FunctionState* function_state) {
function_state->saved_id_gen_ = *function_state->ast_node_id_gen_;
*function_state->ast_node_id_gen_ =
AstNode::IdGen(BailoutId::FirstUsable().ToInt());
}
template <typename FunctionState>
static void TearDownFunctionState(FunctionState* function_state) {
if (function_state->outer_function_state_ != NULL) {
*function_state->ast_node_id_gen_ = function_state->saved_id_gen_;
}
}
// Helper functions for recursive descent. // Helper functions for recursive descent.
bool IsEvalOrArguments(const AstRawString* identifier) const; bool IsEvalOrArguments(const AstRawString* identifier) const;
V8_INLINE bool IsFutureStrictReserved(const AstRawString* identifier) const; V8_INLINE bool IsFutureStrictReserved(const AstRawString* identifier) const;
......
...@@ -116,12 +116,13 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction( ...@@ -116,12 +116,13 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
log_ = log; log_ = log;
// Lazy functions always have trivial outer scopes (no with/catch scopes). // Lazy functions always have trivial outer scopes (no with/catch scopes).
PreParserScope top_scope(scope_, GLOBAL_SCOPE); PreParserScope top_scope(scope_, GLOBAL_SCOPE);
FunctionState top_state(&function_state_, &scope_, &top_scope, NULL, PreParserFactory top_factory(NULL, NULL, NULL);
this->ast_value_factory()); FunctionState top_state(&function_state_, &scope_, &top_scope, &top_factory);
scope_->SetStrictMode(strict_mode); scope_->SetStrictMode(strict_mode);
PreParserScope function_scope(scope_, FUNCTION_SCOPE); PreParserScope function_scope(scope_, FUNCTION_SCOPE);
FunctionState function_state(&function_state_, &scope_, &function_scope, NULL, PreParserFactory function_factory(NULL, NULL, NULL);
this->ast_value_factory()); FunctionState function_state(&function_state_, &scope_, &function_scope,
&function_factory);
function_state.set_is_generator(is_generator); function_state.set_is_generator(is_generator);
DCHECK_EQ(Token::LBRACE, scanner()->current_token()); DCHECK_EQ(Token::LBRACE, scanner()->current_token());
bool ok = true; bool ok = true;
...@@ -824,8 +825,9 @@ PreParser::Expression PreParser::ParseFunctionLiteral( ...@@ -824,8 +825,9 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
// Parse function body. // Parse function body.
ScopeType outer_scope_type = scope_->type(); ScopeType outer_scope_type = scope_->type();
PreParserScope function_scope(scope_, FUNCTION_SCOPE); PreParserScope function_scope(scope_, FUNCTION_SCOPE);
FunctionState function_state(&function_state_, &scope_, &function_scope, NULL, PreParserFactory factory(NULL, NULL, NULL);
this->ast_value_factory()); FunctionState function_state(&function_state_, &scope_, &function_scope,
&factory);
function_state.set_is_generator(IsGeneratorFunction(kind)); function_state.set_is_generator(IsGeneratorFunction(kind));
// FormalParameterList :: // FormalParameterList ::
// '(' (Identifier)*[','] ')' // '(' (Identifier)*[','] ')'
......
...@@ -170,15 +170,11 @@ class ParserBase : public Traits { ...@@ -170,15 +170,11 @@ class ParserBase : public Traits {
FunctionState(FunctionState** function_state_stack, FunctionState(FunctionState** function_state_stack,
typename Traits::Type::Scope** scope_stack, typename Traits::Type::Scope** scope_stack,
typename Traits::Type::Scope* scope, typename Traits::Type::Scope* scope,
typename Traits::Type::Zone* zone = NULL, typename Traits::Type::Factory* factory);
AstValueFactory* ast_value_factory = NULL,
AstNode::IdGen* ast_node_id_gen = NULL);
FunctionState(FunctionState** function_state_stack, FunctionState(FunctionState** function_state_stack,
typename Traits::Type::Scope** scope_stack, typename Traits::Type::Scope** scope_stack,
typename Traits::Type::Scope** scope, typename Traits::Type::Scope** scope,
typename Traits::Type::Zone* zone = NULL, typename Traits::Type::Factory* factory);
AstValueFactory* ast_value_factory = NULL,
AstNode::IdGen* ast_node_id_gen = NULL);
~FunctionState(); ~FunctionState();
int NextMaterializedLiteralIndex() { int NextMaterializedLiteralIndex() {
...@@ -209,7 +205,7 @@ class ParserBase : public Traits { ...@@ -209,7 +205,7 @@ class ParserBase : public Traits {
return generator_object_variable_; return generator_object_variable_;
} }
typename Traits::Type::Factory* factory() { return &factory_; } typename Traits::Type::Factory* factory() { return factory_; }
private: private:
// Used to assign an index to each literal that needs materialization in // Used to assign an index to each literal that needs materialization in
...@@ -234,10 +230,8 @@ class ParserBase : public Traits { ...@@ -234,10 +230,8 @@ class ParserBase : public Traits {
FunctionState* outer_function_state_; FunctionState* outer_function_state_;
typename Traits::Type::Scope** scope_stack_; typename Traits::Type::Scope** scope_stack_;
typename Traits::Type::Scope* outer_scope_; typename Traits::Type::Scope* outer_scope_;
AstNode::IdGen* ast_node_id_gen_; // Only used by ParserTraits.
AstNode::IdGen saved_id_gen_; // Ditto.
typename Traits::Type::Zone* extra_param_; typename Traits::Type::Zone* extra_param_;
typename Traits::Type::Factory factory_; typename Traits::Type::Factory* factory_;
friend class ParserTraits; friend class ParserTraits;
friend class Checkpoint; friend class Checkpoint;
...@@ -1156,13 +1150,6 @@ class PreParserTraits { ...@@ -1156,13 +1150,6 @@ class PreParserTraits {
explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
// Custom operations executed when FunctionStates are created and
// destructed. (The PreParser doesn't need to do anything.)
template <typename FunctionState>
static void SetUpFunctionState(FunctionState* function_state) {}
template <typename FunctionState>
static void TearDownFunctionState(FunctionState* function_state) {}
// Helper functions for recursive descent. // Helper functions for recursive descent.
static bool IsEvalOrArguments(PreParserIdentifier identifier) { static bool IsEvalOrArguments(PreParserIdentifier identifier) {
return identifier.IsEvalOrArguments(); return identifier.IsEvalOrArguments();
...@@ -1445,7 +1432,8 @@ class PreParser : public ParserBase<PreParserTraits> { ...@@ -1445,7 +1432,8 @@ class PreParser : public ParserBase<PreParserTraits> {
// during parsing. // during parsing.
PreParseResult PreParseProgram() { PreParseResult PreParseProgram() {
PreParserScope scope(scope_, GLOBAL_SCOPE); PreParserScope scope(scope_, GLOBAL_SCOPE);
FunctionState top_scope(&function_state_, &scope_, &scope); PreParserFactory factory(NULL, NULL, NULL);
FunctionState top_scope(&function_state_, &scope_, &scope, &factory);
bool ok = true; bool ok = true;
int start_position = scanner()->peek_location().beg_pos; int start_position = scanner()->peek_location().beg_pos;
ParseSourceElements(Token::EOS, &ok); ParseSourceElements(Token::EOS, &ok);
...@@ -1572,8 +1560,8 @@ template <class Traits> ...@@ -1572,8 +1560,8 @@ template <class Traits>
ParserBase<Traits>::FunctionState::FunctionState( ParserBase<Traits>::FunctionState::FunctionState(
FunctionState** function_state_stack, FunctionState** function_state_stack,
typename Traits::Type::Scope** scope_stack, typename Traits::Type::Scope** scope_stack,
typename Traits::Type::Scope* scope, typename Traits::Type::Zone* zone, typename Traits::Type::Scope* scope,
AstValueFactory* ast_value_factory, AstNode::IdGen* ast_node_id_gen) typename Traits::Type::Factory* factory)
: next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize),
next_handler_index_(0), next_handler_index_(0),
expected_property_count_(0), expected_property_count_(0),
...@@ -1583,11 +1571,9 @@ ParserBase<Traits>::FunctionState::FunctionState( ...@@ -1583,11 +1571,9 @@ ParserBase<Traits>::FunctionState::FunctionState(
outer_function_state_(*function_state_stack), outer_function_state_(*function_state_stack),
scope_stack_(scope_stack), scope_stack_(scope_stack),
outer_scope_(*scope_stack), outer_scope_(*scope_stack),
ast_node_id_gen_(ast_node_id_gen), factory_(factory) {
factory_(zone, ast_value_factory, ast_node_id_gen) {
*scope_stack_ = scope; *scope_stack_ = scope;
*function_state_stack = this; *function_state_stack = this;
Traits::SetUpFunctionState(this);
} }
...@@ -1595,8 +1581,8 @@ template <class Traits> ...@@ -1595,8 +1581,8 @@ template <class Traits>
ParserBase<Traits>::FunctionState::FunctionState( ParserBase<Traits>::FunctionState::FunctionState(
FunctionState** function_state_stack, FunctionState** function_state_stack,
typename Traits::Type::Scope** scope_stack, typename Traits::Type::Scope** scope_stack,
typename Traits::Type::Scope** scope, typename Traits::Type::Zone* zone, typename Traits::Type::Scope** scope,
AstValueFactory* ast_value_factory, AstNode::IdGen* ast_node_id_gen) typename Traits::Type::Factory* factory)
: next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize),
next_handler_index_(0), next_handler_index_(0),
expected_property_count_(0), expected_property_count_(0),
...@@ -1606,11 +1592,9 @@ ParserBase<Traits>::FunctionState::FunctionState( ...@@ -1606,11 +1592,9 @@ ParserBase<Traits>::FunctionState::FunctionState(
outer_function_state_(*function_state_stack), outer_function_state_(*function_state_stack),
scope_stack_(scope_stack), scope_stack_(scope_stack),
outer_scope_(*scope_stack), outer_scope_(*scope_stack),
ast_node_id_gen_(ast_node_id_gen), factory_(factory) {
factory_(zone, ast_value_factory, ast_node_id_gen) {
*scope_stack_ = *scope; *scope_stack_ = *scope;
*function_state_stack = this; *function_state_stack = this;
Traits::SetUpFunctionState(this);
} }
...@@ -1618,7 +1602,6 @@ template <class Traits> ...@@ -1618,7 +1602,6 @@ template <class Traits>
ParserBase<Traits>::FunctionState::~FunctionState() { ParserBase<Traits>::FunctionState::~FunctionState() {
*scope_stack_ = outer_scope_; *scope_stack_ = outer_scope_;
*function_state_stack_ = outer_function_state_; *function_state_stack_ = outer_function_state_;
Traits::TearDownFunctionState(this);
} }
...@@ -2651,8 +2634,10 @@ typename ParserBase<Traits>::ExpressionT ParserBase< ...@@ -2651,8 +2634,10 @@ typename ParserBase<Traits>::ExpressionT ParserBase<
int handler_count = 0; int handler_count = 0;
{ {
FunctionState function_state(&function_state_, &scope_, &scope, zone(), typename Traits::Type::Factory function_factory(
this->ast_value_factory(), ast_node_id_gen_); zone(), this->ast_value_factory(), ast_node_id_gen_);
FunctionState function_state(&function_state_, &scope_, &scope,
&function_factory);
Scanner::Location dupe_error_loc = Scanner::Location::invalid(); Scanner::Location dupe_error_loc = Scanner::Location::invalid();
num_parameters = Traits::DeclareArrowParametersFromExpression( num_parameters = Traits::DeclareArrowParametersFromExpression(
params_ast, scope_, &dupe_error_loc, ok); params_ast, scope_, &dupe_error_loc, 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