mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
yacc.c, glr.c: a better YY_LOCATION_PRINT
* data/c.m4 (b4_yy_location_print_define): New. Now issues "short" locations, e.g., "1.1" instead of "1.1-1.1". Was initially a function, but then we face "static but unused" warnings. Simpler as a macro. * tests/local.at, data/glr.c, data/yacc.c: Use it instead of duplicating. * tests/actions.at: Adjust expectations.
This commit is contained in:
31
data/c.m4
31
data/c.m4
@@ -644,8 +644,37 @@ m4_define([b4_yylloc_default_define],
|
||||
#endif
|
||||
]])
|
||||
|
||||
# b4_yy_location_print_define
|
||||
# ---------------------------
|
||||
# Define YY_LOCATION_PRINT.
|
||||
m4_define([b4_yy_location_print_define],
|
||||
[b4_locations_if([[
|
||||
/* YY_LOCATION_PRINT -- Print the location on the stream.
|
||||
This macro was not mandated originally: define only if we know
|
||||
we won't break user code: when these are the locations we know. */
|
||||
|
||||
#ifndef YY_LOCATION_PRINT
|
||||
# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
|
||||
# define YY_LOCATION_PRINT(File, Loc) \
|
||||
do { \
|
||||
fprintf (File, "%d.%d", (Loc).first_line, (Loc).first_column); \
|
||||
if ((Loc).first_line < (Loc).last_line) \
|
||||
fprintf (File, "-%d.%d", (Loc).last_line, (Loc).last_column - 1); \
|
||||
else if ((Loc).first_column < (Loc).last_column - 1) \
|
||||
fprintf (File, "-%d", (Loc).last_column - 1); \
|
||||
} while (0)
|
||||
# else
|
||||
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
|
||||
# endif
|
||||
#endif]],
|
||||
[[/* This macro is provided for backward compatibility. */
|
||||
#ifndef YY_LOCATION_PRINT
|
||||
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
|
||||
#endif]])
|
||||
])
|
||||
|
||||
# b4_yyloc_default_define
|
||||
# ------------------------
|
||||
# -----------------------
|
||||
# Define yyloc_default, which can be used to initialize location
|
||||
# variables.
|
||||
m4_define([b4_yyloc_default_define],
|
||||
|
||||
22
data/glr.c
22
data/glr.c
@@ -475,28 +475,10 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] =
|
||||
#define YYTERROR 1
|
||||
|
||||
]b4_locations_if([[
|
||||
#ifndef YYLLOC_DEFAULT
|
||||
]b4_yylloc_default_define[
|
||||
# define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)
|
||||
|
||||
/* YY_LOCATION_PRINT -- Print the location on the stream.
|
||||
This macro was not mandated originally: define only if we know
|
||||
we won't break user code: when these are the locations we know. */
|
||||
|
||||
# define YY_LOCATION_PRINT(File, Loc) \
|
||||
fprintf (File, "%d.%d-%d.%d", \
|
||||
(Loc).first_line, (Loc).first_column, \
|
||||
(Loc).last_line, (Loc).last_column)
|
||||
#endif
|
||||
]],[
|
||||
#ifndef YYLLOC_DEFAULT
|
||||
# define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)
|
||||
#endif
|
||||
])[
|
||||
|
||||
#ifndef YY_LOCATION_PRINT
|
||||
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
|
||||
#endif
|
||||
]])[
|
||||
]b4_yy_location_print_define[
|
||||
|
||||
/* YYLEX -- calling `yylex' with the right arguments. */
|
||||
#define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
|
||||
|
||||
24
data/yacc.c
24
data/yacc.c
@@ -766,33 +766,15 @@ do \
|
||||
} \
|
||||
while (YYID (0))
|
||||
|
||||
|
||||
/* Error token number */
|
||||
#define YYTERROR 1
|
||||
#define YYERRCODE 256
|
||||
|
||||
]b4_locations_if([[
|
||||
]b4_yylloc_default_define[
|
||||
#define YYRHSLOC(Rhs, K) ((Rhs)[K])
|
||||
|
||||
/* YY_LOCATION_PRINT -- Print the location on the stream.
|
||||
This macro was not mandated originally: define only if we know
|
||||
we won't break user code: when these are the locations we know. */
|
||||
|
||||
#ifndef YY_LOCATION_PRINT
|
||||
# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
|
||||
# define YY_LOCATION_PRINT(File, Loc) \
|
||||
fprintf (File, "%d.%d-%d.%d", \
|
||||
(Loc).first_line, (Loc).first_column, \
|
||||
(Loc).last_line, (Loc).last_column)
|
||||
# else
|
||||
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
|
||||
# endif
|
||||
#endif]],
|
||||
[[/* This macro is provided for backward compatibility. */
|
||||
#ifndef YY_LOCATION_PRINT
|
||||
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
|
||||
#endif]])[
|
||||
|
||||
]])[
|
||||
]b4_yy_location_print_define[
|
||||
|
||||
/* YYLEX -- calling `yylex' with the right arguments. */
|
||||
#ifdef YYLEX_PARAM
|
||||
|
||||
Reference in New Issue
Block a user