Fixes to make 20000508 cpplib's -C a little more useful
Jason R Thorpe
thorpej@zembu.com
Mon May 8 15:29:00 GMT 2000
Hi folks...
cpplib's -C is a little overzealous about reporting errors when comments
appear after CPP directives. Consider the following input:
----- begin cpp-comments.c -----
#include "cpp-dummy-header.h" /* test comment after random directive */
#ifdef SOMETHING /* test comment after #ifdef */
#define SOMETHING_ELSE
#endif
#ifdef SOMETHING_ELSE /* Test those
multi-line comments! */
#define YET_ANOTHER_THING 1
#else /* test comment after #else */
#define YET_ANOTHER_THING 0
#endif /* SOMETHING_ELSE */
#if 0 /* Disable FOR_NOTHING */
#define FOR_NOTHING 668 /* The neighbor of the beast. */
#endif
#if FOR_NOTHING != 668
#undef YET_ANOTHER_THING /* test comment after #undef */
#endif
#define FOO(x) \
do { \
/* This is a comment. */ \
if ((x) > 0) \
foo((x)); \
} while (/*CONSTCOND*/0)
void func(int arg)
{
#ifdef FOR_NOTHING
FOO(FOR_NOTHING);
#else
FOO(arg);
#endif
}
----- end cpp-comments.c -----
----- begin cpp-dummy-header.h -----
/* Dummy header. */
----- end cpp-dummy-header.h -----
When processed with 20000508's `cpp -lang-c -C cpp-comments.c > /dev/null':
cpp-comments.c:1:71: junk at end of `#include'
cpp-comments.c:3:49: warning: garbage at end of `#ifdef' argument
cpp-comments.c:8:30: warning: garbage at end of `#ifdef' argument
cpp-comments.c:14:34: operator '/' has no right operand
cpp-comments.c:19:56: warning: junk on line after #undef
Not terribly useful. The patch appended at the end of this message cleans
up all of them except for the comment after the CPP expression. The fix
there wasn't all that obvious, and I'm not at all familiar with cpplib's
lexer (sigh, yet):
cpp-comments.c:14:34: operator '/' has no right operand
...it's a step, anyhow.
2000-05-08 Jason R Thorpe <thorpej@zembu.com>
* cpplib.c (parse_include): Don't complain about comments
after the directive if we are not discarding comments.
(do_undef): Likewise.
(parse_ifdef): Likewise.
--
-- Jason R. Thorpe <thorpej@zembu.com>
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplib.c,v
retrieving revision 1.163
diff -c -r1.163 cpplib.c
*** cpplib.c 2000/05/04 04:38:00 1.163
--- cpplib.c 2000/05/08 22:22:02
***************
*** 439,447 ****
return 0;
}
! if (_cpp_get_directive_token (pfile) != CPP_VSPACE)
{
! cpp_error (pfile, "junk at end of `#%s'", name);
_cpp_skip_rest_of_line (pfile);
}
--- 439,449 ----
return 0;
}
! token = _cpp_get_directive_token (pfile);
! if (token != CPP_VSPACE)
{
! if (CPP_OPTION (pfile, discard_comments) || token != CPP_COMMENT)
! cpp_error (pfile, "junk at end of `#%s'", name);
_cpp_skip_rest_of_line (pfile);
}
***************
*** 700,706 ****
token = _cpp_get_directive_token (pfile);
if (token != CPP_VSPACE)
{
! cpp_pedwarn (pfile, "junk on line after #undef");
_cpp_skip_rest_of_line (pfile);
}
--- 702,709 ----
token = _cpp_get_directive_token (pfile);
if (token != CPP_VSPACE)
{
! if (CPP_OPTION (pfile, discard_comments) || token != CPP_COMMENT)
! cpp_pedwarn (pfile, "junk on line after #undef");
_cpp_skip_rest_of_line (pfile);
}
***************
*** 1160,1169 ****
if (!CPP_TRADITIONAL (pfile))
{
! if (_cpp_get_directive_token (pfile) == CPP_VSPACE)
goto done;
!
! cpp_pedwarn (pfile, "garbage at end of `#%s' argument", name);
}
_cpp_skip_rest_of_line (pfile);
--- 1163,1174 ----
if (!CPP_TRADITIONAL (pfile))
{
! token = _cpp_get_directive_token (pfile);
! if (token == CPP_VSPACE)
goto done;
!
! if (CPP_OPTION (pfile, discard_comments) || token != CPP_COMMENT)
! cpp_pedwarn (pfile, "garbage at end of `#%s' argument", name);
}
_cpp_skip_rest_of_line (pfile);
More information about the Gcc-patches
mailing list