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

nobled nobled at dreamwidth.org
Fri Apr 13 08:51:35 PDT 2012


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);
    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");
 }


-- 
1.7.4.1


More information about the mesa-dev mailing list