glcpp: Add basic #line support (adapted from the main compiler).
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 19 Aug 2010 00:38:05 +0000 (17:38 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 19 Aug 2010 00:38:47 +0000 (17:38 -0700)
src/glsl/glcpp/glcpp-lex.l

index a14e580ab1a674073c37c02954434158c713c050..c81bd044a2a30e72731cd429aa14ee9074f4d704 100644 (file)
@@ -100,6 +100,37 @@ HEXADECIMAL_INTEGER        0[xX][0-9a-fA-F]+[uU]?
        return OTHER;
 }
 
+{HASH}line{HSPACE}+{DECIMAL_INTEGER}{HSPACE}+{DECIMAL_INTEGER}{HSPACE}*$ {
+       /* Eat characters until the first digit is
+        * encountered
+        */
+       char *ptr = yytext;
+       while (!isdigit(*ptr))
+               ptr++;
+
+       /* Subtract one from the line number because
+        * yylineno is zero-based instead of
+        * one-based.
+        */
+       yylineno = strtol(ptr, &ptr, 0) - 1;
+       yylloc->source = strtol(ptr, NULL, 0);
+}
+
+{HASH}line{HSPACE}+{DECIMAL_INTEGER}{HSPACE}*$ {
+       /* Eat characters until the first digit is
+        * encountered
+        */
+       char *ptr = yytext;
+       while (!isdigit(*ptr))
+               ptr++;
+
+       /* Subtract one from the line number because
+        * yylineno is zero-based instead of
+        * one-based.
+        */
+       yylineno = strtol(ptr, &ptr, 0) - 1;
+}
+
 {HASH}ifdef/.*\n {
        yyextra->lexing_if = 1;
        yyextra->space_tokens = 0;