[Mesa-dev] [PATCH 1/9] glsl: consolidate code

Kenneth Graunke kenneth at whitecape.org
Fri Apr 13 12:17:49 PDT 2012


On 04/13/2012 08:51 AM, nobled wrote:
> This function is about to get longer.
> ---
>   src/glsl/glsl_parser_extras.cpp |   29 +++++++++++++++--------------
>   1 files changed, 15 insertions(+), 14 deletions(-)
>
> diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
> index ae7a365..d14124f 100644
> --- a/src/glsl/glsl_parser_extras.cpp
> +++ b/src/glsl/glsl_parser_extras.cpp
> @@ -134,6 +134,19 @@ _mesa_glsl_shader_target_name(enum
> _mesa_glsl_parser_targets target)
>      return "unknown";
>   }
>
> +static void
> +_mesa_glsl_msg(const YYLTYPE *locp, _mesa_glsl_parse_state *state,
> +               bool error, const char *fmt, va_list ap)
> +{
> +   assert(state->info_log != NULL);
> +   ralloc_asprintf_append(&state->info_log, "%u:%u(%u): %s: ",
> +					    locp->source,
> +					    locp->first_line,
> +					    locp->first_column,
> +					    error ? "error" : "warning");
> +   ralloc_vasprintf_append(&state->info_log, fmt, ap);
> +   ralloc_strcat(&state->info_log, "\n");
> +}
>
>   void
>   _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state,
> @@ -143,15 +156,9 @@ _mesa_glsl_error(YYLTYPE *locp,
> _mesa_glsl_parse_state *state,
>
>      state->error = true;
>
> -   assert(state->info_log != NULL);
> -   ralloc_asprintf_append(&state->info_log, "%u:%u(%u): error: ",
> -					    locp->source,
> -					    locp->first_line,
> -					    locp->first_column);
>      va_start(ap, fmt);
> -   ralloc_vasprintf_append(&state->info_log, fmt, ap);
> +   _mesa_glsl_msg(locp, state, true, fmt, ap);

Hmm.  What do you think about changing the "bool error" parameter to 
"const char *msg_type"?  (Or "prefix" or such.)

Then, we could do:

    _mesa_glsl_msg(locp, state, "error", fmt, ap);
    _mesa_glsl_msg(locp, state, "warning", fmt, ap);

which seems a bit clearer than trying to figure out what true/false mean 
in this instance.

>      va_end(ap);
> -   ralloc_strcat(&state->info_log, "\n");
>   }
>
>
> @@ -161,15 +168,9 @@ _mesa_glsl_warning(const YYLTYPE *locp,
> _mesa_glsl_parse_state *state,
>   {
>      va_list ap;
>
> -   assert(state->info_log != NULL);
> -   ralloc_asprintf_append(&state->info_log, "%u:%u(%u): warning: ",
> -					    locp->source,
> -					    locp->first_line,
> -					    locp->first_column);
>      va_start(ap, fmt);
> -   ralloc_vasprintf_append(&state->info_log, fmt, ap);
> +   _mesa_glsl_msg(locp, state, false, fmt, ap);
>      va_end(ap);
> -   ralloc_strcat(&state->info_log, "\n");
>   }



More information about the mesa-dev mailing list