summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-03-02 07:35:12 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-03-02 07:35:12 +0000
commit3ec84a0b0aef46187209d9d69ecb389c487cc2a3 (patch)
treeae411edfe1a33d4c87567b4c5791c4fa1ec59310 /gcc
parent4baba9f150e4013de41d1f05f567ff14d9af3db4 (diff)
downloadgcc-3ec84a0b0aef46187209d9d69ecb389c487cc2a3.tar.gz
* cppfiles.c (struct include_file): Update.
(stack_include_file): Use search_from. (cpp_included, find_include_file): Update. (cpp_execute_include): Update. ptr->name may not be null terminated. Use the new search_from member variable of cpp_buffer. (_cpp_compare_file_date): Similarly. (search_from): New function, similiar to actual_directory. (actual_directory): Delete. (remap_filename): Update. loc->name may not be null terminated. (struct file_name_list): Rename search_path. Update. * cpphash.h (struct cpp_buffer): Delete actual_dir. New members search_from and dir. (struct cpp_reader): Remove actual_dirs. * cppinit.c (struct cpp_pending): Update for renamed objects. (append_include_chain, remove_dup_dir, remove_dup_dirs, merge_include_chains, cpp_destroy, cpp_start_read): Similarly. * cpplib.h (struct cpp_options): Similarly. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@40178 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog21
-rw-r--r--gcc/cppfiles.c168
-rw-r--r--gcc/cpphash.h40
-rw-r--r--gcc/cppinit.c45
-rw-r--r--gcc/cpplib.h4
5 files changed, 141 insertions, 137 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7a7d1a93281..73859316b99 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,24 @@
+2001-03-02 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * cppfiles.c (struct include_file): Update.
+ (stack_include_file): Use search_from.
+ (cpp_included, find_include_file): Update.
+ (cpp_execute_include): Update. ptr->name may not be
+ null terminated. Use the new search_from member variable
+ of cpp_buffer.
+ (_cpp_compare_file_date): Similarly.
+ (search_from): New function, similiar to actual_directory.
+ (actual_directory): Delete.
+ (remap_filename): Update. loc->name may not be null terminated.
+ (struct file_name_list): Rename search_path. Update.
+ * cpphash.h (struct cpp_buffer): Delete actual_dir. New members
+ search_from and dir.
+ (struct cpp_reader): Remove actual_dirs.
+ * cppinit.c (struct cpp_pending): Update for renamed objects.
+ (append_include_chain, remove_dup_dir, remove_dup_dirs,
+ merge_include_chains, cpp_destroy, cpp_start_read): Similarly.
+ * cpplib.h (struct cpp_options): Similarly.
+
2001-03-01 Zack Weinberg <zackw@stanford.edu>
* config/xm-lynx.h, config/xm-std32.h, config/a29k/xm-a29k.h,
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index 25bc37df1a8..72af4333531 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -68,7 +68,7 @@ struct include_file
{
const char *name; /* actual path name of file */
const cpp_hashnode *cmacro; /* macro, if any, preventing reinclusion. */
- const struct file_name_list *foundhere;
+ const struct search_path *foundhere;
/* location in search path where file was
found, for #include_next and sysp. */
const unsigned char *buffer; /* pointer to cached file contents */
@@ -94,12 +94,12 @@ static struct file_name_map *read_name_map
PARAMS ((cpp_reader *, const char *));
static char *read_filename_string PARAMS ((int, FILE *));
static char *remap_filename PARAMS ((cpp_reader *, char *,
- struct file_name_list *));
-static struct file_name_list *actual_directory
- PARAMS ((cpp_reader *, const char *));
+ struct search_path *));
+static struct search_path *search_from PARAMS ((cpp_reader *,
+ struct include_file *));
static struct include_file *find_include_file
PARAMS ((cpp_reader *, const char *,
- struct file_name_list *));
+ struct search_path *));
static struct include_file *open_file PARAMS ((cpp_reader *, const char *));
static void read_include_file PARAMS ((cpp_reader *, struct include_file *));
static void stack_include_file PARAMS ((cpp_reader *, struct include_file *));
@@ -296,11 +296,7 @@ stack_include_file (pfile, inc)
fp->inc = inc;
fp->inc->refcnt++;
fp->sysp = sysp;
-
- /* The ->actual_dir field is only used when ignore_srcdir is not in effect;
- see do_include */
- if (!CPP_OPTION (pfile, ignore_srcdir))
- fp->actual_dir = actual_directory (pfile, inc->name);
+ fp->search_from = search_from (pfile, inc);
/* Initialise controlling macro state. */
pfile->mi_state = MI_OUTSIDE;
@@ -461,7 +457,7 @@ cpp_included (pfile, fname)
cpp_reader *pfile;
const char *fname;
{
- struct file_name_list *path;
+ struct search_path *path;
char *name;
splay_tree_node nd;
@@ -477,9 +473,9 @@ cpp_included (pfile, fname)
+ 2 + INCLUDE_LEN_FUDGE);
for (path = CPP_OPTION (pfile, quote_include); path; path = path->next)
{
- memcpy (name, path->name, path->nlen);
- name[path->nlen] = '/';
- strcpy (&name[path->nlen+1], fname);
+ memcpy (name, path->name, path->len);
+ name[path->len] = '/';
+ strcpy (&name[path->len + 1], fname);
_cpp_simplify_pathname (name);
if (CPP_OPTION (pfile, remap))
name = remap_filename (pfile, name, path);
@@ -499,9 +495,9 @@ static struct include_file *
find_include_file (pfile, fname, search_start)
cpp_reader *pfile;
const char *fname;
- struct file_name_list *search_start;
+ struct search_path *search_start;
{
- struct file_name_list *path;
+ struct search_path *path;
char *name;
struct include_file *file;
@@ -513,9 +509,9 @@ find_include_file (pfile, fname, search_start)
+ 2 + INCLUDE_LEN_FUDGE);
for (path = search_start; path; path = path->next)
{
- memcpy (name, path->name, path->nlen);
- name[path->nlen] = '/';
- strcpy (&name[path->nlen+1], fname);
+ memcpy (name, path->name, path->len);
+ name[path->len] = '/';
+ strcpy (&name[path->len + 1], fname);
_cpp_simplify_pathname (name);
if (CPP_OPTION (pfile, remap))
name = remap_filename (pfile, name, path);
@@ -527,6 +523,7 @@ find_include_file (pfile, fname, search_start)
return file;
}
}
+
return 0;
}
@@ -587,7 +584,7 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
int no_reinclude;
int include_next;
{
- struct file_name_list *search_start = 0;
+ struct search_path *search_start = 0;
unsigned int len = header->val.str.len;
unsigned int angle_brackets = header->type == CPP_HEADER_NAME;
struct include_file *inc;
@@ -637,10 +634,8 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
{
if (angle_brackets)
search_start = CPP_OPTION (pfile, bracket_include);
- else if (CPP_OPTION (pfile, ignore_srcdir))
- search_start = CPP_OPTION (pfile, quote_include);
else
- search_start = CPP_BUFFER (pfile)->actual_dir;
+ search_start = pfile->buffer->search_from;
if (!search_start)
{
@@ -685,17 +680,18 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
else
{
char *p;
- struct file_name_list *ptr;
+ struct search_path *ptr;
int len;
/* If requested as a system header, assume it belongs in
- the first system header directory. */
+ the first system header directory. */
if (CPP_OPTION (pfile, bracket_include))
ptr = CPP_OPTION (pfile, bracket_include);
else
ptr = CPP_OPTION (pfile, quote_include);
- len = strlen (ptr->name);
+ /* FIXME: ptr can be null, no? */
+ len = ptr->len;
p = (char *) alloca (len + strlen (fname) + 2);
if (len)
{
@@ -728,15 +724,13 @@ _cpp_compare_file_date (pfile, f)
{
unsigned int len = f->val.str.len;
char *fname;
- struct file_name_list *search_start;
+ struct search_path *search_start;
struct include_file *inc;
if (f->type == CPP_HEADER_NAME)
search_start = CPP_OPTION (pfile, bracket_include);
else if (CPP_OPTION (pfile, ignore_srcdir))
- search_start = CPP_OPTION (pfile, quote_include);
- else
- search_start = CPP_BUFFER (pfile)->actual_dir;
+ search_start = pfile->buffer->search_from;
fname = alloca (len + 1);
memcpy (fname, f->val.str.text, len);
@@ -804,6 +798,47 @@ _cpp_pop_file_buffer (pfile, buf)
purge_cache (inc);
}
+/* Returns the first place in the include chain to start searching for
+ "" includes. This involves stripping away the basename of the
+ current file, unless -I- was specified. */
+static struct search_path *
+search_from (pfile, inc)
+ cpp_reader *pfile;
+ struct include_file *inc;
+{
+ cpp_buffer *buffer = pfile->buffer;
+ unsigned int dlen;
+
+ /* Ignore the current file's directory if -I- was given. */
+ if (CPP_OPTION (pfile, ignore_srcdir))
+ return CPP_OPTION (pfile, quote_include);
+
+ dlen = basename (inc->name) - inc->name;
+ if (dlen)
+ {
+ /* We don't guarantee NAME is null-terminated. This saves
+ allocating and freeing memory, and duplicating it when faking
+ buffers in cpp_push_buffer. Drop a trailing '/'. */
+ buffer->dir.name = inc->name;
+ if (dlen > 1)
+ dlen--;
+ }
+ else
+ {
+ buffer->dir.name = ".";
+ dlen = 1;
+ }
+
+ if (dlen > pfile->max_include_len)
+ pfile->max_include_len = dlen;
+
+ buffer->dir.len = dlen;
+ buffer->dir.next = CPP_OPTION (pfile, quote_include);
+ buffer->dir.sysp = buffer->sysp;
+
+ return &buffer->dir;
+}
+
/* The file_name_map structure holds a mapping of file names for a
particular directory. This mapping is read from the file named
FILE_NAME_MAP_FILE in that directory. Such a file can be used to
@@ -950,20 +985,26 @@ static char *
remap_filename (pfile, name, loc)
cpp_reader *pfile;
char *name;
- struct file_name_list *loc;
+ struct search_path *loc;
{
struct file_name_map *map;
const char *from, *p;
- char *dir;
+ char *dir, *dname;
+
+ /* Get a null-terminated path. */
+ dname = alloca (loc->len + 1);
+ memcpy (dname, loc->name, loc->len);
+ dname[loc->len] = '\0';
if (! loc->name_map)
{
- loc->name_map = read_name_map (pfile, loc->name ? loc->name : ".");
+ loc->name_map = read_name_map (pfile, dname);
if (! loc->name_map)
return name;
}
- from = name + strlen (loc->name) + 1;
+ /* FIXME: this doesn't look right - NAME has been simplified. */
+ from = name + loc->len + 1;
for (map = loc->name_map; map; map = map->map_next)
if (!strcmp (map->map_from, from))
@@ -993,65 +1034,6 @@ remap_filename (pfile, name, loc)
return name;
}
-/* Given a path FNAME, extract the directory component and place it
- onto the actual_dirs list. Return a pointer to the allocated
- file_name_list structure. These structures are used to implement
- current-directory "" include searching. */
-
-static struct file_name_list *
-actual_directory (pfile, fname)
- cpp_reader *pfile;
- const char *fname;
-{
- char *last_slash, *dir;
- size_t dlen;
- struct file_name_list *x;
-
- dir = xstrdup (fname);
- last_slash = strrchr (dir, '/');
- if (last_slash)
- {
- if (last_slash == dir)
- {
- dlen = 1;
- last_slash[1] = '\0';
- }
- else
- {
- dlen = last_slash - dir;
- *last_slash = '\0';
- }
- }
- else
- {
- free (dir);
- dir = xstrdup (".");
- dlen = 1;
- }
-
- if (dlen > pfile->max_include_len)
- pfile->max_include_len = dlen;
-
- for (x = pfile->actual_dirs; x; x = x->alloc)
- if (!strcmp (x->name, dir))
- {
- free (dir);
- return x;
- }
-
- /* Not found, make a new one. */
- x = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
- x->name = dir;
- x->nlen = dlen;
- x->next = CPP_OPTION (pfile, quote_include);
- x->alloc = pfile->actual_dirs;
- x->sysp = pfile->buffer->sysp;
- x->name_map = NULL;
-
- pfile->actual_dirs = x;
- return x;
-}
-
/* Simplify a path name in place, deleting redundant components. This
reduces OS overhead and guarantees that equivalent paths compare
the same (modulo symlinks).
diff --git a/gcc/cpphash.h b/gcc/cpphash.h
index 14df2da9b20..5b2c24bd0ae 100644
--- a/gcc/cpphash.h
+++ b/gcc/cpphash.h
@@ -72,23 +72,23 @@ struct cpp_pool
unsigned int locks;
};
-/* List of directories to look for include files in. */
-struct file_name_list
+/* List of directories to look for include files in. */
+struct search_path
{
- struct file_name_list *next;
- struct file_name_list *alloc; /* for the cache of
- current directory entries */
- char *name;
- unsigned int nlen;
+ struct search_path *next;
+
+ /* NOTE: NAME may not be null terminated for the case of the current
+ file's directory! */
+ const char *name;
+ unsigned int len;
/* We use these to tell if the directory mentioned here is a duplicate
- of an earlier directory on the search path. */
+ of an earlier directory on the search path. */
ino_t ino;
dev_t dev;
- /* If the following is nonzero, it is a C-language system include
- directory. */
+ /* Non-zero if it is a system include directory. */
int sysp;
- /* Mapping of file names for this directory.
- Only used on MS-DOS and related platforms. */
+ /* Mapping of file names for this directory. Only used on MS-DOS
+ and related platforms. */
struct file_name_map *name_map;
};
@@ -180,9 +180,6 @@ struct cpp_buffer
/* Filename specified with #line command. */
const char *nominal_fname;
- /* Actual directory of this file, used only for "" includes */
- struct file_name_list *actual_dir;
-
/* Pointer into the include table. Used for include_next and
to record control macros. */
struct include_file *inc;
@@ -227,6 +224,15 @@ struct cpp_buffer
/* Buffer type. */
ENUM_BITFIELD (cpp_buffer_type) type : 8;
+
+ /* The directory of the this buffer's file. Its NAME member is not
+ allocated, so we don't need to worry about freeing it. */
+ struct search_path dir;
+
+ /* The directory to start searching for "" include files. Is either
+ "dir" above, or options.quote_include, depending upon whether -I-
+ was on the command line. */
+ struct search_path *search_from;
};
/* A cpp_reader encapsulates the "state" of a pre-processor run.
@@ -297,10 +303,6 @@ struct cpp_reader
/* Tree of other included files. See cppfiles.c. */
struct splay_tree_s *all_include_files;
- /* Chain of `actual directory' file_name_list entries, for ""
- inclusion. */
- struct file_name_list *actual_dirs;
-
/* Current maximum length of directory names in the search path
for include files. (Altered as we get more of them.) */
unsigned int max_include_len;
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index 2b2e1998420..0406e629040 100644
--- a/gcc/cppinit.c
+++ b/gcc/cppinit.c
@@ -70,10 +70,10 @@ struct cpp_pending
{
struct pending_option *directive_head, *directive_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 search_path *quote_head, *quote_tail;
+ struct search_path *brack_head, *brack_tail;
+ struct search_path *systm_head, *systm_tail;
+ struct search_path *after_head, *after_tail;
struct pending_option *imacros_head, *imacros_tail;
struct pending_option *include_head, *include_tail;
@@ -100,10 +100,10 @@ static void init_library PARAMS ((void));
static void init_builtins PARAMS ((cpp_reader *));
static void append_include_chain PARAMS ((cpp_reader *,
char *, int, int));
-struct file_name_list * remove_dup_dir PARAMS ((cpp_reader *,
- struct file_name_list *));
-struct file_name_list * remove_dup_dirs PARAMS ((cpp_reader *,
- struct file_name_list *));
+struct search_path * remove_dup_dir PARAMS ((cpp_reader *,
+ struct search_path *));
+struct search_path * remove_dup_dirs PARAMS ((cpp_reader *,
+ struct search_path *));
static void merge_include_chains PARAMS ((cpp_reader *));
static void do_includes PARAMS ((cpp_reader *,
struct pending_option *,
@@ -207,7 +207,7 @@ append_include_chain (pfile, dir, path, cxx_aware)
int cxx_aware ATTRIBUTE_UNUSED;
{
struct cpp_pending *pend = CPP_OPTION (pfile, pending);
- struct file_name_list *new;
+ struct search_path *new;
struct stat st;
unsigned int len;
@@ -232,9 +232,9 @@ append_include_chain (pfile, dir, path, cxx_aware)
if (len > pfile->max_include_len)
pfile->max_include_len = len;
- new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
+ new = (struct search_path *) xmalloc (sizeof (struct search_path));
new->name = dir;
- new->nlen = len;
+ new->len = len;
new->ino = st.st_ino;
new->dev = st.st_dev;
if (path == SYSTEM)
@@ -247,7 +247,6 @@ append_include_chain (pfile, dir, path, cxx_aware)
new->sysp = 0;
new->name_map = NULL;
new->next = NULL;
- new->alloc = NULL;
switch (path)
{
@@ -260,18 +259,18 @@ append_include_chain (pfile, dir, path, cxx_aware)
/* Handle a duplicated include path. PREV is the link in the chain
before the duplicate. The duplicate is removed from the chain and
freed. Returns PREV. */
-struct file_name_list *
+struct search_path *
remove_dup_dir (pfile, prev)
cpp_reader *pfile;
- struct file_name_list *prev;
+ struct search_path *prev;
{
- struct file_name_list *cur = prev->next;
+ struct search_path *cur = prev->next;
if (CPP_OPTION (pfile, verbose))
fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name);
prev->next = cur->next;
- free (cur->name);
+ free ((PTR) cur->name);
free (cur);
return prev;
@@ -281,12 +280,12 @@ remove_dup_dir (pfile, prev)
chain, or NULL if the chain is empty. This algorithm is quadratic
in the number of -I switches, which is acceptable since there
aren't usually that many of them. */
-struct file_name_list *
+struct search_path *
remove_dup_dirs (pfile, head)
cpp_reader *pfile;
- struct file_name_list *head;
+ struct search_path *head;
{
- struct file_name_list *prev = NULL, *cur, *other;
+ struct search_path *prev = NULL, *cur, *other;
for (cur = head; cur; cur = cur->next)
{
@@ -315,7 +314,7 @@ static void
merge_include_chains (pfile)
cpp_reader *pfile;
{
- struct file_name_list *quote, *brack, *systm, *qtail;
+ struct search_path *quote, *brack, *systm, *qtail;
struct cpp_pending *pend = CPP_OPTION (pfile, pending);
@@ -559,7 +558,7 @@ cpp_destroy (pfile)
cpp_reader *pfile;
{
int result;
- struct file_name_list *dir, *dirn;
+ struct search_path *dir, *dirn;
cpp_context *context, *contextn;
while (CPP_BUFFER (pfile) != NULL)
@@ -587,7 +586,7 @@ cpp_destroy (pfile)
for (dir = CPP_OPTION (pfile, quote_include); dir; dir = dirn)
{
dirn = dir->next;
- free (dir->name);
+ free ((PTR) dir->name);
free (dir);
}
@@ -910,7 +909,7 @@ cpp_start_read (pfile, fname)
/* With -v, print the list of dirs to search. */
if (CPP_OPTION (pfile, verbose))
{
- struct file_name_list *l;
+ struct search_path *l;
fprintf (stderr, _("#include \"...\" search starts here:\n"));
for (l = CPP_OPTION (pfile, quote_include); l; l = l->next)
{
diff --git a/gcc/cpplib.h b/gcc/cpplib.h
index 099379285a7..50d3bfe5de8 100644
--- a/gcc/cpplib.h
+++ b/gcc/cpplib.h
@@ -240,8 +240,8 @@ struct cpp_options
const char *deps_file;
/* 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 search_path *quote_include; /* "" */
+ struct search_path *bracket_include; /* <> */
/* Map between header names and file names, used only on DOS where
file names are limited in length. */