cpplib.c (skip_if_group): Split out the logic that handles directive recognition to its own function.

1998-12-21 18:03 -0500  Zack Weinberg  <zack@rabi.phys.columbia.edu>
	* cpplib.c (skip_if_group): Split out the logic that handles
	directive recognition to its own function.  Don't use
	parse markers; use a bare pointer into the buffer.  Use
	copy/skip_rest_of_line instead of doing it by hand.  Remove
	`return on any directive' mode which was never used, and take
	only one argument.
	(consider_directive_while_skipping): New function, subroutine
	of skip_if_group.  Logic streamlined a bit.
	(conditional_skip, do_elif, do_else): Call skip_if_group with
	only one argument.

From-SVN: r24485
This commit is contained in:
Zack Weinberg 1999-01-04 12:38:22 +00:00 committed by Dave Brolley
parent 16deb3fb8f
commit ed705a8232
2 changed files with 154 additions and 153 deletions

View File

@ -299,6 +299,19 @@ Tue Dec 22 13:02:22 1998 Michael Meissner <meissner@cygnus.com>
* toplev.c (main): Delete handling of -dM as a preprocessor
option.
1998-12-21 18:03 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu>
* cpplib.c (skip_if_group): Split out the logic that handles
directive recognition to its own function. Don't use
parse markers; use a bare pointer into the buffer. Use
copy/skip_rest_of_line instead of doing it by hand. Remove
`return on any directive' mode which was never used, and take
only one argument.
(consider_directive_while_skipping): New function, subroutine
of skip_if_group. Logic streamlined a bit.
(conditional_skip, do_elif, do_else): Call skip_if_group with
only one argument.
Mon Dec 21 17:39:38 1998 Michael Meissner <meissner@cygnus.com>
* toplev.c (main): Don't emit any warnings when using -dD, -dM, or

View File

