Commit d3a34a0a by Jason Merrill Committed by Jason Merrill

cpplib.c (read_line_number): New fn, split out of...

	* cpplib.c (read_line_number): New fn, split out of...
	(do_line): Here.

From-SVN: r28707
parent 8dd3f57a
Fri Aug 13 17:41:55 1999 Jason Merrill <jason@yorick.cygnus.com>
* cpplib.c (read_line_number): New fn, split out of...
(do_line): Here.
Fri Aug 13 14:18:27 1999 Gavin Romig-Koch <gavin@cygnus.com> Fri Aug 13 14:18:27 1999 Gavin Romig-Koch <gavin@cygnus.com>
tree.c (lang_unsave_expr_now) : New. tree.c (lang_unsave_expr_now) : New.
......
...@@ -1208,6 +1208,34 @@ do_include (pfile, keyword) ...@@ -1208,6 +1208,34 @@ do_include (pfile, keyword)
return 0; return 0;
} }
/* Subroutine of do_line. Read next token from PFILE without adding it to
the output buffer. If it is a number between 1 and 4, store it in *NUM
and return 1; otherwise, return 0 and complain if we aren't at the end
of the directive. */
static int
read_line_number (pfile, num)
cpp_reader *pfile;
int *num;
{
long save_written = CPP_WRITTEN (pfile);
U_CHAR *p = pfile->token_buffer + save_written;
enum cpp_token token = get_directive_token (pfile);
CPP_SET_WRITTEN (pfile, save_written);
if (token == CPP_NUMBER && *p >= '1' && *p <= '4' && p[1] == '\0')
{
*num = p[0] - '0';
return 1;
}
else
{
if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP)
cpp_error (pfile, "invalid format `#line' command");
return 0;
}
}
/* Interpret #line command. /* Interpret #line command.
Note that the filename string (if any) is treated as if it were an Note that the filename string (if any) is treated as if it were an
include filename. That means no escape handling. */ include filename. That means no escape handling. */
...@@ -1249,41 +1277,32 @@ do_line (pfile, keyword) ...@@ -1249,41 +1277,32 @@ do_line (pfile, keyword)
{ {
U_CHAR *fname = pfile->token_buffer + old_written + 1; U_CHAR *fname = pfile->token_buffer + old_written + 1;
U_CHAR *end_name = CPP_PWRITTEN (pfile) - 1; U_CHAR *end_name = CPP_PWRITTEN (pfile) - 1;
long num_start = CPP_WRITTEN (pfile); int action_number = 0;
token = get_directive_token (pfile); if (read_line_number (pfile, &action_number))
if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP)
{ {
U_CHAR *p = pfile->token_buffer + num_start;
if (CPP_PEDANTIC (pfile)) if (CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "garbage at end of `#line' command"); cpp_pedwarn (pfile, "garbage at end of `#line' command");
if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0') if (action_number == 1)
{ {
cpp_error (pfile, "invalid format `#line' command");
goto bad_line_directive;
}
if (*p == '1')
file_change = enter_file; file_change = enter_file;
else if (*p == '2') read_line_number (pfile, &action_number);
}
else if (action_number == 2)
{
file_change = leave_file; file_change = leave_file;
else if (*p == '3') read_line_number (pfile, &action_number);
ip->system_header_p = 1; }
else /* if (*p == '4') */ if (action_number == 3)
ip->system_header_p = 2;
CPP_SET_WRITTEN (pfile, num_start);
token = get_directive_token (pfile);
p = pfile->token_buffer + num_start;
if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4'))
{ {
ip->system_header_p = *p == '3' ? 1 : 2; ip->system_header_p = 1;
token = get_directive_token (pfile); read_line_number (pfile, &action_number);
} }
if (token != CPP_VSPACE) if (action_number == 4)
{ {
cpp_error (pfile, "invalid format `#line' command"); ip->system_header_p = 2;
goto bad_line_directive; read_line_number (pfile, &action_number);
} }
} }
......
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