cppinit.c: Instead of one pending list...

1999-03-15 21:39 -0500  Zack Weinberg  <zack@rabi.columbia.edu>
	* cppinit.c: Instead of one pending list, keep separate lists
	for each category of pending option: -D/-U, -A, -include,
	-imacros.  Move the four partial include-path lists into the
	pending block.  Use head and tail pointers so we don't ever
	have to reverse the lists.
	(cpp_start_read): Break out blocks of code to their own
	functions: install_predefs and initialize_dependency_output.
	Use path_include for C_INCLUDE_PATH and friends as well as
	CPATH.  Remove include_defaults gunk.  Warn about the
	combination of -lang-chill and -trigraphs.  Optimize string
	bashing.  Walk each pending list once, deallocating as we go.
	(append_include_chain): Brought over from cppfiles.c.  Mark
	dirs as system include dirs if and only if appending to
	system include path. If opts->verbose, print a notice when a
	dir is dropped from the include path because it doesn't
	exist.  Fix memory leak: this function is not supposed to copy
	its DIR argument.
	(nreverse_pending, push_pending): Removed.
	(APPEND): New macro for adding to pending lists.
	(path_include): Can now add to any partial include path.
	(base_name): Bring over from cccp.c.
	(cpp_options_init): Allocate the pending block.
	(cpp_handle_option): Add --version.  Exit after --help.  Fix
	formatting.  Order -ifoo options by frequency of usage.
	(install_predefs): New function, simplified version of code
	that was in cpp_start_read.
	(initialize_dependency_output): Likewise.  Understand OBJECT_SUFFIX.
	* cppfiles.c (simplify_pathname): Export.
	(merge_include_chains):  Don't nreverse the lists.  If
	opts->verbose, print a notice when a duplicate dir is detected
	and dropped from the include path.
	(finclude): Fix excessive cleverness in setting
	fp->system_header_p.
	(actual_directory): Set x->sysp from
	CPP_BUFFER (pfile)->system_header_p so that one system header
	may include another with "".
	(deps_output): Fix double adjustment of deps_size which would
	cause all dependencies after the first two lines to be lost.
	* cpplib.c (cpp_unassert): New function.
	* cpplib.h: Lay out struct cpp_pending here.  Adjust
	prototypes.  Add include_prefix_len to struct cpp_options.

From-SVN: r25793
This commit is contained in:
Zack Weinberg 1999-03-15 18:42:46 +00:00 committed by Zack Weinberg
parent 56dc4d15c4
commit 0b22d65c9a
5 changed files with 1194 additions and 1077 deletions

View File

@ -1,3 +1,52 @@
1999-03-15 21:39 -0500 Zack Weinberg <zack@rabi.columbia.edu>
* cppinit.c: Instead of one pending list, keep separate lists
for each category of pending option: -D/-U, -A, -include,
-imacros. Move the four partial include-path lists into the
pending block. Use head and tail pointers so we don't ever
have to reverse the lists.
(cpp_start_read): Break out blocks of code to their own
functions: install_predefs and initialize_dependency_output.
Use path_include for C_INCLUDE_PATH and friends as well as
CPATH. Remove include_defaults gunk. Warn about the
combination of -lang-chill and -trigraphs. Optimize string
bashing. Walk each pending list once, deallocating as we go.
(append_include_chain): Brought over from cppfiles.c. Mark
dirs as system include dirs if and only if appending to
system include path. If opts->verbose, print a notice when a
dir is dropped from the include path because it doesn't
exist. Fix memory leak: this function is not supposed to copy
its DIR argument.
(nreverse_pending, push_pending): Removed.
(APPEND): New macro for adding to pending lists.
(path_include): Can now add to any partial include path.
(base_name): Bring over from cccp.c.
(cpp_options_init): Allocate the pending block.
(cpp_handle_option): Add --version. Exit after --help. Fix
formatting. Order -ifoo options by frequency of usage.
(install_predefs): New function, simplified version of code
that was in cpp_start_read.
(initialize_dependency_output): Likewise. Understand OBJECT_SUFFIX.
* cppfiles.c (simplify_pathname): Export.
(merge_include_chains): Don't nreverse the lists. If
opts->verbose, print a notice when a duplicate dir is detected
and dropped from the include path.
(finclude): Fix excessive cleverness in setting
fp->system_header_p.
(actual_directory): Set x->sysp from
CPP_BUFFER (pfile)->system_header_p so that one system header
may include another with "".
(deps_output): Fix double adjustment of deps_size which would
cause all dependencies after the first two lines to be lost.
* cpplib.c (cpp_unassert): New function.
* cpplib.h: Lay out struct cpp_pending here. Adjust
prototypes. Add include_prefix_len to struct cpp_options.
Mon Mar 15 16:01:52 1999 Jim Wilson <wilson@cygnus.com>
* config/misp/mips.h (REGISTER_MOVE_COST): Make the cost of moving

