From d4506961cd58fde924aa6561e8896e18161b82ad Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Wed, 28 Jun 2000 19:03:08 +0000 Subject: cppfiles.c (open_include_file): If open(2) returns EMFILE or ENFILE... * cppfiles.c (open_include_file): If open(2) returns EMFILE or ENFILE, close all cached file descriptors and try again. (_cpp_execute_include): Keep a count of the number of times each header is included. (close_cached_fd): New function. * cpphash.h (struct include_file): Rename before to include_count; all users updated. Make include_count and sysp unsigned short. * cppinit.c (cpp_finish): If -H, report headers that could use reinclude guards. (report_missing_guard): New function. From-SVN: r34760 --- gcc/cppinit.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'gcc/cppinit.c') diff --git a/gcc/cppinit.c b/gcc/cppinit.c index e21c566..0cbccae 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -227,6 +227,7 @@ static int opt_comp PARAMS ((const void *, const void *)); #endif static int parse_option PARAMS ((const char *)); static int handle_option PARAMS ((cpp_reader *, int, char **)); +static int report_missing_guard PARAMS ((splay_tree_node, void *)); /* Fourth argument to append_include_chain: chain to use */ enum { QUOTE = 0, BRACKET, SYSTEM, AFTER }; @@ -1003,6 +1004,27 @@ cpp_start_read (pfile, print, fname) return 1; } +static int +report_missing_guard (n, b) + splay_tree_node n; + void *b; +{ + struct include_file *f = (struct include_file *) n->value; + int *bannerp = (int *)b; + + if (f && f->cmacro == 0 && f->include_count == 1) + { + if (*bannerp == 0) + { + fputs (_("Multiple include guards may be useful for:\n"), stderr); + *bannerp = 1; + } + fputs (f->name, stderr); + putc ('\n', stderr); + } + return 0; +} + /* This is called at the end of preprocessing. It pops the last buffer and writes dependency output. It should also clear macro definitions, such that you could call cpp_start_read @@ -1055,6 +1077,14 @@ cpp_finish (pfile, print) if (ferror (print->outf) || fclose (print->outf)) cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname)); } + + /* Report on headers that could use multiple include guards. */ + if (CPP_OPTION (pfile, print_include_names)) + { + int banner = 0; + splay_tree_foreach (pfile->all_include_files, report_missing_guard, + (void *) &banner); + } } static void -- cgit v1.1