Commit 1c6d33ef by Neil Booth Committed by Neil Booth

cpplex.c (save_comment): Only store the initial '/' now.

	* cpplex.c (save_comment): Only store the initial '/'
	now.
	(lex_token): Combine handling of the two comment types.
	Pass everything but the initial '/' to save_comment.

From-SVN: r36635
parent 7de4d004
Mon 25-Sep-2000 23:38:27 BST Neil Booth <neilb@earthling.net>
* cpplex.c (save_comment): Only store the initial '/'
now.
(lex_token): Combine handling of the two comment types.
Pass everything but the initial '/' to save_comment.
Mon 25-Sep-2000 23:31:45 BST Neil Booth <neilb@earthling.net> Mon 25-Sep-2000 23:31:45 BST Neil Booth <neilb@earthling.net>
* cpphash.h (_cpp_digraph_spellings, _cpp_process_directive, * cpphash.h (_cpp_digraph_spellings, _cpp_process_directive,
......
...@@ -947,8 +947,7 @@ save_comment (pfile, token, from) ...@@ -947,8 +947,7 @@ save_comment (pfile, token, from)
unsigned int len; unsigned int len;
cpp_toklist *list = &pfile->token_list; cpp_toklist *list = &pfile->token_list;
#define COMMENT_START_LEN 2 len = pfile->buffer->cur - from + 1; /* + 1 for the initial '/'. */
len = pfile->buffer->cur - from + COMMENT_START_LEN;
_cpp_reserve_name_space (list, len); _cpp_reserve_name_space (list, len);
buffer = list->namebuf + list->name_used; buffer = list->namebuf + list->name_used;
list->name_used += len; list->name_used += len;
...@@ -957,10 +956,8 @@ save_comment (pfile, token, from) ...@@ -957,10 +956,8 @@ save_comment (pfile, token, from)
token->val.str.len = len; token->val.str.len = len;
token->val.str.text = buffer; token->val.str.text = buffer;
/* from[-1] is '/' or '*' depending on the comment type. */ buffer[0] = '/';
*buffer++ = '/'; memcpy (buffer + 1, from, len - 1);
*buffer++ = from[-1];
memcpy (buffer, from, len - COMMENT_START_LEN);
} }
/* Subroutine of lex_token to handle '%'. A little tricky, since we /* Subroutine of lex_token to handle '%'. A little tricky, since we
...@@ -1187,65 +1184,56 @@ lex_token (pfile, result) ...@@ -1187,65 +1184,56 @@ lex_token (pfile, result)
break; break;
case '/': case '/':
/* A potential block or line comment. */
comment_start = buffer->cur;
result->type = CPP_DIV; result->type = CPP_DIV;
c = get_effective_char (buffer); c = get_effective_char (buffer);
if (c == '=') if (c == '=')
ACCEPT_CHAR (CPP_DIV_EQ); ACCEPT_CHAR (CPP_DIV_EQ);
else if (c == '*') if (c != '/' && c != '*')
{ break;
comment_start = buffer->cur;
/* Skip_block_comment updates buffer->read_ahead. */ if (c == '*')
{
if (skip_block_comment (pfile)) if (skip_block_comment (pfile))
cpp_error_with_line (pfile, result->line, result->col, cpp_error_with_line (pfile, result->line, result->col,
"unterminated comment"); "unterminated comment");
if (!pfile->state.save_comments)
{
result->flags |= PREV_WHITE;
goto next_char;
}
/* Save the comment as a token in its own right. */
save_comment (pfile, result, comment_start);
} }
else if (c == '/') else
{ {
if (!CPP_OPTION (pfile, cplusplus_comments)
&& !CPP_IN_SYSTEM_HEADER (pfile))
break;
/* We silently allow C++ comments in system headers, /* We silently allow C++ comments in system headers,
irrespective of conformance mode, because lots of irrespective of conformance mode, because lots of
broken systems do that and trying to clean it up in broken systems do that and trying to clean it up in
fixincludes is a nightmare. */ fixincludes is a nightmare. */
if (CPP_IN_SYSTEM_HEADER (pfile)) if (!CPP_IN_SYSTEM_HEADER (pfile)
goto do_line_comment; && CPP_OPTION (pfile, c89) && CPP_PEDANTIC (pfile)
if (CPP_OPTION (pfile, cplusplus_comments)) && !buffer->warned_cplusplus_comments)
{ {
if (CPP_OPTION (pfile, c89) && CPP_PEDANTIC (pfile) cpp_pedwarn (pfile,
&& ! buffer->warned_cplusplus_comments) "C++ style comments are not allowed in ISO C89");
{ cpp_pedwarn (pfile,
cpp_pedwarn (pfile, "(this will be reported only once per input file)");
"C++ style comments are not allowed in ISO C89"); buffer->warned_cplusplus_comments = 1;
cpp_pedwarn (pfile, }
"(this will be reported only once per input file)");
buffer->warned_cplusplus_comments = 1;
}
do_line_comment:
comment_start = buffer->cur;
/* Skip_line_comment updates buffer->read_ahead. */
if (skip_line_comment (pfile))
cpp_warning_with_line (pfile, result->line, result->col,
"multi-line comment");
if (!pfile->state.save_comments) if (skip_line_comment (pfile))
{ cpp_warning_with_line (pfile, result->line, result->col,
result->flags |= PREV_WHITE; "multi-line comment");
goto next_char; }
}
/* Save the comment as a token in its own right. */ /* Skipping the comment has updated buffer->read_ahead. */
save_comment (pfile, result, comment_start); if (!pfile->state.save_comments)
} {
result->flags |= PREV_WHITE;
goto next_char;
} }
/* Save the comment as a token in its own right. */
save_comment (pfile, result, comment_start);
break; break;
case '<': case '<':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment