From 0ae99356d5909eb937ad89c2f3473eb2bd4688b0 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 20 Jun 2003 22:52:12 +0000 Subject: [PATCH] * data/glr.c (YYLLOC_DEFAULT): Parenthesize arguments as needed, and return properly parenthesized result. * data/lalar1.cc (YYLLOC_DEFAULT): Likewise. * data/yacc.c (YYLLOC_DEFAULT): Likewise. Remove unnecessary parentheses from uses. * doc/bison.texinfo (Location Default Action): Describe the conventions for parentheses. --- ChangeLog | 10 ++++++++++ data/glr.c | 10 +++++----- data/lalr1.cc | 2 +- data/yacc.c | 14 +++++++------- doc/bison.texinfo | 26 ++++++++++++++++---------- 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0038c05c..8ff6217c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-06-20 Paul Eggert + + * data/glr.c (YYLLOC_DEFAULT): Parenthesize arguments as needed, + and return properly parenthesized result. + * data/lalar1.cc (YYLLOC_DEFAULT): Likewise. + * data/yacc.c (YYLLOC_DEFAULT): Likewise. + Remove unnecessary parentheses from uses. + * doc/bison.texinfo (Location Default Action): Describe the + conventions for parentheses. + 2003-06-19 Paul Eggert * data/glr.c (yyremoveDeletes, yy_reduce_print, yyglrReduce, diff --git a/data/glr.c b/data/glr.c index b821af17..130cf952 100644 --- a/data/glr.c +++ b/data/glr.c @@ -414,14 +414,14 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] = #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \ - (yyCurrent).first_line = YYRHSLOC(yyRhs,1).first_line; \ - (yyCurrent).first_column = YYRHSLOC(yyRhs,1).first_column; \ - (yyCurrent).last_line = YYRHSLOC(yyRhs,YYN).last_line; \ - (yyCurrent).last_column = YYRHSLOC(yyRhs,YYN).last_column; + ((yyCurrent).first_line = YYRHSLOC(yyRhs, 1).first_line, \ + (yyCurrent).first_column = YYRHSLOC(yyRhs, 1).first_column, \ + (yyCurrent).last_line = YYRHSLOC(yyRhs, YYN).last_line, \ + (yyCurrent).last_column = YYRHSLOC(yyRhs, YYN).last_column) #endif ]],[ #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) +# define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) ((void) 0) #endif ])[ diff --git a/data/lalr1.cc b/data/lalr1.cc index a40521b4..0e33541e 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -170,7 +170,7 @@ b4_syncline([@oline@], [@ofile@])], b4_syncline([@oline@], [@ofile@])[ #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.end = Rhs[N].end; + ((Current).end = Rhs[N].end) #endif namespace yy diff --git a/data/yacc.c b/data/yacc.c index 1af5ec0b..73df3ac8 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -501,11 +501,11 @@ while (0) are run). */ #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.first_line = Rhs[1].first_line; \ - Current.first_column = Rhs[1].first_column; \ - Current.last_line = Rhs[N].last_line; \ - Current.last_column = Rhs[N].last_column; +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + ((Current).first_line = (Rhs)[1].first_line, \ + (Current).first_column = (Rhs)[1].first_column, \ + (Current).last_line = (Rhs)[N].last_line, \ + (Current).last_column = (Rhs)[N].last_column) #endif /* YYLEX -- calling `yylex' with the right arguments. */ @@ -983,7 +983,7 @@ yyreduce: ]b4_location_if( [ /* Default location. */ - YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);])[ + YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);])[ YY_REDUCE_PRINT (yyn); switch (yyn) ]{ @@ -1180,7 +1180,7 @@ yyerrlab1: YYDPRINTF ((stderr, "Shifting error token, ")); *++yyvsp = yylval; -]b4_location_if([ YYLLOC_DEFAULT (yyloc, yylsp, (yylerrsp - yylsp)); +]b4_location_if([ YYLLOC_DEFAULT (yyloc, yylsp, yylerrsp - yylsp); *++yylsp = yyloc;])[ yystate = yyn; diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 7cb1ae5a..536b2cba 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -3210,11 +3210,11 @@ By default, @code{YYLLOC_DEFAULT} is defined this way for simple @example @group -#define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.first_line = Rhs[1].first_line; \ - Current.first_column = Rhs[1].first_column; \ - Current.last_line = Rhs[N].last_line; \ - Current.last_column = Rhs[N].last_column; +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + ((Current).first_line = (Rhs)[1].first_line, \ + (Current).first_column = (Rhs)[1].first_column, \ + (Current).last_line = (Rhs)[N].last_line, \ + (Current).last_column = (Rhs)[N].last_column) @end group @end example @@ -3223,11 +3223,11 @@ and like this for @acronym{GLR} parsers: @example @group -#define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.first_line = YYRHSLOC(Rhs,1).first_line; \ - Current.first_column = YYRHSLOC(Rhs,1).first_column; \ - Current.last_line = YYRHSLOC(Rhs,N).last_line; \ - Current.last_column = YYRHSLOC(Rhs,N).last_column; +# define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \ + ((yyCurrent).first_line = YYRHSLOC(yyRhs, 1).first_line, \ + (yyCurrent).first_column = YYRHSLOC(yyRhs, 1).first_column, \ + (yyCurrent).last_line = YYRHSLOC(yyRhs, YYN).last_line, \ + (yyCurrent).last_column = YYRHSLOC(yyRhs, YYN).last_column) @end group @end example @@ -3241,6 +3241,12 @@ result) should be modified by @code{YYLLOC_DEFAULT}. @item For consistency with semantic actions, valid indexes for the location array range from 1 to @var{n}. + +@item +Your macro should parenthesize its arguments, if need be, since the +actual arguments may not be surrounded by parentheses. Also, your +macro should expand to something that can be used as a single +statement when it is followed by a semicolon. @end itemize @node Declarations -- 2.45.2