summaryrefslogtreecommitdiff
path: root/gcc/cppfiles.c
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-04-14 23:29:45 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-04-14 23:29:45 +0000
commite2f9a79f86f078c40323984d2ee549e1ba2b19d4 (patch)
treec91bee0467728e26a3ab2b06fce2d27db8e99983 /gcc/cppfiles.c
parent96e3d3b7074bc4b9e41ff776c9e2dbb26f348076 (diff)
downloadgcc-e2f9a79f86f078c40323984d2ee549e1ba2b19d4.tar.gz
* cpplex.c (cpp_output_tokens, cpp_scan_buffer_nooutput): New public
interfaces. (safe_fwrite, output_line_command): New static functions. (cpp_expand_to_buffer): Now private to cpplib. (cpp_scan_buffer): Take a printer. * cpphash.h: Update prototypes. * cpplib.h: Update prototypes. (cpp_printer): New. (cpp_buffer): Remove last_nominal_fname. (cpp_reader): Remove lineno. * cppmain.c: Use a cpp_printer. * fix-header.c: No need to inhibit line commands. Call cpp_start_read with no printer. * cpperror.c (cpp_notice_from_errno): Provide default name. * cppfiles.c (make_IHASH, _cpp_fake_ihash): New functions. (find_include_file, cpp_read_file): Use make_IHASH. (file_cleanup): Set control_macro and clear input_stack_listing_current here. (_cpp_execute_include): Don't output entering-file marker. * cpphash.c (special_symbol): Look for the line number in the buffer, not the reader. (_cpp_macroexpand): No need to disable line commands. (_cpp_dump_definition): No need to generate line commands. (dump_hash_helper): Remove excess newline from output. * cppinit.c (dump_special_to_buffer): No need to generate line commands. (cpp_printer_init): New. (cpp_start_read): Take a printer, and start it up if it's not NULL. No need to generate line commands. (cpp_finish): Expect no buffers stacked at all. Take a printer argument, and flush the output buffer if it's not NULL. * cpplex.c (_cpp_lex_token): Return EOF if there's no buffer. Don't put two hashes at the beginning of an assertion. (cpp_get_token): Don't increment pfile->lineno or emit line commands here. Return EOF if there's no buffer when we get EOF. * cpplib.c (do_define, skip_if_group): No need to disable line commands. (_cpp_output_line_command): Delete function. (do_line): Don't emit line commands here, but set things up so they will be emitted if necessary. Use _cpp_fake_ihash to make unique nominal_fnames if necessary. (do_elif, do_else, _cpp_handle_eof): Call cpp_error_with_line with 0 for column, not -1. (_cpp_handle_eof): Don't set the control macro here. Don't clear input_stack_listing_current here. Don't emit line commands. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@33159 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cppfiles.c')
-rw-r--r--gcc/cppfiles.c118
1 files changed, 74 insertions, 44 deletions
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index 2be195aa90c..59ee7c76f03 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -34,6 +34,9 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static IHASH *redundant_include_p PARAMS ((cpp_reader *, IHASH *,
struct file_name_list *));
+static IHASH *make_IHASH PARAMS ((const char *, const char *,
+ struct file_name_list *,
+ unsigned int, IHASH **));
static struct file_name_map *read_name_map
PARAMS ((cpp_reader *, const char *));
static char *read_filename_string PARAMS ((int, FILE *));
@@ -154,6 +157,46 @@ cpp_included (pfile, fname)
return (ptr != NULL);
}
+/* Create an IHASH entry and insert it in SLOT. */
+static IHASH *
+make_IHASH (name, fname, path, hash, slot)
+ const char *name, *fname;
+ struct file_name_list *path;
+ unsigned int hash;
+ IHASH **slot;
+{
+ IHASH *ih;
+ if (path == ABSOLUTE_PATH)
+ {
+ ih = (IHASH *) xmalloc (sizeof (IHASH) + strlen (name));
+ ih->nshort = ih->name;
+ }
+ else
+ {
+ char *s;
+
+ if ((s = strstr (name, fname)) != NULL)
+ {
+ ih = (IHASH *) xmalloc (sizeof (IHASH) + strlen (name));
+ ih->nshort = ih->name + (s - name);
+ }
+ else
+ {
+ ih = (IHASH *) xmalloc (sizeof (IHASH) + strlen (name)
+ + strlen (fname) + 1);
+ ih->nshort = ih->name + strlen (name) + 1;
+ strcpy ((char *)ih->nshort, fname);
+ }
+ }
+ strcpy ((char *)ih->name, name);
+ ih->foundhere = path;
+ ih->control_macro = NULL;
+ ih->hash = hash;
+ ih->next_this_file = *slot;
+ *slot = ih;
+ return ih;
+}
+
static int
file_cleanup (pbuf, pfile)
cpp_buffer *pbuf;
@@ -163,6 +206,12 @@ file_cleanup (pbuf, pfile)
free ((PTR) pbuf->buf);
if (pfile->system_include_depth)
pfile->system_include_depth--;
+ if (pfile->potential_control_macro)
+ {
+ pbuf->ihash->control_macro = pfile->potential_control_macro;
+ pfile->potential_control_macro = 0;
+ }
+ pfile->input_stack_listing_current = 0;
return 0;
}
@@ -265,41 +314,34 @@ find_include_file (pfile, fname, search_start, ihash, before)
if (f == -1)
return -1;
- if (path == ABSOLUTE_PATH)
- {
- ih = (IHASH *) xmalloc (sizeof (IHASH) + strlen (name));
- ih->nshort = ih->name;
- }
- else
- {
- char *s;
-
- if ((s = strstr (name, fname)) != NULL)
- {
- ih = (IHASH *) xmalloc (sizeof (IHASH) + strlen (name));
- ih->nshort = ih->name + (s - name);
- }
- else
- {
- ih = (IHASH *) xmalloc (sizeof (IHASH) + strlen (name)
- + strlen (fname) + 1);
- ih->nshort = ih->name + strlen (name) + 1;
- strcpy ((char *)ih->nshort, fname);
- }
- }
- strcpy ((char *)ih->name, name);
- ih->foundhere = path;
- ih->control_macro = NULL;
- ih->hash = dummy.hash;
-
- ih->next_this_file = *slot;
- *slot = ih;
-
+ ih = make_IHASH (name, fname, path, dummy.hash, slot);
*before = 0;
*ihash = ih;
return f;
}
+/* Create a dummy IHASH entry for FNAME, and return its name pointer.
+ This is used by #line. */
+const char *
+_cpp_fake_ihash (pfile, fname)
+ cpp_reader *pfile;
+ const char *fname;
+{
+ IHASH *ih, **slot;
+ IHASH dummy;
+
+ dummy.nshort = fname;
+ dummy.hash = _cpp_calc_hash (fname, strlen (fname));
+ slot = (IHASH **) htab_find_slot_with_hash (pfile->all_include_files,
+ (const void *)&dummy,
+ dummy.hash, 1);
+ if (*slot)
+ return (*slot)->name;
+ ih = make_IHASH (fname, 0, ABSOLUTE_PATH, dummy.hash, slot);
+ return ih->name;
+}
+
+
/* 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
@@ -594,14 +636,12 @@ _cpp_execute_include (pfile, fname, len, no_reinclude, search_start)
fprintf (stderr, " %s\n", ihash->name);
}
- /* Actually process the file */
-
+ /* 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. */
}
@@ -637,17 +677,7 @@ cpp_read_file (pfile, fname)
return 1; /* Already included. */
}
else
- {
- ih = (IHASH *) xmalloc (sizeof (IHASH) + strlen (fname));
- ih->control_macro = 0;
- ih->foundhere = ABSOLUTE_PATH; /* well sort of ... */
- ih->hash = dummy.hash;
- strcpy ((char *)ih->name, fname);
- ih->nshort = ih->name;
-
- ih->next_this_file = *slot;
- *slot = ih;
- }
+ ih = make_IHASH (fname, 0, ABSOLUTE_PATH, dummy.hash, slot);
if (*fname == '\0')
f = 0;