[Mesa-dev] [PATCH 01/32] glsl: Replace most default cases in switches on GLSL type

Ian Romanick idr at freedesktop.org
Tue Jan 22 00:51:52 PST 2013


From: Ian Romanick <ian.d.romanick at intel.com>

This makes it easier to find switch-statements that need to be updated
after a new GLSL_TYPE_* is added because the compiler will generate a
warning.

Switch-statements that only had a small number of cases (e.g.,
everything in ir_constant_expression.cpp) were not modified.  I may
regret that decision when we eventually add support for doubles.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/ast_to_hir.cpp                        |  4 ----
 src/glsl/glsl_types.cpp                        |  8 ++++++--
 src/glsl/ir_clone.cpp                          |  8 ++++++--
 src/glsl/link_uniform_initializers.cpp         |  5 ++++-
 src/mesa/drivers/dri/i965/brw_fs.cpp           |  7 +++++--
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp   |  3 ++-
 src/mesa/drivers/dri/i965/brw_shader.cpp       |  7 +++++--
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp |  7 +++++--
 src/mesa/program/ir_to_mesa.cpp                | 14 ++++++++++----
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp     |  8 +++++---
 10 files changed, 48 insertions(+), 23 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index de3ce90..e016ccf 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -861,10 +861,6 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
        * ignores the sampler present in the type.
        */
       break;
-
-   default:
-      assert(!"Should not get here.");
-      break;
    }
 
    if (cmp == NULL)
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 71b1850..7386760 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -672,9 +672,13 @@ glsl_type::component_slots() const
    case GLSL_TYPE_ARRAY:
       return this->length * this->fields.array->component_slots();
 
-   default:
-      return 0;
+   case GLSL_TYPE_SAMPLER:
+   case GLSL_TYPE_VOID:
+   case GLSL_TYPE_ERROR:
+      break;
    }
+
+   return 0;
 }
 
 bool
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index c62c1fc..9b7981b 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -375,10 +375,14 @@ ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
       return c;
    }
 
-   default:
+   case GLSL_TYPE_SAMPLER:
+   case GLSL_TYPE_VOID:
+   case GLSL_TYPE_ERROR:
       assert(!"Should not get here.");
-      return NULL;
+      break;
    }
+
+   return NULL;
 }
 
 
diff --git a/src/glsl/link_uniform_initializers.cpp b/src/glsl/link_uniform_initializers.cpp
index 849e080..933df29 100644
--- a/src/glsl/link_uniform_initializers.cpp
+++ b/src/glsl/link_uniform_initializers.cpp
@@ -67,7 +67,10 @@ copy_constant_to_storage(union gl_constant_value *storage,
       case GLSL_TYPE_BOOL:
 	 storage[i].b = int(val->value.b[i]);
 	 break;
-      default:
+      case GLSL_TYPE_ARRAY:
+      case GLSL_TYPE_STRUCT:
+      case GLSL_TYPE_VOID:
+      case GLSL_TYPE_ERROR:
 	 /* All other types should have already been filtered by other
 	  * paths in the caller.
 	  */
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 0d2dde7..03b0630 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -455,10 +455,13 @@ fs_visitor::type_size(const struct glsl_type *type)
        * link time.
        */
       return 0;
-   default:
+   case GLSL_TYPE_VOID:
+   case GLSL_TYPE_ERROR:
       assert(!"not reached");
-      return 0;
+      break;
    }
+
+   return 0;
 }
 
 fs_reg
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 5885989..07df1a8 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -683,7 +683,8 @@ fs_visitor::emit_assignment_writes(fs_reg &l, fs_reg &r,
    case GLSL_TYPE_SAMPLER:
       break;
 
-   default:
+   case GLSL_TYPE_VOID:
+   case GLSL_TYPE_ERROR:
       assert(!"not reached");
       break;
    }
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index 7539d54..49e24d2 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -253,10 +253,13 @@ brw_type_for_base_type(const struct glsl_type *type)
        * way to trip up if we don't.
        */
       return BRW_REGISTER_TYPE_UD;
-   default:
+   case GLSL_TYPE_VOID:
+   case GLSL_TYPE_ERROR:
       assert(!"not reached");
-      return BRW_REGISTER_TYPE_F;
+      break;
    }
+
+   return BRW_REGISTER_TYPE_F;
 }
 
 uint32_t
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index ebf8990..7eda0fb 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -394,10 +394,13 @@ type_size(const struct glsl_type *type)
        * at link time.
        */
       return 1;
-   default:
+   case GLSL_TYPE_VOID:
+   case GLSL_TYPE_ERROR:
       assert(0);
-      return 0;
+      break;
    }
+
+   return 0;
 }
 
 int
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 0f7439b..18527e6 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -623,10 +623,13 @@ type_size(const struct glsl_type *type)
        * at link time.
        */
       return 1;
-   default:
-      assert(0);
-      return 0;
+   case GLSL_TYPE_VOID:
+   case GLSL_TYPE_ERROR:
+      assert(!"Invalid type in type_size");
+      break;
    }
+
+   return 0;
 }
 
 /**
@@ -2522,7 +2525,10 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
 	    format = uniform_native;
 	    columns = 1;
 	    break;
-	 default:
+         case GLSL_TYPE_ARRAY:
+         case GLSL_TYPE_VOID:
+         case GLSL_TYPE_STRUCT:
+         case GLSL_TYPE_ERROR:
 	    assert(!"Should not get here.");
 	    break;
 	 }
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 1d96e90..7326e06 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -984,10 +984,12 @@ type_size(const struct glsl_type *type)
        * at link time.
        */
       return 1;
-   default:
-      assert(0);
-      return 0;
+   case GLSL_TYPE_VOID:
+   case GLSL_TYPE_ERROR:
+      assert(!"Invalid type in type_size");
+      break;
    }
+   return 0;
 }
 
 /**
-- 
1.7.11.7



More information about the mesa-dev mailing list