bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/3] style: change misleading macro argument name


From: Akim Demaille
Subject: Re: [PATCH 1/3] style: change misleading macro argument name
Date: Mon, 30 Sep 2019 07:34:04 +0200


> Le 29 sept. 2019 à 18:34, Akim Demaille <address@hidden> a écrit :
> 
> * data/skeletons/glr.c, data/skeletons/yacc.c
> (yypact_value_is_default): It does not take a rule number as argument.

I'll insert the following commit after that one.


commit a57e74a5bf4ebaaba6eb592f8c5b5047fdc6bc79
Author: Akim Demaille <address@hidden>
Date:   Mon Sep 30 07:17:01 2019 +0200

    style: prefer symbolic values rather than litterals
    
    Instead of
    
        #define YYPACT_NINF -130
        #define yypact_value_is_default(Yystate) \
          (!!((Yystate) == (-130)))
    
    generate
    
        #define YYPACT_NINF (-130)
        #define yypact_value_is_default(Yyn) \
          ((Yyn) == YYPACT_NINF)
    
    * data/skeletons/c.m4 (b4_table_value_equals): Add support for $4.
    * data/skeletons/glr.c, data/skeletons/yacc.c: Use it.
    Also, use shorter macro argument names, the name of the macro is clear
    enough.

diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4
index 27aa2939..6bb6fd79 100644
--- a/data/skeletons/c.m4
+++ b/data/skeletons/c.m4
@@ -189,16 +189,16 @@ m4_define([b4_int_type_for],
 [b4_int_type($1_min, $1_max)])
 
 
-# b4_table_value_equals(TABLE, VALUE, LITERAL)
-# --------------------------------------------
+# b4_table_value_equals(TABLE, VALUE, LITERAL, SYMBOL)
+# ----------------------------------------------------
 # Without inducing a comparison warning from the compiler, check if the
 # literal value LITERAL equals VALUE from table TABLE, which must have
-# TABLE_min and TABLE_max defined.
+# TABLE_min and TABLE_max defined.  SYMBOL denotes
 m4_define([b4_table_value_equals],
 [m4_if(m4_eval($3 < m4_indir([b4_]$1[_min])
                || m4_indir([b4_]$1[_max]) < $3), [1],
        [[0]],
-       [(!!(($2) == ($3)))])])
+       [(($2) == $4)])])
 
 
 ## ----------------- ##
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index 4bf1991e..65ef56bd 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -375,8 +375,8 @@ static const char *const yytname[] =
 };
 #endif
 
-#define YYPACT_NINF ]b4_pact_ninf[
-#define YYTABLE_NINF ]b4_table_ninf[
+#define YYPACT_NINF (]b4_pact_ninf[)
+#define YYTABLE_NINF (]b4_table_ninf[)
 
 ]b4_parser_tables_define[
 
@@ -968,7 +968,7 @@ yylhsNonterm (yyRuleNum yyrule)
 }
 
 #define yypact_value_is_default(Yyn) \
-  ]b4_table_value_equals([[pact]], [[Yyn]], [b4_pact_ninf])[
+  ]b4_table_value_equals([[pact]], [[Yyn]], [b4_pact_ninf], [YYPACT_NINF])[
 
 /** True iff LR state YYSTATE has only a default reduction (regardless
  *  of token).  */
@@ -985,8 +985,8 @@ yydefaultAction (yyStateNum yystate)
   return yydefact[yystate];
 }
 
-#define yytable_value_is_error(Yytable_value) \
-  ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
+#define yytable_value_is_error(Yyn) \
+  ]b4_table_value_equals([[table]], [[Yyn]], [b4_table_ninf], [YYTABLE_NINF])[
 
 /** The action to take in YYSTATE on seeing YYTOKEN.
  *  Result R means
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index 9f1cdd06..0dac4c8a 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -643,15 +643,15 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] =
 };
 # endif
 
-#define YYPACT_NINF ]b4_pact_ninf[
+#define YYPACT_NINF (]b4_pact_ninf[)
 
 #define yypact_value_is_default(Yyn) \
-  ]b4_table_value_equals([[pact]], [[Yyn]], [b4_pact_ninf])[
+  ]b4_table_value_equals([[pact]], [[Yyn]], [b4_pact_ninf], [YYPACT_NINF])[
 
-#define YYTABLE_NINF ]b4_table_ninf[
+#define YYTABLE_NINF (]b4_table_ninf[)
 
-#define yytable_value_is_error(Yytable_value) \
-  ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[
+#define yytable_value_is_error(Yyn) \
+  ]b4_table_value_equals([[table]], [[Yyn]], [b4_table_ninf], [YYTABLE_NINF])[
 
 ]b4_parser_tables_define[
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]