The glcpp implementation has long had code to support a file that ends without a final newline. But we didn't have a "make check" test for this.
Additionally, the <EOF> action was restricted only to the <INITIAL> state so it would fail to get invoked if the EOF was encountered in the <COMMENT> or the <DEFINE> case. Neither of these was a bug, per se, since EOF in either of these cases is an error anyway, (either "unterminated comment" or "missing macro name for #define"). But with the new explicit support for these cases, we not generate clean error messages in these cases, (rather than "unexpected $end" from before). --- src/glsl/glcpp/glcpp-lex.l | 7 +++++-- src/glsl/glcpp/tests/130-eof-without-newline.c | 1 + src/glsl/glcpp/tests/130-eof-without-newline.c.expected | 1 + src/glsl/glcpp/tests/131-eof-without-newline-comment.c | 1 + src/glsl/glcpp/tests/131-eof-without-newline-comment.c.expected | 2 ++ src/glsl/glcpp/tests/132-eof-without-newline-define.c | 1 + src/glsl/glcpp/tests/132-eof-without-newline-define.c.expected | 2 ++ 7 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/glsl/glcpp/tests/130-eof-without-newline.c create mode 100644 src/glsl/glcpp/tests/130-eof-without-newline.c.expected create mode 100644 src/glsl/glcpp/tests/131-eof-without-newline-comment.c create mode 100644 src/glsl/glcpp/tests/131-eof-without-newline-comment.c.expected create mode 100644 src/glsl/glcpp/tests/132-eof-without-newline-define.c create mode 100644 src/glsl/glcpp/tests/132-eof-without-newline-define.c.expected diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l index 0975006..134e71d 100644 --- a/src/glsl/glcpp/glcpp-lex.l +++ b/src/glsl/glcpp/glcpp-lex.l @@ -397,8 +397,11 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? return NEWLINE; } - /* Handle missing newline at EOF. */ -<INITIAL><<EOF>> { +<INITIAL,COMMENT,DEFINE><<EOF>> { + if (YY_START == COMMENT) + glcpp_error(yylloc, yyextra, "Unterminated comment"); + if (YY_START == DEFINE) + glcpp_error(yylloc, yyextra, "#define without macro name"); BEGIN DONE; /* Don't keep matching this rule forever. */ yyextra->lexing_directive = 0; return NEWLINE; diff --git a/src/glsl/glcpp/tests/130-eof-without-newline.c b/src/glsl/glcpp/tests/130-eof-without-newline.c new file mode 100644 index 0000000..240292d --- /dev/null +++ b/src/glsl/glcpp/tests/130-eof-without-newline.c @@ -0,0 +1 @@ +this file ends with no newline \ No newline at end of file diff --git a/src/glsl/glcpp/tests/130-eof-without-newline.c.expected b/src/glsl/glcpp/tests/130-eof-without-newline.c.expected new file mode 100644 index 0000000..5780030 --- /dev/null +++ b/src/glsl/glcpp/tests/130-eof-without-newline.c.expected @@ -0,0 +1 @@ +this file ends with no newline diff --git a/src/glsl/glcpp/tests/131-eof-without-newline-comment.c b/src/glsl/glcpp/tests/131-eof-without-newline-comment.c new file mode 100644 index 0000000..56ec5f7 --- /dev/null +++ b/src/glsl/glcpp/tests/131-eof-without-newline-comment.c @@ -0,0 +1 @@ +This file ends with no newline within a comment /* \ No newline at end of file diff --git a/src/glsl/glcpp/tests/131-eof-without-newline-comment.c.expected b/src/glsl/glcpp/tests/131-eof-without-newline-comment.c.expected new file mode 100644 index 0000000..506eb56 --- /dev/null +++ b/src/glsl/glcpp/tests/131-eof-without-newline-comment.c.expected @@ -0,0 +1,2 @@ +0:1(52): preprocessor error: Unterminated comment +This file ends with no newline within a comment diff --git a/src/glsl/glcpp/tests/132-eof-without-newline-define.c b/src/glsl/glcpp/tests/132-eof-without-newline-define.c new file mode 100644 index 0000000..6795e35 --- /dev/null +++ b/src/glsl/glcpp/tests/132-eof-without-newline-define.c @@ -0,0 +1 @@ +#define \ No newline at end of file diff --git a/src/glsl/glcpp/tests/132-eof-without-newline-define.c.expected b/src/glsl/glcpp/tests/132-eof-without-newline-define.c.expected new file mode 100644 index 0000000..a3ace0f --- /dev/null +++ b/src/glsl/glcpp/tests/132-eof-without-newline-define.c.expected @@ -0,0 +1,2 @@ +0:1(2): preprocessor error: #define without macro name +0:1(2): preprocessor error: syntax error, unexpected NEWLINE, expecting FUNC_IDENTIFIER or OBJ_IDENTIFIER -- 2.0.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev