aboutsummaryrefslogtreecommitdiff
path: root/gcc/cppfiles.c
diff options
context:
space:
mode:
authorZack Weinberg <zack@wolery.cumb.org>2000-03-14 06:34:11 +0000
committerZack Weinberg <zack@gcc.gnu.org>2000-03-14 06:34:11 +0000
commit168d3732aa67159489982b879ce29147ed94a4ac (patch)
tree193e65c2271a732229c4e6fa06aba75d25b7e835 /gcc/cppfiles.c
parent194ae3f644daec5af81b93bbf627275756852728 (diff)
downloadgcc-168d3732aa67159489982b879ce29147ed94a4ac.zip
gcc-168d3732aa67159489982b879ce29147ed94a4ac.tar.gz
gcc-168d3732aa67159489982b879ce29147ed94a4ac.tar.bz2
cppfiles.c: Include mkdeps.h.
* cppfiles.c: Include mkdeps.h. (find_include_file, read_include_file): Remove _cpp_ prefix from name, make static. (_cpp_execute_include): New function, broken out of do_include. * cpplib.c: Don't include mkdeps.h. (struct directive): Remove type field. Reorder entries. The function takes only one argument. (struct if_stack): Make type field an int. (directive_table): Rename to dtable. Generate it, the prototypes of the directive handlers, and the enum for the directive numbers, from a template macro. (do_ifndef, do_include_next, do_import): New functions. (do_define, do_include, do_endif, do_ifdef, do_if, do_else, do_undef, do_line, do_elif, do_error, do_pragma, do_warning, do_ident, do_assert, do_unassert, do_sccs): Take only one argument. (do_sccs): Define always, but alter behavior based on SCCS_DIRECTIVE. (_cpp_handle_directive, consider_directive_while_skipping): Restructure for new directive table layout. (pass_thru_directive): Take a directive number, not a pointer to a struct directive. (parse_include): New function, broken out of do_include. (do_include, do_import, do_include_next): Use parse_include and _cpp_execute_include. (do_elif, do_else): Test for T_ELSE specifically when checking for #elif/#else after #else. (parse_ifdef): New function, broken out of do_ifdef. (validate_else): Expect a name arg without a leading #. (if_directive_name): Delete. (cpp_define, cpp_assert, cpp_undef, cpp_unassert): Call directive handlers with only one argument. * cpphash.h: Update prototypes. (enum node_type): Remove entries for directives. * Makefile.in: Update dependencies. From-SVN: r32519
Diffstat (limited to 'gcc/cppfiles.c')
-rw-r--r--gcc/cppfiles.c134
1 files changed, 126 insertions, 8 deletions
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index ec7529f..cff8cd2 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -30,6 +30,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cpphash.h"
#include "hashtab.h"
#include "intl.h"
+#include "mkdeps.h"
static IHASH *redundant_include_p PARAMS ((cpp_reader *, IHASH *,
struct file_name_list *));
@@ -40,11 +41,14 @@ static char *remap_filename PARAMS ((cpp_reader *, char *,
struct file_name_list *));
static struct file_name_list *actual_directory
PARAMS ((cpp_reader *, const char *));
-
static unsigned int hash_IHASH PARAMS ((const void *));
static int eq_IHASH PARAMS ((const void *, const void *));
-
static int file_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
+static int find_include_file PARAMS ((cpp_reader *, const char *,
+ struct file_name_list *,
+ IHASH **, int *));
+static int read_include_file PARAMS ((cpp_reader *, int, IHASH *));
+
#if 0
static void hack_vms_include_specification PARAMS ((char *));
@@ -58,7 +62,7 @@ static void hack_vms_include_specification PARAMS ((char *));
#endif
/* Open files in nonblocking mode, so we don't get stuck if someone
- clever has asked cpp to process /dev/rmt0. _cpp_read_include_file
+ clever has asked cpp to process /dev/rmt0. read_include_file
will check that we have a real file to work with. Also take care
not to acquire a controlling terminal by mistake (this can't happen
on sane systems, but paranoia is a virtue). */
@@ -185,8 +189,8 @@ file_cleanup (pbuf, pfile)
*IHASH is set to point to the include hash entry for this file, and
*BEFORE is set to 1 if the file was included before (but needs to be read
again). */
-int
-_cpp_find_include_file (pfile, fname, search_start, ihash, before)
+static int
+find_include_file (pfile, fname, search_start, ihash, before)
cpp_reader *pfile;
const char *fname;
struct file_name_list *search_start;
@@ -465,6 +469,120 @@ remap_filename (pfile, name, loc)
return name;
}
+
+void
+_cpp_execute_include (pfile, fname, len, no_reinclude, search_start)
+ cpp_reader *pfile;
+ char *fname;
+ unsigned int len;
+ int no_reinclude;
+ struct file_name_list *search_start;
+{
+ IHASH *ihash;
+ int fd;
+ int angle_brackets = fname[0] == '<';
+ int before;
+
+ if (!search_start)
+ {
+ if (angle_brackets)
+ search_start = CPP_OPTIONS (pfile)->bracket_include;
+ else if (CPP_OPTIONS (pfile)->ignore_srcdir)
+ search_start = CPP_OPTIONS (pfile)->quote_include;
+ else
+ search_start = CPP_BUFFER (pfile)->actual_dir;
+ }
+
+ if (!search_start)
+ {
+ cpp_error (pfile, "No include path in which to find %s", fname);
+ return;
+ }
+
+ /* Remove quote marks. */
+ fname++;
+ len -= 2;
+ fname[len] = '\0';
+
+ fd = find_include_file (pfile, fname, search_start, &ihash, &before);
+
+ if (fd == -2)
+ return;
+
+ if (fd == -1)
+ {
+ if (CPP_OPTIONS (pfile)->print_deps_missing_files
+ && CPP_PRINT_DEPS (pfile) > (angle_brackets ||
+ (pfile->system_include_depth > 0)))
+ {
+ if (!angle_brackets)
+ deps_add_dep (pfile->deps, fname);
+ else
+ {
+ char *p;
+ struct file_name_list *ptr;
+ /* If requested as a system header, assume it belongs in
+ the first system header directory. */
+ if (CPP_OPTIONS (pfile)->bracket_include)
+ ptr = CPP_OPTIONS (pfile)->bracket_include;
+ else
+ ptr = CPP_OPTIONS (pfile)->quote_include;
+
+ p = (char *) alloca (strlen (ptr->name)
+ + strlen (fname) + 2);
+ if (*ptr->name != '\0')
+ {
+ strcpy (p, ptr->name);
+ strcat (p, "/");
+ }
+ strcat (p, fname);
+ deps_add_dep (pfile->deps, p);
+ }
+ }
+ /* If -M was specified, and this header file won't be added to
+ the dependency list, then don't count this as an error,
+ because we can still produce correct output. Otherwise, we
+ can't produce correct output, because there may be
+ dependencies we need inside the missing file, and we don't
+ know what directory this missing file exists in. */
+ else if (CPP_PRINT_DEPS (pfile)
+ && (CPP_PRINT_DEPS (pfile)
+ <= (angle_brackets || (pfile->system_include_depth > 0))))
+ cpp_warning (pfile, "No include path in which to find %s", fname);
+ else
+ cpp_error_from_errno (pfile, fname);
+
+ return;
+ }
+
+ /* For -M, add the file to the dependencies on its first inclusion. */
+ if (!before && (CPP_PRINT_DEPS (pfile)
+ > (angle_brackets || (pfile->system_include_depth > 0))))
+ deps_add_dep (pfile->deps, ihash->name);
+
+ /* Handle -H option. */
+ if (CPP_OPTIONS(pfile)->print_include_names)
+ {
+ cpp_buffer *fp = CPP_BUFFER (pfile);
+ while ((fp = CPP_PREV_BUFFER (fp)) != NULL)
+ putc ('.', stderr);
+ fprintf (stderr, " %s\n", ihash->name);
+ }
+
+ /* Actually process the file */
+
+ if (no_reinclude)
+ ihash->control_macro = (const U_CHAR *) "";
+
+ if (read_include_file (pfile, fd, ihash))
+ {
+ _cpp_output_line_command (pfile, enter_file);
+ if (angle_brackets)
+ pfile->system_include_depth++; /* Decremented in file_cleanup. */
+ }
+}
+
+
/* Push an input buffer and load it up with the contents of FNAME.
If FNAME is "" or NULL, read standard input. */
int
@@ -506,7 +624,7 @@ cpp_read_file (pfile, fname)
else
f = open (fname, OMODES);
- return _cpp_read_include_file (pfile, f, ih);
+ return read_include_file (pfile, f, ih);
}
/* Read the contents of FD into the buffer on the top of PFILE's stack.
@@ -515,8 +633,8 @@ cpp_read_file (pfile, fname)
The caller is responsible for the cpp_push_buffer. */
-int
-_cpp_read_include_file (pfile, fd, ihash)
+static int
+read_include_file (pfile, fd, ihash)
cpp_reader *pfile;
int fd;
IHASH *ihash;