Commit c31a6508 by Zack Weinberg Committed by Zack Weinberg

cppfiles.c: Include splay-tree.h, not hashtab.h.

	* cppfiles.c: Include splay-tree.h, not hashtab.h.
	(redundant_include_p, make_IHASH, hash_IHASH, eq_IHASH): Delete.
	(destroy_include_file_node): New.
	(_cpp_init_include_hash): Rename _cpp_init_include_table.
	Create a splay tree, not a hash table.
	(open_include_file): Look up the path in the include table,
	do the multiple include optimization here, etc.
	(cpp_included): Walk the path.
	(find_include_file): Just walk the path calling
	open_include_file, or call it directly for an absolute path.
	(_cpp_fake_ihash): Rename _cpp_fake_include and update for new
	scheme.
	(read_include_file): Update for new scheme.  Don't close the
	file unless reading fails.
	(_cpp_execute_include, cpp_read_file): Tweak for new scheme.

	* cpphash.h (struct ihash, NEVER_REINCLUDE): Delete.
	(struct include_file): New.
	(NEVER_REREAD, DO_NOT_REREAD, CPP_IN_SYSTEM_HEADER): New
	macros.
	(CPP_PEDANTIC, CPP_WTRADITIONAL): Update.
	Update prototypes.

	* cppinit.c: Include splay-tree.h.
	(cpp_reader_init, cpp_cleanup): Update.

	* cpplib.h (struct cpp_buffer): Change ihash field to
	'struct include_file *inc'.  Remove system_header_p.
	(struct cpp_reader): Change all_include_files to a
	struct splay_tree_s *.

	* cpplex.c: Update all references to cpp_buffer->ihash and/or
	cpp_buffer->system_header_p.
	(cpp_pop_buffer): Close file here, only if DO_NOT_REREAD.

From-SVN: r34636
parent e3cd9945
2000-06-21 Zack Weinberg <zack@wolery.cumb.org>
* cppfiles.c: Include splay-tree.h, not hashtab.h.
(redundant_include_p, make_IHASH, hash_IHASH, eq_IHASH): Delete.
(destroy_include_file_node): New.
(_cpp_init_include_hash): Rename _cpp_init_include_table.
Create a splay tree, not a hash table.
(open_include_file): Look up the path in the include table,
do the multiple include optimization here, etc.
(cpp_included): Walk the path.
(find_include_file): Just walk the path calling
open_include_file, or call it directly for an absolute path.
(_cpp_fake_ihash): Rename _cpp_fake_include and update for new
scheme.
(read_include_file): Update for new scheme. Don't close the
file unless reading fails.
(_cpp_execute_include, cpp_read_file): Tweak for new scheme.
* cpphash.h (struct ihash, NEVER_REINCLUDE): Delete.
(struct include_file): New.
(NEVER_REREAD, DO_NOT_REREAD, CPP_IN_SYSTEM_HEADER): New
macros.
(CPP_PEDANTIC, CPP_WTRADITIONAL): Update.
Update prototypes.
* cppinit.c: Include splay-tree.h.
(cpp_reader_init, cpp_cleanup): Update.
* cpplib.h (struct cpp_buffer): Change ihash field to
'struct include_file *inc'. Remove system_header_p.
(struct cpp_reader): Change all_include_files to a
struct splay_tree_s *.
* cpplex.c: Update all references to cpp_buffer->ihash and/or
cpp_buffer->system_header_p.
(cpp_pop_buffer): Close file here, only if DO_NOT_REREAD.
Wed Jun 21 11:05:48 2000 Martin Buchholz <martin@xemacs.org> Wed Jun 21 11:05:48 2000 Martin Buchholz <martin@xemacs.org>
* invoke.texi (g++): "g++" is not a script anymore. * invoke.texi (g++): "g++" is not a script anymore.
......
...@@ -1148,7 +1148,7 @@ special_symbol (pfile, hp) ...@@ -1148,7 +1148,7 @@ special_symbol (pfile, hp)
case T_STDC: case T_STDC:
#ifdef STDC_0_IN_SYSTEM_HEADERS #ifdef STDC_0_IN_SYSTEM_HEADERS
ip = cpp_file_buffer (pfile); ip = cpp_file_buffer (pfile);
if (ip && ip->system_header_p if (ip && ip->inc->sysp
&& !cpp_defined (pfile, DSC("__STRICT_ANSI__"))) && !cpp_defined (pfile, DSC("__STRICT_ANSI__")))
{ {
CPP_PUTC (pfile, '0'); CPP_PUTC (pfile, '0');
......
...@@ -53,27 +53,27 @@ struct file_name_list ...@@ -53,27 +53,27 @@ struct file_name_list
}; };
#define ABSOLUTE_PATH ((struct file_name_list *)-1) #define ABSOLUTE_PATH ((struct file_name_list *)-1)
/* This structure is used for the table of all includes. It is /* This structure is used for the table of all includes. */
indexed by the `short name' (the name as it appeared in the struct include_file
#include statement) which is stored in *nshort. */
struct ihash
{ {
/* Next file with the same short name but a const char *name; /* actual path name of file */
different (partial) pathname). */
struct ihash *next_this_file;
/* Location of the file in the include search path.
Used for include_next and to detect redundant includes. */
struct file_name_list *foundhere;
unsigned int hash; /* save hash value for future reference */
const char *nshort; /* name of file as referenced in #include;
points into name[] */
const cpp_hashnode *cmacro; /* macro, if any, preventing reinclusion. */ const cpp_hashnode *cmacro; /* macro, if any, preventing reinclusion. */
const char name[1]; /* (partial) pathname of file */ const struct file_name_list *foundhere;
/* location in search path where file was
found, for #include_next */
int fd; /* file descriptor possibly open on file */
unsigned char before; /* file has been included before */
unsigned char sysp; /* file is a system header */
}; };
typedef struct ihash IHASH;
#define NEVER_REINCLUDE ((const cpp_hashnode *)-1) /* The cmacro works like this: If it's NULL, the file is to be
included again. If it's NEVER_REREAD, the file is never to be
included again. Otherwise it is a macro hashnode, and the file is
to be included again if the macro is not defined. */
#define NEVER_REREAD ((const cpp_hashnode *)-1)
#define DO_NOT_REREAD(inc) \
((inc)->cmacro && \
((inc)->cmacro == NEVER_REREAD || (inc)->cmacro->type != T_VOID))
/* Character classes. /* Character classes.
If the definition of `numchar' looks odd to you, please look up the If the definition of `numchar' looks odd to you, please look up the
...@@ -143,10 +143,11 @@ extern unsigned char _cpp_IStable[256]; ...@@ -143,10 +143,11 @@ extern unsigned char _cpp_IStable[256];
#define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps) #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
#define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional) #define CPP_TRADITIONAL(PFILE) CPP_OPTION (PFILE, traditional)
#define CPP_PEDANTIC(PFILE) \ #define CPP_IN_SYSTEM_HEADER(PFILE) (cpp_file_buffer (PFILE)->inc->sysp)
(CPP_OPTION (PFILE, pedantic) && !CPP_BUFFER (PFILE)->system_header_p) #define CPP_PEDANTIC(PF) \
(CPP_OPTION (PF, pedantic) && !CPP_IN_SYSTEM_HEADER (PF))
#define CPP_WTRADITIONAL(PF) \ #define CPP_WTRADITIONAL(PF) \
(CPP_OPTION (PF, warn_traditional) && !CPP_BUFFER (PF)->system_header_p) (CPP_OPTION (PF, warn_traditional) && !CPP_IN_SYSTEM_HEADER (PF))
/* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion. /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
(Note that it is false while we're expanding macro *arguments*.) */ (Note that it is false while we're expanding macro *arguments*.) */
...@@ -192,8 +193,8 @@ extern void _cpp_simplify_pathname PARAMS ((char *)); ...@@ -192,8 +193,8 @@ extern void _cpp_simplify_pathname PARAMS ((char *));
extern void _cpp_execute_include PARAMS ((cpp_reader *, U_CHAR *, extern void _cpp_execute_include PARAMS ((cpp_reader *, U_CHAR *,
unsigned int, int, unsigned int, int,
struct file_name_list *)); struct file_name_list *));
extern void _cpp_init_include_hash PARAMS ((cpp_reader *)); extern void _cpp_init_include_table PARAMS ((cpp_reader *));
extern const char *_cpp_fake_ihash PARAMS ((cpp_reader *, const char *)); extern const char *_cpp_fake_include PARAMS ((cpp_reader *, const char *));
/* In cppexp.c */ /* In cppexp.c */
extern int _cpp_parse_expr PARAMS ((cpp_reader *)); extern int _cpp_parse_expr PARAMS ((cpp_reader *));
...@@ -234,6 +235,10 @@ extern int _cpp_handle_directive PARAMS ((cpp_reader *)); ...@@ -234,6 +235,10 @@ extern int _cpp_handle_directive PARAMS ((cpp_reader *));
extern void _cpp_unwind_if_stack PARAMS ((cpp_reader *, cpp_buffer *)); extern void _cpp_unwind_if_stack PARAMS ((cpp_reader *, cpp_buffer *));
extern void _cpp_check_directive PARAMS ((cpp_toklist *, cpp_token *)); extern void _cpp_check_directive PARAMS ((cpp_toklist *, cpp_token *));
/* Utility routines and macros. */
#define xnew(T) (T *) xmalloc (sizeof(T))
#define xnewvec(T, N) (T *) xmalloc (sizeof(T) * (N))
/* These are inline functions instead of macros so we can get type /* These are inline functions instead of macros so we can get type
checking. */ checking. */
......
...@@ -22,6 +22,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -22,6 +22,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "hashtab.h" #include "hashtab.h"
#include "splay-tree.h"
#include "cpplib.h" #include "cpplib.h"
#include "cpphash.h" #include "cpphash.h"
#include "output.h" #include "output.h"
...@@ -551,7 +552,7 @@ cpp_reader_init (pfile) ...@@ -551,7 +552,7 @@ cpp_reader_init (pfile)
(struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending)); (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
_cpp_init_macro_hash (pfile); _cpp_init_macro_hash (pfile);
_cpp_init_include_hash (pfile); _cpp_init_include_table (pfile);
} }
/* Initialize a cpp_printer structure. As a side effect, open the /* Initialize a cpp_printer structure. As a side effect, open the
...@@ -605,7 +606,7 @@ cpp_cleanup (pfile) ...@@ -605,7 +606,7 @@ cpp_cleanup (pfile)
deps_free (pfile->deps); deps_free (pfile->deps);
htab_delete (pfile->hashtab); htab_delete (pfile->hashtab);
htab_delete (pfile->all_include_files); splay_tree_delete (pfile->all_include_files);
} }
......
...@@ -211,7 +211,7 @@ cpp_pop_buffer (pfile) ...@@ -211,7 +211,7 @@ cpp_pop_buffer (pfile)
if (ACTIVE_MARK_P (pfile)) if (ACTIVE_MARK_P (pfile))
cpp_ice (pfile, "mark active in cpp_pop_buffer"); cpp_ice (pfile, "mark active in cpp_pop_buffer");
if (buf->ihash) if (buf->inc)
{ {
_cpp_unwind_if_stack (pfile, buf); _cpp_unwind_if_stack (pfile, buf);
if (buf->buf) if (buf->buf)
...@@ -220,10 +220,17 @@ cpp_pop_buffer (pfile) ...@@ -220,10 +220,17 @@ cpp_pop_buffer (pfile)
pfile->system_include_depth--; pfile->system_include_depth--;
if (pfile->potential_control_macro) if (pfile->potential_control_macro)
{ {
buf->ihash->cmacro = pfile->potential_control_macro; if (buf->inc->cmacro != NEVER_REREAD)
buf->inc->cmacro = pfile->potential_control_macro;
pfile->potential_control_macro = 0; pfile->potential_control_macro = 0;
} }
pfile->input_stack_listing_current = 0; pfile->input_stack_listing_current = 0;
/* If the file will not be included again, then close it. */
if (DO_NOT_REREAD (buf->inc))
{
close (buf->inc->fd);
buf->inc->fd = -1;
}
} }
else if (buf->macro) else if (buf->macro)
{ {
...@@ -321,13 +328,13 @@ output_line_command (pfile, print, line) ...@@ -321,13 +328,13 @@ output_line_command (pfile, print, line)
if (CPP_OPTION (pfile, cplusplus)) if (CPP_OPTION (pfile, cplusplus))
fprintf (print->outf, "# %u \"%s\"%s%s%s\n", line, ip->nominal_fname, fprintf (print->outf, "# %u \"%s\"%s%s%s\n", line, ip->nominal_fname,
codes[change], codes[change],
ip->system_header_p ? " 3" : "", ip->inc->sysp ? " 3" : "",
(ip->system_header_p == 2) ? " 4" : ""); (ip->inc->sysp == 2) ? " 4" : "");
else else
#endif #endif
fprintf (print->outf, "# %u \"%s\"%s%s\n", line, ip->nominal_fname, fprintf (print->outf, "# %u \"%s\"%s%s\n", line, ip->nominal_fname,
codes[change], codes[change],
ip->system_header_p ? " 3" : ""); ip->inc->sysp ? " 3" : "");
print->lineno = line; print->lineno = line;
} }
...@@ -516,7 +523,7 @@ cpp_file_buffer (pfile) ...@@ -516,7 +523,7 @@ cpp_file_buffer (pfile)
cpp_buffer *ip; cpp_buffer *ip;
for (ip = CPP_BUFFER (pfile); ip; ip = CPP_PREV_BUFFER (ip)) for (ip = CPP_BUFFER (pfile); ip; ip = CPP_PREV_BUFFER (ip))
if (ip->ihash != NULL) if (ip->inc != NULL)
return ip; return ip;
return NULL; return NULL;
} }
...@@ -914,7 +921,7 @@ skip_comment (pfile, m) ...@@ -914,7 +921,7 @@ skip_comment (pfile, m)
} }
else if (m == '/' && PEEKC() == '/') else if (m == '/' && PEEKC() == '/')
{ {
if (CPP_BUFFER (pfile)->system_header_p) if (CPP_IN_SYSTEM_HEADER (pfile))
{ {
/* We silently allow C++ comments in system headers, irrespective /* We silently allow C++ comments in system headers, irrespective
of conformance mode, because lots of busted systems do that of conformance mode, because lots of busted systems do that
...@@ -2965,7 +2972,7 @@ _cpp_lex_line (pfile, list) ...@@ -2965,7 +2972,7 @@ _cpp_lex_line (pfile, list)
irrespective of conformance mode, because lots of irrespective of conformance mode, because lots of
broken systems do that and trying to clean it up broken systems do that and trying to clean it up
in fixincludes is a nightmare. */ in fixincludes is a nightmare. */
if (buffer->system_header_p) if (CPP_IN_SYSTEM_HEADER (pfile))
goto do_line_comment; goto do_line_comment;
else if (CPP_OPTION (pfile, cplusplus_comments)) else if (CPP_OPTION (pfile, cplusplus_comments))
{ {
......
...@@ -214,7 +214,7 @@ _cpp_handle_directive (pfile) ...@@ -214,7 +214,7 @@ _cpp_handle_directive (pfile)
return 0; return 0;
if (CPP_PEDANTIC (pfile) if (CPP_PEDANTIC (pfile)
&& CPP_BUFFER (pfile)->ihash && CPP_BUFFER (pfile)->inc
&& ! CPP_OPTION (pfile, preprocessed)) && ! CPP_OPTION (pfile, preprocessed))
cpp_pedwarn (pfile, "# followed by integer"); cpp_pedwarn (pfile, "# followed by integer");
i = T_LINE; i = T_LINE;
...@@ -463,7 +463,7 @@ do_import (pfile) ...@@ -463,7 +463,7 @@ do_import (pfile)
U_CHAR *token; U_CHAR *token;
if (CPP_OPTION (pfile, warn_import) if (CPP_OPTION (pfile, warn_import)
&& !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning) && !CPP_IN_SYSTEM_HEADER (pfile) && !pfile->import_warning)
{ {
pfile->import_warning = 1; pfile->import_warning = 1;
cpp_warning (pfile, cpp_warning (pfile,
...@@ -508,8 +508,8 @@ do_include_next (pfile) ...@@ -508,8 +508,8 @@ do_include_next (pfile)
file like any other included source, but generate a warning. */ file like any other included source, but generate a warning. */
if (CPP_PREV_BUFFER (CPP_BUFFER (pfile))) if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)))
{ {
if (CPP_BUFFER (pfile)->ihash->foundhere != ABSOLUTE_PATH) if (CPP_BUFFER (pfile)->inc->foundhere)
search_start = CPP_BUFFER (pfile)->ihash->foundhere->next; search_start = CPP_BUFFER (pfile)->inc->foundhere->next;
} }
else else
cpp_warning (pfile, "#include_next in primary source file"); cpp_warning (pfile, "#include_next in primary source file");
...@@ -603,23 +603,23 @@ do_line (pfile) ...@@ -603,23 +603,23 @@ do_line (pfile)
if (action_number == 1) if (action_number == 1)
{ {
pfile->buffer_stack_depth++; pfile->buffer_stack_depth++;
ip->system_header_p = 0; ip->inc->sysp = 0;
read_line_number (pfile, &action_number); read_line_number (pfile, &action_number);
} }
else if (action_number == 2) else if (action_number == 2)
{ {
pfile->buffer_stack_depth--; pfile->buffer_stack_depth--;
ip->system_header_p = 0; ip->inc->sysp = 0;
read_line_number (pfile, &action_number); read_line_number (pfile, &action_number);
} }
if (action_number == 3) if (action_number == 3)
{ {
ip->system_header_p = 1; ip->inc->sysp = 1;
read_line_number (pfile, &action_number); read_line_number (pfile, &action_number);
} }
if (action_number == 4) if (action_number == 4)
{ {
ip->system_header_p = 2; ip->inc->sysp = 2;
read_line_number (pfile, &action_number); read_line_number (pfile, &action_number);
} }
} }
...@@ -628,10 +628,10 @@ do_line (pfile) ...@@ -628,10 +628,10 @@ do_line (pfile)
if (strcmp ((const char *)fname, ip->nominal_fname)) if (strcmp ((const char *)fname, ip->nominal_fname))
{ {
if (!strcmp ((const char *)fname, ip->ihash->name)) if (!strcmp ((const char *)fname, ip->inc->name))
ip->nominal_fname = ip->ihash->name; ip->nominal_fname = ip->inc->name;
else else
ip->nominal_fname = _cpp_fake_ihash (pfile, (const char *)fname); ip->nominal_fname = _cpp_fake_include (pfile, (const char *)fname);
} }
} }
else if (token != CPP_VSPACE && token != CPP_EOF) else if (token != CPP_VSPACE && token != CPP_EOF)
...@@ -868,13 +868,13 @@ do_pragma_once (pfile) ...@@ -868,13 +868,13 @@ do_pragma_once (pfile)
/* Allow #pragma once in system headers, since that's not the user's /* Allow #pragma once in system headers, since that's not the user's
fault. */ fault. */
if (!ip->system_header_p) if (!CPP_IN_SYSTEM_HEADER (pfile))
cpp_warning (pfile, "#pragma once is obsolete"); cpp_warning (pfile, "#pragma once is obsolete");
if (CPP_PREV_BUFFER (ip) == NULL) if (CPP_PREV_BUFFER (ip) == NULL)
cpp_warning (pfile, "#pragma once outside include file"); cpp_warning (pfile, "#pragma once outside include file");
else else
ip->ihash->cmacro = NEVER_REINCLUDE; ip->inc->cmacro = NEVER_REREAD;
return 1; return 1;
} }
...@@ -978,7 +978,7 @@ do_pragma_system_header (pfile) ...@@ -978,7 +978,7 @@ do_pragma_system_header (pfile)
if (CPP_PREV_BUFFER (ip) == NULL) if (CPP_PREV_BUFFER (ip) == NULL)
cpp_warning (pfile, "#pragma system_header outside include file"); cpp_warning (pfile, "#pragma system_header outside include file");
else else
ip->system_header_p = 1; ip->inc->sysp = 1;
return 1; return 1;
} }
......
...@@ -233,9 +233,9 @@ struct cpp_buffer ...@@ -233,9 +233,9 @@ struct cpp_buffer
/* Actual directory of this file, used only for "" includes */ /* Actual directory of this file, used only for "" includes */
struct file_name_list *actual_dir; struct file_name_list *actual_dir;
/* Pointer into the include hash table. Used for include_next and /* Pointer into the include table. Used for include_next and
to record control macros. */ to record control macros. */
struct ihash *ihash; struct include_file *inc;
/* If the buffer is the expansion of a macro, this points to the /* If the buffer is the expansion of a macro, this points to the
macro's hash table entry. */ macro's hash table entry. */
...@@ -248,9 +248,6 @@ struct cpp_buffer ...@@ -248,9 +248,6 @@ struct cpp_buffer
/* Line number at line_base (above). */ /* Line number at line_base (above). */
unsigned int lineno; unsigned int lineno;
/* True if this is a header file included using <FILENAME>. */
char system_header_p;
/* True if buffer contains escape sequences. /* True if buffer contains escape sequences.
Currently there are two kinds: Currently there are two kinds:
"\r-" means following identifier should not be macro-expanded. "\r-" means following identifier should not be macro-expanded.
...@@ -499,7 +496,7 @@ struct cpp_reader ...@@ -499,7 +496,7 @@ struct cpp_reader
struct htab *hashtab; struct htab *hashtab;
/* Hash table of other included files. See cppfiles.c */ /* Hash table of other included files. See cppfiles.c */
struct htab *all_include_files; struct splay_tree_s *all_include_files;
/* Chain of `actual directory' file_name_list entries, /* Chain of `actual directory' file_name_list entries,
for "" inclusion. */ for "" inclusion. */
......
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