diff options
author | Carl Worth <[email protected]> | 2013-12-19 16:06:31 -0800 |
---|---|---|
committer | Carl Worth <[email protected]> | 2014-01-02 14:15:51 -0800 |
commit | 6005e9cb283214cd57038c7c5e7758ba72ec6ac2 (patch) | |
tree | 1116640e24389e8235fb13f5583b2e4fbab9902e /src/glsl/glcpp/tests | |
parent | 61cea49014df6dcf3aa41ad18b2e998e6921320f (diff) |
glcpp: Replace multi-line comment with a space (even as part of macro definition)
The preprocessor has always replaced multi-line comments with a single space
character, (as required by the specification), but as of commit
bd55ba568b301d0f764cd1ca015e84e1ae932c8b the lexer also emitted a NEWLINE
token for each newline within the comment, (in order to preserve line
numbers).
The emitting of NEWLINE tokens within the comment broke the rule of "replace a
multi-line comment with a single space" as could be exposed by code like the
following:
#define FOO a/*
*/b
FOO
Prior to commit bd55ba568b301d0f764cd1ca015e84e1ae932c8b, this code defined
the macro FOO as "a b" as desired. Since that commit, this code instead
defines FOO as "a" and leaves a stray "b" in the output.
In this commit, we fix this by not emitting the NEWLINE tokens while lexing
the comment, but instead merely counting them in the commented_newlines
variable. Then, when the lexer next encounters a non-commented newline it
switches to a NEWLINE_CATCHUP state to emit as many NEWLINE tokens as
necessary (so that subsequent parsing stages still generate correct line
numbers).
Of course, it would have been more clear if we could have written a loop to
emit all the newlines, but flex conventions prevent that, (we must use
"return" for each token we emit).
It similarly would have been clear to have a new rule restricted to the
<NEWLINE_CATCHUP> state with an action much like the body of this if
condition. The problem with that is that this rule must not consume any
characters. It might be possible to write a rule that matches a single
lookahead of any character, but then we would also need an additional rule to
ensure for the <EOF> case where there are no additional characters available
for the lookahead to match.
Given those considerations, and given that the SKIP-state manipulation already
involves a code block at the top of the lexer function, before any rules, it
seems best to me to go with the implementation here which adds a similar
pre-rule code block for the NEWLINE_CATCHUP.
Finally, this commit also changes the expected output of a few, existing glcpp
tests. The change here is that the space character resulting from the
multi-line comment is now emitted before the newlines corresponding to that
comment. (Previously, the newlines were emitted first, and the space character
afterward.)
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=72686
Reviewed-by: Kenneth Graunke <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/glsl/glcpp/tests')
5 files changed, 13 insertions, 4 deletions
diff --git a/src/glsl/glcpp/tests/063-comments.c.expected b/src/glsl/glcpp/tests/063-comments.c.expected index 73ca7071faa..1965c9be02d 100644 --- a/src/glsl/glcpp/tests/063-comments.c.expected +++ b/src/glsl/glcpp/tests/063-comments.c.expected @@ -5,16 +5,16 @@ f = g /h; l(); m = n + p; + - more code here - + are not treated like comments. diff --git a/src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c.expected b/src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c.expected index 84fdc50c920..be20b7c8909 100644 --- a/src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c.expected +++ b/src/glsl/glcpp/tests/094-divide-by-zero-short-circuit.c.expected @@ -1,4 +1,5 @@ 0:12(17): preprocessor error: division by 0 in preprocessor directive + @@ -9,7 +10,6 @@ - diff --git a/src/glsl/glcpp/tests/117-line-continuation-and-non-continuation-backslash.c.expected b/src/glsl/glcpp/tests/117-line-continuation-and-non-continuation-backslash.c.expected index 9b3eb676f08..292d6516fe0 100644 --- a/src/glsl/glcpp/tests/117-line-continuation-and-non-continuation-backslash.c.expected +++ b/src/glsl/glcpp/tests/117-line-continuation-and-non-continuation-backslash.c.expected @@ -1,3 +1,4 @@ + @@ -6,7 +7,6 @@ - diff --git a/src/glsl/glcpp/tests/118-comment-becomes-space.c b/src/glsl/glcpp/tests/118-comment-becomes-space.c new file mode 100644 index 00000000000..53e80394ab6 --- /dev/null +++ b/src/glsl/glcpp/tests/118-comment-becomes-space.c @@ -0,0 +1,4 @@ +#define FOO first/* +*/second + +FOO diff --git a/src/glsl/glcpp/tests/118-comment-becomes-space.c.expected b/src/glsl/glcpp/tests/118-comment-becomes-space.c.expected new file mode 100644 index 00000000000..2adf5d1ba90 --- /dev/null +++ b/src/glsl/glcpp/tests/118-comment-becomes-space.c.expected @@ -0,0 +1,5 @@ + + + +first second + |