From: Paul Eggert Date: Wed, 3 Oct 2007 20:06:08 +0000 (-0700) Subject: * lib/m4sugar/m4sugar.m4 (m4_shift2, m4_shift3): New macros. X-Git-Tag: v2.62~237 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9174b63f95aaf58680bda01f1746dc6f44860a59;p=thirdparty%2Fautoconf.git * lib/m4sugar/m4sugar.m4 (m4_shift2, m4_shift3): New macros. (m4_shiftn): Remove no-longer-needed optimization. Perhaps we should remove m4_shiftn entirely? (m4_case, b4_bmatch, m4_map_sep, m4_bpatsubsts, m4_join): Prefer m4_shift2 and m4_shift3 to m4_shiftn. * lib/autoconf/lang.m4 (_AC_LANG_DISPATCH): Likewise. * lib/m4sugar/m4sh.m4 (AS_CASE, AS_IF): Likewise. * tests/autotest.at (AT_CHECK_AT_TEST): Likewise. --- diff --git a/ChangeLog b/ChangeLog index 8bc9ff52..d37b8b5a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-10-03 Paul Eggert + + * lib/m4sugar/m4sugar.m4 (m4_shift2, m4_shift3): New macros. + (m4_shiftn): Remove no-longer-needed optimization. Perhaps we + should remove m4_shiftn entirely? + (m4_case, b4_bmatch, m4_map_sep, m4_bpatsubsts, m4_join): + Prefer m4_shift2 and m4_shift3 to m4_shiftn. + * lib/autoconf/lang.m4 (_AC_LANG_DISPATCH): Likewise. + * lib/m4sugar/m4sh.m4 (AS_CASE, AS_IF): Likewise. + * tests/autotest.at (AT_CHECK_AT_TEST): Likewise. + 2007-10-03 Eric Blake Comment touchups. diff --git a/lib/autoconf/lang.m4 b/lib/autoconf/lang.m4 index 6532f869..b659b9fe 100644 --- a/lib/autoconf/lang.m4 +++ b/lib/autoconf/lang.m4 @@ -83,7 +83,7 @@ m4_define([AC_LANG_CASE], # unavailable. m4_define([_AC_LANG_DISPATCH], [m4_ifdef([$1($2)], - [m4_indir([$1($2)], m4_shiftn(2, $@))], + [m4_indir([$1($2)], m4_shift2($@))], [AC_FATAL([$1: unknown language: $2])])]) diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index 6f9e9a6d..682a8504 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -462,7 +462,7 @@ m4_define([_AS_CASE], [$#], 1, [ *) $1 ;;], [$#], 2, [ $1) m4_default([$2], [:]) ;;], [ $1) m4_default([$2], [:]) ;; -$0(m4_shiftn(2, $@))])dnl +$0(m4_shift2($@))])dnl ]) m4_defun([AS_CASE], [m4_ifval([$2$3], @@ -504,7 +504,7 @@ m4_define([_AS_IF], [m4_ifval([$2$3], [elif $1; then m4_default([$2], [:]) -m4_ifval([$3], [$0(m4_shiftn(2, $@))])], +m4_ifval([$3], [$0(m4_shift2($@))])], [m4_ifvaln([$1], [else $1])dnl @@ -514,7 +514,7 @@ m4_defun([AS_IF], [m4_ifval([$2$3], [if $1; then m4_default([$2], [:]) -m4_ifval([$3], [_$0(m4_shiftn(2, $@))])[]dnl +m4_ifval([$3], [_$0(m4_shift2($@))])[]dnl fi ])dnl ])# AS_IF diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 4a3a1f79..c835fed9 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -362,7 +362,7 @@ m4_define([m4_case], [$#], 1, [], [$#], 2, [$2], [$1], [$2], [$3], - [$0([$1], m4_shiftn(3, $@))])]) + [$0([$1], m4_shift3($@))])]) # m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT) @@ -384,7 +384,7 @@ m4_define([m4_bmatch], [m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])], [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])], [$#], 2, [$2], - [m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))], + [m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shift3($@))], [$3])])]) @@ -442,7 +442,7 @@ m4_define([m4_map_sep], # due to quotation problems, I need to double quote $1 below, therefore # the anchors are broken :( I can't let users be trapped by that. # -# Recall that m4_shiftn always results in an argument. Hence, we need +# Recall that m4_shift3 always results in an argument. Hence, we need # to distinguish between a final deletion vs. ending recursion. m4_define([m4_bpatsubsts], [m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])], @@ -452,7 +452,7 @@ m4_define([m4_bpatsubsts], m4_define([_m4_bpatsubsts], [m4_if([$#], 2, [$1], [$0(m4_builtin([patsubst], [[$1]], [$2], [$3]), - m4_shiftn(3, $@))])]) + m4_shift3($@))])]) @@ -560,22 +560,21 @@ m4_define([m4_noquote], # m4_shiftn(N, ...) # ----------------- # Returns ... shifted N times. Useful for recursive "varargs" constructs. -# -# Internally, other m4sugar macros frequently use m4_shiftn(2, $@) and -# m4_shiftn(3, $@). Optimize these cases to avoid extra recursion and -# expansion. m4_define([m4_shiftn], -[m4_if(m4_eval(($1 >= 0) && ($# > $1)), 0, - [m4_assert(($1 >= 0) && ($# > $1))], - [$1], 2, [m4_shift(m4_shift(m4_shift($@)))], - [$1], 3, [m4_shift(m4_shift(m4_shift(m4_shift($@))))], - [_m4_shiftn($@)])]) +[m4_assert(0 <= $1 && $1 < $#)dnl +_m4_shiftn($@)]) m4_define([_m4_shiftn], [m4_if([$1], 0, [m4_shift($@)], [_m4_shiftn(m4_eval([$1]-1), m4_shift(m4_shift($@)))])]) +# m4_shift2(...) +# m4_shift3(...) +# ----------------- +# Returns ... shifted twice, and three times. Faster than m4_shiftn. +m4_define([m4_shift2], [m4_shift(m4_shift($@))]) +m4_define([m4_shift3], [m4_shift(m4_shift(m4_shift($@)))]) # m4_undefine(NAME) # ----------------- @@ -1522,7 +1521,7 @@ m4_defun([m4_join], [m4_case([$#], [1], [], [2], [[$2]], - [[$2][$1]$0([$1], m4_shiftn(2, $@))])]) + [[$2][$1]$0([$1], m4_shift2($@))])]) diff --git a/tests/autotest.at b/tests/autotest.at index 61481f36..b9384f8a 100644 --- a/tests/autotest.at +++ b/tests/autotest.at @@ -63,7 +63,7 @@ AT_INIT([artificial test suite]) AT_SETUP([my only test]) $2 AT_CLEANUP -]], m4_shiftn(2, $@))]) +]], m4_shift2($@))]) # Here documents for these tests contain forbidden macros. m4_pattern_allow([^AT_])