ir_constant: Support constant structures in clone
authorIan Romanick <ian.d.romanick@intel.com>
Thu, 10 Jun 2010 00:18:04 +0000 (17:18 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 11 Jun 2010 20:51:42 +0000 (13:51 -0700)
ir.cpp
ir.h

diff --git a/ir.cpp b/ir.cpp
index b60d1b468aa6ff1f83a1687b3e43366081436c49..bb1c4589a57be6d31657f68b595c045fe901b031 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -184,6 +184,11 @@ ir_expression::get_operator(const char *str)
    return (ir_expression_operation) -1;
 }
 
+ir_constant::ir_constant()
+{
+   /* empty */
+}
+
 ir_constant::ir_constant(const struct glsl_type *type, const void *data)
 {
    unsigned size = 0;
@@ -301,6 +306,37 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
    }
 }
 
+ir_constant *
+ir_constant::clone()
+{
+   switch (this->type->base_type) {
+   case GLSL_TYPE_UINT:
+   case GLSL_TYPE_INT:
+   case GLSL_TYPE_FLOAT:
+   case GLSL_TYPE_BOOL:
+      return new ir_constant(this->type, &this->value);
+
+   case GLSL_TYPE_STRUCT: {
+      ir_constant *c = new ir_constant;
+
+      c->type = this->type;
+      for (exec_node *node = this->components.head
+             ; !node->is_tail_sentinal()
+             ; node = node->next) {
+        ir_constant *const orig = (ir_constant *) node;
+
+        c->components.push_tail(orig->clone());
+      }
+
+      return c;
+   }
+
+   default:
+      assert(!"Should not get here."); break;
+      return NULL;
+   }
+}
+
 bool
 ir_constant::get_bool_component(unsigned i) const
 {
diff --git a/ir.h b/ir.h
index 8fd823db09c0b4bd3b020ac4d16dce8e92d22bf1..86beb2d7ce6712169cbd822e263ed9dff5d1ff33 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -1055,10 +1055,7 @@ public:
 
    virtual ir_visitor_status accept(ir_hierarchical_visitor *);
 
-   ir_constant *clone()
-   {
-      return new ir_constant(this->type, &this->value);
-   }
+   ir_constant *clone();
 
    /**
     * Get a particular component of a constant as a specific type
@@ -1089,6 +1086,12 @@ public:
    } value;
 
    exec_list components;
+
+private:
+   /**
+    * Parameterless constructor only used by the clone method
+    */
+   ir_constant(void);
 };
 
 void