From 758eba2b81ccacce770a719792a93c12a7a9e45b Mon Sep 17 00:00:00 2001 From: Alexander Viro Date: Sun, 13 Jun 2004 08:13:32 -0700 Subject: [PATCH] [PATCH] comments handling fix in sparse If we get a newline in the middle of a comment, stream->pos.newline is set and remains set. In effect, newlines in the middle of multiline comments drift to its end. This is wrong - e.g. #define A /* foo */ B is 100% legitimate - since every comment is treated as if replaced with single space, the above is equivalent to #define A B Current code treats it as #define A B which is bogus. Fix is trivial - we simply should restore ->newline we had at the beginning of comment once we finish skipping it. BTW, I'm starting to put new testcases into subdirectories - by translation phase (multibyte character mapping == phase 1, line-splicing == phase 2, tokenizer == phase 3, macro-expansion == phase 4, remapping from source charset to execution charset == phase 5, merging adjacent string constants == phase 6, conversion of tokens from preprocessor to compiler ones and translation proper == phase 7, linking == phase 8). We obviously don't have many of those (no multibyte handling, source and execution charsets are identical and having no backend we obviously do not link anything), but it's easier to keep track of what's what in the tests that way. We already have way too many preprocessor.c in there and going for saner names will only create confusion between preprocessor and parser tests. I'm not moving existing testcases - that's just for new ones... --- tokenize.c | 7 ++++++- validation/phase3/comments | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 validation/phase3/comments diff --git a/tokenize.c b/tokenize.c index eaeb8880..70ab2a04 100644 --- a/tokenize.c +++ b/tokenize.c @@ -480,8 +480,12 @@ static int drop_stream_eoln(stream_t *stream) static int drop_stream_comment(stream_t *stream) { - int next = nextchar(stream); + int newline; + int next; drop_token(stream); + newline = stream->pos.newline; + + next = nextchar(stream); for (;;) { int curr = next; if (curr == EOF) { @@ -492,6 +496,7 @@ static int drop_stream_comment(stream_t *stream) if (curr == '*' && next == '/') break; } + stream->pos.newline = newline; return nextchar(stream); } diff --git a/validation/phase3/comments b/validation/phase3/comments new file mode 100644 index 00000000..8f51a307 --- /dev/null +++ b/validation/phase3/comments @@ -0,0 +1,9 @@ +/* + * Each comment should be treated as if it had been a single space. + */ + +/* This should give nothing */ +/* XXX: currently sparse produces Y */ +/* Fixed */ +#define X /* + */ Y -- 2.11.4.GIT