Mesa (glsl2): glsl: Fix missing initialization of yylloc.source

Carl Worth cworth at kemper.freedesktop.org
Wed Jul 21 20:52:39 UTC 2010


Module: Mesa
Branch: glsl2
Commit: a0cfe8c44085032fd982bbbff1f02252ffaa7114
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a0cfe8c44085032fd982bbbff1f02252ffaa7114

Author: Carl Worth <cworth at cworth.org>
Date:   Wed Jul 21 13:43:47 2010 -0700

glsl: Fix missing initialization of yylloc.source

In both the preprocessor and in the compiler proper, we use a custom
yyltype struct to allow tracking the source-string number in addition
to line and column. However, we were previously relying on bison's
default initialization of the yyltype struct which of course is not
aware of the source field and leaves it uninitialized.

We fix this by defining our own YYLLOC_DEFAULT macro expanding on the
default version (as appears in the bison manual) and adding
initialization of yylloc.source.

---

 src/glsl/glcpp/glcpp.h        |   19 +++++++++++++++++++
 src/glsl/glsl_parser_extras.h |   19 +++++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/glsl/glcpp/glcpp.h b/src/glsl/glcpp/glcpp.h
index fc9511a..869de2e 100644
--- a/src/glsl/glcpp/glcpp.h
+++ b/src/glsl/glcpp/glcpp.h
@@ -69,6 +69,25 @@ typedef struct YYLTYPE {
 # define YYLTYPE_IS_DECLARED 1
 # define YYLTYPE_IS_TRIVIAL 1
 
+# define YYLLOC_DEFAULT(Current, Rhs, N)			\
+do {								\
+   if (N)							\
+   {								\
+      (Current).first_line   = YYRHSLOC(Rhs, 1).first_line;	\
+      (Current).first_column = YYRHSLOC(Rhs, 1).first_column;	\
+      (Current).last_line    = YYRHSLOC(Rhs, N).last_line;	\
+      (Current).last_column  = YYRHSLOC(Rhs, N).last_column;	\
+   }								\
+   else								\
+   {								\
+      (Current).first_line   = (Current).last_line =		\
+	 YYRHSLOC(Rhs, 0).last_line;				\
+      (Current).first_column = (Current).last_column =		\
+	 YYRHSLOC(Rhs, 0).last_column;				\
+   }								\
+   (Current).source = 0;					\
+} while (0)
+
 struct token {
 	int type;
 	YYSTYPE value;
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index e2efbd9..b50d9ee 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -137,6 +137,25 @@ typedef struct YYLTYPE {
 # define YYLTYPE_IS_DECLARED 1
 # define YYLTYPE_IS_TRIVIAL 1
 
+# define YYLLOC_DEFAULT(Current, Rhs, N)			\
+do {								\
+   if (N)							\
+   {								\
+      (Current).first_line   = YYRHSLOC(Rhs, 1).first_line;	\
+      (Current).first_column = YYRHSLOC(Rhs, 1).first_column;	\
+      (Current).last_line    = YYRHSLOC(Rhs, N).last_line;	\
+      (Current).last_column  = YYRHSLOC(Rhs, N).last_column;	\
+   }								\
+   else								\
+   {								\
+      (Current).first_line   = (Current).last_line =		\
+	 YYRHSLOC(Rhs, 0).last_line;				\
+      (Current).first_column = (Current).last_column =		\
+	 YYRHSLOC(Rhs, 0).last_column;				\
+   }								\
+   (Current).source = 0;					\
+} while (0)
+
 extern void _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state,
 			     const char *fmt, ...);
 




More information about the mesa-commit mailing list