This is a followup to: https://gcc.gnu.org/ml/gcc-patches/2015-09/msg01696.html (one of the individual patches has seen iteration since that, so I'm calling the whole thing "v5" for the sake of clarity).
Patches 1-3 are a preamble: "Improvements to description of source_location in line-map.h" "Add stats on adhoc table to dump_line_table_statistics" "libstdc++v3: Explicitly disable carets and colorization within testsuite" Patch 4: "Reimplement diagnostic_show_locus, introducing rich_location classes (v5)" is an updated version of the rewrite of diagnostic_show_locus, via the new rich_location class. I believe this one is ready for trunk and could be applied without needing the followup patches; I have a followup patch that adds support for "fix it hints" on top of this (PR/62314). Patch 5: "Add ranges to libcpp tokens (via ad-hoc data, unoptimized)" implements token range tracking by adding range information to the ad-hoc location table. As noted in the patch, this generalizes source_location (aka location_t) to be both a caret and a range, letting us track them through our existing location-tracking mechanisms, without having to add extra fields to core data structures. The drawback is that it's inefficient. This is addressed by patch 10, which implements a packing scheme to avoid the ad-hoc table for most tokens. Patch 6: "Track expression ranges in C frontend" is an updated version of the patch to add tracking of expression ranges to the C frontend, using the above mechanism. Patch 7: "Add plugin to recursively dump the source-ranges in a tree (v2)" is the test plugin to demo dumping the ranges for all sub-expressions of a complicated expression. It's unchanged since previous versions. Patch 8: "Wire things up so that libcpp users get token underlines" wires up the work from patches 4 and 5 so that most diagnostics in frontends using libcpp will see some kind of underlining, for tokens at least. Patch 9: "Delay some resolution of ad-hoc locations, preserving ranges" tweaks things to provide underlines for some places that patch 8 missed. Patch 10: "Compress short ranges into source_location" is the bit-packing optimization for patch 5. Successfully bootstrapped®rtested the net effect of the kit on x86_64-pc-linux-gnu (with 186 new PASS results for gcc.sum). Some benchmarks can be seen in this post: https://gcc.gnu.org/ml/gcc-patches/2015-10/msg02283.html Are patches 1-4 OK for trunk? (assuming they individually bootstrap®rtest?) How do patches 5-10 look? I'm about to do some more benchmarking. (The patches are relative to r228618 plus the dg-begin-multiline-output patch). Dave gcc/Makefile.in | 1 + gcc/ada/gcc-interface/trans.c | 3 +- gcc/c-family/c-common.c | 25 +- gcc/c-family/c-common.h | 4 +- gcc/c-family/c-opts.c | 2 + gcc/c/c-decl.c | 3 +- gcc/c/c-errors.c | 12 +- gcc/c/c-objc-common.c | 2 +- gcc/c/c-parser.c | 98 ++- gcc/c/c-tree.h | 19 + gcc/c/c-typeck.c | 10 + gcc/cp/error.c | 5 +- gcc/diagnostic-color.c | 5 +- gcc/diagnostic-core.h | 8 + gcc/diagnostic-show-locus.c | 778 ++++++++++++++++++--- gcc/diagnostic.c | 196 +++++- gcc/diagnostic.h | 55 +- gcc/fortran/cpp.c | 13 +- gcc/fortran/error.c | 103 +-- gcc/gcc-rich-location.c | 86 +++ gcc/gcc-rich-location.h | 47 ++ gcc/genmatch.c | 27 +- gcc/gimple.h | 6 +- gcc/input.c | 41 +- gcc/pretty-print.c | 21 + gcc/pretty-print.h | 25 +- gcc/print-tree.c | 21 + gcc/rtl-error.c | 3 +- gcc/testsuite/gcc.dg/diagnostic-token-ranges.c | 120 ++++ .../gcc.dg/diagnostic-tree-expr-ranges-2.c | 23 + .../gcc.dg/plugin/diagnostic-test-expressions-1.c | 422 +++++++++++ .../gcc.dg/plugin/diagnostic-test-show-locus-bw.c | 149 ++++ .../plugin/diagnostic-test-show-locus-color.c | 158 +++++ .../gcc.dg/plugin/diagnostic-test-show-trees-1.c | 65 ++ .../gcc.dg/plugin/diagnostic_plugin_show_trees.c | 174 +++++ .../plugin/diagnostic_plugin_test_show_locus.c | 322 +++++++++ .../diagnostic_plugin_test_tree_expression_range.c | 98 +++ gcc/testsuite/gcc.dg/plugin/plugin.exp | 7 + gcc/testsuite/lib/gcc-dg.exp | 1 + gcc/toplev.c | 1 + gcc/tree-cfg.c | 9 +- gcc/tree-diagnostic.c | 2 +- gcc/tree-inline.c | 5 +- gcc/tree-pretty-print.c | 2 +- gcc/tree.c | 54 +- gcc/tree.h | 34 + libcpp/errors.c | 7 +- libcpp/include/cpplib.h | 7 +- libcpp/include/line-map.h | 354 +++++++++- libcpp/lex.c | 13 + libcpp/line-map.c | 415 ++++++++++- libcpp/location-example.txt | 188 ++--- libstdc++-v3/testsuite/lib/libstdc++.exp | 2 + 53 files changed, 3772 insertions(+), 479 deletions(-) create mode 100644 gcc/gcc-rich-location.c create mode 100644 gcc/gcc-rich-location.h create mode 100644 gcc/testsuite/gcc.dg/diagnostic-token-ranges.c create mode 100644 gcc/testsuite/gcc.dg/diagnostic-tree-expr-ranges-2.c create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-trees-1.c create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c create mode 100644 gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c -- 1.8.5.3