mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
diagnostics: keep the fixits
Introduce proper support for fixits, instead of just printing them on demand. * bootstrap.conf: We need gnulib's xlists. * src/fixits.h, src/fixits.c: New. * src/complain.c (deprecated_directive): Use fixits_register. * src/main.c (main): Use fixits_free.
This commit is contained in:
@@ -28,9 +28,9 @@
|
||||
|
||||
#include "complain.h"
|
||||
#include "files.h"
|
||||
#include "fixits.h"
|
||||
#include "getargs.h"
|
||||
#include "quote.h"
|
||||
#include "quotearg.h"
|
||||
|
||||
err_status complaint_status = status_none;
|
||||
|
||||
@@ -394,14 +394,7 @@ 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));
|
||||
fixits_register (loc, upd);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
95
src/fixits.c
Normal file
95
src/fixits.c
Normal file
@@ -0,0 +1,95 @@
|
||||
/* Support for fixing grammar files.
|
||||
|
||||
Copyright (C) 2019 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "fixits.h"
|
||||
|
||||
#include "system.h"
|
||||
|
||||
#include "getargs.h"
|
||||
#include "gl_xlist.h"
|
||||
#include "gl_array_list.h"
|
||||
#include "quotearg.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
location location;
|
||||
char *fix;
|
||||
} fixit;
|
||||
|
||||
gl_list_t fixits = NULL;
|
||||
|
||||
static fixit *
|
||||
fixit_new (location const *loc, char const* fix)
|
||||
{
|
||||
fixit *res = xmalloc (sizeof *res);
|
||||
res->location = *loc;
|
||||
res->fix = xstrdup (fix);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
fixit_free (fixit *f)
|
||||
{
|
||||
free (f->fix);
|
||||
free (f);
|
||||
}
|
||||
|
||||
|
||||
/* GCC and Clang follow the same pattern.
|
||||
https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Message-Formatting-Options.html
|
||||
http://clang.llvm.org/docs/UsersManual.html#cmdoption-fdiagnostics-parseable-fixits */
|
||||
static void
|
||||
fixit_print (fixit const *f, FILE *out)
|
||||
{
|
||||
fprintf (out, "fix-it:%s:{%d:%d-%d:%d}:%s\n",
|
||||
quotearg_n_style (1, c_quoting_style, f->location.start.file),
|
||||
f->location.start.line, f->location.start.column,
|
||||
f->location.end.line, f->location.end.column,
|
||||
quotearg_n_style (2, c_quoting_style, f->fix));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fixits_register (location const *loc, char const* fix)
|
||||
{
|
||||
if (!fixits)
|
||||
fixits = gl_list_create_empty (GL_ARRAY_LIST,
|
||||
/* equals */ NULL,
|
||||
/* hashcode */ NULL,
|
||||
(gl_listelement_dispose_fn) fixit_free,
|
||||
true);
|
||||
fixit *f = fixit_new (loc, fix);
|
||||
gl_list_add_last (fixits, f);
|
||||
if (feature_flag & feature_fixit_parsable)
|
||||
fixit_print (f, stderr);
|
||||
}
|
||||
|
||||
|
||||
/* Free the registered fixits. */
|
||||
void fixits_free (void)
|
||||
{
|
||||
if (fixits)
|
||||
{
|
||||
gl_list_free (fixits);
|
||||
fixits = NULL;
|
||||
}
|
||||
}
|
||||
29
src/fixits.h
Normal file
29
src/fixits.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/* Support for fixing grammar files.
|
||||
|
||||
Copyright (C) 2019 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef FIXITS_H_
|
||||
# define FIXITS_H_ 1
|
||||
|
||||
# include "location.h"
|
||||
|
||||
/* Declare a fix to apply. */
|
||||
void fixits_register (location const *loc, char const* update);
|
||||
|
||||
/* Free the registered fixits. */
|
||||
void fixits_free (void);
|
||||
|
||||
#endif /* !FIXITS_H_ */
|
||||
@@ -46,6 +46,8 @@ src_bison_SOURCES = \
|
||||
src/derives.h \
|
||||
src/files.c \
|
||||
src/files.h \
|
||||
src/fixits.c \
|
||||
src/fixits.h \
|
||||
src/flex-scanner.h \
|
||||
src/getargs.c \
|
||||
src/getargs.h \
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "conflicts.h"
|
||||
#include "derives.h"
|
||||
#include "files.h"
|
||||
#include "fixits.h"
|
||||
#include "getargs.h"
|
||||
#include "gram.h"
|
||||
#include "lalr.h"
|
||||
@@ -205,6 +206,7 @@ main (int argc, char *argv[])
|
||||
conflicts_free ();
|
||||
grammar_free ();
|
||||
output_file_names_free ();
|
||||
fixits_free ();
|
||||
|
||||
/* The scanner memory cannot be released right after parsing, as it
|
||||
contains things such as user actions, prologue, epilogue etc. */
|
||||
|
||||
Reference in New Issue
Block a user