mesa: set up gl_vert_result and gl_frag_attrib values for gl_ClipDistance.
[mesa.git] / src / glsl / ir_function.cpp
index eca0079c1666a3a7fb885934cf5f967b7666f570..51d32b46f98425a46326117a64452527b38abddd 100644 (file)
 #include "glsl_types.h"
 #include "ir.h"
 
-int
-type_compare(const glsl_type *a, const glsl_type *b)
-{
-   /* If the types are the same, they trivially match.
-    */
-   if (a == b)
-      return 0;
-
-   switch (a->base_type) {
-   case GLSL_TYPE_UINT:
-   case GLSL_TYPE_INT:
-   case GLSL_TYPE_BOOL:
-      /* There is no implicit conversion to or from integer types or bool.
-       */
-      if ((a->is_integer() != b->is_integer())
-         || (a->is_boolean() != b->is_boolean()))
-        return -1;
-
-      /* FALLTHROUGH */
-
-   case GLSL_TYPE_FLOAT:
-      if ((a->vector_elements != b->vector_elements)
-         || (a->matrix_columns != b->matrix_columns))
-        return -1;
-
-      return 1;
-
-   case GLSL_TYPE_SAMPLER:
-   case GLSL_TYPE_STRUCT:
-      /* Samplers and structures must match exactly.
-       */
-      return -1;
-
-   case GLSL_TYPE_ARRAY:
-      if ((b->base_type != GLSL_TYPE_ARRAY)
-         || (a->length != b->length))
-        return -1;
-
-      /* From GLSL 1.50 spec, page 27 (page 33 of the PDF):
-       *    "There are no implicit array or structure conversions."
-       *
-       * If the comparison of the array element types detects that a conversion
-       * would be required, the array types do not match.
-       */
-      return (type_compare(a->fields.array, b->fields.array) == 0) ? 0 : -1;
-
-   case GLSL_TYPE_VOID:
-   case GLSL_TYPE_ERROR:
-   default:
-      /* These are all error conditions.  It is invalid for a parameter to
-       * a function to be declared as error, void, or a function.
-       */
-      return -1;
-   }
-
-   /* This point should be unreachable.
-    */
-   assert(0);
-}
-
+typedef enum {
+   PARAMETER_LIST_NO_MATCH,
+   PARAMETER_LIST_EXACT_MATCH,
+   PARAMETER_LIST_INEXACT_MATCH /*< Match requires implicit conversion. */
+} parameter_list_match_t;
 
 /**
  * \brief Check if two parameter lists match.
  *
  * \param list_a Parameters of the function definition.
  * \param list_b Actual parameters passed to the function.
- * \return If an exact match, return 0.
- *         If an inexact match requiring implicit conversion, return 1.
- *         If not a match, return -1.
  * \see matching_signature()
  */
-static int
+static parameter_list_match_t
 parameter_lists_match(const exec_list *list_a, const exec_list *list_b)
 {
    const exec_node *node_a = list_a->head;
@@ -113,7 +55,7 @@ parameter_lists_match(const exec_list *list_a, const exec_list *list_b)
        * do not match.
        */
       if (node_b->is_tail_sentinel())
-        return -1;
+        return PARAMETER_LIST_NO_MATCH;
 
 
       const ir_variable *const param = (ir_variable *) node_a;
@@ -133,17 +75,17 @@ parameter_lists_match(const exec_list *list_a, const exec_list *list_b)
          * as uniform.
          */
         assert(0);
-        return -1;
+        return PARAMETER_LIST_NO_MATCH;
 
       case ir_var_const_in:
       case ir_var_in:
         if (!actual->type->can_implicitly_convert_to(param->type))
-           return -1;
+           return PARAMETER_LIST_NO_MATCH;
         break;
 
       case ir_var_out:
         if (!param->type->can_implicitly_convert_to(actual->type))
-           return -1;
+           return PARAMETER_LIST_NO_MATCH;
         break;
 
       case ir_var_inout:
@@ -151,11 +93,11 @@ parameter_lists_match(const exec_list *list_a, const exec_list *list_b)
          * there is int -> float but no float -> int), inout parameters must
          * be exact matches.
          */
-        return -1;
+        return PARAMETER_LIST_NO_MATCH;
 
       default:
         assert(false);
-        return -1;
+        return PARAMETER_LIST_NO_MATCH;
       }
    }
 
@@ -164,12 +106,12 @@ parameter_lists_match(const exec_list *list_a, const exec_list *list_b)
     * match.
     */
    if (!node_b->is_tail_sentinel())
-      return -1;
+      return PARAMETER_LIST_NO_MATCH;
 
    if (inexact_match)
-      return 1;
+      return PARAMETER_LIST_INEXACT_MATCH;
    else
-      return 0;
+      return PARAMETER_LIST_EXACT_MATCH;
 }
 
 
@@ -193,18 +135,20 @@ ir_function::matching_signature(const exec_list *actual_parameters)
       ir_function_signature *const sig =
         (ir_function_signature *) iter.get();
 
-      const int score = parameter_lists_match(& sig->parameters,
-                                             actual_parameters);
-
-      /* If we found an exact match, simply return it */
-      if (score == 0)
+      switch (parameter_lists_match(& sig->parameters, actual_parameters)) {
+      case PARAMETER_LIST_EXACT_MATCH:
         return sig;
-
-      if (score > 0) {
+      case PARAMETER_LIST_INEXACT_MATCH:
         if (match == NULL)
            match = sig;
         else
            multiple_inexact_matches = true;
+        continue;
+      case PARAMETER_LIST_NO_MATCH:
+        continue;
+      default:
+        assert(false);
+        return NULL;
       }
    }