diagnostics: add -ffixit support for deprecated features

Issue directives for IDE/editors to fix the source file.
http://clang.llvm.org/docs/UsersManual.html#cmdoption-fdiagnostics-parseable-fixits

Do it for deprecated features.  For instance:

    $ cat foo.y
    %error-verbose

    %name-prefix = "foo"
    %name-prefix="bar"
    %define parser_class_name "Parser"

    %%
    exp:;

    $ LC_ALL=C ./_build/8d/tests/bison -ffixit /tmp/foo.yy
    /tmp/foo.yy:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
     %error-verbose
     ^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{1:1-1:15}:"%define parse.error verbose"
    /tmp/foo.yy:3.1-20: warning: deprecated directive, use '%define api.prefix {foo}' [-Wdeprecated]
     %name-prefix = "foo"
     ^^^^^^^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{3:1-3:21}:"%define api.prefix {foo}"
    /tmp/foo.yy:4.1-18: warning: deprecated directive, use '%define api.prefix {bar}' [-Wdeprecated]
     %name-prefix="bar"
     ^^^^^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{4:1-4:19}:"%define api.prefix {bar}"
    /tmp/foo.yy:5.9-25: warning: deprecated directive, use '%define api.parser.class {Parser}' [-Wdeprecated]
     %define parser_class_name "Parser"
             ^^^^^^^^^^^^^^^^^
    fix-it:"/tmp/foo.yy":{5:9-5:26}:"%define api.parser.class {Parser}"
    /tmp/foo.yy:5.9-25: error: %define variable 'api.parser.class' is not used
     %define parser_class_name "Parser"
             ^^^^^^^^^^^^^^^^^

* src/getargs.h, src/getargs.c (feature_fixit_parsable): New.
(feature_types, feature_args): Use it.
* src/complain.c (deprecated_directive): Use it.

* tests/input.at: Check it.
This commit is contained in:
Akim Demaille
2019-01-12 16:53:32 +01:00
parent a7ff1c75be
commit dad14ec3e4
4 changed files with 52 additions and 3 deletions

View File

@@ -30,6 +30,7 @@
#include "files.h"
#include "getargs.h"
#include "quote.h"
#include "quotearg.h"
err_status complaint_status = status_none;
@@ -393,6 +394,14 @@ deprecated_directive (location const *loc, char const *old, char const *upd)
complain (loc, Wdeprecated,
_("deprecated directive: %s, use %s"),
quote (old), quote_n (1, upd));
/* GCC and Clang follow the same pattern.
http://clang.llvm.org/docs/UsersManual.html#cmdoption-fdiagnostics-parseable-fixits */
if (feature_flag & feature_fixit_parsable)
fprintf (stderr, "fix-it:%s:{%d:%d-%d:%d}:%s\n",
quotearg_n_style (1, c_quoting_style, loc->start.file),
loc->start.line, loc->start.column,
loc->end.line, loc->end.column,
quotearg_n_style (2, c_quoting_style, upd));
}
void

View File

@@ -228,6 +228,7 @@ static const char * const feature_args[] =
{
"none",
"caret", "diagnostics-show-caret",
"fixit", "diagnostics-parseable-fixits",
"all",
0
};
@@ -236,6 +237,7 @@ static const int feature_types[] =
{
feature_none,
feature_caret, feature_caret,
feature_fixit_parsable, feature_fixit_parsable,
feature_all
};

View File

@@ -114,9 +114,10 @@ extern int trace_flag;
enum feature
{
feature_none = 0, /**< No additional feature. */
feature_caret = 1 << 0, /**< Enhance the output of errors with carets. */
feature_all = ~0 /**< All above features. */
feature_none = 0, /**< No additional feature. */
feature_caret = 1 << 0, /**< Output errors with carets. */
feature_fixit_parsable = 1 << 1, /**< Issue instructions to fix the sources. */
feature_all = ~0 /**< All above features. */
};
/** What additional features to use. */
extern int feature_flag;