diff options
Diffstat (limited to 'support/cpp/libcpp/directives.c')
-rw-r--r-- | support/cpp/libcpp/directives.c | 1027 |
1 files changed, 552 insertions, 475 deletions
diff --git a/support/cpp/libcpp/directives.c b/support/cpp/libcpp/directives.c index 13daba97b..49f70b54d 100644 --- a/support/cpp/libcpp/directives.c +++ b/support/cpp/libcpp/directives.c @@ -32,11 +32,11 @@ along with this program; see the file COPYING3. If not see struct if_stack { struct if_stack *next; - linenum_type line; /* Line where condition started. */ + linenum_type line; /* Line where condition started. */ const cpp_hashnode *mi_cmacro;/* macro name for #ifndef around entire file */ - bool skip_elses; /* Can future #else / #elif be skipped? */ - bool was_skipping; /* If were skipping on entry. */ - int type; /* Most recent conditional for diagnostics. */ + bool skip_elses; /* Can future #else / #elif be skipped? */ + bool was_skipping; /* If were skipping on entry. */ + int type; /* Most recent conditional for diagnostics. */ }; /* Contains a registered pragma or pragma namespace. */ @@ -44,7 +44,7 @@ typedef void (*pragma_cb) (cpp_reader *); struct pragma_entry { struct pragma_entry *next; - const cpp_hashnode *pragma; /* Name and length. */ + const cpp_hashnode *pragma; /* Name and length. */ bool is_nspace; bool is_internal; bool is_deferred; @@ -59,9 +59,9 @@ struct pragma_entry /* Values for the origin field of struct directive. KANDR directives come from traditional (K&R) C. STDC89 directives come from the 1989 C standard. EXTENSION directives are extensions. */ -#define KANDR 0 -#define STDC89 1 -#define EXTENSION 2 +#define KANDR 0 +#define STDC89 1 +#define EXTENSION 2 /* Values for the flags field of struct directive. COND indicates a conditional; IF_COND an opening conditional. INCL means to treat @@ -70,23 +70,23 @@ struct pragma_entry effect (these are the directives with callback hooks). EXPAND is set on directives that are always macro-expanded. */ -#define COND (1 << 0) -#define IF_COND (1 << 1) -#define INCL (1 << 2) -#define IN_I (1 << 3) -#define EXPAND (1 << 4) -#define DEPRECATED (1 << 5) +#define COND (1 << 0) +#define IF_COND (1 << 1) +#define INCL (1 << 2) +#define IN_I (1 << 3) +#define EXPAND (1 << 4) +#define DEPRECATED (1 << 5) /* Defines one #-directive, including how to handle it. */ typedef void (*directive_handler) (cpp_reader *); typedef struct directive directive; struct directive { - directive_handler handler; /* Function to handle directive. */ - const uchar *name; /* Name of directive. */ - unsigned short length; /* Length of name. */ - unsigned char origin; /* Origin of directive. */ - unsigned char flags; /* Flags describing this directive. */ + directive_handler handler; /* Function to handle directive. */ + const uchar *name; /* Name of directive. */ + unsigned short length; /* Length of name. */ + unsigned char origin; /* Origin of directive. */ + unsigned char flags; /* Flags describing this directive. */ }; /* Forward declarations. */ @@ -125,6 +125,8 @@ static int parse_answer (cpp_reader *, struct answer **, int); static cpp_hashnode *parse_assertion (cpp_reader *, struct answer **, int); static struct answer ** find_answer (cpp_hashnode *, const struct answer *); static void handle_assertion (cpp_reader *, const char *, int); +static void do_pragma_push_macro (cpp_reader *); +static void do_pragma_pop_macro (cpp_reader *); /* This is the table of directive handlers. It is ordered by frequency of occurrence; the numbers at the end are directive @@ -135,26 +137,26 @@ static void handle_assertion (cpp_reader *, const char *, int); and #import are deprecated. The name is where the extension appears to have come from. */ -#define DIRECTIVE_TABLE \ -D(define, T_DEFINE = 0, KANDR, IN_I) /* 270554 */ \ -D(include, T_INCLUDE, KANDR, INCL | EXPAND) /* 52262 */ \ -D(endif, T_ENDIF, KANDR, COND) /* 45855 */ \ -D(ifdef, T_IFDEF, KANDR, COND | IF_COND) /* 22000 */ \ -D(if, T_IF, KANDR, COND | IF_COND | EXPAND) /* 18162 */ \ -D(else, T_ELSE, KANDR, COND) /* 9863 */ \ -D(ifndef, T_IFNDEF, KANDR, COND | IF_COND) /* 9675 */ \ -D(undef, T_UNDEF, KANDR, IN_I) /* 4837 */ \ -D(line, T_LINE, KANDR, EXPAND) /* 2465 */ \ -D(elif, T_ELIF, STDC89, COND | EXPAND) /* 610 */ \ -D(error, T_ERROR, STDC89, 0) /* 475 */ \ -D(pragma, T_PRAGMA, STDC89, IN_I) /* 195 */ \ -D(warning, T_WARNING, EXTENSION, 0) /* 22 */ \ -D(include_next, T_INCLUDE_NEXT, EXTENSION, INCL | EXPAND) /* 19 */ \ -D(ident, T_IDENT, EXTENSION, IN_I | DEPRECATED) /* 11 */ \ -D(import, T_IMPORT, EXTENSION, INCL | EXPAND) /* 0 ObjC */ \ -D(assert, T_ASSERT, EXTENSION, DEPRECATED) /* 0 SVR4 */ \ -D(unassert, T_UNASSERT, EXTENSION, DEPRECATED) /* 0 SVR4 */ \ -D(sccs, T_SCCS, EXTENSION, IN_I | DEPRECATED) /* 0 SVR4? */ +#define DIRECTIVE_TABLE \ +D(define, T_DEFINE = 0, KANDR, IN_I) /* 270554 */ \ +D(include, T_INCLUDE, KANDR, INCL | EXPAND) /* 52262 */ \ +D(endif, T_ENDIF, KANDR, COND) /* 45855 */ \ +D(ifdef, T_IFDEF, KANDR, COND | IF_COND) /* 22000 */ \ +D(if, T_IF, KANDR, COND | IF_COND | EXPAND) /* 18162 */ \ +D(else, T_ELSE, KANDR, COND) /* 9863 */ \ +D(ifndef, T_IFNDEF, KANDR, COND | IF_COND) /* 9675 */ \ +D(undef, T_UNDEF, KANDR, IN_I) /* 4837 */ \ +D(line, T_LINE, KANDR, EXPAND) /* 2465 */ \ +D(elif, T_ELIF, STDC89, COND | EXPAND) /* 610 */ \ +D(error, T_ERROR, STDC89, 0) /* 475 */ \ +D(pragma, T_PRAGMA, STDC89, IN_I) /* 195 */ \ +D(warning, T_WARNING, EXTENSION, 0) /* 22 */ \ +D(include_next, T_INCLUDE_NEXT, EXTENSION, INCL | EXPAND) /* 19 */ \ +D(ident, T_IDENT, EXTENSION, IN_I | DEPRECATED) /* 11 */ \ +D(import, T_IMPORT, EXTENSION, INCL | EXPAND) /* 0 ObjC */ \ +D(assert, T_ASSERT, EXTENSION, DEPRECATED) /* 0 SVR4 */ \ +D(unassert, T_UNASSERT, EXTENSION, DEPRECATED) /* 0 SVR4 */ \ +D(sccs, T_SCCS, EXTENSION, IN_I | DEPRECATED) /* 0 SVR4? */ /* #sccs is synonymous with #ident. */ #define do_sccs do_ident @@ -214,7 +216,7 @@ check_eol (cpp_reader *pfile) { if (! SEEN_EOL () && _cpp_lex_token (pfile)->type != CPP_EOF) cpp_error (pfile, CPP_DL_PEDWARN, "extra tokens at end of #%s directive", - pfile->directive->name); + pfile->directive->name); } /* Ensure there are no stray tokens other than comments at the end of @@ -231,27 +233,27 @@ check_eol_return_comments (cpp_reader *pfile) if (! SEEN_EOL ()) { while (1) - { - const cpp_token *tok; - - tok = _cpp_lex_token (pfile); - if (tok->type == CPP_EOF) - break; - if (tok->type != CPP_COMMENT) - cpp_error (pfile, CPP_DL_PEDWARN, - "extra tokens at end of #%s directive", - pfile->directive->name); - else - { - if (c + 1 >= capacity) - { - capacity *= 2; - buf = XRESIZEVEC (const cpp_token *, buf, capacity); - } - buf[c] = tok; - ++c; - } - } + { + const cpp_token *tok; + + tok = _cpp_lex_token (pfile); + if (tok->type == CPP_EOF) + break; + if (tok->type != CPP_COMMENT) + cpp_error (pfile, CPP_DL_PEDWARN, + "extra tokens at end of #%s directive", + pfile->directive->name); + else + { + if (c + 1 >= capacity) + { + capacity *= 2; + buf = XRESIZEVEC (const cpp_token *, buf, capacity); + } + buf[c] = tok; + ++c; + } + } } buf[c] = NULL; return buf; @@ -282,17 +284,17 @@ end_directive (cpp_reader *pfile, int skip_line) pfile->state.prevent_expansion--; if (pfile->directive != &dtable[T_DEFINE]) - _cpp_remove_overlay (pfile); + _cpp_remove_overlay (pfile); } /* We don't skip for an assembler #. */ else if (skip_line) { skip_rest_of_line (pfile); if (!pfile->keep_tokens) - { - pfile->cur_run = &pfile->base_run; - pfile->cur_token = pfile->base_run.base; - } + { + pfile->cur_run = &pfile->base_run; + pfile->cur_token = pfile->base_run.base; + } } /* Restore state. */ @@ -310,23 +312,23 @@ prepare_directive_trad (cpp_reader *pfile) if (pfile->directive != &dtable[T_DEFINE]) { bool no_expand = (pfile->directive - && ! (pfile->directive->flags & EXPAND)); + && ! (pfile->directive->flags & EXPAND)); bool was_skipping = pfile->state.skipping; pfile->state.in_expression = (pfile->directive == &dtable[T_IF] - || pfile->directive == &dtable[T_ELIF]); + || pfile->directive == &dtable[T_ELIF]); if (pfile->state.in_expression) - pfile->state.skipping = false; + pfile->state.skipping = false; if (no_expand) - pfile->state.prevent_expansion++; + pfile->state.prevent_expansion++; _cpp_scan_out_logical_line (pfile, NULL); if (no_expand) - pfile->state.prevent_expansion--; + pfile->state.prevent_expansion--; pfile->state.skipping = was_skipping; _cpp_overlay_buffer (pfile, pfile->out.base, - pfile->out.cur - pfile->out.base); + pfile->out.cur - pfile->out.base); } /* Stop ISO C from expanding anything. */ @@ -343,14 +345,14 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented) if (! pfile->state.skipping) { if (dir->origin == EXTENSION - && !(dir == &dtable[T_IMPORT] && CPP_OPTION (pfile, objc)) - && CPP_PEDANTIC (pfile)) - cpp_error (pfile, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name); + && !(dir == &dtable[T_IMPORT] && CPP_OPTION (pfile, objc)) + && CPP_PEDANTIC (pfile)) + cpp_error (pfile, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name); else if (((dir->flags & DEPRECATED) != 0 - || (dir == &dtable[T_IMPORT] && !CPP_OPTION (pfile, objc))) - && CPP_OPTION (pfile, warn_deprecated)) - cpp_error (pfile, CPP_DL_WARNING, "#%s is a deprecated GCC extension", - dir->name); + || (dir == &dtable[T_IMPORT] && !CPP_OPTION (pfile, objc))) + && CPP_OPTION (pfile, warn_deprecated)) + cpp_error (pfile, CPP_DL_WARNING, "#%s is a deprecated GCC extension", + dir->name); } /* Traditionally, a directive is ignored unless its # is in @@ -362,16 +364,16 @@ directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented) if (CPP_WTRADITIONAL (pfile)) { if (dir == &dtable[T_ELIF]) - cpp_error (pfile, CPP_DL_WARNING, - "suggest not using #elif in traditional C"); + cpp_error (pfile, CPP_DL_WARNING, + "suggest not using #elif in traditional C"); else if (indented && dir->origin == KANDR) - cpp_error (pfile, CPP_DL_WARNING, - "traditional C ignores #%s with the # indented", - dir->name); + cpp_error (pfile, CPP_DL_WARNING, + "traditional C ignores #%s with the # indented", + dir->name); else if (!indented && dir->origin != KANDR) - cpp_error (pfile, CPP_DL_WARNING, - "suggest hiding #%s from traditional C with an indented #", - dir->name); + cpp_error (pfile, CPP_DL_WARNING, + "suggest hiding #%s from traditional C with an indented #", + dir->name); } } @@ -395,8 +397,8 @@ _cpp_handle_directive (cpp_reader *pfile, int indented) if (was_parsing_args) { if (CPP_OPTION (pfile, pedantic)) - cpp_error (pfile, CPP_DL_PEDWARN, - "embedding a directive within macro arguments is not portable"); + cpp_error (pfile, CPP_DL_PEDWARN, + "embedding a directive within macro arguments is not portable"); pfile->state.parsing_args = 0; pfile->state.prevent_expansion = 0; } @@ -406,7 +408,7 @@ _cpp_handle_directive (cpp_reader *pfile, int indented) if (dname->type == CPP_NAME) { if (dname->val.node->is_directive) - dir = &dtable[dname->val.node->directive_index]; + dir = &dtable[dname->val.node->directive_index]; } /* We do not recognize the # followed by a number extension in assembler code. */ @@ -414,65 +416,65 @@ _cpp_handle_directive (cpp_reader *pfile, int indented) { dir = &linemarker_dir; if (CPP_PEDANTIC (pfile) && ! CPP_OPTION (pfile, preprocessed) - && ! pfile->state.skipping) - cpp_error (pfile, CPP_DL_PEDWARN, - "style of line directive is a GCC extension"); + && ! pfile->state.skipping) + cpp_error (pfile, CPP_DL_PEDWARN, + "style of line directive is a GCC extension"); } if (dir) { /* If we have a directive that is not an opening conditional, - invalidate any control macro. */ + invalidate any control macro. */ if (! (dir->flags & IF_COND)) - pfile->mi_valid = false; + pfile->mi_valid = false; /* Kluge alert. In order to be sure that code like this - #define HASH # - HASH define foo bar - - does not cause '#define foo bar' to get executed when - compiled with -save-temps, we recognize directives in - -fpreprocessed mode only if the # is in column 1. macro.c - puts a space in front of any '#' at the start of a macro. - - We exclude the -fdirectives-only case because macro expansion - has not been performed yet, and block comments can cause spaces - to preceed the directive. */ + #define HASH # + HASH define foo bar + + does not cause '#define foo bar' to get executed when + compiled with -save-temps, we recognize directives in + -fpreprocessed mode only if the # is in column 1. macro.c + puts a space in front of any '#' at the start of a macro. + + We exclude the -fdirectives-only case because macro expansion + has not been performed yet, and block comments can cause spaces + to preceed the directive. */ if (CPP_OPTION (pfile, preprocessed) - && !CPP_OPTION (pfile, directives_only) - && (indented || !(dir->flags & IN_I))) - { - skip = 0; - dir = 0; - } + && !CPP_OPTION (pfile, directives_only) + && (indented || !(dir->flags & IN_I))) + { + skip = 0; + dir = 0; + } else - { - /* In failed conditional groups, all non-conditional - directives are ignored. Before doing that, whether - skipping or not, we should lex angle-bracketed headers - correctly, and maybe output some diagnostics. */ - pfile->state.angled_headers = dir->flags & INCL; - pfile->state.directive_wants_padding = dir->flags & INCL; - if (! CPP_OPTION (pfile, preprocessed)) - directive_diagnostics (pfile, dir, indented); - if (pfile->state.skipping && !(dir->flags & COND)) - dir = 0; - } + { + /* In failed conditional groups, all non-conditional + directives are ignored. Before doing that, whether + skipping or not, we should lex angle-bracketed headers + correctly, and maybe output some diagnostics. */ + pfile->state.angled_headers = dir->flags & INCL; + pfile->state.directive_wants_padding = dir->flags & INCL; + if (! CPP_OPTION (pfile, preprocessed)) + directive_diagnostics (pfile, dir, indented); + if (pfile->state.skipping && !(dir->flags & COND)) + dir = 0; + } } else if (dname->type == CPP_EOF) - ; /* CPP_EOF is the "null directive". */ + ; /* CPP_EOF is the "null directive". */ else { /* An unknown directive. Don't complain about it in assembly - source: we don't know where the comments are, and # may - introduce assembler pseudo-ops. Don't complain about invalid - directives in skipped conditional groups (6.10 p4). */ + source: we don't know where the comments are, and # may + introduce assembler pseudo-ops. Don't complain about invalid + directives in skipped conditional groups (6.10 p4). */ if (CPP_OPTION (pfile, lang) == CLK_ASM) - skip = 0; + skip = 0; else if (!pfile->state.skipping) - cpp_error (pfile, CPP_DL_ERROR, "invalid preprocessing directive #%s", - cpp_token_as_text (pfile, dname)); + cpp_error (pfile, CPP_DL_ERROR, "invalid preprocessing directive #%s", + cpp_token_as_text (pfile, dname)); } pfile->directive = dir; @@ -502,7 +504,7 @@ static void run_directive (cpp_reader *pfile, int dir_no, const char *buf, size_t count) { cpp_push_buffer (pfile, (const uchar *) buf, count, - /* from_stage3 */ true); + /* from_stage3 */ true); start_directive (pfile); /* This is a short-term fix to prevent a leading '#' being @@ -538,18 +540,18 @@ lex_macro_node (cpp_reader *pfile, bool is_def_or_undef) cpp_hashnode *node = token->val.node; if (is_def_or_undef && node == pfile->spec_nodes.n_defined) - cpp_error (pfile, CPP_DL_ERROR, - "\"defined\" cannot be used as a macro name"); + cpp_error (pfile, CPP_DL_ERROR, + "\"defined\" cannot be used as a macro name"); else if (! (node->flags & NODE_POISONED)) - return node; + return node; } else if (token->flags & NAMED_OP) cpp_error (pfile, CPP_DL_ERROR, "\"%s\" cannot be used as a macro name as it is an operator in C++", - NODE_NAME (token->val.node)); + NODE_NAME (token->val.node)); else if (token->type == CPP_EOF) cpp_error (pfile, CPP_DL_ERROR, "no macro name given in #%s directive", - pfile->directive->name); + pfile->directive->name); else cpp_error (pfile, CPP_DL_ERROR, "macro names must be identifiers"); @@ -565,16 +567,16 @@ do_define (cpp_reader *pfile) if (node) { /* If we have been requested to expand comments into macros, - then re-enable saving of comments. */ + then re-enable saving of comments. */ pfile->state.save_comments = - ! CPP_OPTION (pfile, discard_comments_in_macro_exp); + ! CPP_OPTION (pfile, discard_comments_in_macro_exp); if (pfile->cb.before_define) - pfile->cb.before_define (pfile); + pfile->cb.before_define (pfile); if (_cpp_create_definition (pfile, node)) - if (pfile->cb.define) - pfile->cb.define (pfile, pfile->directive_line, node); + if (pfile->cb.define) + pfile->cb.define (pfile, pfile->directive_line, node); node->flags &= ~NODE_USED; } @@ -589,24 +591,24 @@ do_undef (cpp_reader *pfile) if (node) { if (pfile->cb.before_define) - pfile->cb.before_define (pfile); + pfile->cb.before_define (pfile); if (pfile->cb.undef) - pfile->cb.undef (pfile, pfile->directive_line, node); + pfile->cb.undef (pfile, pfile->directive_line, node); /* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified - identifier is not currently defined as a macro name. */ + identifier is not currently defined as a macro name. */ if (node->type == NT_MACRO) - { - if (node->flags & NODE_WARN) - cpp_error (pfile, CPP_DL_WARNING, - "undefining \"%s\"", NODE_NAME (node)); + { + if (node->flags & NODE_WARN) + cpp_error (pfile, CPP_DL_WARNING, + "undefining \"%s\"", NODE_NAME (node)); - if (CPP_OPTION (pfile, warn_unused_macros)) - _cpp_warn_if_unused_macro (pfile, node, NULL); + if (CPP_OPTION (pfile, warn_unused_macros)) + _cpp_warn_if_unused_macro (pfile, node, NULL); - _cpp_free_definition (node); - } + _cpp_free_definition (node); + } } check_eol (pfile); @@ -616,7 +618,7 @@ do_undef (cpp_reader *pfile) static int undefine_macros (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *h, - void *data_p ATTRIBUTE_UNUSED) + void *data_p ATTRIBUTE_UNUSED) { /* Body of _cpp_free_definition inlined here for speed. Macros and assertions no longer have anything to free. */ @@ -652,26 +654,26 @@ glue_header_name (cpp_reader *pfile) token = get_token_no_padding (pfile); if (token->type == CPP_GREATER) - break; + break; if (token->type == CPP_EOF) - { - cpp_error (pfile, CPP_DL_ERROR, "missing terminating > character"); - break; - } + { + cpp_error (pfile, CPP_DL_ERROR, "missing terminating > character"); + break; + } len = cpp_token_len (token) + 2; /* Leading space, terminating \0. */ if (total_len + len > capacity) - { - capacity = (capacity + len) * 2; - buffer = XRESIZEVEC (char, buffer, capacity); - } + { + capacity = (capacity + len) * 2; + buffer = XRESIZEVEC (char, buffer, capacity); + } if (token->flags & PREV_WHITE) - buffer[total_len++] = ' '; + buffer[total_len++] = ' '; total_len = (cpp_spell_token (pfile, token, (uchar *) &buffer[total_len], - true) - - (uchar *) buffer); + true) + - (uchar *) buffer); } buffer[total_len] = '\0'; @@ -683,7 +685,7 @@ glue_header_name (cpp_reader *pfile) free it. Returns NULL on error. */ static const char * parse_include (cpp_reader *pfile, int *pangle_brackets, - const cpp_token ***buf) + const cpp_token ***buf) { char *fname; const cpp_token *header; @@ -707,11 +709,11 @@ parse_include (cpp_reader *pfile, int *pangle_brackets, const unsigned char *dir; if (pfile->directive == &dtable[T_PRAGMA]) - dir = UC"pragma dependency"; + dir = UC"pragma dependency"; else - dir = pfile->directive->name; + dir = pfile->directive->name; cpp_error (pfile, CPP_DL_ERROR, "#%s expects \"FILENAME\" or <FILENAME>", - dir); + dir); return NULL; } @@ -725,7 +727,7 @@ parse_include (cpp_reader *pfile, int *pangle_brackets, else { /* If we are not discarding comments, then gather them while - doing the eol check. */ + doing the eol check. */ *buf = check_eol_return_comments (pfile); } @@ -748,7 +750,7 @@ do_include_common (cpp_reader *pfile, enum include_type type) if (!fname) { if (buf) - XDELETEVEC (buf); + XDELETEVEC (buf); return; } @@ -771,9 +773,9 @@ do_include_common (cpp_reader *pfile, enum include_type type) skip_rest_of_line (pfile); if (pfile->cb.include) - pfile->cb.include (pfile, pfile->directive_line, - pfile->directive->name, fname, angle_brackets, - buf); + pfile->cb.include (pfile, pfile->directive_line, + pfile->directive->name, fname, angle_brackets, + buf); _cpp_stack_include (pfile, fname, angle_brackets, type); } @@ -805,7 +807,7 @@ do_include_next (cpp_reader *pfile) if (cpp_in_primary_file (pfile)) { cpp_error (pfile, CPP_DL_WARNING, - "#include_next in primary source file"); + "#include_next in primary source file"); type = IT_INCLUDE; } do_include_common (pfile, type); @@ -825,14 +827,14 @@ read_flag (cpp_reader *pfile, unsigned int last) unsigned int flag = token->val.str.text[0] - '0'; if (flag > last && flag <= 4 - && (flag != 4 || last == 3) - && (flag != 2 || last == 0)) - return flag; + && (flag != 4 || last == 3) + && (flag != 2 || last == 0)) + return flag; } if (token->type != CPP_EOF) cpp_error (pfile, CPP_DL_ERROR, "invalid flag \"%s\" in line directive", - cpp_token_as_text (pfile, token)); + cpp_token_as_text (pfile, token)); return 0; } @@ -852,11 +854,11 @@ strtolinenum (const uchar *str, size_t len, linenum_type *nump, bool *wrapped) { c = *str++; if (!ISDIGIT (c)) - return true; + return true; reg *= 10; reg += c - '0'; - if (reg < reg_prev) - *wrapped = true; + if (reg < reg_prev) + *wrapped = true; reg_prev = reg; } *nump = reg; @@ -888,14 +890,14 @@ do_line (cpp_reader *pfile) token = cpp_get_token (pfile); if (token->type != CPP_NUMBER || strtolinenum (token->val.str.text, token->val.str.len, - &new_lineno, &wrapped)) + &new_lineno, &wrapped)) { if (token->type == CPP_EOF) - cpp_error (pfile, CPP_DL_ERROR, "unexpected end of file after #line"); + cpp_error (pfile, CPP_DL_ERROR, "unexpected end of file after #line"); else - cpp_error (pfile, CPP_DL_ERROR, - "\"%s\" after #line is not a positive integer", - cpp_token_as_text (pfile, token)); + cpp_error (pfile, CPP_DL_ERROR, + "\"%s\" after #line is not a positive integer", + cpp_token_as_text (pfile, token)); return; } @@ -909,20 +911,20 @@ do_line (cpp_reader *pfile) { cpp_string s = { 0, 0 }; if (cpp_interpret_string_notranslate (pfile, &token->val.str, 1, - &s, false)) - new_file = (const char *)s.text; + &s, false)) + new_file = (const char *)s.text; check_eol (pfile); } else if (token->type != CPP_EOF) { cpp_error (pfile, CPP_DL_ERROR, "\"%s\" is not a valid filename", - cpp_token_as_text (pfile, token)); + cpp_token_as_text (pfile, token)); return; } skip_rest_of_line (pfile); _cpp_do_file_change (pfile, LC_RENAME, new_file, new_lineno, - map_sysp); + map_sysp); } /* Interpret the # 44 "file" [flags] notation, which has slightly @@ -950,13 +952,13 @@ do_linemarker (cpp_reader *pfile) token = cpp_get_token (pfile); if (token->type != CPP_NUMBER || strtolinenum (token->val.str.text, token->val.str.len, - &new_lineno, &wrapped)) + &new_lineno, &wrapped)) { /* Unlike #line, there does not seem to be a way to get an EOF - here. So, it should be safe to always spell the token. */ + here. So, it should be safe to always spell the token. */ cpp_error (pfile, CPP_DL_ERROR, - "\"%s\" after # is not a positive integer", - cpp_token_as_text (pfile, token)); + "\"%s\" after # is not a positive integer", + cpp_token_as_text (pfile, token)); return; } @@ -965,30 +967,30 @@ do_linemarker (cpp_reader *pfile) { cpp_string s = { 0, 0 }; if (cpp_interpret_string_notranslate (pfile, &token->val.str, - 1, &s, false)) - new_file = (const char *)s.text; + 1, &s, false)) + new_file = (const char *)s.text; new_sysp = 0; flag = read_flag (pfile, 0); if (flag == 1) - { - reason = LC_ENTER; - /* Fake an include for cpp_included (). */ - _cpp_fake_include (pfile, new_file); - flag = read_flag (pfile, flag); - } + { + reason = LC_ENTER; + /* Fake an include for cpp_included (). */ + _cpp_fake_include (pfile, new_file); + flag = read_flag (pfile, flag); + } else if (flag == 2) - { - reason = LC_LEAVE; - flag = read_flag (pfile, flag); - } + { + reason = LC_LEAVE; + flag = read_flag (pfile, flag); + } if (flag == 3) - { - new_sysp = 1; - flag = read_flag (pfile, flag); - if (flag == 4) - new_sysp = 2; - } + { + new_sysp = 1; + flag = read_flag (pfile, flag); + if (flag == 4) + new_sysp = 2; + } pfile->buffer->sysp = new_sysp; check_eol (pfile); @@ -996,7 +998,7 @@ do_linemarker (cpp_reader *pfile) else if (token->type != CPP_EOF) { cpp_error (pfile, CPP_DL_ERROR, "\"%s\" is not a valid filename", - cpp_token_as_text (pfile, token)); + cpp_token_as_text (pfile, token)); return; } @@ -1010,11 +1012,11 @@ do_linemarker (cpp_reader *pfile) and zero otherwise. */ void _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason, - const char *to_file, linenum_type file_line, - unsigned int sysp) + const char *to_file, linenum_type file_line, + unsigned int sysp) { const struct line_map *map = linemap_add (pfile->line_table, reason, sysp, - to_file, file_line); + to_file, file_line); if (map != NULL) linemap_line_start (pfile->line_table, map->to_line, 127); @@ -1064,7 +1066,7 @@ do_ident (cpp_reader *pfile) if (str->type != CPP_STRING) cpp_error (pfile, CPP_DL_ERROR, "invalid #%s directive", - pfile->directive->name); + pfile->directive->name); else if (pfile->cb.ident) pfile->cb.ident (pfile, pfile->directive_line, &str->val.str); @@ -1104,7 +1106,7 @@ new_pragma_entry (cpp_reader *pfile, struct pragma_entry **chain) goes in the global namespace. */ static struct pragma_entry * register_pragma_1 (cpp_reader *pfile, const char *space, const char *name, - bool allow_name_expansion) + bool allow_name_expansion) { struct pragma_entry **chain = &pfile->pragmas; struct pragma_entry *entry; @@ -1115,28 +1117,28 @@ register_pragma_1 (cpp_reader *pfile, const char *space, const char *name, node = cpp_lookup (pfile, UC space, strlen (space)); entry = lookup_pragma_entry (*chain, node); if (!entry) - { - entry = new_pragma_entry (pfile, chain); - entry->pragma = node; - entry->is_nspace = true; - entry->allow_expansion = allow_name_expansion; - } + { + entry = new_pragma_entry (pfile, chain); + entry->pragma = node; + entry->is_nspace = true; + entry->allow_expansion = allow_name_expansion; + } else if (!entry->is_nspace) - goto clash; + goto clash; else if (entry->allow_expansion != allow_name_expansion) - { - cpp_error (pfile, CPP_DL_ICE, - "registering pragmas in namespace \"%s\" with mismatched " - "name expansion", space); - return NULL; - } + { + cpp_error (pfile, CPP_DL_ICE, + "registering pragmas in namespace \"%s\" with mismatched " + "name expansion", space); + return NULL; + } chain = &entry->u.space; } else if (allow_name_expansion) { cpp_error (pfile, CPP_DL_ICE, - "registering pragma \"%s\" with name expansion " - "and no namespace", name); + "registering pragma \"%s\" with name expansion " + "and no namespace", name); return NULL; } @@ -1153,11 +1155,11 @@ register_pragma_1 (cpp_reader *pfile, const char *space, const char *name, if (entry->is_nspace) clash: cpp_error (pfile, CPP_DL_ICE, - "registering \"%s\" as both a pragma and a pragma namespace", - NODE_NAME (node)); + "registering \"%s\" as both a pragma and a pragma namespace", + NODE_NAME (node)); else if (space) cpp_error (pfile, CPP_DL_ICE, "#pragma %s %s is already registered", - space, name); + space, name); else cpp_error (pfile, CPP_DL_ICE, "#pragma %s is already registered", name); @@ -1167,7 +1169,7 @@ register_pragma_1 (cpp_reader *pfile, const char *space, const char *name, /* Register a cpplib internal pragma SPACE NAME with HANDLER. */ static void register_pragma_internal (cpp_reader *pfile, const char *space, - const char *name, pragma_cb handler) + const char *name, pragma_cb handler) { struct pragma_entry *entry; @@ -1183,7 +1185,7 @@ register_pragma_internal (cpp_reader *pfile, const char *space, from libcpp. */ void cpp_register_pragma (cpp_reader *pfile, const char *space, const char *name, - pragma_cb handler, bool allow_expansion) + pragma_cb handler, bool allow_expansion) { struct pragma_entry *entry; @@ -1206,8 +1208,8 @@ cpp_register_pragma (cpp_reader *pfile, const char *space, const char *name, with IDENT in the token->u.pragma slot. */ void cpp_register_deferred_pragma (cpp_reader *pfile, const char *space, - const char *name, unsigned int ident, - bool allow_expansion, bool allow_name_expansion) + const char *name, unsigned int ident, + bool allow_expansion, bool allow_name_expansion) { struct pragma_entry *entry; @@ -1218,7 +1220,7 @@ cpp_register_deferred_pragma (cpp_reader *pfile, const char *space, entry->allow_expansion = allow_expansion; entry->u.ident = ident; } -} +} /* Register the pragmas the preprocessor itself handles. */ void @@ -1226,11 +1228,13 @@ _cpp_init_internal_pragmas (cpp_reader *pfile) { /* Pragmas in the global namespace. */ register_pragma_internal (pfile, 0, "once", do_pragma_once); + register_pragma_internal (pfile, 0, "push_macro", do_pragma_push_macro); + register_pragma_internal (pfile, 0, "pop_macro", do_pragma_pop_macro); /* New GCC-specific pragmas should be put in the GCC namespace. */ register_pragma_internal (pfile, "GCC", "poison", do_pragma_poison); register_pragma_internal (pfile, "GCC", "system_header", - do_pragma_system_header); + do_pragma_system_header); register_pragma_internal (pfile, "GCC", "dependency", do_pragma_dependency); } @@ -1243,7 +1247,7 @@ count_registered_pragmas (struct pragma_entry *pe) for (; pe != NULL; pe = pe->next) { if (pe->is_nspace) - ct += count_registered_pragmas (pe->u.space); + ct += count_registered_pragmas (pe->u.space); ct++; } return ct; @@ -1258,7 +1262,7 @@ save_registered_pragmas (struct pragma_entry *pe, char **sd) for (; pe != NULL; pe = pe->next) { if (pe->is_nspace) - sd = save_registered_pragmas (pe->u.space, sd); + sd = save_registered_pragmas (pe->u.space, sd); *sd++ = (char *) xmemdup (HT_STR (&pe->pragma->ident), HT_LEN (&pe->pragma->ident), HT_LEN (&pe->pragma->ident) + 1); @@ -1283,12 +1287,12 @@ _cpp_save_pragma_names (cpp_reader *pfile) static char ** restore_registered_pragmas (cpp_reader *pfile, struct pragma_entry *pe, - char **sd) + char **sd) { for (; pe != NULL; pe = pe->next) { if (pe->is_nspace) - sd = restore_registered_pragmas (pfile, pe->u.space, sd); + sd = restore_registered_pragmas (pfile, pe->u.space, sd); pe->pragma = cpp_lookup (pfile, UC *sd, strlen (*sd)); free (*sd); sd++; @@ -1328,66 +1332,66 @@ do_pragma (cpp_reader *pfile) { p = lookup_pragma_entry (pfile->pragmas, token->val.node); if (p && p->is_nspace) - { - bool allow_name_expansion = p->allow_expansion; - if (allow_name_expansion) - pfile->state.prevent_expansion--; - token = cpp_get_token (pfile); - if (token->type == CPP_NAME) - p = lookup_pragma_entry (p->u.space, token->val.node); - else - p = NULL; - if (allow_name_expansion) - pfile->state.prevent_expansion++; - count = 2; - } + { + bool allow_name_expansion = p->allow_expansion; + if (allow_name_expansion) + pfile->state.prevent_expansion--; + token = cpp_get_token (pfile); + if (token->type == CPP_NAME) + p = lookup_pragma_entry (p->u.space, token->val.node); + else + p = NULL; + if (allow_name_expansion) + pfile->state.prevent_expansion++; + count = 2; + } } if (p) { if (p->is_deferred) - { - pfile->directive_result.src_loc = pragma_token->src_loc; - pfile->directive_result.type = CPP_PRAGMA; - pfile->directive_result.flags = pragma_token->flags; - pfile->directive_result.val.pragma = p->u.ident; - pfile->state.in_deferred_pragma = true; - pfile->state.pragma_allow_expansion = p->allow_expansion; - if (!p->allow_expansion) - pfile->state.prevent_expansion++; - } + { + pfile->directive_result.src_loc = pragma_token->src_loc; + pfile->directive_result.type = CPP_PRAGMA; + pfile->directive_result.flags = pragma_token->flags; + pfile->directive_result.val.pragma = p->u.ident; + pfile->state.in_deferred_pragma = true; + pfile->state.pragma_allow_expansion = p->allow_expansion; + if (!p->allow_expansion) + pfile->state.prevent_expansion++; + } else - { - /* Since the handler below doesn't get the line number, that - it might need for diagnostics, make sure it has the right - numbers in place. */ - if (pfile->cb.line_change) - (*pfile->cb.line_change) (pfile, pragma_token, false); - if (p->allow_expansion) - pfile->state.prevent_expansion--; - (*p->u.handler) (pfile); - if (p->allow_expansion) - pfile->state.prevent_expansion++; - } + { + /* Since the handler below doesn't get the line number, that + it might need for diagnostics, make sure it has the right + numbers in place. */ + if (pfile->cb.line_change) + (*pfile->cb.line_change) (pfile, pragma_token, false); + if (p->allow_expansion) + pfile->state.prevent_expansion--; + (*p->u.handler) (pfile); + if (p->allow_expansion) + pfile->state.prevent_expansion++; + } } else if (pfile->cb.def_pragma) { if (count == 1 || pfile->context->prev == NULL) - _cpp_backup_tokens (pfile, count); + _cpp_backup_tokens (pfile, count); else - { - /* Invalid name comes from macro expansion, _cpp_backup_tokens - won't allow backing 2 tokens. */ - /* ??? The token buffer is leaked. Perhaps if def_pragma hook - reads both tokens, we could perhaps free it, but if it doesn't, - we don't know the exact lifespan. */ - cpp_token *toks = XNEWVEC (cpp_token, 2); - toks[0] = ns_token; - toks[0].flags |= NO_EXPAND; - toks[1] = *token; - toks[1].flags |= NO_EXPAND; - _cpp_push_token_context (pfile, NULL, toks, 2); - } + { + /* Invalid name comes from macro expansion, _cpp_backup_tokens + won't allow backing 2 tokens. */ + /* ??? The token buffer is leaked. Perhaps if def_pragma hook + reads both tokens, we could perhaps free it, but if it doesn't, + we don't know the exact lifespan. */ + cpp_token *toks = XNEWVEC (cpp_token, 2); + toks[0] = ns_token; + toks[0].flags |= NO_EXPAND; + toks[1] = *token; + toks[1].flags |= NO_EXPAND; + _cpp_push_token_context (pfile, NULL, toks, 2); + } pfile->cb.def_pragma (pfile, pfile->directive_line); } @@ -1405,6 +1409,96 @@ do_pragma_once (cpp_reader *pfile) _cpp_mark_file_once_only (pfile, pfile->buffer->file); } +/* Handle #pragma push_macro(STRING). */ +static void +do_pragma_push_macro (cpp_reader *pfile) +{ + char *macroname, *dest; + const char *limit, *src; + const cpp_token *txt; + struct def_pragma_macro *c; + + txt = get__Pragma_string (pfile); + if (!txt) + { + source_location src_loc = pfile->cur_token[-1].src_loc; + cpp_error_with_line (pfile, CPP_DL_ERROR, src_loc, 0, + "invalid #pragma push_macro directive"); + check_eol (pfile); + skip_rest_of_line (pfile); + return; + } + dest = macroname = (char *) alloca (txt->val.str.len + 2); + src = (const char *) (txt->val.str.text + 1 + (txt->val.str.text[0] == 'L')); + limit = (const char *) (txt->val.str.text + txt->val.str.len - 1); + while (src < limit) + { + /* We know there is a character following the backslash. */ + if (*src == '\\' && (src[1] == '\\' || src[1] == '"')) + src++; + *dest++ = *src++; + } + *dest = 0; + check_eol (pfile); + skip_rest_of_line (pfile); + c = XNEW (struct def_pragma_macro); + c->name = XNEWVAR (char, strlen (macroname) + 1); + strcpy (c->name, macroname); + c->next = pfile->pushed_macros; + c->value = cpp_push_definition (pfile, c->name); + pfile->pushed_macros = c; +} + +/* Handle #pragma pop_macro(STRING). */ +static void +do_pragma_pop_macro (cpp_reader *pfile) +{ + char *macroname, *dest; + const char *limit, *src; + const cpp_token *txt; + struct def_pragma_macro *l = NULL, *c = pfile->pushed_macros; + txt = get__Pragma_string (pfile); + if (!txt) + { + source_location src_loc = pfile->cur_token[-1].src_loc; + cpp_error_with_line (pfile, CPP_DL_ERROR, src_loc, 0, + "invalid #pragma pop_macro directive"); + check_eol (pfile); + skip_rest_of_line (pfile); + return; + } + dest = macroname = (char *) alloca (txt->val.str.len + 2); + src = (const char *) (txt->val.str.text + 1 + (txt->val.str.text[0] == 'L')); + limit = (const char *) (txt->val.str.text + txt->val.str.len - 1); + while (src < limit) + { + /* We know there is a character following the backslash. */ + if (*src == '\\' && (src[1] == '\\' || src[1] == '"')) + src++; + *dest++ = *src++; + } + *dest = 0; + check_eol (pfile); + skip_rest_of_line (pfile); + + while (c != NULL) + { + if (!strcmp (c->name, macroname)) + { + if (!l) + pfile->pushed_macros = c->next; + else + l->next = c->next; + cpp_pop_definition (pfile, c->name, c->value); + free (c->name); + free (c); + break; + } + l = c; + c = c->next; + } +} + /* Handle #pragma GCC poison, to poison one or more identifiers so that the lexer produces a hard error for each subsequent usage. */ static void @@ -1418,21 +1512,21 @@ do_pragma_poison (cpp_reader *pfile) { tok = _cpp_lex_token (pfile); if (tok->type == CPP_EOF) - break; + break; if (tok->type != CPP_NAME) - { - cpp_error (pfile, CPP_DL_ERROR, - "invalid #pragma GCC poison directive"); - break; - } + { + cpp_error (pfile, CPP_DL_ERROR, + "invalid #pragma GCC poison directive"); + break; + } hp = tok->val.node; if (hp->flags & NODE_POISONED) - continue; + continue; if (hp->type == NT_MACRO) - cpp_error (pfile, CPP_DL_WARNING, "poisoning existing macro \"%s\"", - NODE_NAME (hp)); + cpp_error (pfile, CPP_DL_WARNING, "poisoning existing macro \"%s\"", + NODE_NAME (hp)); _cpp_free_definition (hp); hp->flags |= NODE_POISONED | NODE_DIAGNOSTIC; } @@ -1450,7 +1544,7 @@ do_pragma_system_header (cpp_reader *pfile) { if (cpp_in_primary_file (pfile)) cpp_error (pfile, CPP_DL_WARNING, - "#pragma system_header ignored outside include file"); + "#pragma system_header ignored outside include file"); else { check_eol (pfile); @@ -1478,12 +1572,12 @@ do_pragma_dependency (cpp_reader *pfile) else if (ordering > 0) { cpp_error (pfile, CPP_DL_WARNING, - "current file is older than %s", fname); + "current file is older than %s", fname); if (cpp_get_token (pfile)->type != CPP_EOF) - { - _cpp_backup_tokens (pfile, 1); - do_diagnostic (pfile, CPP_DL_WARNING, 0); - } + { + _cpp_backup_tokens (pfile, 1); + do_diagnostic (pfile, CPP_DL_WARNING, 0); + } } free ((void *) fname); @@ -1497,7 +1591,7 @@ get_token_no_padding (cpp_reader *pfile) { const cpp_token *result = cpp_get_token (pfile); if (result->type != CPP_PADDING) - return result; + return result; } } @@ -1552,7 +1646,7 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in) { /* We know there is a character following the backslash. */ if (*src == '\\' && (src[1] == '\\' || src[1] == '"')) - src++; + src++; *dest++ = *src++; } *dest = '\n'; @@ -1577,7 +1671,7 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in) /* Inline run_directive, since we need to delay the _cpp_pop_buffer until we've read all of the tokens that we want. */ cpp_push_buffer (pfile, (const uchar *) result, dest - result, - /* from_stage3 */ true); + /* from_stage3 */ true); /* ??? Antique Disgusting Hack. What does this do? */ if (pfile->buffer->prev) pfile->buffer->file = pfile->buffer->prev->file; @@ -1591,7 +1685,7 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in) pfile->directive = save_directive; /* We always insert at least one token, the directive result. It'll - either be a CPP_PADDING or a CPP_PRAGMA. In the later case, we + either be a CPP_PADDING or a CPP_PRAGMA. In the later case, we need to insert *all* of the tokens, including the CPP_PRAGMA_EOL. */ /* If we're not handling the pragma internally, read all of the tokens from @@ -1610,17 +1704,17 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in) toks[0] = pfile->directive_result; do - { - if (count == maxcount) - { - maxcount = maxcount * 3 / 2; - toks = XRESIZEVEC (cpp_token, toks, maxcount); - } - toks[count] = *cpp_get_token (pfile); - /* Macros have been already expanded by cpp_get_token - if the pragma allowed expansion. */ - toks[count++].flags |= NO_EXPAND; - } + { + if (count == maxcount) + { + maxcount = maxcount * 3 / 2; + toks = XRESIZEVEC (cpp_token, toks, maxcount); + } + toks[count] = *cpp_get_token (pfile); + /* Macros have been already expanded by cpp_get_token + if the pragma allowed expansion. */ + toks[count++].flags |= NO_EXPAND; + } while (toks[count-1].type != CPP_PRAGMA_EOL); } else @@ -1630,9 +1724,9 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in) toks[0] = pfile->directive_result; /* If we handled the entire pragma internally, make sure we get the - line number correct for the next token. */ + line number correct for the next token. */ if (pfile->cb.line_change) - pfile->cb.line_change (pfile, pfile->cur_token, false); + pfile->cb.line_change (pfile, pfile->cur_token, false); } /* Finish inlining run_directive. */ @@ -1662,7 +1756,7 @@ _cpp_do__Pragma (cpp_reader *pfile) return 1; } cpp_error (pfile, CPP_DL_ERROR, - "_Pragma takes a parenthesized string literal"); + "_Pragma takes a parenthesized string literal"); return 0; } @@ -1677,25 +1771,25 @@ do_ifdef (cpp_reader *pfile) cpp_hashnode *node = lex_macro_node (pfile, false); if (node) - { - skip = node->type != NT_MACRO; - _cpp_mark_macro_used (node); - if (!(node->flags & NODE_USED)) - { - node->flags |= NODE_USED; - if (node->type == NT_MACRO) - { - if (pfile->cb.used_define) - pfile->cb.used_define (pfile, pfile->directive_line, node); - } - else - { - if (pfile->cb.used_undef) - pfile->cb.used_undef (pfile, pfile->directive_line, node); - } - } - check_eol (pfile); - } + { + skip = node->type != NT_MACRO; + _cpp_mark_macro_used (node); + if (!(node->flags & NODE_USED)) + { + node->flags |= NODE_USED; + if (node->type == NT_MACRO) + { + if (pfile->cb.used_define) + pfile->cb.used_define (pfile, pfile->directive_line, node); + } + else + { + if (pfile->cb.used_undef) + pfile->cb.used_undef (pfile, pfile->directive_line, node); + } + } + check_eol (pfile); + } } push_conditional (pfile, skip, T_IFDEF, 0); @@ -1713,25 +1807,25 @@ do_ifndef (cpp_reader *pfile) node = lex_macro_node (pfile, false); if (node) - { - skip = node->type == NT_MACRO; - _cpp_mark_macro_used (node); - if (!(node->flags & NODE_USED)) - { - node->flags |= NODE_USED; - if (node->type == NT_MACRO) - { - if (pfile->cb.used_define) - pfile->cb.used_define (pfile, pfile->directive_line, node); - } - else - { - if (pfile->cb.used_undef) - pfile->cb.used_undef (pfile, pfile->directive_line, node); - } - } - check_eol (pfile); - } + { + skip = node->type == NT_MACRO; + _cpp_mark_macro_used (node); + if (!(node->flags & NODE_USED)) + { + node->flags |= NODE_USED; + if (node->type == NT_MACRO) + { + if (pfile->cb.used_define) + pfile->cb.used_define (pfile, pfile->directive_line, node); + } + else + { + if (pfile->cb.used_undef) + pfile->cb.used_undef (pfile, pfile->directive_line, node); + } + } + check_eol (pfile); + } } push_conditional (pfile, skip, T_IFNDEF, node); @@ -1767,11 +1861,11 @@ do_else (cpp_reader *pfile) else { if (ifs->type == T_ELSE) - { - cpp_error (pfile, CPP_DL_ERROR, "#else after #else"); - cpp_error_with_line (pfile, CPP_DL_ERROR, ifs->line, 0, - "the conditional began here"); - } + { + cpp_error (pfile, CPP_DL_ERROR, "#else after #else"); + cpp_error_with_line (pfile, CPP_DL_ERROR, ifs->line, 0, + "the conditional began here"); + } ifs->type = T_ELSE; /* Skip any future (erroneous) #elses or #elifs. */ @@ -1783,7 +1877,7 @@ do_else (cpp_reader *pfile) /* Only check EOL if was not originally skipping. */ if (!ifs->was_skipping && CPP_OPTION (pfile, warn_endif_labels)) - check_eol (pfile); + check_eol (pfile); } } @@ -1800,31 +1894,31 @@ do_elif (cpp_reader *pfile) else { if (ifs->type == T_ELSE) - { - cpp_error (pfile, CPP_DL_ERROR, "#elif after #else"); - cpp_error_with_line (pfile, CPP_DL_ERROR, ifs->line, 0, - "the conditional began here"); - } + { + cpp_error (pfile, CPP_DL_ERROR, "#elif after #else"); + cpp_error_with_line (pfile, CPP_DL_ERROR, ifs->line, 0, + "the conditional began here"); + } ifs->type = T_ELIF; if (! ifs->was_skipping) - { - bool value; - /* The standard mandates that the expression be parsed even - if we are skipping elses at this point -- the lexical - restrictions on #elif only apply to skipped groups, but - this group is not being skipped. Temporarily set - skipping to false to get lexer warnings. */ - pfile->state.skipping = 0; - value = _cpp_parse_expr (pfile, false); - if (ifs->skip_elses) - pfile->state.skipping = 1; - else - { - pfile->state.skipping = ! value; - ifs->skip_elses = value; - } - } + { + bool value; + /* The standard mandates that the expression be parsed even + if we are skipping elses at this point -- the lexical + restrictions on #elif only apply to skipped groups, but + this group is not being skipped. Temporarily set + skipping to false to get lexer warnings. */ + pfile->state.skipping = 0; + value = _cpp_parse_expr (pfile, false); + if (ifs->skip_elses) + pfile->state.skipping = 1; + else + { + pfile->state.skipping = ! value; + ifs->skip_elses = value; + } + } /* Invalidate any controlling macro. */ ifs->mi_cmacro = 0; @@ -1844,14 +1938,14 @@ do_endif (cpp_reader *pfile) { /* Only check EOL if was not originally skipping. */ if (!ifs->was_skipping && CPP_OPTION (pfile, warn_endif_labels)) - check_eol (pfile); + check_eol (pfile); /* If potential control macro, we go back outside again. */ if (ifs->next == 0 && ifs->mi_cmacro) - { - pfile->mi_valid = true; - pfile->mi_cmacro = ifs->mi_cmacro; - } + { + pfile->mi_valid = true; + pfile->mi_cmacro = ifs->mi_cmacro; + } buffer->if_stack = ifs->next; pfile->state.skipping = ifs->was_skipping; @@ -1865,7 +1959,7 @@ do_endif (cpp_reader *pfile) we need to check here that we are at the top of the file. */ static void push_conditional (cpp_reader *pfile, int skip, int type, - const cpp_hashnode *cmacro) + const cpp_hashnode *cmacro) { struct if_stack *ifs; cpp_buffer *buffer = pfile->buffer; @@ -1907,14 +2001,14 @@ parse_answer (cpp_reader *pfile, struct answer **answerp, int type) /* In a conditional no answer is a test for any answer. It could be followed by any token. */ if (type == T_IF) - { - _cpp_backup_tokens (pfile, 1); - return 0; - } + { + _cpp_backup_tokens (pfile, 1); + return 0; + } /* #unassert with no answer is valid - it removes all answers. */ if (type == T_UNASSERT && paren->type == CPP_EOF) - return 0; + return 0; cpp_error (pfile, CPP_DL_ERROR, "missing '(' after predicate"); return 1; @@ -1927,26 +2021,26 @@ parse_answer (cpp_reader *pfile, struct answer **answerp, int type) cpp_token *dest; if (token->type == CPP_CLOSE_PAREN) - break; + break; if (token->type == CPP_EOF) - { - cpp_error (pfile, CPP_DL_ERROR, "missing ')' to complete answer"); - return 1; - } + { + cpp_error (pfile, CPP_DL_ERROR, "missing ')' to complete answer"); + return 1; + } /* struct answer includes the space for one token. */ room_needed = (sizeof (struct answer) + acount * sizeof (cpp_token)); if (BUFF_ROOM (pfile->a_buff) < room_needed) - _cpp_extend_buff (pfile, &pfile->a_buff, sizeof (struct answer)); + _cpp_extend_buff (pfile, &pfile->a_buff, sizeof (struct answer)); dest = &((struct answer *) BUFF_FRONT (pfile->a_buff))->first[acount]; *dest = *token; /* Drop whitespace at start, for answer equivalence purposes. */ if (acount == 0) - dest->flags &= ~PREV_WHITE; + dest->flags &= ~PREV_WHITE; } if (acount == 0) @@ -2009,14 +2103,14 @@ find_answer (cpp_hashnode *node, const struct answer *candidate) struct answer *answer = *result; if (answer->count == candidate->count) - { - for (i = 0; i < answer->count; i++) - if (! _cpp_equiv_tokens (&answer->first[i], &candidate->first[i])) - break; + { + for (i = 0; i < answer->count; i++) + if (! _cpp_equiv_tokens (&answer->first[i], &candidate->first[i])) + break; - if (i == answer->count) - break; - } + if (i == answer->count) + break; + } } return result; @@ -2039,7 +2133,7 @@ _cpp_test_assertion (cpp_reader *pfile, unsigned int *value) if (node) *value = (node->type == NT_ASSERTION && - (answer == 0 || *find_answer (node, answer) != 0)); + (answer == 0 || *find_answer (node, answer) != 0)); else if (pfile->cur_token[-1].type == CPP_EOF) _cpp_backup_tokens (pfile, 1); @@ -2063,28 +2157,28 @@ do_assert (cpp_reader *pfile) is not a duplicate. */ new_answer->next = 0; if (node->type == NT_ASSERTION) - { - if (*find_answer (node, new_answer)) - { - cpp_error (pfile, CPP_DL_WARNING, "\"%s\" re-asserted", - NODE_NAME (node) + 1); - return; - } - new_answer->next = node->value.answers; - } + { + if (*find_answer (node, new_answer)) + { + cpp_error (pfile, CPP_DL_WARNING, "\"%s\" re-asserted", + NODE_NAME (node) + 1); + return; + } + new_answer->next = node->value.answers; + } answer_size = sizeof (struct answer) + ((new_answer->count - 1) - * sizeof (cpp_token)); + * sizeof (cpp_token)); /* Commit or allocate storage for the object. */ if (pfile->hash_table->alloc_subobject) - { - struct answer *temp_answer = new_answer; - new_answer = (struct answer *) pfile->hash_table->alloc_subobject + { + struct answer *temp_answer = new_answer; + new_answer = (struct answer *) pfile->hash_table->alloc_subobject (answer_size); - memcpy (new_answer, temp_answer, answer_size); - } + memcpy (new_answer, temp_answer, answer_size); + } else - BUFF_FRONT (pfile->a_buff) += answer_size; + BUFF_FRONT (pfile->a_buff) += answer_size; node->type = NT_ASSERTION; node->value.answers = new_answer; @@ -2104,22 +2198,22 @@ do_unassert (cpp_reader *pfile) if (node && node->type == NT_ASSERTION) { if (answer) - { - struct answer **p = find_answer (node, answer), *temp; + { + struct answer **p = find_answer (node, answer), *temp; - /* Remove the answer from the list. */ - temp = *p; - if (temp) - *p = temp->next; + /* Remove the answer from the list. */ + temp = *p; + if (temp) + *p = temp->next; - /* Did we free the last answer? */ - if (node->value.answers == 0) - node->type = NT_VOID; + /* Did we free the last answer? */ + if (node->value.answers == 0) + node->type = NT_VOID; - check_eol (pfile); - } + check_eol (pfile); + } else - _cpp_free_definition (node); + _cpp_free_definition (node); } /* We don't commit the memory for the answer - it's temporary only. */ @@ -2200,28 +2294,11 @@ cpp_undef (cpp_reader *pfile, const char *macro) run_directive (pfile, T_UNDEF, buf, len); } -/* Like lex_macro_node, but read the input from STR. */ -static cpp_hashnode * -lex_macro_node_from_str (cpp_reader *pfile, const char *str) -{ - size_t len = strlen (str); - uchar *buf = (uchar *) alloca (len + 1); - cpp_hashnode *node; - - memcpy (buf, str, len); - buf[len] = '\n'; - cpp_push_buffer (pfile, buf, len, true); - node = lex_macro_node (pfile, true); - _cpp_pop_buffer (pfile); - - return node; -} - /* If STR is a defined macro, return its definition node, else return NULL. */ cpp_macro * cpp_push_definition (cpp_reader *pfile, const char *str) { - cpp_hashnode *node = lex_macro_node_from_str (pfile, str); + cpp_hashnode *node = _cpp_lex_identifier (pfile, str); if (node && node->type == NT_MACRO) return node->value.macro; else @@ -2233,7 +2310,7 @@ cpp_push_definition (cpp_reader *pfile, const char *str) void cpp_pop_definition (cpp_reader *pfile, const char *str, cpp_macro *dfn) { - cpp_hashnode *node = lex_macro_node_from_str (pfile, str); + cpp_hashnode *node = _cpp_lex_identifier (pfile, str); if (node == NULL) return; @@ -2243,9 +2320,9 @@ cpp_pop_definition (cpp_reader *pfile, const char *str, cpp_macro *dfn) if (node->type == NT_MACRO) { if (pfile->cb.undef) - pfile->cb.undef (pfile, pfile->directive_line, node); + pfile->cb.undef (pfile, pfile->directive_line, node); if (CPP_OPTION (pfile, warn_unused_macros)) - _cpp_warn_if_unused_macro (pfile, node, NULL); + _cpp_warn_if_unused_macro (pfile, node, NULL); } if (node->type != NT_VOID) _cpp_free_definition (node); @@ -2255,10 +2332,10 @@ cpp_pop_definition (cpp_reader *pfile, const char *str, cpp_macro *dfn) node->type = NT_MACRO; node->value.macro = dfn; if (! ustrncmp (NODE_NAME (node), DSC ("__STDC_"))) - node->flags |= NODE_WARN; + node->flags |= NODE_WARN; if (pfile->cb.define) - pfile->cb.define (pfile, pfile->directive_line, node); + pfile->cb.define (pfile, pfile->directive_line, node); } } @@ -2341,7 +2418,7 @@ cpp_get_deps (cpp_reader *pfile) is the responsibility of the caller. */ cpp_buffer * cpp_push_buffer (cpp_reader *pfile, const uchar *buffer, size_t len, - int from_stage3) + int from_stage3) { cpp_buffer *new_buffer = XOBNEW (&pfile->buffer_ob, cpp_buffer); @@ -2372,7 +2449,7 @@ _cpp_pop_buffer (cpp_reader *pfile) entry to this file, issuing error messages. */ for (ifs = buffer->if_stack; ifs; ifs = ifs->next) cpp_error_with_line (pfile, CPP_DL_ERROR, ifs->line, 0, - "unterminated #%s", dtable[ifs->type].name); + "unterminated #%s", dtable[ifs->type].name); /* In case of a missing #endif. */ pfile->state.skipping = 0; |