Mercurial > hg > CbC > CbC_gcc
comparison libcpp/include/line-map.h @ 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. |
47 i.e. "3:1:" in GCC corresponds to "(3, 0)" in Emacs. */ | 47 i.e. "3:1:" in GCC corresponds to "(3, 0)" in Emacs. */ |
48 | 48 |
49 /* The type of line numbers. */ | 49 /* The type of line numbers. */ |
50 typedef unsigned int linenum_type; | 50 typedef unsigned int linenum_type; |
51 | 51 |
52 /* A type for doing arithmetic on line numbers. */ | |
53 typedef long long linenum_arith_t; | |
54 | |
52 /* A function for for use by qsort for comparing line numbers. */ | 55 /* A function for for use by qsort for comparing line numbers. */ |
53 | 56 |
54 inline int compare (linenum_type lhs, linenum_type rhs) | 57 inline int compare (linenum_type lhs, linenum_type rhs) |
55 { | 58 { |
56 /* Avoid truncation issues by using long long for the comparison, | 59 /* Avoid truncation issues by using linenum_arith_t for the comparison, |
57 and only consider the sign of the result. */ | 60 and only consider the sign of the result. */ |
58 long long diff = (long long)lhs - (long long)rhs; | 61 linenum_arith_t diff = (linenum_arith_t)lhs - (linenum_arith_t)rhs; |
59 if (diff) | 62 if (diff) |
60 return diff > 0 ? 1 : -1; | 63 return diff > 0 ? 1 : -1; |
61 return 0; | 64 return 0; |
62 } | 65 } |
63 | 66 |
71 LC_ENTER_MACRO, /* Begin macro expansion. */ | 74 LC_ENTER_MACRO, /* Begin macro expansion. */ |
72 /* FIXME: add support for stringize and paste. */ | 75 /* FIXME: add support for stringize and paste. */ |
73 LC_HWM /* High Water Mark. */ | 76 LC_HWM /* High Water Mark. */ |
74 }; | 77 }; |
75 | 78 |
76 /* The typedef "source_location" is a key within the location database, | 79 /* The typedef "location_t" is a key within the location database, |
77 identifying a source location or macro expansion, along with range | 80 identifying a source location or macro expansion, along with range |
78 information, and (optionally) a pointer for use by gcc. | 81 information, and (optionally) a pointer for use by gcc. |
79 | 82 |
80 This key only has meaning in relation to a line_maps instance. Within | 83 This key only has meaning in relation to a line_maps instance. Within |
81 gcc there is a single line_maps instance: "line_table", declared in | 84 gcc there is a single line_maps instance: "line_table", declared in |
180 | macromap[m-2]->start_location | Start of penultimate macro map | 183 | macromap[m-2]->start_location | Start of penultimate macro map |
181 -----------+-------------------------------+------------------------------- | 184 -----------+-------------------------------+------------------------------- |
182 | macromap[1]->start_location | Start of macro map 1 | 185 | macromap[1]->start_location | Start of macro map 1 |
183 -----------+-------------------------------+------------------------------- | 186 -----------+-------------------------------+------------------------------- |
184 | macromap[0]->start_location | Start of macro map 0 | 187 | macromap[0]->start_location | Start of macro map 0 |
185 0x7fffffff | MAX_SOURCE_LOCATION | Also used as a mask for | 188 0x7fffffff | MAX_LOCATION_T | Also used as a mask for |
186 | | accessing the ad-hoc data table | 189 | | accessing the ad-hoc data table |
187 -----------+-------------------------------+------------------------------- | 190 -----------+-------------------------------+------------------------------- |
188 0x80000000 | Start of ad-hoc values; the lower 31 bits are used as an index | 191 0x80000000 | Start of ad-hoc values; the lower 31 bits are used as an index |
189 ... | into the line_table->location_adhoc_data_map.data array. | 192 ... | into the line_table->location_adhoc_data_map.data array. |
190 0xffffffff | UINT_MAX | | 193 0xffffffff | UINT_MAX | |
281 == ordmap->start + 0x171e0 | 284 == ordmap->start + 0x171e0 |
282 | 285 |
283 finish == ordmap->start + (23 << 12) + (19 << 5) | 286 finish == ordmap->start + (23 << 12) + (19 << 5) |
284 == ordmap->start + 0x17260 | 287 == ordmap->start + 0x17260 |
285 | 288 |
286 To further see how source_location works in practice, see the | 289 To further see how location_t works in practice, see the |
287 worked example in libcpp/location-example.txt. */ | 290 worked example in libcpp/location-example.txt. */ |
288 typedef unsigned int source_location; | 291 typedef unsigned int location_t; |
289 | 292 |
290 /* Do not track column numbers higher than this one. As a result, the | 293 /* Do not track column numbers higher than this one. As a result, the |
291 range of column_bits is [12, 18] (or 0 if column numbers are | 294 range of column_bits is [12, 18] (or 0 if column numbers are |
292 disabled). */ | 295 disabled). */ |
293 const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 12); | 296 const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 12); |
294 | 297 |
295 /* Do not pack ranges if locations get higher than this. | 298 /* Do not pack ranges if locations get higher than this. |
296 If you change this, update: | 299 If you change this, update: |
297 gcc.dg/plugin/location-overflow-test-*.c. */ | 300 gcc.dg/plugin/location-overflow-test-*.c. */ |
298 const source_location LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES = 0x50000000; | 301 const location_t LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES = 0x50000000; |
299 | 302 |
300 /* Do not track column numbers if locations get higher than this. | 303 /* Do not track column numbers if locations get higher than this. |
301 If you change this, update: | 304 If you change this, update: |
302 gcc.dg/plugin/location-overflow-test-*.c. */ | 305 gcc.dg/plugin/location-overflow-test-*.c. */ |
303 const source_location LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000; | 306 const location_t LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000; |
304 | 307 |
305 /* Highest possible source location encoded within an ordinary map. */ | 308 /* Highest possible source location encoded within an ordinary map. */ |
306 const source_location LINE_MAP_MAX_LOCATION = 0x70000000; | 309 const location_t LINE_MAP_MAX_LOCATION = 0x70000000; |
307 | 310 |
308 /* A range of source locations. | 311 /* A range of source locations. |
309 | 312 |
310 Ranges are closed: | 313 Ranges are closed: |
311 m_start is the first location within the range, | 314 m_start is the first location within the range, |
313 | 316 |
314 We may need a more compact way to store these, but for now, | 317 We may need a more compact way to store these, but for now, |
315 let's do it the simple way, as a pair. */ | 318 let's do it the simple way, as a pair. */ |
316 struct GTY(()) source_range | 319 struct GTY(()) source_range |
317 { | 320 { |
318 source_location m_start; | 321 location_t m_start; |
319 source_location m_finish; | 322 location_t m_finish; |
320 | 323 |
321 /* We avoid using constructors, since various structs that | 324 /* We avoid using constructors, since various structs that |
322 don't yet have constructors will embed instances of | 325 don't yet have constructors will embed instances of |
323 source_range. */ | 326 source_range. */ |
324 | 327 |
325 /* Make a source_range from a source_location. */ | 328 /* Make a source_range from a location_t. */ |
326 static source_range from_location (source_location loc) | 329 static source_range from_location (location_t loc) |
327 { | 330 { |
328 source_range result; | 331 source_range result; |
329 result.m_start = loc; | 332 result.m_start = loc; |
330 result.m_finish = loc; | 333 result.m_finish = loc; |
331 return result; | 334 return result; |
332 } | 335 } |
333 | 336 |
334 /* Make a source_range from a pair of source_location. */ | 337 /* Make a source_range from a pair of location_t. */ |
335 static source_range from_locations (source_location start, | 338 static source_range from_locations (location_t start, |
336 source_location finish) | 339 location_t finish) |
337 { | 340 { |
338 source_range result; | 341 source_range result; |
339 result.m_start = start; | 342 result.m_start = start; |
340 result.m_finish = finish; | 343 result.m_finish = finish; |
341 return result; | 344 return result; |
377 of PLUS. */ | 380 of PLUS. */ |
378 | 381 |
379 /* This contains GTY mark-up to support precompiled headers. | 382 /* This contains GTY mark-up to support precompiled headers. |
380 line_map is an abstract class, only derived objects exist. */ | 383 line_map is an abstract class, only derived objects exist. */ |
381 struct GTY((tag ("0"), desc ("MAP_ORDINARY_P (&%h) ? 1 : 2"))) line_map { | 384 struct GTY((tag ("0"), desc ("MAP_ORDINARY_P (&%h) ? 1 : 2"))) line_map { |
382 source_location start_location; | 385 location_t start_location; |
383 | 386 |
384 /* Size and alignment is (usually) 4 bytes. */ | 387 /* Size and alignment is (usually) 4 bytes. */ |
385 }; | 388 }; |
386 | 389 |
387 /* An ordinary line map encodes physical source locations. Those | 390 /* An ordinary line map encodes physical source locations. Those |
393 long as C<(1<<effective range bits), and the result_location is less than | 396 long as C<(1<<effective range bits), and the result_location is less than |
394 the next line_map's start_location. | 397 the next line_map's start_location. |
395 (The top line is line 1 and the leftmost column is column 1; line/column 0 | 398 (The top line is line 1 and the leftmost column is column 1; line/column 0 |
396 means "entire file/line" or "unknown line/column" or "not applicable".) | 399 means "entire file/line" or "unknown line/column" or "not applicable".) |
397 | 400 |
398 The highest possible source location is MAX_SOURCE_LOCATION. */ | 401 The highest possible source location is MAX_LOCATION_T. */ |
399 struct GTY((tag ("1"))) line_map_ordinary : public line_map { | 402 struct GTY((tag ("1"))) line_map_ordinary : public line_map { |
400 /* Base class is 4 bytes. */ | 403 /* Base class is 4 bytes. */ |
401 | 404 |
402 /* 4 bytes of integers, each 1 byte for easy extraction/insertion. */ | 405 /* 4 bytes of integers, each 1 byte for easy extraction/insertion. */ |
403 | 406 |
408 that therefore needs to be extern "C" protected in C++, and zero | 411 that therefore needs to be extern "C" protected in C++, and zero |
409 otherwise. This field isn't really needed now that it's in | 412 otherwise. This field isn't really needed now that it's in |
410 cpp_buffer. */ | 413 cpp_buffer. */ |
411 unsigned char sysp; | 414 unsigned char sysp; |
412 | 415 |
413 /* Number of the low-order source_location bits used for column numbers | 416 /* Number of the low-order location_t bits used for column numbers |
414 and ranges. */ | 417 and ranges. */ |
415 unsigned int m_column_and_range_bits : 8; | 418 unsigned int m_column_and_range_bits : 8; |
416 | 419 |
417 /* Number of the low-order "column" bits used for storing short ranges | 420 /* Number of the low-order "column" bits used for storing short ranges |
418 inline, rather than in the ad-hoc table. | 421 inline, rather than in the ad-hoc table. |
435 linenum_type to_line; | 438 linenum_type to_line; |
436 | 439 |
437 /* Location from whence this line map was included. For regular | 440 /* Location from whence this line map was included. For regular |
438 #includes, this location will be the last location of a map. For | 441 #includes, this location will be the last location of a map. For |
439 outermost file, this is 0. */ | 442 outermost file, this is 0. */ |
440 source_location included_from; | 443 location_t included_from; |
441 | 444 |
442 /* Size is 20 or 24 bytes, no padding */ | 445 /* Size is 20 or 24 bytes, no padding */ |
443 }; | 446 }; |
444 | 447 |
445 /* This is the highest possible source location encoded within an | 448 /* This is the highest possible source location encoded within an |
446 ordinary or macro map. */ | 449 ordinary or macro map. */ |
447 const source_location MAX_SOURCE_LOCATION = 0x7FFFFFFF; | 450 const location_t MAX_LOCATION_T = 0x7FFFFFFF; |
448 | 451 |
449 struct cpp_hashnode; | 452 struct cpp_hashnode; |
450 | 453 |
451 /* A macro line map encodes location of tokens coming from a macro | 454 /* A macro line map encodes location of tokens coming from a macro |
452 expansion. | 455 expansion. |
519 (the token) might come from. | 522 (the token) might come from. |
520 | 523 |
521 In the example above x1 (for token "+") is going to be the same | 524 In the example above x1 (for token "+") is going to be the same |
522 as y1. x0 is the spelling location for the argument token "1", | 525 as y1. x0 is the spelling location for the argument token "1", |
523 and x2 is the spelling location for the argument token "2". */ | 526 and x2 is the spelling location for the argument token "2". */ |
524 source_location * GTY((atomic)) macro_locations; | 527 location_t * GTY((atomic)) macro_locations; |
525 | 528 |
526 /* This is the location of the expansion point of the current macro | 529 /* This is the location of the expansion point of the current macro |
527 map. It's the location of the macro name. That location is held | 530 map. It's the location of the macro name. That location is held |
528 by the map that was current right before the current one. It | 531 by the map that was current right before the current one. It |
529 could have been either a macro or an ordinary map, depending on | 532 could have been either a macro or an ordinary map, depending on |
530 if we are in a nested expansion context not. */ | 533 if we are in a nested expansion context not. */ |
531 source_location expansion; | 534 location_t expansion; |
532 | 535 |
533 /* Size is 20 or 32 (4 bytes padding on 64-bit). */ | 536 /* Size is 20 or 32 (4 bytes padding on 64-bit). */ |
534 }; | 537 }; |
535 | 538 |
536 #if CHECKING_P && (GCC_VERSION >= 2007) | 539 #if CHECKING_P && (GCC_VERSION >= 2007) |
556 /* Include EXPR, so that unused variable warnings do not occur. */ | 559 /* Include EXPR, so that unused variable warnings do not occur. */ |
557 #define linemap_assert(EXPR) ((void)(0 && (EXPR))) | 560 #define linemap_assert(EXPR) ((void)(0 && (EXPR))) |
558 #define linemap_assert_fails(EXPR) (! (EXPR)) | 561 #define linemap_assert_fails(EXPR) (! (EXPR)) |
559 #endif | 562 #endif |
560 | 563 |
564 /* Get whether location LOC is an ad-hoc, ordinary or macro location. */ | |
565 | |
566 inline bool | |
567 IS_ORDINARY_LOC (location_t loc) | |
568 { | |
569 return loc < LINE_MAP_MAX_LOCATION; | |
570 } | |
571 | |
572 inline bool | |
573 IS_ADHOC_LOC (location_t loc) | |
574 { | |
575 return loc > MAX_LOCATION_T; | |
576 } | |
577 | |
578 inline bool | |
579 IS_MACRO_LOC (location_t loc) | |
580 { | |
581 return !IS_ORDINARY_LOC (loc) && !IS_ADHOC_LOC (loc); | |
582 } | |
583 | |
561 /* Categorize line map kinds. */ | 584 /* Categorize line map kinds. */ |
562 | 585 |
563 inline bool | 586 inline bool |
564 MAP_ORDINARY_P (const line_map *map) | 587 MAP_ORDINARY_P (const line_map *map) |
565 { | 588 { |
566 return map->start_location < LINE_MAP_MAX_LOCATION; | 589 return IS_ORDINARY_LOC (map->start_location); |
567 } | 590 } |
568 | 591 |
569 /* Return TRUE if MAP encodes locations coming from a macro | 592 /* Return TRUE if MAP encodes locations coming from a macro |
570 replacement-list at macro expansion point. */ | 593 replacement-list at macro expansion point. */ |
571 bool | 594 bool |
572 linemap_macro_expansion_map_p (const struct line_map *); | 595 linemap_macro_expansion_map_p (const line_map *); |
573 | 596 |
574 /* Assert that MAP encodes locations of tokens that are not part of | 597 /* Assert that MAP encodes locations of tokens that are not part of |
575 the replacement-list of a macro expansion, downcasting from | 598 the replacement-list of a macro expansion, downcasting from |
576 line_map * to line_map_ordinary *. */ | 599 line_map * to line_map_ordinary *. */ |
577 | 600 |
578 inline line_map_ordinary * | 601 inline line_map_ordinary * |
579 linemap_check_ordinary (struct line_map *map) | 602 linemap_check_ordinary (line_map *map) |
580 { | 603 { |
581 linemap_assert (MAP_ORDINARY_P (map)); | 604 linemap_assert (MAP_ORDINARY_P (map)); |
582 return (line_map_ordinary *)map; | 605 return (line_map_ordinary *)map; |
583 } | 606 } |
584 | 607 |
585 /* Assert that MAP encodes locations of tokens that are not part of | 608 /* Assert that MAP encodes locations of tokens that are not part of |
586 the replacement-list of a macro expansion, downcasting from | 609 the replacement-list of a macro expansion, downcasting from |
587 const line_map * to const line_map_ordinary *. */ | 610 const line_map * to const line_map_ordinary *. */ |
588 | 611 |
589 inline const line_map_ordinary * | 612 inline const line_map_ordinary * |
590 linemap_check_ordinary (const struct line_map *map) | 613 linemap_check_ordinary (const line_map *map) |
591 { | 614 { |
592 linemap_assert (MAP_ORDINARY_P (map)); | 615 linemap_assert (MAP_ORDINARY_P (map)); |
593 return (const line_map_ordinary *)map; | 616 return (const line_map_ordinary *)map; |
594 } | 617 } |
595 | 618 |
612 return (const line_map_macro *)map; | 635 return (const line_map_macro *)map; |
613 } | 636 } |
614 | 637 |
615 /* Read the start location of MAP. */ | 638 /* Read the start location of MAP. */ |
616 | 639 |
617 inline source_location | 640 inline location_t |
618 MAP_START_LOCATION (const line_map *map) | 641 MAP_START_LOCATION (const line_map *map) |
619 { | 642 { |
620 return map->start_location; | 643 return map->start_location; |
621 } | 644 } |
622 | 645 |
665 } | 688 } |
666 | 689 |
667 /* Get the array of pairs of locations within macro map MAP. | 690 /* Get the array of pairs of locations within macro map MAP. |
668 See the declaration of line_map_macro for more information. */ | 691 See the declaration of line_map_macro for more information. */ |
669 | 692 |
670 inline source_location * | 693 inline location_t * |
671 MACRO_MAP_LOCATIONS (const line_map_macro *macro_map) | 694 MACRO_MAP_LOCATIONS (const line_map_macro *macro_map) |
672 { | 695 { |
673 return macro_map->macro_locations; | 696 return macro_map->macro_locations; |
674 } | 697 } |
675 | 698 |
676 /* Get the location of the expansion point of the macro map MAP. */ | 699 /* Get the location of the expansion point of the macro map MAP. */ |
677 | 700 |
678 inline source_location | 701 inline location_t |
679 MACRO_MAP_EXPANSION_POINT_LOCATION (const line_map_macro *macro_map) | 702 MACRO_MAP_EXPANSION_POINT_LOCATION (const line_map_macro *macro_map) |
680 { | 703 { |
681 return macro_map->expansion; | 704 return macro_map->expansion; |
682 } | 705 } |
683 | 706 |
699 | 722 |
700 /* The number of elements used in maps. This number is smaller | 723 /* The number of elements used in maps. This number is smaller |
701 or equal to ALLOCATED. */ | 724 or equal to ALLOCATED. */ |
702 unsigned int used; | 725 unsigned int used; |
703 | 726 |
704 unsigned int cache; | 727 mutable unsigned int cache; |
705 }; | 728 }; |
706 | 729 |
707 struct GTY(()) maps_info_macro { | 730 struct GTY(()) maps_info_macro { |
708 /* This array contains the macro line maps. | 731 /* This array contains the macro line maps. |
709 A macro line map is created whenever a macro expansion occurs. */ | 732 A macro line map is created whenever a macro expansion occurs. */ |
714 | 737 |
715 /* The number of elements used in maps. This number is smaller | 738 /* The number of elements used in maps. This number is smaller |
716 or equal to ALLOCATED. */ | 739 or equal to ALLOCATED. */ |
717 unsigned int used; | 740 unsigned int used; |
718 | 741 |
719 unsigned int cache; | 742 mutable unsigned int cache; |
720 }; | 743 }; |
721 | 744 |
722 /* Data structure to associate a source_range together with an arbitrary | 745 /* Data structure to associate a source_range together with an arbitrary |
723 data pointer with a source location. */ | 746 data pointer with a source location. */ |
724 struct GTY(()) location_adhoc_data { | 747 struct GTY(()) location_adhoc_data { |
725 source_location locus; | 748 location_t locus; |
726 source_range src_range; | 749 source_range src_range; |
727 void * GTY((skip)) data; | 750 void * GTY((skip)) data; |
728 }; | 751 }; |
729 | 752 |
730 struct htab; | 753 struct htab; |
739 bits of the integer is used to index the location_adhoc_data array, | 762 bits of the integer is used to index the location_adhoc_data array, |
740 in which the locus and associated data is stored. */ | 763 in which the locus and associated data is stored. */ |
741 | 764 |
742 struct GTY(()) location_adhoc_data_map { | 765 struct GTY(()) location_adhoc_data_map { |
743 struct htab * GTY((skip)) htab; | 766 struct htab * GTY((skip)) htab; |
744 source_location curr_loc; | 767 location_t curr_loc; |
745 unsigned int allocated; | 768 unsigned int allocated; |
746 struct location_adhoc_data GTY((length ("%h.allocated"))) *data; | 769 struct location_adhoc_data GTY((length ("%h.allocated"))) *data; |
747 }; | 770 }; |
748 | 771 |
749 /* A set of chronological line_map structures. */ | 772 /* A set of chronological line_map structures. */ |
750 struct GTY(()) line_maps { | 773 class GTY(()) line_maps { |
774 public: | |
751 | 775 |
752 ~line_maps (); | 776 ~line_maps (); |
753 | 777 |
754 maps_info_ordinary info_ordinary; | 778 maps_info_ordinary info_ordinary; |
755 | 779 |
759 unsigned int depth; | 783 unsigned int depth; |
760 | 784 |
761 /* If true, prints an include trace a la -H. */ | 785 /* If true, prints an include trace a la -H. */ |
762 bool trace_includes; | 786 bool trace_includes; |
763 | 787 |
764 /* Highest source_location "given out". */ | 788 /* Highest location_t "given out". */ |
765 source_location highest_location; | 789 location_t highest_location; |
766 | 790 |
767 /* Start of line of highest source_location "given out". */ | 791 /* Start of line of highest location_t "given out". */ |
768 source_location highest_line; | 792 location_t highest_line; |
769 | 793 |
770 /* The maximum column number we can quickly allocate. Higher numbers | 794 /* The maximum column number we can quickly allocate. Higher numbers |
771 may require allocating a new line_map. */ | 795 may require allocating a new line_map. */ |
772 unsigned int max_column_hint; | 796 unsigned int max_column_hint; |
773 | 797 |
780 | 804 |
781 struct location_adhoc_data_map location_adhoc_data_map; | 805 struct location_adhoc_data_map location_adhoc_data_map; |
782 | 806 |
783 /* The special location value that is used as spelling location for | 807 /* The special location value that is used as spelling location for |
784 built-in tokens. */ | 808 built-in tokens. */ |
785 source_location builtin_location; | 809 location_t builtin_location; |
786 | 810 |
787 /* True if we've seen a #line or # 44 "file" directive. */ | 811 /* True if we've seen a #line or # 44 "file" directive. */ |
788 bool seen_line_directive; | 812 bool seen_line_directive; |
789 | 813 |
790 /* The default value of range_bits in ordinary line maps. */ | 814 /* The default value of range_bits in ordinary line maps. */ |
839 } | 863 } |
840 | 864 |
841 /* Returns the index of the last map that was looked up with | 865 /* Returns the index of the last map that was looked up with |
842 linemap_lookup. MAP_KIND shall be TRUE if we are interested in | 866 linemap_lookup. MAP_KIND shall be TRUE if we are interested in |
843 macro maps, FALSE otherwise. */ | 867 macro maps, FALSE otherwise. */ |
844 inline unsigned int | 868 inline unsigned int & |
845 LINEMAPS_CACHE (const line_maps *set, bool map_kind) | 869 LINEMAPS_CACHE (const line_maps *set, bool map_kind) |
846 { | |
847 if (map_kind) | |
848 return set->info_macro.cache; | |
849 else | |
850 return set->info_ordinary.cache; | |
851 } | |
852 | |
853 /* As above, but by reference (e.g. as an lvalue). */ | |
854 | |
855 inline unsigned int & | |
856 LINEMAPS_CACHE (line_maps *set, bool map_kind) | |
857 { | 870 { |
858 if (map_kind) | 871 if (map_kind) |
859 return set->info_macro.cache; | 872 return set->info_macro.cache; |
860 else | 873 else |
861 return set->info_ordinary.cache; | 874 return set->info_ordinary.cache; |
901 | 914 |
902 /* Returns the INDEXth ordinary map. */ | 915 /* Returns the INDEXth ordinary map. */ |
903 inline line_map_ordinary * | 916 inline line_map_ordinary * |
904 LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, int index) | 917 LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, int index) |
905 { | 918 { |
906 linemap_assert (index >= 0); | 919 linemap_assert (index >= 0 |
907 linemap_assert ((unsigned int)index < set->info_ordinary.used); | 920 && (unsigned int)index < LINEMAPS_USED (set, false)); |
908 return &set->info_ordinary.maps[index]; | 921 return (line_map_ordinary *)LINEMAPS_MAP_AT (set, false, index); |
909 } | 922 } |
910 | 923 |
911 /* Return the number of ordinary maps allocated in the line table | 924 /* Return the number of ordinary maps allocated in the line table |
912 SET. */ | 925 SET. */ |
913 inline unsigned int | 926 inline unsigned int |
923 return LINEMAPS_USED (set, false); | 936 return LINEMAPS_USED (set, false); |
924 } | 937 } |
925 | 938 |
926 /* Return the index of the last ordinary map that was looked up with | 939 /* Return the index of the last ordinary map that was looked up with |
927 linemap_lookup. */ | 940 linemap_lookup. */ |
928 inline unsigned int | 941 inline unsigned int & |
929 LINEMAPS_ORDINARY_CACHE (const line_maps *set) | 942 LINEMAPS_ORDINARY_CACHE (const line_maps *set) |
930 { | |
931 return LINEMAPS_CACHE (set, false); | |
932 } | |
933 | |
934 /* As above, but by reference (e.g. as an lvalue). */ | |
935 | |
936 inline unsigned int & | |
937 LINEMAPS_ORDINARY_CACHE (line_maps *set) | |
938 { | 943 { |
939 return LINEMAPS_CACHE (set, false); | 944 return LINEMAPS_CACHE (set, false); |
940 } | 945 } |
941 | 946 |
942 /* Returns a pointer to the last ordinary map used in the line table | 947 /* Returns a pointer to the last ordinary map used in the line table |
965 | 970 |
966 /* Returns the INDEXth macro map. */ | 971 /* Returns the INDEXth macro map. */ |
967 inline line_map_macro * | 972 inline line_map_macro * |
968 LINEMAPS_MACRO_MAP_AT (const line_maps *set, int index) | 973 LINEMAPS_MACRO_MAP_AT (const line_maps *set, int index) |
969 { | 974 { |
970 linemap_assert (index >= 0); | 975 linemap_assert (index >= 0 |
971 linemap_assert ((unsigned int)index < set->info_macro.used); | 976 && (unsigned int)index < LINEMAPS_USED (set, true)); |
972 return &set->info_macro.maps[index]; | 977 return (line_map_macro *)LINEMAPS_MAP_AT (set, true, index); |
973 } | 978 } |
974 | 979 |
975 /* Returns the number of macro maps that were allocated in the line | 980 /* Returns the number of macro maps that were allocated in the line |
976 table SET. */ | 981 table SET. */ |
977 inline unsigned int | 982 inline unsigned int |
985 LINEMAPS_MACRO_USED (const line_maps *set) | 990 LINEMAPS_MACRO_USED (const line_maps *set) |
986 { | 991 { |
987 return LINEMAPS_USED (set, true); | 992 return LINEMAPS_USED (set, true); |
988 } | 993 } |
989 | 994 |
990 /* Returns the index of the last macro map looked up with | 995 /* Return the index of the last macro map that was looked up with |
991 linemap_lookup. */ | 996 linemap_lookup. */ |
992 inline unsigned int | 997 inline unsigned int & |
993 LINEMAPS_MACRO_CACHE (const line_maps *set) | 998 LINEMAPS_MACRO_CACHE (const line_maps *set) |
994 { | |
995 return LINEMAPS_CACHE (set, true); | |
996 } | |
997 | |
998 /* As above, but by reference (e.g. as an lvalue). */ | |
999 | |
1000 inline unsigned int & | |
1001 LINEMAPS_MACRO_CACHE (line_maps *set) | |
1002 { | 999 { |
1003 return LINEMAPS_CACHE (set, true); | 1000 return LINEMAPS_CACHE (set, true); |
1004 } | 1001 } |
1005 | 1002 |
1006 /* Returns the last macro map used in the line table SET. */ | 1003 /* Returns the last macro map used in the line table SET. */ |
1010 return (line_map_macro *)LINEMAPS_LAST_MAP (set, true); | 1007 return (line_map_macro *)LINEMAPS_LAST_MAP (set, true); |
1011 } | 1008 } |
1012 | 1009 |
1013 /* Returns the lowest location [of a token resulting from macro | 1010 /* Returns the lowest location [of a token resulting from macro |
1014 expansion] encoded in this line table. */ | 1011 expansion] encoded in this line table. */ |
1015 inline source_location | 1012 inline location_t |
1016 LINEMAPS_MACRO_LOWEST_LOCATION (const line_maps *set) | 1013 LINEMAPS_MACRO_LOWEST_LOCATION (const line_maps *set) |
1017 { | 1014 { |
1018 return LINEMAPS_MACRO_USED (set) | 1015 return LINEMAPS_MACRO_USED (set) |
1019 ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set)) | 1016 ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set)) |
1020 : MAX_SOURCE_LOCATION + 1; | 1017 : MAX_LOCATION_T + 1; |
1021 } | 1018 } |
1022 | 1019 |
1023 /* Returns the last macro map allocated in the line table SET. */ | 1020 /* Returns the last macro map allocated in the line table SET. */ |
1024 inline line_map_macro * | 1021 inline line_map_macro * |
1025 LINEMAPS_LAST_ALLOCATED_MACRO_MAP (const line_maps *set) | 1022 LINEMAPS_LAST_ALLOCATED_MACRO_MAP (const line_maps *set) |
1026 { | 1023 { |
1027 return (line_map_macro *)LINEMAPS_LAST_ALLOCATED_MAP (set, true); | 1024 return (line_map_macro *)LINEMAPS_LAST_ALLOCATED_MAP (set, true); |
1028 } | 1025 } |
1029 | 1026 |
1030 extern source_location get_combined_adhoc_loc (struct line_maps *, | 1027 extern location_t get_combined_adhoc_loc (class line_maps *, |
1031 source_location, | 1028 location_t, |
1032 source_range, | 1029 source_range, |
1033 void *); | 1030 void *); |
1034 extern void *get_data_from_adhoc_loc (struct line_maps *, source_location); | 1031 extern void *get_data_from_adhoc_loc (const line_maps *, location_t); |
1035 extern source_location get_location_from_adhoc_loc (struct line_maps *, | 1032 extern location_t get_location_from_adhoc_loc (const line_maps *, |
1036 source_location); | 1033 location_t); |
1037 | 1034 |
1038 extern source_range get_range_from_loc (line_maps *set, source_location loc); | 1035 extern source_range get_range_from_loc (line_maps *set, location_t loc); |
1039 | |
1040 /* Get whether location LOC is an ad-hoc location. */ | |
1041 | |
1042 inline bool | |
1043 IS_ADHOC_LOC (source_location loc) | |
1044 { | |
1045 return (loc & MAX_SOURCE_LOCATION) != loc; | |
1046 } | |
1047 | 1036 |
1048 /* Get whether location LOC is a "pure" location, or | 1037 /* Get whether location LOC is a "pure" location, or |
1049 whether it is an ad-hoc location, or embeds range information. */ | 1038 whether it is an ad-hoc location, or embeds range information. */ |
1050 | 1039 |
1051 bool | 1040 bool |
1052 pure_location_p (line_maps *set, source_location loc); | 1041 pure_location_p (line_maps *set, location_t loc); |
1053 | 1042 |
1054 /* Given location LOC within SET, strip away any packed range information | 1043 /* Given location LOC within SET, strip away any packed range information |
1055 or ad-hoc information. */ | 1044 or ad-hoc information. */ |
1056 | 1045 |
1057 extern source_location get_pure_location (line_maps *set, | 1046 extern location_t get_pure_location (line_maps *set, |
1058 source_location loc); | 1047 location_t loc); |
1059 | 1048 |
1060 /* Combine LOC and BLOCK, giving a combined adhoc location. */ | 1049 /* Combine LOC and BLOCK, giving a combined adhoc location. */ |
1061 | 1050 |
1062 inline source_location | 1051 inline location_t |
1063 COMBINE_LOCATION_DATA (struct line_maps *set, | 1052 COMBINE_LOCATION_DATA (class line_maps *set, |
1064 source_location loc, | 1053 location_t loc, |
1065 source_range src_range, | 1054 source_range src_range, |
1066 void *block) | 1055 void *block) |
1067 { | 1056 { |
1068 return get_combined_adhoc_loc (set, loc, src_range, block); | 1057 return get_combined_adhoc_loc (set, loc, src_range, block); |
1069 } | 1058 } |
1070 | 1059 |
1071 extern void rebuild_location_adhoc_htab (struct line_maps *); | 1060 extern void rebuild_location_adhoc_htab (class line_maps *); |
1072 | 1061 |
1073 /* Initialize a line map set. SET is the line map set to initialize | 1062 /* Initialize a line map set. SET is the line map set to initialize |
1074 and BUILTIN_LOCATION is the special location value to be used as | 1063 and BUILTIN_LOCATION is the special location value to be used as |
1075 spelling location for built-in tokens. This BUILTIN_LOCATION has | 1064 spelling location for built-in tokens. This BUILTIN_LOCATION has |
1076 to be strictly less than RESERVED_LOCATION_COUNT. */ | 1065 to be strictly less than RESERVED_LOCATION_COUNT. */ |
1077 extern void linemap_init (struct line_maps *set, | 1066 extern void linemap_init (class line_maps *set, |
1078 source_location builtin_location); | 1067 location_t builtin_location); |
1079 | 1068 |
1080 /* Check for and warn about line_maps entered but not exited. */ | 1069 /* Check for and warn about line_maps entered but not exited. */ |
1081 | 1070 |
1082 extern void linemap_check_files_exited (struct line_maps *); | 1071 extern void linemap_check_files_exited (class line_maps *); |
1083 | 1072 |
1084 /* Return a source_location for the start (i.e. column==0) of | 1073 /* Return a location_t for the start (i.e. column==0) of |
1085 (physical) line TO_LINE in the current source file (as in the | 1074 (physical) line TO_LINE in the current source file (as in the |
1086 most recent linemap_add). MAX_COLUMN_HINT is the highest column | 1075 most recent linemap_add). MAX_COLUMN_HINT is the highest column |
1087 number we expect to use in this line (but it does not change | 1076 number we expect to use in this line (but it does not change |
1088 the highest_location). */ | 1077 the highest_location). */ |
1089 | 1078 |
1090 extern source_location linemap_line_start | 1079 extern location_t linemap_line_start |
1091 (struct line_maps *set, linenum_type to_line, unsigned int max_column_hint); | 1080 (class line_maps *set, linenum_type to_line, unsigned int max_column_hint); |
1092 | 1081 |
1093 /* Add a mapping of logical source line to physical source file and | 1082 /* Add a mapping of logical source line to physical source file and |
1094 line number. This function creates an "ordinary map", which is a | 1083 line number. This function creates an "ordinary map", which is a |
1095 map that records locations of tokens that are not part of macro | 1084 map that records locations of tokens that are not part of macro |
1096 replacement-lists present at a macro expansion point. | 1085 replacement-lists present at a macro expansion point. |
1101 TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their | 1090 TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their |
1102 natural values considering the file we are returning to. | 1091 natural values considering the file we are returning to. |
1103 | 1092 |
1104 A call to this function can relocate the previous set of | 1093 A call to this function can relocate the previous set of |
1105 maps, so any stored line_map pointers should not be used. */ | 1094 maps, so any stored line_map pointers should not be used. */ |
1106 extern const struct line_map *linemap_add | 1095 extern const line_map *linemap_add |
1107 (struct line_maps *, enum lc_reason, unsigned int sysp, | 1096 (class line_maps *, enum lc_reason, unsigned int sysp, |
1108 const char *to_file, linenum_type to_line); | 1097 const char *to_file, linenum_type to_line); |
1109 | 1098 |
1110 /* Given a logical source location, returns the map which the | 1099 /* Given a logical source location, returns the map which the |
1111 corresponding (source file, line, column) triplet can be deduced | 1100 corresponding (source file, line, column) triplet can be deduced |
1112 from. Since the set is built chronologically, the logical lines are | 1101 from. Since the set is built chronologically, the logical lines are |
1113 monotonic increasing, and so the list is sorted and we can use a | 1102 monotonic increasing, and so the list is sorted and we can use a |
1114 binary search. If no line map have been allocated yet, this | 1103 binary search. If no line map have been allocated yet, this |
1115 function returns NULL. */ | 1104 function returns NULL. */ |
1116 extern const struct line_map *linemap_lookup | 1105 extern const line_map *linemap_lookup |
1117 (struct line_maps *, source_location); | 1106 (const line_maps *, location_t); |
1118 | 1107 |
1119 /* Returns TRUE if the line table set tracks token locations across | 1108 /* Returns TRUE if the line table set tracks token locations across |
1120 macro expansion, FALSE otherwise. */ | 1109 macro expansion, FALSE otherwise. */ |
1121 bool linemap_tracks_macro_expansion_locs_p (struct line_maps *); | 1110 bool linemap_tracks_macro_expansion_locs_p (class line_maps *); |
1122 | 1111 |
1123 /* Return the name of the macro associated to MACRO_MAP. */ | 1112 /* Return the name of the macro associated to MACRO_MAP. */ |
1124 const char* linemap_map_get_macro_name (const line_map_macro *); | 1113 const char* linemap_map_get_macro_name (const line_map_macro *); |
1125 | 1114 |
1126 /* Return a positive value if LOCATION is the locus of a token that is | 1115 /* Return a positive value if LOCATION is the locus of a token that is |
1130 that therefore needs to be extern "C" protected in C++. | 1119 that therefore needs to be extern "C" protected in C++. |
1131 | 1120 |
1132 Note that this function returns 1 if LOCATION belongs to a token | 1121 Note that this function returns 1 if LOCATION belongs to a token |
1133 that is part of a macro replacement-list defined in a system | 1122 that is part of a macro replacement-list defined in a system |
1134 header, but expanded in a non-system file. */ | 1123 header, but expanded in a non-system file. */ |
1135 int linemap_location_in_system_header_p (struct line_maps *, | 1124 int linemap_location_in_system_header_p (class line_maps *, |
1136 source_location); | 1125 location_t); |
1137 | 1126 |
1138 /* Return TRUE if LOCATION is a source code location of a token that is part of | 1127 /* Return TRUE if LOCATION is a source code location of a token that is part of |
1139 a macro expansion, FALSE otherwise. */ | 1128 a macro expansion, FALSE otherwise. */ |
1140 bool linemap_location_from_macro_expansion_p (const struct line_maps *, | 1129 bool linemap_location_from_macro_expansion_p (const line_maps *, |
1141 source_location); | 1130 location_t); |
1142 | 1131 |
1143 /* TRUE if LOCATION is a source code location of a token that is part of the | 1132 /* TRUE if LOCATION is a source code location of a token that is part of the |
1144 definition of a macro, FALSE otherwise. */ | 1133 definition of a macro, FALSE otherwise. */ |
1145 bool linemap_location_from_macro_definition_p (struct line_maps *, | 1134 bool linemap_location_from_macro_definition_p (class line_maps *, |
1146 source_location); | 1135 location_t); |
1147 | 1136 |
1148 /* With the precondition that LOCATION is the locus of a token that is | 1137 /* With the precondition that LOCATION is the locus of a token that is |
1149 an argument of a function-like macro MACRO_MAP and appears in the | 1138 an argument of a function-like macro MACRO_MAP and appears in the |
1150 expansion of MACRO_MAP, return the locus of that argument in the | 1139 expansion of MACRO_MAP, return the locus of that argument in the |
1151 context of the caller of MACRO_MAP. */ | 1140 context of the caller of MACRO_MAP. */ |
1152 | 1141 |
1153 extern source_location linemap_macro_map_loc_unwind_toward_spelling | 1142 extern location_t linemap_macro_map_loc_unwind_toward_spelling |
1154 (line_maps *set, const line_map_macro *macro_map, source_location location); | 1143 (line_maps *set, const line_map_macro *macro_map, location_t location); |
1155 | 1144 |
1156 /* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will | 1145 /* location_t values from 0 to RESERVED_LOCATION_COUNT-1 will |
1157 be reserved for libcpp user as special values, no token from libcpp | 1146 be reserved for libcpp user as special values, no token from libcpp |
1158 will contain any of those locations. */ | 1147 will contain any of those locations. */ |
1159 const source_location RESERVED_LOCATION_COUNT = 2; | 1148 const location_t RESERVED_LOCATION_COUNT = 2; |
1160 | 1149 |
1161 /* Converts a map and a source_location to source line. */ | 1150 /* Converts a map and a location_t to source line. */ |
1162 inline linenum_type | 1151 inline linenum_type |
1163 SOURCE_LINE (const line_map_ordinary *ord_map, source_location loc) | 1152 SOURCE_LINE (const line_map_ordinary *ord_map, location_t loc) |
1164 { | 1153 { |
1165 return ((loc - ord_map->start_location) | 1154 return ((loc - ord_map->start_location) |
1166 >> ord_map->m_column_and_range_bits) + ord_map->to_line; | 1155 >> ord_map->m_column_and_range_bits) + ord_map->to_line; |
1167 } | 1156 } |
1168 | 1157 |
1169 /* Convert a map and source_location to source column number. */ | 1158 /* Convert a map and location_t to source column number. */ |
1170 inline linenum_type | 1159 inline linenum_type |
1171 SOURCE_COLUMN (const line_map_ordinary *ord_map, source_location loc) | 1160 SOURCE_COLUMN (const line_map_ordinary *ord_map, location_t loc) |
1172 { | 1161 { |
1173 return ((loc - ord_map->start_location) | 1162 return ((loc - ord_map->start_location) |
1174 & ((1 << ord_map->m_column_and_range_bits) - 1)) >> ord_map->m_range_bits; | 1163 & ((1 << ord_map->m_column_and_range_bits) - 1)) >> ord_map->m_range_bits; |
1175 } | 1164 } |
1176 | 1165 |
1177 | 1166 |
1178 inline source_location | 1167 inline location_t |
1179 linemap_included_from (const line_map_ordinary *ord_map) | 1168 linemap_included_from (const line_map_ordinary *ord_map) |
1180 { | 1169 { |
1181 return ord_map->included_from; | 1170 return ord_map->included_from; |
1182 } | 1171 } |
1183 | 1172 |
1191 MAIN_FILE_P (const line_map_ordinary *ord_map) | 1180 MAIN_FILE_P (const line_map_ordinary *ord_map) |
1192 { | 1181 { |
1193 return ord_map->included_from == 0; | 1182 return ord_map->included_from == 0; |
1194 } | 1183 } |
1195 | 1184 |
1196 /* Encode and return a source_location from a column number. The | 1185 /* Encode and return a location_t from a column number. The |
1197 source line considered is the last source line used to call | 1186 source line considered is the last source line used to call |
1198 linemap_line_start, i.e, the last source line which a location was | 1187 linemap_line_start, i.e, the last source line which a location was |
1199 encoded from. */ | 1188 encoded from. */ |
1200 extern source_location | 1189 extern location_t |
1201 linemap_position_for_column (struct line_maps *, unsigned int); | 1190 linemap_position_for_column (class line_maps *, unsigned int); |
1202 | 1191 |
1203 /* Encode and return a source location from a given line and | 1192 /* Encode and return a source location from a given line and |
1204 column. */ | 1193 column. */ |
1205 source_location | 1194 location_t |
1206 linemap_position_for_line_and_column (line_maps *set, | 1195 linemap_position_for_line_and_column (line_maps *set, |
1207 const line_map_ordinary *, | 1196 const line_map_ordinary *, |
1208 linenum_type, unsigned int); | 1197 linenum_type, unsigned int); |
1209 | 1198 |
1210 /* Encode and return a source_location starting from location LOC and | 1199 /* Encode and return a location_t starting from location LOC and |
1211 shifting it by OFFSET columns. This function does not support | 1200 shifting it by OFFSET columns. This function does not support |
1212 virtual locations. */ | 1201 virtual locations. */ |
1213 source_location | 1202 location_t |
1214 linemap_position_for_loc_and_offset (struct line_maps *set, | 1203 linemap_position_for_loc_and_offset (class line_maps *set, |
1215 source_location loc, | 1204 location_t loc, |
1216 unsigned int offset); | 1205 unsigned int offset); |
1217 | 1206 |
1218 /* Return the file this map is for. */ | 1207 /* Return the file this map is for. */ |
1219 inline const char * | 1208 inline const char * |
1220 LINEMAP_FILE (const line_map_ordinary *ord_map) | 1209 LINEMAP_FILE (const line_map_ordinary *ord_map) |
1241 | 1230 |
1242 /* Return a positive value if PRE denotes the location of a token that | 1231 /* Return a positive value if PRE denotes the location of a token that |
1243 comes before the token of POST, 0 if PRE denotes the location of | 1232 comes before the token of POST, 0 if PRE denotes the location of |
1244 the same token as the token for POST, and a negative value | 1233 the same token as the token for POST, and a negative value |
1245 otherwise. */ | 1234 otherwise. */ |
1246 int linemap_compare_locations (struct line_maps *set, | 1235 int linemap_compare_locations (class line_maps *set, |
1247 source_location pre, | 1236 location_t pre, |
1248 source_location post); | 1237 location_t post); |
1249 | 1238 |
1250 /* Return TRUE if LOC_A denotes the location a token that comes | 1239 /* Return TRUE if LOC_A denotes the location a token that comes |
1251 topogically before the token denoted by location LOC_B, or if they | 1240 topogically before the token denoted by location LOC_B, or if they |
1252 are equal. */ | 1241 are equal. */ |
1253 inline bool | 1242 inline bool |
1254 linemap_location_before_p (struct line_maps *set, | 1243 linemap_location_before_p (class line_maps *set, |
1255 source_location loc_a, | 1244 location_t loc_a, |
1256 source_location loc_b) | 1245 location_t loc_b) |
1257 { | 1246 { |
1258 return linemap_compare_locations (set, loc_a, loc_b) >= 0; | 1247 return linemap_compare_locations (set, loc_a, loc_b) >= 0; |
1259 } | 1248 } |
1260 | 1249 |
1261 typedef struct | 1250 typedef struct |
1310 the caret potentially flagged for display, and an optional | 1299 the caret potentially flagged for display, and an optional |
1311 label. */ | 1300 label. */ |
1312 | 1301 |
1313 struct location_range | 1302 struct location_range |
1314 { | 1303 { |
1315 source_location m_loc; | 1304 location_t m_loc; |
1316 | 1305 |
1317 enum range_display_kind m_range_display_kind; | 1306 enum range_display_kind m_range_display_kind; |
1318 | 1307 |
1319 /* If non-NULL, the label for this range. */ | 1308 /* If non-NULL, the label for this range. */ |
1320 const range_label *m_label; | 1309 const range_label *m_label; |
1441 linemap_assert (len <= m_num); | 1430 linemap_assert (len <= m_num); |
1442 m_num = len; | 1431 m_num = len; |
1443 } | 1432 } |
1444 | 1433 |
1445 class fixit_hint; | 1434 class fixit_hint; |
1435 class diagnostic_path; | |
1446 | 1436 |
1447 /* A "rich" source code location, for use when printing diagnostics. | 1437 /* A "rich" source code location, for use when printing diagnostics. |
1448 A rich_location has one or more carets&ranges, where the carets | 1438 A rich_location has one or more carets&ranges, where the carets |
1449 are optional. These are referred to as "ranges" from here. | 1439 are optional. These are referred to as "ranges" from here. |
1450 Typically the zeroth range has a caret; other ranges sometimes | 1440 Typically the zeroth range has a caret; other ranges sometimes |
1593 on the "i" of int). It has a insertion fix-it hint of the string | 1583 on the "i" of int). It has a insertion fix-it hint of the string |
1594 "#include <stdio.h>\n". | 1584 "#include <stdio.h>\n". |
1595 | 1585 |
1596 Adding a fix-it hint can fail: for example, attempts to insert content | 1586 Adding a fix-it hint can fail: for example, attempts to insert content |
1597 at the transition between two line maps may fail due to there being no | 1587 at the transition between two line maps may fail due to there being no |
1598 source_location (aka location_t) value to express the new location. | 1588 location_t value to express the new location. |
1599 | 1589 |
1600 Attempts to add a fix-it hint within a macro expansion will fail. | 1590 Attempts to add a fix-it hint within a macro expansion will fail. |
1601 | 1591 |
1602 There is only limited support for newline characters in fix-it hints: | 1592 There is only limited support for newline characters in fix-it hints: |
1603 only hints with newlines which insert an entire new line are permitted, | 1593 only hints with newlines which insert an entire new line are permitted, |
1623 { | 1613 { |
1624 public: | 1614 public: |
1625 /* Constructors. */ | 1615 /* Constructors. */ |
1626 | 1616 |
1627 /* Constructing from a location. */ | 1617 /* Constructing from a location. */ |
1628 rich_location (line_maps *set, source_location loc, | 1618 rich_location (line_maps *set, location_t loc, |
1629 const range_label *label = NULL); | 1619 const range_label *label = NULL); |
1630 | 1620 |
1631 /* Destructor. */ | 1621 /* Destructor. */ |
1632 ~rich_location (); | 1622 ~rich_location (); |
1633 | 1623 |
1634 /* Accessors. */ | 1624 /* Accessors. */ |
1635 source_location get_loc () const { return get_loc (0); } | 1625 location_t get_loc () const { return get_loc (0); } |
1636 source_location get_loc (unsigned int idx) const; | 1626 location_t get_loc (unsigned int idx) const; |
1637 | 1627 |
1638 void | 1628 void |
1639 add_range (source_location loc, | 1629 add_range (location_t loc, |
1640 enum range_display_kind range_display_kind | 1630 enum range_display_kind range_display_kind |
1641 = SHOW_RANGE_WITHOUT_CARET, | 1631 = SHOW_RANGE_WITHOUT_CARET, |
1642 const range_label *label = NULL); | 1632 const range_label *label = NULL); |
1643 | 1633 |
1644 void | 1634 void |
1645 set_range (unsigned int idx, source_location loc, | 1635 set_range (unsigned int idx, location_t loc, |
1646 enum range_display_kind range_display_kind); | 1636 enum range_display_kind range_display_kind); |
1647 | 1637 |
1648 unsigned int get_num_locations () const { return m_ranges.count (); } | 1638 unsigned int get_num_locations () const { return m_ranges.count (); } |
1649 | 1639 |
1650 const location_range *get_range (unsigned int idx) const; | 1640 const location_range *get_range (unsigned int idx) const; |
1664 void | 1654 void |
1665 add_fixit_insert_before (const char *new_content); | 1655 add_fixit_insert_before (const char *new_content); |
1666 | 1656 |
1667 /* Suggest inserting NEW_CONTENT immediately before the start of WHERE. */ | 1657 /* Suggest inserting NEW_CONTENT immediately before the start of WHERE. */ |
1668 void | 1658 void |
1669 add_fixit_insert_before (source_location where, | 1659 add_fixit_insert_before (location_t where, |
1670 const char *new_content); | 1660 const char *new_content); |
1671 | 1661 |
1672 /* Suggest inserting NEW_CONTENT immediately after the end of the primary | 1662 /* Suggest inserting NEW_CONTENT immediately after the end of the primary |
1673 range. */ | 1663 range. */ |
1674 void | 1664 void |
1675 add_fixit_insert_after (const char *new_content); | 1665 add_fixit_insert_after (const char *new_content); |
1676 | 1666 |
1677 /* Suggest inserting NEW_CONTENT immediately after the end of WHERE. */ | 1667 /* Suggest inserting NEW_CONTENT immediately after the end of WHERE. */ |
1678 void | 1668 void |
1679 add_fixit_insert_after (source_location where, | 1669 add_fixit_insert_after (location_t where, |
1680 const char *new_content); | 1670 const char *new_content); |
1681 | 1671 |
1682 /* Methods for adding removal fix-it hints. */ | 1672 /* Methods for adding removal fix-it hints. */ |
1683 | 1673 |
1684 /* Suggest removing the content covered by range 0. */ | 1674 /* Suggest removing the content covered by range 0. */ |
1686 add_fixit_remove (); | 1676 add_fixit_remove (); |
1687 | 1677 |
1688 /* Suggest removing the content covered between the start and finish | 1678 /* Suggest removing the content covered between the start and finish |
1689 of WHERE. */ | 1679 of WHERE. */ |
1690 void | 1680 void |
1691 add_fixit_remove (source_location where); | 1681 add_fixit_remove (location_t where); |
1692 | 1682 |
1693 /* Suggest removing the content covered by SRC_RANGE. */ | 1683 /* Suggest removing the content covered by SRC_RANGE. */ |
1694 void | 1684 void |
1695 add_fixit_remove (source_range src_range); | 1685 add_fixit_remove (source_range src_range); |
1696 | 1686 |
1701 add_fixit_replace (const char *new_content); | 1691 add_fixit_replace (const char *new_content); |
1702 | 1692 |
1703 /* Suggest replacing the content between the start and finish of | 1693 /* Suggest replacing the content between the start and finish of |
1704 WHERE with NEW_CONTENT. */ | 1694 WHERE with NEW_CONTENT. */ |
1705 void | 1695 void |
1706 add_fixit_replace (source_location where, | 1696 add_fixit_replace (location_t where, |
1707 const char *new_content); | 1697 const char *new_content); |
1708 | 1698 |
1709 /* Suggest replacing the content covered by SRC_RANGE with | 1699 /* Suggest replacing the content covered by SRC_RANGE with |
1710 NEW_CONTENT. */ | 1700 NEW_CONTENT. */ |
1711 void | 1701 void |
1736 bool fixits_can_be_auto_applied_p () const | 1726 bool fixits_can_be_auto_applied_p () const |
1737 { | 1727 { |
1738 return !m_fixits_cannot_be_auto_applied; | 1728 return !m_fixits_cannot_be_auto_applied; |
1739 } | 1729 } |
1740 | 1730 |
1731 /* An optional path through the code. */ | |
1732 const diagnostic_path *get_path () const { return m_path; } | |
1733 void set_path (const diagnostic_path *path) { m_path = path; } | |
1734 | |
1741 private: | 1735 private: |
1742 bool reject_impossible_fixit (source_location where); | 1736 bool reject_impossible_fixit (location_t where); |
1743 void stop_supporting_fixits (); | 1737 void stop_supporting_fixits (); |
1744 void maybe_add_fixit (source_location start, | 1738 void maybe_add_fixit (location_t start, |
1745 source_location next_loc, | 1739 location_t next_loc, |
1746 const char *new_content); | 1740 const char *new_content); |
1747 | 1741 |
1748 public: | 1742 public: |
1749 static const int STATICALLY_ALLOCATED_RANGES = 3; | 1743 static const int STATICALLY_ALLOCATED_RANGES = 3; |
1750 | 1744 |
1760 static const int MAX_STATIC_FIXIT_HINTS = 2; | 1754 static const int MAX_STATIC_FIXIT_HINTS = 2; |
1761 semi_embedded_vec <fixit_hint *, MAX_STATIC_FIXIT_HINTS> m_fixit_hints; | 1755 semi_embedded_vec <fixit_hint *, MAX_STATIC_FIXIT_HINTS> m_fixit_hints; |
1762 | 1756 |
1763 bool m_seen_impossible_fixit; | 1757 bool m_seen_impossible_fixit; |
1764 bool m_fixits_cannot_be_auto_applied; | 1758 bool m_fixits_cannot_be_auto_applied; |
1759 | |
1760 const diagnostic_path *m_path; | |
1765 }; | 1761 }; |
1766 | 1762 |
1767 /* A struct for the result of range_label::get_text: a NUL-terminated buffer | 1763 /* A struct for the result of range_label::get_text: a NUL-terminated buffer |
1768 of localized text, and a flag to determine if the caller should "free" the | 1764 of localized text, and a flag to determine if the caller should "free" the |
1769 buffer. */ | 1765 buffer. */ |
1770 | 1766 |
1771 struct label_text | 1767 class label_text |
1772 { | 1768 { |
1769 public: | |
1773 label_text () | 1770 label_text () |
1774 : m_buffer (NULL), m_caller_owned (false) | 1771 : m_buffer (NULL), m_caller_owned (false) |
1775 {} | |
1776 | |
1777 label_text (char *buffer, bool caller_owned) | |
1778 : m_buffer (buffer), m_caller_owned (caller_owned) | |
1779 {} | 1772 {} |
1780 | 1773 |
1781 void maybe_free () | 1774 void maybe_free () |
1782 { | 1775 { |
1783 if (m_caller_owned) | 1776 if (m_caller_owned) |
1784 free (m_buffer); | 1777 free (m_buffer); |
1785 } | 1778 } |
1786 | 1779 |
1780 /* Create a label_text instance that borrows BUFFER from a | |
1781 longer-lived owner. */ | |
1782 static label_text borrow (const char *buffer) | |
1783 { | |
1784 return label_text (const_cast <char *> (buffer), false); | |
1785 } | |
1786 | |
1787 /* Create a label_text instance that takes ownership of BUFFER. */ | |
1788 static label_text take (char *buffer) | |
1789 { | |
1790 return label_text (buffer, true); | |
1791 } | |
1792 | |
1793 /* Take ownership of the buffer, copying if necessary. */ | |
1794 char *take_or_copy () | |
1795 { | |
1796 if (m_caller_owned) | |
1797 return m_buffer; | |
1798 else | |
1799 return xstrdup (m_buffer); | |
1800 } | |
1801 | |
1787 char *m_buffer; | 1802 char *m_buffer; |
1788 bool m_caller_owned; | 1803 bool m_caller_owned; |
1804 | |
1805 private: | |
1806 label_text (char *buffer, bool owned) | |
1807 : m_buffer (buffer), m_caller_owned (owned) | |
1808 {} | |
1789 }; | 1809 }; |
1790 | 1810 |
1791 /* Abstract base class for labelling a range within a rich_location | 1811 /* Abstract base class for labelling a range within a rich_location |
1792 (e.g. for labelling expressions with their type). | 1812 (e.g. for labelling expressions with their type). |
1793 | 1813 |
1829 the content (preventing e.g. fix-its that split a pre-existing line). */ | 1849 the content (preventing e.g. fix-its that split a pre-existing line). */ |
1830 | 1850 |
1831 class fixit_hint | 1851 class fixit_hint |
1832 { | 1852 { |
1833 public: | 1853 public: |
1834 fixit_hint (source_location start, | 1854 fixit_hint (location_t start, |
1835 source_location next_loc, | 1855 location_t next_loc, |
1836 const char *new_content); | 1856 const char *new_content); |
1837 ~fixit_hint () { free (m_bytes); } | 1857 ~fixit_hint () { free (m_bytes); } |
1838 | 1858 |
1839 bool affects_line_p (const char *file, int line) const; | 1859 bool affects_line_p (const char *file, int line) const; |
1840 source_location get_start_loc () const { return m_start; } | 1860 location_t get_start_loc () const { return m_start; } |
1841 source_location get_next_loc () const { return m_next_loc; } | 1861 location_t get_next_loc () const { return m_next_loc; } |
1842 bool maybe_append (source_location start, | 1862 bool maybe_append (location_t start, |
1843 source_location next_loc, | 1863 location_t next_loc, |
1844 const char *new_content); | 1864 const char *new_content); |
1845 | 1865 |
1846 const char *get_string () const { return m_bytes; } | 1866 const char *get_string () const { return m_bytes; } |
1847 size_t get_length () const { return m_len; } | 1867 size_t get_length () const { return m_len; } |
1848 | 1868 |
1853 private: | 1873 private: |
1854 /* We don't use source_range here since, unlike most places, | 1874 /* We don't use source_range here since, unlike most places, |
1855 this is a half-open/half-closed range: | 1875 this is a half-open/half-closed range: |
1856 [start, next_loc) | 1876 [start, next_loc) |
1857 so that we can support insertion via start == next_loc. */ | 1877 so that we can support insertion via start == next_loc. */ |
1858 source_location m_start; | 1878 location_t m_start; |
1859 source_location m_next_loc; | 1879 location_t m_next_loc; |
1860 char *m_bytes; | 1880 char *m_bytes; |
1861 size_t m_len; | 1881 size_t m_len; |
1862 }; | 1882 }; |
1863 | 1883 |
1864 | 1884 |
1918 returned location. Note that if the returned location wasn't originally | 1938 returned location. Note that if the returned location wasn't originally |
1919 encoded by a map, the *MAP is set to NULL. This can happen if LOC | 1939 encoded by a map, the *MAP is set to NULL. This can happen if LOC |
1920 resolves to a location reserved for the client code, like | 1940 resolves to a location reserved for the client code, like |
1921 UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC. */ | 1941 UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC. */ |
1922 | 1942 |
1923 source_location linemap_resolve_location (struct line_maps *, | 1943 location_t linemap_resolve_location (class line_maps *, |
1924 source_location loc, | 1944 location_t loc, |
1925 enum location_resolution_kind lrk, | 1945 enum location_resolution_kind lrk, |
1926 const line_map_ordinary **loc_map); | 1946 const line_map_ordinary **loc_map); |
1927 | 1947 |
1928 /* Suppose that LOC is the virtual location of a token coming from the | 1948 /* Suppose that LOC is the virtual location of a token coming from the |
1929 expansion of a macro M. This function then steps up to get the | 1949 expansion of a macro M. This function then steps up to get the |
1930 location L of the point where M got expanded. If L is a spelling | 1950 location L of the point where M got expanded. If L is a spelling |
1931 location inside a macro expansion M', then this function returns | 1951 location inside a macro expansion M', then this function returns |
1932 the point where M' was expanded. LOC_MAP is an output parameter. | 1952 the point where M' was expanded. LOC_MAP is an output parameter. |
1933 When non-NULL, *LOC_MAP is set to the map of the returned | 1953 When non-NULL, *LOC_MAP is set to the map of the returned |
1934 location. */ | 1954 location. */ |
1935 source_location linemap_unwind_toward_expansion (struct line_maps *, | 1955 location_t linemap_unwind_toward_expansion (class line_maps *, |
1936 source_location loc, | 1956 location_t loc, |
1937 const struct line_map **loc_map); | 1957 const line_map **loc_map); |
1938 | 1958 |
1939 /* If LOC is the virtual location of a token coming from the expansion | 1959 /* If LOC is the virtual location of a token coming from the expansion |
1940 of a macro M and if its spelling location is reserved (e.g, a | 1960 of a macro M and if its spelling location is reserved (e.g, a |
1941 location for a built-in token), then this function unwinds (using | 1961 location for a built-in token), then this function unwinds (using |
1942 linemap_unwind_toward_expansion) the location until a location that | 1962 linemap_unwind_toward_expansion) the location until a location that |
1948 LOC doesn't come from the expansion of a macro, the function | 1968 LOC doesn't come from the expansion of a macro, the function |
1949 returns LOC as is and *MAP is not touched. | 1969 returns LOC as is and *MAP is not touched. |
1950 | 1970 |
1951 *MAP is set to the map of the returned location if the later is | 1971 *MAP is set to the map of the returned location if the later is |
1952 different from LOC. */ | 1972 different from LOC. */ |
1953 source_location linemap_unwind_to_first_non_reserved_loc (struct line_maps *, | 1973 location_t linemap_unwind_to_first_non_reserved_loc (class line_maps *, |
1954 source_location loc, | 1974 location_t loc, |
1955 const struct line_map **map); | 1975 const line_map **map); |
1956 | 1976 |
1957 /* Expand source code location LOC and return a user readable source | 1977 /* Expand source code location LOC and return a user readable source |
1958 code location. LOC must be a spelling (non-virtual) location. If | 1978 code location. LOC must be a spelling (non-virtual) location. If |
1959 it's a location < RESERVED_LOCATION_COUNT a zeroed expanded source | 1979 it's a location < RESERVED_LOCATION_COUNT a zeroed expanded source |
1960 location is returned. */ | 1980 location is returned. */ |
1961 expanded_location linemap_expand_location (struct line_maps *, | 1981 expanded_location linemap_expand_location (class line_maps *, |
1962 const struct line_map *, | 1982 const line_map *, |
1963 source_location loc); | 1983 location_t loc); |
1964 | 1984 |
1965 /* Statistics about maps allocation and usage as returned by | 1985 /* Statistics about maps allocation and usage as returned by |
1966 linemap_get_statistics. */ | 1986 linemap_get_statistics. */ |
1967 struct linemap_stats | 1987 struct linemap_stats |
1968 { | 1988 { |
1983 | 2003 |
1984 /* Return the highest location emitted for a given file for which | 2004 /* Return the highest location emitted for a given file for which |
1985 there is a line map in SET. FILE_NAME is the file name to | 2005 there is a line map in SET. FILE_NAME is the file name to |
1986 consider. If the function returns TRUE, *LOC is set to the highest | 2006 consider. If the function returns TRUE, *LOC is set to the highest |
1987 location emitted for that file. */ | 2007 location emitted for that file. */ |
1988 bool linemap_get_file_highest_location (struct line_maps * set, | 2008 bool linemap_get_file_highest_location (class line_maps * set, |
1989 const char *file_name, | 2009 const char *file_name, |
1990 source_location *loc); | 2010 location_t *loc); |
1991 | 2011 |
1992 /* Compute and return statistics about the memory consumption of some | 2012 /* Compute and return statistics about the memory consumption of some |
1993 parts of the line table SET. */ | 2013 parts of the line table SET. */ |
1994 void linemap_get_statistics (struct line_maps *, struct linemap_stats *); | 2014 void linemap_get_statistics (line_maps *, struct linemap_stats *); |
1995 | 2015 |
1996 /* Dump debugging information about source location LOC into the file | 2016 /* Dump debugging information about source location LOC into the file |
1997 stream STREAM. SET is the line map set LOC comes from. */ | 2017 stream STREAM. SET is the line map set LOC comes from. */ |
1998 void linemap_dump_location (struct line_maps *, source_location, FILE *); | 2018 void linemap_dump_location (line_maps *, location_t, FILE *); |
1999 | 2019 |
2000 /* Dump line map at index IX in line table SET to STREAM. If STREAM | 2020 /* Dump line map at index IX in line table SET to STREAM. If STREAM |
2001 is NULL, use stderr. IS_MACRO is true if the caller wants to | 2021 is NULL, use stderr. IS_MACRO is true if the caller wants to |
2002 dump a macro map, false otherwise. */ | 2022 dump a macro map, false otherwise. */ |
2003 void linemap_dump (FILE *, struct line_maps *, unsigned, bool); | 2023 void linemap_dump (FILE *, line_maps *, unsigned, bool); |
2004 | 2024 |
2005 /* Dump line table SET to STREAM. If STREAM is NULL, stderr is used. | 2025 /* Dump line table SET to STREAM. If STREAM is NULL, stderr is used. |
2006 NUM_ORDINARY specifies how many ordinary maps to dump. NUM_MACRO | 2026 NUM_ORDINARY specifies how many ordinary maps to dump. NUM_MACRO |
2007 specifies how many macro maps to dump. */ | 2027 specifies how many macro maps to dump. */ |
2008 void line_table_dump (FILE *, struct line_maps *, unsigned int, unsigned int); | 2028 void line_table_dump (FILE *, line_maps *, unsigned int, unsigned int); |
2009 | 2029 |
2010 /* An enum for distinguishing the various parts within a source_location. */ | 2030 /* An enum for distinguishing the various parts within a location_t. */ |
2011 | 2031 |
2012 enum location_aspect | 2032 enum location_aspect |
2013 { | 2033 { |
2014 LOCATION_ASPECT_CARET, | 2034 LOCATION_ASPECT_CARET, |
2015 LOCATION_ASPECT_START, | 2035 LOCATION_ASPECT_START, |
2016 LOCATION_ASPECT_FINISH | 2036 LOCATION_ASPECT_FINISH |
2017 }; | 2037 }; |
2018 | 2038 |
2019 /* The rich_location class requires a way to expand source_location instances. | 2039 /* The rich_location class requires a way to expand location_t instances. |
2020 We would directly use expand_location_to_spelling_point, which is | 2040 We would directly use expand_location_to_spelling_point, which is |
2021 implemented in gcc/input.c, but we also need to use it for rich_location | 2041 implemented in gcc/input.c, but we also need to use it for rich_location |
2022 within genmatch.c. | 2042 within genmatch.c. |
2023 Hence we require client code of libcpp to implement the following | 2043 Hence we require client code of libcpp to implement the following |
2024 symbol. */ | 2044 symbol. */ |
2025 extern expanded_location | 2045 extern expanded_location |
2026 linemap_client_expand_location_to_spelling_point (source_location, | 2046 linemap_client_expand_location_to_spelling_point (location_t, |
2027 enum location_aspect); | 2047 enum location_aspect); |
2028 | 2048 |
2029 #endif /* !LIBCPP_LINE_MAP_H */ | 2049 #endif /* !LIBCPP_LINE_MAP_H */ |