>From the GLSL 1.10 specification: #line must have, after macro substitution, one of the following forms:
#line line #line line source-string-number" Previously, we handled #line directives completely within the glcpp lexer, which obviously precludes proper macro substitution. Instead, just treat #line as a token, allowing normal expansion to occur; the main GLSL compiler can handle the line directives anyway. This also allows comments on #line directives, such as: #line 42 0 /* some pithy comment */ oglconform seems to use this quite a bit, and it seems like it should be allowed since macro expansion means #line needs to be handled post-lexer, which means the lexer should eat comments. +21 oglconforms. Cc: Carl Worth <cwo...@cworth.org> Signed-off-by: Kenneth Graunke <kenn...@whitecape.org> --- src/glsl/glcpp/glcpp-lex.l | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) One bad thing about this patch is that it breaks 091-hash-line.c in glcpp's unit test suite. I'm not sure what to do about that. I could update the output, but the new output doesn't make much sense anymore...it gives you lovely messages like: 0:4(1): preprocessor error: #error line 25 error I also think we should add a test for #line with macro expansion. Maybe something as simple as: #define LINE_NUMBER 25 #define SOURCE_STRING_NUMBER 0 #line LINE_NUMBER SOURCE_STRING_NUMBER But I'm not sure whether to add that as 102, or replace 91. Thoughts? diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l index b34f2c0..0ed83f5 100644 --- a/src/glsl/glcpp/glcpp-lex.l +++ b/src/glsl/glcpp/glcpp-lex.l @@ -129,35 +129,10 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? return OTHER; } -{HASH}line{HSPACE}+{DIGITS}{HSPACE}+{DIGITS}{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}+{DIGITS}{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}line { + yylval->str = ralloc_strdup (yyextra, yytext); + yycolumn = 0; + return OTHER; } <SKIP,INITIAL>{ -- 1.7.10.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev