Mesa (master): glsl2: Set a flag when visiting the assignee of an assignment

Ian Romanick idr at kemper.freedesktop.org
Fri Sep 3 19:01:03 UTC 2010


Module: Mesa
Branch: master
Commit: c8ee8e07f7cc8f18d367ffcec065b45f8a6976f4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c8ee8e07f7cc8f18d367ffcec065b45f8a6976f4

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Thu Aug  5 15:29:24 2010 -0700

glsl2: Set a flag when visiting the assignee of an assignment

---

 src/glsl/ir_hierarchical_visitor.cpp |    1 +
 src/glsl/ir_hierarchical_visitor.h   |    7 +++++++
 src/glsl/ir_hv_accept.cpp            |    9 +++++++++
 src/glsl/ir_rvalue_visitor.cpp       |    7 +++++++
 4 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/src/glsl/ir_hierarchical_visitor.cpp b/src/glsl/ir_hierarchical_visitor.cpp
index 809b08e..b5eacd6 100644
--- a/src/glsl/ir_hierarchical_visitor.cpp
+++ b/src/glsl/ir_hierarchical_visitor.cpp
@@ -29,6 +29,7 @@ ir_hierarchical_visitor::ir_hierarchical_visitor()
    this->base_ir = NULL;
    this->callback = NULL;
    this->data = NULL;
+   this->in_assignee = false;
 }
 
 ir_visitor_status
diff --git a/src/glsl/ir_hierarchical_visitor.h b/src/glsl/ir_hierarchical_visitor.h
index afa780d..dc177f5 100644
--- a/src/glsl/ir_hierarchical_visitor.h
+++ b/src/glsl/ir_hierarchical_visitor.h
@@ -165,6 +165,13 @@ public:
     * Extra data parameter passed to the per-node callback function
     */
    void *data;
+
+   /**
+    * Currently in the LHS of an assignment?
+    *
+    * This is set and cleared by the \c ir_assignment::accept method.
+    */
+   bool in_assignee;
 };
 
 void visit_tree(ir_instruction *ir,
diff --git a/src/glsl/ir_hv_accept.cpp b/src/glsl/ir_hv_accept.cpp
index 6dae4ed..be8b36a 100644
--- a/src/glsl/ir_hv_accept.cpp
+++ b/src/glsl/ir_hv_accept.cpp
@@ -242,7 +242,14 @@ ir_dereference_array::accept(ir_hierarchical_visitor *v)
    if (s != visit_continue)
       return (s == visit_continue_with_parent) ? visit_continue : s;
 
+   /* The array index is not the target of the assignment, so clear the
+    * 'in_assignee' flag.  Restore it after returning from the array index.
+    */
+   const bool was_in_assignee = v->in_assignee;
+   v->in_assignee = false;
    s = this->array_index->accept(v);
+   v->in_assignee = was_in_assignee;
+
    if (s != visit_continue)
       return (s == visit_continue_with_parent) ? visit_continue : s;
 
@@ -270,7 +277,9 @@ ir_assignment::accept(ir_hierarchical_visitor *v)
    if (s != visit_continue)
       return (s == visit_continue_with_parent) ? visit_continue : s;
 
+   v->in_assignee = true;
    s = this->lhs->accept(v);
+   v->in_assignee = false;
    if (s != visit_continue)
       return (s == visit_continue_with_parent) ? visit_continue : s;
 
diff --git a/src/glsl/ir_rvalue_visitor.cpp b/src/glsl/ir_rvalue_visitor.cpp
index 613b07c..773bfcf 100644
--- a/src/glsl/ir_rvalue_visitor.cpp
+++ b/src/glsl/ir_rvalue_visitor.cpp
@@ -83,7 +83,14 @@ ir_rvalue_visitor::visit_leave(ir_swizzle *ir)
 ir_visitor_status
 ir_rvalue_visitor::visit_leave(ir_dereference_array *ir)
 {
+   /* The array index is not the target of the assignment, so clear the
+    * 'in_assignee' flag.  Restore it after returning from the array index.
+    */
+   const bool was_in_assignee = this->in_assignee;
+   this->in_assignee = false;
    handle_rvalue(&ir->array_index);
+   this->in_assignee = was_in_assignee;
+
    handle_rvalue(&ir->array);
    return visit_continue;
 }




More information about the mesa-commit mailing list