From 4f756f887bca79b6feeeeedc821b17fd08079e5b Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Tue, 13 Apr 2010 23:04:03 +0200 Subject: [PATCH] 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. --- ChangeLog | 8 ++++++++ tests/calc.at | 40 +++++++++++++++------------------------- tests/local.at | 30 ++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58f27a5c..81817c75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-04-13 Akim Demaille + + 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 test location_type. 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 -- 2.45.2