From 8e33b8751468a174737a9b924dc901745db6cfcd Mon Sep 17 00:00:00 2001 From: brolley Date: Mon, 4 Jan 1999 12:38:22 +0000 Subject: [PATCH] 1998-12-21 18:03 -0500 Zack Weinberg * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@24485 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 13 +++ gcc/cpplib.c | 288 ++++++++++++++++++++++++++++------------------------------ 2 files changed, 151 insertions(+), 150 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e589f505a82..f7785e6f153 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -299,6 +299,19 @@ Tue Dec 22 13:02:22 1998 Michael Meissner * toplev.c (main): Delete handling of -dM as a preprocessor option. +1998-12-21 18:03 -0500 Zack Weinberg + + * 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 * toplev.c (main): Don't emit any warnings when using -dD, -dM, or diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 891b31278d3..f9990c85125 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -160,8 +160,8 @@ static void push_macro_expansion PARAMS ((cpp_reader *, 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)); + enum node_type, U_CHAR *)); +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. +/* 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 int +consider_directive_while_skipping (pfile, stack) + cpp_reader *pfile; + IF_STACK_FRAME *stack; +{ + long ident_len, ident; + struct directive *kt; + IF_STACK_FRAME *temp; + + cpp_skip_hspace (pfile); + + ident = CPP_WRITTEN (pfile); + parse_name (pfile, GETC()); + ident_len = CPP_WRITTEN (pfile) - ident; + + CPP_SET_WRITTEN (pfile, ident); + + for (kt = directive_table; kt->length >= 0; kt++) + 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 *) xmalloc (sizeof (IF_STACK_FRAME)); + temp->next = pfile->if_stack; + pfile->if_stack = temp; + temp->fname = CPP_BUFFER(pfile)->nominal_fname; + temp->type = kt->type; + return 0; + + 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, "`%s' after `#else'", kt->name); + + if (pfile->if_stack == stack) + return 1; + else + { + pfile->if_stack->type = kt->type; + 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); + return 0; + + default: + return 0; + } + + /* Don't let erroneous code go by. */ + if (!CPP_OPTIONS (pfile)->lang_asm && CPP_PEDANTIC (pfile)) + 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. - * If ANY is nonzero, return at next directive of any sort. */ - static void -skip_if_group (pfile, any) - cpp_reader *pfile; - int any; +skip_if_group (pfile) + cpp_reader *pfile; { int c; - 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; - - 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); - } + U_CHAR *beg_of_line; + long old_written; - 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); + CPP_PUTS (pfile, "#failed\n", 8); + pfile->lineno++; + output_line_command (pfile, 1, same_file); } - 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); - 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; - - /* Handle # followed by a line number. */ - - /* Avoid error for `###' and similar cases unless -pedantic. */ -#endif + old_written = CPP_WRITTEN (pfile); + + for (;;) + { + beg_of_line = CPP_BUFFER (pfile)->cur; - for (kt = directive_table; kt->length >= 0; kt++) + if (! CPP_TRADITIONAL (pfile)) + cpp_skip_hspace (pfile); + c = GETC(); + if (c == '\n') { - 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; - - switch (kt->type) - { - case T_IF: - case T_IFDEF: - case T_IFNDEF: - temp - = (IF_STACK_FRAME *) xcalloc (1, 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 */ + if (CPP_OPTIONS (pfile)->output_conditionals) + CPP_PUTC (pfile, c); + continue; + } + else if (c == '#') + { + if (consider_directive_while_skipping (pfile, save_if_stack)) + break; + } + else if (c == EOF) + return; /* Caller will issue error. */ - if (kt->type != T_ENDIF) - { - if (pfile->if_stack->type == T_ELSE) - cpp_error (pfile, "`#else' or `#elif' after `#else'"); - pfile->if_stack->type = kt->type; - break; - } + 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 */ + } - temp = pfile->if_stack; - pfile->if_stack = temp->next; - free (temp); - break; - default: ; - } - break; - } - /* Don't let erroneous code go by. */ - if (kt->length < 0 && !CPP_OPTIONS (pfile)->lang_asm - && CPP_PEDANTIC (pfile)) - cpp_pedwarn (pfile, "invalid preprocessor directive name"); + c = GETC(); + if (c == EOF) + return; /* Caller will issue error. */ + else + { + /* \n */ + if (CPP_OPTIONS (pfile)->output_conditionals) + CPP_PUTC (pfile, c); } - c = GETC (); - } - /* We're in the middle of a line. Skip the rest of it. */ - for (;;) { - switch (c) - { - 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; - } - c = GETC (); - } - done: - if (CPP_OPTIONS (pfile)->output_conditionals) { - static char end_failed[] = "#endfailed\n"; - CPP_PUTS (pfile, end_failed, sizeof(end_failed)-1); - pfile->lineno++; - } + } + + /* 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; - parse_goto_mark (&line_start_mark, pfile); - parse_clear_mark (&line_start_mark); + if (CPP_OPTIONS (pfile)->output_conditionals) + { + CPP_PUTS (pfile, "#endfailed\n", 11); + pfile->lineno++; + } } /* @@ -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); -- 2.11.0