| @@ -1,5 +1,5 @@ |
| 1 | 1 | /* Map (unsigned int) keys to (source file, line, column) triples. |
| 2 | | − Copyright (C) 2001-2018 Free Software Foundation, Inc. |
| 2 | + Copyright (C) 2001-2019 Free Software Foundation, Inc. |
| 3 | 3 | |
| 4 | 4 | This program is free software; you can redistribute it and/or modify it |
| 5 | 5 | under the terms of the GNU General Public License as published by the |
| @@ -49,36 +49,34 @@ along with this program; see the file COPYING3. If not see · 43 unmodified lines |
| 49 | 49 | /* The type of line numbers. */ |
| 50 | 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 | 55 | /* A function for for use by qsort for comparing line numbers. */ |
| 53 | 56 | |
| 54 | 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 | 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 | 62 | if (diff) |
| 60 | 63 | return diff > 0 ? 1 : -1; |
| 61 | 64 | return 0; |
| 62 | 65 | } |
| 63 | 66 | |
| 64 | | −/* Reason for creating a new line map with linemap_add. LC_ENTER is |
| 65 | | − when including a new file, e.g. a #include directive in C. |
| 66 | | − LC_LEAVE is when reaching a file's end. LC_RENAME is when a file |
| 67 | | − name or line number changes for neither of the above reasons |
| 68 | | − (e.g. a #line directive in C); LC_RENAME_VERBATIM is like LC_RENAME |
| 69 | | − but a filename of "" is not specially interpreted as standard |
| 70 | | − input. LC_ENTER_MACRO is when a macro expansion is about to start. */ |
| 67 | +/* Reason for creating a new line map with linemap_add. */ |
| 71 | 68 | enum lc_reason |
| 72 | 69 | { |
| 73 | | − LC_ENTER = 0, |
| 74 | | − LC_LEAVE, |
| 75 | | − LC_RENAME, |
| 76 | | − LC_RENAME_VERBATIM, |
| 77 | | − LC_ENTER_MACRO |
| 70 | + LC_ENTER = 0, /* Begin #include. */ |
| 71 | + LC_LEAVE, /* Return to including file. */ |
| 72 | + LC_RENAME, /* Other reason for name change. */ |
| 73 | + LC_RENAME_VERBATIM, /* Likewise, but "" != stdin. */ |
| 74 | + LC_ENTER_MACRO, /* Begin macro expansion. */ |
| 78 | 75 | /* FIXME: add support for stringize and paste. */ |
| 76 | + LC_HWM /* High Water Mark. */ |
| 79 | 77 | }; |
| 80 | 78 | |
| 81 | | −/* The typedef "source_location" is a key within the location database, |
| 79 | +/* The typedef "location_t" is a key within the location database, |
| 82 | 80 | identifying a source location or macro expansion, along with range |
| 83 | 81 | information, and (optionally) a pointer for use by gcc. |
| 84 | 82 | |
| @@ -168,7 +166,7 @@ enum lc_reason · 83 unmodified lines |
| 168 | 166 | | Beyond this point, ordinary linemaps have 0 bits per column: |
| 169 | 167 | | each increment of the value corresponds to a new source line. |
| 170 | 168 | | |
| 171 | | − 0x70000000 | LINE_MAP_MAX_SOURCE_LOCATION |
| 169 | + 0x70000000 | LINE_MAP_MAX_LOCATION |
| 172 | 170 | | Beyond the point, we give up on ordinary maps; attempts to |
| 173 | 171 | | create locations in them lead to UNKNOWN_LOCATION (0). |
| 174 | 172 | | |
| @@ -187,7 +185,7 @@ enum lc_reason · 12 unmodified lines |
| 187 | 185 | | macromap[1]->start_location | Start of macro map 1 |
| 188 | 186 | -----------+-------------------------------+------------------------------- |
| 189 | 187 | | macromap[0]->start_location | Start of macro map 0 |
| 190 | | − 0x7fffffff | MAX_SOURCE_LOCATION | Also used as a mask for |
| 188 | + 0x7fffffff | MAX_LOCATION_T | Also used as a mask for |
| 191 | 189 | | | accessing the ad-hoc data table |
| 192 | 190 | -----------+-------------------------------+------------------------------- |
| 193 | 191 | 0x80000000 | Start of ad-hoc values; the lower 31 bits are used as an index |
| @@ -288,9 +286,9 @@ enum lc_reason · 94 unmodified lines |
| 288 | 286 | finish == ordmap->start + (23 << 12) + (19 << 5) |
| 289 | 287 | == ordmap->start + 0x17260 |
| 290 | 288 | |
| 291 | | − To further see how source_location works in practice, see the |
| 289 | + To further see how location_t works in practice, see the |
| 292 | 290 | worked example in libcpp/location-example.txt. */ |
| 293 | | −typedef unsigned int source_location; |
| 291 | +typedef unsigned int location_t; |
| 294 | 292 | |
| 295 | 293 | /* Do not track column numbers higher than this one. As a result, the |
| 296 | 294 | range of column_bits is [12, 18] (or 0 if column numbers are |
| @@ -300,12 +298,15 @@ const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 12); · 3 unmodified lines |
| 300 | 298 | /* Do not pack ranges if locations get higher than this. |
| 301 | 299 | If you change this, update: |
| 302 | 300 | gcc.dg/plugin/location-overflow-test-*.c. */ |
| 303 | | −const source_location LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES = 0x50000000; |
| 301 | +const location_t LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES = 0x50000000; |
| 304 | 302 | |
| 305 | 303 | /* Do not track column numbers if locations get higher than this. |
| 306 | 304 | If you change this, update: |
| 307 | 305 | gcc.dg/plugin/location-overflow-test-*.c. */ |
| 308 | | −const source_location LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000; |
| 306 | +const location_t LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000; |
| 307 | + |
| 308 | +/* Highest possible source location encoded within an ordinary map. */ |
| 309 | +const location_t LINE_MAP_MAX_LOCATION = 0x70000000; |
| 309 | 310 | |
| 310 | 311 | /* A range of source locations. |
| 311 | 312 | |
| @@ -317,15 +318,15 @@ const source_location LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000; · 5 unmodified lines |
| 317 | 318 | let's do it the simple way, as a pair. */ |
| 318 | 319 | struct GTY(()) source_range |
| 319 | 320 | { |
| 320 | | − source_location m_start; |
| 321 | | − source_location m_finish; |
| 321 | + location_t m_start; |
| 322 | + location_t m_finish; |
| 322 | 323 | |
| 323 | 324 | /* We avoid using constructors, since various structs that |
| 324 | 325 | don't yet have constructors will embed instances of |
| 325 | 326 | source_range. */ |
| 326 | 327 | |
| 327 | | − /* Make a source_range from a source_location. */ |
| 328 | | − static source_range from_location (source_location loc) |
| 328 | + /* Make a source_range from a location_t. */ |
| 329 | + static source_range from_location (location_t loc) |
| 329 | 330 | { |
| 330 | 331 | source_range result; |
| 331 | 332 | result.m_start = loc; |
| @@ -333,9 +334,9 @@ struct GTY(()) source_range · 1 unmodified line |
| 333 | 334 | return result; |
| 334 | 335 | } |
| 335 | 336 | |
| 336 | | − /* Make a source_range from a pair of source_location. */ |
| 337 | | − static source_range from_locations (source_location start, |
| 338 | | − source_location finish) |
| 337 | + /* Make a source_range from a pair of location_t. */ |
| 338 | + static source_range from_locations (location_t start, |
| 339 | + location_t finish) |
| 339 | 340 | { |
| 340 | 341 | source_range result; |
| 341 | 342 | result.m_start = start; |
| @@ -377,11 +378,13 @@ typedef size_t (*line_map_round_alloc_size_func) (size_t); · 35 unmodified lines |
| 377 | 378 | location of the expansion point of PLUS. That location is mapped in |
| 378 | 379 | the map that is active right before the location of the invocation |
| 379 | 380 | of PLUS. */ |
| 380 | | −struct GTY((tag ("0"), desc ("%h.reason == LC_ENTER_MACRO ? 2 : 1"))) line_map { |
| 381 | | − source_location start_location; |
| 382 | 381 | |
| 383 | | − /* The reason for creation of this line map. */ |
| 384 | | − ENUM_BITFIELD (lc_reason) reason : CHAR_BIT; |
| 382 | +/* This contains GTY mark-up to support precompiled headers. |
| 383 | + line_map is an abstract class, only derived objects exist. */ |
| 384 | +struct GTY((tag ("0"), desc ("MAP_ORDINARY_P (&%h) ? 1 : 2"))) line_map { |
| 385 | + location_t start_location; |
| 386 | + |
| 387 | + /* Size and alignment is (usually) 4 bytes. */ |
| 385 | 388 | }; |
| 386 | 389 | |
| 387 | 390 | /* An ordinary line map encodes physical source locations. Those |
| @@ -395,15 +398,14 @@ struct GTY((tag ("0"), desc ("%h.reason == LC_ENTER_MACRO ? 2 : 1"))) line_map { · 7 unmodified lines |
| 395 | 398 | (The top line is line 1 and the leftmost column is column 1; line/column 0 |
| 396 | 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 | 402 | struct GTY((tag ("1"))) line_map_ordinary : public line_map { |
| 400 | | − const char *to_file; |
| 401 | | − linenum_type to_line; |
| 403 | + /* Base class is 4 bytes. */ |
| 402 | 404 | |
| 403 | | − /* An index into the set that gives the line mapping at whose end |
| 404 | | − the current one was included. File(s) at the bottom of the |
| 405 | | − include stack have this set to -1. */ |
| 406 | | − int included_from; |
| 405 | + /* 4 bytes of integers, each 1 byte for easy extraction/insertion. */ |
| 406 | + |
| 407 | + /* The reason for creation of this line map. */ |
| 408 | + ENUM_BITFIELD (lc_reason) reason : 8; |
| 407 | 409 | |
| 408 | 410 | /* SYSP is one for a system header, two for a C system header file |
| 409 | 411 | that therefore needs to be extern "C" protected in C++, and zero |
| @@ -411,7 +413,7 @@ struct GTY((tag ("1"))) line_map_ordinary : public line_map { · 1 unmodified line |
| 411 | 413 | cpp_buffer. */ |
| 412 | 414 | unsigned char sysp; |
| 413 | 415 | |
| 414 | | − /* 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 |
| 415 | 417 | and ranges. */ |
| 416 | 418 | unsigned int m_column_and_range_bits : 8; |
| 417 | 419 | |
| @@ -429,11 +431,23 @@ struct GTY((tag ("1"))) line_map_ordinary : public line_map { · 11 unmodified lines |
| 429 | 431 | | | (e.g. 7) | (e.g. 5) | |
| 430 | 432 | +-------------------------+-----------------------+-------------------+ */ |
| 431 | 433 | unsigned int m_range_bits : 8; |
| 434 | + |
| 435 | + /* Pointer alignment boundary on both 32 and 64-bit systems. */ |
| 436 | + |
| 437 | + const char *to_file; |
| 438 | + linenum_type to_line; |
| 439 | + |
| 440 | + /* Location from whence this line map was included. For regular |
| 441 | + #includes, this location will be the last location of a map. For |
| 442 | + outermost file, this is 0. */ |
| 443 | + location_t included_from; |
| 444 | + |
| 445 | + /* Size is 20 or 24 bytes, no padding */ |
| 432 | 446 | }; |
| 433 | 447 | |
| 434 | 448 | /* This is the highest possible source location encoded within an |
| 435 | 449 | ordinary or macro map. */ |
| 436 | | −const source_location MAX_SOURCE_LOCATION = 0x7FFFFFFF; |
| 450 | +const location_t MAX_LOCATION_T = 0x7FFFFFFF; |
| 437 | 451 | |
| 438 | 452 | struct cpp_hashnode; |
| 439 | 453 | |
| @@ -443,15 +457,20 @@ struct cpp_hashnode; · 3 unmodified lines |
| 443 | 457 | The offset from START_LOCATION is used to index into |
| 444 | 458 | MACRO_LOCATIONS; this holds the original location of the token. */ |
| 445 | 459 | struct GTY((tag ("2"))) line_map_macro : public line_map { |
| 446 | | − /* The cpp macro which expansion gave birth to this macro map. */ |
| 447 | | − struct cpp_hashnode * GTY ((nested_ptr (union tree_node, |
| 448 | | − "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL", |
| 449 | | − "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"))) |
| 450 | | − macro; |
| 460 | + /* Base is 4 bytes. */ |
| 451 | 461 | |
| 452 | 462 | /* The number of tokens inside the replacement-list of MACRO. */ |
| 453 | 463 | unsigned int n_tokens; |
| 454 | 464 | |
| 465 | + /* Pointer alignment boundary. */ |
| 466 | + |
| 467 | + /* The cpp macro whose expansion gave birth to this macro map. */ |
| 468 | + struct cpp_hashnode * |
| 469 | + GTY ((nested_ptr (union tree_node, |
| 470 | + "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL", |
| 471 | + "%h ? HT_IDENT_TO_GCC_IDENT (HT_NODE (%h)) : NULL"))) |
| 472 | + macro; |
| 473 | + |
| 455 | 474 | /* This array of location is actually an array of pairs of |
| 456 | 475 | locations. The elements inside it thus look like: |
| 457 | 476 | |
| @@ -505,14 +524,16 @@ struct GTY((tag ("2"))) line_map_macro : public line_map { · 47 unmodified lines |
| 505 | 524 | In the example above x1 (for token "+") is going to be the same |
| 506 | 525 | as y1. x0 is the spelling location for the argument token "1", |
| 507 | 526 | and x2 is the spelling location for the argument token "2". */ |
| 508 | | − source_location * GTY((atomic)) macro_locations; |
| 527 | + location_t * GTY((atomic)) macro_locations; |
| 509 | 528 | |
| 510 | 529 | /* This is the location of the expansion point of the current macro |
| 511 | 530 | map. It's the location of the macro name. That location is held |
| 512 | 531 | by the map that was current right before the current one. It |
| 513 | 532 | could have been either a macro or an ordinary map, depending on |
| 514 | 533 | if we are in a nested expansion context not. */ |
| 515 | | − source_location expansion; |
| 534 | + location_t expansion; |
| 535 | + |
| 536 | + /* Size is 20 or 32 (4 bytes padding on 64-bit). */ |
| 516 | 537 | }; |
| 517 | 538 | |
| 518 | 539 | #if CHECKING_P && (GCC_VERSION >= 2007) |
| @@ -540,6 +561,34 @@ struct GTY((tag ("2"))) line_map_macro : public line_map { · 21 unmodified lines |
| 540 | 561 | #define linemap_assert_fails(EXPR) (! (EXPR)) |
| 541 | 562 | #endif |
| 542 | 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 | + |
| 584 | +/* Categorize line map kinds. */ |
| 585 | + |
| 586 | +inline bool |
| 587 | +MAP_ORDINARY_P (const line_map *map) |
| 588 | +{ |
| 589 | + return IS_ORDINARY_LOC (map->start_location); |
| 590 | +} |
| 591 | + |
| 543 | 592 | /* Return TRUE if MAP encodes locations coming from a macro |
| 544 | 593 | replacement-list at macro expansion point. */ |
| 545 | 594 | bool |
| @@ -552,7 +601,7 @@ linemap_macro_expansion_map_p (const struct line_map *); · 6 unmodified lines |
| 552 | 601 | inline line_map_ordinary * |
| 553 | 602 | linemap_check_ordinary (struct line_map *map) |
| 554 | 603 | { |
| 555 | | − linemap_assert (!linemap_macro_expansion_map_p (map)); |
| 604 | + linemap_assert (MAP_ORDINARY_P (map)); |
| 556 | 605 | return (line_map_ordinary *)map; |
| 557 | 606 | } |
| 558 | 607 | |
| @@ -563,7 +612,7 @@ linemap_check_ordinary (struct line_map *map) · 4 unmodified lines |
| 563 | 612 | inline const line_map_ordinary * |
| 564 | 613 | linemap_check_ordinary (const struct line_map *map) |
| 565 | 614 | { |
| 566 | | − linemap_assert (!linemap_macro_expansion_map_p (map)); |
| 615 | + linemap_assert (MAP_ORDINARY_P (map)); |
| 567 | 616 | return (const line_map_ordinary *)map; |
| 568 | 617 | } |
| 569 | 618 | |
| @@ -572,7 +621,7 @@ linemap_check_ordinary (const struct line_map *map) · 2 unmodified lines |
| 572 | 621 | |
| 573 | 622 | inline line_map_macro *linemap_check_macro (line_map *map) |
| 574 | 623 | { |
| 575 | | − linemap_assert (linemap_macro_expansion_map_p (map)); |
| 624 | + linemap_assert (!MAP_ORDINARY_P (map)); |
| 576 | 625 | return (line_map_macro *)map; |
| 577 | 626 | } |
| 578 | 627 | |
| @@ -582,13 +631,13 @@ inline line_map_macro *linemap_check_macro (line_map *map) · 3 unmodified lines |
| 582 | 631 | inline const line_map_macro * |
| 583 | 632 | linemap_check_macro (const line_map *map) |
| 584 | 633 | { |
| 585 | | − linemap_assert (linemap_macro_expansion_map_p (map)); |
| 634 | + linemap_assert (!MAP_ORDINARY_P (map)); |
| 586 | 635 | return (const line_map_macro *)map; |
| 587 | 636 | } |
| 588 | 637 | |
| 589 | 638 | /* Read the start location of MAP. */ |
| 590 | 639 | |
| 591 | | −inline source_location |
| 640 | +inline location_t |
| 592 | 641 | MAP_START_LOCATION (const line_map *map) |
| 593 | 642 | { |
| 594 | 643 | return map->start_location; |
| @@ -602,17 +651,6 @@ ORDINARY_MAP_STARTING_LINE_NUMBER (const line_map_ordinary *ord_map) · 7 unmodified lines |
| 602 | 651 | return ord_map->to_line; |
| 603 | 652 | } |
| 604 | 653 | |
| 605 | | −/* Get the index of the ordinary map at whose end |
| 606 | | − ordinary map MAP was included. |
| 607 | | − |
| 608 | | − File(s) at the bottom of the include stack have this set. */ |
| 609 | | − |
| 610 | | −inline int |
| 611 | | −ORDINARY_MAP_INCLUDER_FILE_INDEX (const line_map_ordinary *ord_map) |
| 612 | | −{ |
| 613 | | − return ord_map->included_from; |
| 614 | | −} |
| 615 | | − |
| 616 | 654 | /* Return a positive value if map encodes locations from a system |
| 617 | 655 | header, 0 otherwise. Returns 1 if ordinary map MAP encodes locations |
| 618 | 656 | in a system header and 2 if it encodes locations in a C system header |
| @@ -652,7 +690,7 @@ MACRO_MAP_NUM_MACRO_TOKENS (const line_map_macro *macro_map) · 33 unmodified lines |
| 652 | 690 | /* Get the array of pairs of locations within macro map MAP. |
| 653 | 691 | See the declaration of line_map_macro for more information. */ |
| 654 | 692 | |
| 655 | | −inline source_location * |
| 693 | +inline location_t * |
| 656 | 694 | MACRO_MAP_LOCATIONS (const line_map_macro *macro_map) |
| 657 | 695 | { |
| 658 | 696 | return macro_map->macro_locations; |
| @@ -660,7 +698,7 @@ MACRO_MAP_LOCATIONS (const line_map_macro *macro_map) · 1 unmodified line |
| 660 | 698 | |
| 661 | 699 | /* Get the location of the expansion point of the macro map MAP. */ |
| 662 | 700 | |
| 663 | | −inline source_location |
| 701 | +inline location_t |
| 664 | 702 | MACRO_MAP_EXPANSION_POINT_LOCATION (const line_map_macro *macro_map) |
| 665 | 703 | { |
| 666 | 704 | return macro_map->expansion; |
| @@ -707,7 +745,7 @@ struct GTY(()) maps_info_macro { · 40 unmodified lines |
| 707 | 745 | /* Data structure to associate a source_range together with an arbitrary |
| 708 | 746 | data pointer with a source location. */ |
| 709 | 747 | struct GTY(()) location_adhoc_data { |
| 710 | | − source_location locus; |
| 748 | + location_t locus; |
| 711 | 749 | source_range src_range; |
| 712 | 750 | void * GTY((skip)) data; |
| 713 | 751 | }; |
| @@ -726,7 +764,7 @@ struct htab; · 12 unmodified lines |
| 726 | 764 | |
| 727 | 765 | struct GTY(()) location_adhoc_data_map { |
| 728 | 766 | struct htab * GTY((skip)) htab; |
| 729 | | − source_location curr_loc; |
| 767 | + location_t curr_loc; |
| 730 | 768 | unsigned int allocated; |
| 731 | 769 | struct location_adhoc_data GTY((length ("%h.allocated"))) *data; |
| 732 | 770 | }; |
| @@ -746,18 +784,17 @@ struct GTY(()) line_maps { · 13 unmodified lines |
| 746 | 784 | /* If true, prints an include trace a la -H. */ |
| 747 | 785 | bool trace_includes; |
| 748 | 786 | |
| 749 | | − /* Highest source_location "given out". */ |
| 750 | | − source_location highest_location; |
| 787 | + /* Highest location_t "given out". */ |
| 788 | + location_t highest_location; |
| 751 | 789 | |
| 752 | | − /* Start of line of highest source_location "given out". */ |
| 753 | | − source_location highest_line; |
| 790 | + /* Start of line of highest location_t "given out". */ |
| 791 | + location_t highest_line; |
| 754 | 792 | |
| 755 | 793 | /* The maximum column number we can quickly allocate. Higher numbers |
| 756 | 794 | may require allocating a new line_map. */ |
| 757 | 795 | unsigned int max_column_hint; |
| 758 | 796 | |
| 759 | | − /* If non-null, the allocator to use when resizing 'maps'. If null, |
| 760 | | − xrealloc is used. */ |
| 797 | + /* The allocator to use when resizing 'maps', defaults to xrealloc. */ |
| 761 | 798 | line_map_realloc reallocator; |
| 762 | 799 | |
| 763 | 800 | /* The allocators' function used to know the actual size it |
| @@ -768,7 +805,7 @@ struct GTY(()) line_maps { · 4 unmodified lines |
| 768 | 805 | |
| 769 | 806 | /* The special location value that is used as spelling location for |
| 770 | 807 | built-in tokens. */ |
| 771 | | − source_location builtin_location; |
| 808 | + location_t builtin_location; |
| 772 | 809 | |
| 773 | 810 | /* True if we've seen a #line or # 44 "file" directive. */ |
| 774 | 811 | bool seen_line_directive; |
| @@ -998,12 +1035,12 @@ LINEMAPS_LAST_MACRO_MAP (const line_maps *set) · 223 unmodified lines |
| 998 | 1035 | |
| 999 | 1036 | /* Returns the lowest location [of a token resulting from macro |
| 1000 | 1037 | expansion] encoded in this line table. */ |
| 1001 | | −inline source_location |
| 1038 | +inline location_t |
| 1002 | 1039 | LINEMAPS_MACRO_LOWEST_LOCATION (const line_maps *set) |
| 1003 | 1040 | { |
| 1004 | 1041 | return LINEMAPS_MACRO_USED (set) |
| 1005 | 1042 | ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set)) |
| 1006 | | − : MAX_SOURCE_LOCATION; |
| 1043 | + : MAX_LOCATION_T + 1; |
| 1007 | 1044 | } |
| 1008 | 1045 | |
| 1009 | 1046 | /* Returns the last macro map allocated in the line table SET. */ |
| @@ -1013,41 +1050,33 @@ LINEMAPS_LAST_ALLOCATED_MACRO_MAP (const line_maps *set) · 3 unmodified lines |
| 1013 | 1050 | return (line_map_macro *)LINEMAPS_LAST_ALLOCATED_MAP (set, true); |
| 1014 | 1051 | } |
| 1015 | 1052 | |
| 1016 | | −extern source_location get_combined_adhoc_loc (struct line_maps *, |
| 1017 | | − source_location, |
| 1053 | +extern location_t get_combined_adhoc_loc (struct line_maps *, |
| 1054 | + location_t, |
| 1018 | 1055 | source_range, |
| 1019 | 1056 | void *); |
| 1020 | | −extern void *get_data_from_adhoc_loc (struct line_maps *, source_location); |
| 1021 | | −extern source_location get_location_from_adhoc_loc (struct line_maps *, |
| 1022 | | − source_location); |
| 1057 | +extern void *get_data_from_adhoc_loc (struct line_maps *, location_t); |
| 1058 | +extern location_t get_location_from_adhoc_loc (struct line_maps *, |
| 1059 | + location_t); |
| 1023 | 1060 | |
| 1024 | | −extern source_range get_range_from_loc (line_maps *set, source_location loc); |
| 1025 | | − |
| 1026 | | −/* Get whether location LOC is an ad-hoc location. */ |
| 1027 | | − |
| 1028 | | −inline bool |
| 1029 | | −IS_ADHOC_LOC (source_location loc) |
| 1030 | | −{ |
| 1031 | | − return (loc & MAX_SOURCE_LOCATION) != loc; |
| 1032 | | −} |
| 1061 | +extern source_range get_range_from_loc (line_maps *set, location_t loc); |
| 1033 | 1062 | |
| 1034 | 1063 | /* Get whether location LOC is a "pure" location, or |
| 1035 | 1064 | whether it is an ad-hoc location, or embeds range information. */ |
| 1036 | 1065 | |
| 1037 | 1066 | bool |
| 1038 | | −pure_location_p (line_maps *set, source_location loc); |
| 1067 | +pure_location_p (line_maps *set, location_t loc); |
| 1039 | 1068 | |
| 1040 | 1069 | /* Given location LOC within SET, strip away any packed range information |
| 1041 | 1070 | or ad-hoc information. */ |
| 1042 | 1071 | |
| 1043 | | −extern source_location get_pure_location (line_maps *set, |
| 1044 | | − source_location loc); |
| 1072 | +extern location_t get_pure_location (line_maps *set, |
| 1073 | + location_t loc); |
| 1045 | 1074 | |
| 1046 | 1075 | /* Combine LOC and BLOCK, giving a combined adhoc location. */ |
| 1047 | 1076 | |
| 1048 | | −inline source_location |
| 1077 | +inline location_t |
| 1049 | 1078 | COMBINE_LOCATION_DATA (struct line_maps *set, |
| 1050 | | − source_location loc, |
| 1079 | + location_t loc, |
| 1051 | 1080 | source_range src_range, |
| 1052 | 1081 | void *block) |
| 1053 | 1082 | { |
| @@ -1061,19 +1090,19 @@ extern void rebuild_location_adhoc_htab (struct line_maps *); · 7 unmodified lines |
| 1061 | 1090 | spelling location for built-in tokens. This BUILTIN_LOCATION has |
| 1062 | 1091 | to be strictly less than RESERVED_LOCATION_COUNT. */ |
| 1063 | 1092 | extern void linemap_init (struct line_maps *set, |
| 1064 | | − source_location builtin_location); |
| 1093 | + location_t builtin_location); |
| 1065 | 1094 | |
| 1066 | 1095 | /* Check for and warn about line_maps entered but not exited. */ |
| 1067 | 1096 | |
| 1068 | 1097 | extern void linemap_check_files_exited (struct line_maps *); |
| 1069 | 1098 | |
| 1070 | | −/* Return a source_location for the start (i.e. column==0) of |
| 1099 | +/* Return a location_t for the start (i.e. column==0) of |
| 1071 | 1100 | (physical) line TO_LINE in the current source file (as in the |
| 1072 | 1101 | most recent linemap_add). MAX_COLUMN_HINT is the highest column |
| 1073 | 1102 | number we expect to use in this line (but it does not change |
| 1074 | 1103 | the highest_location). */ |
| 1075 | 1104 | |
| 1076 | | −extern source_location linemap_line_start |
| 1105 | +extern location_t linemap_line_start |
| 1077 | 1106 | (struct line_maps *set, linenum_type to_line, unsigned int max_column_hint); |
| 1078 | 1107 | |
| 1079 | 1108 | /* Add a mapping of logical source line to physical source file and |
| @@ -1100,7 +1129,7 @@ extern const struct line_map *linemap_add · 20 unmodified lines |
| 1100 | 1129 | binary search. If no line map have been allocated yet, this |
| 1101 | 1130 | function returns NULL. */ |
| 1102 | 1131 | extern const struct line_map *linemap_lookup |
| 1103 | | − (struct line_maps *, source_location); |
| 1132 | + (struct line_maps *, location_t); |
| 1104 | 1133 | |
| 1105 | 1134 | /* Returns TRUE if the line table set tracks token locations across |
| 1106 | 1135 | macro expansion, FALSE otherwise. */ |
| @@ -1119,114 +1148,86 @@ const char* linemap_map_get_macro_name (const line_map_macro *); · 12 unmodified lines |
| 1119 | 1148 | that is part of a macro replacement-list defined in a system |
| 1120 | 1149 | header, but expanded in a non-system file. */ |
| 1121 | 1150 | int linemap_location_in_system_header_p (struct line_maps *, |
| 1122 | | − source_location); |
| 1151 | + location_t); |
| 1123 | 1152 | |
| 1124 | 1153 | /* Return TRUE if LOCATION is a source code location of a token that is part of |
| 1125 | 1154 | a macro expansion, FALSE otherwise. */ |
| 1126 | 1155 | bool linemap_location_from_macro_expansion_p (const struct line_maps *, |
| 1127 | | − source_location); |
| 1156 | + location_t); |
| 1128 | 1157 | |
| 1129 | 1158 | /* TRUE if LOCATION is a source code location of a token that is part of the |
| 1130 | 1159 | definition of a macro, FALSE otherwise. */ |
| 1131 | 1160 | bool linemap_location_from_macro_definition_p (struct line_maps *, |
| 1132 | | − source_location); |
| 1161 | + location_t); |
| 1133 | 1162 | |
| 1134 | 1163 | /* With the precondition that LOCATION is the locus of a token that is |
| 1135 | 1164 | an argument of a function-like macro MACRO_MAP and appears in the |
| 1136 | 1165 | expansion of MACRO_MAP, return the locus of that argument in the |
| 1137 | 1166 | context of the caller of MACRO_MAP. */ |
| 1138 | 1167 | |
| 1139 | | −extern source_location linemap_macro_map_loc_unwind_toward_spelling |
| 1140 | | − (line_maps *set, const line_map_macro *macro_map, source_location location); |
| 1168 | +extern location_t linemap_macro_map_loc_unwind_toward_spelling |
| 1169 | + (line_maps *set, const line_map_macro *macro_map, location_t location); |
| 1141 | 1170 | |
| 1142 | | −/* source_location values from 0 to RESERVED_LOCATION_COUNT-1 will |
| 1171 | +/* location_t values from 0 to RESERVED_LOCATION_COUNT-1 will |
| 1143 | 1172 | be reserved for libcpp user as special values, no token from libcpp |
| 1144 | 1173 | will contain any of those locations. */ |
| 1145 | | −const source_location RESERVED_LOCATION_COUNT = 2; |
| 1174 | +const location_t RESERVED_LOCATION_COUNT = 2; |
| 1146 | 1175 | |
| 1147 | | −/* Converts a map and a source_location to source line. */ |
| 1176 | +/* Converts a map and a location_t to source line. */ |
| 1148 | 1177 | inline linenum_type |
| 1149 | | −SOURCE_LINE (const line_map_ordinary *ord_map, source_location loc) |
| 1178 | +SOURCE_LINE (const line_map_ordinary *ord_map, location_t loc) |
| 1150 | 1179 | { |
| 1151 | 1180 | return ((loc - ord_map->start_location) |
| 1152 | 1181 | >> ord_map->m_column_and_range_bits) + ord_map->to_line; |
| 1153 | 1182 | } |
| 1154 | 1183 | |
| 1155 | | −/* Convert a map and source_location to source column number. */ |
| 1184 | +/* Convert a map and location_t to source column number. */ |
| 1156 | 1185 | inline linenum_type |
| 1157 | | −SOURCE_COLUMN (const line_map_ordinary *ord_map, source_location loc) |
| 1186 | +SOURCE_COLUMN (const line_map_ordinary *ord_map, location_t loc) |
| 1158 | 1187 | { |
| 1159 | 1188 | return ((loc - ord_map->start_location) |
| 1160 | 1189 | & ((1 << ord_map->m_column_and_range_bits) - 1)) >> ord_map->m_range_bits; |
| 1161 | 1190 | } |
| 1162 | 1191 | |
| 1163 | | −/* Return the location of the last source line within an ordinary |
| 1164 | | − map. */ |
| 1165 | | −inline source_location |
| 1166 | | −LAST_SOURCE_LINE_LOCATION (const line_map_ordinary *map) |
| 1167 | | −{ |
| 1168 | | − return (((map[1].start_location - 1 |
| 1169 | | − - map->start_location) |
| 1170 | | − & ~((1 << map->m_column_and_range_bits) - 1)) |
| 1171 | | − + map->start_location); |
| 1172 | | −} |
| 1173 | | − |
| 1174 | | −/* Returns the last source line number within an ordinary map. This |
| 1175 | | − is the (last) line of the #include, or other directive, that caused |
| 1176 | | − a map change. */ |
| 1177 | | −inline linenum_type |
| 1178 | | −LAST_SOURCE_LINE (const line_map_ordinary *map) |
| 1179 | | −{ |
| 1180 | | − return SOURCE_LINE (map, LAST_SOURCE_LINE_LOCATION (map)); |
| 1181 | | −} |
| 1182 | | − |
| 1183 | | −/* Return the last column number within an ordinary map. */ |
| 1184 | 1192 | |
| 1185 | | −inline linenum_type |
| 1186 | | −LAST_SOURCE_COLUMN (const line_map_ordinary *map) |
| 1193 | +inline location_t |
| 1194 | +linemap_included_from (const line_map_ordinary *ord_map) |
| 1187 | 1195 | { |
| 1188 | | − return SOURCE_COLUMN (map, LAST_SOURCE_LINE_LOCATION (map)); |
| 1196 | + return ord_map->included_from; |
| 1189 | 1197 | } |
| 1190 | 1198 | |
| 1191 | | −/* Returns the map a given map was included from, or NULL if the map |
| 1192 | | − belongs to the main file, i.e, a file that wasn't included by |
| 1193 | | − another one. */ |
| 1194 | | −inline line_map_ordinary * |
| 1195 | | −INCLUDED_FROM (struct line_maps *set, const line_map_ordinary *ord_map) |
| 1196 | | −{ |
| 1197 | | − return ((ord_map->included_from == -1) |
| 1198 | | − ? NULL |
| 1199 | | − : LINEMAPS_ORDINARY_MAP_AT (set, ord_map->included_from)); |
| 1200 | | −} |
| 1199 | +/* The linemap containing the included-from location of MAP. */ |
| 1200 | +const line_map_ordinary *linemap_included_from_linemap |
| 1201 | + (line_maps *set, const line_map_ordinary *map); |
| 1201 | 1202 | |
| 1202 | 1203 | /* True if the map is at the bottom of the include stack. */ |
| 1203 | 1204 | |
| 1204 | 1205 | inline bool |
| 1205 | 1206 | MAIN_FILE_P (const line_map_ordinary *ord_map) |
| 1206 | 1207 | { |
| 1207 | | − return ord_map->included_from < 0; |
| 1208 | + return ord_map->included_from == 0; |
| 1208 | 1209 | } |
| 1209 | 1210 | |
| 1210 | | −/* Encode and return a source_location from a column number. The |
| 1211 | +/* Encode and return a location_t from a column number. The |
| 1211 | 1212 | source line considered is the last source line used to call |
| 1212 | 1213 | linemap_line_start, i.e, the last source line which a location was |
| 1213 | 1214 | encoded from. */ |
| 1214 | | −extern source_location |
| 1215 | +extern location_t |
| 1215 | 1216 | linemap_position_for_column (struct line_maps *, unsigned int); |
| 1216 | 1217 | |
| 1217 | 1218 | /* Encode and return a source location from a given line and |
| 1218 | 1219 | column. */ |
| 1219 | | −source_location |
| 1220 | +location_t |
| 1220 | 1221 | linemap_position_for_line_and_column (line_maps *set, |
| 1221 | 1222 | const line_map_ordinary *, |
| 1222 | 1223 | linenum_type, unsigned int); |
| 1223 | 1224 | |
| 1224 | | −/* Encode and return a source_location starting from location LOC and |
| 1225 | +/* Encode and return a location_t starting from location LOC and |
| 1225 | 1226 | shifting it by OFFSET columns. This function does not support |
| 1226 | 1227 | virtual locations. */ |
| 1227 | | −source_location |
| 1228 | +location_t |
| 1228 | 1229 | linemap_position_for_loc_and_offset (struct line_maps *set, |
| 1229 | | − source_location loc, |
| 1230 | + location_t loc, |
| 1230 | 1231 | unsigned int offset); |
| 1231 | 1232 | |
| 1232 | 1233 | /* Return the file this map is for. */ |
| @@ -1258,16 +1259,16 @@ LINEMAP_SYSP (const line_map_ordinary *ord_map) · 25 unmodified lines |
| 1258 | 1259 | the same token as the token for POST, and a negative value |
| 1259 | 1260 | otherwise. */ |
| 1260 | 1261 | int linemap_compare_locations (struct line_maps *set, |
| 1261 | | − source_location pre, |
| 1262 | | − source_location post); |
| 1262 | + location_t pre, |
| 1263 | + location_t post); |
| 1263 | 1264 | |
| 1264 | 1265 | /* Return TRUE if LOC_A denotes the location a token that comes |
| 1265 | 1266 | topogically before the token denoted by location LOC_B, or if they |
| 1266 | 1267 | are equal. */ |
| 1267 | 1268 | inline bool |
| 1268 | 1269 | linemap_location_before_p (struct line_maps *set, |
| 1269 | | − source_location loc_a, |
| 1270 | | − source_location loc_b) |
| 1270 | + location_t loc_a, |
| 1271 | + location_t loc_b) |
| 1271 | 1272 | { |
| 1272 | 1273 | return linemap_compare_locations (set, loc_a, loc_b) >= 0; |
| 1273 | 1274 | } |
| @@ -1288,23 +1289,50 @@ typedef struct · 14 unmodified lines |
| 1288 | 1289 | bool sysp; |
| 1289 | 1290 | } expanded_location; |
| 1290 | 1291 | |
| 1291 | | −/* A location within a rich_location: a caret&range, with |
| 1292 | | − the caret potentially flagged for display. */ |
| 1292 | +class range_label; |
| 1293 | 1293 | |
| 1294 | | −struct location_range |
| 1295 | | −{ |
| 1296 | | − source_location m_loc; |
| 1294 | +/* A hint to diagnostic_show_locus on how to print a source range within a |
| 1295 | + rich_location. |
| 1297 | 1296 | |
| 1298 | | − /* Should a caret be drawn for this range? Typically this is |
| 1299 | | − true for the 0th range, and false for subsequent ranges, |
| 1300 | | − but the Fortran frontend overrides this for rendering things like: |
| 1297 | + Typically this is SHOW_RANGE_WITH_CARET for the 0th range, and |
| 1298 | + SHOW_RANGE_WITHOUT_CARET for subsequent ranges, |
| 1299 | + but the Fortran frontend uses SHOW_RANGE_WITH_CARET repeatedly for |
| 1300 | + printing things like: |
| 1301 | 1301 | |
| 1302 | 1302 | x = x + y |
| 1303 | 1303 | 1 2 |
| 1304 | 1304 | Error: Shapes for operands at (1) and (2) are not conformable |
| 1305 | 1305 | |
| 1306 | | − where "1" and "2" are notionally carets. */ |
| 1307 | | − bool m_show_caret_p; |
| 1306 | + where "1" and "2" are notionally carets. */ |
| 1307 | + |
| 1308 | +enum range_display_kind |
| 1309 | +{ |
| 1310 | + /* Show the pertinent source line(s), the caret, and underline(s). */ |
| 1311 | + SHOW_RANGE_WITH_CARET, |
| 1312 | + |
| 1313 | + /* Show the pertinent source line(s) and underline(s), but don't |
| 1314 | + show the caret (just an underline). */ |
| 1315 | + SHOW_RANGE_WITHOUT_CARET, |
| 1316 | + |
| 1317 | + /* Just show the source lines; don't show the range itself. |
| 1318 | + This is for use when displaying some line-insertion fix-it hints (for |
| 1319 | + showing the user context on the change, for when it doesn't make sense |
| 1320 | + to highlight the first column on the next line). */ |
| 1321 | + SHOW_LINES_WITHOUT_RANGE |
| 1322 | +}; |
| 1323 | + |
| 1324 | +/* A location within a rich_location: a caret&range, with |
| 1325 | + the caret potentially flagged for display, and an optional |
| 1326 | + label. */ |
| 1327 | + |
| 1328 | +struct location_range |
| 1329 | +{ |
| 1330 | + location_t m_loc; |
| 1331 | + |
| 1332 | + enum range_display_kind m_range_display_kind; |
| 1333 | + |
| 1334 | + /* If non-NULL, the label for this range. */ |
| 1335 | + const range_label *m_label; |
| 1308 | 1336 | }; |
| 1309 | 1337 | |
| 1310 | 1338 | /* A partially-embedded vec for use within rich_location for storing |
| @@ -1446,6 +1474,8 @@ class fixit_hint; · 135 unmodified lines |
| 1446 | 1474 | Additional ranges may be added to help the user identify other |
| 1447 | 1475 | pertinent clauses in a diagnostic. |
| 1448 | 1476 | |
| 1477 | + Ranges can (optionally) be given labels via class range_label. |
| 1478 | + |
| 1449 | 1479 | rich_location instances are intended to be allocated on the stack |
| 1450 | 1480 | when generating diagnostics, and to be short-lived. |
| 1451 | 1481 | |
| @@ -1491,18 +1521,22 @@ class fixit_hint; · 39 unmodified lines |
| 1491 | 1521 | equal to their caret point. The frontend overrides the diagnostic |
| 1492 | 1522 | context's default caret character for these ranges. |
| 1493 | 1523 | |
| 1494 | | − Example E |
| 1495 | | − ********* |
| 1524 | + Example E (range labels) |
| 1525 | + ************************ |
| 1496 | 1526 | printf ("arg0: %i arg1: %s arg2: %i", |
| 1497 | 1527 | ^~ |
| 1528 | + | |
| 1529 | + const char * |
| 1498 | 1530 | 100, 101, 102); |
| 1499 | 1531 | ~~~ |
| 1532 | + | |
| 1533 | + int |
| 1500 | 1534 | This rich location has two ranges: |
| 1501 | 1535 | - range 0 is at the "%s" with start = caret = "%" and finish at |
| 1502 | | − the "s". |
| 1536 | + the "s". It has a range_label ("const char *"). |
| 1503 | 1537 | - range 1 has start/finish covering the "101" and is not flagged for |
| 1504 | | − caret printing; it is perhaps at the start of "101". |
| 1505 | | − |
| 1538 | + caret printing. The caret is at the start of "101", where its |
| 1539 | + range_label is printed ("int"). |
| 1506 | 1540 | |
| 1507 | 1541 | Fix-it hints |
| 1508 | 1542 | ------------ |
| @@ -1562,9 +1596,21 @@ class fixit_hint; · 53 unmodified lines |
| 1562 | 1596 | added via |
| 1563 | 1597 | richloc.add_fixit_replace ("color"); |
| 1564 | 1598 | |
| 1599 | + Example J: fix-it hint: line insertion |
| 1600 | + ************************************** |
| 1601 | + |
| 1602 | + 3 | #include <stddef.h> |
| 1603 | + + |+#include <stdio.h> |
| 1604 | + 4 | int the_next_line; |
| 1605 | + |
| 1606 | + This rich location has a single range at line 4 column 1, marked |
| 1607 | + with SHOW_LINES_WITHOUT_RANGE (to avoid printing a meaningless caret |
| 1608 | + on the "i" of int). It has a insertion fix-it hint of the string |
| 1609 | + "#include <stdio.h>\n". |
| 1610 | + |
| 1565 | 1611 | Adding a fix-it hint can fail: for example, attempts to insert content |
| 1566 | 1612 | at the transition between two line maps may fail due to there being no |
| 1567 | | − source_location (aka location_t) value to express the new location. |
| 1613 | + location_t value to express the new location. |
| 1568 | 1614 | |
| 1569 | 1615 | Attempts to add a fix-it hint within a macro expansion will fail. |
| 1570 | 1616 | |
| @@ -1594,21 +1640,25 @@ class rich_location · 23 unmodified lines |
| 1594 | 1640 | /* Constructors. */ |
| 1595 | 1641 | |
| 1596 | 1642 | /* Constructing from a location. */ |
| 1597 | | − rich_location (line_maps *set, source_location loc); |
| 1643 | + rich_location (line_maps *set, location_t loc, |
| 1644 | + const range_label *label = NULL); |
| 1598 | 1645 | |
| 1599 | 1646 | /* Destructor. */ |
| 1600 | 1647 | ~rich_location (); |
| 1601 | 1648 | |
| 1602 | 1649 | /* Accessors. */ |
| 1603 | | − source_location get_loc () const { return get_loc (0); } |
| 1604 | | − source_location get_loc (unsigned int idx) const; |
| 1650 | + location_t get_loc () const { return get_loc (0); } |
| 1651 | + location_t get_loc (unsigned int idx) const; |
| 1605 | 1652 | |
| 1606 | 1653 | void |
| 1607 | | − add_range (source_location loc, bool show_caret_p); |
| 1654 | + add_range (location_t loc, |
| 1655 | + enum range_display_kind range_display_kind |
| 1656 | + = SHOW_RANGE_WITHOUT_CARET, |
| 1657 | + const range_label *label = NULL); |
| 1608 | 1658 | |
| 1609 | 1659 | void |
| 1610 | | − set_range (line_maps *set, unsigned int idx, source_location loc, |
| 1611 | | − bool show_caret_p); |
| 1660 | + set_range (unsigned int idx, location_t loc, |
| 1661 | + enum range_display_kind range_display_kind); |
| 1612 | 1662 | |
| 1613 | 1663 | unsigned int get_num_locations () const { return m_ranges.count (); } |
| 1614 | 1664 | |
| @@ -1631,7 +1681,7 @@ class rich_location · 16 unmodified lines |
| 1631 | 1681 | |
| 1632 | 1682 | /* Suggest inserting NEW_CONTENT immediately before the start of WHERE. */ |
| 1633 | 1683 | void |
| 1634 | | − add_fixit_insert_before (source_location where, |
| 1684 | + add_fixit_insert_before (location_t where, |
| 1635 | 1685 | const char *new_content); |
| 1636 | 1686 | |
| 1637 | 1687 | /* Suggest inserting NEW_CONTENT immediately after the end of the primary |
| @@ -1641,7 +1691,7 @@ class rich_location · 3 unmodified lines |
| 1641 | 1691 | |
| 1642 | 1692 | /* Suggest inserting NEW_CONTENT immediately after the end of WHERE. */ |
| 1643 | 1693 | void |
| 1644 | | − add_fixit_insert_after (source_location where, |
| 1694 | + add_fixit_insert_after (location_t where, |
| 1645 | 1695 | const char *new_content); |
| 1646 | 1696 | |
| 1647 | 1697 | /* Methods for adding removal fix-it hints. */ |
| @@ -1653,7 +1703,7 @@ class rich_location · 5 unmodified lines |
| 1653 | 1703 | /* Suggest removing the content covered between the start and finish |
| 1654 | 1704 | of WHERE. */ |
| 1655 | 1705 | void |
| 1656 | | − add_fixit_remove (source_location where); |
| 1706 | + add_fixit_remove (location_t where); |
| 1657 | 1707 | |
| 1658 | 1708 | /* Suggest removing the content covered by SRC_RANGE. */ |
| 1659 | 1709 | void |
| @@ -1668,7 +1718,7 @@ class rich_location · 8 unmodified lines |
| 1668 | 1718 | /* Suggest replacing the content between the start and finish of |
| 1669 | 1719 | WHERE with NEW_CONTENT. */ |
| 1670 | 1720 | void |
| 1671 | | − add_fixit_replace (source_location where, |
| 1721 | + add_fixit_replace (location_t where, |
| 1672 | 1722 | const char *new_content); |
| 1673 | 1723 | |
| 1674 | 1724 | /* Suggest replacing the content covered by SRC_RANGE with |
| @@ -1704,10 +1754,10 @@ class rich_location · 29 unmodified lines |
| 1704 | 1754 | } |
| 1705 | 1755 | |
| 1706 | 1756 | private: |
| 1707 | | − bool reject_impossible_fixit (source_location where); |
| 1757 | + bool reject_impossible_fixit (location_t where); |
| 1708 | 1758 | void stop_supporting_fixits (); |
| 1709 | | − void maybe_add_fixit (source_location start, |
| 1710 | | − source_location next_loc, |
| 1759 | + void maybe_add_fixit (location_t start, |
| 1760 | + location_t next_loc, |
| 1711 | 1761 | const char *new_content); |
| 1712 | 1762 | |
| 1713 | 1763 | public: |
| @@ -1729,6 +1779,56 @@ protected: · 15 unmodified lines |
| 1729 | 1779 | bool m_fixits_cannot_be_auto_applied; |
| 1730 | 1780 | }; |
| 1731 | 1781 | |
| 1782 | +/* A struct for the result of range_label::get_text: a NUL-terminated buffer |
| 1783 | + of localized text, and a flag to determine if the caller should "free" the |
| 1784 | + buffer. */ |
| 1785 | + |
| 1786 | +struct label_text |
| 1787 | +{ |
| 1788 | + label_text () |
| 1789 | + : m_buffer (NULL), m_caller_owned (false) |
| 1790 | + {} |
| 1791 | + |
| 1792 | + label_text (char *buffer, bool caller_owned) |
| 1793 | + : m_buffer (buffer), m_caller_owned (caller_owned) |
| 1794 | + {} |
| 1795 | + |
| 1796 | + void maybe_free () |
| 1797 | + { |
| 1798 | + if (m_caller_owned) |
| 1799 | + free (m_buffer); |
| 1800 | + } |
| 1801 | + |
| 1802 | + char *m_buffer; |
| 1803 | + bool m_caller_owned; |
| 1804 | +}; |
| 1805 | + |
| 1806 | +/* Abstract base class for labelling a range within a rich_location |
| 1807 | + (e.g. for labelling expressions with their type). |
| 1808 | + |
| 1809 | + Generating the text could require non-trivial work, so this work |
| 1810 | + is delayed (via the "get_text" virtual function) until the diagnostic |
| 1811 | + printing code "knows" it needs it, thus avoiding doing it e.g. for |
| 1812 | + warnings that are filtered by command-line flags. This virtual |
| 1813 | + function also isolates libcpp and the diagnostics subsystem from |
| 1814 | + the front-end and middle-end-specific code for generating the text |
| 1815 | + for the labels. |
| 1816 | + |
| 1817 | + Like the rich_location instances they annotate, range_label instances |
| 1818 | + are intended to be allocated on the stack when generating diagnostics, |
| 1819 | + and to be short-lived. */ |
| 1820 | + |
| 1821 | +class range_label |
| 1822 | +{ |
| 1823 | + public: |
| 1824 | + virtual ~range_label () {} |
| 1825 | + |
| 1826 | + /* Get localized text for the label. |
| 1827 | + The RANGE_IDX is provided, allowing for range_label instances to be |
| 1828 | + shared by multiple ranges if need be (the "flyweight" design pattern). */ |
| 1829 | + virtual label_text get_text (unsigned range_idx) const = 0; |
| 1830 | +}; |
| 1831 | + |
| 1732 | 1832 | /* A fix-it hint: a suggested insertion, replacement, or deletion of text. |
| 1733 | 1833 | We handle these three types of edit with one class, by representing |
| 1734 | 1834 | them as replacement of a half-open range: |
| @@ -1746,16 +1846,16 @@ protected: · 11 unmodified lines |
| 1746 | 1846 | class fixit_hint |
| 1747 | 1847 | { |
| 1748 | 1848 | public: |
| 1749 | | − fixit_hint (source_location start, |
| 1750 | | − source_location next_loc, |
| 1849 | + fixit_hint (location_t start, |
| 1850 | + location_t next_loc, |
| 1751 | 1851 | const char *new_content); |
| 1752 | 1852 | ~fixit_hint () { free (m_bytes); } |
| 1753 | 1853 | |
| 1754 | 1854 | bool affects_line_p (const char *file, int line) const; |
| 1755 | | − source_location get_start_loc () const { return m_start; } |
| 1756 | | − source_location get_next_loc () const { return m_next_loc; } |
| 1757 | | − bool maybe_append (source_location start, |
| 1758 | | − source_location next_loc, |
| 1855 | + location_t get_start_loc () const { return m_start; } |
| 1856 | + location_t get_next_loc () const { return m_next_loc; } |
| 1857 | + bool maybe_append (location_t start, |
| 1858 | + location_t next_loc, |
| 1759 | 1859 | const char *new_content); |
| 1760 | 1860 | |
| 1761 | 1861 | const char *get_string () const { return m_bytes; } |
| @@ -1770,8 +1870,8 @@ class fixit_hint · 8 unmodified lines |
| 1770 | 1870 | this is a half-open/half-closed range: |
| 1771 | 1871 | [start, next_loc) |
| 1772 | 1872 | so that we can support insertion via start == next_loc. */ |
| 1773 | | − source_location m_start; |
| 1774 | | − source_location m_next_loc; |
| 1873 | + location_t m_start; |
| 1874 | + location_t m_next_loc; |
| 1775 | 1875 | char *m_bytes; |
| 1776 | 1876 | size_t m_len; |
| 1777 | 1877 | }; |
| @@ -1835,10 +1935,10 @@ enum location_resolution_kind · 57 unmodified lines |
| 1835 | 1935 | resolves to a location reserved for the client code, like |
| 1836 | 1936 | UNKNOWN_LOCATION or BUILTINS_LOCATION in GCC. */ |
| 1837 | 1937 | |
| 1838 | | −source_location linemap_resolve_location (struct line_maps *, |
| 1839 | | − source_location loc, |
| 1840 | | − enum location_resolution_kind lrk, |
| 1841 | | − const line_map_ordinary **loc_map); |
| 1938 | +location_t linemap_resolve_location (struct line_maps *, |
| 1939 | + location_t loc, |
| 1940 | + enum location_resolution_kind lrk, |
| 1941 | + const line_map_ordinary **loc_map); |
| 1842 | 1942 | |
| 1843 | 1943 | /* Suppose that LOC is the virtual location of a token coming from the |
| 1844 | 1944 | expansion of a macro M. This function then steps up to get the |
| @@ -1847,9 +1947,9 @@ source_location linemap_resolve_location (struct line_maps *, · 2 unmodified lines |
| 1847 | 1947 | the point where M' was expanded. LOC_MAP is an output parameter. |
| 1848 | 1948 | When non-NULL, *LOC_MAP is set to the map of the returned |
| 1849 | 1949 | location. */ |
| 1850 | | −source_location linemap_unwind_toward_expansion (struct line_maps *, |
| 1851 | | − source_location loc, |
| 1852 | | − const struct line_map **loc_map); |
| 1950 | +location_t linemap_unwind_toward_expansion (struct line_maps *, |
| 1951 | + location_t loc, |
| 1952 | + const struct line_map **loc_map); |
| 1853 | 1953 | |
| 1854 | 1954 | /* If LOC is the virtual location of a token coming from the expansion |
| 1855 | 1955 | of a macro M and if its spelling location is reserved (e.g, a |
| @@ -1865,9 +1965,9 @@ source_location linemap_unwind_toward_expansion (struct line_maps *, · 9 unmodified lines |
| 1865 | 1965 | |
| 1866 | 1966 | *MAP is set to the map of the returned location if the later is |
| 1867 | 1967 | different from LOC. */ |
| 1868 | | −source_location linemap_unwind_to_first_non_reserved_loc (struct line_maps *, |
| 1869 | | − source_location loc, |
| 1870 | | − const struct line_map **map); |
| 1968 | +location_t linemap_unwind_to_first_non_reserved_loc (struct line_maps *, |
| 1969 | + location_t loc, |
| 1970 | + const struct line_map **map); |
| 1871 | 1971 | |
| 1872 | 1972 | /* Expand source code location LOC and return a user readable source |
| 1873 | 1973 | code location. LOC must be a spelling (non-virtual) location. If |
| @@ -1875,7 +1975,7 @@ source_location linemap_unwind_to_first_non_reserved_loc (struct line_maps *, · 1 unmodified line |
| 1875 | 1975 | location is returned. */ |
| 1876 | 1976 | expanded_location linemap_expand_location (struct line_maps *, |
| 1877 | 1977 | const struct line_map *, |
| 1878 | | − source_location loc); |
| 1978 | + location_t loc); |
| 1879 | 1979 | |
| 1880 | 1980 | /* Statistics about maps allocation and usage as returned by |
| 1881 | 1981 | linemap_get_statistics. */ |
| @@ -1902,7 +2002,7 @@ struct linemap_stats · 20 unmodified lines |
| 1902 | 2002 | location emitted for that file. */ |
| 1903 | 2003 | bool linemap_get_file_highest_location (struct line_maps * set, |
| 1904 | 2004 | const char *file_name, |
| 1905 | | − source_location *loc); |
| 2005 | + location_t *loc); |
| 1906 | 2006 | |
| 1907 | 2007 | /* Compute and return statistics about the memory consumption of some |
| 1908 | 2008 | parts of the line table SET. */ |
| @@ -1910,7 +2010,7 @@ void linemap_get_statistics (struct line_maps *, struct linemap_stats *); · 1 unmodified line |
| 1910 | 2010 | |
| 1911 | 2011 | /* Dump debugging information about source location LOC into the file |
| 1912 | 2012 | stream STREAM. SET is the line map set LOC comes from. */ |
| 1913 | | −void linemap_dump_location (struct line_maps *, source_location, FILE *); |
| 2013 | +void linemap_dump_location (struct line_maps *, location_t, FILE *); |
| 1914 | 2014 | |
| 1915 | 2015 | /* Dump line map at index IX in line table SET to STREAM. If STREAM |
| 1916 | 2016 | is NULL, use stderr. IS_MACRO is true if the caller wants to |
| @@ -1922,7 +2022,7 @@ void linemap_dump (FILE *, struct line_maps *, unsigned, bool); · 5 unmodified lines |
| 1922 | 2022 | specifies how many macro maps to dump. */ |
| 1923 | 2023 | void line_table_dump (FILE *, struct line_maps *, unsigned int, unsigned int); |
| 1924 | 2024 | |
| 1925 | | −/* An enum for distinguishing the various parts within a source_location. */ |
| 2025 | +/* An enum for distinguishing the various parts within a location_t. */ |
| 1926 | 2026 | |
| 1927 | 2027 | enum location_aspect |
| 1928 | 2028 | { |
| @@ -1931,14 +2031,14 @@ enum location_aspect · 2 unmodified lines |
| 1931 | 2031 | LOCATION_ASPECT_FINISH |
| 1932 | 2032 | }; |
| 1933 | 2033 | |
| 1934 | | −/* The rich_location class requires a way to expand source_location instances. |
| 2034 | +/* The rich_location class requires a way to expand location_t instances. |
| 1935 | 2035 | We would directly use expand_location_to_spelling_point, which is |
| 1936 | 2036 | implemented in gcc/input.c, but we also need to use it for rich_location |
| 1937 | 2037 | within genmatch.c. |
| 1938 | 2038 | Hence we require client code of libcpp to implement the following |
| 1939 | 2039 | symbol. */ |
| 1940 | 2040 | extern expanded_location |
| 1941 | | −linemap_client_expand_location_to_spelling_point (source_location, |
| 2041 | +linemap_client_expand_location_to_spelling_point (location_t, |
| 1942 | 2042 | enum location_aspect); |
| 1943 | 2043 | |
| 1944 | 2044 | #endif /* !LIBCPP_LINE_MAP_H */ |