From: Ian Romanick Date: Mon, 26 Apr 2010 21:19:49 +0000 (-0700) Subject: Initial implementation of #line X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c11f1a4fb07f09a6b804c5d0e4bb12cd5137fafa;p=mesa.git Initial implementation of #line Does not handle comments in #line or line continuation characters, but it should be good enough for now. --- diff --git a/glsl_lexer.lpp b/glsl_lexer.lpp index a25dbf9e2fe..06214a8eccf 100644 --- a/glsl_lexer.lpp +++ b/glsl_lexer.lpp @@ -21,6 +21,7 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ +#include #include "ast.h" #include "glsl_parser_extras.h" #include "glsl_parser.h" @@ -43,6 +44,13 @@ %x PP COMMENT +DEC_INT [1-9][0-9]* +HEX_INT 0[xX][0-9a-fA-F]+ +OCT_INT 0[0-7]* +INT ({DEC_INT}|{HEX_INT}|{OCT_INT}) +SPC [ \t]* +SPCP [ \t]+ +HASH ^{SPC}#{SPC} %% "/*" { yy_push_state(COMMENT, yyscanner); } @@ -59,7 +67,35 @@ ^[ \t]*#[ \t]*$ ; ^[ \t]*#[ \t]*version { BEGIN PP; return VERSION; } ^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; } -^[ \t]*#[ \t]*line { BEGIN PP; return LINE; } +{HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ { + /* 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{SPCP}{INT}{SPC}$ { + /* 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; + } ^[ \t]*#[ \t]*pragma { BEGIN PP; return PRAGMA; } \/\/[^\n]* { } [ \t\r]* { }