[turbofan] Make ContextScope a proper encapsulation of the current context.
authortitzer <titzer@chromium.org>
Wed, 4 Feb 2015 09:59:48 +0000 (01:59 -0800)
committerCommit bot <commit-bot@chromium.org>
Wed, 4 Feb 2015 09:59:55 +0000 (09:59 +0000)
R=mstarzinger@chromium.org
BUG=

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

Cr-Commit-Position: refs/heads/master@{#26421}

src/compiler/ast-graph-builder.cc
src/compiler/ast-graph-builder.h

index 627b2c1..c6a7954 100644 (file)
@@ -105,28 +105,28 @@ class AstGraphBuilder::AstTestContext FINAL : public AstContext {
 // change the current {scope} and {context} during visitation.
 class AstGraphBuilder::ContextScope BASE_EMBEDDED {
  public:
-  ContextScope(AstGraphBuilder* owner, Scope* scope, Node* context)
-      : owner_(owner),
-        next_(owner->execution_context()),
-        outer_(owner->current_context()),
-        scope_(scope) {
-    owner_->set_execution_context(this);  // Push.
-    owner_->set_current_context(context);
+  ContextScope(AstGraphBuilder* builder, Scope* scope, Node* context)
+      : builder_(builder),
+        outer_(builder->execution_context()),
+        scope_(scope),
+        context_(context) {
+    builder_->set_execution_context(this);  // Push.
   }
 
   ~ContextScope() {
-    owner_->set_execution_context(next_);  // Pop.
-    owner_->set_current_context(outer_);
+    builder_->set_execution_context(outer_);  // Pop.
   }
 
   // Current scope during visitation.
   Scope* scope() const { return scope_; }
+  // Current context node during visitation.
+  Node* context() const { return context_; }
 
  private:
-  AstGraphBuilder* owner_;
-  ContextScope* next_;
-  Node* outer_;
+  AstGraphBuilder* builder_;
+  ContextScope* outer_;
   Scope* scope_;
+  Node* context_;
 };
 
 
@@ -141,13 +141,13 @@ class AstGraphBuilder::ControlScope BASE_EMBEDDED {
  public:
   ControlScope(AstGraphBuilder* builder, int stack_delta)
       : builder_(builder),
-        next_(builder->execution_control()),
+        outer_(builder->execution_control()),
         stack_delta_(stack_delta) {
     builder_->set_execution_control(this);  // Push.
   }
 
   virtual ~ControlScope() {
-    builder_->set_execution_control(next_);  // Pop.
+    builder_->set_execution_control(outer_);  // Pop.
   }
 
   // Either 'break' or 'continue' to the target statement.
@@ -193,7 +193,7 @@ class AstGraphBuilder::ControlScope BASE_EMBEDDED {
 
  private:
   AstGraphBuilder* builder_;
-  ControlScope* next_;
+  ControlScope* outer_;
   int stack_delta_;
 };
 
@@ -380,7 +380,6 @@ AstGraphBuilder::AstGraphBuilder(Zone* local_zone, CompilationInfo* info,
       execution_context_(nullptr),
       input_buffer_size_(0),
       input_buffer_(nullptr),
-      current_context_(nullptr),
       exit_control_(nullptr),
       loop_assignment_analysis_(loop) {
   InitializeAstVisitor(info->isolate(), local_zone);
@@ -431,8 +430,8 @@ bool AstGraphBuilder::CreateGraph() {
   }
 
   // Initialize the incoming context.
-  Node* outer_context = GetFunctionContext();
-  set_current_context(outer_context);
+  Node* incoming_context = GetFunctionContext();
+  ContextScope incoming(this, scope, incoming_context);
 
   // Build receiver check for sloppy mode if necessary.
   // TODO(mstarzinger/verwaest): Should this be moved back into the CallIC?
@@ -442,9 +441,9 @@ bool AstGraphBuilder::CreateGraph() {
 
   // Build node to initialize local function context.
   Node* closure = GetFunctionClosure();
-  Node* inner_context = BuildLocalFunctionContext(outer_context, closure);
+  Node* inner_context = BuildLocalFunctionContext(incoming_context, closure);
 
-  // Push top-level function scope for the function body.
+  // Push top-level function context for the function body.
   ContextScope top_context(this, scope, inner_context);
 
   // Build the arguments object if it is used.
@@ -655,6 +654,11 @@ Scope* AstGraphBuilder::current_scope() const {
 }
 
 
+Node* AstGraphBuilder::current_context() const {
+  return execution_context_->context();
+}
+
+
 void AstGraphBuilder::ControlScope::PerformCommand(Command command,
                                                    Statement* target,
                                                    Node* value) {
@@ -663,7 +667,7 @@ void AstGraphBuilder::ControlScope::PerformCommand(Command command,
   while (current != NULL) {
     if (current->Execute(command, target, value)) break;
     environment()->Drop(current->stack_delta());
-    current = current->next_;
+    current = current->outer_;
   }
   builder()->set_environment(env);
   DCHECK(current != NULL);  // Always handled (unless stack is malformed).
@@ -2409,7 +2413,6 @@ Node* AstGraphBuilder::BuildLocalFunctionContext(Node* context, Node* closure) {
   // Allocate a new local context.
   const Operator* op = javascript()->CreateFunctionContext();
   Node* local_context = NewNode(op, closure);
-  set_current_context(local_context);
 
   // Copy parameters into context if necessary.
   int num_parameters = info()->scope()->num_parameters();
index cb564d8..6da40f4 100644 (file)
@@ -98,9 +98,6 @@ class AstGraphBuilder : public AstVisitor {
   // Node representing the control dependency for dead code.
   SetOncePointer<Node> dead_control_;
 
-  // Node representing the current context within the function body.
-  Node* current_context_;
-
   // Merge of all control nodes that exit the function body.
   Node* exit_control_;
 
@@ -125,7 +122,7 @@ class AstGraphBuilder : public AstVisitor {
   JSOperatorBuilder* javascript() { return jsgraph_->javascript(); }
   ZoneVector<Handle<Object>>* globals() { return &globals_; }
   Scope* current_scope() const;
-  Node* current_context() const { return current_context_; }
+  Node* current_context() const;
   Node* dead_control();
   Node* exit_control() const { return exit_control_; }
 
@@ -133,7 +130,6 @@ class AstGraphBuilder : public AstVisitor {
   void set_ast_context(AstContext* ctx) { ast_context_ = ctx; }
   void set_execution_control(ControlScope* ctrl) { execution_control_ = ctrl; }
   void set_execution_context(ContextScope* ctx) { execution_context_ = ctx; }
-  void set_current_context(Node* ctx) { current_context_ = ctx; }
   void set_exit_control(Node* exit) { exit_control_ = exit; }
 
   // Node creation helpers.