Mesa (master): glsl: Implement remaining as_foo functions with macros

Ian Romanick idr at kemper.freedesktop.org
Wed Mar 25 17:42:16 UTC 2015


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Mar 24 09:02:24 2015 -0700

glsl: Implement remaining as_foo functions with macros

The downcast functions for non-leaf classes were previously implemented
"by hand."  Now they are implemented using macros based on the is_foo
functions added in the previous patch.

v2: Remove redundant parenthesis.  Suggested by Curro (on the next
patch).

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Francisco Jerez <currojerez at riseup.net>

---

 src/glsl/ir.h |   40 +++++++++-------------------------------
 1 file changed, 9 insertions(+), 31 deletions(-)

diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index b3a98b8..0284b02 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -142,39 +142,17 @@ public:
     * Additional downcast functions will be added as needed.
     */
    /*@{*/
-   class ir_rvalue *as_rvalue()
-   {
-      assume(this != NULL);
-      if (ir_type == ir_type_dereference_array ||
-          ir_type == ir_type_dereference_record ||
-          ir_type == ir_type_dereference_variable ||
-          ir_type == ir_type_constant ||
-          ir_type == ir_type_expression ||
-          ir_type == ir_type_swizzle ||
-          ir_type == ir_type_texture)
-         return (class ir_rvalue *) this;
-      return NULL;
-   }
-
-   class ir_dereference *as_dereference()
-   {
-      assume(this != NULL);
-      if (ir_type == ir_type_dereference_array ||
-          ir_type == ir_type_dereference_record ||
-          ir_type == ir_type_dereference_variable)
-         return (class ir_dereference *) this;
-      return NULL;
+   #define AS_BASE(TYPE)                                \
+   class ir_##TYPE *as_##TYPE()                         \
+   {                                                    \
+      assume(this != NULL);                             \
+      return is_##TYPE() ? (ir_##TYPE *) this : NULL;   \
    }
 
-   class ir_jump *as_jump()
-   {
-      assume(this != NULL);
-      if (ir_type == ir_type_loop_jump ||
-          ir_type == ir_type_return ||
-          ir_type == ir_type_discard)
-         return (class ir_jump *) this;
-      return NULL;
-   }
+   AS_BASE(rvalue)
+   AS_BASE(dereference)
+   AS_BASE(jump)
+   #undef AS_BASE
 
    #define AS_CHILD(TYPE) \
    class ir_##TYPE * as_##TYPE() \




More information about the mesa-commit mailing list