| OLD | NEW |
| 1 /* Map logical line numbers to (source file, line number) pairs. | 1 /* Map logical line numbers to (source file, line number) pairs. |
| 2 Copyright (C) 2001, 2003, 2004, 2007, 2008, 2009 | 2 Copyright (C) 2001, 2003, 2004, 2007, 2008, 2009 |
| 3 Free Software Foundation, Inc. | 3 Free Software Foundation, Inc. |
| 4 | 4 |
| 5 This program is free software; you can redistribute it and/or modify it | 5 This program is free software; you can redistribute it and/or modify it |
| 6 under the terms of the GNU General Public License as published by the | 6 under the terms of the GNU General Public License as published by the |
| 7 Free Software Foundation; either version 3, or (at your option) any | 7 Free Software Foundation; either version 3, or (at your option) any |
| 8 later version. | 8 later version. |
| 9 | 9 |
| 10 This program is distributed in the hope that it will be useful, | 10 This program is distributed in the hope that it will be useful, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 void | 31 void |
| 32 linemap_init (struct line_maps *set) | 32 linemap_init (struct line_maps *set) |
| 33 { | 33 { |
| 34 set->maps = NULL; | 34 set->maps = NULL; |
| 35 set->allocated = 0; | 35 set->allocated = 0; |
| 36 set->used = 0; | 36 set->used = 0; |
| 37 set->last_listed = -1; | 37 set->last_listed = -1; |
| 38 set->trace_includes = false; | 38 set->trace_includes = false; |
| 39 set->depth = 0; | 39 set->depth = 0; |
| 40 set->cache = 0; | 40 set->cache = 0; |
| 41 set->highest_location = 0; | 41 set->highest_location = RESERVED_LOCATION_COUNT - 1; |
| 42 set->highest_line = 0; | 42 set->highest_line = RESERVED_LOCATION_COUNT - 1; |
| 43 set->max_column_hint = 0; | 43 set->max_column_hint = 0; |
| 44 set->reallocator = 0; |
| 44 } | 45 } |
| 45 | 46 |
| 46 /* Check for and warn about line_maps entered but not exited. */ | 47 /* Check for and warn about line_maps entered but not exited. */ |
| 47 | 48 |
| 48 void | 49 void |
| 49 linemap_check_files_exited (struct line_maps *set) | 50 linemap_check_files_exited (struct line_maps *set) |
| 50 { | 51 { |
| 51 struct line_map *map; | 52 struct line_map *map; |
| 52 /* Depending upon whether we are handling preprocessed input or | 53 /* Depending upon whether we are handling preprocessed input or |
| 53 not, this can be a user error or an ICE. */ | 54 not, this can be a user error or an ICE. */ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 set->maps | 102 set->maps |
| 102 = (struct line_map *) (*reallocator) (set->maps, | 103 = (struct line_map *) (*reallocator) (set->maps, |
| 103 set->allocated | 104 set->allocated |
| 104 * sizeof (struct line_map)); | 105 * sizeof (struct line_map)); |
| 105 memset (&set->maps[set->used], 0, ((set->allocated - set->used) | 106 memset (&set->maps[set->used], 0, ((set->allocated - set->used) |
| 106 * sizeof (struct line_map))); | 107 * sizeof (struct line_map))); |
| 107 } | 108 } |
| 108 | 109 |
| 109 map = &set->maps[set->used]; | 110 map = &set->maps[set->used]; |
| 110 | 111 |
| 111 if (to_file && *to_file == '\0') | 112 if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM) |
| 112 to_file = "<stdin>"; | 113 to_file = "<stdin>"; |
| 113 | 114 |
| 115 if (reason == LC_RENAME_VERBATIM) |
| 116 reason = LC_RENAME; |
| 117 |
| 114 /* If we don't keep our line maps consistent, we can easily | 118 /* If we don't keep our line maps consistent, we can easily |
| 115 segfault. Don't rely on the client to do it for us. */ | 119 segfault. Don't rely on the client to do it for us. */ |
| 116 if (set->depth == 0) | 120 if (set->depth == 0) |
| 117 reason = LC_ENTER; | 121 reason = LC_ENTER; |
| 118 else if (reason == LC_LEAVE) | 122 else if (reason == LC_LEAVE) |
| 119 { | 123 { |
| 120 struct line_map *from; | 124 struct line_map *from; |
| 121 bool error; | 125 bool error; |
| 122 | 126 |
| 123 if (MAIN_FILE_P (map - 1)) | 127 if (MAIN_FILE_P (map - 1)) |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 if (set->maps[md].start_location > line) | 299 if (set->maps[md].start_location > line) |
| 296 mx = md; | 300 mx = md; |
| 297 else | 301 else |
| 298 mn = md; | 302 mn = md; |
| 299 } | 303 } |
| 300 | 304 |
| 301 set->cache = mn; | 305 set->cache = mn; |
| 302 return &set->maps[mn]; | 306 return &set->maps[mn]; |
| 303 } | 307 } |
| 304 | 308 |
| 305 /* Print the file names and line numbers of the #include commands | |
| 306 which led to the map MAP, if any, to stderr. Nothing is output if | |
| 307 the most recently listed stack is the same as the current one. */ | |
| 308 | |
| 309 void | |
| 310 linemap_print_containing_files (struct line_maps *set, | |
| 311 const struct line_map *map) | |
| 312 { | |
| 313 if (MAIN_FILE_P (map) || set->last_listed == map->included_from) | |
| 314 return; | |
| 315 | |
| 316 set->last_listed = map->included_from; | |
| 317 map = INCLUDED_FROM (set, map); | |
| 318 | |
| 319 fprintf (stderr, _("In file included from %s:%u"), | |
| 320 map->to_file, LAST_SOURCE_LINE (map)); | |
| 321 | |
| 322 while (! MAIN_FILE_P (map)) | |
| 323 { | |
| 324 map = INCLUDED_FROM (set, map); | |
| 325 /* Translators note: this message is used in conjunction | |
| 326 with "In file included from %s:%ld" and some other | |
| 327 tricks. We want something like this: | |
| 328 | |
| 329 | In file included from sys/select.h:123, | |
| 330 | from sys/types.h:234, | |
| 331 | from userfile.c:31: | |
| 332 | bits/select.h:45: <error message here> | |
| 333 | |
| 334 with all the "from"s lined up. | |
| 335 The trailing comma is at the beginning of this message, | |
| 336 and the trailing colon is not translated. */ | |
| 337 fprintf (stderr, _(",\n from %s:%u"), | |
| 338 map->to_file, LAST_SOURCE_LINE (map)); | |
| 339 } | |
| 340 | |
| 341 fputs (":\n", stderr); | |
| 342 } | |
| 343 | |
| 344 /* Print an include trace, for e.g. the -H option of the preprocessor. */ | 309 /* Print an include trace, for e.g. the -H option of the preprocessor. */ |
| 345 | 310 |
| 346 static void | 311 static void |
| 347 trace_include (const struct line_maps *set, const struct line_map *map) | 312 trace_include (const struct line_maps *set, const struct line_map *map) |
| 348 { | 313 { |
| 349 unsigned int i = set->depth; | 314 unsigned int i = set->depth; |
| 350 | 315 |
| 351 while (--i) | 316 while (--i) |
| 352 putc ('.', stderr); | 317 putc ('.', stderr); |
| 353 fprintf (stderr, " %s\n", map->to_file); | 318 fprintf (stderr, " %s\n", map->to_file); |
| 354 } | 319 } |
| OLD | NEW |