Matteo Bruni : d3dcompiler: Add hlsl_report_message function to standardize error messages.

Alexandre Julliard julliard at winehq.org
Thu Jul 12 18:00:32 CDT 2012


Module: wine
Branch: master
Commit: 632703d8cfdaefc9dffeb124970e28d20471a535
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=632703d8cfdaefc9dffeb124970e28d20471a535

Author: Matteo Bruni <mbruni at codeweavers.com>
Date:   Thu Jul 12 16:01:32 2012 +0200

d3dcompiler: Add hlsl_report_message function to standardize error messages.

---

 dlls/d3dcompiler_43/d3dcompiler_private.h |    9 +++++
 dlls/d3dcompiler_43/hlsl.y                |   55 +++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h
index ccac936..aa02eb9 100644
--- a/dlls/d3dcompiler_43/d3dcompiler_private.h
+++ b/dlls/d3dcompiler_43/d3dcompiler_private.h
@@ -840,7 +840,16 @@ struct hlsl_parse_ctx
 
 extern struct hlsl_parse_ctx hlsl_ctx DECLSPEC_HIDDEN;
 
+enum hlsl_error_level
+{
+    HLSL_LEVEL_ERROR = 0,
+    HLSL_LEVEL_WARNING,
+    HLSL_LEVEL_NOTE,
+};
+
 void hlsl_message(const char *fmt, ...) PRINTF_ATTR(1,2) DECLSPEC_HIDDEN;
+void hlsl_report_message(const char *filename, DWORD line, DWORD column,
+        enum hlsl_error_level level, const char *fmt, ...) PRINTF_ATTR(5,6) DECLSPEC_HIDDEN;
 
 static inline struct hlsl_ir_deref *deref_from_node(const struct hlsl_ir_node *node)
 {
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
index 03aa4eb..240eaaf 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -41,10 +41,61 @@ void hlsl_message(const char *fmt, ...)
     va_end(args);
 }
 
+static const char *hlsl_get_error_level_name(enum hlsl_error_level level)
+{
+    const char *names[] =
+    {
+        "error",
+        "warning",
+        "note",
+    };
+    return names[level];
+}
+
+void hlsl_report_message(const char *filename, DWORD line, DWORD column,
+        enum hlsl_error_level level, const char *fmt, ...)
+{
+    va_list args;
+    char *string = NULL;
+    int rc, size = 0;
+
+    while (1)
+    {
+        va_start(args, fmt);
+        rc = vsnprintf(string, size, fmt, args);
+        va_end(args);
+
+        if (rc >= 0 && rc < size)
+            break;
+
+        if (rc >= size)
+            size = rc + 1;
+        else
+            size = size ? size * 2 : 32;
+
+        if (!string)
+            string = d3dcompiler_alloc(size);
+        else
+            string = d3dcompiler_realloc(string, size);
+        if (!string)
+        {
+            ERR("Error reallocating memory for a string.\n");
+            return;
+        }
+    }
+
+    hlsl_message("%s:%u:%u: %s: %s\n", filename, line, column, hlsl_get_error_level_name(level), string);
+    d3dcompiler_free(string);
+
+    if (level == HLSL_LEVEL_ERROR)
+        set_parse_status(&hlsl_ctx.status, PARSE_ERR);
+    else if (level == HLSL_LEVEL_WARNING)
+        set_parse_status(&hlsl_ctx.status, PARSE_WARN);
+}
+
 static void hlsl_error(const char *s)
 {
-    hlsl_message("Line %u: %s\n", hlsl_ctx.line_no, s);
-    set_parse_status(&hlsl_ctx.status, PARSE_ERR);
+    hlsl_report_message(hlsl_ctx.source_file, hlsl_ctx.line_no, 1, HLSL_LEVEL_ERROR, "%s", s);
 }
 
 static void debug_dump_decl(struct hlsl_type *type, DWORD modifiers, const char *declname, unsigned int line_no)




More information about the wine-cvs mailing list