Matteo Bruni : d3dcompiler: Track the location of each lexer token.

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


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

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

d3dcompiler: Track the location of each lexer token.

---

 dlls/d3dcompiler_43/d3dcompiler_private.h |    7 ++++-
 dlls/d3dcompiler_43/hlsl.l                |    9 ++++++++
 dlls/d3dcompiler_43/hlsl.y                |   30 ++++++++++++++++++++++++----
 3 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/dlls/d3dcompiler_43/d3dcompiler_private.h b/dlls/d3dcompiler_43/d3dcompiler_private.h
index aa02eb9..1286f00 100644
--- a/dlls/d3dcompiler_43/d3dcompiler_private.h
+++ b/dlls/d3dcompiler_43/d3dcompiler_private.h
@@ -705,7 +705,7 @@ struct hlsl_ir_node
     enum hlsl_ir_node_type type;
     struct hlsl_type *data_type;
 
-    char *source_file;
+    const char *source_file;
     unsigned int line;
     unsigned int column;
 };
@@ -823,8 +823,11 @@ struct parse_variable_def
 
 struct hlsl_parse_ctx
 {
-    char *source_file;
+    const char **source_files;
+    unsigned int source_files_count;
+    const char *source_file;
     unsigned int line_no;
+    unsigned int column;
     enum parse_status status;
     struct compilation_messages messages;
 
diff --git a/dlls/d3dcompiler_43/hlsl.l b/dlls/d3dcompiler_43/hlsl.l
index 55b6b63..1e3b4a9 100644
--- a/dlls/d3dcompiler_43/hlsl.l
+++ b/dlls/d3dcompiler_43/hlsl.l
@@ -29,6 +29,14 @@
 #include "hlsl.tab.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser);
+
+#define YY_USER_ACTION                               \
+   do {                                              \
+      hlsl_lloc.first_column = hlsl_ctx.column;      \
+      hlsl_lloc.first_line = hlsl_ctx.line_no;       \
+      hlsl_ctx.column += yyleng;                     \
+   } while(0);
+
 %}
 
 %option noyywrap nounput noinput
@@ -206,6 +214,7 @@ row_major               {return KW_ROW_MAJOR;           }
 {WS}+                   {}
 {NEWLINE}               {
                             hlsl_ctx.line_no++;
+                            hlsl_ctx.column = 1;
                         }
 
 ^#                      {
diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
index 240eaaf..48c43a2 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -95,7 +95,7 @@ void hlsl_report_message(const char *filename, DWORD line, DWORD column,
 
 static void hlsl_error(const char *s)
 {
-    hlsl_report_message(hlsl_ctx.source_file, hlsl_ctx.line_no, 1, HLSL_LEVEL_ERROR, "%s", s);
+    hlsl_report_message(hlsl_ctx.source_file, hlsl_ctx.line_no, hlsl_ctx.column, HLSL_LEVEL_ERROR, "%s", s);
 }
 
 static void debug_dump_decl(struct hlsl_type *type, DWORD modifiers, const char *declname, unsigned int line_no)
@@ -177,6 +177,7 @@ static unsigned int components_count_expr_list(struct list *list)
 
 %}
 
+%locations
 %error-verbose
 
 %union
@@ -360,8 +361,19 @@ preproc_directive:        PRE_LINE STRING
                             {
                                 TRACE("Updating line information to file %s, line %u\n", debugstr_a($2), $1);
                                 hlsl_ctx.line_no = $1;
-                                d3dcompiler_free(hlsl_ctx.source_file);
-                                hlsl_ctx.source_file = $2;
+                                if (strcmp($2, hlsl_ctx.source_file))
+                                {
+                                    const char **new_array;
+
+                                    hlsl_ctx.source_file = $2;
+                                    new_array = d3dcompiler_realloc(hlsl_ctx.source_files,
+                                            sizeof(*hlsl_ctx.source_files) * hlsl_ctx.source_files_count + 1);
+                                    if (new_array)
+                                    {
+                                        hlsl_ctx.source_files = new_array;
+                                        hlsl_ctx.source_files[hlsl_ctx.source_files_count++] = $2;
+                                    }
+                                }
                             }
 
 any_identifier:           VAR_IDENTIFIER
@@ -978,11 +990,16 @@ struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD mino
     struct hlsl_scope *scope, *next_scope;
     struct hlsl_type *hlsl_type, *next_type;
     struct hlsl_ir_var *var, *next_var;
+    unsigned int i;
 
     hlsl_ctx.status = PARSE_SUCCESS;
     hlsl_ctx.messages.size = hlsl_ctx.messages.capacity = 0;
-    hlsl_ctx.line_no = 1;
+    hlsl_ctx.line_no = hlsl_ctx.column = 1;
     hlsl_ctx.source_file = d3dcompiler_strdup("");
+    hlsl_ctx.source_files = d3dcompiler_alloc(sizeof(*hlsl_ctx.source_files));
+    if (hlsl_ctx.source_files)
+        hlsl_ctx.source_files[0] = hlsl_ctx.source_file;
+    hlsl_ctx.source_files_count = 1;
     hlsl_ctx.cur_scope = NULL;
     hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR;
     list_init(&hlsl_ctx.scopes);
@@ -1020,7 +1037,10 @@ struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD mino
             d3dcompiler_free(hlsl_ctx.messages.string);
     }
 
-    d3dcompiler_free(hlsl_ctx.source_file);
+    for (i = 0; i < hlsl_ctx.source_files_count; ++i)
+        d3dcompiler_free((void *)hlsl_ctx.source_files[i]);
+    d3dcompiler_free(hlsl_ctx.source_files);
+
     TRACE("Freeing functions IR.\n");
     LIST_FOR_EACH_ENTRY(function, &hlsl_ctx.functions, struct hlsl_ir_function_decl, node.entry)
         free_function(function);




More information about the wine-cvs mailing list