diff options
author | borutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423> | 2010-01-24 17:03:14 +0000 |
---|---|---|
committer | borutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423> | 2010-01-24 17:03:14 +0000 |
commit | 755453312f2698d4d0e70cd618d3e3902ff368f3 (patch) | |
tree | 45a81343dd74b542e22a105ae0f6368e0bebe11f /support/cpp/libcpp | |
parent | 81ff3a4fee5c75991a790d3a2e7c899627334920 (diff) |
* src/z80/gen.c:
fixed declaration in the middle of the block
* support/cpp/ansidecl.h, support/cpp/libcpp/directives.c,
support/cpp/libcpp/errors.c, support/cpp/libcpp/init.c,
support/cpp/libcpp/internal.h, support/cpp/libcpp/lex.c,
support/cpp/libiberty.h, support/cpp/libiberty/hex.c,
support/cpp/libiberty/md5.c, support/cpp/libiberty/splay-tree.c,
support/cpp/md5.h:
SDCPP synchronized with GCC CPP release version 4.4.3
git-svn-id: https://svn.code.sourceforge.net/p/sdcc/code/trunk/sdcc@5652 4a8a32a2-be11-0410-ad9d-d568d2c75423
Diffstat (limited to 'support/cpp/libcpp')
-rw-r--r-- | support/cpp/libcpp/directives.c | 1027 | ||||
-rw-r--r-- | support/cpp/libcpp/errors.c | 82 | ||||
-rw-r--r-- | support/cpp/libcpp/init.c | 147 | ||||
-rw-r--r-- | support/cpp/libcpp/internal.h | 98 | ||||
-rw-r--r-- | support/cpp/libcpp/lex.c | 57 |
5 files changed, 786 insertions, 625 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; diff --git a/support/cpp/libcpp/errors.c b/support/cpp/libcpp/errors.c index f756ca7c5..7c379dfea 100644 --- a/support/cpp/libcpp/errors.c +++ b/support/cpp/libcpp/errors.c @@ -49,18 +49,18 @@ print_location (cpp_reader *pfile, source_location line, unsigned int col) lin = SOURCE_LINE (map, line); if (col == 0) - { - col = SOURCE_COLUMN (map, line); - if (col == 0) - col = 1; - } + { + col = SOURCE_COLUMN (map, line); + if (col == 0) + col = 1; + } if (lin == 0) - fprintf (stderr, "%s:", map->to_file); + fprintf (stderr, "%s:", map->to_file); else if (CPP_OPTION (pfile, show_column) == 0) - fprintf (stderr, "%s:%u:", map->to_file, lin); + fprintf (stderr, "%s:%u:", map->to_file, lin); else - fprintf (stderr, "%s:%u:%u:", map->to_file, lin, col); + fprintf (stderr, "%s:%u:%u:", map->to_file, lin, col); fputc (' ', stderr); } @@ -78,7 +78,7 @@ print_location (cpp_reader *pfile, source_location line, unsigned int col) Returns 0 if the error has been suppressed. */ static int _cpp_begin_message (cpp_reader *pfile, int code, - source_location src_loc, unsigned int column) + source_location src_loc, unsigned int column) { int level = CPP_DL_EXTRACT (code); @@ -87,26 +87,26 @@ _cpp_begin_message (cpp_reader *pfile, int code, case CPP_DL_WARNING: case CPP_DL_PEDWARN: if (cpp_in_system_header (pfile) - && ! CPP_OPTION (pfile, warn_system_headers)) - return 0; + && ! CPP_OPTION (pfile, warn_system_headers)) + return 0; /* Fall through. */ case CPP_DL_WARNING_SYSHDR: if (CPP_OPTION (pfile, warnings_are_errors) - || (level == CPP_DL_PEDWARN && CPP_OPTION (pfile, pedantic_errors))) - { - if (CPP_OPTION (pfile, inhibit_errors)) - return 0; - level = CPP_DL_ERROR; - pfile->errors++; - } + || (level == CPP_DL_PEDWARN && CPP_OPTION (pfile, pedantic_errors))) + { + if (CPP_OPTION (pfile, inhibit_errors)) + return 0; + level = CPP_DL_ERROR; + pfile->errors++; + } else if (CPP_OPTION (pfile, inhibit_warnings)) - return 0; + return 0; break; case CPP_DL_ERROR: if (CPP_OPTION (pfile, inhibit_errors)) - return 0; + return 0; /* ICEs cannot be inhibited. */ case CPP_DL_ICE: pfile->errors++; @@ -137,7 +137,7 @@ cpp_error (cpp_reader * pfile, int level, const char *msgid, ...) { source_location src_loc; va_list ap; - + va_start (ap, msgid); if (CPP_OPTION (pfile, client_diagnostic)) @@ -145,28 +145,28 @@ cpp_error (cpp_reader * pfile, int level, const char *msgid, ...) else { if (CPP_OPTION (pfile, traditional)) - { - if (pfile->state.in_directive) - src_loc = pfile->directive_line; - else - src_loc = pfile->line_table->highest_line; - } + { + if (pfile->state.in_directive) + src_loc = pfile->directive_line; + else + src_loc = pfile->line_table->highest_line; + } /* We don't want to refer to a token before the beginning of the - current run -- that is invalid. */ + current run -- that is invalid. */ else if (pfile->cur_token == pfile->cur_run->base) - { - if (pfile->cur_run->prev != NULL) - src_loc = pfile->cur_run->prev->limit->src_loc; - else - src_loc = 0; - } + { + if (pfile->cur_run->prev != NULL) + src_loc = pfile->cur_run->prev->limit->src_loc; + else + src_loc = 0; + } else - { - src_loc = pfile->cur_token[-1].src_loc; - } + { + src_loc = pfile->cur_token[-1].src_loc; + } if (_cpp_begin_message (pfile, level, src_loc, 0)) - v_message (msgid, ap); + v_message (msgid, ap); } va_end (ap); @@ -175,11 +175,11 @@ cpp_error (cpp_reader * pfile, int level, const char *msgid, ...) /* Print an error at a specific location. */ void cpp_error_with_line (cpp_reader *pfile, int level, - source_location src_loc, unsigned int column, - const char *msgid, ...) + source_location src_loc, unsigned int column, + const char *msgid, ...) { va_list ap; - + va_start (ap, msgid); if (_cpp_begin_message (pfile, level, src_loc, column)) diff --git a/support/cpp/libcpp/init.c b/support/cpp/libcpp/init.c index 762a735c8..305e2a625 100644 --- a/support/cpp/libcpp/init.c +++ b/support/cpp/libcpp/init.c @@ -59,9 +59,9 @@ __extension__ const uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { #endif TRIGRAPH_MAP - s('=', '#') s(')', ']') s('!', '|') - s('(', '[') s('\'', '^') s('>', '}') - s('/', '\\') s('<', '{') s('-', '~') + s('=', '#') s(')', ']') s('!', '|') + s('(', '[') s('\'', '^') s('>', '}') + s('/', '\\') s('<', '{') s('-', '~') END #undef s @@ -108,15 +108,15 @@ cpp_set_lang (cpp_reader *pfile, enum c_lang lang) CPP_OPTION (pfile, lang) = lang; - CPP_OPTION (pfile, c99) = l->c99; - CPP_OPTION (pfile, cplusplus) = l->cplusplus; - CPP_OPTION (pfile, extended_numbers) = l->extended_numbers; - CPP_OPTION (pfile, extended_identifiers) = l->extended_identifiers; - CPP_OPTION (pfile, std) = l->std; - CPP_OPTION (pfile, trigraphs) = l->std; - CPP_OPTION (pfile, cplusplus_comments) = l->cplusplus_comments; - CPP_OPTION (pfile, digraphs) = l->digraphs; - CPP_OPTION (pfile, uliterals) = l->uliterals; + CPP_OPTION (pfile, c99) = l->c99; + CPP_OPTION (pfile, cplusplus) = l->cplusplus; + CPP_OPTION (pfile, extended_numbers) = l->extended_numbers; + CPP_OPTION (pfile, extended_identifiers) = l->extended_identifiers; + CPP_OPTION (pfile, std) = l->std; + CPP_OPTION (pfile, trigraphs) = l->std; + CPP_OPTION (pfile, cplusplus_comments) = l->cplusplus_comments; + CPP_OPTION (pfile, digraphs) = l->digraphs; + CPP_OPTION (pfile, uliterals) = l->uliterals; } /* Initialize library global state. */ @@ -130,8 +130,8 @@ init_library (void) initialized = 1; /* Set up the trigraph map. This doesn't need to do anything if - we were compiled with a compiler that supports C99 designated - initializers. */ + we were compiled with a compiler that supports C99 designated + initializers. */ init_trigraph_map (); #ifdef ENABLE_NLS @@ -143,7 +143,7 @@ init_library (void) /* Initialize a cpp_reader structure. */ cpp_reader * cpp_create_reader (enum c_lang lang, hash_table *table, - struct line_maps *line_table) + struct line_maps *line_table) { cpp_reader *pfile; @@ -218,13 +218,16 @@ cpp_create_reader (enum c_lang lang, hash_table *table, pfile->a_buff = _cpp_get_buff (pfile, 0); pfile->u_buff = _cpp_get_buff (pfile, 0); + /* Initialize table for push_macro/pop_macro. */ + pfile->pushed_macros = 0; + /* The expression parser stack. */ _cpp_expand_op_stack (pfile); /* Initialize the buffer obstack. */ _obstack_begin (&pfile->buffer_ob, 0, 0, - (void *(*) (long)) xmalloc, - (void (*) (void *)) free); + (void *(*) (long)) xmalloc, + (void (*) (void *)) free); _cpp_init_files (pfile); @@ -247,6 +250,7 @@ void cpp_destroy (cpp_reader *pfile) { cpp_context *context, *contextn; + struct def_pragma_macro *pmacro; tokenrun *run, *runn; int i; @@ -282,7 +286,7 @@ cpp_destroy (cpp_reader *pfile) runn = run->next; free (run->base); if (run != &pfile->base_run) - free (run); + free (run); } for (context = pfile->base_context.next; context; context = contextn) @@ -294,10 +298,21 @@ cpp_destroy (cpp_reader *pfile) if (pfile->comments.entries) { for (i = 0; i < pfile->comments.count; i++) - free (pfile->comments.entries[i].comment); + free (pfile->comments.entries[i].comment); free (pfile->comments.entries); } + if (pfile->pushed_macros) + { + do + { + pmacro = pfile->pushed_macros; + pfile->pushed_macros = pmacro->next; + free (pmacro->name); + free (pmacro); + } + while (pfile->pushed_macros); + } free (pfile); } @@ -327,18 +342,18 @@ struct builtin_macro #define B(n, t, f) { DSC(n), t, f } static const struct builtin_macro builtin_array[] = { - B("__TIMESTAMP__", BT_TIMESTAMP, false), - B("__TIME__", BT_TIME, false), - B("__DATE__", BT_DATE, false), - B("__FILE__", BT_FILE, false), - B("__BASE_FILE__", BT_BASE_FILE, false), - B("__LINE__", BT_SPECLINE, true), + B("__TIMESTAMP__", BT_TIMESTAMP, false), + B("__TIME__", BT_TIME, false), + B("__DATE__", BT_DATE, false), + B("__FILE__", BT_FILE, false), + B("__BASE_FILE__", BT_BASE_FILE, false), + B("__LINE__", BT_SPECLINE, true), B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL, true), - B("__COUNTER__", BT_COUNTER, true), + B("__COUNTER__", BT_COUNTER, true), /* Keep builtins not used for -traditional-cpp at the end, and update init_builtins() if any more are added. */ - B("_Pragma", BT_PRAGMA, true), - B("__STDC__", BT_STDC, true), + B("_Pragma", BT_PRAGMA, true), + B("__STDC__", BT_STDC, true), }; #undef B @@ -352,17 +367,17 @@ struct builtin_operator #define B(n, t) { DSC(n), t } static const struct builtin_operator operator_array[] = { - B("and", CPP_AND_AND), - B("and_eq", CPP_AND_EQ), - B("bitand", CPP_AND), - B("bitor", CPP_OR), - B("compl", CPP_COMPL), - B("not", CPP_NOT), - B("not_eq", CPP_NOT_EQ), - B("or", CPP_OR_OR), - B("or_eq", CPP_OR_EQ), - B("xor", CPP_XOR), - B("xor_eq", CPP_XOR_EQ) + B("and", CPP_AND_AND), + B("and_eq", CPP_AND_EQ), + B("bitand", CPP_AND), + B("bitor", CPP_OR), + B("compl", CPP_COMPL), + B("not", CPP_NOT), + B("not_eq", CPP_NOT_EQ), + B("or", CPP_OR_OR), + B("or_eq", CPP_OR_EQ), + B("xor", CPP_XOR), + B("xor_eq", CPP_XOR_EQ) }; #undef B @@ -392,7 +407,7 @@ cpp_init_special_builtins (cpp_reader *pfile) if (CPP_OPTION (pfile, traditional)) n -= 2; else if (! CPP_OPTION (pfile, stdc_0_in_system_headers) - || CPP_OPTION (pfile, std)) + || CPP_OPTION (pfile, std)) n--; for (b = builtin_array; b < builtin_array + n; b++) @@ -402,7 +417,7 @@ cpp_init_special_builtins (cpp_reader *pfile) hp->flags |= NODE_BUILTIN; if (b->always_warn_if_redefined || CPP_OPTION (pfile, warn_builtin_macro_redefined)) - hp->flags |= NODE_WARN; + hp->flags |= NODE_WARN; hp->value.builtin = (enum builtin_type) b->value; } } @@ -417,7 +432,7 @@ cpp_init_builtins (cpp_reader *pfile, int hosted) if (!CPP_OPTION (pfile, traditional) && (! CPP_OPTION (pfile, stdc_0_in_system_headers) - || CPP_OPTION (pfile, std))) + || CPP_OPTION (pfile, std))) _cpp_define_builtin (pfile, "__STDC__ 1"); if (CPP_OPTION (pfile, cplusplus)) @@ -455,37 +470,37 @@ static void sanity_checks (cpp_reader *pfile) if (CPP_OPTION (pfile, precision) > max_precision) cpp_error (pfile, CPP_DL_ICE, - "preprocessor arithmetic has maximum precision of %lu bits;" - " target requires %lu bits", - (unsigned long) max_precision, - (unsigned long) CPP_OPTION (pfile, precision)); + "preprocessor arithmetic has maximum precision of %lu bits;" + " target requires %lu bits", + (unsigned long) max_precision, + (unsigned long) CPP_OPTION (pfile, precision)); if (CPP_OPTION (pfile, precision) < CPP_OPTION (pfile, int_precision)) cpp_error (pfile, CPP_DL_ICE, - "CPP arithmetic must be at least as precise as a target int"); + "CPP arithmetic must be at least as precise as a target int"); if (CPP_OPTION (pfile, char_precision) < 8) cpp_error (pfile, CPP_DL_ICE, "target char is less than 8 bits wide"); if (CPP_OPTION (pfile, wchar_precision) < CPP_OPTION (pfile, char_precision)) cpp_error (pfile, CPP_DL_ICE, - "target wchar_t is narrower than target char"); + "target wchar_t is narrower than target char"); if (CPP_OPTION (pfile, int_precision) < CPP_OPTION (pfile, char_precision)) cpp_error (pfile, CPP_DL_ICE, - "target int is narrower than target char"); + "target int is narrower than target char"); /* This is assumed in eval_token() and could be fixed if necessary. */ if (sizeof (cppchar_t) > sizeof (cpp_num_part)) cpp_error (pfile, CPP_DL_ICE, - "CPP half-integer narrower than CPP character"); + "CPP half-integer narrower than CPP character"); if (CPP_OPTION (pfile, wchar_precision) > BITS_PER_CPPCHAR_T) cpp_error (pfile, CPP_DL_ICE, - "CPP on this host cannot handle wide character constants over" - " %lu bits, but the target requires %lu bits", - (unsigned long) BITS_PER_CPPCHAR_T, - (unsigned long) CPP_OPTION (pfile, wchar_precision)); + "CPP on this host cannot handle wide character constants over" + " %lu bits, but the target requires %lu bits", + (unsigned long) BITS_PER_CPPCHAR_T, + (unsigned long) CPP_OPTION (pfile, wchar_precision)); } #else # define sanity_checks(PFILE) @@ -514,7 +529,7 @@ cpp_read_main_file (cpp_reader *pfile, const char *fname) if (CPP_OPTION (pfile, deps.style) != DEPS_NONE) { if (!pfile->deps) - pfile->deps = deps_init (); + pfile->deps = deps_init (); /* Set the default target (if there is none already). */ deps_add_default_target (pfile, fname); @@ -558,11 +573,11 @@ read_original_filename (cpp_reader *pfile) /* If it's a #line directive, handle it. */ if (token1->type == CPP_NUMBER) - { - _cpp_handle_directive (pfile, token->flags & PREV_WHITE); - read_original_directory (pfile); - return; - } + { + _cpp_handle_directive (pfile, token->flags & PREV_WHITE); + read_original_directory (pfile); + return; + } } /* Backup as if nothing happened. */ @@ -598,8 +613,8 @@ read_original_directory (cpp_reader *pfile) if (token->type != CPP_STRING || ! (token->val.str.len >= 5 - && token->val.str.text[token->val.str.len-2] == '/' - && token->val.str.text[token->val.str.len-3] == '/')) + && token->val.str.text[token->val.str.len-2] == '/' + && token->val.str.text[token->val.str.len-3] == '/')) { _cpp_backup_tokens (pfile, 3); return; @@ -610,11 +625,11 @@ read_original_directory (cpp_reader *pfile) char *debugdir = (char *) alloca (token->val.str.len - 3); memcpy (debugdir, (const char *) token->val.str.text + 1, - token->val.str.len - 4); + token->val.str.len - 4); debugdir[token->val.str.len - 4] = '\0'; pfile->cb.dir_change (pfile, debugdir); - } + } } /* This is called at the end of preprocessing. It pops the last @@ -645,7 +660,7 @@ cpp_finish (cpp_reader *pfile, FILE *deps_stream) deps_write (pfile->deps, deps_stream, 72); if (CPP_OPTION (pfile, deps.phony_targets)) - deps_phony_targets (pfile->deps, deps_stream); + deps_phony_targets (pfile->deps, deps_stream); } /* Report on headers that could use multiple include guards. */ @@ -667,7 +682,7 @@ post_options (cpp_reader *pfile) if (CPP_OPTION (pfile, preprocessed)) { if (!CPP_OPTION (pfile, directives_only)) - pfile->state.prevent_expansion = 1; + pfile->state.prevent_expansion = 1; CPP_OPTION (pfile, traditional) = 0; } diff --git a/support/cpp/libcpp/internal.h b/support/cpp/libcpp/internal.h index 0095d9c4a..c280e9729 100644 --- a/support/cpp/libcpp/internal.h +++ b/support/cpp/libcpp/internal.h @@ -37,13 +37,13 @@ along with this program; see the file COPYING3. If not see typedef int iconv_t; /* dummy */ #endif -struct directive; /* Deliberately incomplete. */ +struct directive; /* Deliberately incomplete. */ struct pending_option; struct op; struct _cpp_strbuf; typedef bool (*convert_f) (iconv_t, const unsigned char *, size_t, - struct _cpp_strbuf *); + struct _cpp_strbuf *); struct cset_converter { convert_f func; @@ -91,8 +91,8 @@ struct dummy #define CPP_ALIGN2(size, align) (((size) + ((align) - 1)) & ~((align) - 1)) #define CPP_ALIGN(size) CPP_ALIGN2 (size, DEFAULT_ALIGNMENT) -#define _cpp_mark_macro_used(NODE) do { \ - if ((NODE)->type == NT_MACRO && !((NODE)->flags & NODE_BUILTIN)) \ +#define _cpp_mark_macro_used(NODE) do { \ + if ((NODE)->type == NT_MACRO && !((NODE)->flags & NODE_BUILTIN)) \ (NODE)->value.macro->used = 1; } while (0) /* A generic memory buffer, and operations on it. */ @@ -226,10 +226,10 @@ struct lexer_state /* Special nodes - identifiers with predefined significance. */ struct spec_nodes { - cpp_hashnode *n_defined; /* defined operator */ - cpp_hashnode *n_true; /* C++ keyword true */ - cpp_hashnode *n_false; /* C++ keyword false */ - cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */ + cpp_hashnode *n_defined; /* defined operator */ + cpp_hashnode *n_true; /* C++ keyword true */ + cpp_hashnode *n_false; /* C++ keyword false */ + cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */ /* SDCC _asm specific */ cpp_hashnode *n__asm1; /* _asm ... _endasm ; */ cpp_hashnode *n__asm; /* __asm ... __endasm ; */ @@ -308,6 +308,16 @@ struct cpp_buffer struct cset_converter input_cset_desc; }; +/* The list of saved macros by push_macro pragma. */ +struct def_pragma_macro { + /* Chain element to previous saved macro. */ + struct def_pragma_macro *next; + /* Name of the macro. */ + char *name; + /* The stored macro content. */ + cpp_macro *value; +}; + /* A cpp_reader encapsulates the "state" of a pre-processor run. Applying cpp_get_token repeatedly yields a stream of pre-processor tokens. Usually, there is only one cpp_reader object active. */ @@ -329,9 +339,9 @@ struct cpp_reader source_location directive_line; /* Memory buffers. */ - _cpp_buff *a_buff; /* Aligned permanent storage. */ - _cpp_buff *u_buff; /* Unaligned permanent storage. */ - _cpp_buff *free_buffs; /* Free buffer chain. */ + _cpp_buff *a_buff; /* Aligned permanent storage. */ + _cpp_buff *u_buff; /* Unaligned permanent storage. */ + _cpp_buff *free_buffs; /* Free buffer chain. */ /* Context stack. */ struct cpp_context base_context; @@ -352,9 +362,9 @@ struct cpp_reader bool set_invocation_location; /* Search paths for include files. */ - struct cpp_dir *quote_include; /* "" */ - struct cpp_dir *bracket_include; /* <> */ - struct cpp_dir no_search_path; /* No path. */ + struct cpp_dir *quote_include; /* "" */ + struct cpp_dir *bracket_include; /* <> */ + struct cpp_dir no_search_path; /* No path. */ /* Chain of all hashed _cpp_file instances. */ struct _cpp_file *all_files; @@ -477,6 +487,9 @@ struct cpp_reader /* Table of comments, when state.save_comments is true. */ cpp_comment_table comments; + + /* List of saved macros by push_macro. */ + struct def_pragma_macro *pushed_macros; }; /* Character classes. Based on the more primitive macros in safe-ctype.h. @@ -486,16 +499,16 @@ struct cpp_reader In the unlikely event that characters other than \r and \n enter the set is_vspace, the macro handle_newline() in lex.c must be updated. */ -#define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident)) +#define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident)) -#define is_idchar(x) (ISIDNUM(x) || _dollar_ok(x)) -#define is_numchar(x) ISIDNUM(x) -#define is_idstart(x) (ISIDST(x) || _dollar_ok(x)) -#define is_numstart(x) ISDIGIT(x) -#define is_hspace(x) ISBLANK(x) -#define is_vspace(x) IS_VSPACE(x) -#define is_nvspace(x) IS_NVSPACE(x) -#define is_space(x) IS_SPACE_OR_NUL(x) +#define is_idchar(x) (ISIDNUM(x) || _dollar_ok(x)) +#define is_numchar(x) ISIDNUM(x) +#define is_idstart(x) (ISIDST(x) || _dollar_ok(x)) +#define is_numstart(x) ISDIGIT(x) +#define is_hspace(x) ISBLANK(x) +#define is_vspace(x) IS_VSPACE(x) +#define is_nvspace(x) IS_NVSPACE(x) +#define is_space(x) IS_SPACE_OR_NUL(x) /* This table is constant if it can be initialized at compile time, which is the case if cpp was compiled with GCC >=2.7, or another @@ -529,15 +542,15 @@ extern void _cpp_free_definition (cpp_hashnode *); extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *); extern void _cpp_pop_context (cpp_reader *); extern void _cpp_push_text_context (cpp_reader *, cpp_hashnode *, - const unsigned char *, size_t); + const unsigned char *, size_t); extern bool _cpp_save_parameter (cpp_reader *, cpp_macro *, cpp_hashnode *); extern bool _cpp_arguments_ok (cpp_reader *, cpp_macro *, const cpp_hashnode *, - unsigned int); + unsigned int); extern const unsigned char *_cpp_builtin_macro_text (cpp_reader *, - cpp_hashnode *); + cpp_hashnode *); extern int _cpp_warn_if_unused_macro (cpp_reader *, cpp_hashnode *, void *); extern void _cpp_push_token_context (cpp_reader *, cpp_hashnode *, - const cpp_token *, unsigned int); + const cpp_token *, unsigned int); extern void _cpp_backup_tokens_direct (cpp_reader *, unsigned int); /* In identifiers.c */ @@ -547,13 +560,13 @@ extern void _cpp_destroy_hashtable (cpp_reader *); /* In files.c */ typedef struct _cpp_file _cpp_file; extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *, - bool, int); + bool, int); extern bool _cpp_find_failed (_cpp_file *); extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *); extern void _cpp_fake_include (cpp_reader *, const char *); extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, bool); extern bool _cpp_stack_include (cpp_reader *, const char *, int, - enum include_type); + enum include_type); extern int _cpp_compare_file_date (cpp_reader *, const char *, int); extern void _cpp_report_missing_guards (cpp_reader *); extern void _cpp_init_files (cpp_reader *); @@ -577,6 +590,7 @@ extern const cpp_token *_cpp_lex_token (cpp_reader *); extern cpp_token *_cpp_lex_direct (cpp_reader *); extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *); extern void _cpp_init_tokenrun (tokenrun *, unsigned int); +extern cpp_hashnode *_cpp_lex_identifier (cpp_reader *, const char *); /* In init.c. */ extern void _cpp_maybe_push_include_file (cpp_reader *); @@ -591,7 +605,7 @@ extern int _cpp_do__Pragma (cpp_reader *); extern void _cpp_init_directives (cpp_reader *); extern void _cpp_init_internal_pragmas (cpp_reader *); extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *, - linenum_type, unsigned int); + linenum_type, unsigned int); extern void _cpp_pop_buffer (cpp_reader *); /* In directives.c */ @@ -603,19 +617,19 @@ struct _cpp_dir_only_callbacks }; extern void _cpp_preprocess_dir_only (cpp_reader *, - const struct _cpp_dir_only_callbacks *); + const struct _cpp_dir_only_callbacks *); /* In traditional.c. */ extern bool _cpp_scan_out_logical_line (cpp_reader *, cpp_macro *); extern bool _cpp_read_logical_line_trad (cpp_reader *); extern void _cpp_overlay_buffer (cpp_reader *pfile, const unsigned char *, - size_t); + size_t); extern void _cpp_remove_overlay (cpp_reader *); extern bool _cpp_create_trad_definition (cpp_reader *, cpp_macro *); extern bool _cpp_expansions_different_trad (const cpp_macro *, - const cpp_macro *); + const cpp_macro *); extern unsigned char *_cpp_copy_replacement_text (const cpp_macro *, - unsigned char *); + unsigned char *); extern size_t _cpp_replacement_text_len (const cpp_macro *); /* In charset.c. */ @@ -624,7 +638,7 @@ extern size_t _cpp_replacement_text_len (const cpp_macro *); It starts initialized to all zeros, and at the end 'level' is the normalization level of the sequence. */ -struct normalize_state +struct normalize_state { /* The previous character. */ cppchar_t previous; @@ -642,16 +656,16 @@ struct normalize_state ((st)->previous = 0, (st)->prev_class = 0) extern cppchar_t _cpp_valid_ucn (cpp_reader *, const unsigned char **, - const unsigned char *, int, - struct normalize_state *state); + const unsigned char *, int, + struct normalize_state *state); extern void _cpp_destroy_iconv (cpp_reader *); extern unsigned char *_cpp_convert_input (cpp_reader *, const char *, - unsigned char *, size_t, size_t, - const unsigned char **, off_t *); + unsigned char *, size_t, size_t, + const unsigned char **, off_t *); extern const char *_cpp_default_encoding (void); extern cpp_hashnode * _cpp_interpret_identifier (cpp_reader *pfile, - const unsigned char *id, - size_t len); + const unsigned char *id, + size_t len); /* Utility routines and macros. */ #define DSC(str) (const unsigned char *)str, sizeof str - 1 @@ -660,7 +674,7 @@ extern cpp_hashnode * _cpp_interpret_identifier (cpp_reader *pfile, checking. */ static inline int ustrcmp (const unsigned char *, const unsigned char *); static inline int ustrncmp (const unsigned char *, const unsigned char *, - size_t); + size_t); static inline size_t ustrlen (const unsigned char *); static inline unsigned char *uxstrdup (const unsigned char *); static inline unsigned char *ustrchr (const unsigned char *, int); diff --git a/support/cpp/libcpp/lex.c b/support/cpp/libcpp/lex.c index d02c50779..00b080f57 100644 --- a/support/cpp/libcpp/lex.c +++ b/support/cpp/libcpp/lex.c @@ -554,6 +554,57 @@ forms_identifier_p (cpp_reader *pfile, int first, return false; } +/* Helper function to get the cpp_hashnode of the identifier BASE. */ +static cpp_hashnode * +lex_identifier_intern (cpp_reader *pfile, const uchar *base) +{ + cpp_hashnode *result; + const uchar *cur; + unsigned int len; + unsigned int hash = HT_HASHSTEP (0, *base); + + cur = base + 1; + while (ISIDNUM (*cur)) + { + hash = HT_HASHSTEP (hash, *cur); + cur++; + } + len = cur - base; + hash = HT_HASHFINISH (hash, len); + result = CPP_HASHNODE (ht_lookup_with_hash (pfile->hash_table, + base, len, hash, HT_ALLOC)); + + /* Rarely, identifiers require diagnostics when lexed. */ + if (__builtin_expect ((result->flags & NODE_DIAGNOSTIC) + && !pfile->state.skipping, 0)) + { + /* It is allowed to poison the same identifier twice. */ + if ((result->flags & NODE_POISONED) && !pfile->state.poisoned_ok) + cpp_error (pfile, CPP_DL_ERROR, "attempt to use poisoned \"%s\"", + NODE_NAME (result)); + + /* Constraint 6.10.3.5: __VA_ARGS__ should only appear in the + replacement list of a variadic macro. */ + if (result == pfile->spec_nodes.n__VA_ARGS__ + && !pfile->state.va_args_ok) + cpp_error (pfile, CPP_DL_PEDWARN, + "__VA_ARGS__ can only appear in the expansion" + " of a C99 variadic macro"); + } + + return result; +} + +/* Get the cpp_hashnode of an identifier specified by NAME in + the current cpp_reader object. If none is found, NULL is returned. */ +cpp_hashnode * +_cpp_lex_identifier (cpp_reader *pfile, const char *name) +{ + cpp_hashnode *result; + result = lex_identifier_intern (pfile, (uchar *) name); + return result; +} + /* Lex an identifier starting at BUFFER->CUR - 1. */ static cpp_hashnode * lex_identifier (cpp_reader *pfile, const uchar *base, bool starts_ucn, @@ -615,7 +666,7 @@ lex_identifier (cpp_reader *pfile, const uchar *base, bool starts_ucn, return result; } -/* SDCC specific */ +/* sdpcc specific */ /* Pedantic parse a number, beginning with character C, skipping embedded backslash-newlines. LEADING_PERIOD is nonzero if there was a "." before C. Place the result in NUMBER. */ @@ -1017,6 +1068,7 @@ lex_string (cpp_reader *pfile, cpp_token *token, const uchar *base) create_literal (pfile, token, base, cur - base, type); } +/* sdcpp specific */ /* Fixed _WIN32 problem with CR-CR-LF sequences when outputting comment blocks (when executed with -C option) and _asm (SDCPP specific) blocks */ @@ -1149,6 +1201,7 @@ save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from, token->val.str.text = buffer; buffer[0] = '/'; + /* sdcpp specific */ copy_text_chars (buffer + 1, from, len); /* Finish conversion to a C comment, if necessary. */ @@ -1479,6 +1532,7 @@ _cpp_lex_direct (cpp_reader *pfile) { struct normalize_state nst = INITIAL_NORMALIZE_STATE; result->type = CPP_NUMBER; + /* sdcpp specific */ if (CPP_OPTION (pfile, pedantic_parse_number)) pedantic_lex_number (pfile, &result->val.str); else @@ -1666,6 +1720,7 @@ _cpp_lex_direct (cpp_reader *pfile) { struct normalize_state nst = INITIAL_NORMALIZE_STATE; result->type = CPP_NUMBER; + /* sdcpp specific */ if (CPP_OPTION (pfile, pedantic_parse_number)) pedantic_lex_number (pfile, &result->val.str); else |