X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fcpplib.c;h=f2556b385a09022d3697f089cf2b22299968d09c;hb=ecbfdc878159c748742c4a5e8d416e4edd90cac9;hp=2829953abbdba82e3fa91b56deea40d506814a3a;hpb=58efbd5a33bd5e70429499fc2bfac0098e326075;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 2829953abbd..f2556b385a0 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -1,6 +1,6 @@ /* CPP Library. (Directive handling.) Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Contributed by Per Bothner, 1994-95. Based on CCCP program by Paul Rubin, June 1986 Adapted to ANSI C, Richard Stallman, Jan 1987 @@ -21,9 +21,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "config.h" #include "system.h" -#include "coretypes.h" -#include "tm.h" - #include "cpplib.h" #include "cpphash.h" #include "obstack.h" @@ -45,11 +42,11 @@ struct if_stack 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. */ + int type; /* Most recent conditional for diagnostics. */ }; /* Contains a registered pragma or pragma namespace. */ -typedef void (*pragma_cb) PARAMS ((cpp_reader *)); +typedef void (*pragma_cb) (cpp_reader *); struct pragma_entry { struct pragma_entry *next; @@ -82,7 +79,7 @@ struct pragma_entry #define EXPAND (1 << 4) /* Defines one #-directive, including how to handle it. */ -typedef void (*directive_handler) PARAMS ((cpp_reader *)); +typedef void (*directive_handler) (cpp_reader *); typedef struct directive directive; struct directive { @@ -95,51 +92,44 @@ struct directive /* Forward declarations. */ -static void skip_rest_of_line PARAMS ((cpp_reader *)); -static void check_eol PARAMS ((cpp_reader *)); -static void start_directive PARAMS ((cpp_reader *)); -static void prepare_directive_trad PARAMS ((cpp_reader *)); -static void end_directive PARAMS ((cpp_reader *, int)); -static void directive_diagnostics - PARAMS ((cpp_reader *, const directive *, int)); -static void run_directive PARAMS ((cpp_reader *, int, - const char *, size_t)); -static char *glue_header_name PARAMS ((cpp_reader *)); -static const char *parse_include PARAMS ((cpp_reader *, int *)); -static void push_conditional PARAMS ((cpp_reader *, int, int, - const cpp_hashnode *)); -static unsigned int read_flag PARAMS ((cpp_reader *, unsigned int)); -static uchar *dequote_string PARAMS ((cpp_reader *, const uchar *, - unsigned int)); -static int strtoul_for_line PARAMS ((const uchar *, unsigned int, - unsigned long *)); -static void do_diagnostic PARAMS ((cpp_reader *, int, int)); -static cpp_hashnode *lex_macro_node PARAMS ((cpp_reader *)); -static void do_include_common PARAMS ((cpp_reader *, enum include_type)); -static struct pragma_entry *lookup_pragma_entry - PARAMS ((struct pragma_entry *, const cpp_hashnode *pragma)); -static struct pragma_entry *insert_pragma_entry - PARAMS ((cpp_reader *, struct pragma_entry **, const cpp_hashnode *, - pragma_cb)); -static int count_registered_pragmas PARAMS ((struct pragma_entry *)); -static char ** save_registered_pragmas - PARAMS ((struct pragma_entry *, char **)); -static char ** restore_registered_pragmas - PARAMS ((cpp_reader *, struct pragma_entry *, char **)); -static void do_pragma_once PARAMS ((cpp_reader *)); -static void do_pragma_poison PARAMS ((cpp_reader *)); -static void do_pragma_system_header PARAMS ((cpp_reader *)); -static void do_pragma_dependency PARAMS ((cpp_reader *)); -static void do_linemarker PARAMS ((cpp_reader *)); -static const cpp_token *get_token_no_padding PARAMS ((cpp_reader *)); -static const cpp_token *get__Pragma_string PARAMS ((cpp_reader *)); -static void destringize_and_run PARAMS ((cpp_reader *, const cpp_string *)); -static int parse_answer PARAMS ((cpp_reader *, struct answer **, int)); -static cpp_hashnode *parse_assertion PARAMS ((cpp_reader *, struct answer **, - int)); -static struct answer ** find_answer PARAMS ((cpp_hashnode *, - const struct answer *)); -static void handle_assertion PARAMS ((cpp_reader *, const char *, int)); +static void skip_rest_of_line (cpp_reader *); +static void check_eol (cpp_reader *); +static void start_directive (cpp_reader *); +static void prepare_directive_trad (cpp_reader *); +static void end_directive (cpp_reader *, int); +static void directive_diagnostics (cpp_reader *, const directive *, int); +static void run_directive (cpp_reader *, int, const char *, size_t); +static char *glue_header_name (cpp_reader *); +static const char *parse_include (cpp_reader *, int *); +static void push_conditional (cpp_reader *, int, int, const cpp_hashnode *); +static unsigned int read_flag (cpp_reader *, unsigned int); +static int strtoul_for_line (const uchar *, unsigned int, unsigned long *); +static void do_diagnostic (cpp_reader *, int, int); +static cpp_hashnode *lex_macro_node (cpp_reader *); +static int undefine_macros (cpp_reader *, cpp_hashnode *, void *); +static void do_include_common (cpp_reader *, enum include_type); +static struct pragma_entry *lookup_pragma_entry (struct pragma_entry *, + const cpp_hashnode *); +static struct pragma_entry *insert_pragma_entry (cpp_reader *, + struct pragma_entry **, + const cpp_hashnode *, + pragma_cb); +static int count_registered_pragmas (struct pragma_entry *); +static char ** save_registered_pragmas (struct pragma_entry *, char **); +static char ** restore_registered_pragmas (cpp_reader *, struct pragma_entry *, + char **); +static void do_pragma_once (cpp_reader *); +static void do_pragma_poison (cpp_reader *); +static void do_pragma_system_header (cpp_reader *); +static void do_pragma_dependency (cpp_reader *); +static void do_linemarker (cpp_reader *); +static const cpp_token *get_token_no_padding (cpp_reader *); +static const cpp_token *get__Pragma_string (cpp_reader *); +static void destringize_and_run (cpp_reader *, const cpp_string *); +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); /* This is the table of directive handlers. It is ordered by frequency of occurrence; the numbers at the end are directive @@ -174,8 +164,7 @@ D(sccs, T_SCCS, EXTENSION, 0) /* 0 SVR4? */ /* Use the table to generate a series of prototypes, an enum for the directive names, and an array of directive handlers. */ -/* Don't invoke CONCAT2 with any whitespace or K&R cc will fail. */ -#define D(name, t, o, f) static void CONCAT2(do_,name) PARAMS ((cpp_reader *)); +#define D(name, t, o, f) static void do_##name (cpp_reader *); DIRECTIVE_TABLE #undef D @@ -187,10 +176,9 @@ enum }; #undef D -/* Don't invoke CONCAT2 with any whitespace or K&R cc will fail. */ #define D(name, t, origin, flags) \ -{ CONCAT2(do_,name), (const uchar *) STRINGX(name), \ - sizeof STRINGX(name) - 1, origin, flags }, +{ do_##name, (const uchar *) #name, \ + sizeof #name - 1, origin, flags }, static const directive dtable[] = { DIRECTIVE_TABLE @@ -210,8 +198,7 @@ static const directive linemarker_dir = /* Skip any remaining tokens in a directive. */ static void -skip_rest_of_line (pfile) - cpp_reader *pfile; +skip_rest_of_line (cpp_reader *pfile) { /* Discard all stacked contexts. */ while (pfile->context->prev) @@ -225,18 +212,16 @@ skip_rest_of_line (pfile) /* Ensure there are no stray tokens at the end of a directive. */ static void -check_eol (pfile) - cpp_reader *pfile; +check_eol (cpp_reader *pfile) { if (! SEEN_EOL () && _cpp_lex_token (pfile)->type != CPP_EOF) - cpp_error (pfile, DL_PEDWARN, "extra tokens at end of #%s directive", + cpp_error (pfile, CPP_DL_PEDWARN, "extra tokens at end of #%s directive", pfile->directive->name); } /* Called when entering a directive, _Pragma or command-line directive. */ static void -start_directive (pfile) - cpp_reader *pfile; +start_directive (cpp_reader *pfile) { /* Setup in-directive state. */ pfile->state.in_directive = 1; @@ -248,9 +233,7 @@ start_directive (pfile) /* Called when leaving a directive, _Pragma or command-line directive. */ static void -end_directive (pfile, skip_line) - cpp_reader *pfile; - int skip_line; +end_directive (cpp_reader *pfile, int skip_line) { if (CPP_OPTION (pfile, traditional)) { @@ -281,8 +264,7 @@ end_directive (pfile, skip_line) /* Prepare to handle the directive in pfile->directive. */ static void -prepare_directive_trad (pfile) - cpp_reader *pfile; +prepare_directive_trad (cpp_reader *pfile) { if (pfile->directive != &dtable[T_DEFINE]) { @@ -290,14 +272,17 @@ prepare_directive_trad (pfile) && ! (pfile->directive->flags & EXPAND)); bool was_skipping = pfile->state.skipping; - pfile->state.skipping = false; pfile->state.in_expression = (pfile->directive == &dtable[T_IF] || pfile->directive == &dtable[T_ELIF]); + if (pfile->state.in_expression) + pfile->state.skipping = false; + if (no_expand) pfile->state.prevent_expansion++; - scan_out_logical_line (pfile, NULL); + _cpp_scan_out_logical_line (pfile, NULL); if (no_expand) pfile->state.prevent_expansion--; + pfile->state.skipping = was_skipping; _cpp_overlay_buffer (pfile, pfile->out.base, pfile->out.cur - pfile->out.base); @@ -310,16 +295,13 @@ prepare_directive_trad (pfile) /* Output diagnostics for a directive DIR. INDENTED is nonzero if the '#' was indented. */ static void -directive_diagnostics (pfile, dir, indented) - cpp_reader *pfile; - const directive *dir; - int indented; +directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented) { /* Issue -pedantic warnings for extensions. */ if (CPP_PEDANTIC (pfile) && ! pfile->state.skipping && dir->origin == EXTENSION) - cpp_error (pfile, DL_PEDWARN, "#%s is a GCC extension", dir->name); + cpp_error (pfile, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name); /* Traditionally, a directive is ignored unless its # is in column 1. Therefore in code intended to work with K+R @@ -330,14 +312,14 @@ directive_diagnostics (pfile, dir, indented) if (CPP_WTRADITIONAL (pfile)) { if (dir == &dtable[T_ELIF]) - cpp_error (pfile, DL_WARNING, + cpp_error (pfile, CPP_DL_WARNING, "suggest not using #elif in traditional C"); else if (indented && dir->origin == KANDR) - cpp_error (pfile, DL_WARNING, + cpp_error (pfile, CPP_DL_WARNING, "traditional C ignores #%s with the # indented", dir->name); else if (!indented && dir->origin != KANDR) - cpp_error (pfile, DL_WARNING, + cpp_error (pfile, CPP_DL_WARNING, "suggest hiding #%s from traditional C with an indented #", dir->name); } @@ -349,9 +331,7 @@ directive_diagnostics (pfile, dir, indented) nonzero if the line of tokens has been handled, zero if we should continue processing the line. */ int -_cpp_handle_directive (pfile, indented) - cpp_reader *pfile; - int indented; +_cpp_handle_directive (cpp_reader *pfile, int indented) { const directive *dir = 0; const cpp_token *dname; @@ -361,7 +341,7 @@ _cpp_handle_directive (pfile, indented) if (was_parsing_args) { if (CPP_OPTION (pfile, pedantic)) - cpp_error (pfile, DL_PEDWARN, + 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; @@ -381,7 +361,7 @@ _cpp_handle_directive (pfile, indented) dir = &linemarker_dir; if (CPP_PEDANTIC (pfile) && ! CPP_OPTION (pfile, preprocessed) && ! pfile->state.skipping) - cpp_error (pfile, DL_PEDWARN, + cpp_error (pfile, CPP_DL_PEDWARN, "style of line directive is a GCC extension"); } @@ -432,7 +412,7 @@ _cpp_handle_directive (pfile, indented) if (CPP_OPTION (pfile, lang) == CLK_ASM) skip = 0; else if (!pfile->state.skipping) - cpp_error (pfile, DL_ERROR, "invalid preprocessing directive #%s", + cpp_error (pfile, CPP_DL_ERROR, "invalid preprocessing directive #%s", cpp_token_as_text (pfile, dname)); } @@ -441,7 +421,7 @@ _cpp_handle_directive (pfile, indented) prepare_directive_trad (pfile); if (dir) - (*pfile->directive->handler) (pfile); + pfile->directive->handler (pfile); else if (skip == 0) _cpp_backup_tokens (pfile, 1); @@ -458,17 +438,13 @@ _cpp_handle_directive (pfile, indented) /* Directive handler wrapper used by the command line option processor. BUF is \n terminated. */ static void -run_directive (pfile, dir_no, buf, count) - cpp_reader *pfile; - int dir_no; - const char *buf; - size_t count; +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, 1); + /* from_stage3 */ true); /* Disgusting hack. */ if (dir_no == T_PRAGMA) - pfile->buffer->inc = pfile->buffer->prev->inc; + pfile->buffer->file = pfile->buffer->prev->file; start_directive (pfile); /* This is a short-term fix to prevent a leading '#' being @@ -478,18 +454,17 @@ run_directive (pfile, dir_no, buf, count) pfile->directive = &dtable[dir_no]; if (CPP_OPTION (pfile, traditional)) prepare_directive_trad (pfile); - (void) (*pfile->directive->handler) (pfile); + pfile->directive->handler (pfile); end_directive (pfile, 1); if (dir_no == T_PRAGMA) - pfile->buffer->inc = NULL; + pfile->buffer->file = NULL; _cpp_pop_buffer (pfile); } /* Checks for validity the macro name in #define, #undef, #ifdef and #ifndef directives. */ static cpp_hashnode * -lex_macro_node (pfile) - cpp_reader *pfile; +lex_macro_node (cpp_reader *pfile) { const cpp_token *token = _cpp_lex_token (pfile); @@ -505,28 +480,27 @@ lex_macro_node (pfile) cpp_hashnode *node = token->val.node; if (node == pfile->spec_nodes.n_defined) - cpp_error (pfile, DL_ERROR, + cpp_error (pfile, CPP_DL_ERROR, "\"defined\" cannot be used as a macro name"); else if (! (node->flags & NODE_POISONED)) return node; } else if (token->flags & NAMED_OP) - cpp_error (pfile, DL_ERROR, + 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)); else if (token->type == CPP_EOF) - cpp_error (pfile, DL_ERROR, "no macro name given in #%s directive", + cpp_error (pfile, CPP_DL_ERROR, "no macro name given in #%s directive", pfile->directive->name); else - cpp_error (pfile, DL_ERROR, "macro names must be identifiers"); + cpp_error (pfile, CPP_DL_ERROR, "macro names must be identifiers"); return NULL; } /* Process a #define directive. Most work is done in cppmacro.c. */ static void -do_define (pfile) - cpp_reader *pfile; +do_define (cpp_reader *pfile) { cpp_hashnode *node = lex_macro_node (pfile); @@ -539,41 +513,83 @@ do_define (pfile) if (_cpp_create_definition (pfile, node)) if (pfile->cb.define) - (*pfile->cb.define) (pfile, pfile->directive_line, node); + pfile->cb.define (pfile, pfile->directive_line, node); } } /* Handle #undef. Mark the identifier NT_VOID in the hash table. */ static void -do_undef (pfile) - cpp_reader *pfile; +do_undef (cpp_reader *pfile) { cpp_hashnode *node = lex_macro_node (pfile); - /* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified identifier - is not currently defined as a macro name. */ - if (node && node->type == NT_MACRO) + if (node) { if (pfile->cb.undef) - (*pfile->cb.undef) (pfile, pfile->directive_line, node); + pfile->cb.undef (pfile, pfile->directive_line, node); - if (node->flags & NODE_WARN) - cpp_error (pfile, DL_WARNING, "undefining \"%s\"", NODE_NAME (node)); + /* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified + 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 (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); } +/* Undefine a single macro/assertion/whatever. */ + +static int +undefine_macros (cpp_reader *pfile, cpp_hashnode *h, + void *data_p ATTRIBUTE_UNUSED) +{ + switch (h->type) + { + case NT_VOID: + break; + + case NT_MACRO: + if (pfile->cb.undef) + (*pfile->cb.undef) (pfile, pfile->directive_line, h); + + if (CPP_OPTION (pfile, warn_unused_macros)) + _cpp_warn_if_unused_macro (pfile, h, NULL); + + /* And fall through.... */ + case NT_ASSERTION: + _cpp_free_definition (h); + break; + + default: + abort (); + } + h->flags &= ~NODE_POISONED; + return 1; +} + +/* Undefine all macros and assertions. */ + +void +cpp_undef_all (cpp_reader *pfile) +{ + cpp_forall_identifiers (pfile, undefine_macros, NULL); +} + + /* Helper routine used by parse_include. Reinterpret the current line as an h-char-sequence (< ... >); we are looking at the first token after the <. Returns a malloced filename. */ static char * -glue_header_name (pfile) - cpp_reader *pfile; +glue_header_name (cpp_reader *pfile) { const cpp_token *token; char *buffer; @@ -590,11 +606,11 @@ glue_header_name (pfile) break; if (token->type == CPP_EOF) { - cpp_error (pfile, DL_ERROR, "missing terminating > character"); + cpp_error (pfile, CPP_DL_ERROR, "missing terminating > character"); break; } - len = cpp_token_len (token); + len = cpp_token_len (token) + 2; /* Leading space, terminating \0. */ if (total_len + len > capacity) { capacity = (capacity + len) * 2; @@ -616,9 +632,7 @@ glue_header_name (pfile) #pragma dependency. The string is malloced and the caller should free it. Returns NULL on error. */ static const char * -parse_include (pfile, pangle_brackets) - cpp_reader *pfile; - int *pangle_brackets; +parse_include (cpp_reader *pfile, int *pangle_brackets) { char *fname; const cpp_token *header; @@ -627,9 +641,9 @@ parse_include (pfile, pangle_brackets) header = get_token_no_padding (pfile); if (header->type == CPP_STRING || header->type == CPP_HEADER_NAME) { - fname = xmalloc (header->val.str.len + 1); - memcpy (fname, header->val.str.text, header->val.str.len); - fname[header->val.str.len] = '\0'; + fname = xmalloc (header->val.str.len - 1); + memcpy (fname, header->val.str.text + 1, header->val.str.len - 2); + fname[header->val.str.len - 2] = '\0'; *pangle_brackets = header->type == CPP_HEADER_NAME; } else if (header->type == CPP_LESS) @@ -645,7 +659,7 @@ parse_include (pfile, pangle_brackets) dir = U"pragma dependency"; else dir = pfile->directive->name; - cpp_error (pfile, DL_ERROR, "#%s expects \"FILENAME\" or ", + cpp_error (pfile, CPP_DL_ERROR, "#%s expects \"FILENAME\" or ", dir); return NULL; @@ -657,9 +671,7 @@ parse_include (pfile, pangle_brackets) /* Handle #include, #include_next and #import. */ static void -do_include_common (pfile, type) - cpp_reader *pfile; - enum include_type type; +do_include_common (cpp_reader *pfile, enum include_type type) { const char *fname; int angle_brackets; @@ -669,47 +681,37 @@ do_include_common (pfile, type) return; /* Prevent #include recursion. */ - if (pfile->line_maps.depth >= CPP_STACK_MAX) - cpp_error (pfile, DL_ERROR, "#include nested too deeply"); + if (pfile->line_table->depth >= CPP_STACK_MAX) + cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply"); else { /* Get out of macro context, if we are. */ skip_rest_of_line (pfile); if (pfile->cb.include) - (*pfile->cb.include) (pfile, pfile->directive_line, - pfile->directive->name, fname, angle_brackets); + pfile->cb.include (pfile, pfile->directive_line, + pfile->directive->name, fname, angle_brackets); - _cpp_execute_include (pfile, fname, angle_brackets, type); + _cpp_stack_include (pfile, fname, angle_brackets, type); } - free ((PTR) fname); + free ((void *) fname); } static void -do_include (pfile) - cpp_reader *pfile; +do_include (cpp_reader *pfile) { do_include_common (pfile, IT_INCLUDE); } static void -do_import (pfile) - cpp_reader *pfile; +do_import (cpp_reader *pfile) { - if (CPP_OPTION (pfile, warn_import)) - { - CPP_OPTION (pfile, warn_import) = 0; - cpp_error (pfile, DL_WARNING, - "#import is obsolete, use an #ifndef wrapper in the header file"); - } - do_include_common (pfile, IT_IMPORT); } static void -do_include_next (pfile) - cpp_reader *pfile; +do_include_next (cpp_reader *pfile) { enum include_type type = IT_INCLUDE_NEXT; @@ -717,7 +719,7 @@ do_include_next (pfile) search logic. */ if (! pfile->buffer->prev) { - cpp_error (pfile, DL_WARNING, + cpp_error (pfile, CPP_DL_WARNING, "#include_next in primary source file"); type = IT_INCLUDE; } @@ -729,9 +731,7 @@ do_include_next (pfile) flag if it is valid, 0 at the end of the directive. Otherwise complain. */ static unsigned int -read_flag (pfile, last) - cpp_reader *pfile; - unsigned int last; +read_flag (cpp_reader *pfile, unsigned int last) { const cpp_token *token = _cpp_lex_token (pfile); @@ -746,45 +746,16 @@ read_flag (pfile, last) } if (token->type != CPP_EOF) - cpp_error (pfile, DL_ERROR, "invalid flag \"%s\" in line directive", + cpp_error (pfile, CPP_DL_ERROR, "invalid flag \"%s\" in line directive", cpp_token_as_text (pfile, token)); return 0; } -/* Subroutine of do_line and do_linemarker. Returns a version of STR - which has a NUL terminator and all escape sequences converted to - their equivalents. Temporary, hopefully. */ -static uchar * -dequote_string (pfile, str, len) - cpp_reader *pfile; - const uchar *str; - unsigned int len; -{ - uchar *result = _cpp_unaligned_alloc (pfile, len + 1); - uchar *dst = result; - const uchar *limit = str + len; - cppchar_t c; - - while (str < limit) - { - c = *str++; - if (c != '\\') - *dst++ = c; - else - *dst++ = cpp_parse_escape (pfile, &str, limit, 0); - } - *dst++ = '\0'; - return result; -} - /* Subroutine of do_line and do_linemarker. Convert a number in STR, of length LEN, to binary; store it in NUMP, and return 0 if the number was well-formed, 1 if not. Temporary, hopefully. */ static int -strtoul_for_line (str, len, nump) - const uchar *str; - unsigned int len; - unsigned long *nump; +strtoul_for_line (const uchar *str, unsigned int len, long unsigned int *nump) { unsigned long reg = 0; uchar c; @@ -804,11 +775,11 @@ strtoul_for_line (str, len, nump) Note that the filename string (if any) is a true string constant (escapes are interpreted), unlike in #line. */ static void -do_line (pfile) - cpp_reader *pfile; +do_line (cpp_reader *pfile) { + const struct line_map *map = linemap_lookup (pfile->line_table, pfile->line); const cpp_token *token; - const char *new_file = pfile->map->to_file; + const char *new_file = map->to_file; unsigned long new_lineno; /* C99 raised the minimum limit on #line numbers. */ @@ -820,45 +791,47 @@ do_line (pfile) || strtoul_for_line (token->val.str.text, token->val.str.len, &new_lineno)) { - cpp_error (pfile, DL_ERROR, + cpp_error (pfile, CPP_DL_ERROR, "\"%s\" after #line is not a positive integer", cpp_token_as_text (pfile, token)); return; } if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap)) - cpp_error (pfile, DL_PEDWARN, "line number out of range"); + cpp_error (pfile, CPP_DL_PEDWARN, "line number out of range"); token = cpp_get_token (pfile); if (token->type == CPP_STRING) { - new_file = (const char *) dequote_string (pfile, token->val.str.text, - token->val.str.len); + cpp_string s = { 0, 0 }; + if (cpp_interpret_string_notranslate (pfile, &token->val.str, 1, + &s, false)) + new_file = (const char *)s.text; check_eol (pfile); } else if (token->type != CPP_EOF) { - cpp_error (pfile, DL_ERROR, "\"%s\" is not a valid filename", + cpp_error (pfile, CPP_DL_ERROR, "\"%s\" is not a valid filename", cpp_token_as_text (pfile, token)); return; } skip_rest_of_line (pfile); _cpp_do_file_change (pfile, LC_RENAME, new_file, new_lineno, - pfile->map->sysp); + map->sysp); } /* Interpret the # 44 "file" [flags] notation, which has slightly different syntax and semantics from #line: Flags are allowed, and we never complain about the line number being too big. */ static void -do_linemarker (pfile) - cpp_reader *pfile; +do_linemarker (cpp_reader *pfile) { + const struct line_map *map = linemap_lookup (pfile->line_table, pfile->line); const cpp_token *token; - const char *new_file = pfile->map->to_file; + const char *new_file = map->to_file; unsigned long new_lineno; - unsigned int new_sysp = pfile->map->sysp; + unsigned int new_sysp = map->sysp; enum lc_reason reason = LC_RENAME; int flag; @@ -873,7 +846,8 @@ do_linemarker (pfile) || strtoul_for_line (token->val.str.text, token->val.str.len, &new_lineno)) { - cpp_error (pfile, DL_ERROR, "\"%s\" after # is not a positive integer", + cpp_error (pfile, CPP_DL_ERROR, + "\"%s\" after # is not a positive integer", cpp_token_as_text (pfile, token)); return; } @@ -881,8 +855,11 @@ do_linemarker (pfile) token = cpp_get_token (pfile); if (token->type == CPP_STRING) { - new_file = (const char *) dequote_string (pfile, token->val.str.text, - token->val.str.len); + cpp_string s = { 0, 0 }; + if (cpp_interpret_string_notranslate (pfile, &token->val.str, + 1, &s, false)) + new_file = (const char *)s.text; + new_sysp = 0; flag = read_flag (pfile, 0); if (flag == 1) @@ -903,13 +880,14 @@ do_linemarker (pfile) flag = read_flag (pfile, flag); if (flag == 4) new_sysp = 2; + pfile->buffer->sysp = new_sysp; } check_eol (pfile); } else if (token->type != CPP_EOF) { - cpp_error (pfile, DL_ERROR, "\"%s\" is not a valid filename", + cpp_error (pfile, CPP_DL_ERROR, "\"%s\" is not a valid filename", cpp_token_as_text (pfile, token)); return; } @@ -923,31 +901,27 @@ do_linemarker (pfile) header, 2 for a system header that needs to be extern "C" protected, and zero otherwise. */ void -_cpp_do_file_change (pfile, reason, to_file, file_line, sysp) - cpp_reader *pfile; - enum lc_reason reason; - const char *to_file; - unsigned int file_line; - unsigned int sysp; -{ - pfile->map = add_line_map (&pfile->line_maps, reason, sysp, - pfile->line, to_file, file_line); +_cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason, + const char *to_file, unsigned int file_line, + unsigned int sysp) +{ + const struct line_map *map = linemap_add (pfile->line_table, reason, sysp, + to_file, file_line); + if (map == NULL) + pfile->line = 0; + else + pfile->line = linemap_line_start (pfile->line_table, map->to_line, 127); if (pfile->cb.file_change) - (*pfile->cb.file_change) (pfile, pfile->map); + pfile->cb.file_change (pfile, map); } /* Report a warning or error detected by the program we are processing. Use the directive's tokens in the error message. */ static void -do_diagnostic (pfile, code, print_dir) - cpp_reader *pfile; - int code; - int print_dir; -{ - if (_cpp_begin_message (pfile, code, - pfile->cur_token[-1].line, - pfile->cur_token[-1].col)) +do_diagnostic (cpp_reader *pfile, int code, int print_dir) +{ + if (_cpp_begin_message (pfile, code, pfile->cur_token[-1].src_loc, 0)) { if (print_dir) fprintf (stderr, "#%s ", pfile->directive->name); @@ -958,31 +932,28 @@ do_diagnostic (pfile, code, print_dir) } static void -do_error (pfile) - cpp_reader *pfile; +do_error (cpp_reader *pfile) { - do_diagnostic (pfile, DL_ERROR, 1); + do_diagnostic (pfile, CPP_DL_ERROR, 1); } static void -do_warning (pfile) - cpp_reader *pfile; +do_warning (cpp_reader *pfile) { /* We want #warning diagnostics to be emitted in system headers too. */ - do_diagnostic (pfile, DL_WARNING_SYSHDR, 1); + do_diagnostic (pfile, CPP_DL_WARNING_SYSHDR, 1); } /* Report program identification. */ static void -do_ident (pfile) - cpp_reader *pfile; +do_ident (cpp_reader *pfile) { const cpp_token *str = cpp_get_token (pfile); if (str->type != CPP_STRING) - cpp_error (pfile, DL_ERROR, "invalid #ident directive"); + cpp_error (pfile, CPP_DL_ERROR, "invalid #ident directive"); else if (pfile->cb.ident) - (*pfile->cb.ident) (pfile, pfile->directive_line, &str->val.str); + pfile->cb.ident (pfile, pfile->directive_line, &str->val.str); check_eol (pfile); } @@ -991,9 +962,7 @@ do_ident (pfile) matching entry, or NULL if none is found. The returned entry could be the start of a namespace chain, or a pragma. */ static struct pragma_entry * -lookup_pragma_entry (chain, pragma) - struct pragma_entry *chain; - const cpp_hashnode *pragma; +lookup_pragma_entry (struct pragma_entry *chain, const cpp_hashnode *pragma) { while (chain && chain->pragma != pragma) chain = chain->next; @@ -1005,11 +974,8 @@ lookup_pragma_entry (chain, pragma) singly-linked CHAIN. If handler is NULL, it is a namespace, otherwise it is a pragma and its handler. */ static struct pragma_entry * -insert_pragma_entry (pfile, chain, pragma, handler) - cpp_reader *pfile; - struct pragma_entry **chain; - const cpp_hashnode *pragma; - pragma_cb handler; +insert_pragma_entry (cpp_reader *pfile, struct pragma_entry **chain, + const cpp_hashnode *pragma, pragma_cb handler) { struct pragma_entry *new; @@ -1036,11 +1002,8 @@ insert_pragma_entry (pfile, chain, pragma, handler) goes in the global namespace. HANDLER is the handler it will call, which must be non-NULL. */ void -cpp_register_pragma (pfile, space, name, handler) - cpp_reader *pfile; - const char *space; - const char *name; - pragma_cb handler; +cpp_register_pragma (cpp_reader *pfile, const char *space, const char *name, + pragma_cb handler) { struct pragma_entry **chain = &pfile->pragmas; struct pragma_entry *entry; @@ -1067,14 +1030,14 @@ cpp_register_pragma (pfile, space, name, handler) { if (entry->is_nspace) clash: - cpp_error (pfile, DL_ICE, + cpp_error (pfile, CPP_DL_ICE, "registering \"%s\" as both a pragma and a pragma namespace", NODE_NAME (node)); else if (space) - cpp_error (pfile, DL_ICE, "#pragma %s %s is already registered", + cpp_error (pfile, CPP_DL_ICE, "#pragma %s %s is already registered", space, name); else - cpp_error (pfile, DL_ICE, "#pragma %s is already registered", name); + cpp_error (pfile, CPP_DL_ICE, "#pragma %s is already registered", name); } else insert_pragma_entry (pfile, chain, node, handler); @@ -1082,8 +1045,7 @@ cpp_register_pragma (pfile, space, name, handler) /* Register the pragmas the preprocessor itself handles. */ void -_cpp_init_internal_pragmas (pfile) - cpp_reader *pfile; +_cpp_init_internal_pragmas (cpp_reader *pfile) { /* Pragmas in the global namespace. */ cpp_register_pragma (pfile, 0, "once", do_pragma_once); @@ -1097,8 +1059,7 @@ _cpp_init_internal_pragmas (pfile) /* Return the number of registered pragmas in PE. */ static int -count_registered_pragmas (pe) - struct pragma_entry *pe; +count_registered_pragmas (struct pragma_entry *pe) { int ct = 0; for (; pe != NULL; pe = pe->next) @@ -1114,9 +1075,7 @@ count_registered_pragmas (pe) and return a pointer to the next free space in SD. */ static char ** -save_registered_pragmas (pe, sd) - struct pragma_entry *pe; - char **sd; +save_registered_pragmas (struct pragma_entry *pe, char **sd) { for (; pe != NULL; pe = pe->next) { @@ -1133,8 +1092,7 @@ save_registered_pragmas (pe, sd) registered pragmas. */ char ** -_cpp_save_pragma_names (pfile) - cpp_reader *pfile; +_cpp_save_pragma_names (cpp_reader *pfile) { int ct = count_registered_pragmas (pfile->pragmas); char **result = xnewvec (char *, ct); @@ -1146,10 +1104,8 @@ _cpp_save_pragma_names (pfile) and return a pointer to the next unused name in SD. */ static char ** -restore_registered_pragmas (pfile, pe, sd) - cpp_reader *pfile; - struct pragma_entry *pe; - char **sd; +restore_registered_pragmas (cpp_reader *pfile, struct pragma_entry *pe, + char **sd) { for (; pe != NULL; pe = pe->next) { @@ -1165,9 +1121,7 @@ restore_registered_pragmas (pfile, pe, sd) /* Restore the names of the registered pragmas from SAVED. */ void -_cpp_restore_pragma_names (pfile, saved) - cpp_reader *pfile; - char **saved; +_cpp_restore_pragma_names (cpp_reader *pfile, char **saved) { (void) restore_registered_pragmas (pfile, pfile->pragmas, saved); free (saved); @@ -1179,11 +1133,10 @@ _cpp_restore_pragma_names (pfile, saved) expansion happens for other pragmas is implementation defined. This implementation never macro-expands the text after #pragma. */ static void -do_pragma (pfile) - cpp_reader *pfile; +do_pragma (cpp_reader *pfile) { const struct pragma_entry *p = NULL; - const cpp_token *token; + const cpp_token *token, *pragma_token = pfile->cur_token; unsigned int count = 1; pfile->state.prevent_expansion++; @@ -1203,20 +1156,22 @@ do_pragma (pfile) } } - /* FIXME. This is an awful kludge to get the front ends to update - their notion of line number for diagnostic purposes. The line - number should be passed to the handler and they should do it - themselves. Stand-alone CPP must ignore us, otherwise it will - prefix the directive with spaces, hence the 1. Ugh. */ - if (pfile->cb.line_change) - (*pfile->cb.line_change)(pfile, token, 1); - if (p) - (*p->u.handler) (pfile); + { + /* 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); + (*p->u.handler) (pfile); + if (pfile->cb.line_change) + (*pfile->cb.line_change) (pfile, pfile->cur_token, false); + + } else if (pfile->cb.def_pragma) { _cpp_backup_tokens (pfile, count); - (*pfile->cb.def_pragma) (pfile, pfile->directive_line); + pfile->cb.def_pragma (pfile, pfile->directive_line); } pfile->state.prevent_expansion--; @@ -1224,25 +1179,19 @@ do_pragma (pfile) /* Handle #pragma once. */ static void -do_pragma_once (pfile) - cpp_reader *pfile; +do_pragma_once (cpp_reader *pfile) { - if (CPP_OPTION (pfile, warn_deprecated)) - cpp_error (pfile, DL_WARNING, "#pragma once is obsolete"); - if (pfile->buffer->prev == NULL) - cpp_error (pfile, DL_WARNING, "#pragma once in main file"); - else - _cpp_never_reread (pfile->buffer->inc); + cpp_error (pfile, CPP_DL_WARNING, "#pragma once in main file"); check_eol (pfile); + _cpp_mark_file_once_only (pfile, pfile->buffer->file); } /* Handle #pragma GCC poison, to poison one or more identifiers so that the lexer produces a hard error for each subsequent usage. */ static void -do_pragma_poison (pfile) - cpp_reader *pfile; +do_pragma_poison (cpp_reader *pfile) { const cpp_token *tok; cpp_hashnode *hp; @@ -1255,7 +1204,8 @@ do_pragma_poison (pfile) break; if (tok->type != CPP_NAME) { - cpp_error (pfile, DL_ERROR, "invalid #pragma GCC poison directive"); + cpp_error (pfile, CPP_DL_ERROR, + "invalid #pragma GCC poison directive"); break; } @@ -1264,7 +1214,7 @@ do_pragma_poison (pfile) continue; if (hp->type == NT_MACRO) - cpp_error (pfile, DL_WARNING, "poisoning existing macro \"%s\"", + cpp_error (pfile, CPP_DL_WARNING, "poisoning existing macro \"%s\"", NODE_NAME (hp)); _cpp_free_definition (hp); hp->flags |= NODE_POISONED | NODE_DIAGNOSTIC; @@ -1279,13 +1229,12 @@ do_pragma_poison (pfile) system include directory. To prevent abuse, it is rejected in the primary source file. */ static void -do_pragma_system_header (pfile) - cpp_reader *pfile; +do_pragma_system_header (cpp_reader *pfile) { cpp_buffer *buffer = pfile->buffer; if (buffer->prev == 0) - cpp_error (pfile, DL_WARNING, + cpp_error (pfile, CPP_DL_WARNING, "#pragma system_header ignored outside include file"); else { @@ -1299,8 +1248,7 @@ do_pragma_system_header (pfile) file. Issue a diagnostic, if the specified file is newer. We use this to determine if a fixed header should be refixed. */ static void -do_pragma_dependency (pfile) - cpp_reader *pfile; +do_pragma_dependency (cpp_reader *pfile) { const char *fname; int angle_brackets, ordering; @@ -1311,24 +1259,24 @@ do_pragma_dependency (pfile) ordering = _cpp_compare_file_date (pfile, fname, angle_brackets); if (ordering < 0) - cpp_error (pfile, DL_WARNING, "cannot find source file %s", fname); + cpp_error (pfile, CPP_DL_WARNING, "cannot find source file %s", fname); else if (ordering > 0) { - cpp_error (pfile, DL_WARNING, "current file is older than %s", fname); + cpp_error (pfile, CPP_DL_WARNING, + "current file is older than %s", fname); if (cpp_get_token (pfile)->type != CPP_EOF) { _cpp_backup_tokens (pfile, 1); - do_diagnostic (pfile, DL_WARNING, 0); + do_diagnostic (pfile, CPP_DL_WARNING, 0); } } - free ((PTR) fname); + free ((void *) fname); } /* Get a token but skip padding. */ static const cpp_token * -get_token_no_padding (pfile) - cpp_reader *pfile; +get_token_no_padding (cpp_reader *pfile) { for (;;) { @@ -1341,8 +1289,7 @@ get_token_no_padding (pfile) /* Check syntax is "(string-literal)". Returns the string on success, or NULL on failure. */ static const cpp_token * -get__Pragma_string (pfile) - cpp_reader *pfile; +get__Pragma_string (cpp_reader *pfile) { const cpp_token *string; @@ -1362,15 +1309,15 @@ get__Pragma_string (pfile) /* Destringize IN into a temporary buffer, by removing the first \ of \" and \\ sequences, and process the result as a #pragma directive. */ static void -destringize_and_run (pfile, in) - cpp_reader *pfile; - const cpp_string *in; +destringize_and_run (cpp_reader *pfile, const cpp_string *in) { const unsigned char *src, *limit; char *dest, *result; - dest = result = alloca (in->len + 1); - for (src = in->text, limit = src + in->len; src < limit;) + dest = result = alloca (in->len - 1); + src = in->text + 1 + (in->text[0] == 'L'); + limit = in->text + in->len - 1; + while (src < limit) { /* We know there is a character following the backslash. */ if (*src == '\\' && (src[1] == '\\' || src[1] == '"')) @@ -1400,7 +1347,6 @@ destringize_and_run (pfile, in) pfile->context = saved_context; pfile->cur_token = saved_cur_token; pfile->cur_run = saved_cur_run; - pfile->line--; } /* See above comment. For the moment, we'd like @@ -1417,34 +1363,31 @@ destringize_and_run (pfile, in) Getting the line markers is a little tricky. */ if (pfile->cb.line_change) - (*pfile->cb.line_change) (pfile, pfile->cur_token, false); + pfile->cb.line_change (pfile, pfile->cur_token, false); } /* Handle the _Pragma operator. */ void -_cpp_do__Pragma (pfile) - cpp_reader *pfile; +_cpp_do__Pragma (cpp_reader *pfile) { const cpp_token *string = get__Pragma_string (pfile); if (string) destringize_and_run (pfile, &string->val.str); else - cpp_error (pfile, DL_ERROR, + cpp_error (pfile, CPP_DL_ERROR, "_Pragma takes a parenthesized string literal"); } -/* Just ignore #sccs on all systems. */ +/* Ignore #sccs on all systems. */ static void -do_sccs (pfile) - cpp_reader *pfile ATTRIBUTE_UNUSED; +do_sccs (cpp_reader *pfile ATTRIBUTE_UNUSED) { } /* Handle #ifdef. */ static void -do_ifdef (pfile) - cpp_reader *pfile; +do_ifdef (cpp_reader *pfile) { int skip = 1; @@ -1465,8 +1408,7 @@ do_ifdef (pfile) /* Handle #ifndef. */ static void -do_ifndef (pfile) - cpp_reader *pfile; +do_ifndef (cpp_reader *pfile) { int skip = 1; const cpp_hashnode *node = 0; @@ -1488,12 +1430,11 @@ do_ifndef (pfile) /* _cpp_parse_expr puts a macro in a "#if !defined ()" expression in pfile->mi_ind_cmacro so we can handle multiple-include - optimisations. If macro expansion occurs in the expression, we + optimizations. If macro expansion occurs in the expression, we cannot treat it as a controlling conditional, since the expansion could change in the future. That is handled by cpp_get_token. */ static void -do_if (pfile) - cpp_reader *pfile; +do_if (cpp_reader *pfile) { int skip = 1; @@ -1507,20 +1448,19 @@ do_if (pfile) if_stack; this is so that the error message for missing #endif's etc. will point to the original #if. */ static void -do_else (pfile) - cpp_reader *pfile; +do_else (cpp_reader *pfile) { cpp_buffer *buffer = pfile->buffer; struct if_stack *ifs = buffer->if_stack; if (ifs == NULL) - cpp_error (pfile, DL_ERROR, "#else without #if"); + cpp_error (pfile, CPP_DL_ERROR, "#else without #if"); else { if (ifs->type == T_ELSE) { - cpp_error (pfile, DL_ERROR, "#else after #else"); - cpp_error_with_line (pfile, DL_ERROR, ifs->line, 0, + 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; @@ -1541,20 +1481,19 @@ do_else (pfile) /* Handle a #elif directive by not changing if_stack either. See the comment above do_else. */ static void -do_elif (pfile) - cpp_reader *pfile; +do_elif (cpp_reader *pfile) { cpp_buffer *buffer = pfile->buffer; struct if_stack *ifs = buffer->if_stack; if (ifs == NULL) - cpp_error (pfile, DL_ERROR, "#elif without #if"); + cpp_error (pfile, CPP_DL_ERROR, "#elif without #if"); else { if (ifs->type == T_ELSE) { - cpp_error (pfile, DL_ERROR, "#elif after #else"); - cpp_error_with_line (pfile, DL_ERROR, ifs->line, 0, + 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; @@ -1577,14 +1516,13 @@ do_elif (pfile) /* #endif pops the if stack and resets pfile->state.skipping. */ static void -do_endif (pfile) - cpp_reader *pfile; +do_endif (cpp_reader *pfile) { cpp_buffer *buffer = pfile->buffer; struct if_stack *ifs = buffer->if_stack; if (ifs == NULL) - cpp_error (pfile, DL_ERROR, "#endif without #if"); + cpp_error (pfile, CPP_DL_ERROR, "#endif without #if"); else { /* Only check EOL if was not originally skipping. */ @@ -1609,11 +1547,8 @@ do_endif (pfile) is #if or #ifndef, CMACRO is a potentially controlling macro, and we need to check here that we are at the top of the file. */ static void -push_conditional (pfile, skip, type, cmacro) - cpp_reader *pfile; - int skip; - int type; - const cpp_hashnode *cmacro; +push_conditional (cpp_reader *pfile, int skip, int type, + const cpp_hashnode *cmacro) { struct if_stack *ifs; cpp_buffer *buffer = pfile->buffer; @@ -1639,10 +1574,7 @@ push_conditional (pfile, skip, type, cmacro) storage, i.e. the #assert case. Returns 0 on success, and sets ANSWERP to point to the answer. */ static int -parse_answer (pfile, answerp, type) - cpp_reader *pfile; - struct answer **answerp; - int type; +parse_answer (cpp_reader *pfile, struct answer **answerp, int type) { const cpp_token *paren; struct answer *answer; @@ -1667,7 +1599,7 @@ parse_answer (pfile, answerp, type) if (type == T_UNASSERT && paren->type == CPP_EOF) return 0; - cpp_error (pfile, DL_ERROR, "missing '(' after predicate"); + cpp_error (pfile, CPP_DL_ERROR, "missing '(' after predicate"); return 1; } @@ -1682,7 +1614,7 @@ parse_answer (pfile, answerp, type) if (token->type == CPP_EOF) { - cpp_error (pfile, DL_ERROR, "missing ')' to complete answer"); + cpp_error (pfile, CPP_DL_ERROR, "missing ')' to complete answer"); return 1; } @@ -1702,7 +1634,7 @@ parse_answer (pfile, answerp, type) if (acount == 0) { - cpp_error (pfile, DL_ERROR, "predicate's answer is empty"); + cpp_error (pfile, CPP_DL_ERROR, "predicate's answer is empty"); return 1; } @@ -1718,10 +1650,7 @@ parse_answer (pfile, answerp, type) the hash node of the predicate, or 0 on error. If an answer was supplied, it is placed in ANSWERP, otherwise it is set to 0. */ static cpp_hashnode * -parse_assertion (pfile, answerp, type) - cpp_reader *pfile; - struct answer **answerp; - int type; +parse_assertion (cpp_reader *pfile, struct answer **answerp, int type) { cpp_hashnode *result = 0; const cpp_token *predicate; @@ -1732,9 +1661,9 @@ parse_assertion (pfile, answerp, type) *answerp = 0; predicate = cpp_get_token (pfile); if (predicate->type == CPP_EOF) - cpp_error (pfile, DL_ERROR, "assertion without predicate"); + cpp_error (pfile, CPP_DL_ERROR, "assertion without predicate"); else if (predicate->type != CPP_NAME) - cpp_error (pfile, DL_ERROR, "predicate must be an identifier"); + cpp_error (pfile, CPP_DL_ERROR, "predicate must be an identifier"); else if (parse_answer (pfile, answerp, type) == 0) { unsigned int len = NODE_LEN (predicate->val.node); @@ -1753,9 +1682,7 @@ parse_assertion (pfile, answerp, type) /* Returns a pointer to the pointer to CANDIDATE in the answer chain, or a pointer to NULL if the answer is not in the chain. */ static struct answer ** -find_answer (node, candidate) - cpp_hashnode *node; - const struct answer *candidate; +find_answer (cpp_hashnode *node, const struct answer *candidate) { unsigned int i; struct answer **result; @@ -1782,9 +1709,7 @@ find_answer (node, candidate) nonzero on failure, zero on success. On success, the result of the test is written into VALUE, otherwise the value 0. */ int -_cpp_test_assertion (pfile, value) - cpp_reader *pfile; - unsigned int *value; +_cpp_test_assertion (cpp_reader *pfile, unsigned int *value) { struct answer *answer; cpp_hashnode *node; @@ -1807,8 +1732,7 @@ _cpp_test_assertion (pfile, value) /* Handle #assert. */ static void -do_assert (pfile) - cpp_reader *pfile; +do_assert (cpp_reader *pfile) { struct answer *new_answer; cpp_hashnode *node; @@ -1823,7 +1747,7 @@ do_assert (pfile) { if (*find_answer (node, new_answer)) { - cpp_error (pfile, DL_WARNING, "\"%s\" re-asserted", + cpp_error (pfile, CPP_DL_WARNING, "\"%s\" re-asserted", NODE_NAME (node) + 1); return; } @@ -1841,8 +1765,7 @@ do_assert (pfile) /* Handle #unassert. */ static void -do_unassert (pfile) - cpp_reader *pfile; +do_unassert (cpp_reader *pfile) { cpp_hashnode *node; struct answer *answer; @@ -1880,9 +1803,7 @@ do_unassert (pfile) If STR has anything after the identifier, then it should be identifier=definition. */ void -cpp_define (pfile, str) - cpp_reader *pfile; - const char *str; +cpp_define (cpp_reader *pfile, const char *str) { char *buf, *p; size_t count; @@ -1892,7 +1813,7 @@ cpp_define (pfile, str) tack " 1" on the end. */ count = strlen (str); - buf = (char *) alloca (count + 3); + buf = alloca (count + 3); memcpy (buf, str, count); p = strchr (str, '='); @@ -1910,9 +1831,7 @@ cpp_define (pfile, str) /* Slight variant of the above for use by initialize_builtins. */ void -_cpp_define_builtin (pfile, str) - cpp_reader *pfile; - const char *str; +_cpp_define_builtin (cpp_reader *pfile, const char *str) { size_t len = strlen (str); char *buf = alloca (len + 1); @@ -1923,9 +1842,7 @@ _cpp_define_builtin (pfile, str) /* Process MACRO as if it appeared as the body of an #undef. */ void -cpp_undef (pfile, macro) - cpp_reader *pfile; - const char *macro; +cpp_undef (cpp_reader *pfile, const char *macro) { size_t len = strlen (macro); char *buf = alloca (len + 1); @@ -1936,35 +1853,28 @@ cpp_undef (pfile, macro) /* Process the string STR as if it appeared as the body of a #assert. */ void -cpp_assert (pfile, str) - cpp_reader *pfile; - const char *str; +cpp_assert (cpp_reader *pfile, const char *str) { handle_assertion (pfile, str, T_ASSERT); } /* Process STR as if it appeared as the body of an #unassert. */ void -cpp_unassert (pfile, str) - cpp_reader *pfile; - const char *str; +cpp_unassert (cpp_reader *pfile, const char *str) { handle_assertion (pfile, str, T_UNASSERT); } /* Common code for cpp_assert (-A) and cpp_unassert (-A-). */ static void -handle_assertion (pfile, str, type) - cpp_reader *pfile; - const char *str; - int type; +handle_assertion (cpp_reader *pfile, const char *str, int type) { size_t count = strlen (str); const char *p = strchr (str, '='); /* Copy the entire option so we can modify it. Change the first "=" in the string to a '(', and tack a ')' on the end. */ - char *buf = (char *) alloca (count + 2); + char *buf = alloca (count + 2); memcpy (buf, str, count); if (p) @@ -1980,41 +1890,28 @@ handle_assertion (pfile, str, type) /* The number of errors for a given reader. */ unsigned int -cpp_errors (pfile) - cpp_reader *pfile; +cpp_errors (cpp_reader *pfile) { return pfile->errors; } /* The options structure. */ cpp_options * -cpp_get_options (pfile) - cpp_reader *pfile; +cpp_get_options (cpp_reader *pfile) { return &pfile->opts; } /* The callbacks structure. */ cpp_callbacks * -cpp_get_callbacks (pfile) - cpp_reader *pfile; +cpp_get_callbacks (cpp_reader *pfile) { return &pfile->cb; } -/* The line map set. */ -const struct line_maps * -cpp_get_line_maps (pfile) - cpp_reader *pfile; -{ - return &pfile->line_maps; -} - /* Copy the given callbacks structure to our own. */ void -cpp_set_callbacks (pfile, cb) - cpp_reader *pfile; - cpp_callbacks *cb; +cpp_set_callbacks (cpp_reader *pfile, cpp_callbacks *cb) { pfile->cb = *cb; } @@ -2023,12 +1920,8 @@ cpp_set_callbacks (pfile, cb) doesn't fail. It does not generate a file change call back; that is the responsibility of the caller. */ cpp_buffer * -cpp_push_buffer (pfile, buffer, len, from_stage3, return_at_eof) - cpp_reader *pfile; - const uchar *buffer; - size_t len; - int from_stage3; - int return_at_eof; +cpp_push_buffer (cpp_reader *pfile, const uchar *buffer, size_t len, + int from_stage3) { cpp_buffer *new = xobnew (&pfile->buffer_ob, cpp_buffer); @@ -2039,27 +1932,26 @@ cpp_push_buffer (pfile, buffer, len, from_stage3, return_at_eof) new->rlimit = buffer + len; new->from_stage3 = from_stage3; new->prev = pfile->buffer; - new->return_at_eof = return_at_eof; new->need_line = true; pfile->buffer = new; + return new; } /* Pops a single buffer, with a file change call-back if appropriate. Then pushes the next -include file, if any remain. */ void -_cpp_pop_buffer (pfile) - cpp_reader *pfile; +_cpp_pop_buffer (cpp_reader *pfile) { cpp_buffer *buffer = pfile->buffer; - struct include_file *inc = buffer->inc; + struct _cpp_file *inc = buffer->file; struct if_stack *ifs; /* Walk back up the conditional stack till we reach its level at entry to this file, issuing error messages. */ for (ifs = buffer->if_stack; ifs; ifs = ifs->next) - cpp_error_with_line (pfile, DL_ERROR, ifs->line, 0, + cpp_error_with_line (pfile, CPP_DL_ERROR, ifs->line, 0, "unterminated #%s", dtable[ifs->type].name); /* In case of a missing #endif. */ @@ -2078,16 +1970,13 @@ _cpp_pop_buffer (pfile) { _cpp_pop_file_buffer (pfile, inc); - /* Don't generate a callback for popping the main file. */ - if (pfile->buffer) - _cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0); + _cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0); } } /* Enter all recognized directives in the hash table. */ void -_cpp_init_directives (pfile) - cpp_reader *pfile; +_cpp_init_directives (cpp_reader *pfile) { unsigned int i; cpp_hashnode *node;