]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Add m4_stack_foreach_sep.
authorEric Blake <ebb9@byu.net>
Tue, 28 Oct 2008 21:11:16 +0000 (15:11 -0600)
committerEric Blake <ebb9@byu.net>
Wed, 29 Oct 2008 12:28:37 +0000 (06:28 -0600)
* 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 <ebb9@byu.net>
ChangeLog
lib/m4sugar/m4sugar.m4
tests/m4sugar.at

index b5026a729ff36eb78a940adc62ebe32953f36297..990a09318872b3a47cee8ca90f7e1aac89f5c8ab 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-10-29  Eric Blake  <ebb9@byu.net>
+
+       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  <bruno@clisp.org>
 
        Mention Sun WorkShop 6.2 OpenMP bug.
index 6bd843e79336af5e5808bfa19c4baa8b8280d5d9..0283ece43af1d45fb7cb047fe477c0f8df9b6d92 100644 (file)
@@ -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.  ##
index 1dff27058872ae39985b17149063fade6c31aa0b..550d0850397634a77ae2f10e992f6073faf13204 100644 (file)
@@ -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
+<jkl>:<ghi>:<def>
+def([123],[456])
+ghi([123],[456])
+jkl([123],[456])
 ]])
 
 AT_CLEANUP