From: Akim Demaille Date: Fri, 3 Aug 2001 09:14:38 +0000 (+0000) Subject: Clean up the handling of the M4 builtins tracing exception. X-Git-Tag: AUTOCONF-2.52d~127 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fcd1589f5a832cec3bedfe66d79e194e2fc3684;p=thirdparty%2Fautoconf.git Clean up the handling of the M4 builtins tracing exception. * bin/autom4te.in (Request::request): Don't complete M4 builtins trace requests. (@m4_builtins): Rename as... (@m4_builtin): this. (%m4_builtin_alternate_name): New. (&parse_args): Complete the trace requests with alternate names. (&handle_traces): Hence no longer do it here. (&trace_requests): Remove, unused. --- diff --git a/ChangeLog b/ChangeLog index 8358d2654..3c44e2436 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2001-08-03 Akim Demaille + + Clean up the handling of the M4 builtins tracing exception. + + * bin/autom4te.in (Request::request): Don't complete M4 builtins + trace requests. + (@m4_builtins): Rename as... + (@m4_builtin): this. + (%m4_builtin_alternate_name): New. + (&parse_args): Complete the trace requests with alternate names. + (&handle_traces): Hence no longer do it here. + (&trace_requests): Remove, unused. + 2001-08-03 Akim Demaille * doc/autoconf.texi (Redefined M4 Macros): Document m4_exit, diff --git a/bin/autom4te.in b/bin/autom4te.in index 22eaf30ec..db508dfd6 100644 --- a/bin/autom4te.in +++ b/bin/autom4te.in @@ -129,12 +129,7 @@ sub request { if (! exists ${$obj->macro}{$_}) { - # FIXME: This is too rough an approximation: we should have - # a means to select only M4 builtins, but @m4_builtins is not - # visible here. - s/^m4_//; ${$obj->macro}{$_} = 1; - ${$obj->macro}{"m4_$_"} = 1; $obj->valid (0); } } @@ -270,9 +265,63 @@ die "$me: need GNU m4 1.4 or later: $m4\n" $m4 .= ' --nesting-limit=1024' if " $m4 " !~ / (--nesting-limit|-L) /; -# @M4_BUILTINS -- M4 builtins and a useful comment. -my @m4_builtins = `echo dumpdef | $m4 2>&1 >/dev/null`; -map { s/:.*//;s/\W// } @m4_builtins; + +# @M4_BUILTIN -- M4 builtins and a useful comment. +my @m4_builtin = `echo dumpdef | $m4 2>&1 >/dev/null`; +map { s/:.*//;s/\W// } @m4_builtin; + + +# %M4_BUILTIN_ALTERNATE_NAME +# -------------------------- +# The builtins are renamed, e.g., `define' is renamed `m4_define'. +# So map `define' to `m4_define' and conversely. +# Some macros don't follow this scheme: be sure to properly map to their +# alternate name too. +# +# This is because GNU M4 1.4's tracing of builtins is buggy. When run on +# this input: +# +# | divert(-1) +# | changequote([, ]) +# | define([m4_eval], defn([eval])) +# | eval(1) +# | m4_eval(2) +# | undefine([eval]) +# | m4_eval(3) +# +# it behaves this way: +# +# | % m4 input.m4 -da -t eval +# | m4trace: -1- eval(1) +# | m4trace: -1- m4_eval(2) +# | m4trace: -1- m4_eval(3) +# | % +# +# Conversely: +# +# | % m4 input.m4 -da -t m4_eval +# | % +# +# So we will merge them, i.e. tracing `BUILTIN' or tracing +# `m4_BUILTIN' will be the same: tracing both, but honoring the +# *last* trace specification. +# +# FIXME: This is not enough: in the output `$0' will be `BUILTIN' +# sometimes and `m4_BUILTIN' at others. We should return a unique name, +# the one specified by the user. +# +# FIXME: To be absolutely rigorous, I would say that given that we +# _redefine_ divert (instead of _copying_ it), divert and the like +# should not be part of this list. +my %m4_builtin_alternate_name; +@m4_builtin_alternate_name{"$_", "m4_$_"} = ("m4_$_", "$_") + foreach (grep { !/m4wrap|m4exit|dnl|ifelse|__.*__/ } @m4_builtin); +@m4_builtin_alternate_name{"ifelse", "m4_if"} = ("m4_if", "ifelse"); +@m4_builtin_alternate_name{"m4exit", "m4_exit"} = ("m4_exit", "m4exit"); +@m4_builtin_alternate_name{"m4wrap", "m4_wrap"} = ("m4_wrap", "m4wrap"); + + + ## ---------- ## @@ -409,10 +458,12 @@ Try `$me --help' for more information.\n" { /^([^:]+)(?::(.*))?$/ms; $trace{$1} = defined $2 ? $2 : '$f:$l:$n:$%'; + $trace{$m4_builtin_alternate_name{$1}} = $trace{$1} + if exists $m4_builtin_alternate_name{$1}; } # We don't want to depend upon m4's --include to find the top level - # files. Try to get a canonical name, as it's a key for caching. + # files. Try to get a canonical name, as it's part of the key for caching. for (my $i = 0; $i < $#ARGV; ++$i) { $ARGV[$i] = find_file ($ARGV[$i]); @@ -420,12 +471,12 @@ Try `$me --help' for more information.\n" } -# handle_m4 ($REQ, @TRACE) +# handle_m4 ($REQ, @MACRO) # ------------------------ -# Run m4 on the input files, and save the traces on the @TRACE macros. +# Run m4 on the input files, and save the traces on the @MACRO. sub handle_m4 ($@) { - my ($req, @trace) = @_; + my ($req, @macro) = @_; # Find the files. We don't want to depend upon m4's --include. # *.m4f files have to be reloaded. @@ -454,7 +505,7 @@ sub handle_m4 ($@) . " --define m4_warnings=$m4_warnings" . ' --debug=aflq' . " --error-output=$me.cache/" . $req->cache - . join (' --trace=', '', @trace) + . join (' --trace=', '', sort @macro) . join (' --include=', '', @include) . $files . " >$tmp/output"); @@ -575,30 +626,6 @@ sub handle_output ($) ## --------------------- ## -# %REQUEST -# trace_requests (%TRACE) -# ----------------------- -sub trace_requests -{ - my (%trace) = @_; - my %res; - - for my $macro (keys %trace) - { - $res{$macro} = 1; - $macro =~ s/^m4_//; - # See &handle_traces for an explanation for this paragraph. - if (grep /^$macro$/, @m4_builtins) - { - $res{$macro} = 1; - $res{"m4_$macro"} = 1; - } - } - - return %res; -} - - # $M4_MACRO # trace_format_to_m4 ($FORMAT) # ---------------------------- @@ -682,46 +709,6 @@ sub handle_traces ($$%) { my ($req, $output, %trace) = @_; - # GNU M4 1.4's tracing of builtins is buggy. When run on this input: - # - # | divert(-1) - # | changequote([, ]) - # | define([m4_eval], defn([eval])) - # | eval(1) - # | m4_eval(2) - # | undefine([eval]) - # | m4_eval(3) - # - # it behaves this way: - # - # | % m4 input.m4 -da -t eval - # | m4trace: -1- eval(1) - # | m4trace: -1- m4_eval(2) - # | m4trace: -1- m4_eval(3) - # | % - # - # Conversely: - # - # | % m4 input.m4 -da -t m4_eval - # | % - # - # So we will merge them, i.e. tracing `BUILTIN' or tracing - # `m4_BUILTIN' will be the same: tracing both, but honoring the - # *last* trace specification. - # FIXME: This is not enough: in the output `$0' will be `BUILTIN' - # sometimes and `m4_BUILTIN' at others. We should return a unique name, - # the one specified by the user. - foreach my $macro (keys %trace) - { - my $format = $trace{$macro}; - $macro =~ s/^m4_//; - if (grep /^$macro$/, @m4_builtins) - { - $trace{$macro} = $format; - $trace{"m4_$macro"} = $format; - } - } - verbose "formatting traces for `$output': ", join (', ', sort keys %trace); # Processing the traces. @@ -781,11 +768,11 @@ EOF # the `at_' name space. print $trace_m4 "# Copy the builtins.\n"; - map { print $trace_m4 "define([at_$_], defn([$_]))\n" } @m4_builtins; + map { print $trace_m4 "define([at_$_], defn([$_]))\n" } @m4_builtin; print $trace_m4 "\n"; print $trace_m4 "# Disable them.\n"; - map { print $trace_m4 "at_undefine([$_])\n" } @m4_builtins; + map { print $trace_m4 "at_undefine([$_])\n" } @m4_builtin; print $trace_m4 "\n";