Commit ed705a82 by Zack Weinberg Committed by Dave Brolley

cpplib.c (skip_if_group): Split out the logic that handles directive recognition…

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