From: Eric Blake Date: Tue, 28 Oct 2008 21:11:16 +0000 (-0600) Subject: Add m4_stack_foreach_sep. X-Git-Tag: v2.63b~170 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52773c7b70c37e6b3bc020cbc153a73bebd10d0c;p=thirdparty%2Fautoconf.git Add m4_stack_foreach_sep. * lib/m4sugar/m4sugar.m4 (m4_stack_foreach_sep) (m4_stack_foreach_sep_lifo): New macros. (_m4_stack_reverse): Adjust prototype, to support it. (m4_copy): Use fewer macros. * tests/m4sugar.at (m4@&t@_stack_foreach): Rename... (m4@&t@_stack): ...and add m4_stack_foreach_sep tests. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index b5026a729..990a09318 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-10-29 Eric Blake + + Add m4_stack_foreach_sep. + * lib/m4sugar/m4sugar.m4 (m4_stack_foreach_sep) + (m4_stack_foreach_sep_lifo): New macros. + (_m4_stack_reverse): Adjust prototype, to support it. + (m4_copy): Use fewer macros. + * tests/m4sugar.at (m4@&t@_stack_foreach): Rename... + (m4@&t@_stack): ...and add m4_stack_foreach_sep tests. + 2008-10-29 Bruno Haible Mention Sun WorkShop 6.2 OpenMP bug. diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 6bd843e79..0283ece43 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -534,10 +534,10 @@ m4_define([_m4_bpatsubsts], # definition. # # Some macros simply can't be renamed with this method: namely, anything -# involved in the implementation of m4_stack_foreach and m4_curry. +# involved in the implementation of m4_stack_foreach_sep. m4_define([m4_copy], [m4_ifdef([$2], [m4_fatal([$0: won't overwrite defined macro: $2])], - [m4_stack_foreach([$1], [m4_curry([m4_pushdef], [$2])])])]dnl + [m4_stack_foreach_sep([$1], [m4_pushdef([$2],], [)])])]dnl [m4_ifdef([m4_location($1)], [m4_define([m4_location($2)], m4_location)])]) @@ -1192,13 +1192,8 @@ m4_define([m4_map_args_pair], # the active definition of MACRO (it will not be the topmost, and may not # be the one passed to FUNC either). # -# The recursive worker _m4_stack_reverse destructively swaps the order of a -# stack. We use a temporary stack, and swap directions twice. Some macros -# simply can't be examined with this method: namely, anything involved -# in the implementation of _m4_stack_reverse. -m4_define([_m4_stack_reverse], -[m4_ifdef([$1], [m4_pushdef([$2], _m4_defn([$1]))$3[]_m4_popdef([$1])$0($@)])]) - +# Some macros simply can't be examined with this method: namely, +# anything involved in the implementation of _m4_stack_reverse. m4_define([m4_stack_foreach], [_m4_stack_reverse([$1], [m4_tmp-$1])]dnl [_m4_stack_reverse([m4_tmp-$1], [$1], [$2(_m4_defn([m4_tmp-$1]))])]) @@ -1207,6 +1202,40 @@ m4_define([m4_stack_foreach_lifo], [_m4_stack_reverse([$1], [m4_tmp-$1], [$2(_m4_defn([m4_tmp-$1]))])]dnl [_m4_stack_reverse([m4_tmp-$1], [$1])]) +# m4_stack_foreach_sep(MACRO, PRE, POST, SEP) +# m4_stack_foreach_sep_lifo(MACRO, PRE, POST, SEP) +# ------------------------------------------------ +# Similar to m4_stack_foreach and m4_stack_foreach_lifo, in that every +# definition of a pushdef stack will be visited. But rather than +# passing the definition as a single argument to a macro, this variant +# expands the concatenation of PRE[]definition[]POST, and expands SEP +# between consecutive expansions. Note that m4_stack_foreach([a], [b]) +# is equivalent to m4_stack_foreach_sep([a], [b(], [)]). +m4_define([m4_stack_foreach_sep], +[_m4_stack_reverse([$1], [m4_tmp-$1])]dnl +[_m4_stack_reverse([m4_tmp-$1], [$1], [$2[]_m4_defn([m4_tmp-$1])$3], [$4])]) + +m4_define([m4_stack_foreach_sep_lifo], +[_m4_stack_reverse([$1], [m4_tmp-$1], [$2[]_m4_defn([m4_tmp-$1])$3], [$4])]dnl +[_m4_stack_reverse([m4_tmp-$1], [$1])]) + + +# _m4_stack_reverse(OLD, NEW, ACTION, SEP) +# ---------------------------------------- +# A recursive worker for pushdef stack manipulation. Destructively +# copy the OLD stack into the NEW, and expanding ACTION for each +# iteration. After the first iteration, SEP is promoted to the front +# of ACTION. The current definition is examined after the NEW has +# been pushed but before OLD has been popped; this order is important, +# as ACTION is permitted to operate on either _m4_defn([OLD]) or +# _m4_defn([NEW]). Since the operation is destructive, this macro is +# generally used twice, with a temporary macro name holding the +# swapped copy. +m4_define([_m4_stack_reverse], +[m4_ifdef([$1], [m4_pushdef([$2], + _m4_defn([$1]))$3[]_m4_popdef([$1])$0([$1], [$2], [$4$3])])]) + + ## --------------------------- ## ## 9. More diversion support. ## diff --git a/tests/m4sugar.at b/tests/m4sugar.at index 1dff27058..550d08503 100644 --- a/tests/m4sugar.at +++ b/tests/m4sugar.at @@ -41,9 +41,11 @@ AT_CHECK_M4SUGAR([-o-],, [$2], [$3]) ## m4_stack_foreach. ## ## ------------------ ## -AT_SETUP([m4@&t@_stack_foreach]) +AT_SETUP([m4@&t@_stack]) -AT_KEYWORDS([m4@&t@_stack_foreach_lifo m4@&t@_copy m4@&t@_n]) +AT_KEYWORDS([m4@&t@_stack_foreach m4@&t@_stack_foreach_lifo]) +AT_KEYWORDS([m4@&t@_stack_foreach_sep m4@&t@_stack_foreach_sep_lifo]) +AT_KEYWORDS([m4@&t@_copy m4@&t@_n]) # Test the semantics of macros to walk stacked macro definitions. AT_CHECK_M4SUGAR_TEXT([[dnl @@ -57,9 +59,11 @@ m4_stack_foreach([abc], [m4_n]) m4_copy([abc], [foo])dnl m4_stack_foreach([foo], [m4_n]) m4_stack_foreach_lifo([foo], [m4_n]) +m4_stack_foreach_sep([abc], [ m4_index([abcdefghijkl],], [)]) +m4_stack_foreach_sep_lifo([abc], [<], [>], [:]) m4_pushdef([xyz], [123])dnl m4_pushdef([xyz], [456])dnl -m4_define([doit], [[$1](m4_shift(m4_stack_foreach([xyz], [,m4_echo]))) +m4_define([doit], [[$1](m4_stack_foreach_sep([xyz], [m4_dquote(], [)], [,])) ])dnl m4_stack_foreach([abc], [doit])]], [[def @@ -83,9 +87,11 @@ jkl ghi def -def(123,456) -ghi(123,456) -jkl(123,456) + 3 6 9 +:: +def([123],[456]) +ghi([123],[456]) +jkl([123],[456]) ]]) AT_CLEANUP