summaryrefslogtreecommitdiff
path: root/gcc/cpplex.c
diff options
context:
space:
mode:
authorthorpej <thorpej@138bc75d-0d04-0410-961f-82ee72b054a4>2002-04-07 03:12:23 +0000
committerthorpej <thorpej@138bc75d-0d04-0410-961f-82ee72b054a4>2002-04-07 03:12:23 +0000
commitd3f7919d2a630945daba61dc8cf51ed5cde46ed1 (patch)
treea89c2d17b9489b6bd19288f037013b3eaa28a891 /gcc/cpplex.c
parenta09b9b19f2afb1554c1f642a77147684d467ab8f (diff)
downloadgcc-d3f7919d2a630945daba61dc8cf51ed5cde46ed1.tar.gz
* cppinit.c (cpp_create_reader): Initialize
discard_comments_in_macro_exp. (COMMAND_LINE_OPTIONS): Add "-CC" option. (cpp_handle_option): Handle "-CC" option. * cpplex.c (save_comment): If saving a C++ comment in a directive, convert it to a C comment. (_cpp_lex_direct): Pass second comment start character to save_comment to indicate comment type. * cpplib.c (_cpp_handle_directive): If processing a "#define" directive and discard_comments_in_macro_exp is false, re-enable saving of comments. (lex_macro_node): If discard_comments_in_macro_exp is false, discard any comments before the macro identifier. * cpplib.h (struct cpp_options): Add discard_comments_in_macro_exp member. * cppmacro.c (cpp_get_token): If expanding a macro while processing a directive, discard any comments we might encounter. (parse_params): If discard_comments_in_macro_exp is false, ignore comments in the macro parameter list. * gcc.c (cpp_unique_options): Add "-CC" option. (option_map): Map "--comments-in-macros" to "-CC". * doc/cppopts.texi: Document "-CC" option. * f/lang-specs.h: Add "-CC" option. * testsuite/gcc.dg/cpp/maccom1.c: New test. * testsuite/gcc.dg/cpp/maccom2.c: New test. * testsuite/gcc.dg/cpp/maccom3.c: New test. * testsuite/gcc.dg/cpp/maccom4.c: New test. * testsuite/gcc.dg/cpp/maccom5.c: New test. * testsuite/gcc.dg/cpp/maccom6.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@51975 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cpplex.c')
-rw-r--r--gcc/cpplex.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index a765967face..a6180314511 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -83,7 +83,8 @@ static void parse_number PARAMS ((cpp_reader *, cpp_string *, int));
static int unescaped_terminator_p PARAMS ((cpp_reader *, const U_CHAR *));
static void parse_string PARAMS ((cpp_reader *, cpp_token *, cppchar_t));
static bool trigraph_p PARAMS ((cpp_reader *));
-static void save_comment PARAMS ((cpp_reader *, cpp_token *, const U_CHAR *));
+static void save_comment PARAMS ((cpp_reader *, cpp_token *, const U_CHAR *,
+ cppchar_t));
static int name_p PARAMS ((cpp_reader *, const cpp_string *));
static int maybe_read_ucs PARAMS ((cpp_reader *, const unsigned char **,
const unsigned char *, unsigned int *));
@@ -673,13 +674,14 @@ parse_string (pfile, token, terminator)
/* The stored comment includes the comment start and any terminator. */
static void
-save_comment (pfile, token, from)
+save_comment (pfile, token, from, type)
cpp_reader *pfile;
cpp_token *token;
const unsigned char *from;
+ cppchar_t type;
{
unsigned char *buffer;
- unsigned int len;
+ unsigned int len, clen;
len = pfile->buffer->cur - from + 1; /* + 1 for the initial '/'. */
@@ -687,14 +689,31 @@ save_comment (pfile, token, from)
line, which we don't want to save in the comment. */
if (is_vspace (pfile->buffer->cur[-1]))
len--;
- buffer = _cpp_unaligned_alloc (pfile, len);
+
+ /* If we are currently in a directive, then we need to store all
+ C++ comments as C comments internally, and so we need to
+ allocate a little extra space in that case.
+
+ Note that the only time we encounter a directive here is
+ when we are saving comments in a "#define". */
+ clen = (pfile->state.in_directive && type == '/') ? len + 2 : len;
+
+ buffer = _cpp_unaligned_alloc (pfile, clen);
token->type = CPP_COMMENT;
- token->val.str.len = len;
+ token->val.str.len = clen;
token->val.str.text = buffer;
buffer[0] = '/';
memcpy (buffer + 1, from, len - 1);
+
+ /* Finish conversion to a C comment, if necessary. */
+ if (pfile->state.in_directive && type == '/')
+ {
+ buffer[1] = '*';
+ buffer[clen - 2] = '*';
+ buffer[clen - 1] = '/';
+ }
}
/* Allocate COUNT tokens for RUN. */
@@ -1021,7 +1040,7 @@ _cpp_lex_direct (pfile)
}
/* Save the comment as a token in its own right. */
- save_comment (pfile, result, comment_start);
+ save_comment (pfile, result, comment_start, c);
break;
case '<':