This is an updated version of this patch kit:
  https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00726.html
It's still at the level of an RFC/work-in-progress; I'm posting for
feedback rather than for formal approval at this time (though the
first two patches are perhaps ready).

For the sake of simplicity, for now I've eliminated anything that
isn't about getting us underlines under expression ranges.  I've also
reduced the scope to just the C frontend.

It captures source ranges for C expressions as they are parsed within
c_expr, and stores them for some trees within GENERIC: in the latter
case only for those that already have a location_t i.e. for all
"compound expressions", but not for e.g. INTEGER_CSTs and VAR_DECLs.
It does this by expanding the ad-hoc lookaside data to include a
source_range (as per Jakub's suggestion).

Doing it this way avoids the need to introduce any new tree nodes, or
to add any fields to any existing tree types.

As in v1 of the kit, the ranges for tokens are stashed into new fields
within the tokens.  I'm thinking for v3 of the kit that that might be
redundant, and that it may be better to stash the token ranges into the
location_t (via the ad-hoc table) immediately as the tokens
are lexed.

The benefit of that approach is (a) the conceptual simplicity that
everything could simply use a location_t, which would become both
a caret location plus a range surrounding it and (b) we'd be able to get
a range from a location_t in the rich_location, and hence (I hope) many
diagnostics would get range underlining "for free".

The drawback is that it could bloat the ad-hoc table.  Can the ad-hoc
table ever get smaller, or does it only ever get inserted into?
An idea I had is that we could stash short ranges directly into the
32 bits of location_t, by offsetting the per-column-bits somewhat.
That way short ranges wouldn't need to use the ad-hoc table, and
(I hope) most tokens could use this optimization.

My plan is to investigate the impact these patches have on the time
and memory consumption of the compiler, and to get some stats on
whether the location_t packing idea is worth it (and maybe
investigate how big an impact going to 64 bits for location_t would
be).

Bootstraps&regrtests; adds 143 PASS results to gcc.sum.
(this v2 patch kit is on top of r227977; v1 was on top of r227562)

Thoughts?

Dave

[BTW, I'm going to be on vacation and away from email from this
Saturday, the 26th through to October 5th]

David Malcolm (5):
  Testsuite: add dg-{begin|end}-multiline-output commands
  Reimplement diagnostic_show_locus, introducing rich_location classes
    (v2)
  Implement token range tracking within libcpp and the C FE (v2)
  Implement tree expression tracking in C FE (v2)
  Add plugin to recursively dump the source-ranges in a tree (v2)

 boehm-gc/testsuite/lib/boehm-gc.exp                |   1 +
 gcc/Makefile.in                                    |   1 +
 gcc/c-family/c-common.c                            |  25 +-
 gcc/c-family/c-common.h                            |   4 +-
 gcc/c-family/c-lex.c                               |   9 +-
 gcc/c-family/c-pragma.h                            |   4 +-
 gcc/c/c-decl.c                                     |   3 +-
 gcc/c/c-errors.c                                   |  12 +-
 gcc/c/c-objc-common.c                              |   2 +-
 gcc/c/c-parser.c                                   |  95 ++-
 gcc/c/c-tree.h                                     |  11 +
 gcc/c/c-typeck.c                                   |  10 +
 gcc/cp/error.c                                     |   5 +-
 gcc/cp/parser.c                                    |   3 +-
 gcc/diagnostic-color.c                             |   5 +-
 gcc/diagnostic-core.h                              |   8 +
 gcc/diagnostic-show-locus.c                        | 700 ++++++++++++++++++++-
 gcc/diagnostic.c                                   | 196 +++++-
 gcc/diagnostic.h                                   |  48 +-
 gcc/fortran/cpp.c                                  |  13 +-
 gcc/fortran/error.c                                |  34 +-
 gcc/gcc-rich-location.c                            |  86 +++
 gcc/gcc-rich-location.h                            |  47 ++
 gcc/genmatch.c                                     |  27 +-
 gcc/gimple.h                                       |   6 +-
 gcc/input.c                                        |   7 +
 gcc/pretty-print.c                                 |  21 +
 gcc/pretty-print.h                                 |  25 +-
 gcc/print-tree.c                                   |  21 +
 gcc/rtl-error.c                                    |   3 +-
 .../gcc.dg/plugin/diagnostic-test-expressions-1.c  | 422 +++++++++++++
 .../gcc.dg/plugin/diagnostic-test-show-locus-bw.c  | 124 ++++
 .../plugin/diagnostic-test-show-locus-color.c      | 131 ++++
 .../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     | 285 +++++++++
 .../diagnostic_plugin_test_tree_expression_range.c | 159 +++++
 gcc/testsuite/gcc.dg/plugin/plugin.exp             |   7 +
 gcc/testsuite/lib/gcc-dg.exp                       |   1 +
 gcc/testsuite/lib/multiline.exp                    | 241 +++++++
 gcc/testsuite/lib/prune.exp                        |   5 +
 gcc/tree-cfg.c                                     |   9 +-
 gcc/tree-diagnostic.c                              |   2 +-
 gcc/tree-inline.c                                  |   5 +-
 gcc/tree-pretty-print.c                            |   2 +-
 gcc/tree.c                                         |  40 +-
 gcc/tree.h                                         |  40 ++
 libatomic/testsuite/lib/libatomic.exp              |   1 +
 libcpp/errors.c                                    |   7 +-
 libcpp/include/cpplib.h                            |   8 +-
 libcpp/include/line-map.h                          | 220 ++++++-
 libcpp/lex.c                                       |  14 +
 libcpp/line-map.c                                  | 156 ++++-
 libgo/testsuite/lib/libgo.exp                      |   1 +
 libgomp/testsuite/lib/libgomp.exp                  |   1 +
 libitm/testsuite/lib/libitm.exp                    |   1 +
 libvtv/testsuite/lib/libvtv.exp                    |   1 +
 57 files changed, 3380 insertions(+), 174 deletions(-)
 create mode 100644 gcc/gcc-rich-location.c
 create mode 100644 gcc/gcc-rich-location.h
 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
 create mode 100644 gcc/testsuite/lib/multiline.exp

-- 
1.8.5.3

Reply via email to