Reviewers: Sven Panne,

Message:
Sven, WDYT?

Description:
Simplify Scope and ScopePtr conversions.

[email protected]

Please review this at https://codereview.chromium.org/643603002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+9, -39 lines):
  M src/parser.h
  M src/preparser.h


Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index e461a99d84cfdcd6a13a4a9c2d81ab5fa1647581..14b139d36ba2215dc5d30baeec9c5d1104896afe 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -352,6 +352,9 @@ 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;

Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 1def94f9296c728f83dad87a82ef795e2512aaba..951dc4dcfa652f5aed84e5410a759feebda6e764 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:
@@ -173,12 +166,6 @@ class ParserBase : public Traits {
                   typename Traits::Type::Zone* zone = NULL,
                   AstValueFactory* ast_value_factory = NULL,
                   AstNode::IdGen* ast_node_id_gen = NULL);
-    FunctionState(FunctionState** function_state_stack,
-                  typename Traits::Type::Scope** scope_stack,
-                  typename Traits::Type::Scope** scope,
-                  typename Traits::Type::Zone* zone = NULL,
-                  AstValueFactory* ast_value_factory = NULL,
-                  AstNode::IdGen* ast_node_id_gen = NULL);
     ~FunctionState();

     int NextMaterializedLiteralIndex() {
@@ -1130,6 +1117,8 @@ class PreParserTraits {
     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;
     // No interaction with Zones.
@@ -1594,29 +1583,6 @@ ParserBase<Traits>::FunctionState::FunctionState(


 template <class Traits>
-ParserBase<Traits>::FunctionState::FunctionState(
-    FunctionState** function_state_stack,
-    typename Traits::Type::Scope** scope_stack,
- typename Traits::Type::Scope** scope, typename Traits::Type::Zone* zone,
-    AstValueFactory* ast_value_factory, AstNode::IdGen* ast_node_id_gen)
-    : 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),
-      ast_node_id_gen_(ast_node_id_gen),
-      factory_(zone, ast_value_factory, ast_node_id_gen) {
-  *scope_stack_ = *scope;
-  *function_state_stack = this;
-  Traits::SetUpFunctionState(this);
-}
-
-
-template <class Traits>
 ParserBase<Traits>::FunctionState::~FunctionState() {
   *scope_stack_ = outer_scope_;
   *function_state_stack_ = outer_function_state_;
@@ -2653,7 +2619,8 @@ typename ParserBase<Traits>::ExpressionT ParserBase<
   int handler_count = 0;

   {
-    FunctionState function_state(&function_state_, &scope_, &scope, zone(),
+    FunctionState function_state(&function_state_, &scope_,
+                                 Traits::Type::ptr_to_scope(scope), zone(),
this->ast_value_factory(), ast_node_id_gen_);
     Scanner::Location dupe_error_loc = Scanner::Location::invalid();
     num_parameters = Traits::DeclareArrowParametersFromExpression(
@@ -2768,14 +2735,14 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::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);



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to