diff options
author | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-08-02 23:03:31 +0000 |
---|---|---|
committer | neil <neil@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-08-02 23:03:31 +0000 |
commit | 386924596ca616f5ccd2725191d07828c8c6652f (patch) | |
tree | aedb0e3e4381261de71d4d7cee777f2ccde7880d /gcc/line-map.c | |
parent | 5aea2c55a9ec5db0a3159aa12ba14f0795b32bc1 (diff) | |
download | gcc-386924596ca616f5ccd2725191d07828c8c6652f.tar.gz |
* line-map.c: New.
* line-map.h: New.
* Makefile.in (line-map.o): New.
(LIBCPP_OBJS, LIBCPP_DEPS): Update.
* c-lex.c (cb_file_change): Update for new cpp_file_change structure.
* cpperror.c (print_containing_files): Similarly.
(print_location): Update. Don't output a space before _Pragma.
* cppfiles.c (stack_include_file): Set to line 1 immediately.
(stack_include_filee, cpp_make_system_header): Update.
(_cpp_execute_include): Get logical line number right for calling
as-yet-unterminated #include.
* cpphash.h (struct cpp_reader): Add line_maps.
(_cpp_do_file_change): Update.
* cppinit.c (cpp_create_reader): Initialize line maps.
(cpp_destroy): Destroy line maps.
(cpp_start_read): Get logical line number right.
* cpplex.c (parse_string): Only warn once for multi-line strings.
Use boolean variable for null warning.
* cpplib.c (_cpp_handle_directive): End the directive if it isn't
already.
(do_include_common): End the directive early.
(do_line): Don't warn about out-of-range lines in preprocessed
source. Update. Remove unused variables.
(_cpp_do_file_change): Update for new line mapping.
(pragma_cb): New typedef.
(cpp_register_pragma): Stop looking ahead before calling the
handler. Clean up.
(do_pragma_system_header): End directive early.
(cpp_get_line_maps): New.
(cpp_pop_buffer): Fudge logical line. Update.
* cpplib.h: Include line-map.h
(enum cpp_fc_reason): Remove.
(struct cpp_file_change): Update.
(cpp_get_line_maps): New.
* cppmain.c (struct_printer): New member map.
(cb_file_change): Update for new mappings.
* fix-header.c (cb_file_change): Similarly.
testsuite:
* gcc.dg/cpp/19951025-1.c: Update.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@44584 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/line-map.c')
-rw-r--r-- | gcc/line-map.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/gcc/line-map.c b/gcc/line-map.c new file mode 100644 index 00000000000..a67191d3aed --- /dev/null +++ b/gcc/line-map.c @@ -0,0 +1,118 @@ +/* Map logical line numbers to (source file, line number) pairs. + Copyright (C) 2001 + Free Software Foundation, Inc. + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + In other words, you are welcome to use, share and improve this program. + You are forbidden to forbid anyone else to use, share and improve + what you give them. Help stamp out software-hoarding! */ + +#include "config.h" +#include "system.h" +#include "line-map.h" + +/* Initialize a line map set. */ + +void +init_line_maps (set) + struct line_maps *set; +{ + set->maps = 0; + set->allocated = 0; + set->used = 0; +} + +/* Free a line map set. */ + +void free_line_maps (set) + struct line_maps *set; +{ + if (set->maps) + free (set->maps); +} + +/* Add a mapping of logical source line to physical source file and + line number. Ther text pointed to by TO_FILE must have a lifetime + at least as long as the final call to lookup_line (). + + FROM_LINE should be monotonic increasing across calls to this + function. */ + +struct line_map * +add_line_map (set, reason, from_line, to_file, to_line) + struct line_maps *set; + enum lc_reason reason; + unsigned int from_line; + const char *to_file; + unsigned int to_line; +{ + struct line_map *map; + + if (set->used && from_line < set->maps[set->used - 1].from_line) + abort (); + + if (set->used == set->allocated) + { + set->allocated = 2 * set->allocated + 256; + set->maps = (struct line_map *) + xrealloc (set->maps, set->allocated * sizeof (struct line_map)); + } + + map = &set->maps[set->used]; + map->from_line = from_line; + map->to_file = to_file; + map->to_line = to_line; + + if (set->used == 0) + map->included_from = -1; + else 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; + } + + set->used++; + return map; +} + +/* Translate a logical line number into a (source file, line) pair. */ + +struct line_map * +lookup_line (set, line) + struct line_maps *set; + unsigned int line; +{ + unsigned int md, mn = 0, mx = set->used; + + if (mx == 0) + abort (); + + while (mx - mn > 1) + { + md = (mn + mx) / 2; + if (set->maps[md].from_line > line) + mx = md; + else + mn = md; + } + + return &set->maps[mn]; +} |