Commit 168d3732 by Zack Weinberg Committed by Zack Weinberg

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
parent 194ae3f6
2000-03-13 Zack Weinberg <zack@wolery.cumb.org> 2000-03-13 Zack Weinberg <zack@wolery.cumb.org>
* 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.
* cpphash.c (dump_hash_helper): Only dump nodes of type * cpphash.c (dump_hash_helper): Only dump nodes of type
T_MACRO. Emit a newline after each definition. T_MACRO. Emit a newline after each definition.
......
...@@ -2050,9 +2050,9 @@ cppulp.o: cppulp.c $(CONFIG_H) system.h output.h ...@@ -2050,9 +2050,9 @@ cppulp.o: cppulp.c $(CONFIG_H) system.h output.h
cpperror.o: cpperror.c $(CONFIG_H) $(LIBCPP_DEPS) cpperror.o: cpperror.c $(CONFIG_H) $(LIBCPP_DEPS)
cppexp.o: cppexp.c $(CONFIG_H) $(LIBCPP_DEPS) cppexp.o: cppexp.c $(CONFIG_H) $(LIBCPP_DEPS)
cpplex.o: cpplex.c $(CONFIG_H) $(LIBCPP_DEPS) cpplex.o: cpplex.c $(CONFIG_H) $(LIBCPP_DEPS)
cppfiles.o: cppfiles.c $(CONFIG_H) $(LIBCPP_DEPS) $(HASHTAB_H) cpplib.o: cpplib.c $(CONFIG_H) $(LIBCPP_DEPS) $(HASHTAB_H)
cpphash.o: cpphash.c $(CONFIG_H) $(LIBCPP_DEPS) $(HASHTAB_H) cpphash.o: cpphash.c $(CONFIG_H) $(LIBCPP_DEPS) $(HASHTAB_H)
cpplib.o: cpplib.c $(CONFIG_H) $(LIBCPP_DEPS) $(HASHTAB_H) mkdeps.h cppfiles.o: cppfiles.c $(CONFIG_H) $(LIBCPP_DEPS) $(HASHTAB_H) mkdeps.h
cppinit.o: cppinit.c $(CONFIG_H) $(LIBCPP_DEPS) $(HASHTAB_H) mkdeps.h \ cppinit.o: cppinit.c $(CONFIG_H) $(LIBCPP_DEPS) $(HASHTAB_H) mkdeps.h \
prefix.h output.h Makefile version.h prefix.h output.h Makefile version.h
......
...@@ -30,6 +30,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -30,6 +30,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "cpphash.h" #include "cpphash.h"
#include "hashtab.h" #include "hashtab.h"
#include "intl.h" #include "intl.h"
#include "mkdeps.h"
static IHASH *redundant_include_p PARAMS ((cpp_reader *, IHASH *, static IHASH *redundant_include_p PARAMS ((cpp_reader *, IHASH *,
struct file_name_list *)); struct file_name_list *));
...@@ -40,11 +41,14 @@ static char *remap_filename PARAMS ((cpp_reader *, char *, ...@@ -40,11 +41,14 @@ static char *remap_filename PARAMS ((cpp_reader *, char *,
struct file_name_list *)); struct file_name_list *));
static struct file_name_list *actual_directory static struct file_name_list *actual_directory
PARAMS ((cpp_reader *, const char *)); PARAMS ((cpp_reader *, const char *));
static unsigned int hash_IHASH PARAMS ((const void *)); static unsigned int hash_IHASH PARAMS ((const void *));
static int eq_IHASH PARAMS ((const void *, const void *)); static int eq_IHASH PARAMS ((const void *, const void *));
static int file_cleanup PARAMS ((cpp_buffer *, cpp_reader *)); 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 #if 0
static void hack_vms_include_specification PARAMS ((char *)); static void hack_vms_include_specification PARAMS ((char *));
...@@ -58,7 +62,7 @@ static void hack_vms_include_specification PARAMS ((char *)); ...@@ -58,7 +62,7 @@ static void hack_vms_include_specification PARAMS ((char *));
#endif #endif
/* Open files in nonblocking mode, so we don't get stuck if someone /* 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 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 not to acquire a controlling terminal by mistake (this can't happen
on sane systems, but paranoia is a virtue). */ on sane systems, but paranoia is a virtue). */
...@@ -185,8 +189,8 @@ file_cleanup (pbuf, pfile) ...@@ -185,8 +189,8 @@ file_cleanup (pbuf, pfile)
*IHASH is set to point to the include hash entry for this file, and *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 *BEFORE is set to 1 if the file was included before (but needs to be read
again). */ again). */
int static int
_cpp_find_include_file (pfile, fname, search_start, ihash, before) find_include_file (pfile, fname, search_start, ihash, before)
cpp_reader *pfile; cpp_reader *pfile;
const char *fname; const char *fname;
struct file_name_list *search_start; struct file_name_list *search_start;
...@@ -465,6 +469,120 @@ remap_filename (pfile, name, loc) ...@@ -465,6 +469,120 @@ remap_filename (pfile, name, loc)
return name; 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. /* Push an input buffer and load it up with the contents of FNAME.
If FNAME is "" or NULL, read standard input. */ If FNAME is "" or NULL, read standard input. */
int int
...@@ -506,7 +624,7 @@ cpp_read_file (pfile, fname) ...@@ -506,7 +624,7 @@ cpp_read_file (pfile, fname)
else else
f = open (fname, OMODES); 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. /* Read the contents of FD into the buffer on the top of PFILE's stack.
...@@ -515,8 +633,8 @@ cpp_read_file (pfile, fname) ...@@ -515,8 +633,8 @@ cpp_read_file (pfile, fname)
The caller is responsible for the cpp_push_buffer. */ The caller is responsible for the cpp_push_buffer. */
int static int
_cpp_read_include_file (pfile, fd, ihash) read_include_file (pfile, fd, ihash)
cpp_reader *pfile; cpp_reader *pfile;
int fd; int fd;
IHASH *ihash; IHASH *ihash;
......
...@@ -83,28 +83,9 @@ struct definition ...@@ -83,28 +83,9 @@ struct definition
It does not contain control words like "#define", which are recognized It does not contain control words like "#define", which are recognized
by a separate piece of code. */ by a separate piece of code. */
/* different flavors of hash nodes --- also used in keyword table */ /* different flavors of hash nodes */
enum node_type enum node_type
{ {
T_DEFINE = 1, /* `#define' */
T_INCLUDE, /* `#include' */
T_INCLUDE_NEXT, /* `#include_next' */
T_IMPORT, /* `#import' */
T_IFDEF, /* `#ifdef' */
T_IFNDEF, /* `#ifndef' */
T_IF, /* `#if' */
T_ELSE, /* `#else' */
T_PRAGMA, /* `#pragma' */
T_ELIF, /* `#elif' */
T_UNDEF, /* `#undef' */
T_LINE, /* `#line' */
T_ERROR, /* `#error' */
T_WARNING, /* `#warning' */
T_ENDIF, /* `#endif' */
T_SCCS, /* `#sccs' */
T_IDENT, /* `#ident' */
T_ASSERT, /* `#assert' */
T_UNASSERT, /* `#unassert', */
T_SPECLINE, /* `__LINE__' */ T_SPECLINE, /* `__LINE__' */
T_DATE, /* `__DATE__' */ T_DATE, /* `__DATE__' */
T_FILE, /* `__FILE__' */ T_FILE, /* `__FILE__' */
...@@ -292,10 +273,9 @@ extern void _cpp_dump_macro_hash PARAMS ((cpp_reader *)); ...@@ -292,10 +273,9 @@ extern void _cpp_dump_macro_hash PARAMS ((cpp_reader *));
/* In cppfiles.c */ /* In cppfiles.c */
extern void _cpp_simplify_pathname PARAMS ((char *)); extern void _cpp_simplify_pathname PARAMS ((char *));
extern int _cpp_find_include_file PARAMS ((cpp_reader *, const char *, extern void _cpp_execute_include PARAMS ((cpp_reader *, char *,
struct file_name_list *, unsigned int, int,
IHASH **, int *)); struct file_name_list *));
extern int _cpp_read_include_file PARAMS ((cpp_reader *, int, IHASH *));
extern void _cpp_init_include_hash PARAMS ((cpp_reader *)); extern void _cpp_init_include_hash PARAMS ((cpp_reader *));
/* In cppexp.c */ /* In cppexp.c */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment