mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-14 23:03:04 +00:00
fixits: handle duplicates of %name-prefix
The test case "Deprecated directives" (currently 56) no longer emits warnings after 'bison -u'! * src/files.h, src/files.c (spec_name_prefix_loc): New. * src/parse-gram.y (handle_name_prefix): Emit fixits for duplicate %name-prefix. * tests/input.at (Deprecated directives): Adjust.
This commit is contained in:
@@ -45,6 +45,7 @@ char const *spec_outfile = NULL; /* for -o. */
|
|||||||
char const *spec_file_prefix = NULL; /* for -b. */
|
char const *spec_file_prefix = NULL; /* for -b. */
|
||||||
location spec_file_prefix_loc = EMPTY_LOCATION_INIT;
|
location spec_file_prefix_loc = EMPTY_LOCATION_INIT;
|
||||||
char const *spec_name_prefix = NULL; /* for -p. */
|
char const *spec_name_prefix = NULL; /* for -p. */
|
||||||
|
location spec_name_prefix_loc = EMPTY_LOCATION_INIT;;
|
||||||
char *spec_verbose_file = NULL; /* for --verbose. */
|
char *spec_verbose_file = NULL; /* for --verbose. */
|
||||||
char *spec_graph_file = NULL; /* for -g. */
|
char *spec_graph_file = NULL; /* for -g. */
|
||||||
char *spec_xml_file = NULL; /* for -x. */
|
char *spec_xml_file = NULL; /* for -x. */
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ extern char *parser_file_name;
|
|||||||
|
|
||||||
/* Symbol prefix specified with -p, or 0 if no -p. */
|
/* Symbol prefix specified with -p, or 0 if no -p. */
|
||||||
extern const char *spec_name_prefix;
|
extern const char *spec_name_prefix;
|
||||||
|
extern location spec_name_prefix_loc;
|
||||||
|
|
||||||
/* File name prefix specified with -b, or 0 if no -b. */
|
/* File name prefix specified with -b, or 0 if no -b. */
|
||||||
extern char const *spec_file_prefix;
|
extern char const *spec_file_prefix;
|
||||||
|
|||||||
@@ -3410,24 +3410,33 @@ static void
|
|||||||
handle_name_prefix (location const *loc,
|
handle_name_prefix (location const *loc,
|
||||||
char const *directive, char const *value)
|
char const *directive, char const *value)
|
||||||
{
|
{
|
||||||
spec_name_prefix = value;
|
bison_directive (loc, directive);
|
||||||
|
|
||||||
char buf1[1024];
|
char buf1[1024];
|
||||||
size_t len1 = sizeof (buf1);
|
size_t len1 = sizeof (buf1);
|
||||||
char *old = asnprintf (buf1, &len1, "%s\"%s\"", directive, value);
|
char *old = asnprintf (buf1, &len1, "%s\"%s\"", directive, value);
|
||||||
if (!old)
|
if (!old)
|
||||||
xalloc_die ();
|
xalloc_die ();
|
||||||
char buf2[1024];
|
|
||||||
size_t len2 = sizeof (buf2);
|
if (location_empty (spec_name_prefix_loc))
|
||||||
char *new = asnprintf (buf2, &len2, "%%define api.prefix {%s}", value);
|
{
|
||||||
if (!new)
|
spec_name_prefix = value;
|
||||||
xalloc_die ();
|
spec_name_prefix_loc = *loc;
|
||||||
bison_directive (loc, old);
|
|
||||||
deprecated_directive (loc, old, new);
|
char buf2[1024];
|
||||||
|
size_t len2 = sizeof (buf2);
|
||||||
|
char *new = asnprintf (buf2, &len2, "%%define api.prefix {%s}", value);
|
||||||
|
if (!new)
|
||||||
|
xalloc_die ();
|
||||||
|
deprecated_directive (loc, old, new);
|
||||||
|
if (new != buf2)
|
||||||
|
free (new);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
duplicate_directive (old, spec_file_prefix_loc, *loc);
|
||||||
|
|
||||||
if (old != buf1)
|
if (old != buf1)
|
||||||
free (old);
|
free (old);
|
||||||
if (new != buf2)
|
|
||||||
free (new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -905,24 +905,33 @@ static void
|
|||||||
handle_name_prefix (location const *loc,
|
handle_name_prefix (location const *loc,
|
||||||
char const *directive, char const *value)
|
char const *directive, char const *value)
|
||||||
{
|
{
|
||||||
spec_name_prefix = value;
|
bison_directive (loc, directive);
|
||||||
|
|
||||||
char buf1[1024];
|
char buf1[1024];
|
||||||
size_t len1 = sizeof (buf1);
|
size_t len1 = sizeof (buf1);
|
||||||
char *old = asnprintf (buf1, &len1, "%s\"%s\"", directive, value);
|
char *old = asnprintf (buf1, &len1, "%s\"%s\"", directive, value);
|
||||||
if (!old)
|
if (!old)
|
||||||
xalloc_die ();
|
xalloc_die ();
|
||||||
char buf2[1024];
|
|
||||||
size_t len2 = sizeof (buf2);
|
if (location_empty (spec_name_prefix_loc))
|
||||||
char *new = asnprintf (buf2, &len2, "%%define api.prefix {%s}", value);
|
{
|
||||||
if (!new)
|
spec_name_prefix = value;
|
||||||
xalloc_die ();
|
spec_name_prefix_loc = *loc;
|
||||||
bison_directive (loc, old);
|
|
||||||
deprecated_directive (loc, old, new);
|
char buf2[1024];
|
||||||
|
size_t len2 = sizeof (buf2);
|
||||||
|
char *new = asnprintf (buf2, &len2, "%%define api.prefix {%s}", value);
|
||||||
|
if (!new)
|
||||||
|
xalloc_die ();
|
||||||
|
deprecated_directive (loc, old, new);
|
||||||
|
if (new != buf2)
|
||||||
|
free (new);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
duplicate_directive (old, spec_file_prefix_loc, *loc);
|
||||||
|
|
||||||
if (old != buf1)
|
if (old != buf1)
|
||||||
free (old);
|
free (old);
|
||||||
if (new != buf2)
|
|
||||||
free (new);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2550,8 +2550,9 @@ fix-it:"input.y":{26:1-26:13}:"%token-table"
|
|||||||
input.y:27.1-14: error: %define variable 'parse.error' redefined
|
input.y:27.1-14: error: %define variable 'parse.error' redefined
|
||||||
input.y:11.1-14: previous definition
|
input.y:11.1-14: previous definition
|
||||||
fix-it:"input.y":{27:1-27:15}:""
|
fix-it:"input.y":{27:1-27:15}:""
|
||||||
input.y:29.1-18: warning: deprecated directive: '%name-prefix "bar"', use '%define api.prefix {bar}' [-Wdeprecated]
|
input.y:29.1-18: warning: duplicate directive: '%name-prefix "bar"' [-Wother]
|
||||||
fix-it:"input.y":{29:1-29:19}:"%define api.prefix {bar}"
|
input.y:13.1-20: previous declaration [-Wother]
|
||||||
|
fix-it:"input.y":{29:1-29:19}:""
|
||||||
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
@@ -2594,20 +2595,11 @@ AT_CHECK([cat input.y], [],
|
|||||||
%pure-parser
|
%pure-parser
|
||||||
%token-table
|
%token-table
|
||||||
%glr-parser
|
%glr-parser
|
||||||
%define api.prefix {bar}
|
|
||||||
%%
|
%%
|
||||||
exp : '0'
|
exp : '0'
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_BISON_CHECK([[-fcaret input.y]], [[1]], [],
|
AT_BISON_CHECK([[input.y]])
|
||||||
[[input.y:23.1-24: error: %define variable 'api.prefix' redefined
|
|
||||||
%define api.prefix {bar}
|
|
||||||
^~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
input.y:15.1-24: previous definition
|
|
||||||
%define api.prefix {foo}
|
|
||||||
^~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
|
||||||
]])
|
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user