auto #ˆl–Ým_JJn-jy@·q·. bÑ¿¿ „ N¶ßÂÁ9£# -*- Autoconf -*- # This file is part of Autoconf. # foreach-based replacements for recursive functions. # Speeds up GNU M4 1.4.x by avoiding quadratic $@ recursion, but penalizes # GNU M4 1.6 by requiring more memory and macro expansions. # # Copyright (C) 2008-2017 Free Software Foundation, Inc. # This file is part of Autoconf. This program is free # software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the # Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # Under Section 7 of GPL version 3, you are granted additional # permissions described in the Autoconf Configure Script Exception, # version 3.0, as published by the Free Software Foundation. # # You should have received a copy of the GNU General Public License # and a copy of the Autoconf Configure Script Exception along with # this program; see the files COPYINGv3 and COPYING.EXCEPTION # respectively. If not, see . # Written by Eric Blake. # In M4 1.4.x, every byte of $@ is rescanned. This means that an # algorithm on n arguments that recurses with one less argument each # iteration will scan n * (n + 1) / 2 arguments, for O(n^2) time. In # M4 1.6, this was fixed so that $@ is only scanned once, then # back-references are made to information stored about the scan. # Thus, n iterations need only scan n arguments, for O(n) time. # Additionally, in M4 1.4.x, recursive algorithms did not clean up # memory very well, requiring O(n^2) memory rather than O(n) for n # iterations. # # This file is designed to overcome the quadratic nature of $@ # recursion by writing a variant of m4_foreach that uses m4_for rather # than $@ recursion to operate on the list. This involves more macro # expansions, but avoids the need to rescan a quadratic number of # arguments, making these replacements very attractive for M4 1.4.x. # On the other hand, in any version of M4, expanding additional macros # costs additional time; therefore, in M4 1.6, where $@ recursion uses # fewer macros, these replacements actually pessimize performance. # Additionally, the use of $10 to mean the tenth argument violates # POSIX; although all versions of m4 1.4.x support this meaning, a # future m4 version may switch to take it as the first argument # concatenated with a literal 0, so the implementations in this file # are not future-proof. Thus, this file is conditionally included as # part of m4_init(), only when it is detected that M4 probably has # quadratic behavior (ie. it lacks the macro __m4_version__). # # Please keep this file in sync with m4sugar.m4. # _m4_foreach(PRE, POST, IGNORED, ARG...) # --------------------------------------- # Form the common basis of the m4_foreach and m4_map macros. For each # ARG, expand PRE[ARG]POST[]. The IGNORED argument makes recursion # easier, and must be supplied rather than implicit. # # This version minimizes the number of times that $@ is evaluated by # using m4_for to generate a boilerplate into _m4_f then passing $@ to # that temporary macro. Thus, the recursion is done in m4_for without # reparsing any user input, and is not quadratic. For an idea of how # this works, note that m4_foreach(i,[1,2],[i]) calls # _m4_foreach([m4_define([i],],[)i],[],[1],[2]) # which defines _m4_f: # $1[$4]$2[]$1[$5]$2[]_m4_popdef([_m4_f]) # then calls _m4_f([m4_define([i],],[)i],[],[1],[2]) for a net result: # m4_define([i],[1])i[]m4_define([i],[2])i[]_m4_popdef([_m4_f]). m4_define([_m4_foreach], [m4_if([$#], [3], [], [m4_pushdef([_m4_f], _m4_for([4], [$#], [1], [$0_([1], [2],], [)])[_m4_popdef([_m4_f])])_m4_f($@)])]) m4_define([_m4_foreach_], [[$$1[$$3]$$2