[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
style: glr.c: prefer returning a value rather than passing pointers
From: |
Akim Demaille |
Subject: |
style: glr.c: prefer returning a value rather than passing pointers |
Date: |
Wed, 2 Jan 2019 12:31:21 +0100 |
commit 6d9818b0cfea4ac3e0308da28e4d466f8fc964f9
Author: Akim Demaille <address@hidden>
Date: Wed Jan 2 11:49:13 2019 +0100
style: glr.c: prefer returning a value rather than passing pointers
This is very debatable. This function is not pure at all, so it could
stick to returning void: that's a common coding style to tell the
difference between "real" (pure) functions and side-effecting
subroutines. However, we already have this style elsewhere (e.g.,
yylex), and I feel the callers are somewhat nice to read this way.
* data/skeletons/glr.c (yygetLRActions): Return the action rather than
passing by pointer.
While at it, fix type of yytoken.
Adjust callers.
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index 779c1c91..0d5ccee9 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -975,7 +975,7 @@ yydefaultAction (yyStateNum yystate)
#define yytable_value_is_error(Yytable_value) \
]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
-/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
+/** The action to take in YYSTATE on seeing YYTOKEN.
* Result R means
* R < 0: Reduce on rule -R.
* R = 0: Error.
@@ -983,26 +983,25 @@ yydefaultAction (yyStateNum yystate)
* Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list
* of conflicting reductions.
*/
-static inline void
-yygetLRActions (yyStateNum yystate, int yytoken,
- int* yyaction, const short** yyconflicts)
+static inline int
+yygetLRActions (yyStateNum yystate, yySymbol yytoken, const short**
yyconflicts)
{
int yyindex = yypact[yystate] + yytoken;
if (yyisDefaultedState (yystate)
|| yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
{
- *yyaction = -yydefact[yystate];
*yyconflicts = yyconfl;
+ return -yydefact[yystate];
}
else if (! yytable_value_is_error (yytable[yyindex]))
{
- *yyaction = yytable[yyindex];
*yyconflicts = yyconfl + yyconflp[yyindex];
+ return yytable[yyindex];
}
else
{
- *yyaction = 0;
*yyconflicts = yyconfl + yyconflp[yyindex];
+ return 0;
}
}
@@ -1977,7 +1976,7 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
yystackp->yytops.yylookaheadNeeds[yyk] = yytrue;
yytoken = ]b4_yygetToken_call[;
- yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
+ yyaction = yygetLRActions (yystate, yytoken, &yyconflicts);
while (*yyconflicts != 0)
{
@@ -2338,9 +2337,8 @@ b4_dollar_popdef])[]dnl
else
{
yySymbol yytoken = ]b4_yygetToken_call;[
- int yyaction;
const short* yyconflicts;
- yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
+ int yyaction = yygetLRActions (yystate, yytoken, &yyconflicts);
if (*yyconflicts != 0)
break;
if (yyisShiftAction (yyaction))
@@ -2418,10 +2416,9 @@ b4_dollar_popdef])[]dnl
yyposn += 1;
for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
{
- int yyaction;
- const short* yyconflicts;
yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState;
- yygetLRActions (yystate, yytoken_to_shift, &yyaction,
+ const short* yyconflicts;
+ int yyaction = yygetLRActions (yystate, yytoken_to_shift,
&yyconflicts);
/* Note that yyconflicts were handled by yyprocessOneStack. */
YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long) yys));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- style: glr.c: prefer returning a value rather than passing pointers,
Akim Demaille <=