diff options
author | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-10-12 22:31:04 +0000 |
---|---|---|
committer | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-10-12 22:31:04 +0000 |
commit | 6c9278b0c46d24d52c55bb2e1edd4a437f059ce7 (patch) | |
tree | 396e9eb3781e3ea20599a3d2a23360d73b3cc621 | |
parent | 14d19d6dc1f03f3fedd77a7a881802066d6106e3 (diff) | |
download | gcc-6c9278b0c46d24d52c55bb2e1edd4a437f059ce7.tar.gz |
* cppmain.c (struct printer): New member source.
(scan_translation_unit): Fix spacing at start of lines.
(cb_line_change): Update.
* gcc.dg/cpp/spacing2.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@46237 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cppmain.c | 19 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/spacing2.c | 21 |
3 files changed, 40 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ae5a21ef194..a6de0e377be 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2001-10-12 Neil Booth <neil@daikokuya.demon.co.uk> + + * cppmain.c (struct printer): New member source. + (scan_translation_unit): Fix spacing at start of lines. + (cb_line_change): Update. + + * gcc.dg/cpp/spacing2.c: New test. + 2001-10-12 Hans-Peter Nilsson <hp@axis.com> * config/cris/arit.c: Use __builtin_labs, not abs. diff --git a/gcc/cppmain.c b/gcc/cppmain.c index 6d41af73f24..a70b41732ae 100644 --- a/gcc/cppmain.c +++ b/gcc/cppmain.c @@ -33,6 +33,7 @@ struct printer FILE *outf; /* Stream to write to. */ const struct line_map *map; /* Logical to physical line mappings. */ const cpp_token *prev; /* Previous token. */ + const cpp_token *source; /* Source token for spacing. */ unsigned int line; /* Line currently being written. */ unsigned char printed; /* Nonzero if something output at line. */ }; @@ -222,8 +223,8 @@ scan_translation_unit (pfile) cpp_reader *pfile; { bool avoid_paste = false; - const cpp_token *source = NULL; + print.source = NULL; for (;;) { const cpp_token *token = cpp_get_token (pfile); @@ -231,9 +232,10 @@ scan_translation_unit (pfile) if (token->type == CPP_PADDING) { avoid_paste = true; - if (source == NULL - || (!(source->flags & PREV_WHITE) && token->val.source == NULL)) - source = token->val.source; + if (print.source == NULL + || (!(print.source->flags & PREV_WHITE) + && token->val.source == NULL)) + print.source = token->val.source; continue; } @@ -243,9 +245,9 @@ scan_translation_unit (pfile) /* Subtle logic to output a space if and only if necessary. */ if (avoid_paste) { - if (source == NULL) - source = token; - if (source->flags & PREV_WHITE + if (print.source == NULL) + print.source = token; + if (print.source->flags & PREV_WHITE || (print.prev && cpp_avoid_paste (pfile, print.prev, token)) || (print.prev == NULL && token->type == CPP_HASH)) putc (' ', print.outf); @@ -254,7 +256,7 @@ scan_translation_unit (pfile) putc (' ', print.outf); avoid_paste = false; - source = NULL; + print.source = NULL; print.prev = token; cpp_output_token (token, print.outf); @@ -348,6 +350,7 @@ cb_line_change (pfile, token, parsing_args) maybe_print_line (print.map, token->line); print.printed = 1; print.prev = 0; + print.source = 0; /* Supply enough spaces to put this token in its original column, one space per column greater than 2, since scan_translation_unit diff --git a/gcc/testsuite/gcc.dg/cpp/spacing2.c b/gcc/testsuite/gcc.dg/cpp/spacing2.c new file mode 100644 index 00000000000..760872aea39 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/spacing2.c @@ -0,0 +1,21 @@ +/* Copyright (C) 2001 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ + +/* We used to output an unnecessary leading space, leading to Emacs + confusion with its Makefile abuse. + + Neil Booth, 12 Oct 2001. */ + +#define EMPTY +#define foo bar + +a = EMPTY +foo.. /* No leading space on output. */ + +/* + { dg-final { if ![file exists spacing2.i] { return } } } + { dg-final { if \{ [grep spacing2.i "^bar\.\."] != "" \} \{ } } + { dg-final { return \} } } + { dg-final { fail "spacing2.c: spacing issues" } } +*/ |