From 15bebb5458d3dfc30d8dd147c0cc74e8a766f7d0 Mon Sep 17 00:00:00 2001 From: borutr Date: Tue, 28 Apr 2009 17:29:31 +0000 Subject: [PATCH] * support/cpp/output.h, support/cpp/opts-common.c, support/cpp/c-ppoutput.c, support/cpp/cppdefault.c, support/cpp/system.h, support/cpp/cppdefault.h, support/cpp/prefix.c, support/cpp/except.h, support/cpp/hwint.h, support/cpp/prefix.h, support/cpp/libiberty/safe-ctype.h, support/cpp/libiberty/filenames.h, support/cpp/libiberty/xstrdup.c, support/cpp/libiberty/md5.c, support/cpp/libiberty/obstack.h, support/cpp/sdcpp.c, support/cpp/intl.h, support/cpp/sdcpp.h support/cpp/libcpp/symtab.c, support/cpp/libcpp/directives.c, support/cpp/libcpp/macro.c, support/cpp/libcpp/include/cpplib.h, support/cpp/libcpp/include/symtab.h, support/cpp/libcpp/include/line-map.h, support/cpp/libcpp/include/cpp-id-data.h, support/cpp/libcpp/include/mkdeps.h, support/cpp/libcpp/files.c, support/cpp/libcpp/line-map.c, support/cpp/libcpp/init.c, support/cpp/libcpp/identifiers.c, support/cpp/libcpp/ucnid.h, support/cpp/libcpp/traditional.c, support/cpp/libcpp/errors.c, support/cpp/libcpp/expr.c, support/cpp/libcpp/internal.h, support/cpp/libcpp/mkdeps.c, support/cpp/libcpp/lex.c, support/cpp/libcpp/system.h, support/cpp/libcpp/charset.c, support/cpp/opts.h, support/cpp/sdcpp-opts.c: SDCPP synchronized with GCC CPP release version 4.4.0 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5444 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 25 ++ support/cpp/c-ppoutput.c | 192 ++++++------ support/cpp/cppdefault.c | 70 ++++- support/cpp/cppdefault.h | 63 ++-- support/cpp/except.h | 80 +++-- support/cpp/hwint.h | 36 +-- support/cpp/intl.h | 11 +- support/cpp/libcpp/charset.c | 162 +++++++--- support/cpp/libcpp/directives.c | 217 +++++++++---- support/cpp/libcpp/errors.c | 89 +++--- support/cpp/libcpp/expr.c | 91 +++++- support/cpp/libcpp/files.c | 46 +-- support/cpp/libcpp/identifiers.c | 35 ++- support/cpp/libcpp/include/cpp-id-data.h | 16 +- support/cpp/libcpp/include/cpplib.h | 101 ++++-- support/cpp/libcpp/include/line-map.h | 29 +- support/cpp/libcpp/include/mkdeps.h | 8 +- support/cpp/libcpp/include/symtab.h | 15 +- support/cpp/libcpp/init.c | 96 +++--- support/cpp/libcpp/internal.h | 35 ++- support/cpp/libcpp/lex.c | 227 ++++++++++++-- support/cpp/libcpp/line-map.c | 19 +- support/cpp/libcpp/macro.c | 139 +++++++-- support/cpp/libcpp/mkdeps.c | 204 ++++++------ support/cpp/libcpp/symtab.c | 214 +++++++------ support/cpp/libcpp/system.h | 11 +- support/cpp/libcpp/traditional.c | 15 +- support/cpp/libcpp/ucnid.h | 8 +- support/cpp/libiberty/filenames.h | 8 + support/cpp/libiberty/md5.c | 89 +++--- support/cpp/libiberty/obstack.h | 376 +++++++++++------------ support/cpp/libiberty/safe-ctype.h | 87 ++++-- support/cpp/libiberty/xstrdup.c | 2 +- support/cpp/opts-common.c | 131 ++++---- support/cpp/opts.h | 50 ++- support/cpp/output.h | 131 ++++---- support/cpp/prefix.c | 151 +++++---- support/cpp/prefix.h | 9 +- support/cpp/sdcpp-opts.c | 176 +++++------ support/cpp/sdcpp.c | 4 +- support/cpp/sdcpp.h | 3 +- support/cpp/system.h | 255 +++++++++------ 42 files changed, 2286 insertions(+), 1440 deletions(-) diff --git a/ChangeLog b/ChangeLog index ad3469f6..00df7cfa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2009-04-27 Borut Razem + + * support/cpp/output.h, support/cpp/opts-common.c, + support/cpp/c-ppoutput.c, support/cpp/cppdefault.c, + support/cpp/system.h, support/cpp/cppdefault.h, + support/cpp/prefix.c, support/cpp/except.h, support/cpp/hwint.h, + support/cpp/prefix.h, support/cpp/libiberty/safe-ctype.h, + support/cpp/libiberty/filenames.h, support/cpp/libiberty/xstrdup.c, + support/cpp/libiberty/md5.c, support/cpp/libiberty/obstack.h, + support/cpp/sdcpp.c, support/cpp/intl.h, support/cpp/sdcpp.h + support/cpp/libcpp/symtab.c, support/cpp/libcpp/directives.c, + support/cpp/libcpp/macro.c, support/cpp/libcpp/include/cpplib.h, + support/cpp/libcpp/include/symtab.h, + support/cpp/libcpp/include/line-map.h, + support/cpp/libcpp/include/cpp-id-data.h, + support/cpp/libcpp/include/mkdeps.h, support/cpp/libcpp/files.c, + support/cpp/libcpp/line-map.c, support/cpp/libcpp/init.c, + support/cpp/libcpp/identifiers.c, support/cpp/libcpp/ucnid.h, + support/cpp/libcpp/traditional.c, support/cpp/libcpp/errors.c, + support/cpp/libcpp/expr.c, support/cpp/libcpp/internal.h, + support/cpp/libcpp/mkdeps.c, support/cpp/libcpp/lex.c, + support/cpp/libcpp/system.h, support/cpp/libcpp/charset.c, + support/cpp/opts.h, support/cpp/sdcpp-opts.c: + SDCPP synchronized with GCC CPP release version 4.4.0 + 2009-04-28 Borut Razem * fixed GCC 4.4.0 mingw compilation: diff --git a/support/cpp/c-ppoutput.c b/support/cpp/c-ppoutput.c index 90855835..29a4f898 100644 --- a/support/cpp/c-ppoutput.c +++ b/support/cpp/c-ppoutput.c @@ -1,21 +1,21 @@ /* Preprocess only, using cpplib. - Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 - Free Software Foundation, Inc. + Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, + 2008 Free Software Foundation, Inc. Written by Per Bothner, 1994-95. -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3, or (at your option) any + later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING3. If not see + . */ #include "config.h" #include "system.h" @@ -26,12 +26,12 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ file. */ static struct { - FILE *outf; /* Stream to write to. */ - const cpp_token *prev; /* Previous token. */ - const cpp_token *source; /* Source token for spacing. */ - int src_line; /* Line number currently being written. */ - unsigned char printed; /* Nonzero if something output at line. */ - bool first_time; /* pp_file_change hasn't been called yet. */ + FILE *outf; /* Stream to write to. */ + const cpp_token *prev; /* Previous token. */ + const cpp_token *source; /* Source token for spacing. */ + int src_line; /* Line number currently being written. */ + unsigned char printed; /* Nonzero if something output at line. */ + bool first_time; /* pp_file_change hasn't been called yet. */ } print; /* General output routines. */ @@ -49,12 +49,12 @@ static void cb_line_change (cpp_reader *, const cpp_token *, int); static void cb_define (cpp_reader *, source_location, cpp_hashnode *); static void cb_undef (cpp_reader *, source_location, cpp_hashnode *); static void cb_include (cpp_reader *, source_location, const unsigned char *, - const char *, int, const cpp_token **); + const char *, int, const cpp_token **); static void cb_ident (cpp_reader *, source_location, const cpp_string *); static void cb_def_pragma (cpp_reader *, source_location); #if 0 static void cb_read_pch (cpp_reader *pfile, const char *name, - int fd, const char *orig_name); + int fd, const char *orig_name); #endif /* Preprocess and output. */ @@ -67,7 +67,7 @@ preprocess_file (cpp_reader *pfile) { /* Scan -included buffers, then the main file. */ while (pfile->buffer->prev) - cpp_scan_nooutput (pfile); + cpp_scan_nooutput (pfile); cpp_scan_nooutput (pfile); } else if (cpp_get_options (pfile)->traditional) @@ -94,12 +94,12 @@ init_pp_output (FILE *out_stream) { cb->line_change = cb_line_change; /* Don't emit #pragma or #ident directives if we are processing - assembly language; the assembler may choke on them. */ + assembly language; the assembler may choke on them. */ if (cpp_get_options (parse_in)->lang != CLK_ASM) - { - cb->ident = cb_ident; - cb->def_pragma = cb_def_pragma; - } + { + cb->ident = cb_ident; + cb->def_pragma = cb_def_pragma; + } } if (flag_dump_includes) @@ -142,31 +142,31 @@ scan_translation_unit (cpp_reader *pfile) const cpp_token *token = cpp_get_token (pfile); if (token->type == CPP_PADDING) - { - avoid_paste = true; - if (print.source == NULL - || (!(print.source->flags & PREV_WHITE) - && token->val.source == NULL)) - print.source = token->val.source; - continue; - } + { + avoid_paste = true; + if (print.source == NULL + || (!(print.source->flags & PREV_WHITE) + && token->val.source == NULL)) + print.source = token->val.source; + continue; + } if (token->type == CPP_EOF) - break; + break; /* Subtle logic to output a space if and only if necessary. */ if (avoid_paste) - { - if (print.source == NULL) - print.source = token; - if (print.source->flags & PREV_WHITE - || (print.prev - && cpp_avoid_paste (pfile, print.prev, token)) - || (print.prev == NULL && token->type == CPP_HASH)) - putc (' ', print.outf); - } + { + if (print.source == NULL) + print.source = token; + if (print.source->flags & PREV_WHITE + || (print.prev + && cpp_avoid_paste (pfile, print.prev, token)) + || (print.prev == NULL && token->type == CPP_HASH)) + putc (' ', print.outf); + } else if (token->flags & PREV_WHITE) - putc (' ', print.outf); + putc (' ', print.outf); avoid_paste = false; print.source = NULL; @@ -174,7 +174,7 @@ scan_translation_unit (cpp_reader *pfile) cpp_output_token (token, print.outf); if (token->type == CPP_COMMENT) - account_for_newlines (token->val.str.text, token->val.str.len); + account_for_newlines (token->val.str.text, token->val.str.len); } } @@ -198,7 +198,7 @@ scan_translation_unit_trad (cpp_reader *pfile) fwrite (pfile->out.base, 1, len, print.outf); print.printed = 1; if (!CPP_OPTION (pfile, discard_comments)) - account_for_newlines (pfile->out.base, len); + account_for_newlines (pfile->out.base, len); } } @@ -208,7 +208,7 @@ scan_translation_unit_trad (cpp_reader *pfile) static void maybe_print_line (source_location src_loc) { - const struct line_map *map = linemap_lookup (&line_table, src_loc); + const struct line_map *map = linemap_lookup (line_table, src_loc); int src_line = SOURCE_LINE (map, src_loc); /* End the previous line of text. */ if (print.printed) @@ -221,10 +221,10 @@ maybe_print_line (source_location src_loc) if (src_line >= print.src_line && src_line < print.src_line + 8) { while (src_line > print.src_line) - { - putc ('\n', print.outf); - print.src_line++; - } + { + putc ('\n', print.outf); + print.src_line++; + } } else print_line (src_loc, ""); @@ -242,7 +242,7 @@ print_line (source_location src_loc, const char *special_flags) if (!flag_no_line_commands) { - const struct line_map *map = linemap_lookup (&line_table, src_loc); + const struct line_map *map = linemap_lookup (line_table, src_loc); size_t to_file_len = strlen (map->to_file); unsigned char *to_file_quoted = @@ -252,18 +252,18 @@ print_line (source_location src_loc, const char *special_flags) print.src_line = SOURCE_LINE (map, src_loc); /* cpp_quote_string does not nul-terminate, so we have to do it - ourselves. */ + ourselves. */ p = cpp_quote_string (to_file_quoted, - (unsigned char *) map->to_file, to_file_len); + (unsigned char *) map->to_file, to_file_len); *p = '\0'; fprintf (print.outf, "# %u \"%s\"%s", - print.src_line == 0 ? 1 : print.src_line, - to_file_quoted, special_flags); + print.src_line == 0 ? 1 : print.src_line, + to_file_quoted, special_flags); if (map->sysp == 2) - fputs (" 3 4", print.outf); + fputs (" 3 4", print.outf); else if (map->sysp == 1) - fputs (" 3", print.outf); + fputs (" 3", print.outf); putc ('\n', print.outf); } @@ -273,7 +273,7 @@ print_line (source_location src_loc, const char *special_flags) of the line, and at end of file will be CPP_EOF. */ static void cb_line_change (cpp_reader *pfile, const cpp_token *token, - int parsing_args) + int parsing_args) { source_location src_loc = token->src_loc; @@ -291,18 +291,18 @@ cb_line_change (cpp_reader *pfile, const cpp_token *token, ought to care. Some things do care; the fault lies with them. */ if (!CPP_OPTION (pfile, traditional)) { - const struct line_map *map = linemap_lookup (&line_table, src_loc); + const struct line_map *map = linemap_lookup (line_table, src_loc); int spaces = SOURCE_COLUMN (map, src_loc) - 2; print.printed = 1; while (-- spaces >= 0) - putc (' ', print.outf); + putc (' ', print.outf); } } static void cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, - const cpp_string *str) + const cpp_string *str) { maybe_print_line (line); fprintf (print.outf, "#ident %s\n", str->text); @@ -318,18 +318,18 @@ cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node) /* 'D' is whole definition; 'N' is name only. */ if (flag_dump_macros == 'D') fputs ((const char *) cpp_macro_definition (pfile, node), - print.outf); + print.outf); else fputs ((const char *) NODE_NAME (node), print.outf); putc ('\n', print.outf); - if (linemap_lookup (&line_table, line)->to_line != 0) + if (linemap_lookup (line_table, line)->to_line != 0) print.src_line++; } static void cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, - cpp_hashnode *node) + cpp_hashnode *node) { maybe_print_line (line); fprintf (print.outf, "#undef %s\n", NODE_NAME (node)); @@ -338,8 +338,8 @@ cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, static void cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, - const unsigned char *dir, const char *header, int angle_brackets, - const cpp_token **comments) + const unsigned char *dir, const char *header, int angle_brackets, + const cpp_token **comments) { maybe_print_line (line); if (angle_brackets) @@ -350,12 +350,12 @@ cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, if (comments != NULL) { while (*comments != NULL) - { - if ((*comments)->flags & PREV_WHITE) - putc (' ', print.outf); - cpp_output_token (*comments, print.outf); - ++comments; - } + { + if ((*comments)->flags & PREV_WHITE) + putc (' ', print.outf); + cpp_output_token (*comments, print.outf); + ++comments; + } } putc ('\n', print.outf); @@ -393,26 +393,26 @@ pp_file_change (const struct line_map *map) if (map != NULL) { if (print.first_time) - { - /* Avoid printing foo.i when the main file is foo.c. */ - if (!cpp_get_options (parse_in)->preprocessed) - print_line (map->start_location, flags); - print.first_time = 0; - } + { + /* Avoid printing foo.i when the main file is foo.c. */ + if (!cpp_get_options (parse_in)->preprocessed) + print_line (map->start_location, flags); + print.first_time = 0; + } else - { - /* Bring current file to correct line when entering a new file. */ - if (map->reason == LC_ENTER) - { - const struct line_map *from = INCLUDED_FROM (&line_table, map); - maybe_print_line (LAST_SOURCE_LINE_LOCATION (from)); - } - if (map->reason == LC_ENTER) - flags = " 1"; - else if (map->reason == LC_LEAVE) - flags = " 2"; - print_line (map->start_location, flags); - } + { + /* Bring current file to correct line when entering a new file. */ + if (map->reason == LC_ENTER) + { + const struct line_map *from = INCLUDED_FROM (line_table, map); + maybe_print_line (LAST_SOURCE_LINE_LOCATION (from)); + } + if (map->reason == LC_ENTER) + flags = " 1"; + else if (map->reason == LC_LEAVE) + flags = " 2"; + print_line (map->start_location, flags); + } } } @@ -434,7 +434,7 @@ dump_macro (cpp_reader *pfile, cpp_hashnode *node, void *v ATTRIBUTE_UNUSED) { fputs ("#define ", print.outf); fputs ((const char *) cpp_macro_definition (pfile, node), - print.outf); + print.outf); putc ('\n', print.outf); print.src_line++; } @@ -449,7 +449,7 @@ dump_macro (cpp_reader *pfile, cpp_hashnode *node, void *v ATTRIBUTE_UNUSED) static void cb_read_pch (cpp_reader *pfile, const char *name, - int fd, const char *orig_name ATTRIBUTE_UNUSED) + int fd, const char *orig_name ATTRIBUTE_UNUSED) { c_common_read_pch (pfile, name, fd, orig_name); diff --git a/support/cpp/cppdefault.c b/support/cpp/cppdefault.c index 283742bf..e8699756 100644 --- a/support/cpp/cppdefault.c +++ b/support/cpp/cppdefault.c @@ -1,23 +1,23 @@ /* CPP Library. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2003, 2004, 2006 Free Software Foundation, Inc. + 1999, 2000, 2003, 2004, 2006, 2007 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 -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3, or (at your option) any + later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING3. If not see + . */ #include "config.h" #include "system.h" @@ -31,7 +31,7 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #define STANDARD_INCLUDE_COMPONENT 0 #endif -#if defined (CROSS_COMPILE) && !defined (TARGET_SYSTEM_ROOT) +#if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT) # undef LOCAL_INCLUDE_DIR # undef SYSTEM_INCLUDE_DIR # undef STANDARD_INCLUDE_DIR @@ -64,9 +64,21 @@ const struct default_include cpp_include_defaults[] { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0 }, #endif #ifdef GCC_INCLUDE_DIR - /* This is the dir for fixincludes and for gcc's private headers. */ + /* This is the dir for gcc's private headers. */ { GCC_INCLUDE_DIR, "GCC", 0, 0, 0, 0 }, #endif +#ifdef FIXED_INCLUDE_DIR + /* This is the dir for fixincludes. */ + { FIXED_INCLUDE_DIR, "GCC", 0, 0, 0, + /* A multilib suffix needs adding if different multilibs use + different headers. */ +#ifdef SYSROOT_HEADERS_SUFFIX_SPEC + 1 +#else + 0 +#endif + }, +#endif #ifdef CROSS_INCLUDE_DIR /* One place the target system's headers might be. */ { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0 }, @@ -94,3 +106,33 @@ const size_t cpp_GCC_INCLUDE_DIR_len = sizeof GCC_INCLUDE_DIR - 8; const char cpp_GCC_INCLUDE_DIR[] = ""; const size_t cpp_GCC_INCLUDE_DIR_len = 0; #endif + +#if 0 +/* The configured prefix. */ +const char cpp_PREFIX[] = PREFIX; +const size_t cpp_PREFIX_len = sizeof PREFIX - 1; +const char cpp_EXEC_PREFIX[] = STANDARD_EXEC_PREFIX; + +/* This value is set by cpp_relocated at runtime */ +const char *gcc_exec_prefix; + +/* Return true if the toolchain is relocated. */ +bool +cpp_relocated (void) +{ + static int relocated = -1; + + /* A relocated toolchain ignores standard include directories. */ + if (relocated == -1) + { + /* Check if the toolchain was relocated? */ + GET_ENVIRONMENT (gcc_exec_prefix, "GCC_EXEC_PREFIX"); + if (gcc_exec_prefix) + relocated = 1; + else + relocated = 0; + } + + return relocated; +} +#endif diff --git a/support/cpp/cppdefault.h b/support/cpp/cppdefault.h index a3a24169..854d4850 100644 --- a/support/cpp/cppdefault.h +++ b/support/cpp/cppdefault.h @@ -1,23 +1,23 @@ /* CPP Library. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2003, 2004, 2006 Free Software Foundation, Inc. + 1999, 2000, 2003, 2004, 2006, 2007 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 -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3, or (at your option) any + later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING3. If not see + . */ #ifndef GCC_CPPDEFAULT_H #define GCC_CPPDEFAULT_H @@ -34,22 +34,37 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ struct default_include { - const char *const fname; /* The name of the directory. */ - const char *const component; /* The component containing the directory - (see update_path in prefix.c) */ - const char cplusplus; /* Only look here if we're compiling C++. */ - const char cxx_aware; /* Includes in this directory don't need to - be wrapped in extern "C" when compiling - C++. */ - const char add_sysroot; /* FNAME should be prefixed by - cpp_SYSROOT. */ - const char multilib; /* FNAME should have the multilib path - specified with -imultilib - appended. */ + const char *const fname; /* The name of the directory. */ + const char *const component; /* The component containing the directory + (see update_path in prefix.c) */ + const char cplusplus; /* Only look here if we're compiling C++. */ + const char cxx_aware; /* Includes in this directory don't need to + be wrapped in extern "C" when compiling + C++. */ + const char add_sysroot; /* FNAME should be prefixed by + cpp_SYSROOT. */ + const char multilib; /* FNAME should have the multilib path + specified with -imultilib + appended. */ }; extern const struct default_include cpp_include_defaults[]; extern const char cpp_GCC_INCLUDE_DIR[]; extern const size_t cpp_GCC_INCLUDE_DIR_len; +/* The configure-time prefix, i.e., the value supplied as the argument + to --prefix=. */ +extern const char cpp_PREFIX[]; +/* The length of the configure-time prefix. */ +extern const size_t cpp_PREFIX_len; +/* The configure-time execution prefix. This is typically the lib/gcc + subdirectory of cpp_PREFIX. */ +extern const char cpp_EXEC_PREFIX[]; +/* The run-time execution prefix. This is typically the lib/gcc + subdirectory of the actual installation. */ +extern const char *gcc_exec_prefix; + +/* Return true if the toolchain is relocated. */ +bool cpp_relocated (void); + #endif /* ! GCC_CPPDEFAULT_H */ diff --git a/support/cpp/except.h b/support/cpp/except.h index 1f96477f..c893d884 100644 --- a/support/cpp/except.h +++ b/support/cpp/except.h @@ -1,13 +1,13 @@ /* Exception Handling interface routines. - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, + 2007, 2008 Free Software Foundation, Inc. Contributed by Mike Stump . This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later +Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY @@ -16,9 +16,8 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ +along with GCC; see the file COPYING3. If not see +. */ struct function; @@ -36,7 +35,6 @@ extern int doing_eh (int); /* Note that the current EH region (if any) may contain a throw, or a call to a function which itself may contain a throw. */ extern void note_eh_region_may_contain_throw (struct eh_region *); -extern void note_current_region_may_contain_throw (void); /* Invokes CALLBACK for every exception handler label. Only used by old loop hackery; should not be used by new code. */ @@ -47,9 +45,9 @@ extern void for_each_eh_region (void (*) (struct eh_region *)); /* Determine if the given INSN can throw an exception. */ extern bool can_throw_internal_1 (int, bool); -extern bool can_throw_internal (rtx); +extern bool can_throw_internal (const_rtx); extern bool can_throw_external_1 (int, bool); -extern bool can_throw_external (rtx); +extern bool can_throw_external (const_rtx); /* Set TREE_NOTHROW and cfun->all_throwers_are_sibcalls. */ extern unsigned int set_nothrow_function_flags (void); @@ -68,7 +66,7 @@ extern void convert_from_eh_region_ranges (void); extern unsigned int convert_to_eh_region_ranges (void); extern void find_exception_handler_labels (void); extern bool current_function_has_exception_handlers (void); -extern void output_function_exception_table (void); +extern void output_function_exception_table (const char *); extern void expand_builtin_unwind_init (void); extern rtx expand_builtin_eh_return_data_regno (tree); @@ -79,17 +77,17 @@ extern rtx expand_builtin_dwarf_sp_column (void); extern void expand_builtin_eh_return (tree, tree); extern void expand_eh_return (void); extern rtx expand_builtin_extend_pointer (tree); -extern rtx get_exception_pointer (struct function *); -extern rtx get_exception_filter (struct function *); +extern rtx get_exception_pointer (void); +extern rtx get_exception_filter (void); typedef tree (*duplicate_eh_regions_map) (tree, void *); extern int duplicate_eh_regions (struct function *, duplicate_eh_regions_map, - void *, int, int); + void *, int, int); extern void sjlj_emit_function_exit_after (rtx); extern void default_init_unwind_resume_libfunc (void); extern struct eh_region *gen_eh_region_cleanup (struct eh_region *, - struct eh_region *); + struct eh_region *); extern struct eh_region *gen_eh_region_try (struct eh_region *); extern struct eh_region *gen_eh_region_catch (struct eh_region *, tree); extern struct eh_region *gen_eh_region_allowed (struct eh_region *, tree); @@ -100,8 +98,8 @@ extern tree get_eh_region_tree_label (struct eh_region *); extern void set_eh_region_tree_label (struct eh_region *, tree); extern void foreach_reachable_handler (int, bool, - void (*) (struct eh_region *, void *), - void *); + void (*) (struct eh_region *, void *), + void *); extern void collect_eh_region_array (void); extern void expand_resx_expr (tree); @@ -110,20 +108,13 @@ extern void dump_eh_tree (FILE *, struct function *); extern bool eh_region_outer_p (struct function *, int, int); extern int eh_region_outermost (struct function *, int, int); -/* tree-eh.c */ -extern void add_stmt_to_eh_region_fn (struct function *, tree, int); -extern bool remove_stmt_from_eh_region_fn (struct function *, tree); -extern int lookup_stmt_eh_region_fn (struct function *, tree); -extern int lookup_stmt_eh_region (tree); -extern bool verify_eh_edges (tree); - /* If non-NULL, this is a function that returns an expression to be executed if an unhandled exception is propagated out of a cleanup region. For example, in C++, an exception thrown by a destructor during stack unwinding is required to result in a call to `std::terminate', so the C++ version of this function returns a CALL_EXPR for `std::terminate'. */ -extern tree (*lang_protect_cleanup_actions) (void); +extern gimple (*lang_protect_cleanup_actions) (void); /* Return true if type A catches type B. */ extern int (*lang_eh_type_covers) (tree a, tree b); @@ -137,46 +128,49 @@ extern tree (*lang_eh_runtime_type) (tree); has appropriate support. */ #ifndef MUST_USE_SJLJ_EXCEPTIONS -# if !(defined (EH_RETURN_DATA_REGNO) \ - && (defined (TARGET_UNWIND_INFO) \ - || (DWARF2_UNWIND_INFO \ - && (defined (EH_RETURN_HANDLER_RTX) \ - || defined (HAVE_eh_return))))) -# define MUST_USE_SJLJ_EXCEPTIONS 1 +# if defined (EH_RETURN_DATA_REGNO) \ + && (defined (TARGET_UNWIND_INFO) \ + || (DWARF2_UNWIND_INFO \ + && (defined (EH_RETURN_HANDLER_RTX) \ + || defined (HAVE_eh_return)))) +# define MUST_USE_SJLJ_EXCEPTIONS 0 # else -# define MUST_USE_SJLJ_EXCEPTIONS 0 +# define MUST_USE_SJLJ_EXCEPTIONS 1 # endif #endif #ifdef CONFIG_SJLJ_EXCEPTIONS # if CONFIG_SJLJ_EXCEPTIONS == 1 -# define USING_SJLJ_EXCEPTIONS 1 +# define USING_SJLJ_EXCEPTIONS 1 # endif # if CONFIG_SJLJ_EXCEPTIONS == 0 -# define USING_SJLJ_EXCEPTIONS 0 -# ifndef EH_RETURN_DATA_REGNO +# define USING_SJLJ_EXCEPTIONS 0 +# if !defined(EH_RETURN_DATA_REGNO) #error "EH_RETURN_DATA_REGNO required" # endif -# if !defined(EH_RETURN_HANDLER_RTX) && !defined(HAVE_eh_return) +# if ! (defined(TARGET_UNWIND_INFO) || DWARF2_UNWIND_INFO) + #error "{DWARF2,TARGET}_UNWIND_INFO required" +# endif +# if !defined(TARGET_UNWIND_INFO) \ + && !(defined(EH_RETURN_HANDLER_RTX) || defined(HAVE_eh_return)) #error "EH_RETURN_HANDLER_RTX or eh_return required" # endif -# if !defined(DWARF2_UNWIND_INFO) && !defined(TARGET_UNWIND_INFO) - #error "{DWARF2,TARGET}_UNWIND_INFO required" +/* Usually the above error checks will have already triggered an + error, but backends may set MUST_USE_SJLJ_EXCEPTIONS for their own + reasons. */ +# if MUST_USE_SJLJ_EXCEPTIONS + #error "Must use SJLJ exceptions but configured not to" # endif # endif #else -# define USING_SJLJ_EXCEPTIONS MUST_USE_SJLJ_EXCEPTIONS +# define USING_SJLJ_EXCEPTIONS MUST_USE_SJLJ_EXCEPTIONS #endif struct throw_stmt_node GTY(()) { - tree stmt; + gimple stmt; int region_nr; }; extern struct htab *get_eh_throw_stmt_table (struct function *); extern void set_eh_throw_stmt_table (struct function *, struct htab *); - -#ifdef ENABLE_CHECKING -extern void verify_eh_throw_table_statements (void); -#endif diff --git a/support/cpp/hwint.h b/support/cpp/hwint.h index 9b28a3ad..4f6d02d3 100644 --- a/support/cpp/hwint.h +++ b/support/cpp/hwint.h @@ -1,5 +1,5 @@ /* HOST_WIDE_INT definitions for the GNU compiler. - Copyright (C) 1998, 2002, 2004 Free Software Foundation, Inc. + Copyright (C) 1998, 2002, 2004, 2008 Free Software Foundation, Inc. This file is part of GCC. @@ -17,7 +17,7 @@ /* The string that should be inserted into a printf style format to indicate a "long long" operand. */ -#ifndef HOST_LONG_LONG_FORMAT +#ifndef HOST_LONG_LONG_FORMAT #define HOST_LONG_LONG_FORMAT "ll" #endif @@ -97,29 +97,29 @@ extern char sizeof_long_long_must_be_8[sizeof(long long) == 8 ? 1 : -1]; #if HOST_BITS_PER_WIDE_INT >= 64 \ || (HOST_BITS_PER_LONGLONG < 64 && HOST_BITS_PER___INT64 < 64) -# define HOST_WIDEST_INT HOST_WIDE_INT -# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_WIDE_INT -# define HOST_WIDEST_INT_PRINT_DEC HOST_WIDE_INT_PRINT_DEC -# define HOST_WIDEST_INT_PRINT_DEC_C HOST_WIDE_INT_PRINT_DEC_C -# define HOST_WIDEST_INT_PRINT_UNSIGNED HOST_WIDE_INT_PRINT_UNSIGNED -# define HOST_WIDEST_INT_PRINT_HEX HOST_WIDE_INT_PRINT_HEX +# define HOST_WIDEST_INT HOST_WIDE_INT +# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_WIDE_INT +# define HOST_WIDEST_INT_PRINT_DEC HOST_WIDE_INT_PRINT_DEC +# define HOST_WIDEST_INT_PRINT_DEC_C HOST_WIDE_INT_PRINT_DEC_C +# define HOST_WIDEST_INT_PRINT_UNSIGNED HOST_WIDE_INT_PRINT_UNSIGNED +# define HOST_WIDEST_INT_PRINT_HEX HOST_WIDE_INT_PRINT_HEX # define HOST_WIDEST_INT_PRINT_DOUBLE_HEX HOST_WIDE_INT_PRINT_DOUBLE_HEX #else # if HOST_BITS_PER_LONGLONG >= 64 -# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG -# define HOST_WIDEST_INT long long +# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG +# define HOST_WIDEST_INT long long # else # if HOST_BITS_PER___INT64 >= 64 -# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER___INT64 -# define HOST_WIDEST_INT __int64 +# define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER___INT64 +# define HOST_WIDEST_INT __int64 # else #error "This line should be impossible to reach" # endif # endif -# define HOST_WIDEST_INT_PRINT_DEC "%" HOST_LONG_LONG_FORMAT "d" -# define HOST_WIDEST_INT_PRINT_DEC_C "%" HOST_LONG_LONG_FORMAT "dLL" -# define HOST_WIDEST_INT_PRINT_UNSIGNED "%" HOST_LONG_LONG_FORMAT "u" -# define HOST_WIDEST_INT_PRINT_HEX "0x%" HOST_LONG_LONG_FORMAT "x" +# define HOST_WIDEST_INT_PRINT_DEC "%" HOST_LONG_LONG_FORMAT "d" +# define HOST_WIDEST_INT_PRINT_DEC_C "%" HOST_LONG_LONG_FORMAT "dLL" +# define HOST_WIDEST_INT_PRINT_UNSIGNED "%" HOST_LONG_LONG_FORMAT "u" +# define HOST_WIDEST_INT_PRINT_HEX "0x%" HOST_LONG_LONG_FORMAT "x" # define HOST_WIDEST_INT_PRINT_DOUBLE_HEX \ "0x%" HOST_LONG_LONG_FORMAT "x%016" HOST_LONG_LONG_FORMAT "x" #endif @@ -128,7 +128,7 @@ extern char sizeof_long_long_must_be_8[sizeof(long long) == 8 ? 1 : -1]; efficiently in hardware. (That is, the widest integer type that fits in a hardware register.) Normally this is "long" but on some hosts it should be "long long" or "__int64". This is no convenient way to - autodect this, so such systems must set a flag in config.host; see there + autodetect this, so such systems must set a flag in config.host; see there for details. */ #ifdef USE_LONG_LONG_FOR_WIDEST_FAST_INT @@ -139,7 +139,7 @@ extern char sizeof_long_long_must_be_8[sizeof(long long) == 8 ? 1 : -1]; # define HOST_WIDEST_FAST_INT __int64 # define HOST_BITS_PER_WIDEST_FAST_INT HOST_BITS_PER___INT64 # else -# error "Your host said it wantted to use long long or __int64 but neither" +# error "Your host said it wanted to use long long or __int64 but neither" # error "exist" # endif #else diff --git a/support/cpp/intl.h b/support/cpp/intl.h index a118c0a9..8c0684ad 100644 --- a/support/cpp/intl.h +++ b/support/cpp/intl.h @@ -1,9 +1,9 @@ /* intl.h - internationalization - Copyright 1998, 2001, 2003, 2004 Free Software Foundation, Inc. + Copyright 1998, 2001, 2003, 2004, 2007 Free Software Foundation, Inc. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) + the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, @@ -12,9 +12,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with GCC; see the file COPYING. If not, write to the Free - Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + along with GCC; see the file COPYING3. If not see + . */ #ifndef GCC_INTL_H #define GCC_INTL_H @@ -39,7 +38,7 @@ extern size_t gcc_gettext_width (const char *); # define bindtextdomain(domain, directory) (domain) # undef gettext # define gettext(msgid) (msgid) -# define gcc_init_libintl() /* nothing */ +# define gcc_init_libintl() /* nothing */ # define gcc_gettext_width(s) strlen(s) #endif diff --git a/support/cpp/libcpp/charset.c b/support/cpp/libcpp/charset.c index 847c8b1b..45d0148f 100644 --- a/support/cpp/libcpp/charset.c +++ b/support/cpp/libcpp/charset.c @@ -1,12 +1,12 @@ /* CPP Library - charsets - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2008, 2009 Free Software Foundation, Inc. Broken out of c-lex.c Apr 2003, adding valid C99 UCN ranges. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +along with this program; see the file COPYING3. If not see +. */ #include "config.h" #include "system.h" @@ -642,6 +642,7 @@ init_iconv_desc (cpp_reader *pfile, const char *to, const char *from) { ret.func = convert_no_conversion; ret.cd = (iconv_t) -1; + ret.width = -1; return ret; } @@ -655,6 +656,7 @@ init_iconv_desc (cpp_reader *pfile, const char *to, const char *from) { ret.func = conversion_tab[i].func; ret.cd = conversion_tab[i].fake_cd; + ret.width = -1; return ret; } @@ -663,6 +665,7 @@ init_iconv_desc (cpp_reader *pfile, const char *to, const char *from) { ret.func = convert_using_iconv; ret.cd = iconv_open (to, from); + ret.width = -1; if (ret.cd == (iconv_t) -1) { @@ -683,6 +686,7 @@ init_iconv_desc (cpp_reader *pfile, const char *to, const char *from) from, to); ret.func = convert_no_conversion; ret.cd = (iconv_t) -1; + ret.width = -1; } return ret; } @@ -716,7 +720,17 @@ cpp_init_iconv (cpp_reader *pfile) wcset = default_wcset; pfile->narrow_cset_desc = init_iconv_desc (pfile, ncset, SOURCE_CHARSET); + pfile->narrow_cset_desc.width = CPP_OPTION (pfile, char_precision); + pfile->char16_cset_desc = init_iconv_desc (pfile, + be ? "UTF-16BE" : "UTF-16LE", + SOURCE_CHARSET); + pfile->char16_cset_desc.width = 16; + pfile->char32_cset_desc = init_iconv_desc (pfile, + be ? "UTF-32BE" : "UTF-32LE", + SOURCE_CHARSET); + pfile->char32_cset_desc.width = 32; pfile->wide_cset_desc = init_iconv_desc (pfile, wcset, SOURCE_CHARSET); + pfile->wide_cset_desc.width = CPP_OPTION (pfile, wchar_precision); } /* Destroy iconv(3) descriptors set up by cpp_init_iconv, if necessary. */ @@ -1051,15 +1065,13 @@ _cpp_valid_ucn (cpp_reader *pfile, const uchar **pstr, An advanced pointer is returned. Issues all relevant diagnostics. */ static const uchar * convert_ucn (cpp_reader *pfile, const uchar *from, const uchar *limit, - struct _cpp_strbuf *tbuf, bool wide) + struct _cpp_strbuf *tbuf, struct cset_converter cvt) { cppchar_t ucn; uchar buf[6]; uchar *bufp = buf; size_t bytesleft = 6; int rval; - struct cset_converter cvt - = wide ? pfile->wide_cset_desc : pfile->narrow_cset_desc; struct normalize_state nst = INITIAL_NORMALIZE_STATE; from++; /* Skip u/U. */ @@ -1086,14 +1098,15 @@ convert_ucn (cpp_reader *pfile, const uchar *from, const uchar *limit, function issues no diagnostics and never fails. */ static void emit_numeric_escape (cpp_reader *pfile, cppchar_t n, - struct _cpp_strbuf *tbuf, bool wide) + struct _cpp_strbuf *tbuf, struct cset_converter cvt) { - if (wide) + size_t width = cvt.width; + + if (width != CPP_OPTION (pfile, char_precision)) { /* We have to render this into the target byte order, which may not be our byte order. */ bool bigend = CPP_OPTION (pfile, bytes_big_endian); - size_t width = CPP_OPTION (pfile, wchar_precision); size_t cwidth = CPP_OPTION (pfile, char_precision); size_t cmask = width_to_mask (cwidth); size_t nbwc = width / cwidth; @@ -1136,12 +1149,11 @@ emit_numeric_escape (cpp_reader *pfile, cppchar_t n, number. You can, e.g. generate surrogate pairs this way. */ static const uchar * convert_hex (cpp_reader *pfile, const uchar *from, const uchar *limit, - struct _cpp_strbuf *tbuf, bool wide) + struct _cpp_strbuf *tbuf, struct cset_converter cvt) { cppchar_t c, n = 0, overflow = 0; int digits_found = 0; - size_t width = (wide ? CPP_OPTION (pfile, wchar_precision) - : CPP_OPTION (pfile, char_precision)); + size_t width = cvt.width; size_t mask = width_to_mask (width); if (CPP_WTRADITIONAL (pfile)) @@ -1174,7 +1186,7 @@ convert_hex (cpp_reader *pfile, const uchar *from, const uchar *limit, n &= mask; } - emit_numeric_escape (pfile, n, tbuf, wide); + emit_numeric_escape (pfile, n, tbuf, cvt); return from; } @@ -1187,12 +1199,11 @@ convert_hex (cpp_reader *pfile, const uchar *from, const uchar *limit, number. */ static const uchar * convert_oct (cpp_reader *pfile, const uchar *from, const uchar *limit, - struct _cpp_strbuf *tbuf, bool wide) + struct _cpp_strbuf *tbuf, struct cset_converter cvt) { size_t count = 0; cppchar_t c, n = 0; - size_t width = (wide ? CPP_OPTION (pfile, wchar_precision) - : CPP_OPTION (pfile, char_precision)); + size_t width = cvt.width; size_t mask = width_to_mask (width); bool overflow = false; @@ -1213,7 +1224,7 @@ convert_oct (cpp_reader *pfile, const uchar *from, const uchar *limit, n &= mask; } - emit_numeric_escape (pfile, n, tbuf, wide); + emit_numeric_escape (pfile, n, tbuf, cvt); return from; } @@ -1224,7 +1235,7 @@ convert_oct (cpp_reader *pfile, const uchar *from, const uchar *limit, pointer. Handles all relevant diagnostics. */ static const uchar * convert_escape (cpp_reader *pfile, const uchar *from, const uchar *limit, - struct _cpp_strbuf *tbuf, bool wide) + struct _cpp_strbuf *tbuf, struct cset_converter cvt) { /* Values of \a \b \e \f \n \r \t \v respectively. */ #if HOST_CHARSET == HOST_CHARSET_ASCII @@ -1236,23 +1247,21 @@ convert_escape (cpp_reader *pfile, const uchar *from, const uchar *limit, #endif uchar c; - struct cset_converter cvt - = wide ? pfile->wide_cset_desc : pfile->narrow_cset_desc; c = *from; switch (c) { /* UCNs, hex escapes, and octal escapes are processed separately. */ case 'u': case 'U': - return convert_ucn (pfile, from, limit, tbuf, wide); + return convert_ucn (pfile, from, limit, tbuf, cvt); case 'x': - return convert_hex (pfile, from, limit, tbuf, wide); + return convert_hex (pfile, from, limit, tbuf, cvt); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': - return convert_oct (pfile, from, limit, tbuf, wide); + return convert_oct (pfile, from, limit, tbuf, cvt); /* Various letter escapes. Get the appropriate host-charset value into C. */ @@ -1312,6 +1321,27 @@ convert_escape (cpp_reader *pfile, const uchar *from, const uchar *limit, return from + 1; } +/* TYPE is a token type. The return value is the conversion needed to + convert from source to execution character set for the given type. */ +static struct cset_converter +converter_for_type (cpp_reader *pfile, enum cpp_ttype type) +{ + switch (type) + { + default: + return pfile->narrow_cset_desc; + case CPP_CHAR16: + case CPP_STRING16: + return pfile->char16_cset_desc; + case CPP_CHAR32: + case CPP_STRING32: + return pfile->char32_cset_desc; + case CPP_WCHAR: + case CPP_WSTRING: + return pfile->wide_cset_desc; + } +} + /* FROM is an array of cpp_string structures of length COUNT. These are to be converted from the source to the execution character set, escape sequences translated, and finally all are to be @@ -1320,13 +1350,12 @@ convert_escape (cpp_reader *pfile, const uchar *from, const uchar *limit, false for failure. */ bool cpp_interpret_string (cpp_reader *pfile, const cpp_string *from, size_t count, - cpp_string *to, bool wide) + cpp_string *to, enum cpp_ttype type) { struct _cpp_strbuf tbuf; const uchar *p, *base, *limit; size_t i; - struct cset_converter cvt - = wide ? pfile->wide_cset_desc : pfile->narrow_cset_desc; + struct cset_converter cvt = converter_for_type (pfile, type); tbuf.asize = MAX (OUTBUF_BLOCK_SIZE, from->len); tbuf.text = XNEWVEC (uchar, tbuf.asize); @@ -1335,7 +1364,7 @@ cpp_interpret_string (cpp_reader *pfile, const cpp_string *from, size_t count, for (i = 0; i < count; i++) { p = from[i].text; - if (*p == 'L') p++; + if (*p == 'L' || *p == 'u' || *p == 'U') p++; p++; /* Skip leading quote. */ limit = from[i].text + from[i].len - 1; /* Skip trailing quote. */ @@ -1354,12 +1383,12 @@ cpp_interpret_string (cpp_reader *pfile, const cpp_string *from, size_t count, if (p == limit) break; - p = convert_escape (pfile, p + 1, limit, &tbuf, wide); + p = convert_escape (pfile, p + 1, limit, &tbuf, cvt); } } /* NUL-terminate the 'to' buffer and translate it to a cpp_string structure. */ - emit_numeric_escape (pfile, 0, &tbuf, wide); + emit_numeric_escape (pfile, 0, &tbuf, cvt); tbuf.text = XRESIZEVEC (uchar, tbuf.text, tbuf.len); to->text = tbuf.text; to->len = tbuf.len; @@ -1375,15 +1404,17 @@ cpp_interpret_string (cpp_reader *pfile, const cpp_string *from, size_t count, in a string, but do not perform character set conversion. */ bool cpp_interpret_string_notranslate (cpp_reader *pfile, const cpp_string *from, - size_t count, cpp_string *to, bool wide) + size_t count, cpp_string *to, + enum cpp_ttype type ATTRIBUTE_UNUSED) { struct cset_converter save_narrow_cset_desc = pfile->narrow_cset_desc; bool retval; pfile->narrow_cset_desc.func = convert_no_conversion; pfile->narrow_cset_desc.cd = (iconv_t) -1; + pfile->narrow_cset_desc.width = CPP_OPTION (pfile, char_precision); - retval = cpp_interpret_string (pfile, from, count, to, wide); + retval = cpp_interpret_string (pfile, from, count, to, CPP_STRING); pfile->narrow_cset_desc = save_narrow_cset_desc; return retval; @@ -1462,13 +1493,14 @@ narrow_str_to_charconst (cpp_reader *pfile, cpp_string str, /* Subroutine of cpp_interpret_charconst which performs the conversion to a number, for wide strings. STR is the string structure returned by cpp_interpret_string. PCHARS_SEEN and UNSIGNEDP are as for - cpp_interpret_charconst. */ + cpp_interpret_charconst. TYPE is the token type. */ static cppchar_t wide_str_to_charconst (cpp_reader *pfile, cpp_string str, - unsigned int *pchars_seen, int *unsignedp) + unsigned int *pchars_seen, int *unsignedp, + enum cpp_ttype type) { bool bigend = CPP_OPTION (pfile, bytes_big_endian); - size_t width = CPP_OPTION (pfile, wchar_precision); + size_t width = converter_for_type (pfile, type).width; size_t cwidth = CPP_OPTION (pfile, char_precision); size_t mask = width_to_mask (width); size_t cmask = width_to_mask (cwidth); @@ -1490,7 +1522,7 @@ wide_str_to_charconst (cpp_reader *pfile, cpp_string str, /* Wide character constants have type wchar_t, and a single character exactly fills a wchar_t, so a multi-character wide character constant is guaranteed to overflow. */ - if (off > 0) + if (str.len > nbwc * 2) cpp_error (pfile, CPP_DL_WARNING, "character constant too long for its type"); @@ -1498,13 +1530,20 @@ wide_str_to_charconst (cpp_reader *pfile, cpp_string str, sign- or zero-extend to the full width of cppchar_t. */ if (width < BITS_PER_CPPCHAR_T) { - if (CPP_OPTION (pfile, unsigned_wchar) || !(result & (1 << (width - 1)))) + if (type == CPP_CHAR16 || type == CPP_CHAR32 + || CPP_OPTION (pfile, unsigned_wchar) + || !(result & (1 << (width - 1)))) result &= mask; else result |= ~mask; } - *unsignedp = CPP_OPTION (pfile, unsigned_wchar); + if (type == CPP_CHAR16 || type == CPP_CHAR32 + || CPP_OPTION (pfile, unsigned_wchar)) + *unsignedp = 1; + else + *unsignedp = 0; + *pchars_seen = 1; return result; } @@ -1518,20 +1557,21 @@ cpp_interpret_charconst (cpp_reader *pfile, const cpp_token *token, unsigned int *pchars_seen, int *unsignedp) { cpp_string str = { 0, 0 }; - bool wide = (token->type == CPP_WCHAR); + bool wide = (token->type != CPP_CHAR); cppchar_t result; - /* an empty constant will appear as L'' or '' */ + /* an empty constant will appear as L'', u'', U'' or '' */ if (token->val.str.len == (size_t) (2 + wide)) { cpp_error (pfile, CPP_DL_ERROR, "empty character constant"); return 0; } - else if (!cpp_interpret_string (pfile, &token->val.str, 1, &str, wide)) + else if (!cpp_interpret_string (pfile, &token->val.str, 1, &str, token->type)) return 0; if (wide) - result = wide_str_to_charconst (pfile, str, pchars_seen, unsignedp); + result = wide_str_to_charconst (pfile, str, pchars_seen, unsignedp, + token->type); else result = narrow_str_to_charconst (pfile, str, pchars_seen, unsignedp); @@ -1598,18 +1638,24 @@ _cpp_interpret_identifier (cpp_reader *pfile, const uchar *id, size_t len) source file) from INPUT_CHARSET to the source character set. INPUT points to the input buffer, SIZE is its allocated size, and LEN is the length of the meaningful data within the buffer. The - translated buffer is returned, and *ST_SIZE is set to the length of - the meaningful data within the translated buffer. - - INPUT is expected to have been allocated with xmalloc. This function - will either return INPUT, or free it and return a pointer to another - xmalloc-allocated block of memory. */ + translated buffer is returned, *ST_SIZE is set to the length of + the meaningful data within the translated buffer, and *BUFFER_START + is set to the start of the returned buffer. *BUFFER_START may + differ from the return value in the case of a BOM or other ignored + marker information. + + INPUT is expected to have been allocated with xmalloc. This + function will either set *BUFFER_START to INPUT, or free it and set + *BUFFER_START to a pointer to another xmalloc-allocated block of + memory. */ uchar * _cpp_convert_input (cpp_reader *pfile, const char *input_charset, - uchar *input, size_t size, size_t len, off_t *st_size) + uchar *input, size_t size, size_t len, + const unsigned char **buffer_start, off_t *st_size) { struct cset_converter input_cset; struct _cpp_strbuf to; + unsigned char *buffer; input_cset = init_iconv_desc (pfile, SOURCE_CHARSET, input_charset); if (input_cset.func == convert_no_conversion) @@ -1650,8 +1696,24 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset, else to.text[to.len] = '\n'; + buffer = to.text; *st_size = to.len; - return to.text; +#if HOST_CHARSET == HOST_CHARSET_ASCII + /* The HOST_CHARSET test just above ensures that the source charset + is UTF-8. So, ignore a UTF-8 BOM if we see one. Note that + glib'c UTF-8 iconv() provider (as of glibc 2.7) does not ignore a + BOM -- however, even if it did, we would still need this code due + to the 'convert_no_conversion' case. */ + if (to.len >= 3 && to.text[0] == 0xef && to.text[1] == 0xbb + && to.text[2] == 0xbf) + { + *st_size -= 3; + buffer += 3; + } +#endif + + *buffer_start = to.text; + return buffer; } /* Decide on the default encoding to assume for input files. */ diff --git a/support/cpp/libcpp/directives.c b/support/cpp/libcpp/directives.c index 89bf6104..13daba97 100644 --- a/support/cpp/libcpp/directives.c +++ b/support/cpp/libcpp/directives.c @@ -1,14 +1,14 @@ /* CPP Library. (Directive handling.) Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2007, 2008 Free Software Foundation, Inc. + 2007, 2008, 2009 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 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +along with this program; see the file COPYING3. If not see +. */ #include "config.h" #include "system.h" @@ -32,7 +32,7 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ struct if_stack { struct if_stack *next; - unsigned int 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. */ @@ -75,6 +75,7 @@ struct pragma_entry #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 *); @@ -101,7 +102,7 @@ static char *glue_header_name (cpp_reader *); static const char *parse_include (cpp_reader *, int *, const cpp_token ***); 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 bool strtolinenum (const uchar *, size_t, linenum_type *, bool *); static void do_diagnostic (cpp_reader *, int, int); static cpp_hashnode *lex_macro_node (cpp_reader *, bool); static int undefine_macros (cpp_reader *, cpp_hashnode *, void *); @@ -130,9 +131,9 @@ static void handle_assertion (cpp_reader *, const char *, int); counts from all the source code I have lying around (egcs and libc CVS as of 1999-05-18, plus grub-0.5.91, linux-2.2.9, and pcmcia-cs-3.0.9). This is no longer important as directive lookup - is now O(1). All extensions other than #warning and #include_next - are deprecated. The name is where the extension appears to have - come from. */ + is now O(1). All extensions other than #warning, #include_next, + 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 */ \ @@ -149,11 +150,11 @@ 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) /* 11 */ \ +D(ident, T_IDENT, EXTENSION, IN_I | DEPRECATED) /* 11 */ \ D(import, T_IMPORT, EXTENSION, INCL | EXPAND) /* 0 ObjC */ \ -D(assert, T_ASSERT, EXTENSION, 0) /* 0 SVR4 */ \ -D(unassert, T_UNASSERT, EXTENSION, 0) /* 0 SVR4 */ \ -D(sccs, T_SCCS, EXTENSION, IN_I) /* 0 SVR4? */ +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 @@ -188,7 +189,7 @@ DIRECTIVE_TABLE did use this notation in its preprocessed output. */ static const directive linemarker_dir = { - do_linemarker, U"#", 1, KANDR, IN_I + do_linemarker, UC"#", 1, KANDR, IN_I }; #define SEEN_EOL() (pfile->cur_token[-1].type == CPP_EOF) @@ -337,11 +338,20 @@ prepare_directive_trad (cpp_reader *pfile) static void 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, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name); + /* Issue -pedantic or deprecated warnings for extensions. We let + -pedantic take precedence if both are applicable. */ + 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); + 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); + } /* Traditionally, a directive is ignored unless its # is in column 1. Therefore in code intended to work with K+R @@ -559,9 +569,14 @@ do_define (cpp_reader *pfile) pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments_in_macro_exp); + if (pfile->cb.before_define) + pfile->cb.before_define (pfile); + if (_cpp_create_definition (pfile, node)) if (pfile->cb.define) pfile->cb.define (pfile, pfile->directive_line, node); + + node->flags &= ~NODE_USED; } } @@ -573,6 +588,9 @@ do_undef (cpp_reader *pfile) if (node) { + if (pfile->cb.before_define) + pfile->cb.before_define (pfile); + if (pfile->cb.undef) pfile->cb.undef (pfile, pfile->directive_line, node); @@ -603,7 +621,7 @@ undefine_macros (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *h, /* Body of _cpp_free_definition inlined here for speed. Macros and assertions no longer have anything to free. */ h->type = NT_VOID; - h->flags &= ~(NODE_POISONED|NODE_BUILTIN|NODE_DISABLED); + h->flags &= ~(NODE_POISONED|NODE_BUILTIN|NODE_DISABLED|NODE_USED); return 1; } @@ -689,7 +707,7 @@ parse_include (cpp_reader *pfile, int *pangle_brackets, const unsigned char *dir; if (pfile->directive == &dtable[T_PRAGMA]) - dir = U"pragma dependency"; + dir = UC"pragma dependency"; else dir = pfile->directive->name; cpp_error (pfile, CPP_DL_ERROR, "#%s expects \"FILENAME\" or ", @@ -819,23 +837,30 @@ read_flag (cpp_reader *pfile, unsigned int last) } /* 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 (const uchar *str, unsigned int len, long unsigned int *nump) + of length LEN, to binary; store it in NUMP, and return false if the + number was well-formed, true if not. WRAPPED is set to true if the + number did not fit into 'unsigned long'. */ +static bool +strtolinenum (const uchar *str, size_t len, linenum_type *nump, bool *wrapped) { - unsigned long reg = 0; + linenum_type reg = 0; + linenum_type reg_prev = 0; + uchar c; + *wrapped = false; while (len--) { c = *str++; if (!ISDIGIT (c)) - return 1; + return true; reg *= 10; reg += c - '0'; + if (reg < reg_prev) + *wrapped = true; + reg_prev = reg; } *nump = reg; - return 0; + return false; } /* Interpret #line command. @@ -853,16 +878,17 @@ do_line (cpp_reader *pfile) unsigned char map_sysp = map->sysp; const cpp_token *token; const char *new_file = map->to_file; - unsigned long new_lineno; + linenum_type new_lineno; /* C99 raised the minimum limit on #line numbers. */ - unsigned int cap = CPP_OPTION (pfile, c99) ? 2147483647 : 32767; + linenum_type cap = CPP_OPTION (pfile, c99) ? 2147483647 : 32767; + bool wrapped; /* #line commands expand macros. */ token = cpp_get_token (pfile); if (token->type != CPP_NUMBER - || strtoul_for_line (token->val.str.text, token->val.str.len, - &new_lineno)) + || strtolinenum (token->val.str.text, token->val.str.len, + &new_lineno, &wrapped)) { if (token->type == CPP_EOF) cpp_error (pfile, CPP_DL_ERROR, "unexpected end of file after #line"); @@ -873,8 +899,10 @@ do_line (cpp_reader *pfile) return; } - if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap)) + if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap || wrapped)) cpp_error (pfile, CPP_DL_PEDWARN, "line number out of range"); + else if (wrapped) + cpp_error (pfile, CPP_DL_WARNING, "line number out of range"); token = cpp_get_token (pfile); if (token->type == CPP_STRING) @@ -907,10 +935,11 @@ do_linemarker (cpp_reader *pfile) const struct line_map *map = &line_table->maps[line_table->used - 1]; const cpp_token *token; const char *new_file = map->to_file; - unsigned long new_lineno; + linenum_type new_lineno; unsigned int new_sysp = map->sysp; enum lc_reason reason = LC_RENAME; int flag; + bool wrapped; /* Back up so we can get the number again. Putting this in _cpp_handle_directive risks two calls to _cpp_backup_tokens in @@ -920,8 +949,8 @@ do_linemarker (cpp_reader *pfile) /* #line commands expand macros. */ token = cpp_get_token (pfile); if (token->type != CPP_NUMBER - || strtoul_for_line (token->val.str.text, token->val.str.len, - &new_lineno)) + || strtolinenum (token->val.str.text, token->val.str.len, + &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. */ @@ -981,7 +1010,7 @@ do_linemarker (cpp_reader *pfile) and zero otherwise. */ void _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason, - const char *to_file, unsigned int file_line, + const char *to_file, linenum_type file_line, unsigned int sysp) { const struct line_map *map = linemap_add (pfile->line_table, reason, sysp, @@ -998,14 +1027,20 @@ _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason, static void 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); - pfile->state.prevent_expansion++; - cpp_output_line (pfile, stderr); - pfile->state.prevent_expansion--; - } + const unsigned char *dir_name; + unsigned char *line; + source_location src_loc = pfile->cur_token[-1].src_loc; + + if (print_dir) + dir_name = pfile->directive->name; + else + dir_name = NULL; + pfile->state.prevent_expansion++; + line = cpp_output_line_to_string (pfile, dir_name); + pfile->state.prevent_expansion--; + + cpp_error_with_line (pfile, code, src_loc, 0, "%s", line); + free (line); } static void @@ -1077,7 +1112,7 @@ register_pragma_1 (cpp_reader *pfile, const char *space, const char *name, if (space) { - node = cpp_lookup (pfile, U space, strlen (space)); + node = cpp_lookup (pfile, UC space, strlen (space)); entry = lookup_pragma_entry (*chain, node); if (!entry) { @@ -1106,7 +1141,7 @@ register_pragma_1 (cpp_reader *pfile, const char *space, const char *name, } /* Check for duplicates. */ - node = cpp_lookup (pfile, U name, strlen (name)); + node = cpp_lookup (pfile, UC name, strlen (name)); entry = lookup_pragma_entry (*chain, node); if (entry == NULL) { @@ -1254,7 +1289,7 @@ restore_registered_pragmas (cpp_reader *pfile, struct pragma_entry *pe, { if (pe->is_nspace) sd = restore_registered_pragmas (pfile, pe->u.space, sd); - pe->pragma = cpp_lookup (pfile, U *sd, strlen (*sd)); + pe->pragma = cpp_lookup (pfile, UC *sd, strlen (*sd)); free (*sd); sd++; } @@ -1483,7 +1518,8 @@ get__Pragma_string (cpp_reader *pfile) string = get_token_no_padding (pfile); if (string->type == CPP_EOF) _cpp_backup_tokens (pfile, 1); - if (string->type != CPP_STRING && string->type != CPP_WSTRING) + if (string->type != CPP_STRING && string->type != CPP_WSTRING + && string->type != CPP_STRING32 && string->type != CPP_STRING16) return NULL; paren = get_token_no_padding (pfile); @@ -1507,6 +1543,7 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in) tokenrun *saved_cur_run; cpp_token *toks; int count; + const struct directive *save_directive; dest = result = (char *) alloca (in->len - 1); src = in->text + 1 + (in->text[0] == 'L'); @@ -1547,8 +1584,11 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in) start_directive (pfile); _cpp_clean_line (pfile); + save_directive = pfile->directive; + pfile->directive = &dtable[T_PRAGMA]; do_pragma (pfile); end_directive (pfile, 1); + 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 @@ -1634,12 +1674,26 @@ do_ifdef (cpp_reader *pfile) if (! pfile->state.skipping) { - const cpp_hashnode *node = lex_macro_node (pfile, false); + 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); } } @@ -1652,7 +1706,7 @@ static void do_ifndef (cpp_reader *pfile) { int skip = 1; - const cpp_hashnode *node = 0; + cpp_hashnode *node = 0; if (! pfile->state.skipping) { @@ -1662,6 +1716,20 @@ do_ifndef (cpp_reader *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); } } @@ -1680,7 +1748,7 @@ do_if (cpp_reader *pfile) int skip = 1; if (! pfile->state.skipping) - skip = _cpp_parse_expr (pfile) == false; + skip = _cpp_parse_expr (pfile, true) == false; push_conditional (pfile, skip, T_IF, pfile->mi_ind_cmacro); } @@ -1739,15 +1807,23 @@ do_elif (cpp_reader *pfile) } ifs->type = T_ELIF; - /* Only evaluate this if we aren't skipping elses. During - evaluation, set skipping to false to get lexer warnings. */ - if (ifs->skip_elses) - pfile->state.skipping = 1; - else + 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; - pfile->state.skipping = ! _cpp_parse_expr (pfile); - ifs->skip_elses = ! pfile->state.skipping; + 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. */ @@ -2082,6 +2158,26 @@ cpp_define (cpp_reader *pfile, const char *str) run_directive (pfile, T_DEFINE, buf, count); } + +/* Use to build macros to be run through cpp_define() as + described above. + Example: cpp_define_formatted (pfile, "MACRO=%d", value); */ + +void +cpp_define_formatted (cpp_reader *pfile, const char *fmt, ...) +{ + char *ptr = NULL; + + va_list ap; + va_start (ap, fmt); + vasprintf (&ptr, fmt, ap); + va_end (ap); + + cpp_define (pfile, ptr); + free (ptr); +} + + /* Slight variant of the above for use by initialize_builtins. */ void _cpp_define_builtin (cpp_reader *pfile, const char *str) @@ -2141,6 +2237,9 @@ cpp_pop_definition (cpp_reader *pfile, const char *str, cpp_macro *dfn) if (node == NULL) return; + if (pfile->cb.before_define) + pfile->cb.before_define (pfile); + if (node->type == NT_MACRO) { if (pfile->cb.undef) diff --git a/support/cpp/libcpp/errors.c b/support/cpp/libcpp/errors.c index 97de4900..f756ca7c 100644 --- a/support/cpp/libcpp/errors.c +++ b/support/cpp/libcpp/errors.c @@ -1,13 +1,13 @@ /* Default error handlers for CPP Library. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, 1999, 2000, - 2001, 2002, 2004 Free Software Foundation, Inc. + 2001, 2002, 2004, 2008, 2009 Free Software Foundation, Inc. Written by Per Bothner, 1994. Based on CCCP program by Paul Rubin, June 1986 Adapted to ANSI C, Richard Stallman, Jan 1987 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +along with this program; see the file COPYING3. If not see +. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve @@ -42,25 +42,25 @@ print_location (cpp_reader *pfile, source_location line, unsigned int col) else { const struct line_map *map; - unsigned int lin; + linenum_type lin; map = linemap_lookup (pfile->line_table, line); linemap_print_containing_files (pfile->line_table, map); 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); } @@ -76,9 +76,9 @@ print_location (cpp_reader *pfile, source_location line, unsigned int col) big enough max_column_hint.) Returns 0 if the error has been suppressed. */ -int +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,19 +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. */ + 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; + } 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); @@ -166,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/expr.c b/support/cpp/libcpp/expr.c index 8ac90108..539663c1 100644 --- a/support/cpp/libcpp/expr.c +++ b/support/cpp/libcpp/expr.c @@ -1,11 +1,11 @@ /* Parse C expressions for cpplib. Copyright (C) 1987, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2001, - 2002, 2004 Free Software Foundation. + 2002, 2004, 2008, 2009 Free Software Foundation. Contributed by Per Bothner, 1994. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,9 +14,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. */ +along with this program; see the file COPYING3. If not see +. */ #include "config.h" #include "system.h" @@ -32,6 +31,7 @@ struct op { const cpp_token *token; /* The token forming op (for diagnostics). */ cpp_num value; /* The value logically "right" of op. */ + source_location loc; /* The location of this value. */ enum cpp_ttype op; }; @@ -637,6 +637,20 @@ parse_defined (cpp_reader *pfile) "this use of \"defined\" may not be portable"); _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); + } + } /* A possible controlling macro of the form #if !defined (). _cpp_parse_expr checks there was no other junk on the line. */ @@ -691,6 +705,8 @@ eval_token (cpp_reader *pfile, const cpp_token *token) case CPP_WCHAR: case CPP_CHAR: + case CPP_CHAR16: + case CPP_CHAR32: { cppchar_t cc = cpp_interpret_charconst (pfile, token, &temp, &unsignedp); @@ -729,10 +745,25 @@ eval_token (cpp_reader *pfile, const cpp_token *token) } break; - default: /* CPP_HASH */ + case CPP_HASH: + if (!pfile->state.skipping) + { + /* A pedantic warning takes precedence over a deprecated + warning here. */ + if (CPP_PEDANTIC (pfile)) + cpp_error (pfile, CPP_DL_PEDWARN, + "assertions are a GCC extension"); + else if (CPP_OPTION (pfile, warn_deprecated)) + cpp_error (pfile, CPP_DL_WARNING, + "assertions are a deprecated extension"); + } _cpp_test_assertion (pfile, &temp); result.high = 0; result.low = temp; + break; + + default: + abort (); } result.unsignedp = !!unsignedp; @@ -793,9 +824,11 @@ static const struct cpp_operator /* COMPL */ {16, NO_L_OPERAND}, /* AND_AND */ {6, LEFT_ASSOC}, /* OR_OR */ {5, LEFT_ASSOC}, - /* QUERY */ {3, 0}, + /* Note that QUERY, COLON, and COMMA must have the same precedence. + However, there are some special cases for these in reduce(). */ + /* QUERY */ {4, 0}, /* COLON */ {4, LEFT_ASSOC | CHECK_PROMOTION}, - /* COMMA */ {2, LEFT_ASSOC}, + /* COMMA */ {4, LEFT_ASSOC}, /* OPEN_PAREN */ {1, NO_L_OPERAND}, /* CLOSE_PAREN */ {0, 0}, /* EOF */ {0, 0}, @@ -819,7 +852,7 @@ static const struct cpp_operator stored in the 'value' field of the stack element of the operator that precedes it. */ bool -_cpp_parse_expr (cpp_reader *pfile) +_cpp_parse_expr (cpp_reader *pfile, bool is_if) { struct op *top = pfile->op_stack; unsigned int lex_count; @@ -842,6 +875,7 @@ _cpp_parse_expr (cpp_reader *pfile) lex_count++; op.token = cpp_get_token (pfile); op.op = op.token->type; + op.loc = op.token->src_loc; switch (op.op) { @@ -849,6 +883,8 @@ _cpp_parse_expr (cpp_reader *pfile) case CPP_NUMBER: case CPP_CHAR: case CPP_WCHAR: + case CPP_CHAR16: + case CPP_CHAR32: case CPP_NAME: case CPP_HASH: if (!want_value) @@ -892,7 +928,7 @@ _cpp_parse_expr (cpp_reader *pfile) SYNTAX_ERROR ("missing expression between '(' and ')'"); if (op.op == CPP_EOF && top->op == CPP_EOF) - SYNTAX_ERROR ("#if with no expression"); + SYNTAX_ERROR2 ("%s with no expression", is_if ? "#if" : "#elif"); if (top->op != CPP_EOF && top->op != CPP_OPEN_PAREN) SYNTAX_ERROR2 ("operator '%s' has no right operand", @@ -943,6 +979,7 @@ _cpp_parse_expr (cpp_reader *pfile) top->op = op.op; top->token = op.token; + top->loc = op.token->src_loc; } /* The controlling macro expression is only valid if we called lex 3 @@ -953,7 +990,8 @@ _cpp_parse_expr (cpp_reader *pfile) if (top != pfile->op_stack) { - cpp_error (pfile, CPP_DL_ICE, "unbalanced stack in #if"); + cpp_error (pfile, CPP_DL_ICE, "unbalanced stack in %s", + is_if ? "#if" : "#elif"); syntax_error: return false; /* Return false on syntax error. */ } @@ -995,6 +1033,7 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op) case CPP_NOT: case CPP_COMPL: top[-1].value = num_unary_op (pfile, top->value, top->op); + top[-1].loc = top->loc; break; case CPP_PLUS: @@ -1004,6 +1043,7 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op) case CPP_COMMA: top[-1].value = num_binary_op (pfile, top[-1].value, top->value, top->op); + top[-1].loc = top->loc; break; case CPP_GREATER: @@ -1012,12 +1052,14 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op) case CPP_LESS_EQ: top[-1].value = num_inequality_op (pfile, top[-1].value, top->value, top->op); + top[-1].loc = top->loc; break; case CPP_EQ_EQ: case CPP_NOT_EQ: top[-1].value = num_equality_op (pfile, top[-1].value, top->value, top->op); + top[-1].loc = top->loc; break; case CPP_AND: @@ -1025,16 +1067,19 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op) case CPP_XOR: top[-1].value = num_bitwise_op (pfile, top[-1].value, top->value, top->op); + top[-1].loc = top->loc; break; case CPP_MULT: top[-1].value = num_mul (pfile, top[-1].value, top->value); + top[-1].loc = top->loc; break; case CPP_DIV: case CPP_MOD: top[-1].value = num_div_op (pfile, top[-1].value, top->value, top->op); + top[-1].loc = top->loc; break; case CPP_OR_OR: @@ -1046,6 +1091,7 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op) top->value.high = 0; top->value.unsignedp = false; top->value.overflow = false; + top->loc = top[1].loc; continue; case CPP_AND_AND: @@ -1057,16 +1103,20 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op) top->value.high = 0; top->value.unsignedp = false; top->value.overflow = false; + top->loc = top[1].loc; continue; case CPP_OPEN_PAREN: if (op != CPP_CLOSE_PAREN) { - cpp_error (pfile, CPP_DL_ERROR, "missing ')' in expression"); + cpp_error_with_line (pfile, CPP_DL_ERROR, + top->token->src_loc, + 0, "missing ')' in expression"); return 0; } top--; top->value = top[1].value; + top->loc = top[1].loc; return top; case CPP_COLON: @@ -1075,14 +1125,21 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op) { pfile->state.skip_eval--; top->value = top[1].value; + top->loc = top[1].loc; } else - top->value = top[2].value; + { + top->value = top[2].value; + top->loc = top[2].loc; + } top->value.unsignedp = (top[1].value.unsignedp || top[2].value.unsignedp); continue; case CPP_QUERY: + /* COMMA and COLON should not reduce a QUERY operator. */ + if (op == CPP_COMMA || op == CPP_COLON) + return top; cpp_error (pfile, CPP_DL_ERROR, "'?' without following ':'"); return 0; @@ -1129,12 +1186,12 @@ check_promotion (cpp_reader *pfile, const struct op *op) if (op->value.unsignedp) { if (!num_positive (op[-1].value, CPP_OPTION (pfile, precision))) - cpp_error (pfile, CPP_DL_WARNING, - "the left operand of \"%s\" changes sign when promoted", - cpp_token_as_text (pfile, op->token)); + cpp_error_with_line (pfile, CPP_DL_WARNING, op[-1].loc, 0, + "the left operand of \"%s\" changes sign when promoted", + cpp_token_as_text (pfile, op->token)); } else if (!num_positive (op->value, CPP_OPTION (pfile, precision))) - cpp_error (pfile, CPP_DL_WARNING, + cpp_error_with_line (pfile, CPP_DL_WARNING, op->loc, 0, "the right operand of \"%s\" changes sign when promoted", cpp_token_as_text (pfile, op->token)); } diff --git a/support/cpp/libcpp/files.c b/support/cpp/libcpp/files.c index 469a73af..615b6ab2 100644 --- a/support/cpp/libcpp/files.c +++ b/support/cpp/libcpp/files.c @@ -1,6 +1,6 @@ /* Part of CPP library. File handling. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Written by Per Bothner, 1994. Based on CCCP program by Paul Rubin, June 1986 @@ -10,7 +10,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -19,8 +19,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +along with this program; see the file COPYING3. If not see +. */ #include "config.h" #include "system.h" @@ -74,6 +74,10 @@ struct _cpp_file /* The contents of NAME after calling read_file(). */ const uchar *buffer; + /* Pointer to the real start of BUFFER. read_file() might increment + BUFFER; when freeing, this this pointer must be used instead. */ + const uchar *buffer_start; + /* The macro, if any, preventing re-inclusion. */ const cpp_hashnode *cmacro; @@ -106,9 +110,6 @@ struct _cpp_file /* If BUFFER above contains the true contents of the file. */ bool buffer_valid; - - /* File is a PCH (on return from find_include_file). */ - bool pch; }; /* A singly-linked list for all searches for a given file name, with @@ -322,9 +323,7 @@ pch_open_file (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch) } closedir (pchdir); } - if (valid) - file->pch = true; - else + if (!valid) *invalid_pch = true; } @@ -602,7 +601,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file) type. Use INTTYPE_MAXIMUM unconditionally to ensure this does not bite us. */ #ifndef __BORLANDC__ - if (file->st.st_size > INTTYPE_MAXIMUM (ssize_t)) + if (file->st.st_size > INTTYPE_MAXIMUM (ssize_t)) { cpp_error (pfile, CPP_DL_ERROR, "%s is too large", file->path); return false; @@ -651,8 +650,11 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file) "%s is shorter than expected", file->path); #endif - file->buffer = _cpp_convert_input (pfile, CPP_OPTION (pfile, input_charset), - buf, size, total, &file->st.st_size); + file->buffer = _cpp_convert_input (pfile, + CPP_OPTION (pfile, input_charset), + buf, size, total, + &file->buffer_start, + &file->st.st_size); file->buffer_valid = true; return true; @@ -714,11 +716,12 @@ should_stack_file (cpp_reader *pfile, _cpp_file *file, bool import) return false; /* Handle PCH files immediately; don't stack them. */ - if (file->pch) + if (file->pchname) { pfile->cb.read_pch (pfile, file->pchname, file->fd, file->path); - close (file->fd); file->fd = -1; + free ((void *) file->pchname); + file->pchname = NULL; return false; } @@ -927,10 +930,10 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets, complicates LAST_SOURCE_LINE_LOCATION. This does not apply if we found a PCH file (in which case linemap_add is not called) or we were included from the command-line. */ - if (! file->pch && file->err_no == 0 && type != IT_CMDLINE) + if (file->pchname == NULL && file->err_no == 0 && type != IT_CMDLINE) pfile->line_table->highest_location--; - return _cpp_stack_file (pfile, file, type == IT_IMPORT); + return _cpp_stack_file (pfile, file, (bool)(type == IT_IMPORT)); } /* Could not open FILE. The complication is dependency output. */ @@ -984,8 +987,8 @@ make_cpp_file (cpp_reader *pfile, cpp_dir *dir, const char *fname) static void destroy_cpp_file (_cpp_file *file) { - if (file->buffer) - free ((void *) file->buffer); + if (file->buffer_start) + free ((void *) file->buffer_start); free ((void *) file->name); free (file); } @@ -1350,9 +1353,10 @@ _cpp_pop_file_buffer (cpp_reader *pfile, _cpp_file *file) /* Invalidate control macros in the #including file. */ pfile->mi_valid = false; - if (file->buffer) + if (file->buffer_start) { - free ((void *) file->buffer); + free ((void *) file->buffer_start); + file->buffer_start = NULL; file->buffer = NULL; file->buffer_valid = false; } diff --git a/support/cpp/libcpp/identifiers.c b/support/cpp/libcpp/identifiers.c index c22f4a71..cbf0bd3c 100644 --- a/support/cpp/libcpp/identifiers.c +++ b/support/cpp/libcpp/identifiers.c @@ -1,13 +1,13 @@ /* Hash tables for the CPP library. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998, - 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2007, 2009 Free Software Foundation, Inc. Written by Per Bothner, 1994. Based on CCCP program by Paul Rubin, June 1986 Adapted to ANSI C, Richard Stallman, Jan 1987 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +along with this program; see the file COPYING3. If not see +. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve @@ -28,18 +28,18 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "cpplib.h" #include "internal.h" -static cpp_hashnode *alloc_node (hash_table *); +static hashnode alloc_node (hash_table *); /* Return an identifier node for hashtable.c. Used by cpplib except when integrated with the C front ends. */ -static cpp_hashnode * +static hashnode alloc_node (hash_table *table) { cpp_hashnode *node; node = XOBNEW (&table->pfile->hash_ob, cpp_hashnode); memset (node, 0, sizeof (cpp_hashnode)); - return node; + return HT_NODE (node); } /* Set up the identifier hash table. Use TABLE if non-null, otherwise @@ -52,12 +52,12 @@ _cpp_init_hashtable (cpp_reader *pfile, hash_table *table) if (table == NULL) { pfile->our_hashtable = 1; - table = ht_create (13); /* 8K (=2^13) entries. */ - table->alloc_node = (hashnode (*) (hash_table *)) alloc_node; + table = ht_create (13); /* 8K (=2^13) entries. */ + table->alloc_node = alloc_node; _obstack_begin (&pfile->hash_ob, 0, 0, - (void *(*) (long)) xmalloc, - (void (*) (void *)) free); + (void *(*) (long)) xmalloc, + (void (*) (void *)) free); } table->pfile = pfile; @@ -68,9 +68,9 @@ _cpp_init_hashtable (cpp_reader *pfile, hash_table *table) _cpp_init_internal_pragmas (pfile); s = &pfile->spec_nodes; - s->n_defined = cpp_lookup (pfile, DSC("defined")); - s->n_true = cpp_lookup (pfile, DSC("true")); - s->n_false = cpp_lookup (pfile, DSC("false")); + s->n_defined = cpp_lookup (pfile, DSC("defined")); + s->n_true = cpp_lookup (pfile, DSC("true")); + s->n_false = cpp_lookup (pfile, DSC("false")); s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__")); s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC; } @@ -107,12 +107,15 @@ cpp_defined (cpp_reader *pfile, const unsigned char *str, int len) return node && node->type == NT_MACRO; } +/* We don't need a proxy since the hash table's identifier comes first + in cpp_hashnode. However, in case this is ever changed, we have a + static assertion for it. */ +extern char proxy_assertion_broken[offsetof (struct cpp_hashnode, ident) == 0 ? 1 : -1]; + /* For all nodes in the hashtable, callback CB with parameters PFILE, the node, and V. */ void cpp_forall_identifiers (cpp_reader *pfile, cpp_cb cb, void *v) { - /* We don't need a proxy since the hash table's identifier comes - first in cpp_hashnode. */ ht_forall (pfile->hash_table, (ht_cb) cb, v); } diff --git a/support/cpp/libcpp/include/cpp-id-data.h b/support/cpp/libcpp/include/cpp-id-data.h index 2445186c..1531c66f 100644 --- a/support/cpp/libcpp/include/cpp-id-data.h +++ b/support/cpp/libcpp/include/cpp-id-data.h @@ -1,10 +1,10 @@ /* Structures that hang off cpp_identifier, for PCH. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -13,8 +13,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +along with this program; see the file COPYING3. If not see +. */ #include "cpplib.h" @@ -22,7 +22,7 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ typedef unsigned char uchar; #endif -#define U (const unsigned char *) /* Intended use: U"string" */ +#define UC (const unsigned char *) /* Intended use: UC"string" */ /* Chained list of answers to an assertion. */ struct answer GTY(()) @@ -38,9 +38,9 @@ struct cpp_macro GTY(()) { /* Parameters, if any. */ cpp_hashnode ** GTY ((nested_ptr (union tree_node, - "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL", - "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"), - length ("%h.paramc"))) + "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL", + "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"), + length ("%h.paramc"))) params; /* Replacement tokens (ISO) or replacement text (traditional). See diff --git a/support/cpp/libcpp/include/cpplib.h b/support/cpp/libcpp/include/cpplib.h index 1015645f..e794dff1 100644 --- a/support/cpp/libcpp/include/cpplib.h +++ b/support/cpp/libcpp/include/cpplib.h @@ -1,12 +1,12 @@ /* Definitions for CPP library. Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2007 + 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. Written by Per Bothner, 1994-95. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +along with this program; see the file COPYING3. If not see +. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve @@ -123,10 +123,14 @@ struct _cpp_file; \ TK(CHAR, LITERAL) /* 'char' */ \ TK(WCHAR, LITERAL) /* L'char' */ \ + TK(CHAR16, LITERAL) /* u'char' */ \ + TK(CHAR32, LITERAL) /* U'char' */ \ TK(OTHER, LITERAL) /* stray punctuation */ \ \ TK(STRING, LITERAL) /* "string" */ \ TK(WSTRING, LITERAL) /* L"string" */ \ + TK(STRING16, LITERAL) /* u"string" */ \ + TK(STRING32, LITERAL) /* U"string" */ \ TK(OBJC_STRING, LITERAL) /* @"string" - Objective-C */ \ TK(HEADER_NAME, LITERAL) /* in #include */ \ \ @@ -274,8 +278,9 @@ struct cpp_options /* Nonzero means handle cplusplus style comments. */ unsigned char cplusplus_comments; - /* Nonzero means define __OBJC__, treat @ as a special token, and - use the OBJC[PLUS]_INCLUDE_PATH environment variable. */ + /* Nonzero means define __OBJC__, treat @ as a special token, use + the OBJC[PLUS]_INCLUDE_PATH environment variable, and allow + "#import". */ unsigned char objc; /* Nonzero means don't copy comments into the output file. */ @@ -294,6 +299,9 @@ struct cpp_options /* Nonzero means to allow hexadecimal floats and LL suffixes. */ unsigned char extended_numbers; + /* Nonzero means process u/U prefix literals (UTF-16/32). */ + unsigned char uliterals; + /* Nonzero means print names of header files (-H). */ unsigned char print_include_names; @@ -344,6 +352,10 @@ struct cpp_options Presumably the usage is protected by the appropriate #ifdef. */ unsigned char warn_variadic_macros; + /* Nonzero means warn about builtin macros that are redefined or + explicitly undefined. */ + unsigned char warn_builtin_macro_redefined; + /* Nonzero means turn warnings into errors. */ unsigned char warnings_are_errors; @@ -496,10 +508,22 @@ struct cpp_callbacks void (*read_pch) (cpp_reader *, const char *, int, const char *); missing_header_cb missing_header; + /* Context-sensitive macro support. Returns macro (if any) that should + be expanded. */ + cpp_hashnode * (*macro_to_expand) (cpp_reader *, const cpp_token *); + /* Called to emit a diagnostic if client_diagnostic option is true. This callback receives the translated message. */ void (*error) (cpp_reader *, int, const char *, va_list *) ATTRIBUTE_FPTR_PRINTF(3,0); + + /* Callbacks for when a macro is expanded, or tested (whether + defined or not at the time) in #ifdef, #ifndef or "defined". */ + void (*used_define) (cpp_reader *, unsigned int, cpp_hashnode *); + void (*used_undef) (cpp_reader *, unsigned int, cpp_hashnode *); + /* Called before #define and #undef or other macro definition + changes are processed. */ + void (*before_define) (cpp_reader *); }; /* Chain of directories to look for include files in. */ @@ -516,6 +540,13 @@ struct cpp_dir "C" guards for C++. */ unsigned char sysp; + /* Is this a user-supplied directory? */ + bool user_supplied_p; + + /* The canonicalized NAME as determined by lrealpath. This field + is only used by hosts that lack reliable inode numbers. */ + char *canonical_name; + /* Mapping of file names for this directory for MS-DOS and related platforms. A NULL-terminated array of (from, to) pairs. */ const char **name_map; @@ -530,9 +561,6 @@ struct cpp_dir directories in the search path. */ ino_t ino; dev_t dev; - - /* Is this a user-supplied directory? */ - bool user_supplied_p; }; /* Name under which this program was invoked. */ @@ -557,6 +585,8 @@ extern const char *progname; #define NODE_WARN (1 << 4) /* Warn if redefined or undefined. */ #define NODE_DISABLED (1 << 5) /* A disabled macro. */ #define NODE_MACRO_ARG (1 << 6) /* Used during #define processing. */ +#define NODE_USED (1 << 7) /* Dumped with -dU. */ +#define NODE_CONDITIONAL (1 << 8) /* Conditional macro */ /* Different flavors of hash node. */ enum node_type @@ -628,8 +658,8 @@ struct cpp_hashnode GTY(()) then index into directive table. Otherwise, a NODE_OPERATOR. */ unsigned char rid_code; /* Rid code - for front ends. */ - ENUM_BITFIELD(node_type) type : 8; /* CPP node type. */ - unsigned char flags; /* CPP flags. */ + ENUM_BITFIELD(node_type) type : 7; /* CPP node type. */ + unsigned int flags : 9; /* CPP flags. */ union _cpp_hashnode_value GTY ((desc ("CPP_HASHNODE_VALUE_IDX (%1)"))) value; }; @@ -716,6 +746,7 @@ extern const cpp_token *cpp_get_token_with_location (cpp_reader *, extern const unsigned char *cpp_macro_definition (cpp_reader *, const cpp_hashnode *); extern void _cpp_backup_tokens (cpp_reader *, unsigned int); +extern const cpp_token *cpp_peek_token (cpp_reader *, int); /* Evaluate a CPP_CHAR or CPP_WCHAR token. */ extern cppchar_t cpp_interpret_charconst (cpp_reader *, const cpp_token *, @@ -723,10 +754,10 @@ extern cppchar_t cpp_interpret_charconst (cpp_reader *, const cpp_token *, /* Evaluate a vector of CPP_STRING or CPP_WSTRING tokens. */ extern bool cpp_interpret_string (cpp_reader *, const cpp_string *, size_t, - cpp_string *, bool); + cpp_string *, enum cpp_ttype); extern bool cpp_interpret_string_notranslate (cpp_reader *, const cpp_string *, size_t, - cpp_string *, bool); + cpp_string *, enum cpp_ttype); /* Convert a host character constant to the execution character set. */ extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t); @@ -734,6 +765,8 @@ extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t); /* Used to register macros and assertions, perhaps from the command line. The text is the same as the command line argument. */ extern void cpp_define (cpp_reader *, const char *); +extern void cpp_define_formatted (cpp_reader *pfile, + const char *fmt, ...) ATTRIBUTE_PRINTF_2; extern void cpp_assert (cpp_reader *, const char *); extern void cpp_undef (cpp_reader *, const char *); extern void cpp_unassert (cpp_reader *, const char *); @@ -842,9 +875,11 @@ extern void cpp_errno (cpp_reader *, int, const char *msgid); extern void cpp_error_with_line (cpp_reader *, int, source_location, unsigned, const char *msgid, ...) ATTRIBUTE_PRINTF_5; -/* In cpplex.c */ +/* In lex.c */ extern int cpp_ideq (const cpp_token *, const char *); extern void cpp_output_line (cpp_reader *, FILE *); +extern unsigned char *cpp_output_line_to_string (cpp_reader *, + const unsigned char *); extern void cpp_output_token (const cpp_token *, FILE *); extern const char *cpp_type2name (enum cpp_ttype); /* Returns the value of an escape sequence, truncated to the correct @@ -855,7 +890,37 @@ extern const char *cpp_type2name (enum cpp_ttype); extern cppchar_t cpp_parse_escape (cpp_reader *, const unsigned char ** pstr, const unsigned char *limit, int wide); -/* In cpphash.c */ +/* Structure used to hold a comment block at a given location in the + source code. */ + +typedef struct +{ + /* Text of the comment including the terminators. */ + char *comment; + + /* source location for the given comment. */ + source_location sloc; +} cpp_comment; + +/* Structure holding all comments for a given cpp_reader. */ + +typedef struct +{ + /* table of comment entries. */ + cpp_comment *entries; + + /* number of actual entries entered in the table. */ + int count; + + /* number of entries allocated currently. */ + int allocated; +} cpp_comment_table; + +/* Returns the table of comments encountered by the preprocessor. This + table is only populated when pfile->state.save_comments is true. */ +extern cpp_comment_table *cpp_get_comments (cpp_reader *); + +/* In hash.c */ /* Lookup an identifier in the hashtable. Puts the identifier in the table if it is not already there. */ @@ -865,13 +930,13 @@ extern cpp_hashnode *cpp_lookup (cpp_reader *, const unsigned char *, typedef int (*cpp_cb) (cpp_reader *, cpp_hashnode *, void *); extern void cpp_forall_identifiers (cpp_reader *, cpp_cb, void *); -/* In cppmacro.c */ +/* In macro.c */ extern void cpp_scan_nooutput (cpp_reader *); extern int cpp_sys_macro_p (cpp_reader *); extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *, unsigned int); -/* In cppfiles.c */ +/* In files.c */ extern bool cpp_included (cpp_reader *, const char *); extern bool cpp_included_before (cpp_reader *, const char *, source_location); extern void cpp_make_system_header (cpp_reader *, int, int); @@ -884,7 +949,7 @@ extern struct _cpp_file *cpp_get_file (cpp_buffer *); extern cpp_buffer *cpp_get_prev (cpp_buffer *); extern void cpp_clear_file_cache (cpp_reader *); -/* In cpppch.c */ +/* In pch.c */ struct save_macro_data; extern int cpp_save_state (cpp_reader *, FILE *); extern int cpp_write_pch_deps (cpp_reader *, FILE *); diff --git a/support/cpp/libcpp/include/line-map.h b/support/cpp/libcpp/include/line-map.h index f5b5791d..60bfeb1b 100644 --- a/support/cpp/libcpp/include/line-map.h +++ b/support/cpp/libcpp/include/line-map.h @@ -1,10 +1,10 @@ /* Map logical line numbers to (source file, line number) pairs. - Copyright (C) 2001, 2003, 2004, 2007 + Copyright (C) 2001, 2003, 2004, 2007, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -13,8 +13,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +along with this program; see the file COPYING3. If not see +. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve @@ -34,6 +34,9 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. (e.g. a #line directive in C). */ enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME}; +/* The type of line numbers. */ +typedef unsigned int linenum_type; + /* A logical line/column number, i.e. an "index" into a line_map. */ /* Long-term, we want to use this to replace struct location_s (in input.h), and effectively typedef source_location location_t. */ @@ -57,7 +60,7 @@ typedef void *(*line_map_realloc) (void *, size_t); struct line_map GTY(()) { const char *to_file; - unsigned int to_line; + linenum_type to_line; source_location start_location; int included_from; ENUM_BITFIELD (lc_reason) reason : CHAR_BIT; @@ -119,7 +122,7 @@ extern void linemap_check_files_exited (struct line_maps *); the highest_location). */ extern source_location linemap_line_start -(struct line_maps *set, unsigned int to_line, unsigned int max_column_hint); +(struct line_maps *set, linenum_type to_line, unsigned int max_column_hint); /* Add a mapping of logical source line to physical source file and line number. @@ -134,7 +137,7 @@ extern source_location linemap_line_start maps, so any stored line_map pointers should not be used. */ extern const struct line_map *linemap_add (struct line_maps *, enum lc_reason, unsigned int sysp, - const char *to_file, unsigned int to_line); + const char *to_file, linenum_type to_line); /* Given a logical line, returns the map from which the corresponding (source file, line) pair can be deduced. */ @@ -148,11 +151,11 @@ extern void linemap_print_containing_files (struct line_maps *, const struct line_map *); /* Converts a map and a source_location to source line. */ -#define SOURCE_LINE(MAP, LINE) \ - ((((LINE) - (MAP)->start_location) >> (MAP)->column_bits) + (MAP)->to_line) +#define SOURCE_LINE(MAP, LOC) \ + ((((LOC) - (MAP)->start_location) >> (MAP)->column_bits) + (MAP)->to_line) -#define SOURCE_COLUMN(MAP, LINE) \ - (((LINE) - (MAP)->start_location) & ((1 << (MAP)->column_bits) - 1)) +#define SOURCE_COLUMN(MAP, LOC) \ + (((LOC) - (MAP)->start_location) & ((1 << (MAP)->column_bits) - 1)) /* Returns the last source line within a map. This is the (last) line of the #include, or other directive, that caused a map change. */ @@ -172,7 +175,7 @@ extern void linemap_print_containing_files (struct line_maps *, /* Set LOC to a source position that is the same line as the most recent linemap_line_start, but with the specified TO_COLUMN column number. */ -#define LINEMAP_POSITION_FOR_COLUMN(LOC, SET, TO_COLUMN) { \ +#define LINEMAP_POSITION_FOR_COLUMN(LOC, SET, TO_COLUMN) do { \ unsigned int to_column = (TO_COLUMN); \ struct line_maps *set = (SET); \ if (__builtin_expect (to_column >= set->max_column_hint, 0)) \ @@ -183,7 +186,7 @@ extern void linemap_print_containing_files (struct line_maps *, if (r >= set->highest_location) \ set->highest_location = r; \ (LOC) = r; \ - }} + }} while (0) extern source_location diff --git a/support/cpp/libcpp/include/mkdeps.h b/support/cpp/libcpp/include/mkdeps.h index 02649701..f743ee72 100644 --- a/support/cpp/libcpp/include/mkdeps.h +++ b/support/cpp/libcpp/include/mkdeps.h @@ -1,10 +1,10 @@ /* Dependency generator for Makefile fragments. - Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2003, 2009 Free Software Foundation, Inc. Contributed by Zack Weinberg, Mar 2000 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -13,8 +13,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +along with this program; see the file COPYING3. If not see +. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve diff --git a/support/cpp/libcpp/include/symtab.h b/support/cpp/libcpp/include/symtab.h index ebe4139d..74ce327c 100644 --- a/support/cpp/libcpp/include/symtab.h +++ b/support/cpp/libcpp/include/symtab.h @@ -1,9 +1,10 @@ /* Hash tables. - Copyright (C) 2000, 2001, 2003, 2004, 2007 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2003, 2004, 2007, 2008, 2009 + Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -12,8 +13,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +along with this program; see the file COPYING3. If not see +. */ #ifndef LIBCPP_SYMTAB_H #define LIBCPP_SYMTAB_H @@ -43,7 +44,7 @@ struct ht_identifier GTY(()) typedef struct ht hash_table; typedef struct ht_identifier *hashnode; -enum ht_lookup_option {HT_NO_INSERT = 0, HT_ALLOC, HT_ALLOCED}; +enum ht_lookup_option {HT_NO_INSERT = 0, HT_ALLOC}; /* An identifier hash table for cpplib and the front ends. */ struct ht @@ -92,6 +93,10 @@ extern hashnode ht_lookup_with_hash (hash_table *, const unsigned char *, typedef int (*ht_cb) (struct cpp_reader *, hashnode, const void *); extern void ht_forall (hash_table *, ht_cb, const void *); +/* For all nodes in TABLE, call the callback. If the callback returns + a nonzero value, the node is removed from the table. */ +extern void ht_purge (hash_table *, ht_cb, const void *); + /* Restore the hash table. */ extern void ht_load (hash_table *ht, hashnode *entries, unsigned int nslots, unsigned int nelements, bool own); diff --git a/support/cpp/libcpp/init.c b/support/cpp/libcpp/init.c index 40d86a28..762a735c 100644 --- a/support/cpp/libcpp/init.c +++ b/support/cpp/libcpp/init.c @@ -1,13 +1,14 @@ /* CPP Library. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2009 + 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 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +17,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +along with this program; see the file COPYING3. If not see +. */ #include "config.h" #include "system.h" @@ -78,20 +79,21 @@ struct lang_flags char std; char cplusplus_comments; char digraphs; + char uliterals; }; static const struct lang_flags lang_defaults[] = -{ /* c99 c++ xnum xid std // digr */ - /* GNUC89 */ { 0, 0, 1, 0, 0, 1, 1 }, - /* GNUC99 */ { 1, 0, 1, 0, 0, 1, 1 }, - /* STDC89 */ { 0, 0, 0, 0, 1, 0, 0 }, - /* STDC94 */ { 0, 0, 0, 0, 1, 0, 1 }, - /* STDC99 */ { 1, 0, 1, 0, 1, 1, 1 }, - /* GNUCXX */ { 0, 1, 1, 0, 0, 1, 1 }, - /* CXX98 */ { 0, 1, 1, 0, 1, 1, 1 }, - /* GNUCXX0X */ { 1, 1, 1, 0, 0, 1, 1 }, - /* CXX0X */ { 1, 1, 1, 0, 1, 1, 1 }, - /* ASM */ { 0, 0, 1, 0, 0, 1, 0 } +{ /* c99 c++ xnum xid std // digr ulit */ + /* GNUC89 */ { 0, 0, 1, 0, 0, 1, 1, 0 }, + /* GNUC99 */ { 1, 0, 1, 0, 0, 1, 1, 1 }, + /* STDC89 */ { 0, 0, 0, 0, 1, 0, 0, 0 }, + /* STDC94 */ { 0, 0, 0, 0, 1, 0, 1, 0 }, + /* STDC99 */ { 1, 0, 1, 0, 1, 1, 1, 0 }, + /* GNUCXX */ { 0, 1, 1, 0, 0, 1, 1, 0 }, + /* CXX98 */ { 0, 1, 1, 0, 1, 1, 1, 0 }, + /* GNUCXX0X */ { 1, 1, 1, 0, 0, 1, 1, 1 }, + /* CXX0X */ { 1, 1, 1, 0, 1, 1, 1, 1 }, + /* ASM */ { 0, 0, 1, 0, 0, 1, 0, 0 } /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and CXX0X when no longer experimental (when all uses of identifiers in the compiler have been audited for correct handling of @@ -114,6 +116,7 @@ cpp_set_lang (cpp_reader *pfile, enum c_lang lang) 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. */ @@ -163,6 +166,7 @@ cpp_create_reader (enum c_lang lang, hash_table *table, CPP_OPTION (pfile, dollars_in_ident) = 1; CPP_OPTION (pfile, warn_dollars) = 1; CPP_OPTION (pfile, warn_variadic_macros) = 1; + CPP_OPTION (pfile, warn_builtin_macro_redefined) = 1; CPP_OPTION (pfile, warn_normalize) = normalized_C; /* Default CPP arithmetic to something sensible for the host for the @@ -244,6 +248,7 @@ cpp_destroy (cpp_reader *pfile) { cpp_context *context, *contextn; tokenrun *run, *runn; + int i; free (pfile->op_stack); @@ -286,6 +291,14 @@ cpp_destroy (cpp_reader *pfile) free (context); } + if (pfile->comments.entries) + { + for (i = 0; i < pfile->comments.count; i++) + free (pfile->comments.entries[i].comment); + + free (pfile->comments.entries); + } + free (pfile); } @@ -303,31 +316,41 @@ cpp_destroy (cpp_reader *pfile) altered through #define, and #if recognizes them as operators. In C, these are not entered into the hash table at all (but see ). The value is a token-type enumerator. */ -struct builtin +struct builtin_macro { - const uchar *name; - unsigned short len; - unsigned short value; + const uchar *const name; + const unsigned short len; + const unsigned short value; + const bool always_warn_if_redefined; }; -#define B(n, t) { DSC(n), t } -static const struct builtin builtin_array[] = +#define B(n, t, f) { DSC(n), t, f } +static const struct builtin_macro builtin_array[] = { - B("__TIMESTAMP__", BT_TIMESTAMP), - B("__TIME__", BT_TIME), - B("__DATE__", BT_DATE), - B("__FILE__", BT_FILE), - B("__BASE_FILE__", BT_BASE_FILE), - B("__LINE__", BT_SPECLINE), - B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL), - B("__COUNTER__", BT_COUNTER), + 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), /* Keep builtins not used for -traditional-cpp at the end, and update init_builtins() if any more are added. */ - B("_Pragma", BT_PRAGMA), - B("__STDC__", BT_STDC), + B("_Pragma", BT_PRAGMA, true), + B("__STDC__", BT_STDC, true), }; +#undef B -static const struct builtin operator_array[] = +struct builtin_operator +{ + const uchar *const name; + const unsigned short len; + const unsigned short value; +}; + +#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), @@ -347,7 +370,7 @@ static const struct builtin operator_array[] = static void mark_named_operators (cpp_reader *pfile) { - const struct builtin *b; + const struct builtin_operator *b; for (b = operator_array; b < (operator_array + ARRAY_SIZE (operator_array)); @@ -363,7 +386,7 @@ mark_named_operators (cpp_reader *pfile) void cpp_init_special_builtins (cpp_reader *pfile) { - const struct builtin *b; + const struct builtin_macro *b; size_t n = ARRAY_SIZE (builtin_array); if (CPP_OPTION (pfile, traditional)) @@ -376,7 +399,10 @@ cpp_init_special_builtins (cpp_reader *pfile) { cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len); hp->type = NT_MACRO; - hp->flags |= NODE_BUILTIN | NODE_WARN; + hp->flags |= NODE_BUILTIN; + if (b->always_warn_if_redefined + || CPP_OPTION (pfile, warn_builtin_macro_redefined)) + hp->flags |= NODE_WARN; hp->value.builtin = (enum builtin_type) b->value; } } diff --git a/support/cpp/libcpp/internal.h b/support/cpp/libcpp/internal.h index ac08c420..660f3d63 100644 --- a/support/cpp/libcpp/internal.h +++ b/support/cpp/libcpp/internal.h @@ -1,10 +1,10 @@ /* Part of CPP library. - Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 - Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, + 2008, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -13,8 +13,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +along with this program; see the file COPYING3. If not see +. */ /* This header defines all the internal data structures and functions that need to be visible across files. It should not be used outside @@ -48,6 +48,7 @@ struct cset_converter { convert_f func; iconv_t cd; + int width; }; #define BITS_PER_CPPCHAR_T (CHAR_BIT * sizeof (cppchar_t)) @@ -67,7 +68,7 @@ struct cset_converter #define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \ const struct line_maps *line_table = PFILE->line_table; \ const struct line_map *map = &line_table->maps[line_table->used-1]; \ - unsigned int line = SOURCE_LINE (map, line_table->highest_line); \ + linenum_type line = SOURCE_LINE (map, line_table->highest_line); \ linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \ } while (0) @@ -400,6 +401,14 @@ struct cpp_reader execution character set. */ struct cset_converter narrow_cset_desc; + /* Descriptor for converting from the source character set to the + UTF-16 execution character set. */ + struct cset_converter char16_cset_desc; + + /* Descriptor for converting from the source character set to the + UTF-32 execution character set. */ + struct cset_converter char32_cset_desc; + /* Descriptor for converting from the source character set to the wide execution character set. */ struct cset_converter wide_cset_desc; @@ -464,6 +473,9 @@ struct cpp_reader /* Next value of __COUNTER__ macro. */ unsigned int counter; + + /* Table of comments, when state.save_comments is true. */ + cpp_comment_table comments; }; /* Character classes. Based on the more primitive macros in safe-ctype.h. @@ -511,10 +523,6 @@ cpp_in_primary_file (cpp_reader *pfile) return pfile->line_table->depth == 1; } -/* In errors.c */ -extern int _cpp_begin_message (cpp_reader *, int, - source_location, unsigned int); - /* In macro.c */ extern void _cpp_free_definition (cpp_hashnode *); extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *); @@ -529,6 +537,7 @@ extern const unsigned char *_cpp_builtin_macro_text (cpp_reader *, 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); +extern void _cpp_backup_tokens_direct (cpp_reader *, unsigned int); /* In identifiers.c */ extern void _cpp_init_hashtable (cpp_reader *, hash_table *); @@ -554,7 +563,7 @@ extern bool _cpp_read_file_entries (cpp_reader *, FILE *); extern struct stat *_cpp_get_file_stat (_cpp_file *); /* In expr.c */ -extern bool _cpp_parse_expr (cpp_reader *); +extern bool _cpp_parse_expr (cpp_reader *, bool); extern struct op *_cpp_expand_op_stack (cpp_reader *); /* In lex.c */ @@ -581,7 +590,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 *, - unsigned int, unsigned int); + linenum_type, unsigned int); extern void _cpp_pop_buffer (cpp_reader *); /* In directives.c */ @@ -637,7 +646,7 @@ extern cppchar_t _cpp_valid_ucn (cpp_reader *, const unsigned char **, extern void _cpp_destroy_iconv (cpp_reader *); extern unsigned char *_cpp_convert_input (cpp_reader *, const char *, unsigned char *, size_t, size_t, - off_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, diff --git a/support/cpp/libcpp/lex.c b/support/cpp/libcpp/lex.c index ab04177e..3777a875 100644 --- a/support/cpp/libcpp/lex.c +++ b/support/cpp/libcpp/lex.c @@ -1,5 +1,6 @@ /* CPP Library - lexical analysis. - Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 + 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 @@ -7,7 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +17,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +along with this program; see the file COPYING3. If not see +. */ #include "config.h" #include "system.h" @@ -40,10 +41,10 @@ struct token_spelling }; static const unsigned char *const digraph_spellings[] = -{ U"%:", U"%:%:", U"<:", U":>", U"<%", U"%>" }; +{ UC"%:", UC"%:%:", UC"<:", UC":>", UC"<%", UC"%>" }; -#define OP(e, s) { SPELL_OPERATOR, U s }, -#define TK(e, s) { SPELL_ ## s, U #e }, +#define OP(e, s) { SPELL_OPERATOR, UC s }, +#define TK(e, s) { SPELL_ ## s, UC #e }, static const struct token_spelling token_spellings[N_TTYPES] = { TTYPE_TABLE }; #undef OP #undef TK @@ -56,6 +57,7 @@ static int skip_line_comment (cpp_reader *); static void skip_whitespace (cpp_reader *, cppchar_t); static void lex_string (cpp_reader *, cpp_token *, const uchar *); static void save_comment (cpp_reader *, cpp_token *, const uchar *, cppchar_t); +static void store_comment (cpp_reader *, cpp_token *); static void create_literal (cpp_reader *, cpp_token *, const uchar *, unsigned int, enum cpp_ttype); static bool warn_in_comment (cpp_reader *, _cpp_line_note *); @@ -433,7 +435,7 @@ static int skip_line_comment (cpp_reader *pfile) { cpp_buffer *buffer = pfile->buffer; - unsigned int orig_line = pfile->line_table->highest_line; + source_location orig_line = pfile->line_table->highest_line; while (*buffer->cur != '\n') buffer->cur++; @@ -587,8 +589,8 @@ lex_identifier (cpp_reader *pfile, const uchar *base, bool starts_ucn, len = cur - base; hash = HT_HASHFINISH (hash, len); - result = (cpp_hashnode *) - ht_lookup_with_hash (pfile->hash_table, base, len, hash, HT_ALLOC); + result = CPP_HASHNODE (ht_lookup_with_hash (pfile->hash_table, + base, len, hash, HT_ALLOC)); } /* Rarely, identifiers require diagnostics when lexed. */ @@ -945,8 +947,10 @@ create_literal (cpp_reader *pfile, cpp_token *token, const uchar *base, /* Lexes a string, character constant, or angle-bracketed header file name. The stored string contains the spelling, including opening - quote and leading any leading 'L'. It returns the type of the - literal, or CPP_OTHER if it was not properly terminated. + quote and leading any leading 'L', 'u' or 'U'. It returns the type + of the literal, or CPP_OTHER if it was not properly terminated, or + CPP_LESS for an unterminated header name which must be relexed as + normal tokens. The spelling is NUL-terminated, but it is not guaranteed that this is the first NUL since embedded NULs are preserved. */ @@ -960,12 +964,16 @@ lex_string (cpp_reader *pfile, cpp_token *token, const uchar *base) cur = base; terminator = *cur++; - if (terminator == 'L') + if (terminator == 'L' || terminator == 'u' || terminator == 'U') terminator = *cur++; if (terminator == '\"') - type = *base == 'L' ? CPP_WSTRING: CPP_STRING; + type = (*base == 'L' ? CPP_WSTRING : + *base == 'U' ? CPP_STRING32 : + *base == 'u' ? CPP_STRING16 : CPP_STRING); else if (terminator == '\'') - type = *base == 'L' ? CPP_WCHAR: CPP_CHAR; + type = (*base == 'L' ? CPP_WCHAR : + *base == 'U' ? CPP_CHAR32 : + *base == 'u' ? CPP_CHAR16 : CPP_CHAR); else terminator = '>', type = CPP_HEADER_NAME; @@ -981,6 +989,14 @@ lex_string (cpp_reader *pfile, cpp_token *token, const uchar *base) else if (c == '\n') { cur--; + /* Unmatched quotes always yield undefined behavior, but + greedy lexing means that what appears to be an unterminated + header name may actually be a legitimate sequence of tokens. */ + if (terminator == '>') + { + token->type = CPP_LESS; + return; + } type = CPP_OTHER; break; } @@ -1053,6 +1069,51 @@ save_asm (cpp_reader *pfile, cpp_token *token, const unsigned char *from) copy_text_chars (buffer + _ASM_LEN, from, len); } +/* Return the comment table. The client may not make any assumption + about the ordering of the table. */ +cpp_comment_table * +cpp_get_comments (cpp_reader *pfile) +{ + return &pfile->comments; +} + +/* Append a comment to the end of the comment table. */ +static void +store_comment (cpp_reader *pfile, cpp_token *token) +{ + int len; + + if (pfile->comments.allocated == 0) + { + pfile->comments.allocated = 256; + pfile->comments.entries = (cpp_comment *) xmalloc + (pfile->comments.allocated * sizeof (cpp_comment)); + } + + if (pfile->comments.count == pfile->comments.allocated) + { + pfile->comments.allocated *= 2; + pfile->comments.entries = (cpp_comment *) xrealloc + (pfile->comments.entries, + pfile->comments.allocated * sizeof (cpp_comment)); + } + + len = token->val.str.len; + + /* Copy comment. Note, token may not be NULL terminated. */ + pfile->comments.entries[pfile->comments.count].comment = + (char *) xmalloc (sizeof (char) * (len + 1)); + memcpy (pfile->comments.entries[pfile->comments.count].comment, + token->val.str.text, len); + pfile->comments.entries[pfile->comments.count].comment[len] = '\0'; + + /* Set source location. */ + pfile->comments.entries[pfile->comments.count].sloc = token->src_loc; + + /* Increment the count of entries in the comment table. */ + pfile->comments.count++; +} + /* The stored comment includes the comment start and any terminator. */ static void save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from, @@ -1092,6 +1153,9 @@ save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from, buffer[clen - 2] = '*'; buffer[clen - 1] = '/'; } + + /* Finally store this comment for use by clients of libcpp. */ + store_comment (pfile, token); } /* Allocate COUNT tokens for RUN. */ @@ -1117,6 +1181,49 @@ next_tokenrun (tokenrun *run) return run->next; } +/* Look ahead in the input stream. */ +const cpp_token * +cpp_peek_token (cpp_reader *pfile, int index) +{ + cpp_context *context = pfile->context; + const cpp_token *peektok; + int count; + + /* First, scan through any pending cpp_context objects. */ + while (context->prev) + { + ptrdiff_t sz = (context->direct_p + ? LAST (context).token - FIRST (context).token + : LAST (context).ptoken - FIRST (context).ptoken); + + if (index < (int) sz) + return (context->direct_p + ? FIRST (context).token + index + : *(FIRST (context).ptoken + index)); + + index -= (int) sz; + context = context->prev; + } + + /* We will have to read some new tokens after all (and do so + without invalidating preceding tokens). */ + count = index; + pfile->keep_tokens++; + + do + { + peektok = _cpp_lex_token (pfile); + if (peektok->type == CPP_EOF) + return peektok; + } + while (index--); + + _cpp_backup_tokens_direct (pfile, count + 1); + pfile->keep_tokens--; + + return peektok; +} + /* Allocate a single token that is invalidated at the same time as the rest of the tokens on the line. Has its line and col set to the same as the last lexed token, so that diagnostics appear in the @@ -1125,9 +1232,30 @@ cpp_token * _cpp_temp_token (cpp_reader *pfile) { cpp_token *old, *result; + ptrdiff_t sz = pfile->cur_run->limit - pfile->cur_token; + ptrdiff_t la = (ptrdiff_t) pfile->lookaheads; old = pfile->cur_token - 1; - if (pfile->cur_token == pfile->cur_run->limit) + /* Any pre-existing lookaheads must not be clobbered. */ + if (la) + { + if (sz <= la) + { + tokenrun *next = next_tokenrun (pfile->cur_run); + + if (sz < la) + memmove (next->base + 1, next->base, + (la - sz) * sizeof (cpp_token)); + + next->base[0] = pfile->cur_run->limit[-1]; + } + + if (sz > 1) + memmove (pfile->cur_token + 1, pfile->cur_token, + MIN (la, sz - 1) * sizeof (cpp_token)); + } + + if (!sz && pfile->cur_token == pfile->cur_run->limit) { pfile->cur_run = next_tokenrun (pfile->cur_run); pfile->cur_token = pfile->cur_run->base; @@ -1355,11 +1483,16 @@ _cpp_lex_direct (cpp_reader *pfile) } case 'L': - /* 'L' may introduce wide characters or strings. */ - if (*buffer->cur == '\'' || *buffer->cur == '"') + case 'u': + case 'U': + /* 'L', 'u' or 'U' may introduce wide characters or strings. */ + if (c == 'L' || CPP_OPTION (pfile, uliterals)) { - lex_string (pfile, result, buffer->cur - 1); - break; + if (*buffer->cur == '\'' || *buffer->cur == '"') + { + lex_string (pfile, result, buffer->cur - 1); + break; + } } /* Fall through. */ @@ -1367,12 +1500,12 @@ _cpp_lex_direct (cpp_reader *pfile) case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': - case 's': case 't': case 'u': case 'v': case 'w': case 'x': + case 's': case 't': case 'v': case 'w': case 'x': case 'y': case 'z': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': + case 'S': case 'T': case 'V': case 'W': case 'X': case 'Y': case 'Z': result->type = CPP_NAME; { @@ -1459,7 +1592,8 @@ _cpp_lex_direct (cpp_reader *pfile) if (pfile->state.angled_headers) { lex_string (pfile, result, buffer->cur - 1); - break; + if (result->type != CPP_LESS) + break; } result->type = CPP_LESS; @@ -1643,7 +1777,7 @@ cpp_token_len (const cpp_token *token) switch (TOKEN_SPELL (token)) { - default: len = 4; break; + default: len = 6; break; case SPELL_LITERAL: len = token->val.str.len; break; case SPELL_IDENT: len = NODE_LEN (token->val.node) * 10; break; } @@ -1933,6 +2067,51 @@ cpp_output_line (cpp_reader *pfile, FILE *fp) putc ('\n', fp); } +/* Return a string representation of all the remaining tokens on the + current line. The result is allocated using xmalloc and must be + freed by the caller. */ +unsigned char * +cpp_output_line_to_string (cpp_reader *pfile, const unsigned char *dir_name) +{ + const cpp_token *token; + unsigned int out = dir_name ? ustrlen (dir_name) : 0; + unsigned int alloced = 120 + out; + unsigned char *result = (unsigned char *) xmalloc (alloced); + + /* If DIR_NAME is empty, there are no initial contents. */ + if (dir_name) + { + sprintf ((char *) result, "#%s ", dir_name); + out += 2; + } + + token = cpp_get_token (pfile); + while (token->type != CPP_EOF) + { + unsigned char *last; + /* Include room for a possible space and the terminating nul. */ + unsigned int len = cpp_token_len (token) + 2; + + if (out + len > alloced) + { + alloced *= 2; + if (out + len > alloced) + alloced = out + len; + result = (unsigned char *) xrealloc (result, alloced); + } + + last = cpp_spell_token (pfile, token, &result[out], 0); + out = last - result; + + token = cpp_get_token (pfile); + if (token->flags & PREV_WHITE) + result[out++] = ' '; + } + + result[out] = '\0'; + return result; +} + /* Memory buffers. Changing these three constants can have a dramatic effect on performance. The values here are reasonable defaults, but might be tuned. If you adjust them, be sure to test across a diff --git a/support/cpp/libcpp/line-map.c b/support/cpp/libcpp/line-map.c index f24cca68..485ef1a7 100644 --- a/support/cpp/libcpp/line-map.c +++ b/support/cpp/libcpp/line-map.c @@ -1,10 +1,10 @@ /* Map logical line numbers to (source file, line number) pairs. - Copyright (C) 2001, 2003, 2004, 2007 + Copyright (C) 2001, 2003, 2004, 2007, 2008, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -13,8 +13,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +along with this program; see the file COPYING3. If not see +. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve @@ -81,12 +81,11 @@ linemap_free (struct line_maps *set) FROM_LINE should be monotonic increasing across calls to this function. A call to this function can relocate the previous set of - A call to this function can relocate the previous set of maps, so any stored line_map pointers should not be used. */ const struct line_map * linemap_add (struct line_maps *set, enum lc_reason reason, - unsigned int sysp, const char *to_file, unsigned int to_line) + unsigned int sysp, const char *to_file, linenum_type to_line) { struct line_map *map; source_location start_location = set->highest_location + 1; @@ -183,13 +182,13 @@ linemap_add (struct line_maps *set, enum lc_reason reason, } source_location -linemap_line_start (struct line_maps *set, unsigned int to_line, +linemap_line_start (struct line_maps *set, linenum_type to_line, unsigned int max_column_hint) { struct line_map *map = &set->maps[set->used - 1]; source_location highest = set->highest_location; source_location r; - unsigned int last_line = SOURCE_LINE (map, set->highest_line); + linenum_type last_line = SOURCE_LINE (map, set->highest_line); int line_delta = to_line - last_line; bool add_map = false; if (line_delta < 0 @@ -225,8 +224,8 @@ linemap_line_start (struct line_maps *set, unsigned int to_line, if (line_delta < 0 || last_line != map->to_line || SOURCE_COLUMN (map, highest) >= (1U << column_bits)) - map = (struct line_map*) linemap_add (set, LC_RENAME, map->sysp, - map->to_file, to_line); + map = (struct line_map *) linemap_add (set, LC_RENAME, map->sysp, + map->to_file, to_line); map->column_bits = column_bits; r = map->start_location + ((to_line - map->to_line) << column_bits); } diff --git a/support/cpp/libcpp/macro.c b/support/cpp/libcpp/macro.c index 764d5e3a..f6884946 100644 --- a/support/cpp/libcpp/macro.c +++ b/support/cpp/libcpp/macro.c @@ -1,14 +1,14 @@ /* Part of CPP library. (Macro and #define handling.) Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008 Free Software Foundation, Inc. + 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Written by Per Bothner, 1994. Based on CCCP program by Paul Rubin, June 1986 Adapted to ANSI C, Richard Stallman, Jan 1987 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +along with this program; see the file COPYING3. If not see +. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve @@ -118,7 +118,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) { const struct line_map *map; const uchar *result = NULL; - unsigned int number = 1; + linenum_type number = 1; switch (node->value.builtin) { @@ -158,7 +158,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) { cpp_errno (pfile, CPP_DL_WARNING, "could not determine file timestamp"); - pbuffer->timestamp = U"\"??? ??? ?? ??:??:?? ????\""; + pbuffer->timestamp = UC"\"??? ??? ?? ??:??:?? ????\""; } } } @@ -200,11 +200,10 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) /* If __LINE__ is embedded in a macro, it must expand to the line of the macro's invocation, not its definition. Otherwise things like assert() will not work properly. */ - if (CPP_OPTION (pfile, traditional)) - number = pfile->line_table->highest_line; - else - number = pfile->cur_token[-1].src_loc; - number = SOURCE_LINE (map, number); + number = SOURCE_LINE (map, + CPP_OPTION (pfile, traditional) + ? pfile->line_table->highest_line + : pfile->cur_token[-1].src_loc); break; /* __STDC__ has the value 1 under normal circumstances. @@ -256,8 +255,8 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node) cpp_errno (pfile, CPP_DL_WARNING, "could not determine date and time"); - pfile->date = U"\"??? ?? ????\""; - pfile->time = U"\"??:??:??\""; + pfile->date = UC"\"??? ?? ????\""; + pfile->time = UC"\"??:??:??\""; } } @@ -375,8 +374,10 @@ stringify_arg (cpp_reader *pfile, macro_arg *arg) continue; } - escape_it = (token->type == CPP_STRING || token->type == CPP_WSTRING - || token->type == CPP_CHAR || token->type == CPP_WCHAR); + escape_it = (token->type == CPP_STRING || token->type == CPP_CHAR + || token->type == CPP_WSTRING || token->type == CPP_STRING + || token->type == CPP_STRING32 || token->type == CPP_CHAR32 + || token->type == CPP_STRING16 || token->type == CPP_CHAR16); /* Room for each char being written in octal, initial space and final quote and NUL. */ @@ -815,6 +816,13 @@ enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, pfile->state.angled_headers = false; + if ((node->flags & NODE_BUILTIN) && !(node->flags & NODE_USED)) + { + node->flags |= NODE_USED; + if (pfile->cb.used_define) + pfile->cb.used_define (pfile, pfile->directive_line, node); + } + /* Handle standard macros. */ if (! (node->flags & NODE_BUILTIN)) { @@ -854,6 +862,13 @@ enter_macro_context (cpp_reader *pfile, cpp_hashnode *node, /* Disable the macro within its expansion. */ node->flags |= NODE_DISABLED; + if (!(node->flags & NODE_USED)) + { + node->flags |= NODE_USED; + if (pfile->cb.used_define) + pfile->cb.used_define (pfile, pfile->directive_line, node); + } + macro->used = 1; if (macro->paramc == 0) @@ -993,6 +1008,17 @@ replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro, macro_arg if (src->flags & PASTE_LEFT) paste_flag = dest - 1; } + else if (CPP_PEDANTIC (pfile) && ! macro->syshdr + && ! CPP_OPTION (pfile, c99) + && ! cpp_in_system_header (pfile)) + { + cpp_error (pfile, CPP_DL_PEDWARN, + "invoking macro %s argument %d: " + "empty macro arguments are undefined" + " in ISO C90 and ISO C++98", + NODE_NAME (node), + src->val.arg_no); + } /* Avoid paste on RHS (even case count == 0). */ if (!pfile->state.in_directive && !(src->flags & PASTE_LEFT)) @@ -1224,14 +1250,45 @@ cpp_get_token (cpp_reader *pfile) if (!(node->flags & NODE_DISABLED)) { - int ret; + int ret = 0; /* If not in a macro context, and we're going to start an expansion, record the location. */ if (can_set && !context->macro) pfile->invocation_location = result->src_loc; if (pfile->state.prevent_expansion) break; - ret = enter_macro_context (pfile, node, result); + + /* Conditional macros require that a predicate be evaluated + first. */ + if ((node->flags & NODE_CONDITIONAL) != 0) + { + if (pfile->cb.macro_to_expand) + { + bool whitespace_after; + const cpp_token *peek_tok = cpp_peek_token (pfile, 0); + + whitespace_after = (peek_tok->type == CPP_PADDING + || (peek_tok->flags & PREV_WHITE)); + node = pfile->cb.macro_to_expand (pfile, result); + if (node) + ret = enter_macro_context (pfile, node, result); + else if (whitespace_after) + { + /* If macro_to_expand hook returned NULL and it + ate some tokens, see if we don't need to add + a padding token in between this and the + next token. */ + peek_tok = cpp_peek_token (pfile, 0); + if (peek_tok->type != CPP_PADDING + && (peek_tok->flags & PREV_WHITE) == 0) + _cpp_push_token_context (pfile, NULL, + padding_token (pfile, + peek_tok), 1); + } + } + } + else + ret = enter_macro_context (pfile, node, result); if (ret) { if (pfile->state.in_directive || ret == 2) @@ -1311,26 +1368,31 @@ cpp_scan_nooutput (cpp_reader *pfile) pfile->state.prevent_expansion--; } -/* Step back one (or more) tokens. Can only step back more than 1 if - they are from the lexer, and not from macro expansion. */ +/* Step back one or more tokens obtained from the lexer. */ void -_cpp_backup_tokens (cpp_reader *pfile, unsigned int count) +_cpp_backup_tokens_direct (cpp_reader *pfile, unsigned int count) { - if (pfile->context->prev == NULL) + pfile->lookaheads += count; + while (count--) { - pfile->lookaheads += count; - while (count--) + pfile->cur_token--; + if (pfile->cur_token == pfile->cur_run->base + /* Possible with -fpreprocessed and no leading #line. */ + && pfile->cur_run->prev != NULL) { - pfile->cur_token--; - if (pfile->cur_token == pfile->cur_run->base - /* Possible with -fpreprocessed and no leading #line. */ - && pfile->cur_run->prev != NULL) - { - pfile->cur_run = pfile->cur_run->prev; - pfile->cur_token = pfile->cur_run->limit; - } + pfile->cur_run = pfile->cur_run->prev; + pfile->cur_token = pfile->cur_run->limit; } } +} + +/* Step back one (or more) tokens. Can only step back more than 1 if + they are from the lexer, and not from macro expansion. */ +void +_cpp_backup_tokens (cpp_reader *pfile, unsigned int count) +{ + if (pfile->context->prev == NULL) + _cpp_backup_tokens_direct (pfile, count); else { if (count != 1) @@ -1356,6 +1418,15 @@ warn_of_redefinition (cpp_reader *pfile, const cpp_hashnode *node, if (node->flags & NODE_WARN) return true; + /* Suppress warnings for builtins that lack the NODE_WARN flag. */ + if (node->flags & NODE_BUILTIN) + return false; + + /* Redefinitions of conditional (context-sensitive) macros, on + the other hand, must be allowed silently. */ + if (node->flags & NODE_CONDITIONAL) + return false; + /* Redefinition of a macro is allowed if and only if the old and new definitions are the same. (6.10.3 paragraph 2). */ macro1 = node->value.macro; @@ -1393,7 +1464,7 @@ _cpp_free_definition (cpp_hashnode *h) /* Macros and assertions no longer have anything to free. */ h->type = NT_VOID; /* Clear builtin flag in case of redefinition. */ - h->flags &= ~(NODE_BUILTIN | NODE_DISABLED); + h->flags &= ~(NODE_BUILTIN | NODE_DISABLED | NODE_USED); } /* Save parameter NODE to the parameter list of macro MACRO. Returns @@ -1789,6 +1860,10 @@ _cpp_create_definition (cpp_reader *pfile, cpp_hashnode *node) && ustrcmp (NODE_NAME (node), (const uchar *) "__STDC_CONSTANT_MACROS")) node->flags |= NODE_WARN; + /* If user defines one of the conditional macros, remove the + conditional flag */ + node->flags &= ~NODE_CONDITIONAL; + return ok; } diff --git a/support/cpp/libcpp/mkdeps.c b/support/cpp/libcpp/mkdeps.c index d4c838e7..05bd8072 100644 --- a/support/cpp/libcpp/mkdeps.c +++ b/support/cpp/libcpp/mkdeps.c @@ -1,10 +1,11 @@ /* Dependency generator for Makefile fragments. - Copyright (C) 2000, 2001, 2003, 2007 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2003, 2007, 2008, 2009 + Free Software Foundation, Inc. Contributed by Zack Weinberg, Mar 2000 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -13,8 +14,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +along with this program; see the file COPYING3. If not see +. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve @@ -30,8 +31,8 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. struct deps { const char **targetv; - unsigned int ntargets; /* number of slots actually occupied */ - unsigned int targets_size; /* amt of allocated space - in words */ + unsigned int ntargets; /* number of slots actually occupied */ + unsigned int targets_size; /* amt of allocated space - in words */ const char **depv; unsigned int ndeps; @@ -62,25 +63,30 @@ munge (const char *filename) for (p = filename, len = 0; *p; p++, len++) { switch (*p) - { - case ' ': - case '\t': - /* GNU make uses a weird quoting scheme for white space. - A space or tab preceded by 2N+1 backslashes represents - N backslashes followed by space; a space or tab - preceded by 2N backslashes represents N backslashes at - the end of a file name; and backslashes in other - contexts should not be doubled. */ - for (q = p - 1; filename <= q && *q == '\\'; q--) - len++; - len++; - break; - - case '$': - /* '$' is quoted by doubling it. */ - len++; - break; - } + { + case ' ': + case '\t': + /* GNU make uses a weird quoting scheme for white space. + A space or tab preceded by 2N+1 backslashes represents + N backslashes followed by space; a space or tab + preceded by 2N backslashes represents N backslashes at + the end of a file name; and backslashes in other + contexts should not be doubled. */ + for (q = p - 1; filename <= q && *q == '\\'; q--) + len++; + len++; + break; + + case '$': + /* '$' is quoted by doubling it. */ + len++; + break; + + case '#': + /* '#' is quoted with a backslash. */ + len++; + break; + } } /* Now we know how big to make the buffer. */ @@ -89,21 +95,25 @@ munge (const char *filename) for (p = filename, dst = buffer; *p; p++, dst++) { switch (*p) - { - case ' ': - case '\t': - for (q = p - 1; filename <= q && *q == '\\'; q--) - *dst++ = '\\'; - *dst++ = '\\'; - break; - - case '$': - *dst++ = '$'; - break; - - default: - /* nothing */; - } + { + case ' ': + case '\t': + for (q = p - 1; filename <= q && *q == '\\'; q--) + *dst++ = '\\'; + *dst++ = '\\'; + break; + + case '$': + *dst++ = '$'; + break; + + case '#': + *dst++ = '\\'; + break; + + default: + /* nothing */; + } *dst = *p; } @@ -120,24 +130,24 @@ apply_vpath (struct deps *d, const char *t) { unsigned int i; for (i = 0; i < d->nvpaths; i++) - { - if (!strncmp (d->vpathv[i], t, d->vpathlv[i])) - { - const char *p = t + d->vpathlv[i]; - if (!IS_DIR_SEPARATOR (*p)) - goto not_this_one; - - /* Do not simplify $(vpath)/../whatever. ??? Might not - be necessary. */ - if (p[1] == '.' && p[2] == '.' && IS_DIR_SEPARATOR (p[3])) - goto not_this_one; - - /* found a match */ - t = t + d->vpathlv[i] + 1; - break; - } - not_this_one:; - } + { + if (!strncmp (d->vpathv[i], t, d->vpathlv[i])) + { + const char *p = t + d->vpathlv[i]; + if (!IS_DIR_SEPARATOR (*p)) + goto not_this_one; + + /* Do not simplify $(vpath)/../whatever. ??? Might not + be necessary. */ + if (p[1] == '.' && p[2] == '.' && IS_DIR_SEPARATOR (p[3])) + goto not_this_one; + + /* found a match */ + t = t + d->vpathlv[i] + 1; + break; + } + not_this_one:; + } } /* Remove leading ./ in any case. */ @@ -145,9 +155,9 @@ apply_vpath (struct deps *d, const char *t) { t += 2; /* If we removed a leading ./, then also remove any /s after the - first. */ + first. */ while (IS_DIR_SEPARATOR (t[0])) - ++t; + ++t; } return t; @@ -169,21 +179,21 @@ deps_free (struct deps *d) if (d->targetv) { for (i = 0; i < d->ntargets; i++) - free ((void *) d->targetv[i]); + free ((void *) d->targetv[i]); free (d->targetv); } if (d->depv) { for (i = 0; i < d->ndeps; i++) - free ((void *) d->depv[i]); + free ((void *) d->depv[i]); free (d->depv); } if (d->vpathv) { for (i = 0; i < d->nvpaths; i++) - free ((void *) d->vpathv[i]); + free ((void *) d->vpathv[i]); free (d->vpathv); free (d->vpathlv); } @@ -232,6 +242,7 @@ deps_add_default_target (cpp_reader *pfile, const char *tgt) #endif const char *start = lbasename (tgt); char *o; + char *suffix; const char *obj_ext; @@ -248,7 +259,6 @@ deps_add_default_target (cpp_reader *pfile, const char *tgt) obj_ext = CPP_OPTION (pfile, obj_ext); o = (char *) alloca (strlen (start) + strlen (obj_ext) + 1); - strcpy (o, start); suffix = strrchr (o, '.'); @@ -288,14 +298,14 @@ deps_add_vpath (struct deps *d, const char *vpath) memcpy (copy, elem, len); copy[len] = '\0'; if (*p == ':') - p++; + p++; if (d->nvpaths == d->vpaths_size) - { - d->vpaths_size = d->vpaths_size * 2 + 8; - d->vpathv = XRESIZEVEC (const char *, d->vpathv, d->vpaths_size); - d->vpathlv = XRESIZEVEC (size_t, d->vpathlv, d->vpaths_size); - } + { + d->vpaths_size = d->vpaths_size * 2 + 8; + d->vpathv = XRESIZEVEC (const char *, d->vpathv, d->vpaths_size); + d->vpathlv = XRESIZEVEC (size_t, d->vpathlv, d->vpaths_size); + } d->vpathv[d->nvpaths] = copy; d->vpathlv[d->nvpaths] = len; d->nvpaths++; @@ -315,37 +325,39 @@ deps_write (const struct deps *d, FILE *fp, unsigned int colmax) { size = strlen (d->targetv[i]); column += size; - if (colmax && column > colmax) - { - fputs (" \\\n ", fp); - column = 1 + size; - } if (i) - { - putc (' ', fp); - column++; - } + { + if (colmax && column > colmax) + { + fputs (" \\\n ", fp); + column = 1 + size; + } + else + { + putc (' ', fp); + column++; + } + } fputs (d->targetv[i], fp); } putc (':', fp); - putc (' ', fp); - column += 2; + column++; for (i = 0; i < d->ndeps; i++) { size = strlen (d->depv[i]); column += size; if (colmax && column > colmax) - { - fputs (" \\\n ", fp); - column = 1 + size; - } - if (i) - { - putc (' ', fp); - column++; - } + { + fputs (" \\\n ", fp); + column = 1 + size; + } + else + { + putc (' ', fp); + column++; + } fputs (d->depv[i], fp); } putc ('\n', fp); @@ -415,14 +427,14 @@ deps_restore (struct deps *deps, FILE *fd, const char *self) { /* Read in # bytes in string. */ if (fread (&num_to_read, 1, sizeof (size_t), fd) != sizeof (size_t)) - return -1; + return -1; if (buf_size < num_to_read + 1) - { - buf_size = num_to_read + 1 + 127; - buf = XRESIZEVEC (char, buf, buf_size); - } + { + buf_size = num_to_read + 1 + 127; + buf = XRESIZEVEC (char, buf, buf_size); + } if (fread (buf, 1, num_to_read, fd) != num_to_read) - return -1; + return -1; buf[num_to_read] = '\0'; /* Generate makefile dependencies from .pch if -nopch-deps. */ diff --git a/support/cpp/libcpp/symtab.c b/support/cpp/libcpp/symtab.c index ffa28f5f..f2a918a7 100644 --- a/support/cpp/libcpp/symtab.c +++ b/support/cpp/libcpp/symtab.c @@ -1,9 +1,10 @@ /* Hash tables. - Copyright (C) 2000, 2001, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2003, 2004, 2008, 2009 + Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -12,8 +13,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +along with this program; see the file COPYING3. If not see +. In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve @@ -27,13 +28,15 @@ Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. hash tables (see libiberty/hashtab.c). The abstraction penalty was too high to continue using the generic form. This code knows intrinsically how to calculate a hash value, and how to compare an - existing entry with a potential new one. Also, the ability to - delete members from the table has been removed. */ + existing entry with a potential new one. */ static unsigned int calc_hash (const unsigned char *, size_t); static void ht_expand (hash_table *); static double approx_sqrt (double); +/* A deleted entry. */ +#define DELETED ((hashnode) -1) + /* Calculate the hash of the string STR of length LEN. */ static unsigned int @@ -60,8 +63,8 @@ ht_create (unsigned int order) /* Strings need no alignment. */ _obstack_begin (&table->stack, 0, 0, - (void *(*) (long)) xmalloc, - (void (*) (void *)) free); + (void *(*) (long)) xmalloc, + (void (*) (void *)) free); obstack_alignment_mask (&table->stack) = 0; @@ -83,28 +86,26 @@ ht_destroy (hash_table *table) } /* Returns the hash entry for the a STR of length LEN. If that string - already exists in the table, returns the existing entry, and, if - INSERT is CPP_ALLOCED, frees the last obstack object. If the + already exists in the table, returns the existing entry. If the identifier hasn't been seen before, and INSERT is CPP_NO_INSERT, returns NULL. Otherwise insert and returns a new entry. A new - string is alloced if INSERT is CPP_ALLOC, otherwise INSERT is - CPP_ALLOCED and the item is assumed to be at the top of the - obstack. */ + string is allocated. */ hashnode ht_lookup (hash_table *table, const unsigned char *str, size_t len, - enum ht_lookup_option insert) + enum ht_lookup_option insert) { return ht_lookup_with_hash (table, str, len, calc_hash (str, len), - insert); + insert); } hashnode ht_lookup_with_hash (hash_table *table, const unsigned char *str, - size_t len, unsigned int hash, - enum ht_lookup_option insert) + size_t len, unsigned int hash, + enum ht_lookup_option insert) { unsigned int hash2; unsigned int index; + unsigned int deleted_index = table->nslots; size_t sizemask; hashnode node; @@ -113,58 +114,63 @@ ht_lookup_with_hash (hash_table *table, const unsigned char *str, table->searches++; node = table->entries[index]; - + if (node != NULL) { - if (node->hash_value == hash - && HT_LEN (node) == (unsigned int) len - && !memcmp (HT_STR (node), str, len)) - { - if (insert == HT_ALLOCED) - /* The string we search for was placed at the end of the - obstack. Release it. */ - obstack_free (&table->stack, (void *) str); - return node; - } + if (node == DELETED) + deleted_index = index; + else if (node->hash_value == hash + && HT_LEN (node) == (unsigned int) len + && !memcmp (HT_STR (node), str, len)) + return node; /* hash2 must be odd, so we're guaranteed to visit every possible - location in the table during rehashing. */ + location in the table during rehashing. */ hash2 = ((hash * 17) & sizemask) | 1; for (;;) - { - table->collisions++; - index = (index + hash2) & sizemask; - node = table->entries[index]; - if (node == NULL) - break; - - if (node->hash_value == hash - && HT_LEN (node) == (unsigned int) len - && !memcmp (HT_STR (node), str, len)) - { - if (insert == HT_ALLOCED) - /* The string we search for was placed at the end of the - obstack. Release it. */ - obstack_free (&table->stack, (void *) str); - return node; - } - } + { + table->collisions++; + index = (index + hash2) & sizemask; + node = table->entries[index]; + if (node == NULL) + break; + + if (node == DELETED) + { + if (deleted_index != table->nslots) + deleted_index = index; + } + else if (node->hash_value == hash + && HT_LEN (node) == (unsigned int) len + && !memcmp (HT_STR (node), str, len)) + return node; + } } if (insert == HT_NO_INSERT) return NULL; + /* We prefer to overwrite the first deleted slot we saw. */ + if (deleted_index != table->nslots) + index = deleted_index; + node = (*table->alloc_node) (table); table->entries[index] = node; HT_LEN (node) = (unsigned int) len; node->hash_value = hash; - if (insert == HT_ALLOC) + + if (table->alloc_subobject) + { + char *chars = table->alloc_subobject (len + 1); + memcpy (chars, str, len); + chars[len] = '\0'; + HT_STR (node) = (const unsigned char *) chars; + } + else HT_STR (node) = (const unsigned char *) obstack_copy0 (&table->stack, str, len); - else - HT_STR (node) = str; if (++table->nelements * 4 >= table->nslots * 3) /* Must expand the string table. */ @@ -188,23 +194,23 @@ ht_expand (hash_table *table) p = table->entries; limit = p + table->nslots; do - if (*p) + if (*p && *p != DELETED) { - unsigned int index, hash, hash2; - - hash = (*p)->hash_value; - index = hash & sizemask; - - if (nentries[index]) - { - hash2 = ((hash * 17) & sizemask) | 1; - do - { - index = (index + hash2) & sizemask; - } - while (nentries[index]); - } - nentries[index] = *p; + unsigned int index, hash, hash2; + + hash = (*p)->hash_value; + index = hash & sizemask; + + if (nentries[index]) + { + hash2 = ((hash * 17) & sizemask) | 1; + do + { + index = (index + hash2) & sizemask; + } + while (nentries[index]); + } + nentries[index] = *p; } while (++p < limit); @@ -225,10 +231,28 @@ ht_forall (hash_table *table, ht_cb cb, const void *v) p = table->entries; limit = p + table->nslots; do - if (*p) + if (*p && *p != DELETED) + { + if ((*cb) (table->pfile, *p, v) == 0) + break; + } + while (++p < limit); +} + +/* Like ht_forall, but a nonzero return from the callback means that + the entry should be removed from the table. */ +void +ht_purge (hash_table *table, ht_cb cb, const void *v) +{ + hashnode *p, *limit; + + p = table->entries; + limit = p + table->nslots; + do + if (*p && *p != DELETED) { - if ((*cb) (table->pfile, *p, v) == 0) - break; + if ((*cb) (table->pfile, *p, v)) + *p = DELETED; } while (++p < limit); } @@ -236,8 +260,8 @@ ht_forall (hash_table *table, ht_cb cb, const void *v) /* Restore the hash table. */ void ht_load (hash_table *ht, hashnode *entries, - unsigned int nslots, unsigned int nelements, - bool own) + unsigned int nslots, unsigned int nelements, + bool own) { if (ht->entries_owned) free (ht->entries); @@ -253,30 +277,32 @@ void ht_dump_statistics (hash_table *table) { size_t nelts, nids, overhead, headers; - size_t total_bytes, longest; + size_t total_bytes, longest, deleted = 0; double sum_of_squares, exp_len, exp_len2, exp2_len; hashnode *p, *limit; #define SCALE(x) ((unsigned long) ((x) < 1024*10 \ - ? (x) \ - : ((x) < 1024*1024*10 \ - ? (x) / 1024 \ - : (x) / (1024*1024)))) + ? (x) \ + : ((x) < 1024*1024*10 \ + ? (x) / 1024 \ + : (x) / (1024*1024)))) #define LABEL(x) ((x) < 1024*10 ? ' ' : ((x) < 1024*1024*10 ? 'k' : 'M')) total_bytes = longest = sum_of_squares = nids = 0; p = table->entries; limit = p + table->nslots; do - if (*p) + if (*p == DELETED) + ++deleted; + else if (*p) { - size_t n = HT_LEN (*p); + size_t n = HT_LEN (*p); - total_bytes += n; - sum_of_squares += (double) n * n; - if (n > longest) - longest = n; - nids++; + total_bytes += n; + sum_of_squares += (double) n * n; + if (n > longest) + longest = n; + nids++; } while (++p < limit); @@ -285,29 +311,31 @@ ht_dump_statistics (hash_table *table) headers = table->nslots * sizeof (hashnode); fprintf (stderr, "\nString pool\nentries\t\t%lu\n", - (unsigned long) nelts); + (unsigned long) nelts); fprintf (stderr, "identifiers\t%lu (%.2f%%)\n", - (unsigned long) nids, nids * 100.0 / nelts); + (unsigned long) nids, nids * 100.0 / nelts); fprintf (stderr, "slots\t\t%lu\n", - (unsigned long) table->nslots); + (unsigned long) table->nslots); + fprintf (stderr, "deleted\t\t%lu\n", + (unsigned long) deleted); fprintf (stderr, "bytes\t\t%lu%c (%lu%c overhead)\n", - SCALE (total_bytes), LABEL (total_bytes), - SCALE (overhead), LABEL (overhead)); + SCALE (total_bytes), LABEL (total_bytes), + SCALE (overhead), LABEL (overhead)); fprintf (stderr, "table size\t%lu%c\n", - SCALE (headers), LABEL (headers)); + SCALE (headers), LABEL (headers)); exp_len = (double)total_bytes / (double)nelts; exp2_len = exp_len * exp_len; exp_len2 = (double) sum_of_squares / (double) nelts; fprintf (stderr, "coll/search\t%.4f\n", - (double) table->collisions / (double) table->searches); + (double) table->collisions / (double) table->searches); fprintf (stderr, "ins/search\t%.4f\n", - (double) nelts / (double) table->searches); + (double) nelts / (double) table->searches); fprintf (stderr, "avg. entry\t%.2f bytes (+/- %.2f)\n", - exp_len, approx_sqrt (exp_len2 - exp2_len)); + exp_len, approx_sqrt (exp_len2 - exp2_len)); fprintf (stderr, "longest entry\t%lu\n", - (unsigned long) longest); + (unsigned long) longest); #undef SCALE #undef LABEL } diff --git a/support/cpp/libcpp/system.h b/support/cpp/libcpp/system.h index 1691b34f..aad63411 100644 --- a/support/cpp/libcpp/system.h +++ b/support/cpp/libcpp/system.h @@ -1,13 +1,13 @@ /* Get common system includes and various definitions and declarations based on autoconf macros. - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. -This file is part of libcpp (aka cpplib). +This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later +Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY @@ -16,9 +16,8 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ +along with GCC; see the file COPYING3. If not see +. */ #ifndef LIBCPP_SYSTEM_H diff --git a/support/cpp/libcpp/traditional.c b/support/cpp/libcpp/traditional.c index 6a9e695c..0304a080 100644 --- a/support/cpp/libcpp/traditional.c +++ b/support/cpp/libcpp/traditional.c @@ -1,10 +1,11 @@ /* CPP Library - traditional lexical analysis and macro expansion. - Copyright (C) 2002, 2004, 2005, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2005, 2007, 2008, 2009 + Free Software Foundation, Inc. Contributed by Neil Booth, May 2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -13,8 +14,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +along with this program; see the file COPYING3. If not see +. */ #include "config.h" #include "system.h" @@ -60,7 +61,7 @@ struct fun_macro size_t offset; /* The line the macro name appeared on. */ - unsigned int line; + source_location line; /* Zero-based index of argument being currently lexed. */ unsigned int argc; @@ -253,8 +254,8 @@ lex_identifier (cpp_reader *pfile, const uchar *cur) CUR (pfile->context) = cur; len = out - pfile->out.cur; - result = (cpp_hashnode *) ht_lookup (pfile->hash_table, pfile->out.cur, - len, HT_ALLOC); + result = CPP_HASHNODE (ht_lookup (pfile->hash_table, pfile->out.cur, + len, HT_ALLOC)); pfile->out.cur = out; return result; } diff --git a/support/cpp/libcpp/ucnid.h b/support/cpp/libcpp/ucnid.h index 7323dccb..e5690b22 100644 --- a/support/cpp/libcpp/ucnid.h +++ b/support/cpp/libcpp/ucnid.h @@ -1,9 +1,9 @@ /* Unicode characters and various properties. - Copyright (C) 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any + Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -12,8 +12,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with this program; see the file COPYING3. If not see + . Copyright (C) 1991-2005 Unicode, Inc. All rights reserved. diff --git a/support/cpp/libiberty/filenames.h b/support/cpp/libiberty/filenames.h index c82950f4..28e6aa69 100644 --- a/support/cpp/libiberty/filenames.h +++ b/support/cpp/libiberty/filenames.h @@ -26,6 +26,10 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. #ifndef FILENAMES_H #define FILENAMES_H +#ifdef __cplusplus +extern "C" { +#endif + #if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__) #ifndef HAVE_DOS_BASED_FILE_SYSTEM @@ -49,4 +53,8 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. extern int filename_cmp (const char *s1, const char *s2); #define FILENAME_CMP(s1, s2) filename_cmp(s1, s2) +#ifdef __cplusplus +} +#endif + #endif /* FILENAMES_H */ diff --git a/support/cpp/libiberty/md5.c b/support/cpp/libiberty/md5.c index 83e0beb3..b7c883d5 100644 --- a/support/cpp/libiberty/md5.c +++ b/support/cpp/libiberty/md5.c @@ -47,7 +47,7 @@ #endif #ifdef WORDS_BIGENDIAN -# define SWAP(n) \ +# define SWAP(n) \ (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24)) #else # define SWAP(n) (n) @@ -112,7 +112,7 @@ md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) /* Put the 64-bit file length in *bits* at the end of the buffer. */ *(md5_uint32 *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] << 3); *(md5_uint32 *) &ctx->buffer[bytes + pad + 4] = SWAP ((ctx->total[1] << 3) | - (ctx->total[0] >> 29)); + (ctx->total[0] >> 29)); /* Process last bytes. */ md5_process_block (ctx->buffer, bytes + pad + 8, ctx); @@ -139,28 +139,28 @@ md5_stream (FILE *stream, void *resblock) while (1) { /* We read the file in blocks of BLOCKSIZE bytes. One call of the - computation function processes the whole buffer so that with the - next round of the loop another block can be read. */ + computation function processes the whole buffer so that with the + next round of the loop another block can be read. */ size_t n; sum = 0; /* Read block. Take care for partial reads. */ do - { - n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); + { + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); - sum += n; - } + sum += n; + } while (sum < BLOCKSIZE && n != 0); if (n == 0 && ferror (stream)) return 1; /* If end of file is reached, end the loop. */ if (n == 0) - break; + break; /* Process buffer with BLOCKSIZE bytes. Note that - BLOCKSIZE % 64 == 0 + BLOCKSIZE % 64 == 0 */ md5_process_block (buffer, BLOCKSIZE, &ctx); } @@ -208,13 +208,13 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx) ctx->buflen += add; if (left_over + add > 64) - { - md5_process_block (ctx->buffer, (left_over + add) & ~63, ctx); - /* The regions in the following copy operation cannot overlap. */ - memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63], - (left_over + add) & 63); - ctx->buflen = (left_over + add) & 63; - } + { + md5_process_block (ctx->buffer, (left_over + add) & ~63, ctx); + /* The regions in the following copy operation cannot overlap. */ + memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63], + (left_over + add) & 63); + ctx->buflen = (left_over + add) & 63; + } buffer = (const void *) ((const char *) buffer + add); len -= add; @@ -234,7 +234,8 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx) if (UNALIGNED_P (buffer)) while (len > 64) { - md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx); + memcpy (ctx->buffer, buffer, 64); + md5_process_block (ctx->buffer, 64, ctx); buffer = (const char *) buffer + 64; len -= 64; } @@ -296,30 +297,30 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx) md5_uint32 D_save = D; /* First round: using the given function, the context and a constant - the next context is computed. Because the algorithms processing - unit is a 32-bit word and it is determined to work on words in - little endian byte order we perhaps have to change the byte order - before the computation. To reduce the work for the next steps - we store the swapped words in the array CORRECT_WORDS. */ - -#define OP(a, b, c, d, s, T) \ - do \ - { \ - a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \ - ++words; \ - CYCLIC (a, s); \ - a += b; \ - } \ + the next context is computed. Because the algorithms processing + unit is a 32-bit word and it is determined to work on words in + little endian byte order we perhaps have to change the byte order + before the computation. To reduce the work for the next steps + we store the swapped words in the array CORRECT_WORDS. */ + +#define OP(a, b, c, d, s, T) \ + do \ + { \ + a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \ + ++words; \ + CYCLIC (a, s); \ + a += b; \ + } \ while (0) /* It is unfortunate that C does not provide an operator for - cyclic rotation. Hope the C compiler is smart enough. */ + cyclic rotation. Hope the C compiler is smart enough. */ #define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s))) /* Before we start, one word to the strange constants. - They are defined in RFC 1321 as + They are defined in RFC 1321 as - T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64 + T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64 */ /* Round 1. */ @@ -341,16 +342,16 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx) OP (B, C, D, A, 22, (md5_uint32) 0x49b40821); /* For the second to fourth round we have the possibly swapped words - in CORRECT_WORDS. Redefine the macro to take an additional first - argument specifying the function to use. */ + in CORRECT_WORDS. Redefine the macro to take an additional first + argument specifying the function to use. */ #undef OP -#define OP(a, b, c, d, k, s, T) \ - do \ - { \ - a += FX (b, c, d) + correct_words[k] + T; \ - CYCLIC (a, s); \ - a += b; \ - } \ +#define OP(a, b, c, d, k, s, T) \ + do \ + { \ + a += FX (b, c, d) + correct_words[k] + T; \ + CYCLIC (a, s); \ + a += b; \ + } \ while (0) #define FX(b, c, d) FG (b, c, d) diff --git a/support/cpp/libiberty/obstack.h b/support/cpp/libiberty/obstack.h index 88c2a264..de792505 100644 --- a/support/cpp/libiberty/obstack.h +++ b/support/cpp/libiberty/obstack.h @@ -1,6 +1,6 @@ /* obstack.h - object stack macros Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005 + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008 Free Software Foundation, Inc. @@ -91,17 +91,17 @@ growing object. This allows the use of register variables, which break the ordinary 'growth' macro. Summary: - We allocate large chunks. - We carve out one object at a time from the current chunk. - Once carved, an object never moves. - We are free to append data of any size to the currently - growing object. - Exactly one object is growing in an obstack at any one time. - You can run one obstack per control block. - You may have as many control blocks as you dare. - Because of the way we do it, you can `unwind' an obstack - back to a previous state. (You may remove objects much - as you would with a stack.) + We allocate large chunks. + We carve out one object at a time from the current chunk. + Once carved, an object never moves. + We are free to append data of any size to the currently + growing object. + Exactly one object is growing in an obstack at any one time. + You can run one obstack per control block. + You may have as many control blocks as you dare. + Because of the way we do it, you can `unwind' an obstack + back to a previous state. (You may remove objects much + as you would with a stack.) */ @@ -154,36 +154,36 @@ extern "C" { # endif #endif -struct _obstack_chunk /* Lives at front of each chunk. */ +struct _obstack_chunk /* Lives at front of each chunk. */ { - char *limit; /* 1 past end of this chunk */ - struct _obstack_chunk *prev; /* address of prior chunk or NULL */ - char contents[4]; /* objects begin here */ + char *limit; /* 1 past end of this chunk */ + struct _obstack_chunk *prev; /* address of prior chunk or NULL */ + char contents[4]; /* objects begin here */ }; -struct obstack /* control current object in current chunk */ +struct obstack /* control current object in current chunk */ { - long chunk_size; /* preferred size to allocate chunks in */ - struct _obstack_chunk *chunk; /* address of current struct obstack_chunk */ - char *object_base; /* address of object we are building */ - char *next_free; /* where to add next char to current object */ - char *chunk_limit; /* address of char after current chunk */ - PTR_INT_TYPE temp; /* Temporary for some macros. */ - int alignment_mask; /* Mask of alignment for each object. */ + long chunk_size; /* preferred size to allocate chunks in */ + struct _obstack_chunk *chunk; /* address of current struct obstack_chunk */ + char *object_base; /* address of object we are building */ + char *next_free; /* where to add next char to current object */ + char *chunk_limit; /* address of char after current chunk */ + PTR_INT_TYPE temp; /* Temporary for some macros. */ + int alignment_mask; /* Mask of alignment for each object. */ /* These prototypes vary based on `use_extra_arg', and we use casts to the prototypeless function type in all assignments, but having prototypes here quiets -Wstrict-prototypes. */ struct _obstack_chunk *(*chunkfun) (void *, long); void (*freefun) (void *, struct _obstack_chunk *); - void *extra_arg; /* first arg for chunk alloc/dealloc funcs */ - unsigned use_extra_arg:1; /* chunk alloc/dealloc funcs take extra arg */ + void *extra_arg; /* first arg for chunk alloc/dealloc funcs */ + unsigned use_extra_arg:1; /* chunk alloc/dealloc funcs take extra arg */ unsigned maybe_empty_object:1;/* There is a possibility that the current - chunk contains a zero-length object. This - prevents freeing the chunk if we allocate - a bigger chunk to replace it. */ - unsigned alloc_failed:1; /* No longer used, as we now call the failed - handler on error, but retained for binary - compatibility. */ + chunk contains a zero-length object. This + prevents freeing the chunk if we allocate + a bigger chunk to replace it. */ + unsigned alloc_failed:1; /* No longer used, as we now call the failed + handler on error, but retained for binary + compatibility. */ }; /* Declare the external functions we use; they are in obstack.c. */ @@ -191,10 +191,10 @@ struct obstack /* control current object in current chunk */ extern void _obstack_newchunk (struct obstack *, int); extern void _obstack_free (struct obstack *, void *); extern int _obstack_begin (struct obstack *, int, int, - void *(*) (long), void (*) (void *)); + void *(*) (long), void (*) (void *)); extern int _obstack_begin_1 (struct obstack *, int, int, - void *(*) (void *, long), - void (*) (void *, void *), void *); + void *(*) (void *, long), + void (*) (void *, void *), void *); extern int _obstack_memory_used (struct obstack *); /* Do the function-declarations after the structs @@ -255,7 +255,7 @@ extern int obstack_exit_failure; /* Pointer to next byte not yet allocated in current chunk. */ -#define obstack_next_free(h) ((h)->next_free) +#define obstack_next_free(h) ((h)->next_free) /* Mask specifying low bits that should be clear in address of an object. */ @@ -265,20 +265,20 @@ extern int obstack_exit_failure; standard C version. */ # define obstack_init(h) \ _obstack_begin ((h), 0, 0, \ - (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free) + (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free) # define obstack_begin(h, size) \ _obstack_begin ((h), (size), 0, \ - (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free) + (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free) # define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \ _obstack_begin ((h), (size), (alignment), \ - (void *(*) (long)) (chunkfun), (void (*) (void *)) (freefun)) + (void *(*) (long)) (chunkfun), (void (*) (void *)) (freefun)) # define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ _obstack_begin_1 ((h), (size), (alignment), \ - (void *(*) (void *, long)) (chunkfun), \ - (void (*) (void *, void *)) (freefun), (arg)) + (void *(*) (void *, long)) (chunkfun), \ + (void (*) (void *, void *)) (freefun), (arg)) # define obstack_chunkfun(h, newchunkfun) \ ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun)) @@ -305,141 +305,141 @@ extern int obstack_exit_failure; without using a global variable. Also, we can avoid using the `temp' slot, to make faster code. */ -# define obstack_object_size(OBSTACK) \ - __extension__ \ - ({ struct obstack *__o = (OBSTACK); \ +# define obstack_object_size(OBSTACK) \ + __extension__ \ + ({ struct obstack *__o = (OBSTACK); \ (unsigned) (__o->next_free - __o->object_base); }) -# define obstack_room(OBSTACK) \ - __extension__ \ - ({ struct obstack *__o = (OBSTACK); \ +# define obstack_room(OBSTACK) \ + __extension__ \ + ({ struct obstack *__o = (OBSTACK); \ (unsigned) (__o->chunk_limit - __o->next_free); }) -# define obstack_make_room(OBSTACK,length) \ -__extension__ \ -({ struct obstack *__o = (OBSTACK); \ - int __len = (length); \ - if (__o->chunk_limit - __o->next_free < __len) \ - _obstack_newchunk (__o, __len); \ +# define obstack_make_room(OBSTACK,length) \ +__extension__ \ +({ struct obstack *__o = (OBSTACK); \ + int __len = (length); \ + if (__o->chunk_limit - __o->next_free < __len) \ + _obstack_newchunk (__o, __len); \ (void) 0; }) -# define obstack_empty_p(OBSTACK) \ - __extension__ \ - ({ struct obstack *__o = (OBSTACK); \ +# define obstack_empty_p(OBSTACK) \ + __extension__ \ + ({ struct obstack *__o = (OBSTACK); \ (__o->chunk->prev == 0 && __o->next_free - __o->chunk->contents == 0); }) -# define obstack_grow(OBSTACK,where,length) \ -__extension__ \ -({ struct obstack *__o = (OBSTACK); \ - int __len = (length); \ - if (__o->next_free + __len > __o->chunk_limit) \ - _obstack_newchunk (__o, __len); \ - _obstack_memcpy (__o->next_free, (where), __len); \ - __o->next_free += __len; \ +# define obstack_grow(OBSTACK,where,length) \ +__extension__ \ +({ struct obstack *__o = (OBSTACK); \ + int __len = (length); \ + if (__o->next_free + __len > __o->chunk_limit) \ + _obstack_newchunk (__o, __len); \ + _obstack_memcpy (__o->next_free, (where), __len); \ + __o->next_free += __len; \ (void) 0; }) -# define obstack_grow0(OBSTACK,where,length) \ -__extension__ \ -({ struct obstack *__o = (OBSTACK); \ - int __len = (length); \ - if (__o->next_free + __len + 1 > __o->chunk_limit) \ - _obstack_newchunk (__o, __len + 1); \ - _obstack_memcpy (__o->next_free, (where), __len); \ - __o->next_free += __len; \ - *(__o->next_free)++ = 0; \ +# define obstack_grow0(OBSTACK,where,length) \ +__extension__ \ +({ struct obstack *__o = (OBSTACK); \ + int __len = (length); \ + if (__o->next_free + __len + 1 > __o->chunk_limit) \ + _obstack_newchunk (__o, __len + 1); \ + _obstack_memcpy (__o->next_free, (where), __len); \ + __o->next_free += __len; \ + *(__o->next_free)++ = 0; \ (void) 0; }) -# define obstack_1grow(OBSTACK,datum) \ -__extension__ \ -({ struct obstack *__o = (OBSTACK); \ - if (__o->next_free + 1 > __o->chunk_limit) \ - _obstack_newchunk (__o, 1); \ - obstack_1grow_fast (__o, datum); \ +# define obstack_1grow(OBSTACK,datum) \ +__extension__ \ +({ struct obstack *__o = (OBSTACK); \ + if (__o->next_free + 1 > __o->chunk_limit) \ + _obstack_newchunk (__o, 1); \ + obstack_1grow_fast (__o, datum); \ (void) 0; }) /* These assume that the obstack alignment is good enough for pointers or ints, and that the data added so far to the current object shares that much alignment. */ -# define obstack_ptr_grow(OBSTACK,datum) \ -__extension__ \ -({ struct obstack *__o = (OBSTACK); \ - if (__o->next_free + sizeof (void *) > __o->chunk_limit) \ - _obstack_newchunk (__o, sizeof (void *)); \ +# define obstack_ptr_grow(OBSTACK,datum) \ +__extension__ \ +({ struct obstack *__o = (OBSTACK); \ + if (__o->next_free + sizeof (void *) > __o->chunk_limit) \ + _obstack_newchunk (__o, sizeof (void *)); \ obstack_ptr_grow_fast (__o, datum); }) -# define obstack_int_grow(OBSTACK,datum) \ -__extension__ \ -({ struct obstack *__o = (OBSTACK); \ - if (__o->next_free + sizeof (int) > __o->chunk_limit) \ - _obstack_newchunk (__o, sizeof (int)); \ +# define obstack_int_grow(OBSTACK,datum) \ +__extension__ \ +({ struct obstack *__o = (OBSTACK); \ + if (__o->next_free + sizeof (int) > __o->chunk_limit) \ + _obstack_newchunk (__o, sizeof (int)); \ obstack_int_grow_fast (__o, datum); }) -# define obstack_ptr_grow_fast(OBSTACK,aptr) \ -__extension__ \ -({ struct obstack *__o1 = (OBSTACK); \ - *(const void **) __o1->next_free = (aptr); \ - __o1->next_free += sizeof (const void *); \ +# define obstack_ptr_grow_fast(OBSTACK,aptr) \ +__extension__ \ +({ struct obstack *__o1 = (OBSTACK); \ + *(const void **) __o1->next_free = (aptr); \ + __o1->next_free += sizeof (const void *); \ (void) 0; }) -# define obstack_int_grow_fast(OBSTACK,aint) \ -__extension__ \ -({ struct obstack *__o1 = (OBSTACK); \ - *(int *) __o1->next_free = (aint); \ - __o1->next_free += sizeof (int); \ +# define obstack_int_grow_fast(OBSTACK,aint) \ +__extension__ \ +({ struct obstack *__o1 = (OBSTACK); \ + *(int *) __o1->next_free = (aint); \ + __o1->next_free += sizeof (int); \ (void) 0; }) -# define obstack_blank(OBSTACK,length) \ -__extension__ \ -({ struct obstack *__o = (OBSTACK); \ - int __len = (length); \ - if (__o->chunk_limit - __o->next_free < __len) \ - _obstack_newchunk (__o, __len); \ - obstack_blank_fast (__o, __len); \ +# define obstack_blank(OBSTACK,length) \ +__extension__ \ +({ struct obstack *__o = (OBSTACK); \ + int __len = (length); \ + if (__o->chunk_limit - __o->next_free < __len) \ + _obstack_newchunk (__o, __len); \ + obstack_blank_fast (__o, __len); \ (void) 0; }) -# define obstack_alloc(OBSTACK,length) \ -__extension__ \ -({ struct obstack *__h = (OBSTACK); \ - obstack_blank (__h, (length)); \ +# define obstack_alloc(OBSTACK,length) \ +__extension__ \ +({ struct obstack *__h = (OBSTACK); \ + obstack_blank (__h, (length)); \ obstack_finish (__h); }) -# define obstack_copy(OBSTACK,where,length) \ -__extension__ \ -({ struct obstack *__h = (OBSTACK); \ - obstack_grow (__h, (where), (length)); \ +# define obstack_copy(OBSTACK,where,length) \ +__extension__ \ +({ struct obstack *__h = (OBSTACK); \ + obstack_grow (__h, (where), (length)); \ obstack_finish (__h); }) -# define obstack_copy0(OBSTACK,where,length) \ -__extension__ \ -({ struct obstack *__h = (OBSTACK); \ - obstack_grow0 (__h, (where), (length)); \ +# define obstack_copy0(OBSTACK,where,length) \ +__extension__ \ +({ struct obstack *__h = (OBSTACK); \ + obstack_grow0 (__h, (where), (length)); \ obstack_finish (__h); }) /* The local variable is named __o1 to avoid a name conflict when obstack_blank is called. */ -# define obstack_finish(OBSTACK) \ -__extension__ \ -({ struct obstack *__o1 = (OBSTACK); \ - void *value; \ - value = (void *) __o1->object_base; \ - if (__o1->next_free == value) \ - __o1->maybe_empty_object = 1; \ - __o1->next_free \ +# define obstack_finish(OBSTACK) \ +__extension__ \ +({ struct obstack *__o1 = (OBSTACK); \ + void *value; \ + value = (void *) __o1->object_base; \ + if (__o1->next_free == value) \ + __o1->maybe_empty_object = 1; \ + __o1->next_free \ = __INT_TO_PTR ((__PTR_TO_INT (__o1->next_free)+__o1->alignment_mask)\ - & ~ (__o1->alignment_mask)); \ - if (__o1->next_free - (char *)__o1->chunk \ - > __o1->chunk_limit - (char *)__o1->chunk) \ - __o1->next_free = __o1->chunk_limit; \ - __o1->object_base = __o1->next_free; \ + & ~ (__o1->alignment_mask)); \ + if (__o1->next_free - (char *)__o1->chunk \ + > __o1->chunk_limit - (char *)__o1->chunk) \ + __o1->next_free = __o1->chunk_limit; \ + __o1->object_base = __o1->next_free; \ value; }) -# define obstack_free(OBSTACK, OBJ) \ -__extension__ \ -({ struct obstack *__o = (OBSTACK); \ - void *__obj = (void *) (OBJ); \ +# define obstack_free(OBSTACK, OBJ) \ +__extension__ \ +({ struct obstack *__o = (OBSTACK); \ + void *__obj = (void *) (OBJ); \ if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \ - __o->next_free = __o->object_base = (char *) __obj; \ + __o->next_free = __o->object_base = (char *) __obj; \ else (obstack_free) (__o, __obj); }) #else /* not __GNUC__ or not __STDC__ */ @@ -447,7 +447,7 @@ __extension__ \ # define obstack_object_size(h) \ (unsigned) ((h)->next_free - (h)->object_base) -# define obstack_room(h) \ +# define obstack_room(h) \ (unsigned) ((h)->chunk_limit - (h)->next_free) # define obstack_empty_p(h) \ @@ -459,87 +459,87 @@ __extension__ \ Casting the third operand to void was tried before, but some compilers won't accept it. */ -# define obstack_make_room(h,length) \ -( (h)->temp = (length), \ - (((h)->next_free + (h)->temp > (h)->chunk_limit) \ +# define obstack_make_room(h,length) \ +( (h)->temp = (length), \ + (((h)->next_free + (h)->temp > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), (h)->temp), 0) : 0)) -# define obstack_grow(h,where,length) \ -( (h)->temp = (length), \ - (((h)->next_free + (h)->temp > (h)->chunk_limit) \ - ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ - _obstack_memcpy ((h)->next_free, (where), (h)->temp), \ +# define obstack_grow(h,where,length) \ +( (h)->temp = (length), \ + (((h)->next_free + (h)->temp > (h)->chunk_limit) \ + ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ + _obstack_memcpy ((h)->next_free, (where), (h)->temp), \ (h)->next_free += (h)->temp) -# define obstack_grow0(h,where,length) \ -( (h)->temp = (length), \ - (((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \ - ? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \ - _obstack_memcpy ((h)->next_free, (where), (h)->temp), \ - (h)->next_free += (h)->temp, \ +# define obstack_grow0(h,where,length) \ +( (h)->temp = (length), \ + (((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \ + ? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \ + _obstack_memcpy ((h)->next_free, (where), (h)->temp), \ + (h)->next_free += (h)->temp, \ *((h)->next_free)++ = 0) -# define obstack_1grow(h,datum) \ -( (((h)->next_free + 1 > (h)->chunk_limit) \ - ? (_obstack_newchunk ((h), 1), 0) : 0), \ +# define obstack_1grow(h,datum) \ +( (((h)->next_free + 1 > (h)->chunk_limit) \ + ? (_obstack_newchunk ((h), 1), 0) : 0), \ obstack_1grow_fast (h, datum)) -# define obstack_ptr_grow(h,datum) \ -( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \ - ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \ +# define obstack_ptr_grow(h,datum) \ +( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \ + ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \ obstack_ptr_grow_fast (h, datum)) -# define obstack_int_grow(h,datum) \ -( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \ - ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \ +# define obstack_int_grow(h,datum) \ +( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \ + ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \ obstack_int_grow_fast (h, datum)) -# define obstack_ptr_grow_fast(h,aptr) \ +# define obstack_ptr_grow_fast(h,aptr) \ (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr)) -# define obstack_int_grow_fast(h,aint) \ +# define obstack_int_grow_fast(h,aint) \ (((int *) ((h)->next_free += sizeof (int)))[-1] = (aptr)) -# define obstack_blank(h,length) \ -( (h)->temp = (length), \ - (((h)->chunk_limit - (h)->next_free < (h)->temp) \ - ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ +# define obstack_blank(h,length) \ +( (h)->temp = (length), \ + (((h)->chunk_limit - (h)->next_free < (h)->temp) \ + ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ obstack_blank_fast (h, (h)->temp)) -# define obstack_alloc(h,length) \ +# define obstack_alloc(h,length) \ (obstack_blank ((h), (length)), obstack_finish ((h))) -# define obstack_copy(h,where,length) \ +# define obstack_copy(h,where,length) \ (obstack_grow ((h), (where), (length)), obstack_finish ((h))) -# define obstack_copy0(h,where,length) \ +# define obstack_copy0(h,where,length) \ (obstack_grow0 ((h), (where), (length)), obstack_finish ((h))) -# define obstack_finish(h) \ -( ((h)->next_free == (h)->object_base \ - ? (((h)->maybe_empty_object = 1), 0) \ - : 0), \ - (h)->temp = __PTR_TO_INT ((h)->object_base), \ - (h)->next_free \ - = __INT_TO_PTR ((__PTR_TO_INT ((h)->next_free)+(h)->alignment_mask) \ - & ~ ((h)->alignment_mask)), \ - (((h)->next_free - (char *) (h)->chunk \ - > (h)->chunk_limit - (char *) (h)->chunk) \ - ? ((h)->next_free = (h)->chunk_limit) : 0), \ - (h)->object_base = (h)->next_free, \ - __INT_TO_PTR ((h)->temp)) - -# define obstack_free(h,obj) \ -( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \ +# define obstack_finish(h) \ +( ((h)->next_free == (h)->object_base \ + ? (((h)->maybe_empty_object = 1), 0) \ + : 0), \ + (h)->temp = __PTR_TO_INT ((h)->object_base), \ + (h)->next_free \ + = __INT_TO_PTR ((__PTR_TO_INT ((h)->next_free)+(h)->alignment_mask) \ + & ~ ((h)->alignment_mask)), \ + (((h)->next_free - (char *) (h)->chunk \ + > (h)->chunk_limit - (char *) (h)->chunk) \ + ? ((h)->next_free = (h)->chunk_limit) : 0), \ + (h)->object_base = (h)->next_free, \ + (void *) __INT_TO_PTR ((h)->temp)) + +# define obstack_free(h,obj) \ +( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \ (((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\ - ? (int) ((h)->next_free = (h)->object_base \ - = (h)->temp + (char *) (h)->chunk) \ + ? (int) ((h)->next_free = (h)->object_base \ + = (h)->temp + (char *) (h)->chunk) \ : (((obstack_free) ((h), (h)->temp + (char *) (h)->chunk), 0), 0))) #endif /* not __GNUC__ or not __STDC__ */ #ifdef __cplusplus -} /* C++ */ +} /* C++ */ #endif #endif /* obstack.h */ diff --git a/support/cpp/libiberty/safe-ctype.h b/support/cpp/libiberty/safe-ctype.h index e59b357c..0f8d1d31 100644 --- a/support/cpp/libiberty/safe-ctype.h +++ b/support/cpp/libiberty/safe-ctype.h @@ -35,10 +35,6 @@ Boston, MA 02110-1301, USA. */ #ifndef SAFE_CTYPE_H #define SAFE_CTYPE_H -#ifdef isalpha - #error "safe-ctype.h and ctype.h may not be used simultaneously" -#endif - /* Determine host character set. */ #define HOST_CHARSET_UNKNOWN 0 #define HOST_CHARSET_ASCII 1 @@ -60,29 +56,29 @@ Boston, MA 02110-1301, USA. */ enum { /* In C99 */ - _sch_isblank = 0x0001, /* space \t */ - _sch_iscntrl = 0x0002, /* nonprinting characters */ - _sch_isdigit = 0x0004, /* 0-9 */ - _sch_islower = 0x0008, /* a-z */ - _sch_isprint = 0x0010, /* any printing character including ' ' */ - _sch_ispunct = 0x0020, /* all punctuation */ - _sch_isspace = 0x0040, /* space \t \n \r \f \v */ - _sch_isupper = 0x0080, /* A-Z */ - _sch_isxdigit = 0x0100, /* 0-9A-Fa-f */ + _sch_isblank = 0x0001, /* space \t */ + _sch_iscntrl = 0x0002, /* nonprinting characters */ + _sch_isdigit = 0x0004, /* 0-9 */ + _sch_islower = 0x0008, /* a-z */ + _sch_isprint = 0x0010, /* any printing character including ' ' */ + _sch_ispunct = 0x0020, /* all punctuation */ + _sch_isspace = 0x0040, /* space \t \n \r \f \v */ + _sch_isupper = 0x0080, /* A-Z */ + _sch_isxdigit = 0x0100, /* 0-9A-Fa-f */ /* Extra categories useful to cpplib. */ - _sch_isidst = 0x0200, /* A-Za-z_ */ - _sch_isvsp = 0x0400, /* \n \r */ - _sch_isnvsp = 0x0800, /* space \t \f \v \0 */ + _sch_isidst = 0x0200, /* A-Za-z_ */ + _sch_isvsp = 0x0400, /* \n \r */ + _sch_isnvsp = 0x0800, /* space \t \f \v \0 */ /* Combinations of the above. */ - _sch_isalpha = _sch_isupper|_sch_islower, /* A-Za-z */ - _sch_isalnum = _sch_isalpha|_sch_isdigit, /* A-Za-z0-9 */ - _sch_isidnum = _sch_isidst|_sch_isdigit, /* A-Za-z0-9_ */ - _sch_isgraph = _sch_isalnum|_sch_ispunct, /* isprint and not space */ - _sch_iscppsp = _sch_isvsp|_sch_isnvsp, /* isspace + \0 */ + _sch_isalpha = _sch_isupper|_sch_islower, /* A-Za-z */ + _sch_isalnum = _sch_isalpha|_sch_isdigit, /* A-Za-z0-9 */ + _sch_isidnum = _sch_isidst|_sch_isdigit, /* A-Za-z0-9_ */ + _sch_isgraph = _sch_isalnum|_sch_ispunct, /* isprint and not space */ + _sch_iscppsp = _sch_isvsp|_sch_isnvsp, /* isspace + \0 */ _sch_isbasic = _sch_isprint|_sch_iscppsp /* basic charset of ISO C - (plus ` and @) */ + (plus ` and @) */ }; /* Character classification. */ @@ -103,12 +99,12 @@ extern const unsigned short _sch_istable[256]; #define ISUPPER(c) _sch_test(c, _sch_isupper) #define ISXDIGIT(c) _sch_test(c, _sch_isxdigit) -#define ISIDNUM(c) _sch_test(c, _sch_isidnum) -#define ISIDST(c) _sch_test(c, _sch_isidst) -#define IS_ISOBASIC(c) _sch_test(c, _sch_isbasic) -#define IS_VSPACE(c) _sch_test(c, _sch_isvsp) -#define IS_NVSPACE(c) _sch_test(c, _sch_isnvsp) -#define IS_SPACE_OR_NUL(c) _sch_test(c, _sch_iscppsp) +#define ISIDNUM(c) _sch_test(c, _sch_isidnum) +#define ISIDST(c) _sch_test(c, _sch_isidst) +#define IS_ISOBASIC(c) _sch_test(c, _sch_isbasic) +#define IS_VSPACE(c) _sch_test(c, _sch_isvsp) +#define IS_NVSPACE(c) _sch_test(c, _sch_isnvsp) +#define IS_SPACE_OR_NUL(c) _sch_test(c, _sch_iscppsp) /* Character transformation. */ extern const unsigned char _sch_toupper[256]; @@ -116,4 +112,39 @@ extern const unsigned char _sch_tolower[256]; #define TOUPPER(c) _sch_toupper[(c) & 0xff] #define TOLOWER(c) _sch_tolower[(c) & 0xff] +/* Prevent the users of safe-ctype.h from accidently using the routines + from ctype.h. Initially, the approach was to produce an error when + detecting that ctype.h has been included. But this was causing + trouble as ctype.h might get indirectly included as a result of + including another system header (for instance gnulib's stdint.h). + So we include ctype.h here and then immediately redefine its macros. */ + +#include +#undef isalpha +#define isalpha(c) do_not_use_isalpha_with_safe_ctype +#undef isalnum +#define isalnum(c) do_not_use_isalnum_with_safe_ctype +#undef iscntrl +#define iscntrl(c) do_not_use_iscntrl_with_safe_ctype +#undef isdigit +#define isdigit(c) do_not_use_isdigit_with_safe_ctype +#undef isgraph +#define isgraph(c) do_not_use_isgraph_with_safe_ctype +#undef islower +#define islower(c) do_not_use_islower_with_safe_ctype +#undef isprint +#define isprint(c) do_not_use_isprint_with_safe_ctype +#undef ispunct +#define ispunct(c) do_not_use_ispunct_with_safe_ctype +#undef isspace +#define isspace(c) do_not_use_isspace_with_safe_ctype +#undef isupper +#define isupper(c) do_not_use_isupper_with_safe_ctype +#undef isxdigit +#define isxdigit(c) do_not_use_isxdigit_with_safe_ctype +#undef toupper +#define toupper(c) do_not_use_toupper_with_safe_ctype +#undef tolower +#define tolower(c) do_not_use_tolower_with_safe_ctype + #endif /* SAFE_CTYPE_H */ diff --git a/support/cpp/libiberty/xstrdup.c b/support/cpp/libiberty/xstrdup.c index 9ac2ea03..fa12c96a 100644 --- a/support/cpp/libiberty/xstrdup.c +++ b/support/cpp/libiberty/xstrdup.c @@ -13,10 +13,10 @@ obtain memory. */ -#include #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include #ifdef HAVE_STRING_H #include #else diff --git a/support/cpp/opts-common.c b/support/cpp/opts-common.c index dcbbe2c1..f442c560 100644 --- a/support/cpp/opts-common.c +++ b/support/cpp/opts-common.c @@ -1,11 +1,11 @@ /* Command line option handling. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later +Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY @@ -14,9 +14,8 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ +along with GCC; see the file COPYING3. If not see +. */ #include "config.h" #include "system.h" @@ -38,7 +37,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA before having tested "-g". This doesn't match, and as "-gen-decls" is less than "-gstabs", it will become the lower bound of the binary search range, and "-g" will never be seen. To resolve this - issue, opts.sh makes "-gen-decls" point, via the back_chain member, + issue, 'optc-gen.awk' makes "-gen-decls" point, via the back_chain member, to "-g" so that failed searches that end between "-gen-decls" and the lexicographically subsequent switch know to go back and see if "-g" causes a match (which it does in this example). @@ -66,9 +65,9 @@ find_opt (const char *input, int lang_mask) comp = strncmp (input, cl_options[md].opt_text + 1, opt_len); if (comp < 0) - mx = md; + mx = md; else - mn = md; + mn = md; } /* This is the switch that is the best match but for a different @@ -83,22 +82,22 @@ find_opt (const char *input, int lang_mask) const struct cl_option *opt = &cl_options[mn]; /* Is the input either an exact match or a prefix that takes a - joined argument? */ + joined argument? */ if (!strncmp (input, opt->opt_text + 1, opt->opt_len) - && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED))) - { - /* If language is OK, return it. */ - if (opt->flags & lang_mask) - return mn; - - /* If we haven't remembered a prior match, remember this - one. Any prior match is necessarily better. */ - if (match_wrong_lang == cl_options_count) - match_wrong_lang = mn; - } + && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED))) + { + /* If language is OK, return it. */ + if (opt->flags & lang_mask) + return mn; + + /* If we haven't remembered a prior match, remember this + one. Any prior match is necessarily better. */ + if (match_wrong_lang == cl_options_count) + match_wrong_lang = mn; + } /* Try the next possibility. This is cl_options_count if there - are no more. */ + are no more. */ mn = opt->back_chain; } while (mn != cl_options_count); @@ -120,8 +119,8 @@ cancel_option (int opt_idx, int next_opt_idx, int orig_next_opt_idx) if (cl_options [next_opt_idx].neg_index != orig_next_opt_idx) return cancel_option (opt_idx, cl_options [next_opt_idx].neg_index, - orig_next_opt_idx); - + orig_next_opt_idx); + return false; } @@ -131,8 +130,8 @@ void prune_options (int *argcp, char ***argvp) { int argc = *argcp; - int *options = xmalloc (argc * sizeof (*options)); - char **argv = xmalloc (argc * sizeof (char *)); + int *options = XNEWVEC (int, argc); + char **argv = XNEWVEC (char *, argc); int i, arg_count, need_prune = 0; const struct cl_option *option; size_t opt_index; @@ -145,43 +144,43 @@ prune_options (int *argcp, char ***argvp) opt_index = find_opt (opt + 1, -1); if (opt_index == cl_options_count - && (opt[1] == 'W' || opt[1] == 'f' || opt[1] == 'm') - && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-') - { - char *dup; - - /* Drop the "no-" from negative switches. */ - size_t len = strlen (opt) - 3; - - dup = XNEWVEC (char, len + 1); - dup[0] = '-'; - dup[1] = opt[1]; - memcpy (dup + 2, opt + 5, len - 2 + 1); - opt = dup; - value = 0; - opt_index = find_opt (opt + 1, -1); - free (dup); - } + && (opt[1] == 'W' || opt[1] == 'f' || opt[1] == 'm') + && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-') + { + char *dup; + + /* Drop the "no-" from negative switches. */ + size_t len = strlen (opt) - 3; + + dup = XNEWVEC (char, len + 1); + dup[0] = '-'; + dup[1] = opt[1]; + memcpy (dup + 2, opt + 5, len - 2 + 1); + opt = dup; + value = 0; + opt_index = find_opt (opt + 1, -1); + free (dup); + } if (opt_index == cl_options_count) - { + { cont: - options [i] = 0; - continue; - } + options [i] = 0; + continue; + } option = &cl_options[opt_index]; if (option->neg_index < 0) - goto cont; + goto cont; /* Skip joined switches. */ if ((option->flags & CL_JOINED)) - goto cont; + goto cont; /* Reject negative form of switches that don't take negatives as - unrecognized. */ + unrecognized. */ if (!value && (option->flags & CL_REJECT_NEGATIVE)) - goto cont; + goto cont; options [i] = (int) opt_index; need_prune |= options [i]; @@ -199,26 +198,26 @@ cont: opt_idx = options [i]; if (opt_idx) - { - int next_opt_idx; - for (j = i + 1; j < argc; j++) - { - next_opt_idx = options [j]; - if (next_opt_idx - && cancel_option (opt_idx, next_opt_idx, - next_opt_idx)) - break; - } - } + { + int next_opt_idx; + for (j = i + 1; j < argc; j++) + { + next_opt_idx = options [j]; + if (next_opt_idx + && cancel_option (opt_idx, next_opt_idx, + next_opt_idx)) + break; + } + } else - goto keep; + goto keep; if (j == argc) - { + { keep: - argv [arg_count] = (*argvp) [i]; - arg_count++; - } + argv [arg_count] = (*argvp) [i]; + arg_count++; + } } if (arg_count != argc) diff --git a/support/cpp/opts.h b/support/cpp/opts.h index 3af501fb..72114374 100644 --- a/support/cpp/opts.h +++ b/support/cpp/opts.h @@ -1,11 +1,12 @@ /* Command line option handling. - Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008 + Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later +Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY @@ -14,9 +15,8 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ +along with GCC; see the file COPYING3. If not see +. */ #ifndef GCC_OPTS_H #define GCC_OPTS_H @@ -64,18 +64,31 @@ struct cl_option_state { extern const struct cl_option cl_options[]; extern const unsigned int cl_options_count; extern const char *const lang_names[]; -extern bool no_unit_at_a_time_default; - -#define CL_DISABLED (1 << 21) /* Disabled in this configuration. */ -#define CL_TARGET (1 << 22) /* Target-specific option. */ -#define CL_REPORT (1 << 23) /* Report argument with -fverbose-asm */ -#define CL_JOINED (1 << 24) /* If takes joined argument. */ -#define CL_SEPARATE (1 << 25) /* If takes a separate argument. */ -#define CL_REJECT_NEGATIVE (1 << 26) /* Reject no- form. */ -#define CL_MISSING_OK (1 << 27) /* Missing argument OK (joined). */ -#define CL_UINTEGER (1 << 28) /* Argument is an integer >=0. */ -#define CL_COMMON (1 << 29) /* Language-independent. */ -#define CL_UNDOCUMENTED (1 << 30) /* Do not output with --help. */ +extern const unsigned int cl_lang_count; + +#define CL_PARAMS (1 << 17) /* Fake entry. Used to display --param info with --help. */ +#define CL_WARNING (1 << 18) /* Enables an (optional) warning message. */ +#define CL_OPTIMIZATION (1 << 19) /* Enables an (optional) optimization. */ +#define CL_TARGET (1 << 20) /* Target-specific option. */ +#define CL_COMMON (1 << 21) /* Language-independent. */ + +#define CL_MIN_OPTION_CLASS CL_PARAMS +#define CL_MAX_OPTION_CLASS CL_COMMON + +/* From here on the bits describe attributes of the options. + Before this point the bits have described the class of the option. + This distinction is important because --help will not list options + which only have these higher bits set. */ + +#define CL_SAVE (1 << 22) /* Target-specific option for attribute. */ +#define CL_DISABLED (1 << 23) /* Disabled in this configuration. */ +#define CL_REPORT (1 << 24) /* Report argument with -fverbose-asm */ +#define CL_JOINED (1 << 25) /* If takes joined argument. */ +#define CL_SEPARATE (1 << 26) /* If takes a separate argument. */ +#define CL_REJECT_NEGATIVE (1 << 27) /* Reject no- form. */ +#define CL_MISSING_OK (1 << 28) /* Missing argument OK (joined). */ +#define CL_UINTEGER (1 << 29) /* Argument is an integer >=0. */ +#define CL_UNDOCUMENTED (1 << 30) /* Do not output with --help. */ /* Input file names. */ @@ -91,4 +104,7 @@ extern void decode_options (unsigned int argc, const char **argv); extern int option_enabled (int opt_idx); extern bool get_option_state (int, struct cl_option_state *); +extern void enable_warning_as_error (const char *arg, int value, + unsigned int lang_mask); +extern void print_ignored_options (void); #endif diff --git a/support/cpp/output.h b/support/cpp/output.h index fda098bc..0ac1318e 100644 --- a/support/cpp/output.h +++ b/support/cpp/output.h @@ -1,13 +1,13 @@ /* Declarations for insn-output.c. These functions are defined in recog.c, final.c, and varasm.c. - Copyright (C) 1987, 1991, 1994, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1987, 1991, 1994, 1997, 1998, 1999, 2000, 2001, 2002, + 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later +Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY @@ -16,9 +16,8 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ +along with GCC; see the file COPYING3. If not see +. */ #ifndef GCC_OUTPUT_H #define GCC_OUTPUT_H @@ -98,6 +97,9 @@ extern int label_to_alignment (rtx); /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol. */ extern void output_asm_label (rtx); +/* Marks SYMBOL_REFs in x as referenced through use of assemble_external. */ +extern void mark_symbol_refs_as_used (rtx); + /* Print a memory reference operand for address X using machine-dependent assembler syntax. */ extern void output_address (rtx); @@ -145,9 +147,6 @@ extern void leaf_renumber_regs_insn (rtx); /* Locate the proper template for the given insn-code. */ extern const char *get_insn_template (int, rtx); -/* Functions in flow.c */ -extern int regno_clobbered_at_setjmp (int); - /* Functions in varasm.c. */ /* Declare DECL to be a weak symbol. */ @@ -158,6 +157,9 @@ extern void merge_weak (tree, tree); /* Emit any pending weak declarations. */ extern void weak_finish (void); +/* Emit any pending emutls declarations and initializations. */ +extern void emutls_finish (void); + /* Decode an `asm' spec for a declaration as a register name. Return the register number, or -1 if nothing specified, or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized, @@ -200,9 +202,9 @@ extern void assemble_variable (tree, int, int, int); DONT_OUTPUT_DATA is from assemble_variable. */ extern void align_variable (tree decl, bool dont_output_data); -/* Output something to declare an external symbol to the assembler. - (Most assemblers don't need this, so we normally output nothing.) - Do nothing if DECL is not external. */ +/* Queue for outputting something to declare an external symbol to the + assembler. (Most assemblers don't need this, so we normally output + nothing.) Do nothing if DECL is not external. */ extern void assemble_external (tree); /* Assemble code to leave SIZE bytes of zeros. */ @@ -265,6 +267,9 @@ extern bool assemble_integer (rtx, unsigned, unsigned, int); extern void assemble_real (REAL_VALUE_TYPE, enum machine_mode, unsigned); #endif +/* Write the address of the entity given by SYMBOL to SEC. */ +extern void assemble_addr_to_section (rtx, section *); + /* Return the size of the constant pool. */ extern int get_pool_size (void); @@ -281,7 +286,7 @@ extern void output_object_blocks (void); and has been exposed to let other functions like categorize_ctor_elements evaluate the property while walking a constructor for other purposes. */ -extern bool constructor_static_from_elts_p (tree); +extern bool constructor_static_from_elts_p (const_tree); /* Return nonzero if VALUE is a valid constant-valued expression for use in initializing a static variable; one that can be an @@ -340,7 +345,7 @@ extern int current_function_is_leaf; /* Nonzero if function being compiled doesn't modify the stack pointer (ignoring the prologue and epilogue). This is only valid after - life_analysis has run. */ + pass_stack_ptr_mod has run. */ extern int current_function_sp_is_unchanging; @@ -376,7 +381,7 @@ extern bool first_function_block_is_cold; /* Decide whether DECL needs to be in a writable section. RELOC is the same as for SELECT_SECTION. */ -extern bool decl_readonly_section (tree, int); +extern bool decl_readonly_section (const_tree, int); /* This can be used to compute RELOC for the function above, when given a constant expression. */ @@ -392,32 +397,32 @@ extern void default_function_pro_epilogue (FILE *, HOST_WIDE_INT); extern void no_asm_to_stream (FILE *); /* Flags controlling properties of a section. */ -#define SECTION_ENTSIZE 0x000ff /* entity size in section */ -#define SECTION_CODE 0x00100 /* contains code */ -#define SECTION_WRITE 0x00200 /* data is writable */ -#define SECTION_DEBUG 0x00400 /* contains debug data */ -#define SECTION_LINKONCE 0x00800 /* is linkonce */ -#define SECTION_SMALL 0x01000 /* contains "small data" */ -#define SECTION_BSS 0x02000 /* contains zeros only */ -#define SECTION_FORGET 0x04000 /* forget that we've entered the section */ -#define SECTION_MERGE 0x08000 /* contains mergeable data */ -#define SECTION_STRINGS 0x10000 /* contains zero terminated strings without - embedded zeros */ -#define SECTION_OVERRIDE 0x20000 /* allow override of default flags */ -#define SECTION_TLS 0x40000 /* contains thread-local storage */ -#define SECTION_NOTYPE 0x80000 /* don't output @progbits */ -#define SECTION_DECLARED 0x100000 /* section has been used */ -#define SECTION_STYLE_MASK 0x600000 /* bits used for SECTION_STYLE */ -#define SECTION_COMMON 0x800000 /* contains common data */ -#define SECTION_MACH_DEP 0x1000000 /* subsequent bits reserved for target */ +#define SECTION_ENTSIZE 0x000ff /* entity size in section */ +#define SECTION_CODE 0x00100 /* contains code */ +#define SECTION_WRITE 0x00200 /* data is writable */ +#define SECTION_DEBUG 0x00400 /* contains debug data */ +#define SECTION_LINKONCE 0x00800 /* is linkonce */ +#define SECTION_SMALL 0x01000 /* contains "small data" */ +#define SECTION_BSS 0x02000 /* contains zeros only */ +#define SECTION_FORGET 0x04000 /* forget that we've entered the section */ +#define SECTION_MERGE 0x08000 /* contains mergeable data */ +#define SECTION_STRINGS 0x10000 /* contains zero terminated strings without + embedded zeros */ +#define SECTION_OVERRIDE 0x20000 /* allow override of default flags */ +#define SECTION_TLS 0x40000 /* contains thread-local storage */ +#define SECTION_NOTYPE 0x80000 /* don't output @progbits */ +#define SECTION_DECLARED 0x100000 /* section has been used */ +#define SECTION_STYLE_MASK 0x600000 /* bits used for SECTION_STYLE */ +#define SECTION_COMMON 0x800000 /* contains common data */ +#define SECTION_MACH_DEP 0x1000000 /* subsequent bits reserved for target */ /* This SECTION_STYLE is used for unnamed sections that we can switch to using a special assembler directive. */ -#define SECTION_UNNAMED 0x000000 +#define SECTION_UNNAMED 0x000000 /* This SECTION_STYLE is used for named sections that we can switch to using a general section directive. */ -#define SECTION_NAMED 0x200000 +#define SECTION_NAMED 0x200000 /* This SECTION_STYLE is used for sections that we cannot switch to at all. The choice of section is implied by the directive that we use @@ -441,13 +446,13 @@ enum section_category /* To optimize loading of shared programs, define following subsections of data section: - _REL Contains data that has relocations, so they get grouped - together and dynamic linker will visit fewer pages in memory. - _RO Contains data that is otherwise read-only. This is useful - with prelinking as most relocations won't be dynamically - linked and thus stay read only. - _LOCAL Marks data containing relocations only to local objects. - These relocations will get fully resolved by prelinking. */ + _REL Contains data that has relocations, so they get grouped + together and dynamic linker will visit fewer pages in memory. + _RO Contains data that is otherwise read-only. This is useful + with prelinking as most relocations won't be dynamically + linked and thus stay read only. + _LOCAL Marks data containing relocations only to local objects. + These relocations will get fully resolved by prelinking. */ SECCAT_DATA_REL, SECCAT_DATA_REL_LOCAL, SECCAT_DATA_REL_RO, @@ -458,7 +463,10 @@ enum section_category SECCAT_BSS, SECCAT_SBSS, - SECCAT_TBSS + SECCAT_TBSS, + + SECCAT_EMUTLS_VAR, + SECCAT_EMUTLS_TMPL }; /* Information that is provided by all instances of the section type. */ @@ -506,8 +514,8 @@ struct unnamed_section GTY(()) { alignment. A false return value implies that we are relying on the rounded size to align the decl. */ typedef bool (*noswitch_section_callback) (tree decl, const char *name, - unsigned HOST_WIDE_INT size, - unsigned HOST_WIDE_INT rounded); + unsigned HOST_WIDE_INT size, + unsigned HOST_WIDE_INT rounded); /* Information about a SECTION_NOSWITCH section. */ struct noswitch_section GTY(()) { @@ -551,19 +559,23 @@ extern GTY(()) section *in_section; extern GTY(()) bool in_cold_section_p; extern section *get_unnamed_section (unsigned int, void (*) (const void *), - const void *); + const void *); extern section *get_section (const char *, unsigned int, tree); extern section *get_named_section (tree, const char *, int); extern void place_block_symbol (rtx); extern rtx get_section_anchor (struct object_block *, HOST_WIDE_INT, - enum tls_model); + enum tls_model); extern section *mergeable_constant_section (enum machine_mode, - unsigned HOST_WIDE_INT, - unsigned int); + unsigned HOST_WIDE_INT, + unsigned int); extern section *function_section (tree); extern section *unlikely_text_section (void); extern section *current_function_section (void); +/* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if + not) section for PRIORITY. */ +extern section *get_cdtor_priority_section (int, bool); + extern bool unlikely_text_section_p (section *); extern void switch_to_section (section *); extern void output_section_asm_op (const void *); @@ -573,7 +585,7 @@ extern unsigned int default_section_type_flags (tree, const char *, int); extern bool have_global_bss_p (void); extern void default_no_named_section (const char *, unsigned int, tree); extern void default_elf_asm_named_section (const char *, unsigned int, tree); -extern enum section_category categorize_decl_for_section (tree, int); +extern enum section_category categorize_decl_for_section (const_tree, int); extern void default_coff_asm_named_section (const char *, unsigned int, tree); extern void default_pe_asm_named_section (const char *, unsigned int, tree); @@ -590,16 +602,17 @@ extern void default_unique_section (tree, int); extern section *default_function_rodata_section (tree); extern section *default_no_function_rodata_section (tree); extern section *default_select_rtx_section (enum machine_mode, rtx, - unsigned HOST_WIDE_INT); + unsigned HOST_WIDE_INT); extern section *default_elf_select_rtx_section (enum machine_mode, rtx, - unsigned HOST_WIDE_INT); + unsigned HOST_WIDE_INT); extern void default_encode_section_info (tree, rtx, int); extern const char *default_strip_name_encoding (const char *); extern void default_asm_output_anchor (rtx); -extern bool default_use_anchors_for_symbol_p (rtx); -extern bool default_binds_local_p (tree); -extern bool default_binds_local_p_1 (tree, int); +extern bool default_use_anchors_for_symbol_p (const_rtx); +extern bool default_binds_local_p (const_tree); +extern bool default_binds_local_p_1 (const_tree, int); extern void default_globalize_label (FILE *, const char *); +extern void default_globalize_decl_name (FILE *, tree); extern void default_emit_unwind_label (FILE *, tree, int, int); extern void default_emit_except_table_label (FILE *); extern void default_internal_label (FILE *, const char *, unsigned long); @@ -607,7 +620,11 @@ extern void default_file_start (void); extern void file_end_indicate_exec_stack (void); extern bool default_valid_pointer_mode (enum machine_mode); -extern int default_address_cost (rtx); +extern void default_elf_asm_output_external (FILE *file, tree, + const char *); +extern int maybe_assemble_visibility (tree); + +extern int default_address_cost (rtx, bool); /* dbxout helper functions */ #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO @@ -625,7 +642,7 @@ extern void dbxout_stab_value_label (const char *); extern void dbxout_stab_value_label_diff (const char *, const char *); extern void dbxout_stab_value_internal_label (const char *, int *); extern void dbxout_stab_value_internal_label_diff (const char *, int *, - const char *); + const char *); #endif diff --git a/support/cpp/prefix.c b/support/cpp/prefix.c index 652f49b9..02301c1e 100644 --- a/support/cpp/prefix.c +++ b/support/cpp/prefix.c @@ -1,12 +1,12 @@ /* Utility to update paths from internal to external forms. - Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, + 2007 Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at +the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GCC is distributed in the hope that it will be useful, @@ -15,9 +15,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public -License along with GCC; see the file COPYING. If not, write to the Free -Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. */ +License along with GCC; see the file COPYING3. If not see +. */ /* This file contains routines to update a path, both to canonicalize the directory format and to handle any prefix translation. @@ -139,21 +138,21 @@ lookup_key (char *key) if (reg_key == (HKEY) INVALID_HANDLE_VALUE) { res = RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE", 0, - KEY_READ, ®_key); + KEY_READ, ®_key); if (res == ERROR_SUCCESS) - res = RegOpenKeyExA (reg_key, "Free Software Foundation", 0, - KEY_READ, ®_key); + res = RegOpenKeyExA (reg_key, "Free Software Foundation", 0, + KEY_READ, ®_key); if (res == ERROR_SUCCESS) - res = RegOpenKeyExA (reg_key, WIN32_REGISTRY_KEY, 0, - KEY_READ, ®_key); + res = RegOpenKeyExA (reg_key, WIN32_REGISTRY_KEY, 0, + KEY_READ, ®_key); if (res != ERROR_SUCCESS) - { - reg_key = (HKEY) INVALID_HANDLE_VALUE; - return 0; - } + { + reg_key = (HKEY) INVALID_HANDLE_VALUE; + return 0; + } } size = 32; @@ -192,33 +191,33 @@ translate_name (char *name) { code = name[0]; if (code != '@' && code != '$') - break; + break; for (keylen = 0; - (name[keylen + 1] != 0 && !IS_DIR_SEPARATOR (name[keylen + 1])); - keylen++) - ; + (name[keylen + 1] != 0 && !IS_DIR_SEPARATOR (name[keylen + 1])); + keylen++) + ; key = (char *) alloca (keylen + 1); strncpy (key, &name[1], keylen); key[keylen] = 0; if (code == '@') - { - prefix = get_key_value (key); - if (prefix == 0) - prefix = std_prefix; - } + { + prefix = get_key_value (key); + if (prefix == 0) + prefix = std_prefix; + } else - prefix = getenv (key); + prefix = getenv (key); if (prefix == 0) - prefix = PREFIX; + prefix = PREFIX; /* We used to strip trailing DIR_SEPARATORs here, but that can - sometimes yield a result with no separator when one was coded - and intended by the user, causing two path components to run - together. */ + sometimes yield a result with no separator when one was coded + and intended by the user, causing two path components to run + together. */ old_name = name; name = concat (prefix, &name[keylen + 1], NULL); @@ -235,7 +234,7 @@ tr (char *string, int c1, int c2) do { if (*string == c1) - *string = c2; + *string = c2; } while (*string++); } @@ -258,14 +257,14 @@ update_path (const char *path, const char *key) bool free_key = false; if (key[0] != '$') - { - key = concat ("@", key, NULL); - free_key = true; - } + { + key = concat ("@", key, NULL); + free_key = true; + } result = concat (key, &path[len], NULL); if (free_key) - free ((char *) key); + free (CONST_CAST (char *, key)); result = translate_name (result); } else @@ -282,50 +281,50 @@ update_path (const char *path, const char *key) p = strchr (p, '.'); if (p == NULL) - break; + break; /* Look for `/../' */ if (p[1] == '.' - && IS_DIR_SEPARATOR (p[2]) - && (p != result && IS_DIR_SEPARATOR (p[-1]))) - { - *p = 0; - if (!ALWAYS_STRIP_DOTDOT && access (result, X_OK) == 0) - { - *p = '.'; - break; - } - else - { - /* We can't access the dir, so we won't be able to - access dir/.. either. Strip out `dir/../'. If `dir' - turns out to be `.', strip one more path component. */ - dest = p; - do - { - --dest; - while (dest != result && IS_DIR_SEPARATOR (*dest)) - --dest; - while (dest != result && !IS_DIR_SEPARATOR (dest[-1])) - --dest; - } - while (dest != result && *dest == '.'); - /* If we have something like `./..' or `/..', don't - strip anything more. */ - if (*dest == '.' || IS_DIR_SEPARATOR (*dest)) - { - *p = '.'; - break; - } - src = p + 3; - while (IS_DIR_SEPARATOR (*src)) - ++src; - p = dest; - while ((*dest++ = *src++) != 0) - ; - } - } + && IS_DIR_SEPARATOR (p[2]) + && (p != result && IS_DIR_SEPARATOR (p[-1]))) + { + *p = 0; + if (!ALWAYS_STRIP_DOTDOT && access (result, X_OK) == 0) + { + *p = '.'; + break; + } + else + { + /* We can't access the dir, so we won't be able to + access dir/.. either. Strip out `dir/../'. If `dir' + turns out to be `.', strip one more path component. */ + dest = p; + do + { + --dest; + while (dest != result && IS_DIR_SEPARATOR (*dest)) + --dest; + while (dest != result && !IS_DIR_SEPARATOR (dest[-1])) + --dest; + } + while (dest != result && *dest == '.'); + /* If we have something like `./..' or `/..', don't + strip anything more. */ + if (*dest == '.' || IS_DIR_SEPARATOR (*dest)) + { + *p = '.'; + break; + } + src = p + 3; + while (IS_DIR_SEPARATOR (*src)) + ++src; + p = dest; + while ((*dest++ = *src++) != 0) + ; + } + } else - ++p; + ++p; } #ifdef UPDATE_PATH_HOST_CANONICALIZE diff --git a/support/cpp/prefix.h b/support/cpp/prefix.h index e6e653ad..c6d9ae59 100644 --- a/support/cpp/prefix.h +++ b/support/cpp/prefix.h @@ -1,11 +1,11 @@ /* Provide prototypes for functions exported from prefix.c. - Copyright (C) 1999, 2003 Free Software Foundation, Inc. + Copyright (C) 1999, 2003, 2007 Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by -the Free Software Foundation; either version 2 of the License, or (at +the Free Software Foundation; either version 3 of the License, or (at your option) any later version. GCC is distributed in the hope that it will be useful, @@ -14,9 +14,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public -License along with GCC; see the file COPYING. If not, write to the Free -Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -Boston, MA 02110-1301, USA. */ +License along with GCC; see the file COPYING3. If not see +. */ #ifndef GCC_PREFIX_H diff --git a/support/cpp/sdcpp-opts.c b/support/cpp/sdcpp-opts.c index 3a09f7a9..047b3105 100644 --- a/support/cpp/sdcpp-opts.c +++ b/support/cpp/sdcpp-opts.c @@ -171,7 +171,7 @@ defer_opt (enum opt_code code, const char *arg) unsigned int sdcpp_common_init_options (unsigned int argc, const char **argv ATTRIBUTE_UNUSED) { - parse_in = cpp_create_reader (CLK_GNUC89, NULL, &line_table); + parse_in = cpp_create_reader (CLK_GNUC89, NULL, line_table); cpp_opts = cpp_get_options (parse_in); cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS; @@ -231,23 +231,23 @@ sdcpp_common_handle_option (size_t scode, const char *arg, int value) case OPT_I: if (strcmp (arg, "-")) - add_path (xstrdup (arg), BRACKET, 0, true); + add_path (xstrdup (arg), BRACKET, 0, true); else - { - if (quote_chain_split) - error ("-I- specified twice"); - quote_chain_split = true; - split_quote_chain (); - inform ("obsolete option -I- used, please use -iquote instead"); - } + { + if (quote_chain_split) + error ("-I- specified twice"); + quote_chain_split = true; + split_quote_chain (); + inform ("obsolete option -I- used, please use -iquote instead"); + } break; case OPT_M: case OPT_MM: /* When doing dependencies with -M or -MM, suppress normal - preprocessed output, but still do -dM etc. as software - depends on this. Preprocessed output does occur if -MD, -MMD - or environment var dependency generation is used. */ + preprocessed output, but still do -dM etc. as software + depends on this. Preprocessed output does occur if -MD, -MMD + or environment var dependency generation is used. */ cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER); flag_no_output = 1; cpp_opts->inhibit_warnings = 1; @@ -296,7 +296,7 @@ sdcpp_common_handle_option (size_t scode, const char *arg, int value) cpp_opts->warn_trigraphs = value; cpp_opts->warn_comments = value; cpp_opts->warn_num_sign_change = value; - cpp_opts->warn_multichar = value; /* Was C++ only. */ + cpp_opts->warn_multichar = value; /* Was C++ only. */ break; case OPT_Wcomment: @@ -391,7 +391,7 @@ sdcpp_common_handle_option (size_t scode, const char *arg, int value) case OPT_ftabstop_: /* It is documented that we silently ignore silly values. */ if (value >= 1 && value <= 100) - cpp_opts->tabstop = value; + cpp_opts->tabstop = value; break; case OPT_fexec_charset_: @@ -458,9 +458,9 @@ sdcpp_common_handle_option (size_t scode, const char *arg, int value) case OPT_o: if (!out_fname) - out_fname = arg; + out_fname = arg; else - error ("output filename specified twice"); + error ("output filename specified twice"); break; /* SDCPP specfic */ @@ -469,8 +469,8 @@ sdcpp_common_handle_option (size_t scode, const char *arg, int value) break; /* We need to handle the -pedantic switches here, rather than in - sdcpp_common_post_options, so that a subsequent -Wno-endif-labels - is not overridden. */ + sdcpp_common_post_options, so that a subsequent -Wno-endif-labels + is not overridden. */ case OPT_pedantic_errors: cpp_opts->pedantic_errors = 1; /* Fall through. */ @@ -552,7 +552,7 @@ sdcpp_common_post_options (const char **pfilename) sanitize_cpp_opts (); register_include_chains (parse_in, sysroot, iprefix, imultilib, - std_inc, 0, verbose); + std_inc, 0, verbose); /* Open the output now. We must do so even if flag_no_output is on, because there may be other output than from the actual @@ -570,7 +570,7 @@ sdcpp_common_post_options (const char **pfilename) if (num_in_fnames > 1) error ("too many filenames given. Type %s --help for usage", - progname); + progname); init_pp_output (out_stream); @@ -634,15 +634,15 @@ sdcpp_common_finish (void) if (cpp_opts->deps.style != DEPS_NONE) { /* If -M or -MM was seen without -MF, default output to the - output stream. */ + output stream. */ if (!deps_file) - deps_stream = out_stream; + deps_stream = out_stream; else - { - deps_stream = fopen (deps_file, deps_append ? "a": "w"); - if (!deps_stream) - fatal_error ("opening dependency file %s: %s", deps_file, strerror(errno)); - } + { + deps_stream = fopen (deps_file, deps_append ? "a": "w"); + if (!deps_stream) + fatal_error ("opening dependency file %s: %s", deps_file, strerror(errno)); + } } /* For performance, avoid tearing down cpplib's internal structures @@ -676,10 +676,10 @@ check_deps_environment_vars (void) { GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES"); if (spec) - { - cpp_opts->deps.style = DEPS_SYSTEM; - cpp_opts->deps.ignore_main_file = true; - } + { + cpp_opts->deps.style = DEPS_SYSTEM; + cpp_opts->deps.ignore_main_file = true; + } } if (spec) @@ -687,15 +687,15 @@ check_deps_environment_vars (void) /* Find the space before the DEPS_TARGET, if there is one. */ char *s = strchr (spec, ' '); if (s) - { - /* Let the caller perform MAKE quoting. */ - defer_opt (OPT_MT, s + 1); - *s = '\0'; - } + { + /* Let the caller perform MAKE quoting. */ + defer_opt (OPT_MT, s + 1); + *s = '\0'; + } /* Command line -MF overrides environment variables and default. */ if (!deps_file) - deps_file = spec; + deps_file = spec; deps_append = 1; deps_seen = true; @@ -722,7 +722,7 @@ handle_deferred_opts (void) struct deferred_opt *opt = &deferred_opts[i]; if (opt->code == OPT_MT || opt->code == OPT_MQ) - deps_add_target (deps, opt->arg, opt->code == OPT_MQ); + deps_add_target (deps, opt->arg, opt->code == OPT_MQ); } } @@ -747,7 +747,7 @@ sanitize_cpp_opts (void) if (flag_no_output) { if (flag_dump_macros != 'M') - flag_dump_macros = 0; + flag_dump_macros = 0; flag_dump_includes = 0; flag_no_line_commands = 1; } @@ -795,53 +795,53 @@ finish_options (void) size_t i; cb_file_change (parse_in, - linemap_add (&line_table, LC_RENAME, 0, - _(""), 0)); + linemap_add (line_table, LC_RENAME, 0, + _(""), 0)); cpp_init_builtins (parse_in, 0 /*flag_hosted*/); /* We're about to send user input to cpplib, so make it warn for - things that we previously (when we sent it internal definitions) - told it to not warn. - - C99 permits implementation-defined characters in identifiers. - The documented meaning of -std= is to turn off extensions that - conflict with the specified standard, and since a strictly - conforming program cannot contain a '$', we do not condition - their acceptance on the -std= setting. */ + things that we previously (when we sent it internal definitions) + told it to not warn. + + C99 permits implementation-defined characters in identifiers. + The documented meaning of -std= is to turn off extensions that + conflict with the specified standard, and since a strictly + conforming program cannot contain a '$', we do not condition + their acceptance on the -std= setting. */ cpp_opts->warn_dollars = (cpp_opts->pedantic && !cpp_opts->c99); cpp_change_file (parse_in, LC_RENAME, _("")); for (i = 0; i < deferred_count; i++) - { - struct deferred_opt *opt = &deferred_opts[i]; - - if (opt->code == OPT_D) - cpp_define (parse_in, opt->arg); - else if (opt->code == OPT_U) - cpp_undef (parse_in, opt->arg); - else if (opt->code == OPT_A) - { - if (opt->arg[0] == '-') - cpp_unassert (parse_in, opt->arg + 1); - else - cpp_assert (parse_in, opt->arg); - } - } + { + struct deferred_opt *opt = &deferred_opts[i]; + + if (opt->code == OPT_D) + cpp_define (parse_in, opt->arg); + else if (opt->code == OPT_U) + cpp_undef (parse_in, opt->arg); + else if (opt->code == OPT_A) + { + if (opt->arg[0] == '-') + cpp_unassert (parse_in, opt->arg + 1); + else + cpp_assert (parse_in, opt->arg); + } + } /* Handle -imacros after -D and -U. */ for (i = 0; i < deferred_count; i++) - { - struct deferred_opt *opt = &deferred_opts[i]; - - if (opt->code == OPT_imacros - && cpp_push_include (parse_in, opt->arg)) - { - /* Disable push_command_line_include callback for now. */ - include_cursor = deferred_count + 1; - cpp_scan_nooutput (parse_in); - } - } + { + struct deferred_opt *opt = &deferred_opts[i]; + + if (opt->code == OPT_imacros + && cpp_push_include (parse_in, opt->arg)) + { + /* Disable push_command_line_include callback for now. */ + include_cursor = deferred_count + 1; + cpp_scan_nooutput (parse_in); + } + } } include_cursor = 0; @@ -857,8 +857,8 @@ push_command_line_include (void) struct deferred_opt *opt = &deferred_opts[include_cursor++]; if (!cpp_opts->preprocessed && opt->code == OPT_include - && cpp_push_include (parse_in, opt->arg)) - return; + && cpp_push_include (parse_in, opt->arg)) + return; } if (include_cursor == deferred_count) @@ -868,18 +868,18 @@ push_command_line_include (void) cpp_opts->warn_unused_macros = warn_unused_macros; /* Restore the line map from . */ if (!cpp_opts->preprocessed) - cpp_change_file (parse_in, LC_RENAME, this_input_filename); + cpp_change_file (parse_in, LC_RENAME, this_input_filename); /* Set this here so the client can change the option if it wishes, - and after stacking the main file so we don't trace the main file. */ - line_table.trace_includes = cpp_opts->print_include_names; + and after stacking the main file so we don't trace the main file. */ + line_table->trace_includes = cpp_opts->print_include_names; } } /* File change callback. Has to handle -include files. */ static void cb_file_change (cpp_reader * ARG_UNUSED (pfile), - const struct line_map *new_map) + const struct line_map *new_map) { pp_file_change (new_map); @@ -919,14 +919,14 @@ handle_OPT_d (const char *arg) while ((c = *arg++) != '\0') switch (c) { - case 'M': /* Dump macros only. */ - case 'N': /* Dump names. */ - case 'D': /* Dump definitions. */ - flag_dump_macros = c; - break; + case 'M': /* Dump macros only. */ + case 'N': /* Dump names. */ + case 'D': /* Dump definitions. */ + flag_dump_macros = c; + break; case 'I': - flag_dump_includes = 1; - break; + flag_dump_includes = 1; + break; } } diff --git a/support/cpp/sdcpp.c b/support/cpp/sdcpp.c index 285b5ec7..67155b90 100644 --- a/support/cpp/sdcpp.c +++ b/support/cpp/sdcpp.c @@ -63,7 +63,7 @@ const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; const char *main_input_filename; -struct line_maps line_table; +struct line_maps *line_table; /* Temporarily suppress certain warnings. This is set while reading code from a system header file. */ @@ -267,6 +267,8 @@ general_init (const char *argv0) hex_init (); gcc_init_libintl (); + + line_table = XNEW (struct line_maps); } /* Process the options that have been parsed. */ diff --git a/support/cpp/sdcpp.h b/support/cpp/sdcpp.h index 296db1bf..80e16fca 100644 --- a/support/cpp/sdcpp.h +++ b/support/cpp/sdcpp.h @@ -199,7 +199,7 @@ extern struct cpp_reader* parse_in; /* * From input.h */ -extern struct line_maps line_table; +extern struct line_maps *line_table; typedef source_location location_t; /* deprecated typedef */ @@ -227,5 +227,4 @@ union tree_node */ extern int errorcount; - #endif /* __SDCPP_H */ diff --git a/support/cpp/system.h b/support/cpp/system.h index 8f669437..fe8fd13c 100644 --- a/support/cpp/system.h +++ b/support/cpp/system.h @@ -1,13 +1,13 @@ /* Get common system includes and various definitions and declarations based on autoconf macros. - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2, or (at your option) any later +Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY @@ -16,9 +16,8 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING. If not, write to the Free -Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ +along with GCC; see the file COPYING3. If not see +. */ #ifndef GCC_SYSTEM_H @@ -258,7 +257,8 @@ extern int errno; UPPER. However the bounds themselves can be either positive or negative. */ #define IN_RANGE(VALUE, LOWER, UPPER) \ - ((unsigned HOST_WIDE_INT)((VALUE) - (LOWER)) <= ((UPPER) - (LOWER))) + ((unsigned HOST_WIDE_INT) (VALUE) - (unsigned HOST_WIDE_INT) (LOWER) \ + <= (unsigned HOST_WIDE_INT) (UPPER) - (unsigned HOST_WIDE_INT) (LOWER)) /* Infrastructure for defining missing _MAX and _MIN macros. Note that macros defined with these cannot be used in #if. */ @@ -559,7 +559,7 @@ extern int vsnprintf(char *, size_t, const char *, va_list); #endif #ifndef offsetof -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER) +#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER) #endif /* Various error reporting routines want to use __FUNCTION__. */ @@ -583,7 +583,7 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; /* Use gcc_assert(EXPR) to test invariants. */ #if ENABLE_ASSERT_CHECKING -#define gcc_assert(EXPR) \ +#define gcc_assert(EXPR) \ ((void)(!(EXPR) ? fancy_abort (__FILE__, __LINE__, __FUNCTION__), 0 : 0)) #else /* Include EXPR, so that unused variable warnings do not occur. */ @@ -621,9 +621,6 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; # define FALSE false #endif /* !__cplusplus */ -/////* Get definition of double_int. */ -////#include "double-int.h" - /* Some compilers do not allow the use of unsigned char in bitfields. */ #define BOOL_BITFIELD unsigned int @@ -667,96 +664,100 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; #endif /* Old target macros that have moved to the target hooks structure. */ - #pragma GCC poison ASM_OPEN_PAREN ASM_CLOSE_PAREN \ - FUNCTION_PROLOGUE FUNCTION_EPILOGUE \ - FUNCTION_END_PROLOGUE FUNCTION_BEGIN_EPILOGUE \ - DECL_MACHINE_ATTRIBUTES COMP_TYPE_ATTRIBUTES INSERT_ATTRIBUTES \ - VALID_MACHINE_DECL_ATTRIBUTE VALID_MACHINE_TYPE_ATTRIBUTE \ - SET_DEFAULT_TYPE_ATTRIBUTES SET_DEFAULT_DECL_ATTRIBUTES \ - MERGE_MACHINE_TYPE_ATTRIBUTES MERGE_MACHINE_DECL_ATTRIBUTES \ - MD_INIT_BUILTINS MD_EXPAND_BUILTIN ASM_OUTPUT_CONSTRUCTOR \ - ASM_OUTPUT_DESTRUCTOR SIGNED_CHAR_SPEC MAX_CHAR_TYPE_SIZE \ - WCHAR_UNSIGNED UNIQUE_SECTION SELECT_SECTION SELECT_RTX_SECTION \ - ENCODE_SECTION_INFO STRIP_NAME_ENCODING ASM_GLOBALIZE_LABEL \ - ASM_OUTPUT_MI_THUNK CONST_COSTS RTX_COSTS DEFAULT_RTX_COSTS \ - ADDRESS_COST MACHINE_DEPENDENT_REORG ASM_FILE_START ASM_FILE_END \ - ASM_SIMPLIFY_DWARF_ADDR INIT_TARGET_OPTABS INIT_SUBTARGET_OPTABS \ - INIT_GOFAST_OPTABS MULSI3_LIBCALL MULDI3_LIBCALL DIVSI3_LIBCALL \ - DIVDI3_LIBCALL UDIVSI3_LIBCALL UDIVDI3_LIBCALL MODSI3_LIBCALL \ - MODDI3_LIBCALL UMODSI3_LIBCALL UMODDI3_LIBCALL BUILD_VA_LIST_TYPE \ - PRETEND_OUTGOING_VARARGS_NAMED STRUCT_VALUE_INCOMING_REGNUM \ - ASM_OUTPUT_SECTION_NAME PROMOTE_FUNCTION_ARGS \ - STRUCT_VALUE_INCOMING STRICT_ARGUMENT_NAMING \ - PROMOTE_FUNCTION_RETURN PROMOTE_PROTOTYPES STRUCT_VALUE_REGNUM \ - SETUP_INCOMING_VARARGS EXPAND_BUILTIN_SAVEREGS \ - DEFAULT_SHORT_ENUMS SPLIT_COMPLEX_ARGS MD_ASM_CLOBBERS \ - HANDLE_PRAGMA_REDEFINE_EXTNAME HANDLE_PRAGMA_EXTERN_PREFIX \ - MUST_PASS_IN_STACK FUNCTION_ARG_PASS_BY_REFERENCE \ - VECTOR_MODE_SUPPORTED_P TARGET_SUPPORTS_HIDDEN \ - FUNCTION_ARG_PARTIAL_NREGS ASM_OUTPUT_DWARF_DTPREL \ - ALLOCATE_INITIAL_VALUE + #pragma GCC poison ASM_OPEN_PAREN ASM_CLOSE_PAREN \ + FUNCTION_PROLOGUE FUNCTION_EPILOGUE \ + FUNCTION_END_PROLOGUE FUNCTION_BEGIN_EPILOGUE \ + DECL_MACHINE_ATTRIBUTES COMP_TYPE_ATTRIBUTES INSERT_ATTRIBUTES \ + VALID_MACHINE_DECL_ATTRIBUTE VALID_MACHINE_TYPE_ATTRIBUTE \ + SET_DEFAULT_TYPE_ATTRIBUTES SET_DEFAULT_DECL_ATTRIBUTES \ + MERGE_MACHINE_TYPE_ATTRIBUTES MERGE_MACHINE_DECL_ATTRIBUTES \ + MD_INIT_BUILTINS MD_EXPAND_BUILTIN ASM_OUTPUT_CONSTRUCTOR \ + ASM_OUTPUT_DESTRUCTOR SIGNED_CHAR_SPEC MAX_CHAR_TYPE_SIZE \ + WCHAR_UNSIGNED UNIQUE_SECTION SELECT_SECTION SELECT_RTX_SECTION \ + ENCODE_SECTION_INFO STRIP_NAME_ENCODING ASM_GLOBALIZE_LABEL \ + ASM_OUTPUT_MI_THUNK CONST_COSTS RTX_COSTS DEFAULT_RTX_COSTS \ + ADDRESS_COST MACHINE_DEPENDENT_REORG ASM_FILE_START ASM_FILE_END \ + ASM_SIMPLIFY_DWARF_ADDR INIT_TARGET_OPTABS INIT_SUBTARGET_OPTABS \ + INIT_GOFAST_OPTABS MULSI3_LIBCALL MULDI3_LIBCALL DIVSI3_LIBCALL \ + DIVDI3_LIBCALL UDIVSI3_LIBCALL UDIVDI3_LIBCALL MODSI3_LIBCALL \ + MODDI3_LIBCALL UMODSI3_LIBCALL UMODDI3_LIBCALL BUILD_VA_LIST_TYPE \ + PRETEND_OUTGOING_VARARGS_NAMED STRUCT_VALUE_INCOMING_REGNUM \ + ASM_OUTPUT_SECTION_NAME PROMOTE_FUNCTION_ARGS \ + STRUCT_VALUE_INCOMING STRICT_ARGUMENT_NAMING \ + PROMOTE_FUNCTION_RETURN PROMOTE_PROTOTYPES STRUCT_VALUE_REGNUM \ + SETUP_INCOMING_VARARGS EXPAND_BUILTIN_SAVEREGS \ + DEFAULT_SHORT_ENUMS SPLIT_COMPLEX_ARGS MD_ASM_CLOBBERS \ + HANDLE_PRAGMA_REDEFINE_EXTNAME HANDLE_PRAGMA_EXTERN_PREFIX \ + MUST_PASS_IN_STACK FUNCTION_ARG_PASS_BY_REFERENCE \ + VECTOR_MODE_SUPPORTED_P TARGET_SUPPORTS_HIDDEN \ + FUNCTION_ARG_PARTIAL_NREGS ASM_OUTPUT_DWARF_DTPREL \ + ALLOCATE_INITIAL_VALUE /* Other obsolete target macros, or macros that used to be in target headers and were not used, and may be obsolete or may never have been used. */ - #pragma GCC poison INT_ASM_OP ASM_OUTPUT_EH_REGION_BEG CPP_PREDEFINES \ - ASM_OUTPUT_EH_REGION_END ASM_OUTPUT_LABELREF_AS_INT SMALL_STACK \ - DOESNT_NEED_UNWINDER EH_TABLE_LOOKUP OBJC_SELECTORS_WITHOUT_LABELS \ - OMIT_EH_TABLE EASY_DIV_EXPR IMPLICIT_FIX_EXPR \ - LONGJMP_RESTORE_FROM_STACK MAX_INT_TYPE_SIZE ASM_IDENTIFY_GCC \ - STDC_VALUE TRAMPOLINE_ALIGN ASM_IDENTIFY_GCC_AFTER_SOURCE \ - SLOW_ZERO_EXTEND SUBREG_REGNO_OFFSET DWARF_LINE_MIN_INSTR_LENGTH \ - TRADITIONAL_RETURN_FLOAT NO_BUILTIN_SIZE_TYPE \ - NO_BUILTIN_PTRDIFF_TYPE NO_BUILTIN_WCHAR_TYPE NO_BUILTIN_WINT_TYPE \ - BLOCK_PROFILER BLOCK_PROFILER_CODE FUNCTION_BLOCK_PROFILER \ - FUNCTION_BLOCK_PROFILER_EXIT MACHINE_STATE_SAVE \ - MACHINE_STATE_RESTORE SCCS_DIRECTIVE SECTION_ASM_OP BYTEORDER \ - ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL HOST_WORDS_BIG_ENDIAN \ - OBJC_PROLOGUE ALLOCATE_TRAMPOLINE HANDLE_PRAGMA ROUND_TYPE_SIZE \ - ROUND_TYPE_SIZE_UNIT CONST_SECTION_ASM_OP CRT_GET_RFIB_TEXT \ - DBX_LBRAC_FIRST DBX_OUTPUT_ENUM DBX_OUTPUT_SOURCE_FILENAME \ - DBX_WORKING_DIRECTORY INSN_CACHE_DEPTH INSN_CACHE_SIZE \ - INSN_CACHE_LINE_WIDTH INIT_SECTION_PREAMBLE NEED_ATEXIT ON_EXIT \ - EXIT_BODY OBJECT_FORMAT_ROSE MULTIBYTE_CHARS MAP_CHARACTER \ - LIBGCC_NEEDS_DOUBLE FINAL_PRESCAN_LABEL DEFAULT_CALLER_SAVES \ - LOAD_ARGS_REVERSED MAX_INTEGER_COMPUTATION_MODE \ - CONVERT_HARD_REGISTER_TO_SSA_P ASM_OUTPUT_MAIN_SOURCE_FILENAME \ - FIRST_INSN_ADDRESS TEXT_SECTION SHARED_BSS_SECTION_ASM_OP \ - PROMOTED_MODE EXPAND_BUILTIN_VA_END \ - LINKER_DOES_NOT_WORK_WITH_DWARF2 FUNCTION_ARG_KEEP_AS_REFERENCE \ - GIV_SORT_CRITERION MAX_LONG_TYPE_SIZE MAX_LONG_DOUBLE_TYPE_SIZE \ - MAX_WCHAR_TYPE_SIZE SHARED_SECTION_ASM_OP INTEGRATE_THRESHOLD \ - FINAL_REG_PARM_STACK_SPACE MAYBE_REG_PARM_STACK_SPACE \ - TRADITIONAL_PIPELINE_INTERFACE DFA_PIPELINE_INTERFACE \ - DBX_OUTPUT_STANDARD_TYPES BUILTIN_SETJMP_FRAME_VALUE \ - SUNOS4_SHARED_LIBRARIES PROMOTE_FOR_CALL_ONLY \ - SPACE_AFTER_L_OPTION NO_RECURSIVE_FUNCTION_CSE \ - DEFAULT_MAIN_RETURN TARGET_MEM_FUNCTIONS EXPAND_BUILTIN_VA_ARG \ - COLLECT_PARSE_FLAG DWARF2_GENERATE_TEXT_SECTION_LABEL WINNING_GDB \ - ASM_OUTPUT_FILENAME ASM_OUTPUT_SOURCE_LINE FILE_NAME_JOINER \ - GDB_INV_REF_REGPARM_STABS_LETTER DBX_MEMPARM_STABS_LETTER \ - PUT_SDB_SRC_FILE STABS_GCC_MARKER DBX_OUTPUT_FUNCTION_END \ - DBX_OUTPUT_GCC_MARKER DBX_FINISH_SYMBOL SDB_GENERATE_FAKE \ - NON_SAVING_SETJMP TARGET_LATE_RTL_PROLOGUE_EPILOGUE \ - CASE_DROPS_THROUGH TARGET_BELL TARGET_BS TARGET_CR TARGET_DIGIT0 \ - TARGET_ESC TARGET_FF TARGET_NEWLINE TARGET_TAB TARGET_VT \ - LINK_LIBGCC_SPECIAL DONT_ACCESS_GBLS_AFTER_EPILOGUE \ - TARGET_OPTIONS TARGET_SWITCHES EXTRA_CC_MODES FINALIZE_PIC \ - PREDICATE_CODES SPECIAL_MODE_PREDICATES HOST_PTR_PRINTF \ - EXTRA_SECTIONS EXTRA_SECTION_FUNCTIONS READONLY_DATA_SECTION \ - TARGET_ASM_EXCEPTION_SECTION TARGET_ASM_EH_FRAME_SECTION \ - SMALL_ARG_MAX ASM_OUTPUT_SHARED_BSS ASM_OUTPUT_SHARED_COMMON \ - ASM_OUTPUT_SHARED_LOCAL UNALIGNED_WORD_ASM_OP + #pragma GCC poison INT_ASM_OP ASM_OUTPUT_EH_REGION_BEG CPP_PREDEFINES \ + ASM_OUTPUT_EH_REGION_END ASM_OUTPUT_LABELREF_AS_INT SMALL_STACK \ + DOESNT_NEED_UNWINDER EH_TABLE_LOOKUP OBJC_SELECTORS_WITHOUT_LABELS \ + OMIT_EH_TABLE EASY_DIV_EXPR IMPLICIT_FIX_EXPR \ + LONGJMP_RESTORE_FROM_STACK MAX_INT_TYPE_SIZE ASM_IDENTIFY_GCC \ + STDC_VALUE TRAMPOLINE_ALIGN ASM_IDENTIFY_GCC_AFTER_SOURCE \ + SLOW_ZERO_EXTEND SUBREG_REGNO_OFFSET DWARF_LINE_MIN_INSTR_LENGTH \ + TRADITIONAL_RETURN_FLOAT NO_BUILTIN_SIZE_TYPE \ + NO_BUILTIN_PTRDIFF_TYPE NO_BUILTIN_WCHAR_TYPE NO_BUILTIN_WINT_TYPE \ + BLOCK_PROFILER BLOCK_PROFILER_CODE FUNCTION_BLOCK_PROFILER \ + FUNCTION_BLOCK_PROFILER_EXIT MACHINE_STATE_SAVE \ + MACHINE_STATE_RESTORE SCCS_DIRECTIVE SECTION_ASM_OP BYTEORDER \ + ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL HOST_WORDS_BIG_ENDIAN \ + OBJC_PROLOGUE ALLOCATE_TRAMPOLINE HANDLE_PRAGMA ROUND_TYPE_SIZE \ + ROUND_TYPE_SIZE_UNIT CONST_SECTION_ASM_OP CRT_GET_RFIB_TEXT \ + DBX_LBRAC_FIRST DBX_OUTPUT_ENUM DBX_OUTPUT_SOURCE_FILENAME \ + DBX_WORKING_DIRECTORY INSN_CACHE_DEPTH INSN_CACHE_SIZE \ + INSN_CACHE_LINE_WIDTH INIT_SECTION_PREAMBLE NEED_ATEXIT ON_EXIT \ + EXIT_BODY OBJECT_FORMAT_ROSE MULTIBYTE_CHARS MAP_CHARACTER \ + LIBGCC_NEEDS_DOUBLE FINAL_PRESCAN_LABEL DEFAULT_CALLER_SAVES \ + LOAD_ARGS_REVERSED MAX_INTEGER_COMPUTATION_MODE \ + CONVERT_HARD_REGISTER_TO_SSA_P ASM_OUTPUT_MAIN_SOURCE_FILENAME \ + FIRST_INSN_ADDRESS TEXT_SECTION SHARED_BSS_SECTION_ASM_OP \ + PROMOTED_MODE EXPAND_BUILTIN_VA_END \ + LINKER_DOES_NOT_WORK_WITH_DWARF2 FUNCTION_ARG_KEEP_AS_REFERENCE \ + GIV_SORT_CRITERION MAX_LONG_TYPE_SIZE MAX_LONG_DOUBLE_TYPE_SIZE \ + MAX_WCHAR_TYPE_SIZE SHARED_SECTION_ASM_OP INTEGRATE_THRESHOLD \ + FINAL_REG_PARM_STACK_SPACE MAYBE_REG_PARM_STACK_SPACE \ + TRADITIONAL_PIPELINE_INTERFACE DFA_PIPELINE_INTERFACE \ + DBX_OUTPUT_STANDARD_TYPES BUILTIN_SETJMP_FRAME_VALUE \ + SUNOS4_SHARED_LIBRARIES PROMOTE_FOR_CALL_ONLY \ + SPACE_AFTER_L_OPTION NO_RECURSIVE_FUNCTION_CSE \ + DEFAULT_MAIN_RETURN TARGET_MEM_FUNCTIONS EXPAND_BUILTIN_VA_ARG \ + COLLECT_PARSE_FLAG DWARF2_GENERATE_TEXT_SECTION_LABEL WINNING_GDB \ + ASM_OUTPUT_FILENAME ASM_OUTPUT_SOURCE_LINE FILE_NAME_JOINER \ + GDB_INV_REF_REGPARM_STABS_LETTER DBX_MEMPARM_STABS_LETTER \ + PUT_SDB_SRC_FILE STABS_GCC_MARKER DBX_OUTPUT_FUNCTION_END \ + DBX_OUTPUT_GCC_MARKER DBX_FINISH_SYMBOL SDB_GENERATE_FAKE \ + NON_SAVING_SETJMP TARGET_LATE_RTL_PROLOGUE_EPILOGUE \ + CASE_DROPS_THROUGH TARGET_BELL TARGET_BS TARGET_CR TARGET_DIGIT0 \ + TARGET_ESC TARGET_FF TARGET_NEWLINE TARGET_TAB TARGET_VT \ + LINK_LIBGCC_SPECIAL DONT_ACCESS_GBLS_AFTER_EPILOGUE \ + TARGET_OPTIONS TARGET_SWITCHES EXTRA_CC_MODES FINALIZE_PIC \ + PREDICATE_CODES SPECIAL_MODE_PREDICATES HOST_PTR_PRINTF \ + EXTRA_SECTIONS EXTRA_SECTION_FUNCTIONS READONLY_DATA_SECTION \ + TARGET_ASM_EXCEPTION_SECTION TARGET_ASM_EH_FRAME_SECTION \ + SMALL_ARG_MAX ASM_OUTPUT_SHARED_BSS ASM_OUTPUT_SHARED_COMMON \ + ASM_OUTPUT_SHARED_LOCAL UNALIGNED_WORD_ASM_OP \ + ASM_MAKE_LABEL_LINKONCE /* Hooks that are no longer used. */ - #pragma GCC poison LANG_HOOKS_FUNCTION_MARK LANG_HOOKS_FUNCTION_FREE \ - LANG_HOOKS_MARK_TREE LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES \ - LANG_HOOKS_TREE_INLINING_ESTIMATE_NUM_INSNS \ - LANG_HOOKS_PUSHLEVEL LANG_HOOKS_SET_BLOCK \ - LANG_HOOKS_MAYBE_BUILD_CLEANUP LANG_HOOKS_UPDATE_DECL_AFTER_SAVING \ - LANG_HOOKS_POPLEVEL LANG_HOOKS_TRUTHVALUE_CONVERSION - -/* Libiberty macros that are no longer used in GCC. */ + #pragma GCC poison LANG_HOOKS_FUNCTION_MARK LANG_HOOKS_FUNCTION_FREE \ + LANG_HOOKS_MARK_TREE LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES \ + LANG_HOOKS_TREE_INLINING_ESTIMATE_NUM_INSNS \ + LANG_HOOKS_PUSHLEVEL LANG_HOOKS_SET_BLOCK \ + LANG_HOOKS_MAYBE_BUILD_CLEANUP LANG_HOOKS_UPDATE_DECL_AFTER_SAVING \ + LANG_HOOKS_POPLEVEL LANG_HOOKS_TRUTHVALUE_CONVERSION + +/* Miscellaneous macros that are no longer used. */ + #pragma GCC poison USE_MAPPED_LOCATION + + /* Libiberty macros that are no longer used in GCC. */ #undef ANSI_PROTOTYPES #undef PTR_CONST #undef LONG_DOUBLE @@ -779,6 +780,70 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; #endif /* GCC >= 3.0 */ +/* This macro allows casting away const-ness to pass -Wcast-qual + warnings. DO NOT USE THIS UNLESS YOU REALLY HAVE TO! It should + only be used in certain specific cases. One valid case is where + the C standard definitions or prototypes force you to. E.g. if you + need to free a const object, or if you pass a const string to + execv, et al. Another valid use would be in an allocation function + that creates const objects that need to be initialized. In some + cases we have non-const functions that return the argument + (e.g. next_nonnote_insn). Rather than create const shadow + functions, we can cast away const-ness in calling these interfaces + if we're careful to verify that the called function does indeed not + modify its argument and the return value is only used in a const + context. (This can be somewhat dangerous as these assumptions can + change after the fact). Beyond these uses, most other cases of + using this macro should be viewed with extreme caution. */ + +#if defined(__GNUC__) && GCC_VERSION > 4000 +/* GCC 4.0.x has a bug where it may ICE on this expression, + so does GCC 3.4.x (PR17436). */ +#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((__extension__(union {FROMTYPE _q; TOTYPE _nq;})(X))._nq) +#else +#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((TOTYPE)(FROMTYPE)(X)) +#endif +#define CONST_CAST(TYPE,X) CONST_CAST2(TYPE, const TYPE, (X)) +#define CONST_CAST_TREE(X) CONST_CAST(union tree_node *, (X)) +#define CONST_CAST_RTX(X) CONST_CAST(struct rtx_def *, (X)) +#define CONST_CAST_BB(X) CONST_CAST(struct basic_block_def *, (X)) +#define CONST_CAST_GIMPLE(X) CONST_CAST(union gimple_statement_d *, (X)) + +/* Activate certain diagnostics as warnings (not errors via the + -Werror flag). */ +#if GCC_VERSION >= 4003 +/* If asserts are disabled, activate -Wuninitialized as a warning (not + an error/-Werror). */ +#ifndef ENABLE_ASSERT_CHECKING +#pragma GCC diagnostic warning "-Wuninitialized" +#endif +#endif + +#ifdef ENABLE_VALGRIND_CHECKING +# ifdef HAVE_VALGRIND_MEMCHECK_H +# include +# elif defined HAVE_MEMCHECK_H +# include +# else +# include +# endif +/* Compatibility macros to let valgrind 3.1 work. */ +# ifndef VALGRIND_MAKE_MEM_NOACCESS +# define VALGRIND_MAKE_MEM_NOACCESS VALGRIND_MAKE_NOACCESS +# endif +# ifndef VALGRIND_MAKE_MEM_DEFINED +# define VALGRIND_MAKE_MEM_DEFINED VALGRIND_MAKE_READABLE +# endif +# ifndef VALGRIND_MAKE_MEM_UNDEFINED +# define VALGRIND_MAKE_MEM_UNDEFINED VALGRIND_MAKE_WRITABLE +# endif +#else +/* Avoid #ifdef:s when we can help it. */ +#define VALGRIND_DISCARD(x) +#define VALGRIND_MALLOCLIKE_BLOCK(w,x,y,z) +#define VALGRIND_FREELIKE_BLOCK(x,y) +#endif + /* SDCC specific */ #include "sdcpp.h" -- 2.30.2