]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Simplify expansion stack handling.
authorEric Blake <ebb9@byu.net>
Thu, 30 Oct 2008 18:16:15 +0000 (12:16 -0600)
committerEric Blake <ebb9@byu.net>
Fri, 31 Oct 2008 15:59:56 +0000 (09:59 -0600)
* lib/m4sugar/m4sugar.m4 (m4_expansion_stack): Use fewer macros;
always output 'top level'.
(_m4_expansion_stack_entry): New macro, to format the string only
when needed.
(m4_expansion_stack_push): Only push a macro name.
(m4_warn, _m4_defun_pro): Update callers.
(m4_expansion_stack_pop, m4_expansion_stack_dump): Delete.
(_m4_defun_epi, m4_fatal): Inline the calls.
* tests/m4sugar.at (m4@&t@_expansion_stack): New test.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/m4sugar/m4sugar.m4
tests/m4sugar.at

index d1c89f9d63ce43a0dd2c8ea8a8a3b5fe5c4471b3..18c2919529e8586943736032397ec23799162570 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2008-10-31  Eric Blake  <ebb9@byu.net>
+
+       Simplify expansion stack handling.
+       * lib/m4sugar/m4sugar.m4 (m4_expansion_stack): Use fewer macros;
+       always output 'top level'.
+       (_m4_expansion_stack_entry): New macro, to format the string only
+       when needed.
+       (m4_expansion_stack_push): Only push a macro name.
+       (m4_warn, _m4_defun_pro): Update callers.
+       (m4_expansion_stack_pop, m4_expansion_stack_dump): Delete.
+       (_m4_defun_epi, m4_fatal): Inline the calls.
+       * tests/m4sugar.at (m4@&t@_expansion_stack): New test.
+
 2008-10-30  Eric Blake  <ebb9@byu.net>
 
        Better documentation of AC_CHECK_HEADER's fourth argument.
index 85d36d0c3fbfbb8835754d678de5554b0ee79528..9a0d184b302d4bd040ccc496a2735b9069cc9ffa 100644 (file)
@@ -223,9 +223,8 @@ m4_define([m4_warning],
 # ----------------------------
 # Fatal the user.                                                      :)
 m4_define([m4_fatal],
-[m4_errprintn(m4_location[: error: $1])dnl
-m4_expansion_stack_dump()dnl
-m4_exit(m4_if([$2],, 1, [$2]))])
+[m4_errprintn(m4_location[: error: $1]
+m4_expansion_stack)m4_exit(m4_if([$2],, 1, [$2]))])
 
 
 # m4_assert(EXPRESSION, [EXIT-STATUS = 1])
@@ -259,8 +258,7 @@ m4_define([_m4_warn], [])
 # Report a MESSAGE to the user if the CATEGORY of warnings is enabled.
 m4_define([m4_warn],
 [_m4_warn([$1], [$2],
-m4_ifdef([_m4_expansion_stack],
-        [m4_expansion_stack[]m4_location[: the top level]]))])
+m4_ifdef([_m4_expansion_stack], [m4_expansion_stack]))])
 
 
 
