X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libcpp%2Fline-map.c;h=a82c4286f07ba2d48bde4b2d5a9e7c4008651a24;hb=3e5482040c58423a2a6e5fdb321d630adcea200c;hp=e6dd48df7562f5506280a1861b3d2f01e39d0502;hpb=d856c8a6b9ed6ffbbb012ce9f999e9db3a8ee302;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libcpp/line-map.c b/libcpp/line-map.c index e6dd48df756..a82c4286f07 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -1,10 +1,10 @@ /* Map logical line numbers to (source file, line number) pairs. - Copyright (C) 2001, 2003, 2004 + Copyright (C) 2001, 2003, 2004, 2007, 2008, 2009 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 +Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -13,8 +13,8 @@ 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. +along with this program; see the file COPYING3. If not see +. 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 @@ -38,9 +38,10 @@ linemap_init (struct line_maps *set) set->trace_includes = false; set->depth = 0; set->cache = 0; - set->highest_location = 0; - set->highest_line = 0; + set->highest_location = RESERVED_LOCATION_COUNT - 1; + set->highest_line = RESERVED_LOCATION_COUNT - 1; set->max_column_hint = 0; + set->reallocator = 0; } /* Check for and warn about line_maps entered but not exited. */ @@ -81,12 +82,11 @@ linemap_free (struct line_maps *set) FROM_LINE should be monotonic increasing across calls to this function. A call to this function can relocate the previous set of - A call to this function can relocate the previous set of maps, so any stored line_map pointers should not be used. */ const struct line_map * linemap_add (struct line_maps *set, enum lc_reason reason, - unsigned int sysp, const char *to_file, unsigned int to_line) + unsigned int sysp, const char *to_file, linenum_type to_line) { struct line_map *map; source_location start_location = set->highest_location + 1; @@ -96,15 +96,25 @@ linemap_add (struct line_maps *set, enum lc_reason reason, if (set->used == set->allocated) { + line_map_realloc reallocator + = set->reallocator ? set->reallocator : xrealloc; set->allocated = 2 * set->allocated + 256; - set->maps = xrealloc (set->maps, set->allocated * sizeof (struct line_map)); + set->maps + = (struct line_map *) (*reallocator) (set->maps, + set->allocated + * sizeof (struct line_map)); + memset (&set->maps[set->used], 0, ((set->allocated - set->used) + * sizeof (struct line_map))); } map = &set->maps[set->used]; - if (to_file && *to_file == '\0') + if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM) to_file = ""; + if (reason == LC_RENAME_VERBATIM) + reason = LC_RENAME; + /* 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->depth == 0) @@ -176,13 +186,13 @@ linemap_add (struct line_maps *set, enum lc_reason reason, } source_location -linemap_line_start (struct line_maps *set, unsigned int to_line, +linemap_line_start (struct line_maps *set, linenum_type to_line, unsigned int max_column_hint) { struct line_map *map = &set->maps[set->used - 1]; source_location highest = set->highest_location; source_location r; - unsigned int last_line = SOURCE_LINE (map, set->highest_line); + linenum_type last_line = SOURCE_LINE (map, set->highest_line); int line_delta = to_line - last_line; bool add_map = false; if (line_delta < 0 @@ -199,6 +209,8 @@ linemap_line_start (struct line_maps *set, unsigned int to_line, int column_bits; if (max_column_hint > 100000 || highest > 0xC0000000) { + /* If the column number is ridiculous or we've allocated a huge + number of source_locations, give up on column numbers. */ max_column_hint = 0; if (highest >0xF0000000) return 0; @@ -211,13 +223,15 @@ linemap_line_start (struct line_maps *set, unsigned int to_line, column_bits++; max_column_hint = 1U << column_bits; } + /* Allocate the new line_map. However, if the current map only has a + single line we can sometimes just increase its column_bits instead. */ if (line_delta < 0 || last_line != map->to_line || SOURCE_COLUMN (map, highest) >= (1U << column_bits)) - map = (struct line_map*) linemap_add (set, LC_RENAME, map->sysp, - map->to_file, to_line); + map = (struct line_map *) linemap_add (set, LC_RENAME, map->sysp, + map->to_file, to_line); map->column_bits = column_bits; - r = map->start_location; + r = map->start_location + ((to_line - map->to_line) << column_bits); } else r = highest - SOURCE_COLUMN (map, highest) @@ -292,45 +306,6 @@ linemap_lookup (struct line_maps *set, source_location 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 -linemap_print_containing_files (struct line_maps *set, - const 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: - - 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); -} - /* Print an include trace, for e.g. the -H option of the preprocessor. */ static void