diff options
author | Neil Booth <neil@daikokuya.co.uk> | 2003-03-14 21:47:50 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2003-03-14 21:47:50 +0000 |
commit | 23345bbbcc8dc9c11168d0fd6b2afb415cb6c4e6 (patch) | |
tree | f86d032aa7796736ae3b48b9d527b9b116caa900 /gcc | |
parent | 98d2dec7e3268ca0baee90e2d89da4d75fe4c193 (diff) | |
download | gcc-23345bbbcc8dc9c11168d0fd6b2afb415cb6c4e6.zip gcc-23345bbbcc8dc9c11168d0fd6b2afb415cb6c4e6.tar.gz gcc-23345bbbcc8dc9c11168d0fd6b2afb415cb6c4e6.tar.bz2 |
/home/neil/diffs/include.log
From-SVN: r64373
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 33 | ||||
-rw-r--r-- | gcc/Makefile.in | 4 | ||||
-rw-r--r-- | gcc/c-common.h | 4 | ||||
-rw-r--r-- | gcc/c-lex.c | 31 | ||||
-rw-r--r-- | gcc/c-opts.c | 90 | ||||
-rw-r--r-- | gcc/c-ppoutput.c | 15 | ||||
-rw-r--r-- | gcc/cpphash.h | 8 | ||||
-rw-r--r-- | gcc/cppinit.c | 42 | ||||
-rw-r--r-- | gcc/cpplib.c | 11 | ||||
-rw-r--r-- | gcc/cppmacro.c | 6 |
10 files changed, 137 insertions, 107 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1d7dbc2..6b7d28c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,36 @@ +2003-03-14 Neil Booth <neil@daikokuya.co.uk> + + * Makefile.in: Update. + * c-common.h (fe_file_change, pp_file_change): New. + * c-lex.c (init_c_lex): Don't set cb_file_change. + (c_common_parse_file): Move to c-opts.c. + (cb_file_change): Rename fe_file_change. + * c-opts.c: Include debug.h. + (warn_unused_macros, include_cursor): New. + (push_command_line_include, cb_file_change): New. + (COMMAND_LINE_OPTIONS): Handle -include. + (c_common_decode_option): Use local warn_unused_macros. + Handle OPT_include. + (c_common_post_options): Set file change callback. + (handle_deferred_opts): Skip -include. Don't free the array. + (c_common_init): Call cpp_finish_options here, and push an + initial -include file. + * c-ppoutput.c (cb_file_change): Rename pp_file_change. + (preprocess_file): Don't call cpp_finish_options. + (init_pp_output): Don't set the file change callback. + (pp_file_change): Return if no line commands or no output. + * cpphash.h (next_include_file, first_unused_line): Remove. + * cppinit.c (include_head, include_tail): Remove. + (cpp_destroy): Don't free -include chain. + (cpp_finish_options): Don't handle -include, or worry about + -Wunused-macros. + (_cpp_maybe_push_include_file): Remove. + (COMMAND_LINE_OPTIONS, cpp_handle_option): Don't handle -include. + * cpplib.c (_cpp_pop_buffer): Don't handle -include. + * cppmacro.c (_cpp_warn_if_unused_macro, _cpp_create_definition): + Used flag is set based upon the state of the warn_unused_macros + flag, and so use of first_unused_line is unnecessary. + Thu Mar 13 18:39:42 CET 2003 Jan Hubicka <jh@suse.cz> * cselib.c (clear_table): Do not take argument; always clear just diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 9fc3222..f1d5e91 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1308,9 +1308,9 @@ c-common.o : c-common.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \ c-pretty-print.o : c-pretty-print.c c-pretty-print.h pretty-print.h \ $(C_COMMON_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) real.h -c-opts.o : c-opts.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(C_COMMON_H) \ +c-opts.o : c-opts.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \ c-pragma.h flags.h toplev.h langhooks.h tree-inline.h diagnostic.h \ - intl.h + intl.h debug.h $(C_COMMON_H) c-cppbuiltin.o : c-cppbuiltin.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ $(TREE_H) $(C_COMMON_H) c-pragma.h flags.h toplev.h langhooks.h \ diff --git a/gcc/c-common.h b/gcc/c-common.h index ddd557da..472cb50 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -1,6 +1,6 @@ /* Definitions for c-common.c. Copyright (C) 1987, 1993, 1994, 1995, 1997, 1998, - 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This file is part of GCC. @@ -1295,9 +1295,11 @@ extern void c_common_write_pch PARAMS ((void)); extern void builtin_define_with_value PARAMS ((const char *, const char *, int)); extern void c_stddef_cpp_builtins PARAMS ((void)); +extern void fe_file_change PARAMS ((const struct line_map *)); /* In c-ppoutput.c */ extern void init_pp_output PARAMS ((FILE *)); extern void preprocess_file PARAMS ((cpp_reader *)); +extern void pp_file_change PARAMS ((const struct line_map *)); #endif /* ! GCC_C_COMMON_H */ diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 9e97ad7..7256c5a 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -86,7 +86,6 @@ static int dump_one_header PARAMS ((splay_tree_node, void *)); static void cb_line_change PARAMS ((cpp_reader *, const cpp_token *, int)); static void cb_ident PARAMS ((cpp_reader *, unsigned int, const cpp_string *)); -static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *)); static void cb_def_pragma PARAMS ((cpp_reader *, unsigned int)); static void cb_define PARAMS ((cpp_reader *, unsigned int, cpp_hashnode *)); @@ -116,7 +115,6 @@ init_c_lex () cb->register_builtins = cb_register_builtins; cb->line_change = cb_line_change; cb->ident = cb_ident; - cb->file_change = cb_file_change; cb->def_pragma = cb_def_pragma; cb->valid_pch = c_common_valid_pch; cb->read_pch = c_common_read_pch; @@ -131,30 +129,6 @@ init_c_lex () } } -/* A thin wrapper around the real parser that initializes the - integrated preprocessor after debug output has been initialized. - Also, make sure the start_source_file debug hook gets called for - the primary source file. */ - -void -c_common_parse_file (set_yydebug) - int set_yydebug ATTRIBUTE_UNUSED; -{ -#if YYDEBUG != 0 - yydebug = set_yydebug; -#else - warning ("YYDEBUG not defined"); -#endif - - (*debug_hooks->start_source_file) (lineno, input_filename); - cpp_finish_options (parse_in); - - pch_init(); - - yyparse (); - free_parser_stacks (); -} - struct c_fileinfo * get_fileinfo (name) const char *name; @@ -245,9 +219,8 @@ cb_line_change (pfile, token, parsing_args) src_lineno = SOURCE_LINE (map, token->line); } -static void -cb_file_change (pfile, new_map) - cpp_reader *pfile ATTRIBUTE_UNUSED; +void +fe_file_change (new_map) const struct line_map *new_map; { unsigned int to_line = SOURCE_LINE (new_map, new_map->to_line); diff --git a/gcc/c-opts.c b/gcc/c-opts.c index a06f0fe8..b931bbe 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -34,6 +34,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "intl.h" #include "cppdefault.h" #include "c-incpath.h" +#include "debug.h" /* For debug_hooks. */ #ifndef TARGET_SYSTEM_ROOT # define TARGET_SYSTEM_ROOT NULL @@ -78,9 +79,15 @@ static bool std_cxx_inc = true; /* If the quote chain has been split by -I-. */ static bool quote_chain_split; +/* If -Wunused-macros. */ +static bool warn_unused_macros; + /* Number of deferred options, deferred options array size. */ static size_t deferred_count, deferred_size; +/* Number of deferred options scanned for -include. */ +static size_t include_cursor; + static void missing_arg PARAMS ((size_t)); static size_t find_opt PARAMS ((const char *, int)); static void set_Wimplicit PARAMS ((int)); @@ -95,6 +102,8 @@ static void check_deps_environment_vars PARAMS ((void)); static void handle_deferred_opts PARAMS ((void)); static void sanitize_cpp_opts PARAMS ((void)); static void add_prefixed_path PARAMS ((const char *, size_t)); +static void push_command_line_include PARAMS ((void)); +static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *)); #ifndef STDC_0_IN_SYSTEM_HEADERS #define STDC_0_IN_SYSTEM_HEADERS 0 @@ -288,6 +297,7 @@ static void add_prefixed_path PARAMS ((const char *, size_t)); OPT("fxref", CL_CXX, OPT_fxref) \ OPT("gen-decls", CL_OBJC, OPT_gen_decls) \ OPT("idirafter", CL_ALL | CL_ARG, OPT_idirafter) \ + OPT("include", CL_ALL | CL_ARG, OPT_include) \ OPT("iprefix", CL_ALL | CL_ARG, OPT_iprefix) \ OPT("isysroot", CL_ALL | CL_ARG, OPT_isysroot) \ OPT("isystem", CL_ALL | CL_ARG, OPT_isystem) \ @@ -1040,7 +1050,7 @@ c_common_decode_option (argc, argv) break; case OPT_Wunused_macros: - cpp_opts->warn_unused_macros = on; + warn_unused_macros = on; break; case OPT_Wwrite_strings: @@ -1323,6 +1333,10 @@ c_common_decode_option (argc, argv) add_path (xstrdup (arg), AFTER, 0); break; + case OPT_include: + defer_opt (code, arg); + break; + case OPT_iprefix: iprefix = arg; break; @@ -1521,6 +1535,8 @@ c_common_post_options (pfilename) lineno = 0; } + cpp_get_callbacks (parse_in)->file_change = cb_file_change; + /* NOTE: we use in_fname here, not the one supplied. */ *pfilename = cpp_read_main_file (parse_in, in_fname, ident_hash); @@ -1550,8 +1566,9 @@ c_common_init () if (flag_preprocess_only) { - if (main_input_filename) - preprocess_file (parse_in); + cpp_finish_options (parse_in); + push_command_line_include (); + preprocess_file (parse_in); return false; } @@ -1561,6 +1578,28 @@ c_common_init () return true; } +/* A thin wrapper around the real parser that initializes the + integrated preprocessor after debug output has been initialized. + Also, make sure the start_source_file debug hook gets called for + the primary source file. */ +void +c_common_parse_file (set_yydebug) + int set_yydebug ATTRIBUTE_UNUSED; +{ +#if YYDEBUG != 0 + yydebug = set_yydebug; +#else + warning ("YYDEBUG not defined"); +#endif + + (*debug_hooks->start_source_file) (lineno, input_filename); + cpp_finish_options (parse_in); + push_command_line_include (); + pch_init(); + yyparse (); + free_parser_stacks (); +} + /* Common finish hook for the C, ObjC and C++ front ends. */ void c_common_finish () @@ -1654,12 +1693,13 @@ handle_deferred_opts () cpp_add_dependency_target (parse_in, opt->arg, opt->code == OPT_MQ); break; + case OPT_include: + break; + default: abort (); } } - - free (deferred_opts); } /* These settings are appropriate for GCC, but not necessarily so for @@ -1717,6 +1757,46 @@ add_prefixed_path (suffix, chain) add_path (path, chain, 0); } +/* Give CPP the next file given by -include, if any. */ +static void +push_command_line_include () +{ + if (cpp_opts->preprocessed) + return; + + while (include_cursor < deferred_count) + { + struct deferred_opt *opt = &deferred_opts[include_cursor++]; + + if (opt->code == OPT_include && cpp_push_include (parse_in, opt->arg)) + return; + } + + if (include_cursor == deferred_count) + { + /* Restore the line map from <command line>. */ + cpp_rename_file (parse_in, main_input_filename); + /* -Wunused-macros should only warn about macros defined hereafter. */ + cpp_opts->warn_unused_macros = warn_unused_macros; + include_cursor++; + } +} + +/* File change callback. Has to handle -include files. */ +static void +cb_file_change (pfile, new_map) + cpp_reader *pfile ATTRIBUTE_UNUSED; + const struct line_map *new_map; +{ + if (flag_preprocess_only) + pp_file_change (new_map); + else + fe_file_change (new_map); + + if (new_map->reason == LC_LEAVE && MAIN_FILE_P (new_map)) + push_command_line_include (); +} + /* Set the C 89 standard (with 1994 amendments if C94, without GNU extensions if ISO). There is no concept of gnu94. */ static void diff --git a/gcc/c-ppoutput.c b/gcc/c-ppoutput.c index 14ae31b..c4e3121 100644 --- a/gcc/c-ppoutput.c +++ b/gcc/c-ppoutput.c @@ -58,7 +58,6 @@ static void cb_include PARAMS ((cpp_reader *, unsigned int, const unsigned char *, const cpp_token *)); static void cb_ident PARAMS ((cpp_reader *, unsigned int, const cpp_string *)); -static void cb_file_change PARAMS ((cpp_reader *, const struct line_map *)); static void cb_def_pragma PARAMS ((cpp_reader *, unsigned int)); /* Preprocess and output. */ @@ -66,8 +65,6 @@ void preprocess_file (pfile) cpp_reader *pfile; { - cpp_finish_options (pfile); - /* A successful cpp_read_main_file guarantees that we can call cpp_scan_nooutput or cpp_get_token next. */ if (flag_no_output) @@ -110,8 +107,6 @@ init_pp_output (out_stream) cb->ident = cb_ident; cb->def_pragma = cb_def_pragma; } - if (!flag_no_line_commands) - cb->file_change = cb_file_change; } if (flag_dump_includes) @@ -368,18 +363,20 @@ cb_include (pfile, line, dir, header) described in MAP. From this point on, the old print.map might be pointing to freed memory, and so must not be dereferenced. */ -static void -cb_file_change (pfile, map) - cpp_reader *pfile; +void +pp_file_change (map) const struct line_map *map; { const char *flags = ""; + if (flag_no_line_commands || flag_no_output) + return; + /* First time? */ if (print.map == NULL) { /* Avoid printing foo.i when the main file is foo.c. */ - if (!CPP_OPTION (pfile, preprocessed)) + if (!cpp_get_options (parse_in)->preprocessed) print_line (map, map->from_line, flags); } else diff --git a/gcc/cpphash.h b/gcc/cpphash.h index 6fc6369..bc0d099 100644 --- a/gcc/cpphash.h +++ b/gcc/cpphash.h @@ -332,11 +332,6 @@ struct cpp_reader /* If in_directive, the directive if known. */ const struct directive *directive; - /* The next -include-d file; NULL if they all are done. If it - points to NULL, the last one is in progress, and - _cpp_maybe_push_include_file has yet to restore the line map. */ - struct pending_option **next_include_file; - /* Search paths for include files. */ struct cpp_path *quote_include; /* "" */ struct cpp_path *bracket_include; /* <> */ @@ -368,9 +363,6 @@ struct cpp_reader for include files. (Altered as we get more of them.) */ unsigned int max_include_len; - /* Macros on or after this line are warned about if unused. */ - unsigned int first_unused_line; - /* Date and time text. Calculated together if either is requested. */ const uchar *date; const uchar *time; diff --git a/gcc/cppinit.c b/gcc/cppinit.c index 8982474..6eeedf8 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -48,7 +48,6 @@ struct cpp_pending { struct pending_option *directive_head, *directive_tail; struct pending_option *imacros_head, *imacros_tail; - struct pending_option *include_head, *include_tail; }; #ifdef __STDC__ @@ -278,7 +277,6 @@ cpp_destroy (pfile) cpp_context *context, *contextn; tokenrun *run, *runn; - free_chain (CPP_OPTION (pfile, pending)->include_head); free (CPP_OPTION (pfile, pending)); free (pfile->op_stack); @@ -603,8 +601,6 @@ cpp_finish_options (pfile) { struct pending_option *p; - /* Prevent -Wunused-macros with command-line redefinitions. */ - pfile->first_unused_line = (unsigned int) -1; _cpp_do_file_change (pfile, LC_RENAME, _("<built-in>"), 1, 0); init_builtins (pfile); _cpp_do_file_change (pfile, LC_RENAME, _("<command line>"), 1, 0); @@ -617,42 +613,12 @@ cpp_finish_options (pfile) for (p = CPP_OPTION (pfile, pending)->imacros_head; p; p = p->next) if (cpp_push_include (pfile, p->arg)) cpp_scan_nooutput (pfile); - - pfile->next_include_file = &CPP_OPTION (pfile, pending)->include_head; - _cpp_maybe_push_include_file (pfile); } - pfile->first_unused_line = pfile->line; - free_chain (CPP_OPTION (pfile, pending)->imacros_head); free_chain (CPP_OPTION (pfile, pending)->directive_head); } -/* Push the next buffer on the stack given by -include, if any. */ -void -_cpp_maybe_push_include_file (pfile) - cpp_reader *pfile; -{ - if (pfile->next_include_file) - { - struct pending_option *head = *pfile->next_include_file; - - while (head && !cpp_push_include (pfile, head->arg)) - head = head->next; - - if (head) - pfile->next_include_file = &head->next; - else - { - /* All done; restore the line map from <command line>. */ - _cpp_do_file_change (pfile, LC_RENAME, - pfile->line_maps.maps[0].to_file, 1, 0); - /* Don't come back here again. */ - pfile->next_include_file = NULL; - } - } -} - /* This is called at the end of preprocessing. It pops the last buffer and writes dependency output, and returns the number of errors. @@ -723,7 +689,7 @@ new_pending_directive (pend, text, handler) DEF_OPT("D", no_mac, OPT_D) \ DEF_OPT("U", no_mac, OPT_U) \ DEF_OPT("imacros", no_fil, OPT_imacros) \ - DEF_OPT("include", no_fil, OPT_include) + #define DEF_OPT(text, msg, code) code, enum opt_code @@ -887,7 +853,6 @@ cpp_handle_option (pfile, argc, argv) case OPT_U: new_pending_directive (pend, arg, cpp_undef); break; - case OPT_include: case OPT_imacros: { struct pending_option *o = (struct pending_option *) @@ -895,10 +860,7 @@ cpp_handle_option (pfile, argc, argv) o->arg = arg; o->next = NULL; - if (opt_code == OPT_include) - APPEND (pend, include, o); - else - APPEND (pend, imacros, o); + APPEND (pend, imacros, o); } break; } diff --git a/gcc/cpplib.c b/gcc/cpplib.c index ed2bc95..7d2d965 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -1,6 +1,6 @@ /* CPP Library. (Directive handling.) Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003 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 @@ -2072,14 +2072,7 @@ _cpp_pop_buffer (pfile) /* Don't generate a callback for popping the main file. */ if (pfile->buffer) - { - _cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0); - - /* If this is the main file, there may be some -include - files left to push. */ - if (!pfile->buffer->prev) - _cpp_maybe_push_include_file (pfile); - } + _cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0); } } diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c index 99043ff..94fa858 100644 --- a/gcc/cppmacro.c +++ b/gcc/cppmacro.c @@ -1,6 +1,6 @@ /* Part of CPP library. (Macro and #define handling.) Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998, - 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003 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 @@ -89,8 +89,6 @@ _cpp_warn_if_unused_macro (pfile, node, v) cpp_macro *macro = node->value.macro; if (!macro->used - /* Skip front-end built-ins and command line macros. */ - && macro->line >= pfile->first_unused_line && MAIN_FILE_P (lookup_line (&pfile->line_maps, macro->line))) cpp_error_with_line (pfile, DL_WARNING, macro->line, 0, "macro \"%s\" is not used", NODE_NAME (node)); @@ -1568,7 +1566,7 @@ _cpp_create_definition (pfile, node) macro->params = 0; macro->paramc = 0; macro->variadic = 0; - macro->used = 0; + macro->used = !CPP_OPTION (pfile, warn_unused_macros); macro->count = 0; macro->fun_like = 0; /* To suppress some diagnostics. */ |