mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-16 15:53: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:
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
# gnulib modules used by this package.
|
# gnulib modules used by this package.
|
||||||
gnulib_modules='
|
gnulib_modules='
|
||||||
argmatch assert
|
argmatch array-list assert
|
||||||
bitsetv
|
bitsetv
|
||||||
calloc-posix close closeout config-h c-strcase
|
calloc-posix close closeout config-h c-strcase
|
||||||
configmake
|
configmake
|
||||||
@@ -26,7 +26,9 @@ gnulib_modules='
|
|||||||
getopt-gnu
|
getopt-gnu
|
||||||
gettext git-version-gen gitlog-to-changelog
|
gettext git-version-gen gitlog-to-changelog
|
||||||
gpl-3.0 hash inttypes isnan javacomp-script
|
gpl-3.0 hash inttypes isnan javacomp-script
|
||||||
javaexec-script ldexpl malloc-gnu
|
javaexec-script
|
||||||
|
ldexpl
|
||||||
|
malloc-gnu
|
||||||
mbswidth
|
mbswidth
|
||||||
non-recursive-gnulib-prefix-hack
|
non-recursive-gnulib-prefix-hack
|
||||||
obstack
|
obstack
|
||||||
@@ -44,6 +46,7 @@ gnulib_modules='
|
|||||||
xalloc
|
xalloc
|
||||||
xalloc-die
|
xalloc-die
|
||||||
xconcat-filename
|
xconcat-filename
|
||||||
|
xlist
|
||||||
xmemdup0
|
xmemdup0
|
||||||
xstrndup
|
xstrndup
|
||||||
|
|
||||||
|
|||||||
78
lib/.gitignore
vendored
78
lib/.gitignore
vendored
@@ -8,6 +8,10 @@
|
|||||||
/alignof.h
|
/alignof.h
|
||||||
/alloca.h
|
/alloca.h
|
||||||
/alloca.in.h
|
/alloca.in.h
|
||||||
|
/allocator.c
|
||||||
|
/allocator.h
|
||||||
|
/areadlink.c
|
||||||
|
/areadlink.h
|
||||||
/arg-nonnull.h
|
/arg-nonnull.h
|
||||||
/argmatch.c
|
/argmatch.c
|
||||||
/argmatch.h
|
/argmatch.h
|
||||||
@@ -18,6 +22,11 @@
|
|||||||
/binary-io.h
|
/binary-io.h
|
||||||
/bitrotate.c
|
/bitrotate.c
|
||||||
/bitrotate.h
|
/bitrotate.h
|
||||||
|
/bitset.c
|
||||||
|
/bitset.h
|
||||||
|
/bitset/
|
||||||
|
/bitsetv.c
|
||||||
|
/bitsetv.h
|
||||||
/c++defs.h
|
/c++defs.h
|
||||||
/c-ctype.c
|
/c-ctype.c
|
||||||
/c-ctype.h
|
/c-ctype.h
|
||||||
@@ -26,6 +35,9 @@
|
|||||||
/c-strcaseeq.h
|
/c-strcaseeq.h
|
||||||
/c-strncasecmp.c
|
/c-strncasecmp.c
|
||||||
/calloc.c
|
/calloc.c
|
||||||
|
/canonicalize-lgpl.c
|
||||||
|
/careadlinkat.c
|
||||||
|
/careadlinkat.h
|
||||||
/charset.alias
|
/charset.alias
|
||||||
/cloexec.c
|
/cloexec.c
|
||||||
/cloexec.h
|
/cloexec.h
|
||||||
@@ -78,6 +90,8 @@
|
|||||||
/fseterr.h
|
/fseterr.h
|
||||||
/fstat.c
|
/fstat.c
|
||||||
/getdtablesize.c
|
/getdtablesize.c
|
||||||
|
/gethrxtime.c
|
||||||
|
/gethrxtime.h
|
||||||
/getopt-cdefs.in.h
|
/getopt-cdefs.in.h
|
||||||
/getopt-core.h
|
/getopt-core.h
|
||||||
/getopt-ext.h
|
/getopt-ext.h
|
||||||
@@ -90,7 +104,16 @@
|
|||||||
/getopt_int.h
|
/getopt_int.h
|
||||||
/getprogname.c
|
/getprogname.c
|
||||||
/getprogname.h
|
/getprogname.h
|
||||||
|
/getrusage.c
|
||||||
/gettext.h
|
/gettext.h
|
||||||
|
/gettime.c
|
||||||
|
/gettimeofday.c
|
||||||
|
/gl_array_list.c
|
||||||
|
/gl_array_list.h
|
||||||
|
/gl_list.c
|
||||||
|
/gl_list.h
|
||||||
|
/gl_xlist.c
|
||||||
|
/gl_xlist.h
|
||||||
/gnulib.mk
|
/gnulib.mk
|
||||||
/hard-locale.c
|
/hard-locale.c
|
||||||
/hard-locale.h
|
/hard-locale.h
|
||||||
@@ -112,6 +135,8 @@
|
|||||||
/limits.in.h
|
/limits.in.h
|
||||||
/localcharset.c
|
/localcharset.c
|
||||||
/localcharset.h
|
/localcharset.h
|
||||||
|
/localtime-buffer.c
|
||||||
|
/localtime-buffer.h
|
||||||
/lstat.c
|
/lstat.c
|
||||||
/malloc.c
|
/malloc.c
|
||||||
/malloca.c
|
/malloca.c
|
||||||
@@ -150,17 +175,23 @@
|
|||||||
/printf.c
|
/printf.c
|
||||||
/progname.c
|
/progname.c
|
||||||
/progname.h
|
/progname.h
|
||||||
|
/progreloc.c
|
||||||
/quote.h
|
/quote.h
|
||||||
/quotearg.c
|
/quotearg.c
|
||||||
/quotearg.h
|
/quotearg.h
|
||||||
/raise.c
|
/raise.c
|
||||||
/rawmemchr.c
|
/rawmemchr.c
|
||||||
/rawmemchr.valgrind
|
/rawmemchr.valgrind
|
||||||
|
/readlink.c
|
||||||
/realloc.c
|
/realloc.c
|
||||||
/ref-add.sed
|
/ref-add.sed
|
||||||
/ref-del.sed
|
/ref-del.sed
|
||||||
|
/relocatable.c
|
||||||
|
/relocatable.h
|
||||||
|
/relocwrapper.c
|
||||||
/sched.h
|
/sched.h
|
||||||
/sched.in.h
|
/sched.in.h
|
||||||
|
/setenv.c
|
||||||
/sig-handler.c
|
/sig-handler.c
|
||||||
/sig-handler.h
|
/sig-handler.h
|
||||||
/sigaction.c
|
/sigaction.c
|
||||||
@@ -190,6 +221,8 @@
|
|||||||
/spawnp.c
|
/spawnp.c
|
||||||
/sprintf.c
|
/sprintf.c
|
||||||
/stamp-h1
|
/stamp-h1
|
||||||
|
/stat-time.c
|
||||||
|
/stat-time.h
|
||||||
/stat-w32.c
|
/stat-w32.c
|
||||||
/stat-w32.h
|
/stat-w32.h
|
||||||
/stat.c
|
/stat.c
|
||||||
@@ -223,13 +256,20 @@
|
|||||||
/strverscmp.c
|
/strverscmp.c
|
||||||
/sys
|
/sys
|
||||||
/sys_ioctl.in.h
|
/sys_ioctl.in.h
|
||||||
|
/sys_resource.in.h
|
||||||
/sys_socket.in.h
|
/sys_socket.in.h
|
||||||
/sys_stat.in.h
|
/sys_stat.in.h
|
||||||
|
/sys_time.in.h
|
||||||
|
/sys_times.in.h
|
||||||
/sys_types.in.h
|
/sys_types.in.h
|
||||||
/sys_wait.in.h
|
/sys_wait.in.h
|
||||||
/sysexits.in.h
|
/sysexits.in.h
|
||||||
/time.h
|
/time.h
|
||||||
/time.in.h
|
/time.in.h
|
||||||
|
/timespec.c
|
||||||
|
/timespec.h
|
||||||
|
/timevar.c
|
||||||
|
/timevar.h
|
||||||
/unistd--.h
|
/unistd--.h
|
||||||
/unistd-safer.h
|
/unistd-safer.h
|
||||||
/unistd.c
|
/unistd.c
|
||||||
@@ -267,45 +307,11 @@
|
|||||||
/xmalloc.c
|
/xmalloc.c
|
||||||
/xmemdup0.c
|
/xmemdup0.c
|
||||||
/xmemdup0.h
|
/xmemdup0.h
|
||||||
|
/xreadlink.c
|
||||||
|
/xreadlink.h
|
||||||
/xsize.c
|
/xsize.c
|
||||||
/xsize.h
|
/xsize.h
|
||||||
/xstrndup.c
|
/xstrndup.c
|
||||||
/xstrndup.h
|
/xstrndup.h
|
||||||
/stat-time.c
|
|
||||||
/stat-time.h
|
|
||||||
/timevar.c
|
|
||||||
/timevar.h
|
|
||||||
/sys_time.in.h
|
|
||||||
/sys_times.in.h
|
|
||||||
/gethrxtime.c
|
|
||||||
/gethrxtime.h
|
|
||||||
/getrusage.c
|
|
||||||
/gettime.c
|
|
||||||
/gettimeofday.c
|
|
||||||
/localtime-buffer.c
|
|
||||||
/localtime-buffer.h
|
|
||||||
/sys_resource.in.h
|
|
||||||
/timespec.c
|
|
||||||
/timespec.h
|
|
||||||
/xtime.c
|
/xtime.c
|
||||||
/xtime.h
|
/xtime.h
|
||||||
/bitset.c
|
|
||||||
/bitset.h
|
|
||||||
/bitset/
|
|
||||||
/bitsetv.c
|
|
||||||
/bitsetv.h
|
|
||||||
/allocator.c
|
|
||||||
/allocator.h
|
|
||||||
/areadlink.c
|
|
||||||
/areadlink.h
|
|
||||||
/canonicalize-lgpl.c
|
|
||||||
/careadlinkat.c
|
|
||||||
/careadlinkat.h
|
|
||||||
/progreloc.c
|
|
||||||
/readlink.c
|
|
||||||
/relocatable.c
|
|
||||||
/relocatable.h
|
|
||||||
/relocwrapper.c
|
|
||||||
/setenv.c
|
|
||||||
/xreadlink.c
|
|
||||||
/xreadlink.h
|
|
||||||
|
|||||||
@@ -28,9 +28,9 @@
|
|||||||
|
|
||||||
#include "complain.h"
|
#include "complain.h"
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
|
#include "fixits.h"
|
||||||
#include "getargs.h"
|
#include "getargs.h"
|
||||||
#include "quote.h"
|
#include "quote.h"
|
||||||
#include "quotearg.h"
|
|
||||||
|
|
||||||
err_status complaint_status = status_none;
|
err_status complaint_status = status_none;
|
||||||
|
|
||||||
@@ -394,14 +394,7 @@ deprecated_directive (location const *loc, char const *old, char const *upd)
|
|||||||
complain (loc, Wdeprecated,
|
complain (loc, Wdeprecated,
|
||||||
_("deprecated directive: %s, use %s"),
|
_("deprecated directive: %s, use %s"),
|
||||||
quote (old), quote_n (1, upd));
|
quote (old), quote_n (1, upd));
|
||||||
/* GCC and Clang follow the same pattern.
|
fixits_register (loc, upd);
|
||||||
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
|
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/derives.h \
|
||||||
src/files.c \
|
src/files.c \
|
||||||
src/files.h \
|
src/files.h \
|
||||||
|
src/fixits.c \
|
||||||
|
src/fixits.h \
|
||||||
src/flex-scanner.h \
|
src/flex-scanner.h \
|
||||||
src/getargs.c \
|
src/getargs.c \
|
||||||
src/getargs.h \
|
src/getargs.h \
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include "conflicts.h"
|
#include "conflicts.h"
|
||||||
#include "derives.h"
|
#include "derives.h"
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
|
#include "fixits.h"
|
||||||
#include "getargs.h"
|
#include "getargs.h"
|
||||||
#include "gram.h"
|
#include "gram.h"
|
||||||
#include "lalr.h"
|
#include "lalr.h"
|
||||||
@@ -205,6 +206,7 @@ main (int argc, char *argv[])
|
|||||||
conflicts_free ();
|
conflicts_free ();
|
||||||
grammar_free ();
|
grammar_free ();
|
||||||
output_file_names_free ();
|
output_file_names_free ();
|
||||||
|
fixits_free ();
|
||||||
|
|
||||||
/* The scanner memory cannot be released right after parsing, as it
|
/* The scanner memory cannot be released right after parsing, as it
|
||||||
contains things such as user actions, prologue, epilogue etc. */
|
contains things such as user actions, prologue, epilogue etc. */
|
||||||
|
|||||||
Reference in New Issue
Block a user