comparison libcpp/line-map.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Map (unsigned int) keys to (source file, line, column) triples. 1 /* Map (unsigned int) keys to (source file, line, column) triples.
2 Copyright (C) 2001-2018 Free Software Foundation, Inc. 2 Copyright (C) 2001-2020 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify it 4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the 5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3, or (at your option) any 6 Free Software Foundation; either version 3, or (at your option) any
7 later version. 7 later version.
24 #include "line-map.h" 24 #include "line-map.h"
25 #include "cpplib.h" 25 #include "cpplib.h"
26 #include "internal.h" 26 #include "internal.h"
27 #include "hashtab.h" 27 #include "hashtab.h"
28 28
29 static void trace_include (const struct line_maps *, const line_map_ordinary *); 29 static void trace_include (const line_maps *, const line_map_ordinary *);
30 static const line_map_ordinary * linemap_ordinary_map_lookup (struct line_maps *, 30 static const line_map_ordinary * linemap_ordinary_map_lookup (const line_maps *,
31 source_location); 31 location_t);
32 static const line_map_macro* linemap_macro_map_lookup (struct line_maps *, 32 static const line_map_macro* linemap_macro_map_lookup (const line_maps *,
33 source_location); 33 location_t);
34 static source_location linemap_macro_map_loc_to_def_point 34 static location_t linemap_macro_map_loc_to_def_point
35 (const line_map_macro *, source_location); 35 (const line_map_macro *, location_t);
36 static source_location linemap_macro_map_loc_to_exp_point 36 static location_t linemap_macro_map_loc_to_exp_point
37 (const line_map_macro *, source_location); 37 (const line_map_macro *, location_t);
38 static source_location linemap_macro_loc_to_spelling_point 38 static location_t linemap_macro_loc_to_spelling_point
39 (struct line_maps *, source_location, const line_map_ordinary **); 39 (line_maps *, location_t, const line_map_ordinary **);
40 static source_location linemap_macro_loc_to_def_point (struct line_maps *, 40 static location_t linemap_macro_loc_to_def_point (line_maps *,
41 source_location, 41 location_t,
42 const line_map_ordinary **); 42 const line_map_ordinary **);
43 static source_location linemap_macro_loc_to_exp_point (struct line_maps *, 43 static location_t linemap_macro_loc_to_exp_point (line_maps *,
44 source_location, 44 location_t,
45 const line_map_ordinary **); 45 const line_map_ordinary **);
46 46
47 /* Counters defined in macro.c. */ 47 /* Counters defined in macro.c. */
48 extern unsigned num_expanded_macros_counter; 48 extern unsigned num_expanded_macros_counter;
49 extern unsigned num_macro_tokens_counter; 49 extern unsigned num_macro_tokens_counter;
50 50
96 } 96 }
97 97
98 /* Rebuild the hash table from the location adhoc data. */ 98 /* Rebuild the hash table from the location adhoc data. */
99 99
100 void 100 void
101 rebuild_location_adhoc_htab (struct line_maps *set) 101 rebuild_location_adhoc_htab (line_maps *set)
102 { 102 {
103 unsigned i; 103 unsigned i;
104 set->location_adhoc_data_map.htab = 104 set->location_adhoc_data_map.htab =
105 htab_create (100, location_adhoc_data_hash, location_adhoc_data_eq, NULL); 105 htab_create (100, location_adhoc_data_hash, location_adhoc_data_eq, NULL);
106 for (i = 0; i < set->location_adhoc_data_map.curr_loc; i++) 106 for (i = 0; i < set->location_adhoc_data_map.curr_loc; i++)
108 set->location_adhoc_data_map.data + i, INSERT); 108 set->location_adhoc_data_map.data + i, INSERT);
109 } 109 }
110 110
111 /* Helper function for get_combined_adhoc_loc. 111 /* Helper function for get_combined_adhoc_loc.
112 Can the given LOCUS + SRC_RANGE and DATA pointer be stored compactly 112 Can the given LOCUS + SRC_RANGE and DATA pointer be stored compactly
113 within a source_location, without needing to use an ad-hoc location. */ 113 within a location_t, without needing to use an ad-hoc location. */
114 114
115 static bool 115 static bool
116 can_be_stored_compactly_p (struct line_maps *set, 116 can_be_stored_compactly_p (line_maps *set,
117 source_location locus, 117 location_t locus,
118 source_range src_range, 118 source_range src_range,
119 void *data) 119 void *data)
120 { 120 {
121 /* If there's an ad-hoc pointer, we can't store it directly in the 121 /* If there's an ad-hoc pointer, we can't store it directly in the
122 source_location, we need the lookaside. */ 122 location_t, we need the lookaside. */
123 if (data) 123 if (data)
124 return false; 124 return false;
125 125
126 /* We only store ranges that begin at the locus and that are sufficiently 126 /* We only store ranges that begin at the locus and that are sufficiently
127 "sane". */ 127 "sane". */
137 if (locus >= LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES) 137 if (locus >= LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES)
138 return false; 138 return false;
139 139
140 /* All 3 locations must be within ordinary maps, typically, the same 140 /* All 3 locations must be within ordinary maps, typically, the same
141 ordinary map. */ 141 ordinary map. */
142 source_location lowest_macro_loc = LINEMAPS_MACRO_LOWEST_LOCATION (set); 142 location_t lowest_macro_loc = LINEMAPS_MACRO_LOWEST_LOCATION (set);
143 if (locus >= lowest_macro_loc) 143 if (locus >= lowest_macro_loc)
144 return false; 144 return false;
145 if (src_range.m_start >= lowest_macro_loc) 145 if (src_range.m_start >= lowest_macro_loc)
146 return false; 146 return false;
147 if (src_range.m_finish >= lowest_macro_loc) 147 if (src_range.m_finish >= lowest_macro_loc)
151 return true; 151 return true;
152 } 152 }
153 153
154 /* Combine LOCUS and DATA to a combined adhoc loc. */ 154 /* Combine LOCUS and DATA to a combined adhoc loc. */
155 155
156 source_location 156 location_t
157 get_combined_adhoc_loc (struct line_maps *set, 157 get_combined_adhoc_loc (line_maps *set,
158 source_location locus, 158 location_t locus,
159 source_range src_range, 159 source_range src_range,
160 void *data) 160 void *data)
161 { 161 {
162 struct location_adhoc_data lb; 162 struct location_adhoc_data lb;
163 struct location_adhoc_data **slot; 163 struct location_adhoc_data **slot;
164 164
165 if (IS_ADHOC_LOC (locus)) 165 if (IS_ADHOC_LOC (locus))
166 locus 166 locus = get_location_from_adhoc_loc (set, locus);
167 = set->location_adhoc_data_map.data[locus & MAX_SOURCE_LOCATION].locus;
168 if (locus == 0 && data == NULL) 167 if (locus == 0 && data == NULL)
169 return 0; 168 return 0;
170 169
171 /* Any ordinary locations ought to be "pure" at this point: no 170 /* Any ordinary locations ought to be "pure" at this point: no
172 compressed ranges. */ 171 compressed ranges. */
184 const line_map_ordinary *ordmap = linemap_check_ordinary (map); 183 const line_map_ordinary *ordmap = linemap_check_ordinary (map);
185 unsigned int int_diff = src_range.m_finish - src_range.m_start; 184 unsigned int int_diff = src_range.m_finish - src_range.m_start;
186 unsigned int col_diff = (int_diff >> ordmap->m_range_bits); 185 unsigned int col_diff = (int_diff >> ordmap->m_range_bits);
187 if (col_diff < (1U << ordmap->m_range_bits)) 186 if (col_diff < (1U << ordmap->m_range_bits))
188 { 187 {
189 source_location packed = locus | col_diff; 188 location_t packed = locus | col_diff;
190 set->num_optimized_ranges++; 189 set->num_optimized_ranges++;
191 return packed; 190 return packed;
192 } 191 }
193 } 192 }
194 193
241 } 240 }
242 241
243 /* Return the data for the adhoc loc. */ 242 /* Return the data for the adhoc loc. */
244 243
245 void * 244 void *
246 get_data_from_adhoc_loc (struct line_maps *set, source_location loc) 245 get_data_from_adhoc_loc (const class line_maps *set, location_t loc)
247 { 246 {
248 linemap_assert (IS_ADHOC_LOC (loc)); 247 linemap_assert (IS_ADHOC_LOC (loc));
249 return set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].data; 248 return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].data;
250 } 249 }
251 250
252 /* Return the location for the adhoc loc. */ 251 /* Return the location for the adhoc loc. */
253 252
254 source_location 253 location_t
255 get_location_from_adhoc_loc (struct line_maps *set, source_location loc) 254 get_location_from_adhoc_loc (const class line_maps *set, location_t loc)
256 { 255 {
257 linemap_assert (IS_ADHOC_LOC (loc)); 256 linemap_assert (IS_ADHOC_LOC (loc));
258 return set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; 257 return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus;
259 } 258 }
260 259
261 /* Return the source_range for adhoc location LOC. */ 260 /* Return the source_range for adhoc location LOC. */
262 261
263 static source_range 262 static source_range
264 get_range_from_adhoc_loc (struct line_maps *set, source_location loc) 263 get_range_from_adhoc_loc (const class line_maps *set, location_t loc)
265 { 264 {
266 linemap_assert (IS_ADHOC_LOC (loc)); 265 linemap_assert (IS_ADHOC_LOC (loc));
267 return set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].src_range; 266 return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].src_range;
268 } 267 }
269 268
270 /* Get the source_range of location LOC, either from the ad-hoc 269 /* Get the source_range of location LOC, either from the ad-hoc
271 lookaside table, or embedded inside LOC itself. */ 270 lookaside table, or embedded inside LOC itself. */
272 271
273 source_range 272 source_range
274 get_range_from_loc (struct line_maps *set, 273 get_range_from_loc (line_maps *set,
275 source_location loc) 274 location_t loc)
276 { 275 {
277 if (IS_ADHOC_LOC (loc)) 276 if (IS_ADHOC_LOC (loc))
278 return get_range_from_adhoc_loc (set, loc); 277 return get_range_from_adhoc_loc (set, loc);
279 278
280 /* For ordinary maps, extract packed range. */ 279 /* For ordinary maps, extract packed range. */
296 295
297 /* Get whether location LOC is a "pure" location, or 296 /* Get whether location LOC is a "pure" location, or
298 whether it is an ad-hoc location, or embeds range information. */ 297 whether it is an ad-hoc location, or embeds range information. */
299 298
300 bool 299 bool
301 pure_location_p (line_maps *set, source_location loc) 300 pure_location_p (line_maps *set, location_t loc)
302 { 301 {
303 if (IS_ADHOC_LOC (loc)) 302 if (IS_ADHOC_LOC (loc))
304 return false; 303 return false;
305 304
306 const line_map *map = linemap_lookup (set, loc); 305 const line_map *map = linemap_lookup (set, loc);
315 } 314 }
316 315
317 /* Given location LOC within SET, strip away any packed range information 316 /* Given location LOC within SET, strip away any packed range information
318 or ad-hoc information. */ 317 or ad-hoc information. */
319 318
320 source_location 319 location_t
321 get_pure_location (line_maps *set, source_location loc) 320 get_pure_location (line_maps *set, location_t loc)
322 { 321 {
323 if (IS_ADHOC_LOC (loc)) 322 if (IS_ADHOC_LOC (loc))
324 loc 323 loc = get_location_from_adhoc_loc (set, loc);
325 = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus;
326 324
327 if (loc >= LINEMAPS_MACRO_LOWEST_LOCATION (set)) 325 if (loc >= LINEMAPS_MACRO_LOWEST_LOCATION (set))
328 return loc; 326 return loc;
329 327
330 if (loc < RESERVED_LOCATION_COUNT) 328 if (loc < RESERVED_LOCATION_COUNT)
337 } 335 }
338 336
339 /* Initialize a line map set. */ 337 /* Initialize a line map set. */
340 338
341 void 339 void
342 linemap_init (struct line_maps *set, 340 linemap_init (line_maps *set,
343 source_location builtin_location) 341 location_t builtin_location)
344 { 342 {
345 #if __GNUC__ == 4 && __GNUC_MINOR__ == 2 && !defined (__clang__) 343 #if __GNUC__ == 4 && __GNUC_MINOR__ == 2 && !defined (__clang__)
346 /* PR33916, needed to fix PR82939. */ 344 /* PR33916, needed to fix PR82939. */
347 memset (set, 0, sizeof (struct line_maps)); 345 memset (set, 0, sizeof (line_maps));
348 #else 346 #else
349 new (set) line_maps(); 347 new (set) line_maps();
350 #endif 348 #endif
351 /* Set default reallocator (used for initial alloc too). */ 349 /* Set default reallocator (used for initial alloc too). */
352 set->reallocator = xrealloc; 350 set->reallocator = xrealloc;
367 } 365 }
368 366
369 /* Check for and warn about line_maps entered but not exited. */ 367 /* Check for and warn about line_maps entered but not exited. */
370 368
371 void 369 void
372 linemap_check_files_exited (struct line_maps *set) 370 linemap_check_files_exited (line_maps *set)
373 { 371 {
374 /* Depending upon whether we are handling preprocessed input or 372 /* Depending upon whether we are handling preprocessed input or
375 not, this can be a user error or an ICE. */ 373 not, this can be a user error or an ICE. */
376 for (const line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (set); 374 for (const line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (set);
377 ! MAIN_FILE_P (map); 375 ! MAIN_FILE_P (map);
384 REASON is the reason of creating the map. It determines the type 382 REASON is the reason of creating the map. It determines the type
385 of map created (ordinary or macro map). Note that ordinary maps and 383 of map created (ordinary or macro map). Note that ordinary maps and
386 macro maps are allocated in different memory location. */ 384 macro maps are allocated in different memory location. */
387 385
388 static struct line_map * 386 static struct line_map *
389 new_linemap (struct line_maps *set, source_location start_location) 387 new_linemap (line_maps *set, location_t start_location)
390 { 388 {
391 bool macro_p = start_location >= LINE_MAP_MAX_LOCATION; 389 bool macro_p = start_location >= LINE_MAP_MAX_LOCATION;
392 unsigned num_maps_allocated = LINEMAPS_ALLOCATED (set, macro_p); 390 unsigned num_maps_allocated = LINEMAPS_ALLOCATED (set, macro_p);
393 unsigned num_maps_used = LINEMAPS_USED (set, macro_p); 391 unsigned num_maps_used = LINEMAPS_USED (set, macro_p);
394 392
457 FROM_LINE should be monotonic increasing across calls to this 455 FROM_LINE should be monotonic increasing across calls to this
458 function. A call to this function can relocate the previous set of 456 function. A call to this function can relocate the previous set of
459 maps, so any stored line_map pointers should not be used. */ 457 maps, so any stored line_map pointers should not be used. */
460 458
461 const struct line_map * 459 const struct line_map *
462 linemap_add (struct line_maps *set, enum lc_reason reason, 460 linemap_add (line_maps *set, enum lc_reason reason,
463 unsigned int sysp, const char *to_file, linenum_type to_line) 461 unsigned int sysp, const char *to_file, linenum_type to_line)
464 { 462 {
465 /* Generate a start_location above the current highest_location. 463 /* Generate a start_location above the current highest_location.
466 If possible, make the low range bits be zero. */ 464 If possible, make the low range bits be zero. */
467 source_location start_location; 465 location_t start_location;
468 if (set->highest_location < LINE_MAP_MAX_LOCATION_WITH_COLS) 466 if (set->highest_location < LINE_MAP_MAX_LOCATION_WITH_COLS)
469 { 467 {
470 start_location = set->highest_location + (1 << set->default_range_bits); 468 start_location = set->highest_location + (1 << set->default_range_bits);
471 if (set->default_range_bits) 469 if (set->default_range_bits)
472 start_location &= ~((1 << set->default_range_bits) - 1); 470 start_location &= ~((1 << set->default_range_bits) - 1);
578 576
579 /* Returns TRUE if the line table set tracks token locations across 577 /* Returns TRUE if the line table set tracks token locations across
580 macro expansion, FALSE otherwise. */ 578 macro expansion, FALSE otherwise. */
581 579
582 bool 580 bool
583 linemap_tracks_macro_expansion_locs_p (struct line_maps *set) 581 linemap_tracks_macro_expansion_locs_p (line_maps *set)
584 { 582 {
585 return LINEMAPS_MACRO_MAPS (set) != NULL; 583 return LINEMAPS_MACRO_MAPS (set) != NULL;
586 } 584 }
587 585
588 /* Create a macro map. A macro map encodes source locations of tokens 586 /* Create a macro map. A macro map encodes source locations of tokens
607 locations, this function returns NULL. In that case, callers of 605 locations, this function returns NULL. In that case, callers of
608 this function cannot encode {line,column} pairs into locations of 606 this function cannot encode {line,column} pairs into locations of
609 macro tokens anymore. */ 607 macro tokens anymore. */
610 608
611 const line_map_macro * 609 const line_map_macro *
612 linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node, 610 linemap_enter_macro (class line_maps *set, struct cpp_hashnode *macro_node,
613 source_location expansion, unsigned int num_tokens) 611 location_t expansion, unsigned int num_tokens)
614 { 612 {
615 source_location start_location 613 location_t start_location
616 = LINEMAPS_MACRO_LOWEST_LOCATION (set) - num_tokens; 614 = LINEMAPS_MACRO_LOWEST_LOCATION (set) - num_tokens;
617 615
618 if (start_location < LINE_MAP_MAX_LOCATION) 616 if (start_location < LINE_MAP_MAX_LOCATION)
619 /* We ran out of macro map space. */ 617 /* We ran out of macro map space. */
620 return NULL; 618 return NULL;
622 line_map_macro *map = linemap_check_macro (new_linemap (set, start_location)); 620 line_map_macro *map = linemap_check_macro (new_linemap (set, start_location));
623 621
624 map->macro = macro_node; 622 map->macro = macro_node;
625 map->n_tokens = num_tokens; 623 map->n_tokens = num_tokens;
626 map->macro_locations 624 map->macro_locations
627 = (source_location*) set->reallocator (NULL, 625 = (location_t*) set->reallocator (NULL,
628 2 * num_tokens 626 2 * num_tokens
629 * sizeof (source_location)); 627 * sizeof (location_t));
630 map->expansion = expansion; 628 map->expansion = expansion;
631 memset (MACRO_MAP_LOCATIONS (map), 0, 629 memset (MACRO_MAP_LOCATIONS (map), 0,
632 2 * num_tokens * sizeof (source_location)); 630 2 * num_tokens * sizeof (location_t));
633 631
634 LINEMAPS_MACRO_CACHE (set) = LINEMAPS_MACRO_USED (set) - 1; 632 LINEMAPS_MACRO_CACHE (set) = LINEMAPS_MACRO_USED (set) - 1;
635 633
636 return map; 634 return map;
637 } 635 }
657 655
658 ORIG_PARM_REPLACEMENT_LOC is the location in the macro definition, 656 ORIG_PARM_REPLACEMENT_LOC is the location in the macro definition,
659 either of the token itself or of a macro parameter that it 657 either of the token itself or of a macro parameter that it
660 replaces. */ 658 replaces. */
661 659
662 source_location 660 location_t
663 linemap_add_macro_token (const line_map_macro *map, 661 linemap_add_macro_token (const line_map_macro *map,
664 unsigned int token_no, 662 unsigned int token_no,
665 source_location orig_loc, 663 location_t orig_loc,
666 source_location orig_parm_replacement_loc) 664 location_t orig_parm_replacement_loc)
667 { 665 {
668 source_location result; 666 location_t result;
669 667
670 linemap_assert (linemap_macro_expansion_map_p (map)); 668 linemap_assert (linemap_macro_expansion_map_p (map));
671 linemap_assert (token_no < MACRO_MAP_NUM_MACRO_TOKENS (map)); 669 linemap_assert (token_no < MACRO_MAP_NUM_MACRO_TOKENS (map));
672 670
673 MACRO_MAP_LOCATIONS (map)[2 * token_no] = orig_loc; 671 MACRO_MAP_LOCATIONS (map)[2 * token_no] = orig_loc;
675 673
676 result = MAP_START_LOCATION (map) + token_no; 674 result = MAP_START_LOCATION (map) + token_no;
677 return result; 675 return result;
678 } 676 }
679 677
680 /* Return a source_location for the start (i.e. column==0) of 678 /* Return a location_t for the start (i.e. column==0) of
681 (physical) line TO_LINE in the current source file (as in the 679 (physical) line TO_LINE in the current source file (as in the
682 most recent linemap_add). MAX_COLUMN_HINT is the highest column 680 most recent linemap_add). MAX_COLUMN_HINT is the highest column
683 number we expect to use in this line (but it does not change 681 number we expect to use in this line (but it does not change
684 the highest_location). */ 682 the highest_location). */
685 683
686 source_location 684 location_t
687 linemap_line_start (struct line_maps *set, linenum_type to_line, 685 linemap_line_start (line_maps *set, linenum_type to_line,
688 unsigned int max_column_hint) 686 unsigned int max_column_hint)
689 { 687 {
690 line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (set); 688 line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (set);
691 source_location highest = set->highest_location; 689 location_t highest = set->highest_location;
692 source_location r; 690 location_t r;
693 linenum_type last_line = 691 linenum_type last_line =
694 SOURCE_LINE (map, set->highest_line); 692 SOURCE_LINE (map, set->highest_line);
695 int line_delta = to_line - last_line; 693 int line_delta = to_line - last_line;
696 bool add_map = false; 694 bool add_map = false;
697 linemap_assert (map->m_column_and_range_bits >= map->m_range_bits); 695 linemap_assert (map->m_column_and_range_bits >= map->m_range_bits);
715 int range_bits; 713 int range_bits;
716 if (max_column_hint > LINE_MAP_MAX_COLUMN_NUMBER 714 if (max_column_hint > LINE_MAP_MAX_COLUMN_NUMBER
717 || highest > LINE_MAP_MAX_LOCATION_WITH_COLS) 715 || highest > LINE_MAP_MAX_LOCATION_WITH_COLS)
718 { 716 {
719 /* If the column number is ridiculous or we've allocated a huge 717 /* If the column number is ridiculous or we've allocated a huge
720 number of source_locations, give up on column numbers 718 number of location_ts, give up on column numbers
721 (and on packed ranges). */ 719 (and on packed ranges). */
722 max_column_hint = 0; 720 max_column_hint = 1;
723 column_bits = 0; 721 column_bits = 0;
724 range_bits = 0; 722 range_bits = 0;
725 if (highest >= LINE_MAP_MAX_LOCATION) 723 if (highest >= LINE_MAP_MAX_LOCATION)
726 return 0; 724 goto overflowed;
727 } 725 }
728 else 726 else
729 { 727 {
730 column_bits = 7; 728 column_bits = 7;
731 if (highest <= LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES) 729 if (highest <= LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES)
735 while (max_column_hint >= (1U << column_bits)) 733 while (max_column_hint >= (1U << column_bits))
736 column_bits++; 734 column_bits++;
737 max_column_hint = 1U << column_bits; 735 max_column_hint = 1U << column_bits;
738 column_bits += range_bits; 736 column_bits += range_bits;
739 } 737 }
738
740 /* Allocate the new line_map. However, if the current map only has a 739 /* Allocate the new line_map. However, if the current map only has a
741 single line we can sometimes just increase its column_bits instead. */ 740 single line we can sometimes just increase its column_bits instead. */
742 if (line_delta < 0 741 if (line_delta < 0
743 || last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map) 742 || last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map)
744 || SOURCE_COLUMN (map, highest) >= (1U << (column_bits - range_bits)) 743 || SOURCE_COLUMN (map, highest) >= (1U << (column_bits - range_bits))
744 || ( /* We can't reuse the map if the line offset is sufficiently
745 large to cause overflow when computing location_t values. */
746 (to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map))
747 >= (((uint64_t) 1)
748 << (CHAR_BIT * sizeof (linenum_type) - column_bits)))
745 || range_bits < map->m_range_bits) 749 || range_bits < map->m_range_bits)
746 map = linemap_check_ordinary 750 map = linemap_check_ordinary
747 (const_cast <line_map *> 751 (const_cast <line_map *>
748 (linemap_add (set, LC_RENAME, 752 (linemap_add (set, LC_RENAME,
749 ORDINARY_MAP_IN_SYSTEM_HEADER_P (map), 753 ORDINARY_MAP_IN_SYSTEM_HEADER_P (map),
759 r = set->highest_line + (line_delta << map->m_column_and_range_bits); 763 r = set->highest_line + (line_delta << map->m_column_and_range_bits);
760 764
761 /* Locations of ordinary tokens are always lower than locations of 765 /* Locations of ordinary tokens are always lower than locations of
762 macro tokens. */ 766 macro tokens. */
763 if (r >= LINE_MAP_MAX_LOCATION) 767 if (r >= LINE_MAP_MAX_LOCATION)
764 return 0; 768 {
769 overflowed:
770 /* Remember we overflowed. */
771 set->highest_line = set->highest_location = LINE_MAP_MAX_LOCATION - 1;
772 /* No column numbers! */
773 set->max_column_hint = 1;
774 return 0;
775 }
765 776
766 set->highest_line = r; 777 set->highest_line = r;
767 if (r > set->highest_location) 778 if (r > set->highest_location)
768 set->highest_location = r; 779 set->highest_location = r;
769 set->max_column_hint = max_column_hint; 780 set->max_column_hint = max_column_hint;
780 || map->m_column_and_range_bits == 0); 791 || map->m_column_and_range_bits == 0);
781 linemap_assert (SOURCE_LINE (map, r) == to_line); 792 linemap_assert (SOURCE_LINE (map, r) == to_line);
782 return r; 793 return r;
783 } 794 }
784 795
785 /* Encode and return a source_location from a column number. The 796 /* Encode and return a location_t from a column number. The
786 source line considered is the last source line used to call 797 source line considered is the last source line used to call
787 linemap_line_start, i.e, the last source line which a location was 798 linemap_line_start, i.e, the last source line which a location was
788 encoded from. */ 799 encoded from. */
789 800
790 source_location 801 location_t
791 linemap_position_for_column (struct line_maps *set, unsigned int to_column) 802 linemap_position_for_column (line_maps *set, unsigned int to_column)
792 { 803 {
793 source_location r = set->highest_line; 804 location_t r = set->highest_line;
794 805
795 linemap_assert 806 linemap_assert
796 (!linemap_macro_expansion_map_p (LINEMAPS_LAST_ORDINARY_MAP (set))); 807 (!linemap_macro_expansion_map_p (LINEMAPS_LAST_ORDINARY_MAP (set)));
797 808
798 if (to_column >= set->max_column_hint) 809 if (to_column >= set->max_column_hint)
799 { 810 {
800 if (r > LINE_MAP_MAX_LOCATION_WITH_COLS 811 if (r > LINE_MAP_MAX_LOCATION_WITH_COLS
801 || to_column > LINE_MAP_MAX_COLUMN_NUMBER) 812 || to_column > LINE_MAP_MAX_COLUMN_NUMBER)
802 { 813 {
803 /* Running low on source_locations - disable column numbers. */ 814 /* Running low on location_ts - disable column numbers. */
804 return r; 815 return r;
805 } 816 }
806 else 817 else
807 { 818 {
808 /* Otherwise, attempt to start a new line that can hold TO_COLUMN, 819 /* Otherwise, attempt to start a new line that can hold TO_COLUMN,
831 } 842 }
832 843
833 /* Encode and return a source location from a given line and 844 /* Encode and return a source location from a given line and
834 column. */ 845 column. */
835 846
836 source_location 847 location_t
837 linemap_position_for_line_and_column (line_maps *set, 848 linemap_position_for_line_and_column (line_maps *set,
838 const line_map_ordinary *ord_map, 849 const line_map_ordinary *ord_map,
839 linenum_type line, 850 linenum_type line,
840 unsigned column) 851 unsigned column)
841 { 852 {
842 linemap_assert (ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map) <= line); 853 linemap_assert (ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map) <= line);
843 854
844 source_location r = MAP_START_LOCATION (ord_map); 855 location_t r = MAP_START_LOCATION (ord_map);
845 r += ((line - ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map)) 856 r += ((line - ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map))
846 << ord_map->m_column_and_range_bits); 857 << ord_map->m_column_and_range_bits);
847 if (r <= LINE_MAP_MAX_LOCATION_WITH_COLS) 858 if (r <= LINE_MAP_MAX_LOCATION_WITH_COLS)
848 r += ((column & ((1 << ord_map->m_column_and_range_bits) - 1)) 859 r += ((column & ((1 << ord_map->m_column_and_range_bits) - 1))
849 << ord_map->m_range_bits); 860 << ord_map->m_range_bits);
850 source_location upper_limit = LINEMAPS_MACRO_LOWEST_LOCATION (set); 861 location_t upper_limit = LINEMAPS_MACRO_LOWEST_LOCATION (set);
851 if (r >= upper_limit) 862 if (r >= upper_limit)
852 r = upper_limit - 1; 863 r = upper_limit - 1;
853 if (r > set->highest_location) 864 if (r > set->highest_location)
854 set->highest_location = r; 865 set->highest_location = r;
855 return r; 866 return r;
856 } 867 }
857 868
858 /* Encode and return a source_location starting from location LOC and 869 /* Encode and return a location_t starting from location LOC and
859 shifting it by COLUMN_OFFSET columns. This function does not support 870 shifting it by COLUMN_OFFSET columns. This function does not support
860 virtual locations. */ 871 virtual locations. */
861 872
862 source_location 873 location_t
863 linemap_position_for_loc_and_offset (struct line_maps *set, 874 linemap_position_for_loc_and_offset (line_maps *set,
864 source_location loc, 875 location_t loc,
865 unsigned int column_offset) 876 unsigned int column_offset)
866 { 877 {
867 const line_map_ordinary * map = NULL; 878 const line_map_ordinary * map = NULL;
868 879
869 if (IS_ADHOC_LOC (loc)) 880 if (IS_ADHOC_LOC (loc))
870 loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; 881 loc = get_location_from_adhoc_loc (set, loc);
871 882
872 /* This function does not support virtual locations yet. */ 883 /* This function does not support virtual locations yet. */
873 if (linemap_location_from_macro_expansion_p (set, loc)) 884 if (linemap_location_from_macro_expansion_p (set, loc))
874 return loc; 885 return loc;
875 886
911 /* Bail out if the column is not representable within the existing 922 /* Bail out if the column is not representable within the existing
912 linemap. */ 923 linemap. */
913 if (column >= (1u << (map->m_column_and_range_bits - map->m_range_bits))) 924 if (column >= (1u << (map->m_column_and_range_bits - map->m_range_bits)))
914 return loc; 925 return loc;
915 926
916 source_location r = 927 location_t r =
917 linemap_position_for_line_and_column (set, map, line, column); 928 linemap_position_for_line_and_column (set, map, line, column);
918 if (linemap_assert_fails (r <= set->highest_location) 929 if (linemap_assert_fails (r <= set->highest_location)
919 || linemap_assert_fails (map == linemap_lookup (set, r))) 930 || linemap_assert_fails (map == linemap_lookup (set, r)))
920 return loc; 931 return loc;
921 932
924 935
925 /* Given a virtual source location yielded by a map (either an 936 /* Given a virtual source location yielded by a map (either an
926 ordinary or a macro map), returns that map. */ 937 ordinary or a macro map), returns that map. */
927 938
928 const struct line_map* 939 const struct line_map*
929 linemap_lookup (struct line_maps *set, source_location line) 940 linemap_lookup (const line_maps *set, location_t line)
930 { 941 {
931 if (IS_ADHOC_LOC (line)) 942 if (IS_ADHOC_LOC (line))
932 line = set->location_adhoc_data_map.data[line & MAX_SOURCE_LOCATION].locus; 943 line = get_location_from_adhoc_loc (set, line);
933 if (linemap_location_from_macro_expansion_p (set, line)) 944 if (linemap_location_from_macro_expansion_p (set, line))
934 return linemap_macro_map_lookup (set, line); 945 return linemap_macro_map_lookup (set, line);
935 return linemap_ordinary_map_lookup (set, line); 946 return linemap_ordinary_map_lookup (set, line);
936 } 947 }
937 948
939 map. Since the set is built chronologically, the logical lines are 950 map. Since the set is built chronologically, the logical lines are
940 monotonic increasing, and so the list is sorted and we can use a 951 monotonic increasing, and so the list is sorted and we can use a
941 binary search. */ 952 binary search. */
942 953
943 static const line_map_ordinary * 954 static const line_map_ordinary *
944 linemap_ordinary_map_lookup (struct line_maps *set, source_location line) 955 linemap_ordinary_map_lookup (const line_maps *set, location_t line)
945 { 956 {
946 unsigned int md, mn, mx; 957 unsigned int md, mn, mx;
947 const line_map_ordinary *cached, *result; 958 const line_map_ordinary *cached, *result;
948 959
949 if (IS_ADHOC_LOC (line)) 960 if (IS_ADHOC_LOC (line))
950 line = set->location_adhoc_data_map.data[line & MAX_SOURCE_LOCATION].locus; 961 line = get_location_from_adhoc_loc (set, line);
951 962
952 if (set == NULL || line < RESERVED_LOCATION_COUNT) 963 if (set == NULL || line < RESERVED_LOCATION_COUNT)
953 return NULL; 964 return NULL;
954 965
955 mn = LINEMAPS_ORDINARY_CACHE (set); 966 mn = LINEMAPS_ORDINARY_CACHE (set);
956 mx = LINEMAPS_ORDINARY_USED (set); 967 mx = LINEMAPS_ORDINARY_USED (set);
957 968
958 cached = LINEMAPS_ORDINARY_MAP_AT (set, mn); 969 cached = LINEMAPS_ORDINARY_MAP_AT (set, mn);
959 /* We should get a segfault if no line_maps have been added yet. */ 970 /* We should get a segfault if no line_maps have been added yet. */
960 if (line >= MAP_START_LOCATION (cached)) 971 if (line >= MAP_START_LOCATION (cached))
961 { 972 {
962 if (mn + 1 == mx || line < MAP_START_LOCATION (&cached[1])) 973 if (mn + 1 == mx || line < MAP_START_LOCATION (&cached[1]))
987 Since the set is built chronologically, the logical lines are 998 Since the set is built chronologically, the logical lines are
988 monotonic decreasing, and so the list is sorted and we can use a 999 monotonic decreasing, and so the list is sorted and we can use a
989 binary search. */ 1000 binary search. */
990 1001
991 static const line_map_macro * 1002 static const line_map_macro *
992 linemap_macro_map_lookup (struct line_maps *set, source_location line) 1003 linemap_macro_map_lookup (const line_maps *set, location_t line)
993 { 1004 {
994 unsigned int md, mn, mx; 1005 unsigned int md, mn, mx;
995 const struct line_map_macro *cached, *result; 1006 const struct line_map_macro *cached, *result;
996 1007
997 if (IS_ADHOC_LOC (line)) 1008 if (IS_ADHOC_LOC (line))
998 line = set->location_adhoc_data_map.data[line & MAX_SOURCE_LOCATION].locus; 1009 line = get_location_from_adhoc_loc (set, line);
999 1010
1000 linemap_assert (line >= LINEMAPS_MACRO_LOWEST_LOCATION (set)); 1011 linemap_assert (line >= LINEMAPS_MACRO_LOWEST_LOCATION (set));
1001 1012
1002 if (set == NULL) 1013 if (set == NULL)
1003 return NULL; 1014 return NULL;
1043 macro expansion return the location of the macro expansion point. 1054 macro expansion return the location of the macro expansion point.
1044 1055
1045 Read the comments of struct line_map and struct line_map_macro in 1056 Read the comments of struct line_map and struct line_map_macro in
1046 line-map.h to understand what a macro expansion point is. */ 1057 line-map.h to understand what a macro expansion point is. */
1047 1058
1048 static source_location 1059 static location_t
1049 linemap_macro_map_loc_to_exp_point (const line_map_macro *map, 1060 linemap_macro_map_loc_to_exp_point (const line_map_macro *map,
1050 source_location location ATTRIBUTE_UNUSED) 1061 location_t location ATTRIBUTE_UNUSED)
1051 { 1062 {
1052 linemap_assert (linemap_macro_expansion_map_p (map) 1063 linemap_assert (linemap_macro_expansion_map_p (map)
1053 && location >= MAP_START_LOCATION (map)); 1064 && location >= MAP_START_LOCATION (map));
1054 1065
1055 /* Make sure LOCATION is correct. */ 1066 /* Make sure LOCATION is correct. */
1063 replacement-list as part of the macro expansion denoted by MAP. 1074 replacement-list as part of the macro expansion denoted by MAP.
1064 1075
1065 Return the location of the token at the definition point of the 1076 Return the location of the token at the definition point of the
1066 macro. */ 1077 macro. */
1067 1078
1068 static source_location 1079 static location_t
1069 linemap_macro_map_loc_to_def_point (const line_map_macro *map, 1080 linemap_macro_map_loc_to_def_point (const line_map_macro *map,
1070 source_location location) 1081 location_t location)
1071 { 1082 {
1072 unsigned token_no; 1083 unsigned token_no;
1073 1084
1074 linemap_assert (linemap_macro_expansion_map_p (map) 1085 linemap_assert (linemap_macro_expansion_map_p (map)
1075 && location >= MAP_START_LOCATION (map)); 1086 && location >= MAP_START_LOCATION (map));
1087 function-like macro M and appears in the expansion of M, return the 1098 function-like macro M and appears in the expansion of M, return the
1088 locus of that argument in the context of the caller of M. 1099 locus of that argument in the context of the caller of M.
1089 1100
1090 In other words, this returns the xI location presented in the 1101 In other words, this returns the xI location presented in the
1091 comments of line_map_macro above. */ 1102 comments of line_map_macro above. */
1092 source_location 1103 location_t
1093 linemap_macro_map_loc_unwind_toward_spelling (line_maps *set, 1104 linemap_macro_map_loc_unwind_toward_spelling (line_maps *set,
1094 const line_map_macro* map, 1105 const line_map_macro* map,
1095 source_location location) 1106 location_t location)
1096 { 1107 {
1097 unsigned token_no; 1108 unsigned token_no;
1098 1109
1099 if (IS_ADHOC_LOC (location)) 1110 if (IS_ADHOC_LOC (location))
1100 location = get_location_from_adhoc_loc (set, location); 1111 location = get_location_from_adhoc_loc (set, location);
1117 LOCATION is the source location of token that is part of the 1128 LOCATION is the source location of token that is part of the
1118 replacement-list of a macro expansion return the line number of the 1129 replacement-list of a macro expansion return the line number of the
1119 macro expansion point. */ 1130 macro expansion point. */
1120 1131
1121 int 1132 int
1122 linemap_get_expansion_line (struct line_maps *set, 1133 linemap_get_expansion_line (line_maps *set,
1123 source_location location) 1134 location_t location)
1124 { 1135 {
1125 const line_map_ordinary *map = NULL; 1136 const line_map_ordinary *map = NULL;
1126 1137
1127 if (IS_ADHOC_LOC (location)) 1138 if (IS_ADHOC_LOC (location))
1128 location = set->location_adhoc_data_map.data[location 1139 location = get_location_from_adhoc_loc (set, location);
1129 & MAX_SOURCE_LOCATION].locus;
1130 1140
1131 if (location < RESERVED_LOCATION_COUNT) 1141 if (location < RESERVED_LOCATION_COUNT)
1132 return 0; 1142 return 0;
1133 1143
1134 location = 1144 location =
1145 macro expansion point. 1155 macro expansion point.
1146 1156
1147 SET is the line map set LOCATION comes from. */ 1157 SET is the line map set LOCATION comes from. */
1148 1158
1149 const char* 1159 const char*
1150 linemap_get_expansion_filename (struct line_maps *set, 1160 linemap_get_expansion_filename (line_maps *set,
1151 source_location location) 1161 location_t location)
1152 { 1162 {
1153 const struct line_map_ordinary *map = NULL; 1163 const struct line_map_ordinary *map = NULL;
1154 1164
1155 if (IS_ADHOC_LOC (location)) 1165 if (IS_ADHOC_LOC (location))
1156 location = set->location_adhoc_data_map.data[location 1166 location = get_location_from_adhoc_loc (set, location);
1157 & MAX_SOURCE_LOCATION].locus;
1158 1167
1159 if (location < RESERVED_LOCATION_COUNT) 1168 if (location < RESERVED_LOCATION_COUNT)
1160 return NULL; 1169 return NULL;
1161 1170
1162 location = 1171 linemap_macro_loc_to_exp_point (set, location, &map);
1163 linemap_macro_loc_to_exp_point (set, location, &map);
1164 1172
1165 return LINEMAP_FILE (map); 1173 return LINEMAP_FILE (map);
1166 } 1174 }
1167 1175
1168 /* Return the name of the macro associated to MACRO_MAP. */ 1176 /* Return the name of the macro associated to MACRO_MAP. */
1183 Note that this function returns 1 if LOCATION belongs to a token 1191 Note that this function returns 1 if LOCATION belongs to a token
1184 that is part of a macro replacement-list defined in a system 1192 that is part of a macro replacement-list defined in a system
1185 header, but expanded in a non-system file. */ 1193 header, but expanded in a non-system file. */
1186 1194
1187 int 1195 int
1188 linemap_location_in_system_header_p (struct line_maps *set, 1196 linemap_location_in_system_header_p (line_maps *set,
1189 source_location location) 1197 location_t location)
1190 { 1198 {
1191 const struct line_map *map = NULL; 1199 const struct line_map *map = NULL;
1192 1200
1193 if (IS_ADHOC_LOC (location)) 1201 if (IS_ADHOC_LOC (location))
1194 location = set->location_adhoc_data_map.data[location 1202 location = get_location_from_adhoc_loc (set, location);
1195 & MAX_SOURCE_LOCATION].locus;
1196 1203
1197 if (location < RESERVED_LOCATION_COUNT) 1204 if (location < RESERVED_LOCATION_COUNT)
1198 return false; 1205 return false;
1199 1206
1200 /* Let's look at where the token for LOCATION comes from. */ 1207 /* Let's look at where the token for LOCATION comes from. */
1209 else 1216 else
1210 { 1217 {
1211 const line_map_macro *macro_map = linemap_check_macro (map); 1218 const line_map_macro *macro_map = linemap_check_macro (map);
1212 1219
1213 /* It's a token resulting from a macro expansion. */ 1220 /* It's a token resulting from a macro expansion. */
1214 source_location loc = 1221 location_t loc =
1215 linemap_macro_map_loc_unwind_toward_spelling (set, macro_map, location); 1222 linemap_macro_map_loc_unwind_toward_spelling (set, macro_map, location);
1216 if (loc < RESERVED_LOCATION_COUNT) 1223 if (loc < RESERVED_LOCATION_COUNT)
1217 /* This token might come from a built-in macro. Let's 1224 /* This token might come from a built-in macro. Let's
1218 look at where that macro got expanded. */ 1225 look at where that macro got expanded. */
1219 location = linemap_macro_map_loc_to_exp_point (macro_map, location); 1226 location = linemap_macro_map_loc_to_exp_point (macro_map, location);
1229 1236
1230 /* Return TRUE if LOCATION is a source code location of a token that is part of 1237 /* Return TRUE if LOCATION is a source code location of a token that is part of
1231 a macro expansion, FALSE otherwise. */ 1238 a macro expansion, FALSE otherwise. */
1232 1239
1233 bool 1240 bool
1234 linemap_location_from_macro_expansion_p (const struct line_maps *set, 1241 linemap_location_from_macro_expansion_p (const class line_maps *set,
1235 source_location location) 1242 location_t location)
1236 { 1243 {
1237 if (IS_ADHOC_LOC (location)) 1244 if (IS_ADHOC_LOC (location))
1238 location = set->location_adhoc_data_map.data[location 1245 location = get_location_from_adhoc_loc (set, location);
1239 & MAX_SOURCE_LOCATION].locus; 1246
1240 1247 return IS_MACRO_LOC (location);
1241 return location >= LINE_MAP_MAX_LOCATION;
1242 } 1248 }
1243 1249
1244 /* Given two virtual locations *LOC0 and *LOC1, return the first 1250 /* Given two virtual locations *LOC0 and *LOC1, return the first
1245 common macro map in their macro expansion histories. Return NULL 1251 common macro map in their macro expansion histories. Return NULL
1246 if no common macro was found. *LOC0 (resp. *LOC1) is set to the 1252 if no common macro was found. *LOC0 (resp. *LOC1) is set to the
1247 virtual location of the token inside the resulting macro. */ 1253 virtual location of the token inside the resulting macro. */
1248 1254
1249 static const struct line_map* 1255 static const struct line_map*
1250 first_map_in_common_1 (struct line_maps *set, 1256 first_map_in_common_1 (line_maps *set,
1251 source_location *loc0, 1257 location_t *loc0,
1252 source_location *loc1) 1258 location_t *loc1)
1253 { 1259 {
1254 source_location l0 = *loc0, l1 = *loc1; 1260 location_t l0 = *loc0, l1 = *loc1;
1255 const struct line_map *map0 = linemap_lookup (set, l0), 1261 const struct line_map *map0 = linemap_lookup (set, l0);
1256 *map1 = linemap_lookup (set, l1); 1262 if (IS_ADHOC_LOC (l0))
1263 l0 = get_location_from_adhoc_loc (set, l0);
1264
1265 const struct line_map *map1 = linemap_lookup (set, l1);
1266 if (IS_ADHOC_LOC (l1))
1267 l1 = get_location_from_adhoc_loc (set, l1);
1257 1268
1258 while (linemap_macro_expansion_map_p (map0) 1269 while (linemap_macro_expansion_map_p (map0)
1259 && linemap_macro_expansion_map_p (map1) 1270 && linemap_macro_expansion_map_p (map1)
1260 && (map0 != map1)) 1271 && (map0 != map1))
1261 { 1272 {
1287 common macro was found. *RES_LOC0 (resp. *RES_LOC1) is set to the 1298 common macro was found. *RES_LOC0 (resp. *RES_LOC1) is set to the
1288 virtual location of the token inside the resulting macro, upon 1299 virtual location of the token inside the resulting macro, upon
1289 return of a non-NULL result. */ 1300 return of a non-NULL result. */
1290 1301
1291 static const struct line_map* 1302 static const struct line_map*
1292 first_map_in_common (struct line_maps *set, 1303 first_map_in_common (line_maps *set,
1293 source_location loc0, 1304 location_t loc0,
1294 source_location loc1, 1305 location_t loc1,
1295 source_location *res_loc0, 1306 location_t *res_loc0,
1296 source_location *res_loc1) 1307 location_t *res_loc1)
1297 { 1308 {
1298 *res_loc0 = loc0; 1309 *res_loc0 = loc0;
1299 *res_loc1 = loc1; 1310 *res_loc1 = loc1;
1300 1311
1301 return first_map_in_common_1 (set, res_loc0, res_loc1); 1312 return first_map_in_common_1 (set, res_loc0, res_loc1);
1305 comes before the token of POST, 0 if PRE denotes the location of 1316 comes before the token of POST, 0 if PRE denotes the location of
1306 the same token as the token for POST, and a negative value 1317 the same token as the token for POST, and a negative value
1307 otherwise. */ 1318 otherwise. */
1308 1319
1309 int 1320 int
1310 linemap_compare_locations (struct line_maps *set, 1321 linemap_compare_locations (line_maps *set,
1311 source_location pre, 1322 location_t pre,
1312 source_location post) 1323 location_t post)
1313 { 1324 {
1314 bool pre_virtual_p, post_virtual_p; 1325 bool pre_virtual_p, post_virtual_p;
1315 source_location l0 = pre, l1 = post; 1326 location_t l0 = pre, l1 = post;
1316 1327
1317 if (IS_ADHOC_LOC (l0)) 1328 if (IS_ADHOC_LOC (l0))
1318 l0 = get_location_from_adhoc_loc (set, l0); 1329 l0 = get_location_from_adhoc_loc (set, l0);
1319 if (IS_ADHOC_LOC (l1)) 1330 if (IS_ADHOC_LOC (l1))
1320 l1 = get_location_from_adhoc_loc (set, l1); 1331 l1 = get_location_from_adhoc_loc (set, l1);
1361 } 1372 }
1362 1373
1363 /* Print an include trace, for e.g. the -H option of the preprocessor. */ 1374 /* Print an include trace, for e.g. the -H option of the preprocessor. */
1364 1375
1365 static void 1376 static void
1366 trace_include (const struct line_maps *set, const line_map_ordinary *map) 1377 trace_include (const class line_maps *set, const line_map_ordinary *map)
1367 { 1378 {
1368 unsigned int i = set->depth; 1379 unsigned int i = set->depth;
1369 1380
1370 while (--i) 1381 while (--i)
1371 putc ('.', stderr); 1382 putc ('.', stderr);
1376 /* Return the spelling location of the token wherever it comes from, 1387 /* Return the spelling location of the token wherever it comes from,
1377 whether part of a macro definition or not. 1388 whether part of a macro definition or not.
1378 1389
1379 This is a subroutine for linemap_resolve_location. */ 1390 This is a subroutine for linemap_resolve_location. */
1380 1391
1381 static source_location 1392 static location_t
1382 linemap_macro_loc_to_spelling_point (struct line_maps *set, 1393 linemap_macro_loc_to_spelling_point (line_maps *set,
1383 source_location location, 1394 location_t location,
1384 const line_map_ordinary **original_map) 1395 const line_map_ordinary **original_map)
1385 { 1396 {
1386 linemap_assert (set && location >= RESERVED_LOCATION_COUNT); 1397 linemap_assert (set && location >= RESERVED_LOCATION_COUNT);
1387 1398
1388 while (true) 1399 while (true)
1410 the function sets *ORIGINAL_MAP to the ordinary (non-macro) map the 1421 the function sets *ORIGINAL_MAP to the ordinary (non-macro) map the
1411 returned location comes from. 1422 returned location comes from.
1412 1423
1413 This is a subroutine of linemap_resolve_location. */ 1424 This is a subroutine of linemap_resolve_location. */
1414 1425
1415 static source_location 1426 static location_t
1416 linemap_macro_loc_to_def_point (struct line_maps *set, 1427 linemap_macro_loc_to_def_point (line_maps *set,
1417 source_location location, 1428 location_t location,
1418 const line_map_ordinary **original_map) 1429 const line_map_ordinary **original_map)
1419 { 1430 {
1420 linemap_assert (set && location >= RESERVED_LOCATION_COUNT); 1431 linemap_assert (set && location >= RESERVED_LOCATION_COUNT);
1421 1432
1422 for (;;) 1433 for (;;)
1423 { 1434 {
1424 source_location caret_loc = location; 1435 location_t caret_loc = location;
1425 if (IS_ADHOC_LOC (caret_loc)) 1436 if (IS_ADHOC_LOC (caret_loc))
1426 caret_loc = get_location_from_adhoc_loc (set, caret_loc); 1437 caret_loc = get_location_from_adhoc_loc (set, caret_loc);
1427 1438
1428 const line_map *map = linemap_lookup (set, caret_loc); 1439 const line_map *map = linemap_lookup (set, caret_loc);
1429 if (!map || MAP_ORDINARY_P (map)) 1440 if (!map || MAP_ORDINARY_P (map))
1452 sets *ORIGINAL_MAP to the ordinary (non-macro) map the returned 1463 sets *ORIGINAL_MAP to the ordinary (non-macro) map the returned
1453 location comes from. 1464 location comes from.
1454 1465
1455 This is a subroutine of linemap_resolve_location. */ 1466 This is a subroutine of linemap_resolve_location. */
1456 1467
1457 static source_location 1468 static location_t
1458 linemap_macro_loc_to_exp_point (struct line_maps *set, 1469 linemap_macro_loc_to_exp_point (line_maps *set,
1459 source_location location, 1470 location_t location,
1460 const line_map_ordinary **original_map) 1471 const line_map_ordinary **original_map)
1461 { 1472 {
1462 struct line_map *map; 1473 struct line_map *map;
1463 1474
1464 if (IS_ADHOC_LOC (location)) 1475 if (IS_ADHOC_LOC (location))
1465 location = set->location_adhoc_data_map.data[location 1476 location = get_location_from_adhoc_loc (set, location);
1466 & MAX_SOURCE_LOCATION].locus;
1467 1477
1468 linemap_assert (set && location >= RESERVED_LOCATION_COUNT); 1478 linemap_assert (set && location >= RESERVED_LOCATION_COUNT);
1469 1479
1470 while (true) 1480 while (true)
1471 { 1481 {
1527 returned location. Note that if the returned location wasn't originally 1537 returned location. Note that if the returned location wasn't originally
1528 encoded by a map, then *MAP is set to NULL. This can happen if LOC 1538 encoded by a map, then *MAP is set to NULL. This can happen if LOC
1529 resolves to a location reserved for the client code, like 1539 resolves to a location reserved for the client code, like
1530 UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC. */ 1540 UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC. */
1531 1541
1532 source_location 1542 location_t
1533 linemap_resolve_location (struct line_maps *set, 1543 linemap_resolve_location (line_maps *set,
1534 source_location loc, 1544 location_t loc,
1535 enum location_resolution_kind lrk, 1545 enum location_resolution_kind lrk,
1536 const line_map_ordinary **map) 1546 const line_map_ordinary **map)
1537 { 1547 {
1538 source_location locus = loc; 1548 location_t locus = loc;
1539 if (IS_ADHOC_LOC (loc)) 1549 if (IS_ADHOC_LOC (loc))
1540 locus = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; 1550 locus = get_location_from_adhoc_loc (set, loc);
1541 1551
1542 if (locus < RESERVED_LOCATION_COUNT) 1552 if (locus < RESERVED_LOCATION_COUNT)
1543 { 1553 {
1544 /* A reserved location wasn't encoded in a map. Let's return a 1554 /* A reserved location wasn't encoded in a map. Let's return a
1545 NULL map here, just like what linemap_ordinary_map_lookup 1555 NULL map here, just like what linemap_ordinary_map_lookup
1568 1578
1569 /* TRUE if LOCATION is a source code location of a token that is part of the 1579 /* TRUE if LOCATION is a source code location of a token that is part of the
1570 definition of a macro, FALSE otherwise. */ 1580 definition of a macro, FALSE otherwise. */
1571 1581
1572 bool 1582 bool
1573 linemap_location_from_macro_definition_p (struct line_maps *set, 1583 linemap_location_from_macro_definition_p (line_maps *set,
1574 source_location loc) 1584 location_t loc)
1575 { 1585 {
1576 if (IS_ADHOC_LOC (loc)) 1586 if (IS_ADHOC_LOC (loc))
1577 loc = get_location_from_adhoc_loc (set, loc); 1587 loc = get_location_from_adhoc_loc (set, loc);
1578 1588
1579 if (!linemap_location_from_macro_expansion_p (set, loc)) 1589 if (!linemap_location_from_macro_expansion_p (set, loc))
1582 while (true) 1592 while (true)
1583 { 1593 {
1584 const struct line_map_macro *map 1594 const struct line_map_macro *map
1585 = linemap_check_macro (linemap_lookup (set, loc)); 1595 = linemap_check_macro (linemap_lookup (set, loc));
1586 1596
1587 source_location s_loc 1597 location_t s_loc
1588 = linemap_macro_map_loc_unwind_toward_spelling (set, map, loc); 1598 = linemap_macro_map_loc_unwind_toward_spelling (set, map, loc);
1589 if (linemap_location_from_macro_expansion_p (set, s_loc)) 1599 if (linemap_location_from_macro_expansion_p (set, s_loc))
1590 loc = s_loc; 1600 loc = s_loc;
1591 else 1601 else
1592 { 1602 {
1593 source_location def_loc 1603 location_t def_loc
1594 = linemap_macro_map_loc_to_def_point (map, loc); 1604 = linemap_macro_map_loc_to_def_point (map, loc);
1595 return s_loc == def_loc; 1605 return s_loc == def_loc;
1596 } 1606 }
1597 } 1607 }
1598 } 1608 }
1607 the expansion of M. 1617 the expansion of M.
1608 1618
1609 *LOC_MAP must be set to the map of LOC. This function then sets it 1619 *LOC_MAP must be set to the map of LOC. This function then sets it
1610 to the map of the returned location. */ 1620 to the map of the returned location. */
1611 1621
1612 source_location 1622 location_t
1613 linemap_unwind_toward_expansion (struct line_maps *set, 1623 linemap_unwind_toward_expansion (line_maps *set,
1614 source_location loc, 1624 location_t loc,
1615 const struct line_map **map) 1625 const struct line_map **map)
1616 { 1626 {
1617 source_location resolved_location; 1627 location_t resolved_location;
1618 const line_map_macro *macro_map = linemap_check_macro (*map); 1628 const line_map_macro *macro_map = linemap_check_macro (*map);
1619 const struct line_map *resolved_map; 1629 const struct line_map *resolved_map;
1620 1630
1621 if (IS_ADHOC_LOC (loc)) 1631 if (IS_ADHOC_LOC (loc))
1622 loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; 1632 loc = get_location_from_adhoc_loc (set, loc);
1623 1633
1624 resolved_location = 1634 resolved_location =
1625 linemap_macro_map_loc_unwind_toward_spelling (set, macro_map, loc); 1635 linemap_macro_map_loc_unwind_toward_spelling (set, macro_map, loc);
1626 resolved_map = linemap_lookup (set, resolved_location); 1636 resolved_map = linemap_lookup (set, resolved_location);
1627 1637
1647 LOC doesn't come from the expansion of a macro, the function 1657 LOC doesn't come from the expansion of a macro, the function
1648 returns LOC as is and *MAP is not touched. 1658 returns LOC as is and *MAP is not touched.
1649 1659
1650 *MAP is set to the map of the returned location if the later is 1660 *MAP is set to the map of the returned location if the later is
1651 different from LOC. */ 1661 different from LOC. */
1652 source_location 1662 location_t
1653 linemap_unwind_to_first_non_reserved_loc (struct line_maps *set, 1663 linemap_unwind_to_first_non_reserved_loc (line_maps *set,
1654 source_location loc, 1664 location_t loc,
1655 const struct line_map **map) 1665 const struct line_map **map)
1656 { 1666 {
1657 source_location resolved_loc; 1667 location_t resolved_loc;
1658 const struct line_map *map0 = NULL; 1668 const struct line_map *map0 = NULL;
1659 const line_map_ordinary *map1 = NULL; 1669 const line_map_ordinary *map1 = NULL;
1660 1670
1661 if (IS_ADHOC_LOC (loc)) 1671 if (IS_ADHOC_LOC (loc))
1662 loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; 1672 loc = get_location_from_adhoc_loc (set, loc);
1663 1673
1664 map0 = linemap_lookup (set, loc); 1674 map0 = linemap_lookup (set, loc);
1665 if (!linemap_macro_expansion_map_p (map0)) 1675 if (!linemap_macro_expansion_map_p (map0))
1666 return loc; 1676 return loc;
1667 1677
1692 code location. LOC must be a spelling (non-virtual) location. If 1702 code location. LOC must be a spelling (non-virtual) location. If
1693 it's a location < RESERVED_LOCATION_COUNT a zeroed expanded source 1703 it's a location < RESERVED_LOCATION_COUNT a zeroed expanded source
1694 location is returned. */ 1704 location is returned. */
1695 1705
1696 expanded_location 1706 expanded_location
1697 linemap_expand_location (struct line_maps *set, 1707 linemap_expand_location (line_maps *set,
1698 const struct line_map *map, 1708 const struct line_map *map,
1699 source_location loc) 1709 location_t loc)
1700 1710
1701 { 1711 {
1702 expanded_location xloc; 1712 expanded_location xloc;
1703 1713
1704 memset (&xloc, 0, sizeof (xloc)); 1714 memset (&xloc, 0, sizeof (xloc));
1705 if (IS_ADHOC_LOC (loc)) 1715 if (IS_ADHOC_LOC (loc))
1706 { 1716 {
1707 xloc.data 1717 xloc.data = get_data_from_adhoc_loc (set, loc);
1708 = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].data; 1718 loc = get_location_from_adhoc_loc (set, loc);
1709 loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus;
1710 } 1719 }
1711 1720
1712 if (loc < RESERVED_LOCATION_COUNT) 1721 if (loc < RESERVED_LOCATION_COUNT)
1713 /* The location for this token wasn't generated from a line map. 1722 /* The location for this token wasn't generated from a line map.
1714 It was probably a location for a builtin token, chosen by some 1723 It was probably a location for a builtin token, chosen by some
1742 /* Dump line map at index IX in line table SET to STREAM. If STREAM 1751 /* Dump line map at index IX in line table SET to STREAM. If STREAM
1743 is NULL, use stderr. IS_MACRO is true if the caller wants to 1752 is NULL, use stderr. IS_MACRO is true if the caller wants to
1744 dump a macro map, false otherwise. */ 1753 dump a macro map, false otherwise. */
1745 1754
1746 void 1755 void
1747 linemap_dump (FILE *stream, struct line_maps *set, unsigned ix, bool is_macro) 1756 linemap_dump (FILE *stream, class line_maps *set, unsigned ix, bool is_macro)
1748 { 1757 {
1749 const char *const lc_reasons_v[LC_HWM] 1758 const char *const lc_reasons_v[LC_HWM]
1750 = { "LC_ENTER", "LC_LEAVE", "LC_RENAME", "LC_RENAME_VERBATIM", 1759 = { "LC_ENTER", "LC_LEAVE", "LC_RENAME", "LC_RENAME_VERBATIM",
1751 "LC_ENTER_MACRO" }; 1760 "LC_ENTER_MACRO" };
1752 const line_map *map; 1761 const line_map *map;
1798 1807
1799 /* Dump debugging information about source location LOC into the file 1808 /* Dump debugging information about source location LOC into the file
1800 stream STREAM. SET is the line map set LOC comes from. */ 1809 stream STREAM. SET is the line map set LOC comes from. */
1801 1810
1802 void 1811 void
1803 linemap_dump_location (struct line_maps *set, 1812 linemap_dump_location (line_maps *set,
1804 source_location loc, 1813 location_t loc,
1805 FILE *stream) 1814 FILE *stream)
1806 { 1815 {
1807 const line_map_ordinary *map; 1816 const line_map_ordinary *map;
1808 source_location location; 1817 location_t location;
1809 const char *path = "", *from = ""; 1818 const char *path = "", *from = "";
1810 int l = -1, c = -1, s = -1, e = -1; 1819 int l = -1, c = -1, s = -1, e = -1;
1811 1820
1812 if (IS_ADHOC_LOC (loc)) 1821 if (IS_ADHOC_LOC (loc))
1813 loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; 1822 loc = get_location_from_adhoc_loc (set, loc);
1814 1823
1815 if (loc == 0) 1824 if (loc == 0)
1816 return; 1825 return;
1817 1826
1818 location = 1827 location =
1848 there is a line map in SET. FILE_NAME is the file name to 1857 there is a line map in SET. FILE_NAME is the file name to
1849 consider. If the function returns TRUE, *LOC is set to the highest 1858 consider. If the function returns TRUE, *LOC is set to the highest
1850 location emitted for that file. */ 1859 location emitted for that file. */
1851 1860
1852 bool 1861 bool
1853 linemap_get_file_highest_location (struct line_maps *set, 1862 linemap_get_file_highest_location (line_maps *set,
1854 const char *file_name, 1863 const char *file_name,
1855 source_location *loc) 1864 location_t *loc)
1856 { 1865 {
1857 /* If the set is empty or no ordinary map has been created then 1866 /* If the set is empty or no ordinary map has been created then
1858 there is no file to look for ... */ 1867 there is no file to look for ... */
1859 if (set == NULL || set->info_ordinary.used == 0) 1868 if (set == NULL || set->info_ordinary.used == 0)
1860 return false; 1869 return false;
1872 return false; 1881 return false;
1873 1882
1874 /* The highest location for a given map is either the starting 1883 /* The highest location for a given map is either the starting
1875 location of the next map minus one, or -- if the map is the 1884 location of the next map minus one, or -- if the map is the
1876 latest one -- the highest location of the set. */ 1885 latest one -- the highest location of the set. */
1877 source_location result; 1886 location_t result;
1878 if (i == (int) set->info_ordinary.used - 1) 1887 if (i == (int) set->info_ordinary.used - 1)
1879 result = set->highest_location; 1888 result = set->highest_location;
1880 else 1889 else
1881 result = set->info_ordinary.maps[i + 1].start_location - 1; 1890 result = set->info_ordinary.maps[i + 1].start_location - 1;
1882 1891
1886 1895
1887 /* Compute and return statistics about the memory consumption of some 1896 /* Compute and return statistics about the memory consumption of some
1888 parts of the line table SET. */ 1897 parts of the line table SET. */
1889 1898
1890 void 1899 void
1891 linemap_get_statistics (struct line_maps *set, 1900 linemap_get_statistics (line_maps *set,
1892 struct linemap_stats *s) 1901 struct linemap_stats *s)
1893 { 1902 {
1894 long ordinary_maps_allocated_size, ordinary_maps_used_size, 1903 long ordinary_maps_allocated_size, ordinary_maps_used_size,
1895 macro_maps_allocated_size, macro_maps_used_size, 1904 macro_maps_allocated_size, macro_maps_used_size,
1896 macro_maps_locations_size = 0, duplicated_macro_maps_locations_size = 0; 1905 macro_maps_locations_size = 0, duplicated_macro_maps_locations_size = 0;
1913 unsigned i; 1922 unsigned i;
1914 1923
1915 linemap_assert (linemap_macro_expansion_map_p (cur_map)); 1924 linemap_assert (linemap_macro_expansion_map_p (cur_map));
1916 1925
1917 macro_maps_locations_size += 1926 macro_maps_locations_size +=
1918 2 * MACRO_MAP_NUM_MACRO_TOKENS (cur_map) * sizeof (source_location); 1927 2 * MACRO_MAP_NUM_MACRO_TOKENS (cur_map) * sizeof (location_t);
1919 1928
1920 for (i = 0; i < 2 * MACRO_MAP_NUM_MACRO_TOKENS (cur_map); i += 2) 1929 for (i = 0; i < 2 * MACRO_MAP_NUM_MACRO_TOKENS (cur_map); i += 2)
1921 { 1930 {
1922 if (MACRO_MAP_LOCATIONS (cur_map)[i] == 1931 if (MACRO_MAP_LOCATIONS (cur_map)[i] ==
1923 MACRO_MAP_LOCATIONS (cur_map)[i + 1]) 1932 MACRO_MAP_LOCATIONS (cur_map)[i + 1])
1924 duplicated_macro_maps_locations_size += 1933 duplicated_macro_maps_locations_size +=
1925 sizeof (source_location); 1934 sizeof (location_t);
1926 } 1935 }
1927 } 1936 }
1928 1937
1929 macro_maps_used_size = 1938 macro_maps_used_size =
1930 LINEMAPS_MACRO_USED (set) * sizeof (struct line_map_macro); 1939 LINEMAPS_MACRO_USED (set) * sizeof (struct line_map_macro);
1950 /* Dump line table SET to STREAM. If STREAM is NULL, stderr is used. 1959 /* Dump line table SET to STREAM. If STREAM is NULL, stderr is used.
1951 NUM_ORDINARY specifies how many ordinary maps to dump. NUM_MACRO 1960 NUM_ORDINARY specifies how many ordinary maps to dump. NUM_MACRO
1952 specifies how many macro maps to dump. */ 1961 specifies how many macro maps to dump. */
1953 1962
1954 void 1963 void
1955 line_table_dump (FILE *stream, struct line_maps *set, unsigned int num_ordinary, 1964 line_table_dump (FILE *stream, class line_maps *set, unsigned int num_ordinary,
1956 unsigned int num_macro) 1965 unsigned int num_macro)
1957 { 1966 {
1958 unsigned int i; 1967 unsigned int i;
1959 1968
1960 if (set == NULL) 1969 if (set == NULL)
1987 1996
1988 /* class rich_location. */ 1997 /* class rich_location. */
1989 1998
1990 /* Construct a rich_location with location LOC as its initial range. */ 1999 /* Construct a rich_location with location LOC as its initial range. */
1991 2000
1992 rich_location::rich_location (line_maps *set, source_location loc, 2001 rich_location::rich_location (line_maps *set, location_t loc,
1993 const range_label *label) : 2002 const range_label *label) :
1994 m_line_table (set), 2003 m_line_table (set),
1995 m_ranges (), 2004 m_ranges (),
1996 m_column_override (0), 2005 m_column_override (0),
1997 m_have_expanded_location (false), 2006 m_have_expanded_location (false),
1998 m_fixit_hints (), 2007 m_fixit_hints (),
1999 m_seen_impossible_fixit (false), 2008 m_seen_impossible_fixit (false),
2000 m_fixits_cannot_be_auto_applied (false) 2009 m_fixits_cannot_be_auto_applied (false),
2010 m_path (NULL)
2001 { 2011 {
2002 add_range (loc, SHOW_RANGE_WITH_CARET, label); 2012 add_range (loc, SHOW_RANGE_WITH_CARET, label);
2003 } 2013 }
2004 2014
2005 /* The destructor for class rich_location. */ 2015 /* The destructor for class rich_location. */
2010 delete get_fixit_hint (i); 2020 delete get_fixit_hint (i);
2011 } 2021 }
2012 2022
2013 /* Get location IDX within this rich_location. */ 2023 /* Get location IDX within this rich_location. */
2014 2024
2015 source_location 2025 location_t
2016 rich_location::get_loc (unsigned int idx) const 2026 rich_location::get_loc (unsigned int idx) const
2017 { 2027 {
2018 const location_range *locrange = get_range (idx); 2028 const location_range *locrange = get_range (idx);
2019 return locrange->m_loc; 2029 return locrange->m_loc;
2020 } 2030 }
2073 } 2083 }
2074 2084
2075 /* Add the given range. */ 2085 /* Add the given range. */
2076 2086
2077 void 2087 void
2078 rich_location::add_range (source_location loc, 2088 rich_location::add_range (location_t loc,
2079 enum range_display_kind range_display_kind, 2089 enum range_display_kind range_display_kind,
2080 const range_label *label) 2090 const range_label *label)
2081 { 2091 {
2082 location_range range; 2092 location_range range;
2083 range.m_loc = loc; 2093 range.m_loc = loc;
2098 (which writes the source location of a tree back into location 0 of 2108 (which writes the source location of a tree back into location 0 of
2099 the rich_location), and 2109 the rich_location), and
2100 - the "%C" and "%L" format codes in the Fortran frontend. */ 2110 - the "%C" and "%L" format codes in the Fortran frontend. */
2101 2111
2102 void 2112 void
2103 rich_location::set_range (unsigned int idx, source_location loc, 2113 rich_location::set_range (unsigned int idx, location_t loc,
2104 enum range_display_kind range_display_kind) 2114 enum range_display_kind range_display_kind)
2105 { 2115 {
2106 /* We can either overwrite an existing range, or add one exactly 2116 /* We can either overwrite an existing range, or add one exactly
2107 on the end of the array. */ 2117 on the end of the array. */
2108 linemap_assert (idx <= m_ranges.count ()); 2118 linemap_assert (idx <= m_ranges.count ());
2134 2144
2135 /* Add a fixit-hint, suggesting insertion of NEW_CONTENT 2145 /* Add a fixit-hint, suggesting insertion of NEW_CONTENT
2136 immediately before the start of WHERE. */ 2146 immediately before the start of WHERE. */
2137 2147
2138 void 2148 void
2139 rich_location::add_fixit_insert_before (source_location where, 2149 rich_location::add_fixit_insert_before (location_t where,
2140 const char *new_content) 2150 const char *new_content)
2141 { 2151 {
2142 source_location start = get_range_from_loc (m_line_table, where).m_start; 2152 location_t start = get_range_from_loc (m_line_table, where).m_start;
2143 maybe_add_fixit (start, start, new_content); 2153 maybe_add_fixit (start, start, new_content);
2144 } 2154 }
2145 2155
2146 /* Add a fixit-hint, suggesting insertion of NEW_CONTENT 2156 /* Add a fixit-hint, suggesting insertion of NEW_CONTENT
2147 immediately after the primary range's end-point. */ 2157 immediately after the primary range's end-point. */
2154 2164
2155 /* Add a fixit-hint, suggesting insertion of NEW_CONTENT 2165 /* Add a fixit-hint, suggesting insertion of NEW_CONTENT
2156 immediately after the end-point of WHERE. */ 2166 immediately after the end-point of WHERE. */
2157 2167
2158 void 2168 void
2159 rich_location::add_fixit_insert_after (source_location where, 2169 rich_location::add_fixit_insert_after (location_t where,
2160 const char *new_content) 2170 const char *new_content)
2161 { 2171 {
2162 source_location finish = get_range_from_loc (m_line_table, where).m_finish; 2172 location_t finish = get_range_from_loc (m_line_table, where).m_finish;
2163 source_location next_loc 2173 location_t next_loc
2164 = linemap_position_for_loc_and_offset (m_line_table, finish, 1); 2174 = linemap_position_for_loc_and_offset (m_line_table, finish, 1);
2165 2175
2166 /* linemap_position_for_loc_and_offset can fail, if so, it returns 2176 /* linemap_position_for_loc_and_offset can fail, if so, it returns
2167 its input value. */ 2177 its input value. */
2168 if (next_loc == finish) 2178 if (next_loc == finish)
2187 2197
2188 /* Add a fixit-hint, suggesting removal of the content between 2198 /* Add a fixit-hint, suggesting removal of the content between
2189 the start and finish of WHERE. */ 2199 the start and finish of WHERE. */
2190 2200
2191 void 2201 void
2192 rich_location::add_fixit_remove (source_location where) 2202 rich_location::add_fixit_remove (location_t where)
2193 { 2203 {
2194 source_range range = get_range_from_loc (m_line_table, where); 2204 source_range range = get_range_from_loc (m_line_table, where);
2195 add_fixit_remove (range); 2205 add_fixit_remove (range);
2196 } 2206 }
2197 2207
2217 2227
2218 /* Add a fixit-hint, suggesting replacement of the content between 2228 /* Add a fixit-hint, suggesting replacement of the content between
2219 the start and finish of WHERE with NEW_CONTENT. */ 2229 the start and finish of WHERE with NEW_CONTENT. */
2220 2230
2221 void 2231 void
2222 rich_location::add_fixit_replace (source_location where, 2232 rich_location::add_fixit_replace (location_t where,
2223 const char *new_content) 2233 const char *new_content)
2224 { 2234 {
2225 source_range range = get_range_from_loc (m_line_table, where); 2235 source_range range = get_range_from_loc (m_line_table, where);
2226 add_fixit_replace (range, new_content); 2236 add_fixit_replace (range, new_content);
2227 } 2237 }
2231 2241
2232 void 2242 void
2233 rich_location::add_fixit_replace (source_range src_range, 2243 rich_location::add_fixit_replace (source_range src_range,
2234 const char *new_content) 2244 const char *new_content)
2235 { 2245 {
2236 source_location start = get_pure_location (m_line_table, src_range.m_start); 2246 location_t start = get_pure_location (m_line_table, src_range.m_start);
2237 source_location finish = get_pure_location (m_line_table, src_range.m_finish); 2247 location_t finish = get_pure_location (m_line_table, src_range.m_finish);
2238 2248
2239 /* Fix-it hints use half-closed ranges, so attempt to offset the endpoint. */ 2249 /* Fix-it hints use half-closed ranges, so attempt to offset the endpoint. */
2240 source_location next_loc 2250 location_t next_loc
2241 = linemap_position_for_loc_and_offset (m_line_table, finish, 1); 2251 = linemap_position_for_loc_and_offset (m_line_table, finish, 1);
2242 /* linemap_position_for_loc_and_offset can fail, if so, it returns 2252 /* linemap_position_for_loc_and_offset can fail, if so, it returns
2243 its input value. */ 2253 its input value. */
2244 if (next_loc == finish) 2254 if (next_loc == finish)
2245 { 2255 {
2266 supporting fixits, purging any thay were already added, and return true. 2276 supporting fixits, purging any thay were already added, and return true.
2267 2277
2268 Otherwise (the common case), return false. */ 2278 Otherwise (the common case), return false. */
2269 2279
2270 bool 2280 bool
2271 rich_location::reject_impossible_fixit (source_location where) 2281 rich_location::reject_impossible_fixit (location_t where)
2272 { 2282 {
2273 /* Fix-its within a rich_location should either all be suggested, or 2283 /* Fix-its within a rich_location should either all be suggested, or
2274 none of them should be suggested. 2284 none of them should be suggested.
2275 Once we've rejected a fixit, we reject any more, even those 2285 Once we've rejected a fixit, we reject any more, even those
2276 with reasonable locations. */ 2286 with reasonable locations. */
2304 2314
2305 /* Add HINT to the fix-it hints in this rich_location, 2315 /* Add HINT to the fix-it hints in this rich_location,
2306 consolidating into the prior fixit if possible. */ 2316 consolidating into the prior fixit if possible. */
2307 2317
2308 void 2318 void
2309 rich_location::maybe_add_fixit (source_location start, 2319 rich_location::maybe_add_fixit (location_t start,
2310 source_location next_loc, 2320 location_t next_loc,
2311 const char *new_content) 2321 const char *new_content)
2312 { 2322 {
2313 if (reject_impossible_fixit (start)) 2323 if (reject_impossible_fixit (start))
2314 return; 2324 return;
2315 if (reject_impossible_fixit (next_loc)) 2325 if (reject_impossible_fixit (next_loc))
2386 m_fixit_hints.push (new fixit_hint (start, next_loc, new_content)); 2396 m_fixit_hints.push (new fixit_hint (start, next_loc, new_content));
2387 } 2397 }
2388 2398
2389 /* class fixit_hint. */ 2399 /* class fixit_hint. */
2390 2400
2391 fixit_hint::fixit_hint (source_location start, 2401 fixit_hint::fixit_hint (location_t start,
2392 source_location next_loc, 2402 location_t next_loc,
2393 const char *new_content) 2403 const char *new_content)
2394 : m_start (start), 2404 : m_start (start),
2395 m_next_loc (next_loc), 2405 m_next_loc (next_loc),
2396 m_bytes (xstrdup (new_content)), 2406 m_bytes (xstrdup (new_content)),
2397 m_len (strlen (new_content)) 2407 m_len (strlen (new_content))
2425 If possible, merge a pending fix-it hint with the given params 2435 If possible, merge a pending fix-it hint with the given params
2426 into this one and return true. 2436 into this one and return true.
2427 Otherwise return false. */ 2437 Otherwise return false. */
2428 2438
2429 bool 2439 bool
2430 fixit_hint::maybe_append (source_location start, 2440 fixit_hint::maybe_append (location_t start,
2431 source_location next_loc, 2441 location_t next_loc,
2432 const char *new_content) 2442 const char *new_content)
2433 { 2443 {
2434 /* For consolidation to be possible, START must be at this hint's 2444 /* For consolidation to be possible, START must be at this hint's
2435 m_next_loc. */ 2445 m_next_loc. */
2436 if (start != m_next_loc) 2446 if (start != m_next_loc)