@ -161,7 +161,7 @@ static struct cpp_pending *nreverse_pending PARAMS ((struct cpp_pending *));
static void conditional_skip PROTO ((cpp_reader *, int,
enum node_type, U_CHAR *));
static void skip_if_group PROTO ((cpp_reader *, int));
static void skip_if_group PROTO ((cpp_reader *));
static int parse_name PARAMS ((cpp_reader *, int));
static void print_help PROTO ((void));
@ -3549,11 +3549,11 @@ do_elif (pfile, keyword)
}
if (pfile->if_stack->if_succeeded)
skip_if_group (pfile, 0);
skip_if_group (pfile);
else {
HOST_WIDE_INT value = eval_if_expression (pfile);
if (value == 0)
skip_if_group (pfile, 0);
skip_if_group (pfile);
else {
++pfile->if_stack->if_succeeded; /* continue processing input */
output_line_command (pfile, 1, same_file);
@ -3695,7 +3695,7 @@ conditional_skip (pfile, skip, type, control_macro)
pfile->if_stack->type = type;
if (skip != 0) {
skip_if_group (pfile, 0);
skip_if_group (pfile);
return;
} else {
++pfile->if_stack->if_succeeded;
@ -3703,167 +3703,155 @@ conditional_skip (pfile, skip, type, control_macro)
}
}
/*
* skip to #endif, #else, or #elif. adjust line numbers, etc.
* leaves input ptr at the sharp sign found.
* If ANY is nonzero, return at next directive of any sort.
*/
/* Subroutine of skip_if_group. Examine one preprocessing directive and
return 0 if skipping should continue, 1 if it should halt. Also
adjusts the if_stack as appropriate.
The `#' has been read, but not the identifier. */
static void
skip_if_group (pfile, any)
static int
consider_directive_while_skipping (pfile, stack)
cpp_reader *pfile;
int any;
IF_STACK_FRAME *stack;
{
int c;
long ident_len, ident;
struct directive *kt;
IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
#if 0
U_CHAR *beg_of_line = bp;
#endif
register int ident_length;
U_CHAR *ident;
struct parse_marker line_start_mark;
IF_STACK_FRAME *temp;
parse_set_mark (&line_start_mark, pfile);
if (CPP_OPTIONS (pfile)->output_conditionals) {
static char failed[] = "#failed\n";
CPP_PUTS (pfile, failed, sizeof(failed)-1);
pfile->lineno++;
output_line_command (pfile, 1, same_file);
}
beg_of_line:
if (CPP_OPTIONS (pfile)->output_conditionals)
{
cpp_buffer *pbuf = CPP_BUFFER (pfile);
U_CHAR *start_line = pbuf->buf + line_start_mark.position;
CPP_PUTS (pfile, start_line, pbuf->cur - start_line);
}
parse_move_mark (&line_start_mark, pfile);
if (!CPP_TRADITIONAL (pfile))
cpp_skip_hspace (pfile);
c = GETC();
if (c == '#')
{
int old_written = CPP_WRITTEN (pfile);
cpp_skip_hspace (pfile);
ident = CPP_WRITTEN (pfile);
parse_name (pfile, GETC());
ident_length = CPP_WRITTEN (pfile) - old_written;
ident = pfile->token_buffer + old_written;
pfile->limit = ident;
#if 0
if (ident_length == 0)
goto not_a_directive;
ident_len = CPP_WRITTEN (pfile) - ident;
/* Handle # followed by a line number. */
/* Avoid error for `###' and similar cases unless -pedantic. */
#endif
CPP_SET_WRITTEN (pfile, ident);
for (kt = directive_table; kt->length >= 0; kt++)
{
IF_STACK_FRAME *temp;
if (ident_length == kt->length
&& strncmp (ident, kt->name, kt->length) == 0)
{
/* If we are asked to return on next directive, do so now. */
if (any)
goto done;
if (kt->length == ident_len
&& strncmp (pfile->token_buffer + ident, kt->name, kt->length) == 0)
switch (kt->type)
{
case T_IF:
case T_IFDEF:
case T_IFNDEF:
temp
= (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
temp = (IF_STACK_FRAME *) xmalloc (sizeof (IF_STACK_FRAME));
temp->next = pfile->if_stack;
pfile->if_stack = temp;
#if 0
temp->lineno = CPP_BUFFER(pfile)->lineno;
#endif
temp->fname = CPP_BUFFER(pfile)->nominal_fname;
temp->type = kt->type;
break;
case T_ELSE:
case T_ENDIF:
if (CPP_PEDANTIC (pfile) && pfile->if_stack != save_if_stack)
validate_else (pfile,
kt->type == T_ELSE ? "#else" : "#endif");
case T_ELIF:
if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
{
cpp_error (pfile,
"`#%s' not within a conditional", kt->name);
break;
}
else if (pfile->if_stack == save_if_stack)
goto done; /* found what we came for */
return 0;
if (kt->type != T_ENDIF)
{
case T_ELSE:
if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
validate_else (pfile, "#else");
/* fall through */
case T_ELIF:
if (pfile->if_stack->type == T_ELSE)
cpp_error (pfile, "`#else' or `#elif' after `#else'");
cpp_error (pfile, "`%s' after `#else'", kt->name);
if (pfile->if_stack == stack)
return 1;
else
{
pfile->if_stack->type = kt->type;
break;
return 0;
}
case T_ENDIF:
if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
validate_else (pfile, "#endif");
if (pfile->if_stack == stack)
return 1;
temp = pfile->if_stack;
pfile->if_stack = temp->next;
free (temp);
break;
default: ;
}
break;
return 0;
default:
return 0;
}
/* Don't let erroneous code go by. */
if (kt->length < 0 && !CPP_OPTIONS (pfile)->lang_asm
&& CPP_PEDANTIC (pfile))
if (!CPP_OPTIONS (pfile)->lang_asm && CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "invalid preprocessor directive name");
return 0;
}
c = GETC ();
}
/* We're in the middle of a line. Skip the rest of it. */
for (;;) {
switch (c)
/* skip to #endif, #else, or #elif. adjust line numbers, etc.
* leaves input ptr at the sharp sign found.
*/
static void
skip_if_group (pfile)
cpp_reader *pfile;
{
long old;
case EOF:
goto done;
case '/': /* possible comment */
c = skip_comment (pfile, NULL);
if (c == EOF)
goto done;
break;
case '\"':
case '\'':
FORWARD(-1);
old = CPP_WRITTEN (pfile);
cpp_get_token (pfile);
CPP_SET_WRITTEN (pfile, old);
break;
case '\\':
/* Char after backslash loses its special meaning. */
if (PEEKC() == '\n')
FORWARD (1);
break;
case '\n':
goto beg_of_line;
break;
int c;
IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
U_CHAR *beg_of_line;
long old_written;
if (CPP_OPTIONS (pfile)->output_conditionals)
{
CPP_PUTS (pfile, "#failed\n", 8);
pfile->lineno++;
output_line_command (pfile, 1, same_file);
}
old_written = CPP_WRITTEN (pfile);
for (;;)
{
beg_of_line = CPP_BUFFER (pfile)->cur;
if (! CPP_TRADITIONAL (pfile))
cpp_skip_hspace (pfile);
c = GETC();
if (c == '\n')
{
if (CPP_OPTIONS (pfile)->output_conditionals)
CPP_PUTC (pfile, c);
continue;
}
done:
if (CPP_OPTIONS (pfile)->output_conditionals) {
static char end_failed[] = "#endfailed\n";
CPP_PUTS (pfile, end_failed, sizeof(end_failed)-1);
else if (c == '#')
{
if (consider_directive_while_skipping (pfile, save_if_stack))
break;
}
else if (c == EOF)
return; /* Caller will issue error. */
FORWARD(-1);
if (CPP_OPTIONS (pfile)->output_conditionals)
{
CPP_PUTS (pfile, beg_of_line, CPP_BUFFER (pfile)->cur - beg_of_line);
copy_rest_of_line (pfile);
}
else
{
copy_rest_of_line (pfile);
CPP_SET_WRITTEN (pfile, old_written); /* discard it */
}
c = GETC();
if (c == EOF)
return; /* Caller will issue error. */
else
{
/* \n */
if (CPP_OPTIONS (pfile)->output_conditionals)
CPP_PUTC (pfile, c);
}
}
/* Back up to the beginning of this line. Caller will process the
directive. */
CPP_BUFFER (pfile)->cur = beg_of_line;
pfile->only_seen_white = 1;
if (CPP_OPTIONS (pfile)->output_conditionals)
{
CPP_PUTS (pfile, "#endfailed\n", 11);
pfile->lineno++;
}
pfile->only_seen_white = 1;
parse_goto_mark (&line_start_mark, pfile);
parse_clear_mark (&line_start_mark);
}
/*
@ -3903,7 +3891,7 @@ do_else (pfile, keyword)
}
if (pfile->if_stack->if_succeeded)
skip_if_group (pfile, 0);
skip_if_group (pfile);
else {
++pfile->if_stack->if_succeeded; /* continue processing input */
output_line_command (pfile, 1, same_file);