summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAkim Demaille <demaille@gostai.com>2010-04-13 23:04:03 +0200
committerAkim Demaille <demaille@gostai.com>2010-04-13 23:31:57 +0200
commit4f756f887bca79b6feeeeedc821b17fd08079e5b (patch)
treeb5d0d8bb560026021260b450b9a6cb824be26b01 /tests
parent24bb8c8c257631f988941fcd78ecce09bc5d5f23 (diff)
downloadbison-4f756f887bca79b6feeeeedc821b17fd08079e5b.tar.gz
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/calc.at40
-rw-r--r--tests/local.at30
2 files changed, 45 insertions, 25 deletions
diff --git a/tests/calc.at b/tests/calc.at
index 16e40f5b..fddddee4 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -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
@@ -328,13 +318,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);
}])[
diff --git a/tests/local.at b/tests/local.at
index f8a88c96..8ebf26a8 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -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])
# -----------------------------------------
@@ -131,6 +150,16 @@ 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_GLR_IF([AT_KEYWORDS([glr])])
])# _AT_BISON_OPTION_PUSHDEFS
@@ -161,6 +190,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