[Mesa-dev] [PATCH 5/5] glsl: Clarify ir_function::matching_sigature()

Kenneth Graunke kenneth at whitecape.org
Fri Jul 29 14:11:12 PDT 2011


On 07/27/2011 10:55 PM, Chad Versace wrote:
> The function used a variable named 'score', which was an outright lie.
> A signature matches or it doesn't; there is no fuzzy scoring.
> 
> CC: Ian Romanick <ian.d.romanick at intel.com>
> CC: Kenneth Graunke <kenneth at whitecape.org>
> Signed-off-by: Chad Versace <chad at chad-versace.us>
> ---
>  src/glsl/ir_function.cpp |   19 ++++++++++++-------
>  1 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/src/glsl/ir_function.cpp b/src/glsl/ir_function.cpp
> index e25b094..5a2c9bb 100644
> --- a/src/glsl/ir_function.cpp
> +++ b/src/glsl/ir_function.cpp
> @@ -134,18 +134,23 @@ 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 0:
> +	 /* Exact match. */
>  	 return sig;
> -
> -      if (score > 0) {
> +      case 1:

I like the switch statement, but it'd be even clearer to use an enum.

> +	 /* Inexact match that requires implicit conversion. */
>  	 if (match == NULL)
>  	    match = sig;
>  	 else
>  	    multiple_inexact_matches = true;
> +	 continue;
> +      case -1:
> +	 /* Not a match. */
> +	 continue;
> +      default:
> +	 assert(false);
> +	 return NULL;
>        }
>     }


More information about the mesa-dev mailing list