PR preprocessor/13726
* directives.c (check_eol_return_comments): New static function.
(parse_include): Add buf parameter. Change all callers.
(do_include_common): If not discard comments, turn on
save_comments. Pass collected comments to include callback.
* include/cpplib.h (struct cpp_callbacks): Add new parameter to
include callback: cpp_token list.
gcc/
PR preprocessor/13726
* c-ppoutput.c (cb_include): Add comments parameter, and print out
any comments passed in.
gcc/testsuite/
PR preprocessor/13726
* gcc.dg/cpp/cmdlne-dI-C.c: New test.
* gcc.dg/cpp/cmdlne-dI-C.h: New file.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@104951
138bc75d-0d04-0410-961f-
82ee72b054a4
+2005-10-04 Ian Lance Taylor <ian@airs.com>
+
+ PR preprocessor/13726
+ * c-ppoutput.c (cb_include): Add comments parameter, and print out
+ any comments passed in.
+
2005-10-04 Andrew Pinski <pinskia@physics.uc.edu>
* tree.c (annotate_with_file_line): Fix typo.
2005-10-04 Andrew Pinski <pinskia@physics.uc.edu>
* tree.c (annotate_with_file_line): Fix typo.
static void cb_define (cpp_reader *, source_location, cpp_hashnode *);
static void cb_undef (cpp_reader *, source_location, cpp_hashnode *);
static void cb_include (cpp_reader *, source_location, const unsigned char *,
static void cb_define (cpp_reader *, source_location, cpp_hashnode *);
static void cb_undef (cpp_reader *, source_location, cpp_hashnode *);
static void cb_include (cpp_reader *, source_location, const unsigned char *,
+ const char *, int, const cpp_token **);
static void cb_ident (cpp_reader *, source_location, const cpp_string *);
static void cb_def_pragma (cpp_reader *, source_location);
static void cb_read_pch (cpp_reader *pfile, const char *name,
static void cb_ident (cpp_reader *, source_location, const cpp_string *);
static void cb_def_pragma (cpp_reader *, source_location);
static void cb_read_pch (cpp_reader *pfile, const char *name,
static void
cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
static void
cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
- const unsigned char *dir, const char *header, int angle_brackets)
+ const unsigned char *dir, const char *header, int angle_brackets,
+ const cpp_token **comments)
{
maybe_print_line (line);
if (angle_brackets)
{
maybe_print_line (line);
if (angle_brackets)
- fprintf (print.outf, "#%s <%s>\n", dir, header);
+ fprintf (print.outf, "#%s <%s>", dir, header);
- fprintf (print.outf, "#%s \"%s\"\n", dir, header);
+ fprintf (print.outf, "#%s \"%s\"", dir, header);
+
+ if (comments != NULL)
+ {
+ while (*comments != NULL)
+ {
+ if ((*comments)->flags & PREV_WHITE)
+ putc (' ', print.outf);
+ cpp_output_token (*comments, print.outf);
+ ++comments;
+ }
+ }
+
+ putc ('\n', print.outf);
+2005-10-04 Ian Lance Taylor <ian@airs.com>
+
+ PR preprocessor/13726
+ * gcc.dg/cpp/cmdlne-dI-C.c: New test.
+ * gcc.dg/cpp/cmdlne-dI-C.h: New file.
+
2005-10-04 Richard Guenther <rguenther@suse.de>
PR c/23576
2005-10-04 Richard Guenther <rguenther@suse.de>
PR c/23576
--- /dev/null
+/* Copyright (C) 2005 Free Software Foundation, Inc. */
+/* PR 13726 */
+
+/* { dg-do preprocess } */
+/* { dg-options "-dI -C" } */
+
+#include "cmdlne-dI-C.h" /* #include comment */
+/* comment 2 */
+
+/* { dg-final { scan-file cmdlne-dI-C.i "#include c+omment" } } */
+/* { dg-final { scan-file cmdlne-dI-C.i "header file c+omment" } } */
--- /dev/null
+/* header file comment */
+2005-10-04 Ian Lance Taylor <ian@airs.com>
+
+ PR preprocessor/13726
+ * directives.c (check_eol_return_comments): New static function.
+ (parse_include): Add buf parameter. Change all callers.
+ (do_include_common): If not discard comments, turn on
+ save_comments. Pass collected comments to include callback.
+ * include/cpplib.h (struct cpp_callbacks): Add new parameter to
+ include callback: cpp_token list.
+
2005-09-20 Joseph S. Myers <joseph@codesourcery.com>
* include/cpplib.h (struct cpp_options): Add extended_identifiers.
2005-09-20 Joseph S. Myers <joseph@codesourcery.com>
* include/cpplib.h (struct cpp_options): Add extended_identifiers.
static void directive_diagnostics (cpp_reader *, const directive *, int);
static void run_directive (cpp_reader *, int, const char *, size_t);
static char *glue_header_name (cpp_reader *);
static void directive_diagnostics (cpp_reader *, const directive *, int);
static void run_directive (cpp_reader *, int, const char *, size_t);
static char *glue_header_name (cpp_reader *);
-static const char *parse_include (cpp_reader *, int *);
+static const char *parse_include (cpp_reader *, int *, const cpp_token ***);
static void push_conditional (cpp_reader *, int, int, const cpp_hashnode *);
static unsigned int read_flag (cpp_reader *, unsigned int);
static int strtoul_for_line (const uchar *, unsigned int, unsigned long *);
static void push_conditional (cpp_reader *, int, int, const cpp_hashnode *);
static unsigned int read_flag (cpp_reader *, unsigned int);
static int strtoul_for_line (const uchar *, unsigned int, unsigned long *);
pfile->directive->name);
}
pfile->directive->name);
}
+/* Ensure there are no stray tokens other than comments at the end of
+ a directive, and gather the comments. */
+static const cpp_token **
+check_eol_return_comments (cpp_reader *pfile)
+{
+ size_t c;
+ size_t capacity = 8;
+ const cpp_token **buf;
+
+ buf = XNEWVEC (const cpp_token *, capacity);
+ c = 0;
+ if (! SEEN_EOL ())
+ {
+ while (1)
+ {
+ const cpp_token *tok;
+
+ tok = _cpp_lex_token (pfile);
+ if (tok->type == CPP_EOF)
+ break;
+ if (tok->type != CPP_COMMENT)
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "extra tokens at end of #%s directive",
+ pfile->directive->name);
+ else
+ {
+ if (c + 1 >= capacity)
+ {
+ capacity *= 2;
+ buf = XRESIZEVEC (const cpp_token *, buf, capacity);
+ }
+ buf[c] = tok;
+ ++c;
+ }
+ }
+ }
+ buf[c] = NULL;
+ return buf;
+}
+
/* Called when entering a directive, _Pragma or command-line directive. */
static void
start_directive (cpp_reader *pfile)
/* Called when entering a directive, _Pragma or command-line directive. */
static void
start_directive (cpp_reader *pfile)
#pragma dependency. The string is malloced and the caller should
free it. Returns NULL on error. */
static const char *
#pragma dependency. The string is malloced and the caller should
free it. Returns NULL on error. */
static const char *
-parse_include (cpp_reader *pfile, int *pangle_brackets)
+parse_include (cpp_reader *pfile, int *pangle_brackets,
+ const cpp_token ***buf)
{
char *fname;
const cpp_token *header;
{
char *fname;
const cpp_token *header;
+ if (buf == NULL || CPP_OPTION (pfile, discard_comments))
+ check_eol (pfile);
+ else
+ {
+ /* If we are not discarding comments, then gather them while
+ doing the eol check. */
+ *buf = check_eol_return_comments (pfile);
+ }
+
{
const char *fname;
int angle_brackets;
{
const char *fname;
int angle_brackets;
+ const cpp_token **buf = NULL;
- fname = parse_include (pfile, &angle_brackets);
+ /* Re-enable saving of comments if requested, so that the include
+ callback can dump comments which follow #include. */
+ pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
+
+ fname = parse_include (pfile, &angle_brackets, &buf);
+ {
+ if (buf)
+ XDELETEVEC (buf);
+ return;
+ }
if (!*fname)
{
cpp_error (pfile, CPP_DL_ERROR, "empty filename in #%s",
pfile->directive->name);
if (!*fname)
{
cpp_error (pfile, CPP_DL_ERROR, "empty filename in #%s",
pfile->directive->name);
+ XDELETEVEC (fname);
+ if (buf)
+ XDELETEVEC (buf);
if (pfile->cb.include)
pfile->cb.include (pfile, pfile->directive_line,
if (pfile->cb.include)
pfile->cb.include (pfile, pfile->directive_line,
- pfile->directive->name, fname, angle_brackets);
+ pfile->directive->name, fname, angle_brackets,
+ buf);
_cpp_stack_include (pfile, fname, angle_brackets, type);
}
_cpp_stack_include (pfile, fname, angle_brackets, type);
}
+ XDELETEVEC (fname);
+ if (buf)
+ XDELETEVEC (buf);
const char *fname;
int angle_brackets, ordering;
const char *fname;
int angle_brackets, ordering;
- fname = parse_include (pfile, &angle_brackets);
+ fname = parse_include (pfile, &angle_brackets, NULL);
void (*dir_change) (cpp_reader *, const char *);
void (*include) (cpp_reader *, unsigned int, const unsigned char *,
void (*dir_change) (cpp_reader *, const char *);
void (*include) (cpp_reader *, unsigned int, const unsigned char *,
+ const char *, int, const cpp_token **);
void (*define) (cpp_reader *, unsigned int, cpp_hashnode *);
void (*undef) (cpp_reader *, unsigned int, cpp_hashnode *);
void (*ident) (cpp_reader *, unsigned int, const cpp_string *);
void (*define) (cpp_reader *, unsigned int, cpp_hashnode *);
void (*undef) (cpp_reader *, unsigned int, cpp_hashnode *);
void (*ident) (cpp_reader *, unsigned int, const cpp_string *);