From bd187d7b6573a60ad56c3fbcaccb5c768bc8d7ba Mon Sep 17 00:00:00 2001
From: Akim Demaille <demaille@gostai.com>
Date: Mon, 17 Nov 2008 08:48:00 +0100
Subject: [PATCH] Use b4_subtract where possible.

	* data/lalr1.cc (b4_subtract): Move to...
	* data/bison.m4: here.
	* data/glr.c (b4_rhs_data): Use it.
	* data/yacc.c (b4_rhs_value, b4_rhs_location): Use it.
---
 ChangeLog     |  8 ++++++++
 data/bison.m4 | 14 +++++++++-----
 data/glr.c    |  2 +-
 data/lalr1.cc | 10 ----------
 data/yacc.c   |  4 ++--
 5 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 608c2cea..3531117d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-11-18  Akim Demaille  <demaille@gostai.com>
+
+	Use b4_subtract where possible.
+	* data/lalr1.cc (b4_subtract): Move to...
+	* data/bison.m4: here.
+	* data/glr.c (b4_rhs_data): Use it.
+	* data/yacc.c (b4_rhs_value, b4_rhs_location): Use it.
+
 2008-11-18  Akim Demaille  <demaille@gostai.com>
 
 	Remove incorrect mode specification.
diff --git a/data/bison.m4 b/data/bison.m4
index 7cb43b80..c7392b38 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -212,6 +212,15 @@ m4_define([b4_ints_in],
 [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
 
 
+# b4_subtract(LHS, RHS)
+# ---------------------
+# Evaluate LHS - RHS if they are integer literals, otherwise expand
+# to (LHS) - (RHS).
+m4_define([b4_subtract],
+[m4_bmatch([$1$2], [^[0123456789]*$],
+           [m4_eval([$1 - $2])],
+           [($1) - ($2)])])
+
 
 ## ------------------ ##
 ## Decoding options.  ##
@@ -257,11 +266,6 @@ b4_define_flag_if([nondeterministic])	# Whether conflicts should be handled.
 b4_define_flag_if([yacc])	        # Whether POSIX Yacc is emulated.
 
 
-## ------------------------- ##
-## Assigning token numbers.  ##
-## ------------------------- ##
-
-
 ## ----------- ##
 ## Synclines.  ##
 ## ----------- ##
diff --git a/data/glr.c b/data/glr.c
index f8a32a82..910a8ee1 100644
--- a/data/glr.c
+++ b/data/glr.c
@@ -117,7 +117,7 @@ m4_define([b4_lhs_value],
 # Expand to the semantic stack place that contains value and location
 # of symbol number NUM in a rule of length RULE-LENGTH.
 m4_define([b4_rhs_data],
-[((yyGLRStackItem const *)yyvsp)@{YYFILL (($2) - ($1))@}.yystate])
+[((yyGLRStackItem const *)yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate])
 
 
 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 6e5042d4..58ebe94c 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -18,16 +18,6 @@
 
 m4_include(b4_pkgdatadir/[c++.m4])
 
-# b4_subtract(LHS, RHS)
-# ---------------------
-# Evaluate LHS - RHS if they are integer literals, otherwise expand
-# to (LHS) - (RHS).
-m4_define([b4_subtract],
-[m4_bmatch([$1$2], [^[0123456789]*$],
-           [m4_eval([$1 - $2])],
-           [($1) - ($2)])])
-
-
 # b4_args(ARG1, ...)
 # _b4_args(ARG1, ...)
 # -------------------
diff --git a/data/yacc.c b/data/yacc.c
index 36028e27..872e63f1 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -124,7 +124,7 @@ m4_define([b4_lhs_value],
 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
 # symbols on RHS.
 m4_define([b4_rhs_value],
-[b4_symbol_value([yyvsp@{($2) - ($1)@}], [$3])])
+          [b4_symbol_value([yyvsp@{b4_subtract([$2], [$1])@}], [$3])])
 
 
 
@@ -144,7 +144,7 @@ m4_define([b4_lhs_location],
 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
 # on RHS.
 m4_define([b4_rhs_location],
-[(yylsp@{($2) - ($1)@})])
+          [(yylsp@{b4_subtract([$2], [$1])@})])
 
 
 
-- 
2.47.2