The #line directive specifies the line number for the subsequent line of text.
So, since we will see another newline before that line, (and hence, increment
yylineno one more time), we have to set the yylineno value to one less than
we would otherwise.

This is in addition to setting it to one less for sake of being zero-based,
(which we were already doing).

So, subtract 2 for the value we want.
---
 src/glsl/glsl_lexer.ll |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/glsl/glsl_lexer.ll b/src/glsl/glsl_lexer.ll
index 4fca4ea..2a0e01b 100644
--- a/src/glsl/glsl_lexer.ll
+++ b/src/glsl/glsl_lexer.ll
@@ -177,11 +177,12 @@ HASH              ^{SPC}#{SPC}
                                   while (!isdigit(*ptr))
                                      ptr++;
 
-                                  /* Subtract one from the line number because
-                                   * yylineno is zero-based instead of
-                                   * one-based.
+                                  /* Subtract two from the line number parsed.
+                                   * 1 because yylineno is zero-based and
+                                   * 2 because #line gives the line number for
+                                   * the subsequent line of the source.
                                    */
-                                  yylineno = strtol(ptr, &ptr, 0) - 1;
+                                  yylineno = strtol(ptr, &ptr, 0) - 2;
                                   yylloc->source = strtol(ptr, NULL, 0);
                                }
 {HASH}line{SPCP}{INT}{SPC}$    {
@@ -192,11 +193,12 @@ HASH              ^{SPC}#{SPC}
                                   while (!isdigit(*ptr))
                                      ptr++;
 
-                                  /* Subtract one from the line number because
-                                   * yylineno is zero-based instead of
-                                   * one-based.
+                                  /* Subtract two from the line number parsed.
+                                   * 1 because yylineno is zero-based and
+                                   * 2 because #line gives the line number for
+                                   * the subsequent line of the source.
                                    */
-                                  yylineno = strtol(ptr, &ptr, 0) - 1;
+                                  yylineno = strtol(ptr, &ptr, 0) - 2;
                                }
 ^{SPC}#{SPC}pragma{SPCP}debug{SPC}\({SPC}on{SPC}\) {
                                  BEGIN PP;
-- 
1.7.10

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to