From e7bab2df968dd287d0a35a6c8a38569332af2ca2 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 12 May 2010 07:27:13 +0200 Subject: [PATCH] c++: use YYRHSLOC. * data/lalr1.cc (YYRHSLOC): New. (YYLLOC_DEFAULT): Use it. * data/glr.cc: If location_type was user defined, do not include location.hh, and do not produce location.hh and position.hh. * tests/calc.at (YYLLOC_DEFAULT): Use YYRHSLOC. Check that glr.cc supports user defined location_type. * NEWS: Document this. (cherry picked from commit bb9191dd311e4c6d80f8dd12c6a7ce9254404fbc) Conflicts: ChangeLog NEWS data/lalr1.cc tests/calc.at --- ChangeLog | 11 +++++++++++ NEWS | 35 +++++++++++++++++++++++++++++++++++ data/glr.cc | 3 ++- data/lalr1.cc | 25 +++++++++++++------------ tests/calc.at | 25 +++++++++++++------------ 5 files changed, 74 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 966b0050..7d8b96be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-05-07 Akim Demaille + + c++: use YYRHSLOC. + * data/lalr1.cc (YYRHSLOC): New. + (YYLLOC_DEFAULT): Use it. + * data/glr.cc: If location_type was user defined, do not include + location.hh, and do not produce location.hh and position.hh. + * tests/calc.at (YYLLOC_DEFAULT): Use YYRHSLOC. + Check that glr.cc supports user defined location_type. + * NEWS: Document this. + 2010-05-10 Akim Demaille doc: fix lalr1.cc documentation. diff --git a/NEWS b/NEWS index 93312ff9..ee269105 100644 --- a/NEWS +++ b/NEWS @@ -180,6 +180,41 @@ Bison News determine which destructor to call for the lookahead upon a syntax error or upon parser return. This bug has been fixed. +** C++ parsers use YYRHSLOC + + Similarly to the C parsers, the C++ parsers now define the YYRHSLOC + macro and use it in the default YYLLOC_DEFAULT. You are encouraged + to use it. If, for instance, your location structure has "first" + and "last" members, instead of + + # define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).first = (Rhs)[1].location.first; \ + (Current).last = (Rhs)[N].location.last; \ + } \ + else \ + { \ + (Current).first = (Current).last = (Rhs)[0].location.last; \ + } \ + while (false) + + use: + + # define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).first = YYRHSLOC (Rhs, 1).first; \ + (Current).last = YYRHSLOC (Rhs, N).last; \ + } \ + else \ + { \ + (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \ + } \ + while (false) + * Changes in version 2.4.3 (????-??-??): ** Problems with spawning M4 on at least FreeBSD 8 and FreeBSD 9 have diff --git a/data/glr.cc b/data/glr.cc index fb9a87b6..a55df4f3 100644 --- a/data/glr.cc +++ b/data/glr.cc @@ -53,7 +53,8 @@ b4_defines_if([], [b4_fatal([b4_skeleton[: using %%defines is mandatory]])]) m4_include(b4_pkgdatadir/[c++.m4]) -m4_include(b4_pkgdatadir/[location.cc]) +b4_percent_define_ifdef([[location_type]], [], + [m4_include(b4_pkgdatadir/[location.cc])]) m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])]) diff --git a/data/lalr1.cc b/data/lalr1.cc index 4009b7c8..b400b310 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -73,19 +73,20 @@ dnl FIXME: This is wrong, we want computed header guards. If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */ +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ -do { \ - if (N) \ - { \ - (Current).begin = (Rhs)[1].begin; \ - (Current).end = (Rhs)[N].end; \ - } \ - else \ - { \ - (Current).begin = (Current).end = (Rhs)[0].end; \ - } \ -} while (false) +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).begin = YYRHSLOC (Rhs, 1).begin; \ + (Current).end = YYRHSLOC (Rhs, N).end; \ + } \ + else \ + { \ + (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \ + } \ + while (false) #endif ]b4_namespace_open[ diff --git a/tests/calc.at b/tests/calc.at index b3955ca5..23716663 100644 --- a/tests/calc.at +++ b/tests/calc.at @@ -170,18 +170,18 @@ AT_SKEL_CC_IF( Point last; }; -# define YYLLOC_DEFAULT(Current, Rhs, N) \ -do { \ - if (N) \ - { \ - (Current).first = (Rhs)[1].first; \ - (Current).last = (Rhs)[N].last; \ - } \ - else \ - { \ - (Current).first = (Current).last = (Rhs)[0].last; \ - } \ -} while (false) +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).first = YYRHSLOC (Rhs, 1).first; \ + (Current).last = YYRHSLOC (Rhs, N).last; \ + } \ + else \ + { \ + (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \ + } \ + while (false) ]])[ /* Exercise pre-prologue dependency to %union. */ @@ -712,6 +712,7 @@ m4_define([AT_CHECK_CALC_GLR_CC], [AT_CHECK_CALC([%language "C++" %glr-parser %defines %locations] $@)]) AT_CHECK_CALC_GLR_CC([]) +AT_CHECK_CALC_GLR_CC([%define location_type Span]) AT_CHECK_CALC_GLR_CC([%error-verbose %name-prefix "calc" %verbose %yacc]) AT_CHECK_CALC_GLR_CC([%debug]) -- 2.47.2