ebedc9a341
This patch combines: [PATCH 05/10] Add ranges to libcpp tokens (via ad-hoc data, unoptimized) [PATCH 06/10] Track expression ranges in C frontend [PATCH 07/10] Add plugin to recursively dump the source-ranges in a tree (v2) [PATCH 08/10] Wire things up so that libcpp users get token underlines [PATCH 09/10] Delay some resolution of ad-hoc locations, preserving ranges [PATCH 10/10] Compress short ranges into source_location [PATCH] libcpp: add examples to source_location description along with fixes for the nits identified during review. gcc/ChangeLog: * Makefile.in (OBJS): Add gcc-rich-location.o. * diagnostic.c (diagnostic_append_note): Pass line_table to rich_location ctor. (emit_diagnostic): Likewise. (inform): Likewise. (inform_n): Likewise. (warning): Likewise. (warning_at): Likewise. (warning_n): Likewise. (pedwarn): Likewise. (permerror): Likewise. (error): Likewise. (error_n): Likewise. (error_at): Likewise. (sorry): Likewise. (fatal_error): Likewise. (internal_error): Likewise. (internal_error_no_backtrace): Likewise. (source_range::debug): Likewise. * gcc-rich-location.c: New file. * gcc-rich-location.h: New file. * genmatch.c (fatal_at): Pass line_table to rich_location ctor. (warning_at): Likewise. * gimple.h (gimple_set_block): Use set_block function. * input.c (dump_line_table_statistics): Dump stats on how many ranges were optimized vs how many needed ad-hoc table. (write_digit_row): Add "map" param; use its range_bits to calculate the per-character offset. (dump_location_info): Print the range and column bits for each ordinary map. Use the range bits to calculate the per-character offset. Pass the map as a new param to the various calls to write_digit_row. Eliminate uses of ORDINARY_MAP_NUMBER_OF_COLUMN_BITS. * print-tree.c (print_node): Print any source range information. * rtl-error.c (diagnostic_for_asm): Likewise. * toplev.c (general_init): Initialize line_table's default_range_bits. * tree-cfg.c (move_block_to_fn): Likewise. (move_block_to_fn): Likewise. * tree-inline.c (copy_phis_for_bb): Likewise. * tree.c (tree_set_block): Likewise. (get_pure_location): New function. (set_source_range): New functions. (set_block): New function. (set_source_range): New functions. * tree.h (CAN_HAVE_RANGE_P): New. (EXPR_LOCATION_RANGE): New. (EXPR_HAS_RANGE): New. (get_expr_source_range): New inline function. (DECL_LOCATION_RANGE): New. (set_source_range): New decls. (get_decl_source_range): New inline function. gcc/ada/ChangeLog: * gcc-interface/trans.c (Sloc_to_locus): Add line_table param when calling linemap_position_for_line_and_column. gcc/c-family/ChangeLog: * c-common.c (c_fully_fold_internal): Capture existing souce_range, and store it on the result. * c-opts.c (c_common_init_options): Set global_dc->colorize_source_p. gcc/c/ChangeLog: * c-decl.c (warn_defaults_to): Pass line_table to rich_location ctor. * c-errors.c (pedwarn_c99): Likewise. (pedwarn_c90): Likewise. * c-parser.c (set_c_expr_source_range): New functions. (c_token::get_range): New method. (c_token::get_finish): New method. (c_parser_expr_no_commas): Call set_c_expr_source_range on the ret based on the range from the start of the LHS to the end of the RHS. (c_parser_conditional_expression): Likewise, based on the range from the start of the cond.value to the end of exp2.value. (c_parser_binary_expression): Call set_c_expr_source_range on the stack values for TRUTH_ANDIF_EXPR and TRUTH_ORIF_EXPR. (c_parser_cast_expression): Call set_c_expr_source_range on ret based on the cast_loc through to the end of the expr. (c_parser_unary_expression): Likewise, based on the op_loc through to the end of op. (c_parser_sizeof_expression) Likewise, based on the start of the sizeof token through to either the closing paren or the end of expr. (c_parser_postfix_expression): Likewise, using the token range, or from the open paren through to the close paren for parenthesized expressions. (c_parser_postfix_expression_after_primary): Likewise, for various kinds of expression. * c-tree.h (struct c_expr): Add field "src_range". (c_expr::get_start): New method. (c_expr::get_finish): New method. (set_c_expr_source_range): New decls. * c-typeck.c (parser_build_unary_op): Call set_c_expr_source_range on ret for prefix unary ops. (parser_build_binary_op): Likewise, running from the start of arg1.value through to the end of arg2.value. gcc/cp/ChangeLog: * error.c (pedwarn_cxx98): Pass line_table to rich_location ctor. gcc/fortran/ChangeLog: * error.c (gfc_warning): Pass line_table to rich_location ctor. (gfc_warning_now_at): Likewise. (gfc_warning_now): Likewise. (gfc_error_now): Likewise. (gfc_fatal_error): Likewise. (gfc_error): Likewise. (gfc_internal_error): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/diagnostic-token-ranges.c: New file. * gcc.dg/diagnostic-tree-expr-ranges-2.c: New file. * gcc.dg/plugin/diagnostic-test-expressions-1.c: New file. * gcc.dg/plugin/diagnostic-test-show-trees-1.c: New file. * gcc.dg/plugin/diagnostic_plugin_show_trees.c: New file. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (get_loc): Add line_table param when calling linemap_position_for_line_and_column. (test_show_locus): Pass line_table to rich_location ctors. (plugin_init): Remove setting of global_dc->colorize_source_p. * gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c: New file. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add diagnostic_plugin_test_tree_expression_range.c, diagnostic-test-expressions-1.c, diagnostic_plugin_show_trees.c, and diagnostic-test-show-trees-1.c. libcpp/ChangeLog: * errors.c (cpp_diagnostic): Pass pfile->line_table to rich_location ctor. (cpp_diagnostic_with_line): Likewise. * include/cpplib.h (struct cpp_token): Update comment for src_loc to indicate that the range of the token is "baked into" the source_location. * include/line-map.h (source_location): Update the descriptive comment to reflect the packing scheme for short ranges, adding worked examples of location encoding. (struct line_map_ordinary): Drop field "column_bits" in favor of field "m_column_and_range_bits"; add field "m_range_bits". (ORDINARY_MAP_NUMBER_OF_COLUMN_BITS): Delete. (location_adhoc_data): Add source_range field. (struct line_maps): Add fields "default_range_bits", "num_optimized_ranges" and "num_unoptimized_ranges". (get_combined_adhoc_loc): Add source_range param. (get_range_from_loc): New declaration. (pure_location_p): New prototype. (COMBINE_LOCATION_DATA): Add source_range param. (SOURCE_LINE): Update for renaming of column_bits. (SOURCE_COLUMN): Likewise. Shift the column right by the map's range_bits. (LAST_SOURCE_LINE_LOCATION): Update for renaming of column_bits. (linemap_position_for_line_and_column): Add line_maps * params. (rich_location::rich_location): Likewise. * lex.c (_cpp_lex_direct): Capture the range of the token, baking it into token->src_loc via a call to COMBINE_LOCATION_DATA. * line-map.c (LINE_MAP_MAX_COLUMN_NUMBER): Reduce from 1U << 17 to 1U << 12. (location_adhoc_data_hash): Add the src_range into the hash value. (location_adhoc_data_eq): Require equality of the src_range values. (can_be_stored_compactly_p): New function. (get_combined_adhoc_loc): Add src_range param, and store it, via a bit-packing scheme for short ranges, otherwise within the lookaside table. Remove the requirement that data is non-NULL. (get_range_from_adhoc_loc): New function. (get_range_from_loc): New function. (pure_location_p): New function. (linemap_add): Ensure that start_location has zero for the range_bits, unless we're past LINE_MAP_MAX_LOCATION_WITH_COLS. Initialize range_bits to zero. Assert that the start_location is "pure". (linemap_line_start): Assert that the column_and_range_bits >= range_bits. Update determinination of whether we need to start a new map using the effective column bits, without the range bits. Use the set's default_range_bits in new maps, apart from those with column_bits == 0, which should also have 0 range_bits. Increase the column bits for new maps by the range bits. When adding lines to an existing map, use set->highest_line directly rather than offsetting highest by SOURCE_COLUMN. Add assertions to sanity-check the return value. (linemap_position_for_column): Offset to_column by range_bits. Update set->highest_location if necessary. (linemap_position_for_line_and_column): Add line_maps * param. Update the calculation to offset the column by range_bits, and conditionalize it on being <= LINE_MAP_MAX_LOCATION_WITH_COLS. Bound it by LINEMAPS_MACRO_LOWEST_LOCATION. Update set->highest_location if necessary. (linemap_position_for_loc_and_offset): Handle ad-hoc locations; pass "set" to linemap_position_for_line_and_column. (linemap_macro_map_loc_unwind_toward_spelling): Add line_maps param. Handle ad-hoc locations. (linemap_location_in_system_header_p): Pass on "set" to call to linemap_macro_map_loc_unwind_toward_spelling. (linemap_macro_loc_to_spelling_point): Retain ad-hoc locations. Pass on "set" to call to linemap_macro_map_loc_unwind_toward_spelling. (linemap_resolve_location): Retain ad-hoc locations. Pass on "set" to call to linemap_macro_map_loc_unwind_toward_spelling. (linemap_unwind_toward_expansion): Pass on "set" to call to linemap_macro_map_loc_unwind_toward_spelling. (linemap_expand_location): Extract the data pointer before extracting the location. (rich_location::rich_location): Add line_maps param; use it to extract the range from the source_location. * location-example.txt: Regenerate, showing new representation. From-SVN: r230331
233 lines
6.8 KiB
Plaintext
233 lines
6.8 KiB
Plaintext
Consider compiling test.c, with this content:
|
|
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
|
#include "test.h"
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
int a = PLUS (1,2);
|
|
int b = PLUS (3,4);
|
|
return 0;
|
|
}
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
...where test.h has this content:
|
|
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
|
extern int foo ();
|
|
|
|
#define PLUS(A, B) A + B
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
The undocumented -fdump-internal-locations option outputs this information
|
|
to stderr, showing what each source_location value means. Source code
|
|
lines are quoted, showing both per-line source_location values and
|
|
per-line&column source_location values (written vertically under the
|
|
corresponding character of source code).
|
|
|
|
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
|
RESERVED LOCATIONS
|
|
source_location interval: 0 <= loc < 2
|
|
|
|
ORDINARY MAP: 0
|
|
source_location interval: 32 <= loc < 64
|
|
file: test.c
|
|
starting at line: 1
|
|
column bits: 12
|
|
range bits: 5
|
|
test.c: 1|loc: 32|#include "test.h"
|
|
|69269258258148147
|
|
|46802468024680246
|
|
|
|
ORDINARY MAP: 1
|
|
source_location interval: 64 <= loc < 96
|
|
file: <built-in>
|
|
starting at line: 0
|
|
column bits: 0
|
|
range bits: 0
|
|
|
|
ORDINARY MAP: 2
|
|
source_location interval: 96 <= loc < 128
|
|
file: <command-line>
|
|
starting at line: 0
|
|
column bits: 0
|
|
range bits: 0
|
|
|
|
ORDINARY MAP: 3
|
|
source_location interval: 128 <= loc < 160128
|
|
file: /usr/include/stdc-predef.h
|
|
starting at line: 1
|
|
column bits: 12
|
|
range bits: 5
|
|
(contents of /usr/include/stdc-predef.h snipped for brevity)
|
|
|
|
ORDINARY MAP: 4
|
|
source_location interval: 160128 <= loc < 160160
|
|
file: <command-line>
|
|
starting at line: 32
|
|
column bits: 12
|
|
range bits: 5
|
|
|
|
ORDINARY MAP: 5
|
|
source_location interval: 160160 <= loc < 164256
|
|
file: test.c
|
|
starting at line: 1
|
|
column bits: 12
|
|
range bits: 5
|
|
test.c: 1|loc:160160|#include "test.h"
|
|
|00000000000000000
|
|
|12223334445556667
|
|
|92582581481470470
|
|
|24680246802468024
|
|
|
|
ORDINARY MAP: 6
|
|
source_location interval: 164256 <= loc < 173280
|
|
file: test.h
|
|
starting at line: 1
|
|
column bits: 12
|
|
range bits: 5
|
|
test.h: 1|loc:164256|extern int foo ();
|
|
|444444444444444444
|
|
|233344455566677788
|
|
|825814814704703603
|
|
|802468024680246802
|
|
test.h: 2|loc:168352|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test.h: 3|loc:172448|#define PLUS(A, B) A + B
|
|
|222222222222222223333333
|
|
|455566677788889990001112
|
|
|814704703603692692582581
|
|
|024680246802468024680246
|
|
|
|
ORDINARY MAP: 7
|
|
source_location interval: 173280 <= loc < 202016
|
|
file: test.c
|
|
starting at line: 2
|
|
column bits: 12
|
|
range bits: 5
|
|
test.c: 2|loc:173280|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test.c: 3|loc:177376|int
|
|
|777
|
|
|444
|
|
|047
|
|
|802
|
|
test.c: 4|loc:181472|main (int argc, char **argv)
|
|
|1111111111111111222222222222
|
|
|5556666777888999000111222333
|
|
|0360369269258258148147047036
|
|
|4680246802468024680246802468
|
|
test.c: 5|loc:185568|{
|
|
|5
|
|
|6
|
|
|0
|
|
|0
|
|
test.c: 6|loc:189664| int a = PLUS (1,2);
|
|
|999999999900000000000
|
|
|677788899900011122233
|
|
|926925825814814704703
|
|
|680246802468024680246
|
|
test.c: 7|loc:193760| int b = PLUS (3,4);
|
|
|333333344444444444444
|
|
|788899900011122233344
|
|
|925825814814704703603
|
|
|246802468024680246802
|
|
test.c: 8|loc:197856| return 0;
|
|
|77778888888
|
|
|89990001112
|
|
|82581481470
|
|
|80246802468
|
|
test.c: 9|loc:201952|}
|
|
|1
|
|
|9
|
|
|8
|
|
|4
|
|
|
|
UNALLOCATED LOCATIONS
|
|
source_location interval: 202016 <= loc < 2147483633
|
|
|
|
MACRO 1: PLUS (7 tokens)
|
|
source_location interval: 2147483633 <= loc < 2147483640
|
|
test.c:7:11: note: expansion point is location 194115
|
|
int b = PLUS (3,4);
|
|
^~~~
|
|
|
|
map->start_location: 2147483633
|
|
macro_locations:
|
|
0: 194304, 173088
|
|
test.c:7:17: note: token 0 has x-location == 194304
|
|
int b = PLUS (3,4);
|
|
^
|
|
|
|
test.c:7:17: note: token 0 has y-location == 173088
|
|
1: 173152, 173152
|
|
In file included from test.c:1:0:
|
|
test.h:3:22: note: token 1 has x-location == y-location == 173152
|
|
#define PLUS(A, B) A + B
|
|
^
|
|
|
|
2: 194368, 173216
|
|
test.c:7:19: note: token 2 has x-location == 194368
|
|
int b = PLUS (3,4);
|
|
^
|
|
|
|
test.c:7:19: note: token 2 has y-location == 173216
|
|
3: 0, 2947526575
|
|
cc1: note: token 3 has x-location == 0
|
|
cc1: note: token 3 has y-location == 2947526575
|
|
4: 2947526575, 2947526575
|
|
x-location == y-location == 2947526575 encodes token # 800042942
|
|
5: 2947526575, 2947526575
|
|
x-location == y-location == 2947526575 encodes token # 800042942
|
|
6: 2947526575, 2947526575
|
|
x-location == y-location == 2947526575 encodes token # 800042942
|
|
|
|
MACRO 0: PLUS (7 tokens)
|
|
source_location interval: 2147483640 <= loc < 2147483647
|
|
test.c:6:11: note: expansion point is location 190019
|
|
int a = PLUS (1,2);
|
|
^~~~
|
|
|
|
map->start_location: 2147483640
|
|
macro_locations:
|
|
0: 190208, 173088
|
|
test.c:6:17: note: token 0 has x-location == 190208
|
|
int a = PLUS (1,2);
|
|
^
|
|
|
|
test.c:6:17: note: token 0 has y-location == 173088
|
|
1: 173152, 173152
|
|
In file included from test.c:1:0:
|
|
test.h:3:22: note: token 1 has x-location == y-location == 173152
|
|
#define PLUS(A, B) A + B
|
|
^
|
|
|
|
2: 190272, 173216
|
|
test.c:6:19: note: token 2 has x-location == 190272
|
|
int a = PLUS (1,2);
|
|
^
|
|
|
|
test.c:6:19: note: token 2 has y-location == 173216
|
|
3: 0, 2947526575
|
|
cc1: note: token 3 has x-location == 0
|
|
cc1: note: token 3 has y-location == 2947526575
|
|
4: 2947526575, 2947526575
|
|
x-location == y-location == 2947526575 encodes token # 800042935
|
|
5: 2947526575, 2947526575
|
|
x-location == y-location == 2947526575 encodes token # 800042935
|
|
6: 2947526575, 2947526575
|
|
x-location == y-location == 2947526575 encodes token # 800042935
|
|
|
|
MAX_SOURCE_LOCATION
|
|
source_location interval: 2147483647 <= loc < 2147483648
|
|
|
|
AD-HOC LOCATIONS
|
|
source_location interval: 2147483648 <= loc < 4294967295
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|