[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: m4_expansion_stack
From: |
Akim Demaille |
Subject: |
FYI: m4_expansion_stack |
Date: |
17 Jan 2001 16:23:18 +0100 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.1 (Crater Lake) |
Before tracing the diversion, let's cleanup the sister code which
traces expansions.
Index: ChangeLog
from Akim Demaille <address@hidden>
* m4sugar.m4 (m4_undefine, m4_popdef): Don't tolerate undefined
arguments.
(_m4_expansion_stack): Rename as...
(m4_expansion_stack): this, and change its value: instead of using
the pushdef stack to stack each *line* of the stack, each
definition contains the whole stack. I.e., to display the whole
stack, instead of popdefing and displaying each definition, just
display the current definition.
(m4_expansion_stack_push, m4_expansion_stack_pop): New.
* tests/atspecific.m4 (AT_CHECK_AUTOCONF): Let $2 be the expected
exit status.
* tests/m4sugar.m4 (m4_require: circular dependencies): New test.
Index: m4sugar.m4
===================================================================
RCS file: /cvs/autoconf/m4sugar.m4,v
retrieving revision 2.34
diff -u -u -r2.34 m4sugar.m4
--- m4sugar.m4 2001/01/12 09:20:00 2.34
+++ m4sugar.m4 2001/01/17 15:23:28
@@ -123,6 +123,7 @@
m4_rename_m4([format])
m4_rename_m4([ifdef])
m4_rename([ifelse], [m4_if])
+m4_rename_m4([include])
m4_rename_m4([incr])
m4_rename_m4([index])
m4_rename_m4([indir])
@@ -131,10 +132,11 @@
m4_rename([m4wrap], [m4_wrap])
m4_rename_m4([maketemp])
m4_rename_m4([patsubst])
-m4_rename_m4([popdef])
+m4_undefine([popdef])
m4_rename_m4([pushdef])
m4_rename_m4([regexp])
m4_rename_m4([shift])
+m4_rename_m4([sinclude])
m4_rename_m4([substr])
m4_rename_m4([symbols])
m4_rename_m4([syscmd])
@@ -261,6 +263,7 @@
+
## ------------------- ##
## 4. File inclusion. ##
## ------------------- ##
@@ -302,10 +305,6 @@
[m4_include_unique([$1])dnl
m4_builtin([sinclude], [$1])])
-# Neutralize include and sinclude.
-m4_undefine([include])
-m4_undefine([sinclude])
-
## ------------------------------------ ##
@@ -327,7 +326,7 @@
# m4_ifval(COND, [IF-TRUE], [IF-FALSE])
-#--- ----------------------------------
+# -------------------------------------
# If COND is not the empty string, expand IF-TRUE, otherwise IF-FALSE.
# Comparable to m4_ifdef.
m4_define([m4_ifval],
@@ -485,6 +484,16 @@
_m4_dumpdefs_down([$1])])
+# m4_popdef(NAME)
+# ---------------
+# Unlike to the original, don't tolerate popping something which is
+# undefined.
+m4_define([m4_popdef],
+[m4_ifndef([$1]
+ [m4_fatal([$0: undefined: $1])])dnl
+m4_builtin([popdef], $@)])
+
+
# m4_quote(STRING)
# ----------------
# Return STRING quoted.
@@ -507,6 +516,16 @@
[m4_changequote(-=<{,}>=-)$1-=<{}>=-m4_changequote([,])])
+# m4_undefine(NAME)
+# -----------------
+# Unlike to the original, don't tolerate undefining something which is
+# undefined.
+m4_define([m4_undefine],
+[m4_ifndef([$1]
+ [m4_fatal([$0: undefined: $1])])dnl
+m4_builtin([undefine], $@)])
+
+
## -------------------------- ##
## 7. Implementing m4 loops. ##
## -------------------------- ##
@@ -1018,28 +1037,52 @@
# not for define'd macros.
#
# The scheme is simplistic: each time we enter an m4_defun'd macros,
-# we m4_pushdef its name in _m4_expansion_stack, and when we exit the
-# macro, we m4_popdef _m4_expansion_stack.
+# we prepend its name in m4_expansion_stack, and when we exit the
+# macro, we remove it (thanks to pushdef/popdef).
#
# In addition, we want to use the expansion stack to detect circular
# m4_require dependencies. This means we need to browse the stack to
# check whether a macro being expanded is m4_require'd. For ease of
# implementation, and certainly for the benefit of performances, we
-# don't browse the _m4_expansion_stack, rather each time we expand a
-# macro FOO we define _AC_EXPANDING(FOO). Then m4_require(BAR) simply
-# needs to check whether _AC_EXPANDING(BAR) is defined to diagnose a
+# don't browse the m4_expansion_stack, rather each time we expand a
+# macro FOO we define _m4_expanding(FOO). Then m4_require(BAR) simply
+# needs to check whether _m4_expanding(BAR) is defined to diagnose a
# circular dependency.
#
# To improve the diagnostic, in addition to keeping track of the stack
-# of macro calls, _m4_expansion_stack also records the m4_require
+# of macro calls, m4_expansion_stack also records the m4_require
# stack. Note that therefore an m4_defun'd macro being required will
# appear twice in the stack: the first time because it is required,
# the second because it is expanded. We can avoid this, but it has
# two small drawbacks: (i) the implementation is slightly more
# complex, and (ii) it hides the difference between define'd macros
-# (which don't appear in _m4_expansion_stack) and m4_defun'd macros
+# (which don't appear in m4_expansion_stack) and m4_defun'd macros
# (which do). The more debugging information, the better.
+
+# m4_expansion_stack_push(TEXT)
+# -----------------------------
+m4_define([m4_expansion_stack_push],
+[m4_pushdef([m4_expansion_stack],
+ [$1]
+m4_defn([m4_expansion_stack]))])
+
+
+# m4_expansion_stack_pop
+# ----------------------
+# Dump the expansion stack.
+m4_define([m4_expansion_stack_pop],
+[m4_popdef([m4_expansion_stack])])
+
+
+# m4_expansion_stack_dump
+# -----------------------
+# Dump the expansion stack.
+m4_define([m4_expansion_stack_dump],
+[m4_errprint(m4_defn([m4_expansion_stack]))dnl
+m4_errprintn(m4_location[: the top level])])
+
+
# _m4_divert(GROW)
# ----------------
# This diversion is used by the m4_defun/m4_require machinery. It is
@@ -1058,23 +1101,12 @@
m4_define([_m4_divert(GROW)], 10000)
-# m4_expansion_stack_dump
-# -----------------------
-# Dump the expansion stack.
-m4_define([m4_expansion_stack_dump],
-[m4_ifdef([_m4_expansion_stack],
- [m4_errprintn(m4_defn([_m4_expansion_stack]))dnl
-m4_popdef([_m4_expansion_stack])dnl
-m4_expansion_stack_dump()],
- [m4_errprintn(m4_location[: the top level])])])
-
# _m4_defun_pro(MACRO-NAME)
# -------------------------
# The prologue for Autoconf macros.
m4_define([_m4_defun_pro],
-[m4_pushdef([_m4_expansion_stack],
- m4_defn([m4_location($1)])[: $1 is expanded from...])dnl
+[m4_expansion_stack_push(m4_defn([m4_location($1)])[: $1 is expanded
from...])dnl
m4_pushdef([_m4_expanding($1)])dnl
m4_ifdef([_m4_divert_dump],
[m4_divert_push(m4_defn([_m4_divert_diversion]))],
@@ -1092,7 +1124,7 @@
m4_if(_m4_divert_dump, _m4_divert_diversion,
[m4_undivert(_m4_divert([GROW]))dnl
m4_undefine([_m4_divert_dump])])dnl
-m4_popdef([_m4_expansion_stack])dnl
+m4_expansion_stack_pop()dnl
m4_popdef([_m4_expanding($1)])dnl
m4_provide([$1])dnl
])
@@ -1158,7 +1190,7 @@
# If NAME-TO-CHECK has never been expanded (actually, if it is not
# m4_provide'd), expand BODY-TO-EXPAND *before* the current macro
# expansion. Once expanded, emit it in _m4_divert_dump. Keep track
-# of the m4_require chain in _m4_expansion_stack.
+# of the m4_require chain in m4_expansion_stack.
#
# The normal cases are:
#
@@ -1186,8 +1218,7 @@
# `extension' prevents `AC_LANG_COMPILER' from having actual arguments that
# it passes to `AC_LANG_COMPILER(C)'.
m4_define([m4_require],
-[m4_pushdef([_m4_expansion_stack],
- m4_location[: $1 is required by...])dnl
+[m4_expansion_stack_push(m4_location[: $1 is required by...])
m4_ifdef([_m4_expanding($1)],
[m4_fatal([$0: circular dependency of $1])])dnl
m4_ifndef([_m4_divert_dump],
@@ -1202,7 +1233,7 @@
[],
[m4_warn([syntax],
[$1 is m4_require'd but is not m4_defun'd])])dnl
-m4_popdef([_m4_expansion_stack])dnl
+m4_expansion_stack_pop()dnl
])
Index: tests/atspecific.m4
===================================================================
RCS file: /cvs/autoconf/tests/atspecific.m4,v
retrieving revision 1.36
diff -u -u -r1.36 atspecific.m4
--- tests/atspecific.m4 2000/12/23 10:11:59 1.36
+++ tests/atspecific.m4 2001/01/17 15:23:28
@@ -22,13 +22,14 @@
## ---------------------------------------- ##
-# AT_CHECK_AUTOCONF(FLAGS, STDOUT, STDERR)
-# ----------------------------------------
+# AT_CHECK_AUTOCONF(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
+# -----------------------------------------------------------
# Also remove `configure.in', just in case one remained from a previous
# run.
m4_define([AT_CHECK_AUTOCONF],
[AT_CLEANUP_FILES(configure.in configure)dnl
-AT_CHECK([autoconf --autoconf-dir .. -l $at_srcdir $1], 0, [$2], [$3])])
+AT_CHECK([autoconf --autoconf-dir .. -l $at_srcdir $1],
+ m4_default([$2], [0]), [$3], [$4])])
# AT_CHECK_AUTOHEADER
Index: tests/base.at
===================================================================
RCS file: /cvs/autoconf/tests/base.at,v
retrieving revision 1.10
diff -u -u -r1.10 base.at
--- tests/base.at 2000/12/23 10:11:59 1.10
+++ tests/base.at 2001/01/17 15:23:28
@@ -122,7 +122,7 @@
esac
]])
-AT_CHECK_AUTOCONF([], [],
+AT_CHECK_AUTOCONF([], 0, [],
[configure.ac:15: warning: SINGLE_TEST invoked multiple times
])
AT_CHECK_CONFIGURE
@@ -157,4 +157,4 @@
AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE
-AT_CLEANUP(configure)
+AT_CLEANUP
Index: tests/m4sugar.at
===================================================================
RCS file: /cvs/autoconf/tests/m4sugar.at,v
retrieving revision 1.8
diff -u -u -r1.8 m4sugar.at
--- tests/m4sugar.at 2000/12/23 10:11:59 1.8
+++ tests/m4sugar.at 2001/01/17 15:23:28
@@ -2,6 +2,94 @@
AT_BANNER([M4sugar.])
+
+# Order of the tests:
+# - m4_warn
+#
+# - m4_require
+# uses warn/error code.
+#
+# - m4_text_wrap
+
+## --------- ##
+## m4_warn. ##
+## --------- ##
+
+AT_SETUP([[m4_warn]])
+
+# m4_text_wrap is used to display the help strings. Also, check that
+# commas are not swallowed. This can easily happen because of
+# m4-listification.
+
+AT_DATA(configure.ac,
+[[m4_warn([foo], [foo])
+m4_warn([bar], [bar])
+m4_warn([syntax], [syntax])
+]])
+
+AT_CHECK([autoconf --autoconf-dir .. -l $at_srcdir -o-],
+ 0, [],
+[configure.ac:3: warning: syntax
+])
+
+AT_CHECK([autoconf --autoconf-dir .. -l $at_srcdir -o- -Wall],
+ 0, [],
+[configure.ac:1: warning: foo
+configure.ac:2: warning: bar
+configure.ac:3: warning: syntax
+])
+
+AT_CHECK([autoconf --autoconf-dir .. -l $at_srcdir -o- -Wnone,bar],
+ 0, [],
+[configure.ac:2: warning: bar
+])
+
+AT_CHECK([autoconf --autoconf-dir .. -l $at_srcdir -o- -Wnone,bar,error],
+ 1, [],
+[configure.ac:2: error: bar
+configure.ac:2: the top level
+])
+
+AT_CLEANUP
+
+
+## ----------------------------------- ##
+## m4_require: circular dependencies. ##
+## ----------------------------------- ##
+
+AT_SETUP([[m4_require: circular dependencies]])
+
+# m4_text_wrap is used to display the help strings. Also, check that
+# commas are not swallowed. This can easily happen because of
+# m4-listification.
+
+AT_DATA([configure.ac],
+[[m4_defun([foo],
+[m4_require([bar])])
+
+m4_defun([bar],
+[m4_require([foo])])
+
+m4_defun([baz],
+[m4_require([foo])])
+
+baz
+]])
+
+AT_CHECK_AUTOCONF([], 1, [],
+[[configure.ac:10: error: m4_require: circular dependency of foo
+configure.ac:10: foo is required by...
+configure.ac:5: bar is expanded from...
+configure.ac:10: bar is required by...
+configure.ac:2: foo is expanded from...
+configure.ac:10: foo is required by...
+configure.ac:8: baz is expanded from...
+configure.ac:10: the top level
+]])
+
+AT_CLEANUP
+
+
## -------------- ##
## m4_text_wrap. ##
## -------------- ##
@@ -44,50 +132,7 @@
First, second , third, [,quoted]
]])
-
-AT_CHECK_AUTOCONF([-o-], [expout])
-
-AT_CLEANUP
-
-
-
-## --------- ##
-## m4_warn. ##
-## --------- ##
-
-AT_SETUP([[m4_warn]])
-
-# m4_text_wrap is used to display the help strings. Also, check that
-# commas are not swallowed. This can easily happen because of
-# m4-listification.
-
-AT_DATA(configure.ac,
-[[m4_warn([foo], [foo])
-m4_warn([bar], [bar])
-m4_warn([syntax], [syntax])
-]])
-
-AT_CHECK([autoconf --autoconf-dir .. -l $at_srcdir -o-],
- 0, [],
-[configure.ac:3: warning: syntax
-])
-
-AT_CHECK([autoconf --autoconf-dir .. -l $at_srcdir -o- -Wall],
- 0, [],
-[configure.ac:1: warning: foo
-configure.ac:2: warning: bar
-configure.ac:3: warning: syntax
-])
-AT_CHECK([autoconf --autoconf-dir .. -l $at_srcdir -o- -Wnone,bar],
- 0, [],
-[configure.ac:2: warning: bar
-])
-
-AT_CHECK([autoconf --autoconf-dir .. -l $at_srcdir -o- -Wnone,bar,error],
- 1, [],
-[configure.ac:2: error: bar
-configure.ac:2: the top level
-])
+AT_CHECK_AUTOCONF([-o-], 0, [expout])
AT_CLEANUP
Index: tests/semantics.at
===================================================================
RCS file: /cvs/autoconf/tests/semantics.at,v
retrieving revision 1.15
diff -u -u -r1.15 semantics.at
--- tests/semantics.at 2001/01/16 10:21:45 1.15
+++ tests/semantics.at 2001/01/17 15:23:28
@@ -157,7 +157,7 @@
AC_OUTPUT
]])
-AT_CHECK_AUTOCONF([], [],
+AT_CHECK_AUTOCONF([], 0, [],
[configure.ac:10: warning: AC_CHECK_TYPE: assuming `uint65536_t' is not a type
])
AT_CHECK([[sed -e '/^#(cut-from-here/,/^#to-here)/!d' -e '/^#/d' configure]],
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: m4_expansion_stack,
Akim Demaille <=