diff options
author | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-08-06 21:07:41 +0000 |
---|---|---|
committer | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-08-06 21:07:41 +0000 |
commit | bd507c05c4b80c10844cdacac547bca837686b52 (patch) | |
tree | 31a1005e7788f3f63227ac0f3097f1ff9111a46e /gcc | |
parent | c6e2ff2063e0087a87cff9af0a8809c350318572 (diff) | |
download | gcc-bd507c05c4b80c10844cdacac547bca837686b52.tar.gz |
* cpperror.c (print_containing_files): Moved to line-map.c.
(print_location): line-map.c handles re-listing or otherwise.
* cpphash.h (struct lexer_state): Remove next_bol.
(struct cpp_buffer): Remove include_stack_listed.
* cpplib.c (do_line, cpp_push_buffer, _cpp_pop_buffer):
Remove faked buffer handling.
(_cpp_do_file_change): Tweak.
* cpplib.h (enum cpp_buffer_type): Remove BUF_FAKE.
* cppmain.c (struct printer): Remove filename.
(print_line, cb_file_change): Update accordingly.
* line-map.c: Include intl.h.
(init_line_maps): Initialize last_listed.
(free_line_maps): Sanity check, warn if ENABLED_CHECKING.
(add_line_map): Sanity check inputs, warn if ENABLED_CHECKING.
(print_containing_files): New.
* line-map.h (struct line_maps): New member last_listed.
(print_containing_files, INCLUDED_FROM): New.
* Makefile.in: Update.
* po/POTFILES.in: Add line-map.c.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@44670 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 22 | ||||
-rw-r--r-- | gcc/Makefile.in | 2 | ||||
-rw-r--r-- | gcc/cpperror.c | 52 | ||||
-rw-r--r-- | gcc/cpphash.h | 7 | ||||
-rw-r--r-- | gcc/cpplib.c | 155 | ||||
-rw-r--r-- | gcc/cpplib.h | 7 | ||||
-rw-r--r-- | gcc/cppmain.c | 7 | ||||
-rw-r--r-- | gcc/line-map.c | 82 | ||||
-rw-r--r-- | gcc/line-map.h | 14 | ||||
-rw-r--r-- | gcc/po/POTFILES.in | 1 |
10 files changed, 161 insertions, 188 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 485d769274c..b3cbf8bf87f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,25 @@ +2001-08-06 Neil Booth <neil@daikokuya.demon.co.uk> + + * cpperror.c (print_containing_files): Moved to line-map.c. + (print_location): line-map.c handles re-listing or otherwise. + * cpphash.h (struct lexer_state): Remove next_bol. + (struct cpp_buffer): Remove include_stack_listed. + * cpplib.c (do_line, cpp_push_buffer, _cpp_pop_buffer): + Remove faked buffer handling. + (_cpp_do_file_change): Tweak. + * cpplib.h (enum cpp_buffer_type): Remove BUF_FAKE. + * cppmain.c (struct printer): Remove filename. + (print_line, cb_file_change): Update accordingly. + * line-map.c: Include intl.h. + (init_line_maps): Initialize last_listed. + (free_line_maps): Sanity check, warn if ENABLED_CHECKING. + (add_line_map): Sanity check inputs, warn if ENABLED_CHECKING. + (print_containing_files): New. + * line-map.h (struct line_maps): New member last_listed. + (print_containing_files, INCLUDED_FROM): New. + * Makefile.in: Update. + * po/POTFILES.in: Add line-map.c. + 2001-08-06 Richard Henderson <rth@redhat.com> * except.c (convert_from_eh_region_ranges_1): Never mark diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 6db8ae1ac97..eca0b961a2f 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1325,7 +1325,7 @@ stringpool.o: stringpool.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(OBSTACK_H) \ hashtable.o: hashtable.c hashtable.h $(CONFIG_H) $(SYSTEM_H) $(OBSTACK_H) -line-map.o: line-map.c line-map.h $(CONFIG_H) $(SYSTEM_H) +line-map.o: line-map.c line-map.h intl.h $(CONFIG_H) $(SYSTEM_H) ggc-none.o: ggc-none.c $(GCONFIG_H) $(SYSTEM_H) $(GGC_H) $(CC) -c $(ALL_CFLAGS) -DGENERATOR_FILE $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION) diff --git a/gcc/cpperror.c b/gcc/cpperror.c index 4ed4de6273a..167ea9d46a5 100644 --- a/gcc/cpperror.c +++ b/gcc/cpperror.c @@ -29,8 +29,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "cpphash.h" #include "intl.h" -static void print_containing_files PARAMS ((struct line_map *, - struct line_map *)); static void print_location PARAMS ((cpp_reader *, const char *, const cpp_lexer_pos *)); @@ -40,49 +38,6 @@ static void print_location PARAMS ((cpp_reader *, #define v_message(msgid, ap) \ do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0) -/* Print the file names and line numbers of the #include - commands which led to the current file. */ -static void -print_containing_files (map_array, map) - struct line_map *map_array; - struct line_map *map; -{ - int first = 1; - - for (;;) - { - if (MAIN_FILE_P (map)) - break; - map = &map_array[map->included_from]; - - if (first) - { - first = 0; - /* The current line in each outer source file is now the - same as the line of the #include. */ - fprintf (stderr, _("In file included from %s:%u"), - map->to_file, LAST_SOURCE_LINE (map)); - } - else - /* Translators note: this message is used in conjunction - with "In file included from %s:%ld" and some other - tricks. We want something like this: - - | In file included from sys/select.h:123, - | from sys/types.h:234, - | from userfile.c:31: - | bits/select.h:45: <error message here> - - with all the "from"s lined up. - The trailing comma is at the beginning of this message, - and the trailing colon is not translated. */ - fprintf (stderr, _(",\n from %s:%u"), - map->to_file, LAST_SOURCE_LINE (map)); - } - - fputs (":\n", stderr); -} - static void print_location (pfile, filename, pos) cpp_reader *pfile; @@ -122,12 +77,7 @@ print_location (pfile, filename, pos) if (col == 0) col = 1; - /* Don't repeat the include stack unnecessarily. */ - if (buffer->prev && ! buffer->include_stack_listed) - { - buffer->include_stack_listed = 1; - print_containing_files (pfile->line_maps.maps, map); - } + print_containing_files (&pfile->line_maps, map); } if (filename == 0) diff --git a/gcc/cpphash.h b/gcc/cpphash.h index 1ba4282561b..5409e070569 100644 --- a/gcc/cpphash.h +++ b/gcc/cpphash.h @@ -131,9 +131,6 @@ struct lexer_state all directives apart from #define. */ unsigned char save_comments; - /* If nonzero the next token is at the beginning of the line. */ - unsigned char next_bol; - /* Nonzero if we're mid-comment. */ unsigned char lexing_comment; @@ -219,10 +216,6 @@ struct cpp_buffer /* 1 = system header file, 2 = C system header file used for C++. */ unsigned char sysp; - /* Nonzero means we have printed (while error reporting) a list of - containing files that matches the current status. */ - unsigned char include_stack_listed; - /* Nonzero means that the directory to start searching for "" include files has been calculated and stored in "dir" below. */ unsigned char search_cached; diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 0792f2b45b9..4710beb6ced 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -736,12 +736,10 @@ do_line (pfile) cpp_get_token (pfile, &token); if (token.type == CPP_STRING) { - const char *fname = (const char *) token.val.str.text; + buffer->nominal_fname = (const char *) token.val.str.text; /* Only accept flags for the # 55 form. */ - if (! pfile->state.line_extension) - check_eol (pfile); - else + if (pfile->state.line_extension) { int flag = 0, sysp = 0; @@ -749,6 +747,8 @@ do_line (pfile) if (flag == 1) { reason = LC_ENTER; + /* Fake an include for cpp_included (). */ + _cpp_fake_include (pfile, buffer->nominal_fname); flag = read_flag (pfile, flag); } else if (flag == 2) @@ -761,43 +761,11 @@ do_line (pfile) sysp = 1; flag = read_flag (pfile, flag); if (flag == 4) - sysp = 2, read_flag (pfile, flag); - } - - if (reason == LC_ENTER) - { - /* Fake a buffer stack for diagnostics. */ - cpp_push_buffer (pfile, 0, 0, BUF_FAKE, fname, 0); - /* Fake an include for cpp_included. */ - _cpp_fake_include (pfile, fname); - buffer = pfile->buffer; - } - else if (reason == LC_LEAVE) - { - if (buffer->type != BUF_FAKE) - { - cpp_warning (pfile, "file \"%s\" left but not entered", - buffer->nominal_fname); - reason = LC_RENAME; - } - else - { - _cpp_pop_buffer (pfile); - pfile->lexer_pos.output_line++; - buffer = pfile->buffer; -#ifdef ENABLE_CHECKING - if (strcmp (buffer->nominal_fname, fname)) - cpp_warning (pfile, "expected to return to file \"%s\"", - buffer->nominal_fname); - if (buffer->sysp != sysp) - cpp_warning (pfile, "header flags for \"%s\" have changed", - buffer->nominal_fname); -#endif - } + sysp = 2; } buffer->sysp = sysp; } - buffer->nominal_fname = fname; + check_eol (pfile); } else if (token.type != CPP_EOF) { @@ -818,9 +786,8 @@ _cpp_do_file_change (pfile, reason, file_line) enum lc_reason reason; unsigned int file_line; { - cpp_buffer *buffer; - - buffer = pfile->buffer; + cpp_buffer *buffer = pfile->buffer; + pfile->map = add_line_map (&pfile->line_maps, reason, pfile->line, buffer->nominal_fname, file_line); @@ -1785,36 +1752,27 @@ cpp_push_buffer (pfile, buffer, len, type, filename, return_at_eof) { cpp_buffer *new = xobnew (&pfile->buffer_ob, cpp_buffer); - if (type == BUF_FAKE) - { - /* A copy of the current buffer, just with a new name and type. */ - memcpy (new, pfile->buffer, sizeof (cpp_buffer)); - new->type = BUF_FAKE; - } - else - { - if (type == BUF_BUILTIN) - filename = _("<builtin>"); - else if (type == BUF_CL_OPTION) - filename = _("<command line>"); - else if (type == BUF_PRAGMA) - filename = "<_Pragma>"; - - /* Clears, amongst other things, if_stack and mi_cmacro. */ - memset (new, 0, sizeof (cpp_buffer)); - - new->line_base = new->buf = new->cur = buffer; - new->rlimit = buffer + len; - new->sysp = 0; - - /* No read ahead or extra char initially. */ - new->read_ahead = EOF; - new->extra_char = EOF; - - /* Preprocessed files, builtins, _Pragma and command line - options don't do trigraph and escaped newline processing. */ - new->from_stage3 = type != BUF_FILE || CPP_OPTION (pfile, preprocessed); - } + if (type == BUF_BUILTIN) + filename = _("<builtin>"); + else if (type == BUF_CL_OPTION) + filename = _("<command line>"); + else if (type == BUF_PRAGMA) + filename = "<_Pragma>"; + + /* Clears, amongst other things, if_stack and mi_cmacro. */ + memset (new, 0, sizeof (cpp_buffer)); + + new->line_base = new->buf = new->cur = buffer; + new->rlimit = buffer + len; + new->sysp = 0; + + /* No read ahead or extra char initially. */ + new->read_ahead = EOF; + new->extra_char = EOF; + + /* Preprocessed files, builtins, _Pragma and command line + options don't do trigraph and escaped newline processing. */ + new->from_stage3 = type != BUF_FILE || CPP_OPTION (pfile, preprocessed); if (*filename == '\0') new->nominal_fname = _("<stdin>"); @@ -1823,10 +1781,8 @@ cpp_push_buffer (pfile, buffer, len, type, filename, return_at_eof) new->type = type; new->prev = pfile->buffer; new->pfile = pfile; - new->include_stack_listed = 0; new->return_at_eof = return_at_eof; - pfile->state.next_bol = 1; pfile->buffer_stack_depth++; pfile->buffer = new; @@ -1840,49 +1796,26 @@ void _cpp_pop_buffer (pfile) cpp_reader *pfile; { - cpp_buffer *buffer; + cpp_buffer *buffer = pfile->buffer; struct if_stack *ifs; - for (;;) - { - buffer = pfile->buffer; - /* Walk back up the conditional stack till we reach its level at - entry to this file, issuing error messages. */ - for (ifs = buffer->if_stack; ifs; ifs = ifs->next) - cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col, - "unterminated #%s", dtable[ifs->type].name); - - if (buffer->type == BUF_FAKE) - { - buffer->prev->cur = buffer->cur; - buffer->prev->line_base = buffer->line_base; - buffer->prev->read_ahead = buffer->read_ahead; - } - else if (buffer->type == BUF_FILE) - _cpp_pop_file_buffer (pfile, buffer); - - pfile->buffer = buffer->prev; - pfile->buffer_stack_depth--; - - /* Callbacks only generated for faked or real files. */ - if (buffer->type != BUF_FILE && buffer->type != BUF_FAKE) - break; - - /* No callback for EOF of last file. */ - if (!pfile->buffer) - break; + /* Walk back up the conditional stack till we reach its level at + entry to this file, issuing error messages. */ + for (ifs = buffer->if_stack; ifs; ifs = ifs->next) + cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col, + "unterminated #%s", dtable[ifs->type].name); - /* do_line does its own call backs. */ - pfile->buffer->include_stack_listed = 0; - if (pfile->directive == &dtable[T_LINE]) - break; + /* Update the reader's buffer before _cpp_do_file_change. */ + pfile->buffer = buffer->prev; + pfile->buffer_stack_depth--; - _cpp_do_file_change (pfile, LC_LEAVE, pfile->buffer->return_to_line); - if (pfile->buffer->type == BUF_FILE) - break; + if (buffer->type == BUF_FILE) + { + /* Callbacks are not generated for popping the main file. */ + if (buffer->prev) + _cpp_do_file_change (pfile, LC_LEAVE, buffer->prev->return_to_line); - cpp_warning (pfile, "file \"%s\" entered but not left", - buffer->nominal_fname); + _cpp_pop_file_buffer (pfile, buffer); } obstack_free (&pfile->buffer_ob, buffer); diff --git a/gcc/cpplib.h b/gcc/cpplib.h index 937e6047693..29f20d7cb65 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -416,10 +416,9 @@ struct cpp_callbacks /* Name under which this program was invoked. */ extern const char *progname; -/* Where does this buffer come from? A faked include, a source file, - a builtin macro, a command-line option, or a _Pragma operator. */ -enum cpp_buffer_type {BUF_FAKE, BUF_FILE, BUF_BUILTIN, - BUF_CL_OPTION, BUF_PRAGMA}; +/* Where does this buffer come from? A source file, a builtin macro, + a command-line option, or a _Pragma operator. */ +enum cpp_buffer_type {BUF_FILE, BUF_BUILTIN, BUF_CL_OPTION, BUF_PRAGMA}; /* The structure of a node in the hash table. The hash table has entries for all identifiers: either macros defined by #define diff --git a/gcc/cppmain.c b/gcc/cppmain.c index 86d245ab9f1..978c6447b57 100644 --- a/gcc/cppmain.c +++ b/gcc/cppmain.c @@ -31,7 +31,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct printer { FILE *outf; /* Stream to write to. */ - const char *filename; /* Name of current file. */ const char *syshdr_flags; /* System header flags, if any. */ unsigned int line; /* Line currently being written. */ unsigned char printed; /* Nonzero if something output at line. */ @@ -81,8 +80,7 @@ main (argc, argv) do_preprocessing (argc, argv); - /* Call to cpp_destroy () omitted for performance reasons. */ - if (cpp_errors (pfile)) + if (cpp_destroy (pfile)) return FATAL_EXIT_CODE; return SUCCESS_EXIT_CODE; @@ -328,7 +326,7 @@ print_line (line, special_flags) if (! options->no_line_commands) fprintf (print.outf, "# %u \"%s\"%s%s\n", SOURCE_LINE (print.map, print.line), - print.filename, special_flags, print.syshdr_flags); + print.map->to_file, special_flags, print.syshdr_flags); } /* Callbacks. */ @@ -400,7 +398,6 @@ cb_file_change (pfile, fc) maybe_print_line (fc->line - 1); print.map = fc->map; - print.filename = fc->map->to_file; if (fc->externc) print.syshdr_flags = " 3 4"; else if (fc->sysp) diff --git a/gcc/line-map.c b/gcc/line-map.c index 27bcf2f94cd..1cd1bfdfc0f 100644 --- a/gcc/line-map.c +++ b/gcc/line-map.c @@ -23,6 +23,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "config.h" #include "system.h" #include "line-map.h" +#include "intl.h" /* Initialize a line map set. */ @@ -33,15 +34,27 @@ init_line_maps (set) set->maps = 0; set->allocated = 0; set->used = 0; + set->last_listed = -1; } /* Free a line map set. */ -void free_line_maps (set) +void +free_line_maps (set) struct line_maps *set; { if (set->maps) - free (set->maps); + { +#ifdef ENABLE_CHECKING + struct line_map *map; + + for (map = CURRENT_LINE_MAP (set); ! MAIN_FILE_P (map); + map = INCLUDED_FROM (set, map)) + fprintf (stderr, "line-map.c: file \"%s\" entered but not left\n", + map->to_file); +#endif + free (set->maps); + } } /* Add a mapping of logical source line to physical source file and @@ -76,18 +89,29 @@ add_line_map (set, reason, from_line, to_file, to_line) map->to_file = to_file; map->to_line = to_line; + /* If we don't keep our line maps consistent, we can easily + segfault. Don't rely on the client to do it for us. */ if (set->used == 0) - map->included_from = -1; - else if (reason == LC_ENTER) + reason = LC_ENTER; + else if (reason == LC_LEAVE) + { + if (MAIN_FILE_P (map - 1) + || strcmp (INCLUDED_FROM (set, map - 1)->to_file, to_file)) + { +#ifdef ENABLE_CHECKING + fprintf (stderr, "line-map.c: file \"%s\" left but not entered\n", + to_file); +#endif + reason = LC_RENAME; + } + } + + if (reason == LC_ENTER) map->included_from = set->used - 1; else if (reason == LC_RENAME) map->included_from = map[-1].included_from; else if (reason == LC_LEAVE) - { - if (map[-1].included_from < 0) - abort (); - map->included_from = set->maps[map[-1].included_from].included_from; - } + map->included_from = INCLUDED_FROM (set, map - 1)->included_from; set->used++; return map; @@ -119,3 +143,43 @@ lookup_line (set, line) return &set->maps[mn]; } + +/* Print the file names and line numbers of the #include commands + which led to the map MAP, if any, to stderr. Nothing is output if + the most recently listed stack is the same as the current one. */ + +void +print_containing_files (set, map) + struct line_maps *set; + struct line_map *map; +{ + if (MAIN_FILE_P (map) || set->last_listed == map->included_from) + return; + + set->last_listed = map->included_from; + map = INCLUDED_FROM (set, map); + + fprintf (stderr, _("In file included from %s:%u"), + map->to_file, LAST_SOURCE_LINE (map)); + + while (! MAIN_FILE_P (map)) + { + map = INCLUDED_FROM (set, map); + /* Translators note: this message is used in conjunction + with "In file included from %s:%ld" and some other + tricks. We want something like this: + + | In file included from sys/select.h:123, + | from sys/types.h:234, + | from userfile.c:31: + | bits/select.h:45: <error message here> + + with all the "from"s lined up. + The trailing comma is at the beginning of this message, + and the trailing colon is not translated. */ + fprintf (stderr, _(",\n from %s:%u"), + map->to_file, LAST_SOURCE_LINE (map)); + } + + fputs (":\n", stderr); +} diff --git a/gcc/line-map.h b/gcc/line-map.h index bbc6caacd5a..d5705c75614 100644 --- a/gcc/line-map.h +++ b/gcc/line-map.h @@ -42,6 +42,11 @@ struct line_maps struct line_map *maps; unsigned int allocated; unsigned int used; + + /* The most recently listed include stack, if any, starts with + LAST_LISTED as the topmost including file. -1 indicates nothing + has been listed yet. */ + int last_listed; }; /* Reason for adding a line change with add_line_map (). LC_ENTER is @@ -74,6 +79,12 @@ extern struct line_map *add_line_map extern struct line_map *lookup_line PARAMS ((struct line_maps *, unsigned int)); +/* Print the file names and line numbers of the #include commands + which led to the map MAP, if any, to stderr. Nothing is output if + the most recently listed stack is the same as the current one. */ +extern void print_containing_files + PARAMS ((struct line_maps *, struct line_map *)); + /* Converts a map and logical line to source line. */ #define SOURCE_LINE(MAP, LINE) ((LINE) + (MAP)->to_line - (MAP)->from_line) @@ -81,6 +92,9 @@ extern struct line_map *lookup_line of the #include, or other directive, that caused a map change. */ #define LAST_SOURCE_LINE(MAP) SOURCE_LINE ((MAP), (MAP)[1].from_line - 1) +/* Returns the map a given map was included from. */ +#define INCLUDED_FROM(SET, MAP) (&(SET)->maps[(MAP)->included_from]) + /* Non-zero if the map is at the bottom of the include stack. */ #define MAIN_FILE_P(MAP) ((MAP)->included_from < 0) diff --git a/gcc/po/POTFILES.in b/gcc/po/POTFILES.in index f4acdba0a65..67a53801a56 100644 --- a/gcc/po/POTFILES.in +++ b/gcc/po/POTFILES.in @@ -941,6 +941,7 @@ lcm.c #libgcc2.h is part of the GCC library #limitx.h is part of the GCC library #limity.h is part of the GCC library +line-map.c lists.c local-alloc.c #longlong.h is part of the GCC library |