[Mesa-dev] [PATCH 5/9] glcpp: consolidate error/warning code

nobled nobled at dreamwidth.org
Fri Apr 13 08:52:02 PDT 2012


---
 src/glsl/glcpp/pp.c |   33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/glsl/glcpp/pp.c b/src/glsl/glcpp/pp.c
index 3640896..b0afed4 100644
--- a/src/glsl/glcpp/pp.c
+++ b/src/glsl/glcpp/pp.c
@@ -27,21 +27,32 @@
 #include "glcpp.h"
 #include "main/core.h" /* for isblank() on MSVC */

+static void
+glcpp_msg (YYLTYPE *locp, glcpp_parser_t *parser, bool error,
+           const char *fmt, va_list ap)
+{
+	ralloc_asprintf_append(&parser->info_log, "%u:%u(%u): "
+						  "preprocessor %s: ",
+						  locp->source,
+						  locp->first_line,
+						  locp->first_column,
+						  error ? "error" : "warning");
+
+	ralloc_vasprintf_append(&parser->info_log, fmt, ap);
+
+	ralloc_strcat(&parser->info_log, "\n");
+}
+
 void
 glcpp_error (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...)
 {
 	va_list ap;

 	parser->error = 1;
-	ralloc_asprintf_append(&parser->info_log, "%u:%u(%u): "
-						  "preprocessor error: ",
-						  locp->source,
-						  locp->first_line,
-						  locp->first_column);
+
 	va_start(ap, fmt);
-	ralloc_vasprintf_append(&parser->info_log, fmt, ap);
+	glcpp_msg(locp, parser, true, fmt, ap);
 	va_end(ap);
-	ralloc_strcat(&parser->info_log, "\n");
 }

 void
@@ -49,15 +60,9 @@ glcpp_warning (YYLTYPE *locp, glcpp_parser_t
*parser, const char *fmt, ...)
 {
 	va_list ap;

-	ralloc_asprintf_append(&parser->info_log, "%u:%u(%u): "
-						  "preprocessor warning: ",
-						  locp->source,
-						  locp->first_line,
-						  locp->first_column);
 	va_start(ap, fmt);
-	ralloc_vasprintf_append(&parser->info_log, fmt, ap);
+	glcpp_msg(locp, parser, false, fmt, ap);
 	va_end(ap);
-	ralloc_strcat(&parser->info_log, "\n");
 }

 /* Searches backwards for '^ *#' from a given starting point. */
-- 
1.7.4.1


More information about the mesa-dev mailing list