View File

@ -43,7 +43,6 @@ static char *remap_filename PROTO ((cpp_reader *, char *,
struct file_name_list *));
static long read_and_prescan PROTO ((cpp_reader *, cpp_buffer *,
int, size_t));
static void simplify_pathname PROTO ((char *));
static struct file_name_list *actual_directory PROTO ((cpp_reader *, char *));
#if 0
@ -61,54 +60,6 @@ static void hack_vms_include_specification PROTO ((char *));
#define INO_T_EQ(a, b) ((a) == (b))
#endif
/* Append an entry for dir DIR to list LIST, simplifying it if
possible. SYS says whether this is a system include directory.
*** DIR is modified in place. It must be writable and permanently
allocated. LIST is a pointer to the head pointer, because we actually
*prepend* the dir, and reverse the list later (in merge_include_chains). */
void
append_include_chain (pfile, list, dir, sysp)
cpp_reader *pfile;
struct file_name_list **list;
const char *dir;
int sysp;
{
struct file_name_list *new;
struct stat st;
unsigned int len;
char * newdir = xstrdup (dir);
simplify_pathname (newdir);
if (stat (newdir, &st))
{
/* Dirs that don't exist are silently ignored. */
if (errno != ENOENT)
cpp_perror_with_name (pfile, newdir);
return;
}
if (!S_ISDIR (st.st_mode))
{
cpp_message (pfile, 1, "%s: %s: Not a directory", progname, newdir);
return;
}
len = strlen(newdir);
if (len > pfile->max_include_len)
pfile->max_include_len = len;
new = (struct file_name_list *)xmalloc (sizeof (struct file_name_list));
new->name = newdir;
new->nlen = len;
new->next = *list;
new->ino = st.st_ino;
new->dev = st.st_dev;
new->sysp = sysp;
new->name_map = NULL;
*list = new;
}
/* Merge the four include chains together in the order quote, bracket,
system, after. Remove duplicate dirs (as determined by
INO_T_EQ()). The system_include and after_include chains are never
@ -122,51 +73,19 @@ void
merge_include_chains (opts)
struct cpp_options *opts;
{
struct file_name_list *prev, *next, *cur, *other;
struct file_name_list *prev, *cur, *other;
struct file_name_list *quote, *brack, *systm, *after;
struct file_name_list *qtail, *btail, *stail, *atail;
qtail = opts->quote_include;
btail = opts->bracket_include;
stail = opts->system_include;
atail = opts->after_include;
qtail = opts->pending->quote_tail;
btail = opts->pending->brack_tail;
stail = opts->pending->systm_tail;
atail = opts->pending->after_tail;
/* Nreverse the four lists. */
prev = 0;
for (cur = qtail; cur; cur = next)
{
next = cur->next;
cur->next = prev;
prev = cur;
}
quote = prev;
prev = 0;
for (cur = btail; cur; cur = next)
{
next = cur->next;
cur->next = prev;
prev = cur;
}
brack = prev;
prev = 0;
for (cur = stail; cur; cur = next)
{
next = cur->next;
cur->next = prev;
prev = cur;
}
systm = prev;
prev = 0;
for (cur = atail; cur; cur = next)
{
next = cur->next;
cur->next = prev;
prev = cur;
}
after = prev;
quote = opts->pending->quote_head;
brack = opts->pending->brack_head;
systm = opts->pending->systm_head;
after = opts->pending->after_head;
/* Paste together bracket, system, and after include chains. */
if (stail)
@ -188,7 +107,10 @@ merge_include_chains (opts)
then we may lose directories from the <> search path that should
be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
-Ibar -I- -Ifoo -Iquux. */
-Ibar -I- -Ifoo -Iquux.
Note that this algorithm is quadratic in the number of -I switches,
which is acceptable since there aren't usually that many of them. */
for (cur = quote; cur; cur = cur->next)
{
@ -196,6 +118,9 @@ merge_include_chains (opts)
if (INO_T_EQ (cur->ino, other->ino)
&& cur->dev == other->dev)
{
if (opts->verbose)
cpp_notice ("ignoring duplicate directory `%s'\n", cur->name);
prev->next = cur->next;
free (cur->name);
free (cur);
@ -212,6 +137,9 @@ merge_include_chains (opts)
if (INO_T_EQ (cur->ino, other->ino)
&& cur->dev == other->dev)
{
if (opts->verbose)
cpp_notice ("ignoring duplicate directory `%s'\n", cur->name);
prev->next = cur->next;
free (cur->name);
free (cur);
@ -227,6 +155,10 @@ merge_include_chains (opts)
{
if (quote == qtail)
{
if (opts->verbose)
cpp_notice ("ignoring duplicate directory `%s'\n",
quote->name);
free (quote->name);
free (quote);
quote = brack;
@ -237,6 +169,10 @@ merge_include_chains (opts)
while (cur->next != qtail)
cur = cur->next;
cur->next = brack;
if (opts->verbose)
cpp_notice ("ignoring duplicate directory `%s'\n",
qtail->name);
free (qtail->name);
free (qtail);
}
@ -249,8 +185,6 @@ merge_include_chains (opts)
opts->quote_include = quote;
opts->bracket_include = brack;
opts->system_include = NULL;
opts->after_include = NULL;
}
/* Look up or add an entry to the table of all includes. This table
@ -742,8 +676,8 @@ finclude (pfile, fd, ihash)
close (fd);
fp->rlimit = fp->alimit = fp->buf + length;
fp->cur = fp->buf;
fp->system_header_p = (ihash->foundhere != ABSOLUTE_PATH
&& ihash->foundhere->sysp);
if (ihash->foundhere != ABSOLUTE_PATH)
fp->system_header_p = ihash->foundhere->sysp;
fp->lineno = 1;
fp->colno = 1;
fp->cleanup = file_cleanup;
@ -816,7 +750,7 @@ actual_directory (pfile, fname)
x->nlen = dlen;
x->next = CPP_OPTIONS (pfile)->quote_include;
x->alloc = pfile->actual_dirs;
x->sysp = 0;
x->sysp = CPP_BUFFER (pfile)->system_header_p;
x->name_map = NULL;
pfile->actual_dirs = x;
@ -1063,12 +997,11 @@ deps_output (pfile, string, spacer)
if (pfile->deps_column > 0
&& (pfile->deps_column + size) > MAX_OUTPUT_COLUMNS)
{
size += 5;
cr = 1;
cr = 5;
pfile->deps_column = 0;
}
if (pfile->deps_size + size + 8 > pfile->deps_allocated_size)
if (pfile->deps_size + size + cr + 8 > pfile->deps_allocated_size)
{
pfile->deps_allocated_size = (pfile->deps_size + size + 50) * 2;
pfile->deps_buffer = (char *) xrealloc (pfile->deps_buffer,
@ -1105,7 +1038,7 @@ deps_output (pfile, string, spacer)
Guarantees no trailing slashes. All transforms reduce the length
of the string.
*/
static void
void
simplify_pathname (path)
char *path;
{

File diff suppressed because it is too large Load Diff

View File

@ -2936,6 +2936,19 @@ do_unassert (pfile, keyword)
return 1;
}
/* Process STR as if it appeared as the body of an #unassert. */
void
cpp_unassert (pfile, str)
cpp_reader *pfile;
unsigned char *str;
{
if (cpp_push_buffer (pfile, str, strlen (str)) != NULL)
{
do_assert (pfile, NULL);
cpp_pop_buffer (pfile);
}
}
int
cpp_read_check_assertion (pfile)
cpp_reader *pfile;

View File

@ -145,7 +145,6 @@ struct cpp_buffer
char has_escapes;
};
struct cpp_pending; /* Forward declaration - for C++. */
struct file_name_map_list;
/* Maximum nesting of cpp_buffers. We use a static limit, partly for
@ -297,6 +296,24 @@ struct cpp_reader
/* The bottom of the buffer stack. */
#define CPP_NULL_BUFFER(PFILE) NULL
/* The `pending' structure accumulates all the options that are not
actually processed until we hit cpp_start_read. It consists of
several lists, one for each type of option. We keep both head and
tail pointers for quick insertion. */
struct cpp_pending
{
struct pending_option *define_head, *define_tail;
struct pending_option *assert_head, *assert_tail;
struct file_name_list *quote_head, *quote_tail;
struct file_name_list *brack_head, *brack_tail;
struct file_name_list *systm_head, *systm_tail;
struct file_name_list *after_head, *after_tail;
struct pending_option *imacros_head, *imacros_tail;
struct pending_option *include_head, *include_tail;
};
/* Pointed to by cpp_reader.opts. */
struct cpp_options {
char *in_fname;
@ -435,16 +452,14 @@ struct cpp_options {
char done_initializing;
/* Search paths for include files. system_include, after_include are
only used during option parsing. */
/* Search paths for include files. */
struct file_name_list *quote_include; /* First dir to search for "file" */
struct file_name_list *bracket_include;/* First dir to search for <file> */
struct file_name_list *system_include; /* First dir with system headers */
struct file_name_list *after_include; /* Headers to search after system */
/* Directory prefix that should replace `/usr' in the standard
include file directories. */
/* Directory prefix that should replace `/usr/lib/gcc-lib/TARGET/VERSION'
in the standard include file directories. */
char *include_prefix;
int include_prefix_len;
char inhibit_predefs;
char no_standard_includes;
@ -472,7 +487,7 @@ struct cpp_options {
even if they are ifdefed out. */
int dump_includes;
/* Pending -D, -U and -A options, in reverse order. */
/* Pending options - -D, -U, -A, -I, -ixxx. */
struct cpp_pending *pending;
/* File name which deps are being written to.
@ -671,6 +686,7 @@ extern cpp_buffer* cpp_file_buffer PARAMS((cpp_reader *));
extern void cpp_define PARAMS ((cpp_reader *, unsigned char *));
extern void cpp_assert PARAMS ((cpp_reader *, unsigned char *));
extern void cpp_undef PARAMS ((cpp_reader *, unsigned char *));
extern void cpp_unassert PARAMS ((cpp_reader *, unsigned char *));
extern void cpp_error PVPROTO ((cpp_reader *, const char *, ...))
ATTRIBUTE_PRINTF_2;
@ -728,9 +744,7 @@ extern void cpp_print_containing_files PROTO ((cpp_reader *));
extern void cpp_notice PVPROTO ((const char *msgid, ...)) ATTRIBUTE_PRINTF_1;
/* In cppfiles.c */
extern void append_include_chain PROTO ((cpp_reader *,
struct file_name_list **,
const char *, int));
extern void simplify_pathname PROTO ((char *));
extern void merge_include_chains PROTO ((struct cpp_options *));
extern int find_include_file PROTO ((cpp_reader *, char *,
struct file_name_list *,