From 49e5b0d60cdb7ddd94f416674c10041900dd055d Mon Sep 17 00:00:00 2001 From: "dslomov@chromium.org" Date: Thu, 9 Oct 2014 10:40:18 +0000 Subject: [PATCH] Simplify Scope and ScopePtr conversions. R=svenpanne@chromium.org Review URL: https://codereview.chromium.org/643603002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24488 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/parser.h | 2 ++ src/preparser.h | 40 +++++----------------------------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/src/parser.h b/src/parser.h index 19ed18539a..74f3944718 100644 --- a/src/parser.h +++ b/src/parser.h @@ -352,6 +352,8 @@ class ParserTraits { // Used by FunctionState and BlockState. typedef v8::internal::Scope Scope; typedef v8::internal::Scope* ScopePtr; + inline static Scope* ptr_to_scope(ScopePtr scope) { return scope; } + typedef Variable GeneratorVariable; typedef v8::internal::Zone Zone; diff --git a/src/preparser.h b/src/preparser.h index 1062907c5f..a41b228224 100644 --- a/src/preparser.h +++ b/src/preparser.h @@ -150,13 +150,6 @@ class ParserBase : public Traits { scope_(scope) { *scope_stack_ = scope_; } - BlockState(typename Traits::Type::Scope** scope_stack, - typename Traits::Type::Scope** scope) - : scope_stack_(scope_stack), - outer_scope_(*scope_stack), - scope_(*scope) { - *scope_stack_ = scope_; - } ~BlockState() { *scope_stack_ = outer_scope_; } private: @@ -171,10 +164,6 @@ class ParserBase : public Traits { typename Traits::Type::Scope** scope_stack, typename Traits::Type::Scope* scope, typename Traits::Type::Factory* factory); - FunctionState(FunctionState** function_state_stack, - typename Traits::Type::Scope** scope_stack, - typename Traits::Type::Scope** scope, - typename Traits::Type::Factory* factory); ~FunctionState(); int NextMaterializedLiteralIndex() { @@ -1123,6 +1112,7 @@ class PreParserTraits { // Used by FunctionState and BlockState. typedef PreParserScope Scope; typedef PreParserScope ScopePtr; + inline static Scope* ptr_to_scope(ScopePtr& scope) { return &scope; } // PreParser doesn't need to store generator variables. typedef void GeneratorVariable; @@ -1577,27 +1567,6 @@ ParserBase::FunctionState::FunctionState( } -template -ParserBase::FunctionState::FunctionState( - FunctionState** function_state_stack, - typename Traits::Type::Scope** scope_stack, - typename Traits::Type::Scope** scope, - typename Traits::Type::Factory* factory) - : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), - next_handler_index_(0), - expected_property_count_(0), - is_generator_(false), - generator_object_variable_(NULL), - function_state_stack_(function_state_stack), - outer_function_state_(*function_state_stack), - scope_stack_(scope_stack), - outer_scope_(*scope_stack), - factory_(factory) { - *scope_stack_ = *scope; - *function_state_stack = this; -} - - template ParserBase::FunctionState::~FunctionState() { *scope_stack_ = outer_scope_; @@ -2636,7 +2605,8 @@ typename ParserBase::ExpressionT ParserBase< { typename Traits::Type::Factory function_factory( zone(), this->ast_value_factory(), ast_node_id_gen_); - FunctionState function_state(&function_state_, &scope_, &scope, + FunctionState function_state(&function_state_, &scope_, + Traits::Type::ptr_to_scope(scope), &function_factory); Scanner::Location dupe_error_loc = Scanner::Location::invalid(); num_parameters = Traits::DeclareArrowParametersFromExpression( @@ -2751,14 +2721,14 @@ typename ParserBase::ExpressionT ParserBase::ParseClassLiteral( ExpressionT extends = this->EmptyExpression(); if (Check(Token::EXTENDS)) { typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE); - BlockState block_state(&scope_, &scope); + BlockState block_state(&scope_, Traits::Type::ptr_to_scope(scope)); scope_->SetStrictMode(STRICT); extends = this->ParseLeftHandSideExpression(CHECK_OK); } // TODO(arv): Implement scopes and name binding in class body only. typename Traits::Type::ScopePtr scope = this->NewScope(scope_, BLOCK_SCOPE); - BlockState block_state(&scope_, &scope); + BlockState block_state(&scope_, Traits::Type::ptr_to_scope(scope)); scope_->SetStrictMode(STRICT); scope_->SetScopeName(name);