mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-12 13:53:03 +00:00
diagnostics: display suggested update after the caret-info
This commit adds the suggestion in green, on the line below the
caret-and-tildes.
foo.y:1.1-14: warning: deprecated directive: '%error-verbose', use '%define parse.error verbose' [-Wdeprecated]
1 | %error-verbose
| ^~~~~~~~~~~~~~
| %define parse.error verbose
The current approach, with location_caret_suggestion, is fragile:
there's a protocol of calls to the complain functions which is strict.
We should rather have a richer structure describing the diagnostics,
including with submessages such as the suggestions, passed in the end
to the routines in charge of formatting and printing them.
* src/location.h, src/location.c (location_caret_suggestion): New.
* src/complain.c (deprecated_directive): Use it.
* tests/diagnostics.at, tests/input.at: Adjust expectations.
This commit is contained in:
@@ -546,17 +546,16 @@ bison_directive (location const *loc, char const *directive)
|
||||
void
|
||||
deprecated_directive (location const *loc, char const *old, char const *upd)
|
||||
{
|
||||
if (feature_flag & feature_caret)
|
||||
complain (loc, Wdeprecated,
|
||||
_("deprecated directive, use %s"),
|
||||
quote_n (1, upd));
|
||||
else
|
||||
complain (loc, Wdeprecated,
|
||||
_("deprecated directive: %s, use %s"),
|
||||
quote (old), quote_n (1, upd));
|
||||
/* Register updates only if -Wdeprecated is enabled. */
|
||||
if (warning_is_enabled (Wdeprecated))
|
||||
fixits_register (loc, upd);
|
||||
{
|
||||
complain (loc, Wdeprecated,
|
||||
_("deprecated directive: %s, use %s"),
|
||||
quote (old), quote_n (1, upd));
|
||||
if (feature_flag & feature_caret)
|
||||
location_caret_suggestion (*loc, upd, stderr);
|
||||
/* Register updates only if -Wdeprecated is enabled. */
|
||||
fixits_register (loc, upd);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -470,6 +470,19 @@ location_caret (location loc, const char *style, FILE *out)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
location_caret_suggestion (location loc, const char *s, FILE *out)
|
||||
{
|
||||
const char *style = "insertion";
|
||||
fprintf (out, " | %*s",
|
||||
loc.start.column - 1 - caret_info.skip + (caret_info.skip ? 3 : 0),
|
||||
"");
|
||||
begin_use_class (style, out);
|
||||
fputs (s, out);
|
||||
end_use_class (style, out);
|
||||
putc ('\n', out);
|
||||
}
|
||||
|
||||
bool
|
||||
location_empty (location loc)
|
||||
{
|
||||
|
||||
@@ -125,6 +125,10 @@ void caret_free (void);
|
||||
with the color STYLE. */
|
||||
void location_caret (location loc, const char* style, FILE *out);
|
||||
|
||||
/* Display a suggestion of replacement for LOC with S. To call after
|
||||
location_caret. */
|
||||
void location_caret_suggestion (location loc, const char *s, FILE *out);
|
||||
|
||||
/* Return -1, 0, 1, depending whether a is before, equal, or
|
||||
after b. */
|
||||
static inline int
|
||||
|
||||
Reference in New Issue
Block a user