tests: calc: simplify location management.

* tests/local.at (AT_LOC_PUSHDEF, AT_LOC_POPDEF): New.
	(_AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS): Use them to
	define the appropriate AT_LOC accessors.
	* tests/calc.at: Use AT_LOC accessors.

(cherry picked from commit 4f756f887b)

Conflicts:

	tests/local.at
This commit is contained in:
Akim Demaille
2010-04-13 23:04:03 +02:00
parent cacfdef716
commit ed228e60b2
3 changed files with 52 additions and 25 deletions

View File

@@ -1,3 +1,11 @@
2010-04-13 Akim Demaille <demaille@gostai.com>
tests: calc: simplify location management.
* tests/local.at (AT_LOC_PUSHDEF, AT_LOC_POPDEF): New.
(_AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS): Use them to
define the appropriate AT_LOC accessors.
* tests/calc.at: Use AT_LOC accessors.
2010-04-13 Akim Demaille <demaille@gostai.com>
test location_type.

View File

@@ -55,11 +55,11 @@ get_char (]AT_LEX_FORMALS[)
last_yylloc = AT_LOC;
if (res == '\n')
{
AT_LOC.last_line++;
AT_LOC.last_column = 1;
AT_LOC_LAST_LINE++;
AT_LOC_LAST_COLUMN = 1;
}
else
AT_LOC.last_column++;
AT_LOC_LAST_COLUMN++;
])[
return res;
}
@@ -117,22 +117,22 @@ int
{
init = 0;
]AT_LOCATION_IF([
AT_LOC.last_column = 1;
AT_LOC.last_line = 1;
AT_LOC_LAST_COLUMN = 1;
AT_LOC_LAST_LINE = 1;
])[
}
]AT_LOCATION_IF([
AT_LOC.first_column = AT_LOC.last_column;
AT_LOC.first_line = AT_LOC.last_line;
AT_LOC_FIRST_COLUMN = AT_LOC_LAST_COLUMN;
AT_LOC_FIRST_LINE = AT_LOC_LAST_LINE;
])[
/* Skip white space. */
while ((c = get_char (]AT_LEX_ARGS[)) == ' ' || c == '\t')
{
]AT_LOCATION_IF(
[ AT_LOC.first_column = AT_LOC.last_column;
AT_LOC.first_line = AT_LOC.last_line;
[ AT_LOC_FIRST_COLUMN = AT_LOC_LAST_COLUMN;
AT_LOC_FIRST_LINE = AT_LOC_LAST_LINE;
])[
}
@@ -192,17 +192,7 @@ extern FILE *input;]AT_SKEL_CC_IF([[
#ifndef YYLTYPE
# define YYLTYPE ]AT_NAME_PREFIX[::parser::location_type
#endif
]AT_LOCATION_TYPE_IF([[
#define first_line begin.l
#define first_column begin.c
#define last_line end.l
#define last_column end.c
]], [[
#define first_line begin.line
#define first_column begin.column
#define last_line end.line
#define last_column end.column
]])])[
]])[
}
%code
@@ -329,13 +319,13 @@ yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *llocp, ])
AT_PARAM_IF([(void) result; (void) count;])
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)
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)
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);
AT_LOC_LAST_COLUMN - 1);
fprintf (stderr, ": ");])
fprintf (stderr, "%s\n", s);
}])[

View File

@@ -40,6 +40,25 @@ printf "$count\n";' $1], [0], [$3
## Macros decoding Bison options. ##
## ------------------------------- ##
# AT_LOC_PUSHDEF(FIRST-LINE, FIRST-COLUMN, LAST-LINE, LAST-COLUMN)
# ----------------------------------------------------------------
# Pushdef AT_LOC_(FIRST|LAST)_(LINE|COLUMN).
m4_define([AT_LOC_PUSHDEF],
[m4_pushdef([AT_LOC_FIRST_LINE], [AT_LOC.$1])
m4_pushdef([AT_LOC_FIRST_COLUMN], [AT_LOC.$2])
m4_pushdef([AT_LOC_LAST_LINE], [AT_LOC.$3])
m4_pushdef([AT_LOC_LAST_COLUMN], [AT_LOC.$4])])
# AT_LOC_POPDEF
# -------------
# Popdef AT_LOC_(FIRST|LAST)_(LINE|COL).
m4_define([AT_LOC_POPDEF],
[m4_popdef([AT_LOC_FIRST_LINE])
m4_popdef([AT_LOC_FIRST_COLUMN])
m4_popdef([AT_LOC_LAST_LINE])
m4_popdef([AT_LOC_LAST_COLUMN])])
# AT_BISON_OPTION_PUSHDEFS([BISON-OPTIONS])
# -----------------------------------------
@@ -128,6 +147,15 @@ AT_PURE_LEX_IF(
m4_pushdef([AT_LEX_PRE_FORMALS], [])
m4_pushdef([AT_LEX_PRE_ARGS], [])
])
# Handle the different types of location components.
AT_SKEL_CC_IF(
[AT_LOCATION_TYPE_IF(
[AT_LOC_PUSHDEF([begin.l], [begin.c], [end.l], [end.c])],
[AT_LOC_PUSHDEF([begin.line], [begin.column], [end.line], [end.column])])],
[AT_LOC_PUSHDEF([first_line], [first_column], [last_line], [last_column])])
])# _AT_BISON_OPTION_PUSHDEFS
@@ -157,6 +185,7 @@ m4_popdef([AT_SKEL_CC_IF])
m4_popdef([AT_GLR_CC_IF])
m4_popdef([AT_LALR1_CC_IF])
m4_popdef([AT_DEFINES_IF])
AT_LOC_POPDEF
])# AT_BISON_OPTION_POPDEFS