d3dcompiler: Track the location of each lexer token.
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 @@
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 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 @@
{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 @@
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 @@
%}
+%locations
%error-verbose
%union
@@ -360,8 +361,19 @@
{
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 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 @@
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);