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:
Akim Demaille
2012-11-05 16:58:24 +01:00
parent 7d846072c7
commit 3237f57096
5 changed files with 53 additions and 67 deletions

View File

@@ -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],

View File

@@ -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)[

View File

@@ -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

View File

@@ -651,29 +651,29 @@ AT_PARSER_CHECK([./input], 1,
]],
[[Starting parse
Entering state 0
Reading a token: Next token is token 'a' (1.1-1.1: <> printer for 'a' @ 1)
Shifting token 'a' (1.1-1.1: <> printer for 'a' @ 1)
Reading a token: Next token is token 'a' (1.1: <> printer for 'a' @ 1)
Shifting token 'a' (1.1: <> printer for 'a' @ 1)
Entering state 1
Reading a token: Next token is token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2)
Shifting token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2)
Reading a token: Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
Entering state 3
Reading a token: Next token is token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3)
Shifting token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3)
Reading a token: Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
Entering state 5
Reading a token: Next token is token 'd' (1.4-1.4: <> printer for 'd' @ 4)
Shifting token 'd' (1.4-1.4: <> printer for 'd' @ 4)
Reading a token: Next token is token 'd' (1.4: <> printer for 'd' @ 4)
Shifting token 'd' (1.4: <> printer for 'd' @ 4)
Entering state 6
Reading a token: Now at end of input.
1.5: syntax error, unexpected $end, expecting 'e'
Error: popping token 'd' (1.4-1.4: <> printer for 'd' @ 4)
Error: popping token 'd' (1.4: <> printer for 'd' @ 4)
Stack now 0 1 3 5
Error: popping token 'c' (1.3-1.3: 'b'/'c' printer for 'c' @ 3)
Error: popping token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
Stack now 0 1 3
Error: popping token 'b' (1.2-1.2: 'b'/'c' printer for 'b' @ 2)
Error: popping token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
Stack now 0 1
Error: popping token 'a' (1.1-1.1: <> printer for 'a' @ 1)
Error: popping token 'a' (1.1: <> printer for 'a' @ 1)
Stack now 0
Cleanup: discarding lookahead token $end (1.5-1.5: )
Cleanup: discarding lookahead token $end (1.5: )
Stack now 0
]])
@@ -895,15 +895,15 @@ AT_PARSER_CHECK([./input$1], 0,
[[Starting parse
Entering state 0
Reducing stack by rule 1 (line 46):
-> $$ = nterm start (1.1-1.1: <]]kind[[> for 'S' @ 1)
-> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
Stack now 0
Entering state 1
Reading a token: Now at end of input.
Shifting token END (1.1-1.1: <]]kind[[> for 'E' @ 1)
Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
Entering state 2
Stack now 0 1 2
Cleanup: popping token END (1.1-1.1: <]]kind[[> for 'E' @ 1)
Cleanup: popping nterm start (1.1-1.1: <]]kind[[> for 'S' @ 1)
Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
]])
m4_popdef([kind])

View File

@@ -386,14 +386,7 @@ static
[[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\), *], [
YYUSE(\1);])dnl
AT_YYERROR_SEES_LOC_IF([[
fprintf (stderr, "%d.%d",
]AT_LOC_FIRST_LINE[, ]AT_LOC_FIRST_COLUMN[);
if (]AT_LOC_FIRST_LINE[ < ]AT_LOC_LAST_LINE[)
fprintf (stderr, "-%d.%d",
]AT_LOC_LAST_LINE[, ]AT_LOC_LAST_COLUMN[ - 1);
else if (]AT_LOC_FIRST_COLUMN[ < ]AT_LOC_LAST_COLUMN[ - 1)
fprintf (stderr, "-%d",
]AT_LOC_LAST_COLUMN[ - 1);
YY_LOCATION_PRINT (stderr, ]AT_LOC[);
fprintf (stderr, ": ");]])[
fprintf (stderr, "%s\n", msg);
}]],