mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-19 09:13:04 +00:00
c: no longer require stdio.h when locations are enabled
Recent changes (in 2.7) introduced a dependency on both FILE and fprintf, which are "available" only in %debug mode. This was to define yy_location_print_, which is used only in %debug mode by the parser, but massively used by the test suite to output the locations in yyerror. Break this dependency: the test suite should define its own routines to display the locations. Eventually Bison will provide the user with a means to display locations, but not yet. * data/c.m4 (b4_yy_location_print_define): Use YYFPRINTF instead of fprintf directly. * data/yacc.c (b4_yy_location_print_define): Invoke it only in %debug mode, so that stdio.h is included (needed for FILE*), and YYFPRINTF is defined. * tests/local.at (AT_YYERROR_DECLARE, AT_YYERROR_DEFINE): Declare and define location_print and LOCATION_PRINT. * tests/actions.at, tests/existing.at, tests/glr-regression.at, * tests/input.at, tests/named-refs.at, tests/regression.at: Adjust to use them. Fix the expected line numbers (as the prologue's length has changed).
This commit is contained in:
@@ -32,10 +32,10 @@ AT_BISON_OPTION_PUSHDEFS
|
||||
AT_DATA_GRAMMAR([[input.y]],
|
||||
[[%define parse.error verbose
|
||||
%debug
|
||||
%{
|
||||
%code {
|
||||
]AT_YYERROR_DECLARE[
|
||||
]AT_YYLEX_DECLARE[
|
||||
%}
|
||||
}
|
||||
%%
|
||||
exp: { putchar ('0'); }
|
||||
'1' { putchar ('1'); }
|
||||
@@ -92,7 +92,7 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
}
|
||||
%%
|
||||
exp: { ]AT_SKEL_CC_IF([[std::cerr << @$ << std::endl]],
|
||||
[[YY_LOCATION_PRINT(stderr, @$); fputc ('\n', stderr)]])[; }
|
||||
[[LOCATION_PRINT(stderr, @$); fputc ('\n', stderr)]])[; }
|
||||
%%
|
||||
]AT_YYERROR_DEFINE[
|
||||
|
||||
@@ -146,7 +146,7 @@ AT_TEST([glr.cc])
|
||||
AT_TEST([yacc.c], [%define api.pure full],
|
||||
[[%{
|
||||
# define YYLTYPE int
|
||||
# define YY_LOCATION_PRINT(Stream, Loc) \
|
||||
# define LOCATION_PRINT(Stream, Loc) \
|
||||
(void) (Loc)
|
||||
# define YYLLOC_DEFAULT(Current, Rhs, N) \
|
||||
(Current) = ((Rhs)[N ? 1 : 0])
|
||||
@@ -157,7 +157,7 @@ AT_TEST([yacc.c], [%define api.pure full],
|
||||
AT_TEST([yacc.c], [%define api.pure full],
|
||||
[[%{
|
||||
# define YYLTYPE int
|
||||
# define YY_LOCATION_PRINT(Stream, Loc) \
|
||||
# define LOCATION_PRINT(Stream, Loc) \
|
||||
fprintf ((Stream), "%d", (Loc))
|
||||
# define YYLLOC_DEFAULT(Current, Rhs, N) \
|
||||
(Current) = ((Rhs)[N ? 1 : 0])
|
||||
@@ -190,8 +190,6 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
]$3[
|
||||
%code
|
||||
{
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h> /* getenv */
|
||||
]AT_YYERROR_DECLARE[
|
||||
]AT_YYLEX_DECLARE[
|
||||
}
|
||||
@@ -212,7 +210,7 @@ main (void)
|
||||
loc.]AT_LAST_LINE[ = L2; \
|
||||
loc.]AT_LAST_COLUMN[ = C2; \
|
||||
]AT_SKEL_CC_IF([std::cout << loc],
|
||||
[YY_LOCATION_PRINT(stdout, loc)])[;\
|
||||
[LOCATION_PRINT(stdout, loc)])[;\
|
||||
putchar ('\n');
|
||||
|
||||
TEST(1, 1, 1, 1);
|
||||
@@ -259,11 +257,11 @@ AT_BISON_OPTION_PUSHDEFS
|
||||
AT_DATA_GRAMMAR([[input.y]],
|
||||
[[%define parse.error verbose
|
||||
%debug
|
||||
%{
|
||||
%code {
|
||||
]AT_YYERROR_DECLARE[
|
||||
]AT_YYLEX_DECLARE[
|
||||
# define USE(Var)
|
||||
%}
|
||||
}
|
||||
|
||||
%union
|
||||
{
|
||||
@@ -309,7 +307,6 @@ AT_PARSER_CHECK([./input], 0,
|
||||
AT_DATA_GRAMMAR([[input.y]],
|
||||
[[
|
||||
%{
|
||||
# include <stdio.h>
|
||||
]AT_YYERROR_DECLARE[
|
||||
]AT_YYLEX_DECLARE[
|
||||
typedef struct { int val; } stype;
|
||||
@@ -764,13 +761,11 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
%debug
|
||||
%locations
|
||||
|
||||
%{
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
%code {
|
||||
]AT_YYLEX_DECLARE[
|
||||
]AT_YYERROR_DECLARE[
|
||||
# define USE(SYM)
|
||||
%}
|
||||
}
|
||||
|
||||
%printer {
|
||||
fprintf (yyoutput, "<*> printer should not be called.\n");
|
||||
@@ -805,8 +800,8 @@ start: 'a' 'b' 'c' 'd' 'e' { $$ = 'S'; USE(($1, $2, $3, $4, $5)); } ;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([-o input.c input.y], [], [],
|
||||
[[input.y:23.3-5: warning: useless %destructor for type <*> [-Wother]
|
||||
input.y:23.3-5: warning: useless %printer for type <*> [-Wother]
|
||||
[[input.y:30.3-5: warning: useless %destructor for type <*> [-Wother]
|
||||
input.y:30.3-5: warning: useless %printer for type <*> [-Wother]
|
||||
]])
|
||||
AT_COMPILE([input])
|
||||
AT_PARSER_CHECK([./input --debug], 1,
|
||||
@@ -859,8 +854,6 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
%debug
|
||||
|
||||
%{
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
]AT_YYERROR_DECLARE[
|
||||
]AT_YYLEX_DECLARE[
|
||||
# define USE(SYM)
|
||||
@@ -988,13 +981,11 @@ AT_DATA_GRAMMAR([[input]]$1[[.y]],
|
||||
%debug
|
||||
%locations
|
||||
|
||||
%{
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
%code {
|
||||
]AT_YYERROR_DECLARE[
|
||||
]AT_YYLEX_DECLARE[
|
||||
# define USE(SYM)
|
||||
%}
|
||||
}
|
||||
|
||||
%destructor {
|
||||
fprintf (yyoutput, "<]]not_kind[[> destructor should not be called.\n");
|
||||
@@ -1022,7 +1013,7 @@ AT_DATA_GRAMMAR([[input]]$1[[.y]],
|
||||
start: { $$ = 'S'; } ;
|
||||
|
||||
%%
|
||||
|
||||
#include <stdlib.h> // abort
|
||||
static int
|
||||
yylex (void)
|
||||
{
|
||||
@@ -1041,11 +1032,11 @@ AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([-o input$1.c input$1.y], [], [],
|
||||
[m4_if([$1], [0],
|
||||
[[input0.y:23.3-5: warning: useless %destructor for type <*> [-Wother]
|
||||
input0.y:23.3-5: warning: useless %printer for type <*> [-Wother]
|
||||
[[input0.y:30.3-5: warning: useless %destructor for type <*> [-Wother]
|
||||
input0.y:30.3-5: warning: useless %printer for type <*> [-Wother]
|
||||
]],
|
||||
[[input1.y:23.3-4: warning: useless %destructor for type <> [-Wother]
|
||||
input1.y:23.3-4: warning: useless %printer for type <> [-Wother]
|
||||
[[input1.y:30.3-4: warning: useless %destructor for type <> [-Wother]
|
||||
input1.y:30.3-4: warning: useless %printer for type <> [-Wother]
|
||||
]])])
|
||||
|
||||
AT_COMPILE([input$1])
|
||||
@@ -1056,7 +1047,7 @@ AT_PARSER_CHECK([./input$1 --debug], 0,
|
||||
]],
|
||||
[[Starting parse
|
||||
Entering state 0
|
||||
Reducing stack by rule 1 (line 42):
|
||||
Reducing stack by rule 1 (line 49):
|
||||
-> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
|
||||
Stack now 0
|
||||
Entering state 1
|
||||
@@ -1131,8 +1122,8 @@ start:
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([-o input.c input.y], [], [],
|
||||
[[input.y:21.6-8: warning: useless %destructor for type <*> [-Wother]
|
||||
input.y:21.6-8: warning: useless %printer for type <*> [-Wother]
|
||||
[[input.y:23.6-8: warning: useless %destructor for type <*> [-Wother]
|
||||
input.y:23.6-8: warning: useless %printer for type <*> [-Wother]
|
||||
]])
|
||||
AT_COMPILE([input])
|
||||
AT_PARSER_CHECK([./input --debug], [1], [],
|
||||
@@ -1229,8 +1220,8 @@ start: { USE($$); } ;
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_BISON_CHECK([-o input.c input.y], [], [],
|
||||
[[input.y:22.3-4: warning: useless %destructor for type <> [-Wother]
|
||||
input.y:22.3-4: warning: useless %printer for type <> [-Wother]
|
||||
[[input.y:24.3-4: warning: useless %destructor for type <> [-Wother]
|
||||
input.y:24.3-4: warning: useless %printer for type <> [-Wother]
|
||||
]])
|
||||
AT_COMPILE([input])
|
||||
|
||||
@@ -1249,14 +1240,12 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
[[%debug /* So that %printer is actually compiled. */
|
||||
|
||||
%{
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
]AT_YYERROR_DECLARE[
|
||||
]AT_YYLEX_DECLARE[
|
||||
# define USE(SYM)
|
||||
# define YYLTYPE int
|
||||
# define YYLLOC_DEFAULT(Current, Rhs, N) (void)(Rhs)
|
||||
# define YY_LOCATION_PRINT(File, Loc)
|
||||
# define LOCATION_PRINT(File, Loc)
|
||||
%}
|
||||
|
||||
%printer { fprintf (yyoutput, "%d", @$); } <>
|
||||
|
||||
Reference in New Issue
Block a user