@@ -1507,7 +1505,7 @@ m4_define([m4_undivert],
 # You should keep the definitions of _m4_defun_pro, _m4_defun_epi, and
 # m4_require at hand to follow the steps.
 #
-# This implements tries not to assume that the current diversion is
+# This implementation tries not to assume that the current diversion is
 # BODY, so as soon as a macro (m4_defun'd) is expanded, we first
 # record the current diversion under the name _m4_divert_dump (denoted
 # DUMP below for short).  This introduces an important difference with
@@ -1614,33 +1612,25 @@ m4_define([m4_undivert],
 
 # m4_expansion_stack
 # ------------------
-# Expands to the entire contents of the expansion stack, if not empty,
-# with a newline at its end.
+# Expands to the entire contents of the expansion stack.  The caller
+# must supply a trailing newline.  This macro always prints a
+# location; check whether _m4_expansion_stack is defined to filter out
+# the case when no defun'd macro is in force.
 m4_define([m4_expansion_stack],
-[m4_ifdef([_m4_expansion_stack],
-         [m4_stack_foreach_lifo([_m4_expansion_stack], [m4_n])])])
-
-# m4_expansion_stack_push(TEXT)
-# -----------------------------
-# Form an entry of the expansion stack and push it.
-m4_define([m4_expansion_stack_push],
-[m4_pushdef([_m4_expansion_stack], [[$1]])])
-
-
-# m4_expansion_stack_pop
-# ----------------------
-# Pop the topmost entry of the expansion stack.
-m4_define([m4_expansion_stack_pop],
-[m4_popdef([_m4_expansion_stack])])
+[m4_stack_foreach_sep_lifo([_$0], [_$0_entry(], [)
+])m4_location[: the top level]])
 
+# _m4_expansion_stack_entry(MACRO)
+# --------------------------------
+# Format an entry for MACRO found on the expansion stack.
+m4_define([_m4_expansion_stack_entry],
+[_m4_defn([m4_location($1)])[: $1 is expanded from...]])
 
-# m4_expansion_stack_dump
-# -----------------------
-# Dump the expansion stack.
-m4_define([m4_expansion_stack_dump],
-[m4_ifdef([_m4_expansion_stack],
-         [m4_errprint(m4_expansion_stack)])dnl
-m4_errprintn(m4_location[: the top level])])
+# m4_expansion_stack_push(MACRO)
+# ------------------------------
+# Form an entry of the expansion stack on entry to MACRO and push it.
+m4_define([m4_expansion_stack_push],
+[m4_pushdef([_m4_expansion_stack], [$1])])
 
 
 # _m4_divert(GROW)
@@ -1669,10 +1659,8 @@ m4_define([_m4_divert(GROW)],       10000)
 # This is called frequently, so minimize the number of macro invocations
 # by avoiding dnl and m4_defn overhead.
 m4_define([_m4_defun_pro],
-m4_do([[m4_ifdef([_m4_expansion_stack], [], [_m4_defun_pro_outer[]])]],
-      [[m4_expansion_stack_push(_m4_defn(
-         [m4_location($1)])[: $1 is expanded from...])]],
-      [[m4_pushdef([_m4_expanding($1)])]]))
+[m4_ifdef([_m4_expansion_stack], [], [_m4_defun_pro_outer[]])]dnl
+[m4_expansion_stack_push([$1])m4_pushdef([_m4_expanding($1)])])
 
 m4_define([_m4_defun_pro_outer],
 [m4_define([_m4_divert_dump],
@@ -1686,10 +1674,9 @@ m4_define([_m4_defun_pro_outer],
 # This is called frequently, so minimize the number of macro invocations
 # by avoiding dnl and m4_popdef overhead.
 m4_define([_m4_defun_epi],
-m4_do([[_m4_popdef([_m4_expanding($1)])]],
-      [[m4_expansion_stack_pop()]],
-      [[m4_ifdef([_m4_expansion_stack], [], [_m4_defun_epi_outer[]])]],
-      [[m4_provide([$1])]]))
+[_m4_popdef([_m4_expanding($1)], [_m4_expansion_stack])]dnl
+[m4_ifdef([_m4_expansion_stack], [], [_m4_defun_epi_outer[]])]dnl
+[m4_provide([$1])])
 
 m4_define([_m4_defun_epi_outer],
 [_m4_undefine([_m4_divert_dump])m4_divert_pop([GROW])m4_undivert([GROW])])
index 550d0850397634a77ae2f10e992f6073faf13204..d8554b5625d91956a15d4984afd65488590909bf 100644 (file)
@@ -243,6 +243,30 @@ script.4s:6: the top level
 AT_CLEANUP
 
 
+## -------------------- ##
+## m4_expansion_stack.  ##
+## -------------------- ##
+
+AT_SETUP([m4@&t@_expansion_stack])
+
+AT_CHECK_M4SUGAR_TEXT([[1.m4_expansion_stack
+m4_defun([a], [b])dnl
+m4_define([c], [d])dnl
+m4_defun([d], [2.m4_expansion_stack])dnl
+m4_defun([b], [c])dnl
+a
+3.m4_ifdef([_m4_expansion_stack], [m4_expansion_stack])
+]], [[1.script.4s:3: the top level
+2.script.4s:6: d is expanded from...
+script.4s:7: b is expanded from...
+script.4s:4: a is expanded from...
+script.4s:8: the top level
+3.
+]])
+
+AT_CLEANUP
+
+
 ## --------------------------- ##
 ## m4_require: error message.  ##
 ## --------------------------- ##