mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 16:53:02 +00:00
diagnostics: don't try to quote special files
Based on a report by Todd Freed. http://lists.gnu.org/archive/html/bug-bison/2019-04/msg00000.html See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90034 * src/location.c (caret_info): Also track the file name. (location_caret): Don't quote special files.
This commit is contained in:
1
THANKS
1
THANKS
@@ -170,6 +170,7 @@ Tim Josling tej@melbpc.org.au
|
|||||||
Tim Landscheidt tim@tim-landscheidt.de
|
Tim Landscheidt tim@tim-landscheidt.de
|
||||||
Tim Van Holder tim.van.holder@pandora.be
|
Tim Van Holder tim.van.holder@pandora.be
|
||||||
Tobias Frost tobi@debian.org
|
Tobias Frost tobi@debian.org
|
||||||
|
Todd Freed todd.freed@gmail.com
|
||||||
Tom Lane tgl@sss.pgh.pa.us
|
Tom Lane tgl@sss.pgh.pa.us
|
||||||
Tom Tromey tromey@cygnus.com
|
Tom Tromey tromey@cygnus.com
|
||||||
Tommy Nordgren tommy.nordgren@chello.se
|
Tommy Nordgren tommy.nordgren@chello.se
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include <mbswidth.h>
|
#include <mbswidth.h>
|
||||||
#include <quotearg.h>
|
#include <quotearg.h>
|
||||||
|
#include <stdio.h> /* fileno */
|
||||||
|
#include <sys/stat.h> /* fstat */
|
||||||
|
|
||||||
#include "complain.h"
|
#include "complain.h"
|
||||||
#include "location.h"
|
#include "location.h"
|
||||||
@@ -138,33 +140,63 @@ location_print (location loc, FILE *out)
|
|||||||
|
|
||||||
/* Persistent data used by location_caret to avoid reopening and rereading the
|
/* Persistent data used by location_caret to avoid reopening and rereading the
|
||||||
same file all over for each error. */
|
same file all over for each error. */
|
||||||
struct caret_info
|
static struct
|
||||||
{
|
{
|
||||||
FILE *source;
|
FILE *source;
|
||||||
|
/* The last file we tried to open. If non NULL, but SOURCE is NULL,
|
||||||
|
it means this file is special and should not be quoted. */
|
||||||
|
uniqstr file;
|
||||||
size_t line;
|
size_t line;
|
||||||
/* Offset in SOURCE where line LINE starts. */
|
/* Offset in SOURCE where line LINE starts. */
|
||||||
size_t offset;
|
size_t offset;
|
||||||
};
|
} caret_info;
|
||||||
|
|
||||||
static struct caret_info caret_info = { NULL, 1, 0 };
|
|
||||||
|
|
||||||
void
|
void
|
||||||
caret_free ()
|
caret_free ()
|
||||||
{
|
{
|
||||||
if (caret_info.source)
|
if (caret_info.source)
|
||||||
fclose (caret_info.source);
|
{
|
||||||
caret_info.source = NULL;
|
fclose (caret_info.source);
|
||||||
caret_info.line = 1;
|
caret_info.source = NULL;
|
||||||
caret_info.offset = 0;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
location_caret (location loc, const char *style, FILE *out)
|
location_caret (location loc, const char *style, FILE *out)
|
||||||
{
|
{
|
||||||
if (! (caret_info.source
|
if (loc.start.column == -1 || loc.start.line == -1)
|
||||||
|| (caret_info.source = fopen (loc.start.file, "r")))
|
|
||||||
|| loc.start.column == -1 || loc.start.line == -1)
|
|
||||||
return;
|
return;
|
||||||
|
/* If a different source than before, close and let the rest open
|
||||||
|
the new one. */
|
||||||
|
if (caret_info.file && caret_info.file != loc.start.file)
|
||||||
|
{
|
||||||
|
caret_free ();
|
||||||
|
caret_info.file = NULL;
|
||||||
|
}
|
||||||
|
if (!caret_info.file)
|
||||||
|
{
|
||||||
|
caret_info.file = loc.start.file;
|
||||||
|
if ((caret_info.source = fopen (caret_info.file, "r")))
|
||||||
|
{
|
||||||
|
/* If the file is not regular (imagine #line 1 "/dev/stdin"
|
||||||
|
in the input file for instance), don't try to quote the
|
||||||
|
source. Keep caret_info.file set so that we don't try to
|
||||||
|
open it again, but leave caret_info.source NULL so that
|
||||||
|
we don't try to quote it. */
|
||||||
|
struct stat buf;
|
||||||
|
if (fstat (fileno (caret_info.source), &buf) == 0
|
||||||
|
&& buf.st_mode & S_IFREG)
|
||||||
|
{
|
||||||
|
caret_info.line = 1;
|
||||||
|
caret_info.offset = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
caret_free ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!caret_info.source)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
/* If the line we want to quote is seekable (the same line as the previous
|
/* If the line we want to quote is seekable (the same line as the previous
|
||||||
location), just seek it. If it was a previous line, we lost track of it,
|
location), just seek it. If it was a previous line, we lost track of it,
|
||||||
|
|||||||
@@ -161,5 +161,27 @@ input.y:18.4-17: <warning>warning:</warning> empty rule without %empty [<warning
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
|
|
||||||
|
## -------------- ##
|
||||||
|
## Special files. ##
|
||||||
|
## -------------- ##
|
||||||
|
|
||||||
|
# Don't try to quote special files.
|
||||||
|
# http://lists.gnu.org/archive/html/bug-bison/2019-04/msg00000.html
|
||||||
|
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90034
|
||||||
|
|
||||||
|
AT_TEST([[Special files]],
|
||||||
|
[[%%
|
||||||
|
exp: a b
|
||||||
|
a: {}
|
||||||
|
#line 1 "/dev/stdout"
|
||||||
|
b: {}
|
||||||
|
]],
|
||||||
|
[[input.y:11.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
|
||||||
|
11 | a: <warning>{}</warning>
|
||||||
|
| <warning>^~</warning>
|
||||||
|
/dev/stdout:1.4-5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
|
||||||
|
]])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m4_popdef([AT_TEST])
|
m4_popdef([AT_TEST])
|
||||||
|
|||||||
Reference in New Issue
Block a user