diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-01-10 08:33:47 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-01-10 08:33:47 -0500 |
commit | 5daf9104ed5d4ef21b01e9564e5325adb157e5d8 (patch) | |
tree | e0ceb725b163c5a2048246b707712ea145caa71d /gcc/pretty-print.h | |
parent | 7daa935c7997f3d09536d6aeab91bff2b68ca297 (diff) | |
download | gcc-5daf9104ed5d4ef21b01e9564e5325adb157e5d8.zip gcc-5daf9104ed5d4ef21b01e9564e5325adb157e5d8.tar.gz gcc-5daf9104ed5d4ef21b01e9564e5325adb157e5d8.tar.bz2 |
pretty-print: support urlification in phase 3
TL;DR: for the case when the user misspells a command-line option
and we suggest one, with this patch we now provide a documentation URL
for the suggestion.
In r14-5118-gc5db4d8ba5f3de I added a mechanism to automatically add
URLs to quoted strings in diagnostics, and in r14-6920-g9e49746da303b8
through r14-6923-g4ded42c2c5a5c9 wired this up so that any time
we mention a command-line option in a diagnostic message in quotes,
the user gets a URL to the HTML documentation for that option.
However this only worked for quoted strings that were fully within
a single "chunk" within the pretty-printer implementation, such as:
* "%<-foption%>" (handled in phase 1)
* "%qs", "-foption" (handled in phase 2)
but not where the the quoted string straddled multiple chunks, in
particular for this important case in the gcc.cc:
error ("unrecognized command-line option %<-%s%>;"
" did you mean %<-%s%>?",
switches[i].part1, hint);
e.g. for:
$ LANG=C ./xgcc -B. -finling-small-functions
xgcc: error: unrecognized command-line option '-finling-small-functions'; did you mean '-finline-small-functions'?
which within pp_format becomes these chunks:
* chunk 0: "unrecognized command-line option `-"
* chunk 1: switches[i].part1 (e.g. "finling-small-functions")
* chunk 2: "'; did you mean `-"
* chunk 3: hint (e.g. "finline-small-functions")
* chunk 4: "'?"
where the first quoted run is in chunks 1-3 and the second in
chunks 2-4.
Hence we were not attempting to provide a URL for the two quoted runs,
and, in particular not for the hint.
This patch refactors the urlification mechanism in pretty-print.cc so
that it checks for quoted runs that appear in phase 3 (as well as in
phases 1 and 2, as before). With this, the quoted text runs
"-finling-small-functions" and "-finline-small-functions" are passed
to the urlifier, which successfully finds a documentation URL for
the latter.
As before, the urlification code is only run if the URL escapes are
enabled, and only for messages from diagnostic.cc (error, warn, inform,
etc), not for all pretty_printer usage.
gcc/ChangeLog:
* diagnostic.cc (diagnostic_context::report_diagnostic): Pass
m_urlifier to pp_output_formatted_text.
* pretty-print.cc: Add #define of INCLUDE_VECTOR.
(obstack_append_string): New overload, taking a length.
(urlify_quoted_string): Pass in an obstack ptr, rather than using
that of the pp's buffer. Generalize to handle trailing text in
the buffer beyond the run of quoted text.
(class quoting_info): New.
(on_begin_quote): New.
(on_end_quote): New.
(pp_format): Refactor phase 1 and phase 2 quoting support, moving
it to calls to on_begin_quote and on_end_quote.
(struct auto_obstack): New.
(quoting_info::handle_phase_3): New.
(pp_output_formatted_text): Add urlifier param. Use it if there
is deferred urlification. Delete m_quotes.
(selftest::pp_printf_with_urlifier): Pass urlifier to
pp_output_formatted_text.
(selftest::test_urlification): Update results for the existing
case of quoted text stradding chunks; add more such test cases.
* pretty-print.h (class quoting_info): New forward decl.
(chunk_info::m_quotes): New field.
(pp_output_formatted_text): Add optional urlifier param.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/pretty-print.h')
-rw-r--r-- | gcc/pretty-print.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h index 4548c25..14a225e 100644 --- a/gcc/pretty-print.h +++ b/gcc/pretty-print.h @@ -69,6 +69,8 @@ enum diagnostic_prefixing_rule_t DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2 }; +class quoting_info; + /* The chunk_info data structure forms a stack of the results from the first phase of formatting (pp_format) which have not yet been output (pp_output_formatted_text). A stack is necessary because @@ -86,6 +88,10 @@ struct chunk_info text, and the third phase simply emits all the chunks in sequence with appropriate line-wrapping. */ const char *args[PP_NL_ARGMAX * 2]; + + /* If non-null, information on quoted text runs within the chunks + for use by a urlifier. */ + quoting_info *m_quotes; }; /* The output buffer datatype. This is best seen as an abstract datatype @@ -409,7 +415,8 @@ extern void pp_flush (pretty_printer *); extern void pp_really_flush (pretty_printer *); extern void pp_format (pretty_printer *, text_info *, const urlifier * = nullptr); -extern void pp_output_formatted_text (pretty_printer *); +extern void pp_output_formatted_text (pretty_printer *, + const urlifier * = nullptr); extern void pp_format_verbatim (pretty_printer *, text_info *); extern void pp_indent (pretty_printer *); |