aboutsummaryrefslogtreecommitdiff
path: root/tools/mhmake/src
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-01-19 20:29:24 +0000
committermarha <marha@users.sourceforge.net>2011-01-19 20:29:24 +0000
commitcbe6ed88f01b654241301539d8fa3f6111a0a6de (patch)
tree0fe25b7083dc4cc0c3e162fe18e9d427fcb712a5 /tools/mhmake/src
parentcdc60fdcddbe5666aac11af34c6c030d4a670b99 (diff)
downloadvcxsrv-cbe6ed88f01b654241301539d8fa3f6111a0a6de.tar.gz
vcxsrv-cbe6ed88f01b654241301539d8fa3f6111a0a6de.tar.bz2
vcxsrv-cbe6ed88f01b654241301539d8fa3f6111a0a6de.zip
Use bison instead of bison++
The += operator should also take the environment variables into account Solved problem when & in redirect operator on command line Solved syntax error when SPACE was follewed by SPACE Removed kdevelop3 project files Enable debug info in debug build on linux Added support for foreach function Fixed dependency problem for implicit rules with extra dependencies Increased gnu make compatibility: allow implicit rules without commands Solved wrong error message when it cannot build a target in mhmake_dbg On windows: when checking the extension of a command: make sure a / does not cause a wrong decision Added safety against recursive implicit rules. Fixed wrong check on failure to open makefiles. Make sure no message is printed when -include is used flex and bison generated files: make sure the #line statements have the correct line numbers for the debugger after having added one line in the beginning of the file after running the flex/bison. Make sure that the variable defined just before an error or message/info macro is defined when the message is generated. mhmake_dbg: print error message when a target cannot be build because the directory of the target does not exist (and no rule is defined for it) Reformatted message/info macro output Also print makefile and line number when using error and message macro Solved crash in mhmake_dbg when -C is specified on the command line Solved problem in macro expansion when 2 patsubst inside each other addprefix should not give an error when done on an empty string Use comspec when echo is followed by a pipe character (piping is not supported by the echo internal command of mhmake) Solved possible stack curruption (there was little chance that this was occuring)
Diffstat (limited to 'tools/mhmake/src')
-rw-r--r--tools/mhmake/src/bison.cc1025
-rw-r--r--tools/mhmake/src/bison.h249
-rw-r--r--tools/mhmake/src/bisondata/bison.m4556
-rw-r--r--tools/mhmake/src/bisondata/c++.m4170
-rw-r--r--tools/mhmake/src/bisondata/c.m4477
-rw-r--r--tools/mhmake/src/bisondata/lalr1.cc1169
-rw-r--r--tools/mhmake/src/bisondata/location.cc279
-rw-r--r--tools/mhmake/src/bisondata/m4sugar/foreach.m4400
-rw-r--r--tools/mhmake/src/bisondata/m4sugar/m4sugar.m42789
-rw-r--r--tools/mhmake/src/build.cpp89
-rw-r--r--tools/mhmake/src/commandqueue.cpp23
-rw-r--r--tools/mhmake/src/curdir.cpp3
-rw-r--r--tools/mhmake/src/fileinfo.cpp11
-rw-r--r--tools/mhmake/src/flex.skl1
-rw-r--r--tools/mhmake/src/flexlexer.h41
-rw-r--r--tools/mhmake/src/md5.cpp2
-rw-r--r--tools/mhmake/src/mhmake.cpp2
-rw-r--r--tools/mhmake/src/mhmakefileparser.cpp67
-rw-r--r--tools/mhmake/src/mhmakefileparser.h36
-rw-r--r--tools/mhmake/src/mhmakelexer.l478
-rw-r--r--tools/mhmake/src/mhmakeparser.y63
-rw-r--r--tools/mhmake/src/rule.cpp2
-rw-r--r--tools/mhmake/src/stdafx.h6
-rw-r--r--tools/mhmake/src/util.cpp8
-rw-r--r--tools/mhmake/src/util.h2
25 files changed, 6332 insertions, 1616 deletions
diff --git a/tools/mhmake/src/bison.cc b/tools/mhmake/src/bison.cc
deleted file mode 100644
index 5a203f719..000000000
--- a/tools/mhmake/src/bison.cc
+++ /dev/null
@@ -1,1025 +0,0 @@
-/* This file is part of mhmake.
- *
- * Copyright (C) 2001-2010 marha@sourceforge.net
- *
- * Mhmake 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.
- *
- * Mhmake 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with Mhmake. If not, see <http://www.gnu.org/licenses/>.
-*/
-/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
-/* Skeleton output parser for bison,
- Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
-
- 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 1, 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.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
-/* HEADER SECTION */
-#if defined( _MSDOS ) || defined(MSDOS) || defined(__MSDOS__)
-#define __MSDOS_AND_ALIKE
-#endif
-#if defined(_WINDOWS) && defined(_MSC_VER)
-#define __HAVE_NO_ALLOCA
-#define __MSDOS_AND_ALIKE
-#endif
-
-#ifndef alloca
-#if defined( __GNUC__)
-#define alloca __builtin_alloca
-
-#elif (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
-#include <alloca.h>
-
-#elif defined (__MSDOS_AND_ALIKE)
-#include <malloc.h>
-#ifndef __TURBOC__
-/* MS C runtime lib */
-#define alloca _alloca
-#endif
-
-#elif defined(_AIX)
-#include <malloc.h>
-#pragma alloca
-
-#elif defined(__hpux)
-#ifdef __cplusplus
-extern "C" {
-void *alloca (unsigned int);
-};
-#else /* not __cplusplus */
-void *alloca ();
-#endif /* not __cplusplus */
-
-#endif /* not _AIX not MSDOS, or __TURBOC__ or _AIX, not sparc. */
-#endif /* alloca not defined. */
-#ifdef c_plusplus
-#ifndef __cplusplus
-#define __cplusplus
-#endif
-#endif
-#ifdef __cplusplus
-#ifndef YY_USE_CLASS
-#define YY_USE_CLASS
-#endif
-#else
-#ifndef __STDC__
-#define const
-#endif
-#endif
-#include <stdio.h>
-#define YYBISON 1
-$/* %{ and %header{ and %union, during decl */
-#define YY_@_BISON 1
-#ifndef YY_@_COMPATIBILITY
-#ifndef YY_USE_CLASS
-#define YY_@_COMPATIBILITY 1
-#else
-#define YY_@_COMPATIBILITY 0
-#endif
-#endif
-
-#if YY_@_COMPATIBILITY != 0
-/* backward compatibility */
-#ifdef YYLTYPE
-#ifndef YY_@_LTYPE
-#define YY_@_LTYPE YYLTYPE
-#endif
-#endif
-#ifdef YYSTYPE
-#ifndef YY_@_STYPE
-#define YY_@_STYPE YYSTYPE
-#endif
-#endif
-#ifdef YYDEBUG
-#ifndef YY_@_DEBUG
-#define YY_@_DEBUG YYDEBUG
-#endif
-#endif
-#ifdef YY_@_STYPE
-#ifndef yystype
-#define yystype YY_@_STYPE
-#endif
-#endif
-/* use goto to be compatible */
-#ifndef YY_@_USE_GOTO
-#define YY_@_USE_GOTO 1
-#endif
-#endif
-
-/* use no goto to be clean in C++ */
-#ifndef YY_@_USE_GOTO
-#define YY_@_USE_GOTO 0
-#endif
-
-#ifndef YY_@_PURE
-$/* YY_@_PURE */
-#endif
-
-/* section apres lecture def, avant lecture grammaire S2 */
-$/* prefix */
-#ifndef YY_@_DEBUG
-$/* YY_@_DEBUG */
-#endif
-
-
-#ifndef YY_@_LSP_NEEDED
-$ /* YY_@_LSP_NEEDED*/
-#endif
-
-
-
-/* DEFAULT LTYPE*/
-#ifdef YY_@_LSP_NEEDED
-#ifndef YY_@_LTYPE
-typedef struct yyltype
-{
- int timestamp;
- int first_line;
- int first_column;
- int last_line;
- int last_column;
- char *text;
-}
-yyltype;
-
-#define YY_@_LTYPE yyltype
-#endif
-#endif
-/* DEFAULT STYPE*/
- /* We used to use `unsigned long' as YY_@_STYPE on MSDOS,
- but it seems better to be consistent.
- Most programs should declare their own type anyway. */
-
-#ifndef YY_@_STYPE
-#define YY_@_STYPE int
-#endif
-/* DEFAULT MISCELANEOUS */
-#ifndef YY_@_PARSE
-#define YY_@_PARSE yyparse
-#endif
-#ifndef YY_@_LEX
-#define YY_@_LEX yylex
-#endif
-#ifndef YY_@_LVAL
-#define YY_@_LVAL yylval
-#endif
-#ifndef YY_@_LLOC
-#define YY_@_LLOC yylloc
-#endif
-#ifndef YY_@_CHAR
-#define YY_@_CHAR yychar
-#endif
-#ifndef YY_@_NERRS
-#define YY_@_NERRS yynerrs
-#endif
-#ifndef YY_@_DEBUG_FLAG
-#define YY_@_DEBUG_FLAG yydebug
-#endif
-#ifndef YY_@_ERROR
-#define YY_@_ERROR yyerror
-#endif
-#ifndef YY_@_PARSE_PARAM
-#ifndef __STDC__
-#ifndef __cplusplus
-#ifndef YY_USE_CLASS
-#define YY_@_PARSE_PARAM
-#ifndef YY_@_PARSE_PARAM_DEF
-#define YY_@_PARSE_PARAM_DEF
-#endif
-#endif
-#endif
-#endif
-#ifndef YY_@_PARSE_PARAM
-#define YY_@_PARSE_PARAM void
-#endif
-#endif
-#if YY_@_COMPATIBILITY != 0
-/* backward compatibility */
-#ifdef YY_@_LTYPE
-#ifndef YYLTYPE
-#define YYLTYPE YY_@_LTYPE
-#else
-/* WARNING obsolete !!! user defined YYLTYPE not reported into generated header */
-#endif
-#endif
-#ifndef YYSTYPE
-#define YYSTYPE YY_@_STYPE
-#else
-/* WARNING obsolete !!! user defined YYSTYPE not reported into generated header */
-#endif
-#ifdef YY_@_PURE
-#ifndef YYPURE
-#define YYPURE YY_@_PURE
-#endif
-#endif
-#ifdef YY_@_DEBUG
-#ifndef YYDEBUG
-#define YYDEBUG YY_@_DEBUG
-#endif
-#endif
-#ifndef YY_@_ERROR_VERBOSE
-#ifdef YYERROR_VERBOSE
-#define YY_@_ERROR_VERBOSE YYERROR_VERBOSE
-#endif
-#endif
-#ifndef YY_@_LSP_NEEDED
-#ifdef YYLSP_NEEDED
-#define YY_@_LSP_NEEDED YYLSP_NEEDED
-#endif
-#endif
-#endif
-#ifndef YY_USE_CLASS
-/* TOKEN C */
-$ /* #defines tokens */
-#else
-/* CLASS */
-#ifndef YY_@_CLASS
-#define YY_@_CLASS @
-#endif
-#ifndef YY_@_INHERIT
-#define YY_@_INHERIT
-#endif
-#ifndef YY_@_MEMBERS
-#define YY_@_MEMBERS
-#endif
-#ifndef YY_@_LEX_BODY
-#define YY_@_LEX_BODY
-#endif
-#ifndef YY_@_ERROR_BODY
-#define YY_@_ERROR_BODY
-#endif
-#ifndef YY_@_CONSTRUCTOR_PARAM
-#define YY_@_CONSTRUCTOR_PARAM
-#endif
-#ifndef YY_@_CONSTRUCTOR_CODE
-#define YY_@_CONSTRUCTOR_CODE
-#endif
-#ifndef YY_@_CONSTRUCTOR_INIT
-#define YY_@_CONSTRUCTOR_INIT
-#endif
-/* choose between enum and const */
-#ifndef YY_@_USE_CONST_TOKEN
-#define YY_@_USE_CONST_TOKEN 0
-/* yes enum is more compatible with flex, */
-/* so by default we use it */
-#endif
-#if YY_@_USE_CONST_TOKEN != 0
-#ifndef YY_@_ENUM_TOKEN
-#define YY_@_ENUM_TOKEN yy_@_enum_token
-#endif
-#endif
-
-class YY_@_CLASS YY_@_INHERIT
-{
-public:
-#if YY_@_USE_CONST_TOKEN != 0
-/* static const int token ... */
-$ /* decl const */
-#else
-enum YY_@_ENUM_TOKEN { YY_@_NULL_TOKEN=0
-$ /* enum token */
- }; /* end of enum declaration */
-#endif
-public:
- int YY_@_PARSE (YY_@_PARSE_PARAM);
-#ifdef YY_@_PURE
-#else
-#ifdef YY_@_LSP_NEEDED
- YY_@_LTYPE YY_@_LLOC;
-#endif
- int YY_@_NERRS;
- int YY_@_CHAR;
-#endif
-#if YY_@_DEBUG != 0
- int YY_@_DEBUG_FLAG; /* nonzero means print parse trace */
-#endif
-public:
- YY_@_CLASS(YY_@_CONSTRUCTOR_PARAM);
-public:
- YY_@_MEMBERS
-};
-/* other declare folow */
-#if YY_@_USE_CONST_TOKEN != 0
-$ /* const YY_@_CLASS::token */
-#endif
-/*apres const */
-YY_@_CLASS::YY_@_CLASS(YY_@_CONSTRUCTOR_PARAM) YY_@_CONSTRUCTOR_INIT
-{
-#if YY_@_DEBUG != 0
-YY_@_DEBUG_FLAG=0;
-#endif
-YY_@_CONSTRUCTOR_CODE;
-};
-#endif
-$ /* fattrs + tables */
-
-/* parser code folow */
-
-
-/* This is the parser code that is written into each bison parser
- when the %semantic_parser declaration is not specified in the grammar.
- It was written by Richard Stallman by simplifying the hairy parser
- used when %semantic_parser is specified. */
-
-/* Note: dollar marks section change
- the next is replaced by the list of actions, each action
- as one case of the switch. */
-
-#if YY_@_USE_GOTO != 0
-/*
- SUPRESSION OF GOTO : on some C++ compiler (sun c++)
- the goto is strictly forbidden if any constructor/destructor
- is used in the whole function (very stupid isn't it ?)
- so goto are to be replaced with a 'while/switch/case construct'
- here are the macro to keep some apparent compatibility
-*/
-#define YYGOTO(lb) {yy_gotostate=lb;continue;}
-#define YYBEGINGOTO enum yy_labels yy_gotostate=yygotostart; \
- for(;;) switch(yy_gotostate) { case yygotostart: {
-#define YYLABEL(lb) } case lb: {
-#define YYENDGOTO } }
-#define YYBEGINDECLARELABEL enum yy_labels {yygotostart
-#define YYDECLARELABEL(lb) ,lb
-#define YYENDDECLARELABEL };
-#else
-/* macro to keep goto */
-#define YYGOTO(lb) goto lb
-#define YYBEGINGOTO
-#define YYLABEL(lb) lb:
-#define YYENDGOTO
-#define YYBEGINDECLARELABEL
-#define YYDECLARELABEL(lb)
-#define YYENDDECLARELABEL
-#endif
-/* LABEL DECLARATION */
-YYBEGINDECLARELABEL
- YYDECLARELABEL(yynewstate)
- YYDECLARELABEL(yybackup)
-/* YYDECLARELABEL(yyresume) */
- YYDECLARELABEL(yydefault)
- YYDECLARELABEL(yyreduce)
- YYDECLARELABEL(yyerrlab) /* here on detecting error */
- YYDECLARELABEL(yyerrlab1) /* here on error raised explicitly by an action */
- YYDECLARELABEL(yyerrdefault) /* current state does not do anything special for the error token. */
- YYDECLARELABEL(yyerrpop) /* pop the current state because it cannot handle the error token */
- YYDECLARELABEL(yyerrhandle)
-YYENDDECLARELABEL
-/* ALLOCA SIMULATION */
-/* __HAVE_NO_ALLOCA */
-#ifdef __HAVE_NO_ALLOCA
-int __alloca_free_ptr(char *ptr,char *ref)
-{if(ptr!=ref) free(ptr);
- return 0;}
-
-#define __ALLOCA_alloca(size) malloc(size)
-#define __ALLOCA_free(ptr,ref) __alloca_free_ptr((char *)ptr,(char *)ref)
-
-#ifdef YY_@_LSP_NEEDED
-#define __ALLOCA_return(num) \
- return( __ALLOCA_free(yyss,yyssa)+\
- __ALLOCA_free(yyvs,yyvsa)+\
- __ALLOCA_free(yyls,yylsa)+\
- (num))
-#else
-#define __ALLOCA_return(num) \
- return( __ALLOCA_free(yyss,yyssa)+\
- __ALLOCA_free(yyvs,yyvsa)+\
- (num))
-#endif
-#else
-#define __ALLOCA_return(num) return(num)
-#define __ALLOCA_alloca(size) alloca(size)
-#define __ALLOCA_free(ptr,ref)
-#endif
-
-/* ENDALLOCA SIMULATION */
-
-#define yyerrok (yyerrstatus = 0)
-#define yyclearin (YY_@_CHAR = YYEMPTY)
-#define YYEMPTY -2
-#define YYEOF 0
-#define YYACCEPT __ALLOCA_return(0)
-#define YYABORT __ALLOCA_return(1)
-#define YYERROR YYGOTO(yyerrlab1)
-/* Like YYERROR except do call yyerror.
- This remains here temporarily to ease the
- transition to the new meaning of YYERROR, for GCC.
- Once GCC version 2 has supplanted version 1, this can go. */
-#define YYFAIL YYGOTO(yyerrlab)
-#define YYRECOVERING() (!!yyerrstatus)
-#define YYBACKUP(token, value) \
-do\
- if (YY_@_CHAR == YYEMPTY && yylen == 1)\
- {\
- YY_@_CHAR = (token), YY_@_LVAL = (value);\
- yychar1 = YYTRANSLATE (YY_@_CHAR);\
- YYPOPSTACK;\
- YYGOTO(yybackup);\
- }\
- else\
- {\
- YY_@_ERROR ("syntax error: cannot back up"); YYERROR;\
- }\
-while (0)
-
-#define YYTERROR 1
-#define YYERRCODE 256
-
-#ifndef YY_@_PURE
-/* UNPURE */
-#define YYLEX YY_@_LEX()
-#ifndef YY_USE_CLASS
-/* If nonreentrant, and not class , generate the variables here */
-int YY_@_CHAR; /* the lookahead symbol */
- /* lookahead symbol */
-int YY_@_NERRS; /* number of parse errors so far */
-#ifdef YY_@_LSP_NEEDED
-YY_@_LTYPE YY_@_LLOC; /* location data for the lookahead */
- /* symbol */
-#endif
-#endif
-
-
-#else
-/* PURE */
-#ifdef YY_@_LSP_NEEDED
-#define YYLEX YY_@_LEX(&YY_@_LVAL, &YY_@_LLOC)
-#else
-#define YYLEX YY_@_LEX(&YY_@_LVAL)
-#endif
-#endif
-#ifndef YY_USE_CLASS
-#if YY_@_DEBUG != 0
-int YY_@_DEBUG_FLAG; /* nonzero means print parse trace */
-/* Since this is uninitialized, it does not stop multiple parsers
- from coexisting. */
-#endif
-#endif
-
-
-
-/* YYINITDEPTH indicates the initial size of the parser's stacks */
-
-#ifndef YYINITDEPTH
-#define YYINITDEPTH 200
-#endif
-
-/* YYMAXDEPTH is the maximum size the stacks can grow to
- (effective only if the built-in stack extension method is used). */
-
-#if YYMAXDEPTH == 0
-#undef YYMAXDEPTH
-#endif
-
-#ifndef YYMAXDEPTH
-#define YYMAXDEPTH 10000
-#endif
-
-
-#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
-#define __yy_bcopy(FROM,TO,COUNT) __builtin_memcpy(TO,FROM,COUNT)
-#else /* not GNU C or C++ */
-
-/* This is the most reliable way to avoid incompatibilities
- in available built-in functions on various systems. */
-
-#ifdef __cplusplus
-static void __yy_bcopy (char *from, char *to, size_t count)
-#else
-#ifdef __STDC__
-static void __yy_bcopy (char *from, char *to, int count)
-#else
-static void __yy_bcopy (from, to, count)
- char *from;
- char *to;
- int count;
-#endif
-#endif
-{
- register char *f = from;
- register char *t = to;
- register size_t i = count;
-
- while (i-- > 0)
- *t++ = *f++;
-}
-#endif
-
-int
-#ifdef YY_USE_CLASS
- YY_@_CLASS::
-#endif
- YY_@_PARSE(YY_@_PARSE_PARAM)
-#ifndef __STDC__
-#ifndef __cplusplus
-#ifndef YY_USE_CLASS
-/* parameter definition without protypes */
-YY_@_PARSE_PARAM_DEF
-#endif
-#endif
-#endif
-{
- register int yystate;
- register int yyn;
- register short *yyssp;
- register YY_@_STYPE *yyvsp;
- int yyerrstatus; /* number of tokens to shift before error messages enabled */
- int yychar1=0; /* lookahead token as an internal (translated) token number */
-
- short yyssa[YYINITDEPTH]; /* the state stack */
- YY_@_STYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
-
- short *yyss = yyssa; /* refer to the stacks thru separate pointers */
- YY_@_STYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
-
-#ifdef YY_@_LSP_NEEDED
- YY_@_LTYPE yylsa[YYINITDEPTH]; /* the location stack */
- YY_@_LTYPE *yyls = yylsa;
- YY_@_LTYPE *yylsp;
-
-#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
-#else
-#define YYPOPSTACK (yyvsp--, yyssp--)
-#endif
-
- int yystacksize = YYINITDEPTH;
-
-#ifdef YY_@_PURE
- int YY_@_CHAR;
- YY_@_STYPE YY_@_LVAL;
- int YY_@_NERRS;
-#ifdef YY_@_LSP_NEEDED
- YY_@_LTYPE YY_@_LLOC;
-#endif
-#endif
-
- YY_@_STYPE yyval; /* the variable used to return */
- /* semantic values from the action */
- /* routines */
-
- int yylen;
-/* start loop, in which YYGOTO may be used. */
-YYBEGINGOTO
-
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- fprintf(stderr, "Starting parse\n");
-#endif
- yystate = 0;
- yyerrstatus = 0;
- YY_@_NERRS = 0;
- YY_@_CHAR = YYEMPTY; /* Cause a token to be read. */
-
- /* Initialize stack pointers.
- Waste one element of value and location stack
- so that they stay on the same level as the state stack.
- The wasted elements are never initialized. */
-
- yyssp = yyss - 1;
- yyvsp = yyvs;
-#ifdef YY_@_LSP_NEEDED
- yylsp = yyls;
-#endif
-
-/* Push a new state, which is found in yystate . */
-/* In all cases, when you get here, the value and location stacks
- have just been pushed. so pushing a state here evens the stacks. */
-YYLABEL(yynewstate)
-
- *++yyssp = yystate;
-
- if (yyssp >= yyss + yystacksize - 1)
- {
- /* Give user a chance to reallocate the stack */
- /* Use copies of these so that the &'s don't force the real ones into memory. */
- YY_@_STYPE *yyvs1 = yyvs;
- short *yyss1 = yyss;
-#ifdef YY_@_LSP_NEEDED
- YY_@_LTYPE *yyls1 = yyls;
-#endif
-
- /* Get the current used size of the three stacks, in elements. */
- size_t size = yyssp - yyss + 1;
-
-#ifdef yyoverflow
- /* Each stack pointer address is followed by the size of
- the data in use in that stack, in bytes. */
-#ifdef YY_@_LSP_NEEDED
- /* This used to be a conditional around just the two extra args,
- but that might be undefined if yyoverflow is a macro. */
- yyoverflow("parser stack overflow",
- &yyss1, size * sizeof (*yyssp),
- &yyvs1, size * sizeof (*yyvsp),
- &yyls1, size * sizeof (*yylsp),
- &yystacksize);
-#else
- yyoverflow("parser stack overflow",
- &yyss1, size * sizeof (*yyssp),
- &yyvs1, size * sizeof (*yyvsp),
- &yystacksize);
-#endif
-
- yyss = yyss1; yyvs = yyvs1;
-#ifdef YY_@_LSP_NEEDED
- yyls = yyls1;
-#endif
-#else /* no yyoverflow */
- /* Extend the stack our own way. */
- if (yystacksize >= YYMAXDEPTH)
- {
- YY_@_ERROR("parser stack overflow");
- __ALLOCA_return(2);
- }
- yystacksize *= 2;
- if (yystacksize > YYMAXDEPTH)
- yystacksize = YYMAXDEPTH;
- yyss = (short *) __ALLOCA_alloca (yystacksize * sizeof (*yyssp));
- __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
- __ALLOCA_free(yyss1,yyssa);
- yyvs = (YY_@_STYPE *) __ALLOCA_alloca (yystacksize * sizeof (*yyvsp));
- __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
- __ALLOCA_free(yyvs1,yyvsa);
-#ifdef YY_@_LSP_NEEDED
- yyls = (YY_@_LTYPE *) __ALLOCA_alloca (yystacksize * sizeof (*yylsp));
- __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
- __ALLOCA_free(yyls1,yylsa);
-#endif
-#endif /* no yyoverflow */
-
- yyssp = yyss + size - 1;
- yyvsp = yyvs + size - 1;
-#ifdef YY_@_LSP_NEEDED
- yylsp = yyls + size - 1;
-#endif
-
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- fprintf(stderr, "Stack size increased to %d\n", yystacksize);
-#endif
-
- if (yyssp >= yyss + yystacksize - 1)
- YYABORT;
- }
-
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- fprintf(stderr, "Entering state %d\n", yystate);
-#endif
-
- YYGOTO(yybackup);
-YYLABEL(yybackup)
-
-/* Do appropriate processing given the current state. */
-/* Read a lookahead token if we need one and don't already have one. */
-/* YYLABEL(yyresume) */
-
- /* First try to decide what to do without reference to lookahead token. */
-
- yyn = yypact[yystate];
- if (yyn == YYFLAG)
- YYGOTO(yydefault);
-
- /* Not known => get a lookahead token if don't already have one. */
-
- /* yychar is either YYEMPTY or YYEOF
- or a valid token in external form. */
-
- if (YY_@_CHAR == YYEMPTY)
- {
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- fprintf(stderr, "Reading a token: ");
-#endif
- YY_@_CHAR = YYLEX;
- }
-
- /* Convert token to internal form (in yychar1) for indexing tables with */
-
- if (YY_@_CHAR <= 0) /* This means end of input. */
- {
- yychar1 = 0;
- YY_@_CHAR = YYEOF; /* Don't call YYLEX any more */
-
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- fprintf(stderr, "Now at end of input.\n");
-#endif
- }
- else
- {
- yychar1 = YYTRANSLATE(YY_@_CHAR);
-
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- {
- fprintf (stderr, "Next token is %d (%s", YY_@_CHAR, yytname[yychar1]);
- /* Give the individual parser a way to print the precise meaning
- of a token, for further debugging info. */
-#ifdef YYPRINT
- YYPRINT (stderr, YY_@_CHAR, YY_@_LVAL);
-#endif
- fprintf (stderr, ")\n");
- }
-#endif
- }
-
- yyn += yychar1;
- if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
- YYGOTO(yydefault);
-
- yyn = yytable[yyn];
-
- /* yyn is what to do for this token type in this state.
- Negative => reduce, -yyn is rule number.
- Positive => shift, yyn is new state.
- New state is final state => don't bother to shift,
- just return success.
- 0, or most negative number => error. */
-
- if (yyn < 0)
- {
- if (yyn == YYFLAG)
- YYGOTO(yyerrlab);
- yyn = -yyn;
- YYGOTO(yyreduce);
- }
- else if (yyn == 0)
- YYGOTO(yyerrlab);
-
- if (yyn == YYFINAL)
- YYACCEPT;
-
- /* Shift the lookahead token. */
-
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- fprintf(stderr, "Shifting token %d (%s), ", YY_@_CHAR, yytname[yychar1]);
-#endif
-
- /* Discard the token being shifted unless it is eof. */
- if (YY_@_CHAR != YYEOF)
- YY_@_CHAR = YYEMPTY;
-
- *++yyvsp = YY_@_LVAL;
-#ifdef YY_@_LSP_NEEDED
- *++yylsp = YY_@_LLOC;
-#endif
-
- /* count tokens shifted since error; after three, turn off error status. */
- if (yyerrstatus) yyerrstatus--;
-
- yystate = yyn;
- YYGOTO(yynewstate);
-
-/* Do the default action for the current state. */
-YYLABEL(yydefault)
-
- yyn = yydefact[yystate];
- if (yyn == 0)
- YYGOTO(yyerrlab);
-
-/* Do a reduction. yyn is the number of a rule to reduce with. */
-YYLABEL(yyreduce)
- yylen = yyr2[yyn];
- if (yylen > 0)
- yyval = yyvsp[1-yylen]; /* implement default value of the action */
-
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- {
- int i;
-
- fprintf (stderr, "Reducing via rule %d (line %d), ",
- yyn, yyrline[yyn]);
-
- /* Print the symbols being reduced, and their result. */
- for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
- fprintf (stderr, "%s ", yytname[yyrhs[i]]);
- fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
- }
-#endif
-
-$ /* the action file gets copied in in place of this dollarsign */
- yyvsp -= yylen;
- yyssp -= yylen;
-#ifdef YY_@_LSP_NEEDED
- yylsp -= yylen;
-#endif
-
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- {
- short *ssp1 = yyss - 1;
- fprintf (stderr, "state stack now");
- while (ssp1 != yyssp)
- fprintf (stderr, " %d", *++ssp1);
- fprintf (stderr, "\n");
- }
-#endif
-
- *++yyvsp = yyval;
-
-#ifdef YY_@_LSP_NEEDED
- yylsp++;
- if (yylen == 0)
- {
- *yylsp= YY_@_LLOC;
- //yylsp->first_line = YY_@_LLOC.first_line;
- //yylsp->first_column = YY_@_LLOC.first_column;
- //yylsp->last_line = (yylsp-1)->last_line;
- //yylsp->last_column = (yylsp-1)->last_column;
- //yylsp->text = 0;
- }
- else
- {
- *yylsp = *(yylsp+yylen-1);
- //yylsp->last_line = (yylsp+yylen-1)->last_line;
- //yylsp->last_column = (yylsp+yylen-1)->last_column;
- }
-#endif
-
- /* Now "shift" the result of the reduction.
- Determine what state that goes to,
- based on the state we popped back to
- and the rule number reduced by. */
-
- yyn = yyr1[yyn];
-
- yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
- if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
- yystate = yytable[yystate];
- else
- yystate = yydefgoto[yyn - YYNTBASE];
-
- YYGOTO(yynewstate);
-
-YYLABEL(yyerrlab) /* here on detecting error */
-
- if (! yyerrstatus)
- /* If not already recovering from an error, report this error. */
- {
- ++YY_@_NERRS;
-
-#ifdef YY_@_ERROR_VERBOSE
- yyn = yypact[yystate];
-
- if (yyn > YYFLAG && yyn < YYLAST)
- {
- size_t size = 0;
- char *msg;
- int x, count;
-
- count = 0;
- /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
- for (x = (yyn < 0 ? -yyn : 0);
- x < (sizeof(yytname) / sizeof(char *)); x++)
- if (yycheck[x + yyn] == x)
- size += strlen(yytname[x]) + 15, count++;
- msg = (char *) malloc(size + 15);
- if (msg != 0)
- {
- strcpy(msg, "parse error");
-
- if (count < 5)
- {
- count = 0;
- for (x = (yyn < 0 ? -yyn : 0);
- x < (sizeof(yytname) / sizeof(char *)); x++)
- if (yycheck[x + yyn] == x)
- {
- strcat(msg, count == 0 ? ", expecting `" : " or `");
- strcat(msg, yytname[x]);
- strcat(msg, "'");
- count++;
- }
- }
- YY_@_ERROR(msg);
- free(msg);
- }
- else
- YY_@_ERROR ("parse error; also virtual memory exceeded");
- }
- else
-#endif /* YY_@_ERROR_VERBOSE */
- YY_@_ERROR("parse error");
- }
-
- YYGOTO(yyerrlab1);
-YYLABEL(yyerrlab1) /* here on error raised explicitly by an action */
-
- if (yyerrstatus == 3)
- {
- /* if just tried and failed to reuse lookahead token after an error, discard it. */
-
- /* return failure if at end of input */
- if (YY_@_CHAR == YYEOF)
- YYABORT;
-
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- fprintf(stderr, "Discarding token %d (%s).\n", YY_@_CHAR, yytname[yychar1]);
-#endif
-
- YY_@_CHAR = YYEMPTY;
- }
-
- /* Else will try to reuse lookahead token
- after shifting the error token. */
-
- yyerrstatus = 3; /* Each real token shifted decrements this */
-
- YYGOTO(yyerrhandle);
-
-YYLABEL(yyerrdefault) /* current state does not do anything special for the error token. */
-
-#if 0
- /* This is wrong; only states that explicitly want error tokens
- should shift them. */
- yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
- if (yyn) YYGOTO(yydefault);
-#endif
-
-YYLABEL(yyerrpop) /* pop the current state because it cannot handle the error token */
-
- if (yyssp == yyss) YYABORT;
- yyvsp--;
- yystate = *--yyssp;
-#ifdef YY_@_LSP_NEEDED
- yylsp--;
-#endif
-
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- {
- short *ssp1 = yyss - 1;
- fprintf (stderr, "Error: state stack now");
- while (ssp1 != yyssp)
- fprintf (stderr, " %d", *++ssp1);
- fprintf (stderr, "\n");
- }
-#endif
-
-YYLABEL(yyerrhandle)
-
- yyn = yypact[yystate];
- if (yyn == YYFLAG)
- YYGOTO(yyerrdefault);
-
- yyn += YYTERROR;
- if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
- YYGOTO(yyerrdefault);
-
- yyn = yytable[yyn];
- if (yyn < 0)
- {
- if (yyn == YYFLAG)
- YYGOTO(yyerrpop);
- yyn = -yyn;
- YYGOTO(yyreduce);
- }
- else if (yyn == 0)
- YYGOTO(yyerrpop);
-
- if (yyn == YYFINAL)
- YYACCEPT;
-
-#if YY_@_DEBUG != 0
- if (YY_@_DEBUG_FLAG)
- fprintf(stderr, "Shifting error token, ");
-#endif
-
- *++yyvsp = YY_@_LVAL;
-#ifdef YY_@_LSP_NEEDED
- *++yylsp = YY_@_LLOC;
-#endif
-
- yystate = yyn;
- YYGOTO(yynewstate);
-/* end loop, in which YYGOTO may be used. */
- YYENDGOTO
-}
-
-/* END */
-$ /* section 3 */
-
-/* AFTER END , NEVER READ !!! */
-
diff --git a/tools/mhmake/src/bison.h b/tools/mhmake/src/bison.h
deleted file mode 100644
index 0724ae112..000000000
--- a/tools/mhmake/src/bison.h
+++ /dev/null
@@ -1,249 +0,0 @@
-/* This file is part of mhmake.
- *
- * Copyright (C) 2001-2010 marha@sourceforge.net
- *
- * Mhmake 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.
- *
- * Mhmake 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with Mhmake. If not, see <http://www.gnu.org/licenses/>.
-*/
-/* before anything */
-#ifdef c_plusplus
-#ifndef __cplusplus
-#define __cplusplus
-#endif
-#endif
-#ifdef __cplusplus
-#ifndef YY_USE_CLASS
-#define YY_USE_CLASS
-#endif
-#else
-#endif
-#include <stdio.h>
-$ /* %{ and %header{ and %union, during decl */
-#ifndef YY_@_COMPATIBILITY
-#ifndef YY_USE_CLASS
-#define YY_@_COMPATIBILITY 1
-#else
-#define YY_@_COMPATIBILITY 0
-#endif
-#endif
-
-#if YY_@_COMPATIBILITY != 0
-/* backward compatibility */
-#ifdef YYLTYPE
-#ifndef YY_@_LTYPE
-#define YY_@_LTYPE YYLTYPE
-/* WARNING obsolete !!! user defined YYLTYPE not reported into generated header */
-/* use %define LTYPE */
-#endif
-#endif
-#ifdef YYSTYPE
-#ifndef YY_@_STYPE
-#define YY_@_STYPE YYSTYPE
-/* WARNING obsolete !!! user defined YYSTYPE not reported into generated header */
-/* use %define STYPE */
-#endif
-#endif
-#ifdef YYDEBUG
-#ifndef YY_@_DEBUG
-#define YY_@_DEBUG YYDEBUG
-/* WARNING obsolete !!! user defined YYDEBUG not reported into generated header */
-/* use %define DEBUG */
-#endif
-#endif
-#ifdef YY_@_STYPE
-#ifndef yystype
-#define yystype YY_@_STYPE
-#endif
-#endif
-/* use goto to be compatible */
-#ifndef YY_@_USE_GOTO
-#define YY_@_USE_GOTO 1
-#endif
-#endif
-
-/* use no goto to be clean in C++ */
-#ifndef YY_@_USE_GOTO
-#define YY_@_USE_GOTO 0
-#endif
-
-#ifndef YY_@_PURE
-$/* YY_@_PURE */
-#endif
-$/* prefix */
-#ifndef YY_@_DEBUG
-$/* YY_@_DEBUG */
-#endif
-#ifndef YY_@_LSP_NEEDED
-$ /* YY_@_LSP_NEEDED*/
-#endif
-/* DEFAULT LTYPE*/
-#ifdef YY_@_LSP_NEEDED
-#ifndef YY_@_LTYPE
-typedef
- struct yyltype
- {
- int timestamp;
- int first_line;
- int first_column;
- int last_line;
- int last_column;
- char *text;
- }
- yyltype;
-
-#define YY_@_LTYPE yyltype
-#endif
-#endif
-/* DEFAULT STYPE*/
-#ifndef YY_@_STYPE
-#define YY_@_STYPE int
-#endif
-/* DEFAULT MISCELANEOUS */
-#ifndef YY_@_PARSE
-#define YY_@_PARSE yyparse
-#endif
-#ifndef YY_@_LEX
-#define YY_@_LEX yylex
-#endif
-#ifndef YY_@_LVAL
-#define YY_@_LVAL yylval
-#endif
-#ifndef YY_@_LLOC
-#define YY_@_LLOC yylloc
-#endif
-#ifndef YY_@_CHAR
-#define YY_@_CHAR yychar
-#endif
-#ifndef YY_@_NERRS
-#define YY_@_NERRS yynerrs
-#endif
-#ifndef YY_@_DEBUG_FLAG
-#define YY_@_DEBUG_FLAG yydebug
-#endif
-#ifndef YY_@_ERROR
-#define YY_@_ERROR yyerror
-#endif
-
-#ifndef YY_@_PARSE_PARAM
-#ifndef __STDC__
-#ifndef __cplusplus
-#ifndef YY_USE_CLASS
-#define YY_@_PARSE_PARAM
-#ifndef YY_@_PARSE_PARAM_DEF
-#define YY_@_PARSE_PARAM_DEF
-#endif
-#endif
-#endif
-#endif
-#ifndef YY_@_PARSE_PARAM
-#define YY_@_PARSE_PARAM void
-#endif
-#endif
-
-/* TOKEN C */
-#ifndef YY_USE_CLASS
-
-#ifndef YY_@_PURE
-extern YY_@_STYPE YY_@_LVAL;
-#endif
-
-$ /* #defines token */
-/* after #define tokens, before const tokens S5*/
-#else
-#ifndef YY_@_CLASS
-#define YY_@_CLASS @
-#endif
-
-#ifndef YY_@_INHERIT
-#define YY_@_INHERIT
-#endif
-#ifndef YY_@_MEMBERS
-#define YY_@_MEMBERS
-#endif
-#ifndef YY_@_LEX_BODY
-#define YY_@_LEX_BODY
-#endif
-#ifndef YY_@_ERROR_BODY
-#define YY_@_ERROR_BODY
-#endif
-#ifndef YY_@_CONSTRUCTOR_PARAM
-#define YY_@_CONSTRUCTOR_PARAM
-#endif
-/* choose between enum and const */
-#ifndef YY_@_USE_CONST_TOKEN
-#define YY_@_USE_CONST_TOKEN 0
-/* yes enum is more compatible with flex, */
-/* so by default we use it */
-#endif
-#if YY_@_USE_CONST_TOKEN != 0
-#ifndef YY_@_ENUM_TOKEN
-#define YY_@_ENUM_TOKEN yy_@_enum_token
-#endif
-#endif
-
-class YY_@_CLASS YY_@_INHERIT
-{
-public:
-#if YY_@_USE_CONST_TOKEN != 0
-/* static const int token ... */
-$ /* decl const */
-#else
-enum YY_@_ENUM_TOKEN { YY_@_NULL_TOKEN=0
-$ /* enum token */
- }; /* end of enum declaration */
-#endif
-public:
- int YY_@_PARSE(YY_@_PARSE_PARAM);
-#ifdef YY_@_PURE
-#else
-#ifdef YY_@_LSP_NEEDED
- YY_@_LTYPE YY_@_LLOC;
-#endif
- int YY_@_NERRS;
- int YY_@_CHAR;
-#endif
-#if YY_@_DEBUG != 0
-public:
- int YY_@_DEBUG_FLAG; /* nonzero means print parse trace */
-#endif
-public:
- YY_@_CLASS(YY_@_CONSTRUCTOR_PARAM);
-public:
- YY_@_MEMBERS
-};
-/* other declare folow */
-#endif
-
-
-#if YY_@_COMPATIBILITY != 0
-/* backward compatibility */
-#ifndef YYSTYPE
-#define YYSTYPE YY_@_STYPE
-#endif
-
-#ifndef YYLTYPE
-#define YYLTYPE YY_@_LTYPE
-#endif
-#ifndef YYDEBUG
-#ifdef YY_@_DEBUG
-#define YYDEBUG YY_@_DEBUG
-#endif
-#endif
-
-#endif
-/* END */
-$ /* section 3 %header{ */
- /* AFTER END , NEVER READ !!! */
-
-
-
diff --git a/tools/mhmake/src/bisondata/bison.m4 b/tools/mhmake/src/bisondata/bison.m4
new file mode 100644
index 000000000..af7c8f7a7
--- /dev/null
+++ b/tools/mhmake/src/bisondata/bison.m4
@@ -0,0 +1,556 @@
+ -*- Autoconf -*-
+
+# Language-independent M4 Macros for Bison.
+# Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008 Free Software Foundation,
+# Inc.
+
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+## ---------------- ##
+## Identification. ##
+## ---------------- ##
+
+# b4_copyright(TITLE, YEARS)
+# --------------------------
+m4_define([b4_copyright],
+[b4_comment([A Bison parser, made by GNU Bison b4_version.])
+
+b4_comment([$1
+
+m4_text_wrap([Copyright (C) $2 Free Software Foundation, Inc.], [ ])
+
+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.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.])
+
+b4_comment([As a special exception, you may create a larger work that contains
+part or all of the Bison parser skeleton and distribute that work
+under terms of your choice, so long as that work isn't itself a
+parser generator using the skeleton or a modified version thereof
+as a parser skeleton. Alternatively, if you modify or redistribute
+the parser skeleton itself, you may (at your option) remove this
+special exception, which will cause the skeleton and the resulting
+Bison output files to be licensed under the GNU General Public
+License without this special exception.
+
+This special exception was added by the Free Software Foundation in
+version 2.2 of Bison.])])
+
+
+## ---------------- ##
+## Error handling. ##
+## ---------------- ##
+
+# The following error handling macros print error directives that should not
+# become arguments of other macro invocations since they would likely then be
+# mangled. Thus, they print to stdout directly.
+
+# b4_cat(TEXT)
+# ------------
+# Write TEXT to stdout. Precede the final newline with an @ so that it's
+# escaped. For example:
+#
+# b4_cat([[@complain(invalid input@)]])
+m4_define([b4_cat],
+[m4_syscmd([cat <<'_m4eof'
+]m4_bpatsubst(m4_dquote($1), [_m4eof], [_m4@`eof])[@
+_m4eof
+])dnl
+m4_if(m4_sysval, [0], [], [m4_fatal([$0: cannot write to stdout])])])
+
+# b4_error(KIND, FORMAT, [ARG1], [ARG2], ...)
+# -------------------------------------------
+# Write @KIND(FORMAT@,ARG1@,ARG2@,...@) to stdout.
+#
+# For example:
+#
+# b4_error([[warn]], [[invalid value for `%s': %s]], [[foo]], [[3]])
+m4_define([b4_error],
+[b4_cat([[@]$1[(]$2[]]dnl
+[m4_if([$#], [2], [],
+ [m4_foreach([b4_arg],
+ m4_dquote(m4_shift(m4_shift($@))),
+ [[@,]b4_arg])])[@)]])])
+
+# b4_error_at(KIND, START, END, FORMAT, [ARG1], [ARG2], ...)
+# ----------------------------------------------------------
+# Write @KIND_at(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
+#
+# For example:
+#
+# b4_error_at([[complain]], [[input.y:2.3]], [[input.y:5.4]],
+# [[invalid %s]], [[foo]])
+m4_define([b4_error_at],
+[b4_cat([[@]$1[_at(]$2[@,]$3[@,]$4[]]dnl
+[m4_if([$#], [4], [],
+ [m4_foreach([b4_arg],
+ m4_dquote(m4_shift(m4_shift(m4_shift(m4_shift($@))))),
+ [[@,]b4_arg])])[@)]])])
+
+# b4_warn(FORMAT, [ARG1], [ARG2], ...)
+# ------------------------------------
+# Write @warn(FORMAT@,ARG1@,ARG2@,...@) to stdout.
+#
+# For example:
+#
+# b4_warn([[invalid value for `%s': %s]], [[foo]], [[3]])
+#
+# As a simple test suite, this:
+#
+# m4_divert(-1)
+# m4_define([asdf], [ASDF])
+# m4_define([fsa], [FSA])
+# m4_define([fdsa], [FDSA])
+# b4_warn([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]])
+# b4_warn([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]])
+# b4_warn()
+# b4_warn(1)
+# b4_warn(1, 2)
+#
+# Should produce this without newlines:
+#
+# @warn([asdf), asdf]@,[fsa), fsa]@,[fdsa), fdsa]@)
+# @warn(asdf), asdf@,fsa), fsa@,fdsa), fdsa@)
+# @warn(@)
+# @warn(1@)
+# @warn(1@,2@)
+m4_define([b4_warn],
+[b4_error([[warn]], $@)])
+
+# b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...)
+# ---------------------------------------------------
+# Write @warn(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
+#
+# For example:
+#
+# b4_warn_at([[input.y:2.3]], [[input.y:5.4]], [[invalid %s]], [[foo]])
+m4_define([b4_warn_at],
+[b4_error_at([[warn]], $@)])
+
+# b4_complain(FORMAT, [ARG1], [ARG2], ...)
+# ----------------------------------------
+# Write @complain(FORMAT@,ARG1@,ARG2@,...@) to stdout.
+#
+# See b4_warn example.
+m4_define([b4_complain],
+[b4_error([[complain]], $@)])
+
+# b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...)
+# -------------------------------------------------------
+# Write @complain(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
+#
+# See b4_warn_at example.
+m4_define([b4_complain_at],
+[b4_error_at([[complain]], $@)])
+
+# b4_fatal(FORMAT, [ARG1], [ARG2], ...)
+# -------------------------------------
+# Write @fatal(FORMAT@,ARG1@,ARG2@,...@) to stdout and exit.
+#
+# See b4_warn example.
+m4_define([b4_fatal],
+[b4_error([[fatal]], $@)dnl
+m4_exit(1)])
+
+# b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...)
+# ----------------------------------------------------
+# Write @fatal(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout and exit.
+#
+# See b4_warn_at example.
+m4_define([b4_fatal_at],
+[b4_error_at([[fatal]], $@)dnl
+m4_exit(1)])
+
+
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+# m4_define_default([b4_lex_param], []) dnl breaks other skeletons
+m4_define_default([b4_pre_prologue], [])
+m4_define_default([b4_post_prologue], [])
+m4_define_default([b4_epilogue], [])
+m4_define_default([b4_parse_param], [])
+
+# The initial column and line.
+m4_define_default([b4_location_initial_column], [1])
+m4_define_default([b4_location_initial_line], [1])
+
+
+## ------------ ##
+## Data Types. ##
+## ------------ ##
+
+# b4_ints_in(INT1, INT2, LOW, HIGH)
+# ---------------------------------
+# Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
+m4_define([b4_ints_in],
+[m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
+
+
+
+## ------------------ ##
+## Decoding options. ##
+## ------------------ ##
+
+# b4_flag_if(FLAG, IF-TRUE, IF-FALSE)
+# -----------------------------------
+# Run IF-TRUE if b4_FLAG_flag is 1, IF-FALSE if FLAG is 0, otherwise fail.
+m4_define([b4_flag_if],
+[m4_case(b4_$1_flag,
+ [0], [$3],
+ [1], [$2],
+ [m4_fatal([invalid $1 value: ]$1)])])
+
+
+# b4_define_flag_if(FLAG)
+# -----------------------
+# Define "b4_FLAG_if(IF-TRUE, IF-FALSE)" that depends on the
+# value of the Boolean FLAG.
+m4_define([b4_define_flag_if],
+[_b4_define_flag_if($[1], $[2], [$1])])
+
+# _b4_define_flag_if($1, $2, FLAG)
+# --------------------------------
+# This macro works around the impossibility to define macros
+# inside macros, because issuing `[$1]' is not possible in M4 :(.
+# This sucks hard, GNU M4 should really provide M5 like $$1.
+m4_define([_b4_define_flag_if],
+[m4_if([$1$2], $[1]$[2], [],
+ [m4_fatal([$0: Invalid arguments: $@])])dnl
+m4_define([b4_$3_if],
+ [b4_flag_if([$3], [$1], [$2])])])
+
+
+# b4_FLAG_if(IF-TRUE, IF-FALSE)
+# -----------------------------
+# Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise.
+b4_define_flag_if([defines]) # Whether headers are requested.
+b4_define_flag_if([error_verbose]) # Whether error are verbose.
+b4_define_flag_if([glr]) # Whether a GLR parser is requested.
+b4_define_flag_if([locations]) # Whether locations are tracked.
+b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled.
+b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
+
+
+## ------------------------- ##
+## Assigning token numbers. ##
+## ------------------------- ##
+
+
+## ----------- ##
+## Synclines. ##
+## ----------- ##
+
+# b4_basename(NAME)
+# -----------------
+# Similar to POSIX basename; the differences don't matter here.
+# Beware that NAME is not evaluated.
+m4_define([b4_basename],
+[m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])])
+
+
+# b4_syncline(LINE, FILE)
+# -----------------------
+m4_define([b4_syncline],
+[b4_flag_if([synclines], [
+b4_sync_end([__line__], [b4_basename(m4_quote(__file__))])
+b4_sync_start([$1], [$2])])])
+
+m4_define([b4_sync_end], [b4_comment([Line $1 of $2])])
+m4_define([b4_sync_start], [b4_comment([Line $1 of $2])])
+
+# b4_user_code(USER-CODE)
+# -----------------------
+# Emit code from the user, ending it with synclines.
+m4_define([b4_user_code],
+[$1
+b4_syncline([@oline@], [@ofile@])])
+
+
+# b4_define_user_code(MACRO)
+# --------------------------
+# From b4_MACRO, build b4_user_MACRO that includes the synclines.
+m4_define([b4_define_user_code],
+[m4_define([b4_user_$1],
+[b4_user_code([b4_$1])])])
+
+
+# b4_user_actions
+# b4_user_initial_action
+# b4_user_post_prologue
+# b4_user_pre_prologue
+# b4_user_stype
+# ----------------------
+# Macros that issue user code, ending with synclines.
+b4_define_user_code([actions])
+b4_define_user_code([initial_action])
+b4_define_user_code([post_prologue])
+b4_define_user_code([pre_prologue])
+b4_define_user_code([stype])
+
+
+# b4_check_user_names(WHAT, USER-LIST, BISON-NAMESPACE)
+# --------------------------------------------------------
+# Warn if any name of type WHAT is used by the user (as recorded in USER-LIST)
+# but is not used by Bison (as recorded by macros in the namespace
+# BISON-NAMESPACE).
+#
+# USER-LIST must expand to a list specifying all grammar occurrences of all
+# names of type WHAT. Each item in the list must be a triplet specifying one
+# occurrence: name, start boundary, and end boundary. Empty string names are
+# fine. An empty list is fine.
+#
+# For example, to define b4_foo_user_names to be used for USER-LIST with three
+# name occurrences and with correct quoting:
+#
+# m4_define([b4_foo_user_names],
+# [[[[[[bar]], [[parser.y:1.7]], [[parser.y:1.16]]]],
+# [[[[bar]], [[parser.y:5.7]], [[parser.y:5.16]]]],
+# [[[[baz]], [[parser.y:8.7]], [[parser.y:8.16]]]]]])
+#
+# The macro BISON-NAMESPACE(bar) must be defined iff the name bar of type WHAT
+# is used by Bison (in the front-end or in the skeleton). Empty string names
+# are fine, but it would be ugly for Bison to actually use one.
+#
+# For example, to use b4_foo_bison_names for BISON-NAMESPACE and define that
+# the names bar and baz are used by Bison:
+#
+# m4_define([b4_foo_bison_names(bar)])
+# m4_define([b4_foo_bison_names(baz)])
+#
+# To invoke b4_check_user_names with TYPE foo, with USER-LIST
+# b4_foo_user_names, with BISON-NAMESPACE b4_foo_bison_names, and with correct
+# quoting:
+#
+# b4_check_user_names([[foo]], [b4_foo_user_names],
+# [[b4_foo_bison_names]])
+m4_define([b4_check_user_names],
+[m4_foreach([b4_occurrence], $2,
+[m4_pushdef([b4_occurrence], b4_occurrence)dnl
+m4_pushdef([b4_user_name], m4_car(b4_occurrence))dnl
+m4_pushdef([b4_start], m4_car(m4_shift(b4_occurrence)))dnl
+m4_pushdef([b4_end], m4_shift(m4_shift(b4_occurrence)))dnl
+m4_ifndef($3[(]m4_quote(b4_user_name)[)],
+ [b4_warn_at([b4_start], [b4_end],
+ [[%s `%s' is not used]],
+ [$1], [b4_user_name])])[]dnl
+m4_popdef([b4_occurrence])dnl
+m4_popdef([b4_user_name])dnl
+m4_popdef([b4_start])dnl
+m4_popdef([b4_end])dnl
+])])
+
+# b4_percent_define_get(VARIABLE)
+# -------------------------------
+# Mimic muscle_percent_define_get in ../src/muscle_tab.h exactly. That is, if
+# the %define variable VARIABLE is defined, emit its value. Also, record
+# Bison's usage of VARIABLE by defining
+# b4_percent_define_bison_variables(VARIABLE).
+#
+# For example:
+#
+# b4_percent_define_get([[foo]])
+m4_define([b4_percent_define_get],
+[m4_define([b4_percent_define_bison_variables(]$1[)])dnl
+m4_ifdef([b4_percent_define(]$1[)], [m4_indir([b4_percent_define(]$1[)])])])
+
+# b4_percent_define_get_loc(VARIABLE)
+# -----------------------------------
+# Mimic muscle_percent_define_get_loc in ../src/muscle_tab.h exactly. That is,
+# if the %define variable VARIABLE is undefined, complain fatally since that's
+# a Bison or skeleton error. Otherwise, return its definition location in a
+# form approriate for the first two arguments of b4_warn_at, b4_complain_at, or
+# b4_fatal_at. Don't record this as a Bison usage of VARIABLE as there's no
+# reason to suspect that the user-supplied value has yet influenced the output.
+#
+# For example:
+#
+# b4_complain_at(b4_percent_define_get_loc([[foo]]), [[invalid foo]])
+m4_define([b4_percent_define_get_loc],
+[m4_ifdef([b4_percent_define_loc(]$1[)],
+ [m4_pushdef([b4_loc], m4_indir([b4_percent_define_loc(]$1[)]))dnl
+b4_loc[]dnl
+m4_popdef([b4_loc])],
+ [b4_fatal([[undefined %%define variable `%s' passed to b4_percent_define_get_loc]], [$1])])])
+
+# b4_percent_define_get_syncline(VARIABLE)
+# ----------------------------------------
+# Mimic muscle_percent_define_get_syncline in ../src/muscle_tab.h exactly.
+# That is, if the %define variable VARIABLE is undefined, complain fatally
+# since that's a Bison or skeleton error. Otherwise, return its definition
+# location as a b4_syncline invocation. Don't record this as a Bison usage of
+# VARIABLE as there's no reason to suspect that the user-supplied value has yet
+# influenced the output.
+#
+# For example:
+#
+# b4_percent_define_get_syncline([[foo]])
+m4_define([b4_percent_define_get_syncline],
+[m4_ifdef([b4_percent_define_syncline(]$1[)],
+ [m4_indir([b4_percent_define_syncline(]$1[)])],
+ [b4_fatal([[undefined %%define variable `%s' passed to b4_percent_define_get_syncline]], [$1])])])
+
+# b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE])
+# ------------------------------------------------------
+# Mimic muscle_percent_define_ifdef in ../src/muscle_tab.h exactly. That is,
+# if the %define variable VARIABLE is defined, expand IF-TRUE, else expand
+# IF-FALSE. Also, record Bison's usage of VARIABLE by defining
+# b4_percent_define_bison_variables(VARIABLE).
+#
+# For example:
+#
+# b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]])
+m4_define([b4_percent_define_ifdef],
+[m4_ifdef([b4_percent_define(]$1[)],
+ [m4_define([b4_percent_define_bison_variables(]$1[)])$2],
+ [$3])])
+
+# b4_percent_define_flag_if(VARIABLE, IF-TRUE, [IF-FALSE])
+# --------------------------------------------------------
+# Mimic muscle_percent_define_flag_if in ../src/muscle_tab.h exactly. That is,
+# if the %define variable VARIABLE is defined to "" or "true", expand IF-TRUE.
+# If it is defined to "false", expand IF-FALSE. Complain if it is undefined
+# (a Bison or skeleton error since the default value should have been set
+# already) or defined to any other value (possibly a user error). Also, record
+# Bison's usage of VARIABLE by defining
+# b4_percent_define_bison_variables(VARIABLE).
+#
+# For example:
+#
+# b4_percent_define_flag_if([[foo]], [[it's true]], [[it's false]])
+m4_define([b4_percent_define_flag_if],
+[b4_percent_define_ifdef([$1],
+ [m4_case(b4_percent_define_get([$1]),
+ [], [$2], [true], [$2], [false], [$3],
+ [m4_expand_once([b4_complain_at(b4_percent_define_get_loc([$1]),
+ [[invalid value for %%define Boolean variable `%s']],
+ [$1])],
+ [[b4_percent_define_flag_if($1)]])])],
+ [b4_fatal([[undefined %%define variable `%s' passed to b4_percent_define_flag_if]], [$1])])])
+
+# b4_percent_define_default(VARIABLE, DEFAULT)
+# --------------------------------------------
+# Mimic muscle_percent_define_default in ../src/muscle_tab.h exactly. That is,
+# if the %define variable VARIABLE is undefined, set its value to DEFAULT.
+# Don't record this as a Bison usage of VARIABLE as there's no reason to
+# suspect that the value has yet influenced the output.
+#
+# For example:
+#
+# b4_percent_define_default([[foo]], [[default value]])
+m4_define([b4_percent_define_default],
+[m4_ifndef([b4_percent_define(]$1[)],
+ [m4_define([b4_percent_define(]$1[)], [$2])dnl
+ m4_define([b4_percent_define_loc(]$1[)],
+ [[[[[Bison:b4_percent_define_default]:1.0]], [[[Bison:b4_percent_define_default]:1.0]]]])dnl
+ m4_define([b4_percent_define_syncline(]$1[)],
+ [[]b4_syncline(1, [["[Bison:b4_percent_define_default]"]])[
+]])])])
+
+# b4_percent_define_check_values(VALUES)
+# --------------------------------------
+# Mimic muscle_percent_define_check_values in ../src/muscle_tab.h exactly
+# except that the VALUES structure is more appropriate for M4. That is, VALUES
+# is a list of sublists of strings. For each sublist, the first string is the
+# name of a %define variable, and all remaining strings in that sublist are the
+# valid values for that variable. Complain if such a variable is undefined (a
+# Bison error since the default value should have been set already) or defined
+# to any other value (possibly a user error). Don't record this as a Bison
+# usage of the variable as there's no reason to suspect that the value has yet
+# influenced the output.
+#
+# For example:
+#
+# b4_percent_define_check_values([[[[foo]], [[foo-value1]], [[foo-value2]]]],
+# [[[[bar]], [[bar-value1]]]])
+m4_define([b4_percent_define_check_values],
+[m4_foreach([b4_sublist], m4_quote($@),
+ [_b4_percent_define_check_values(b4_sublist)])])
+
+m4_define([_b4_percent_define_check_values],
+[m4_ifdef([b4_percent_define(]$1[)],
+ [m4_pushdef([b4_good_value], [0])dnl
+ m4_if($#, 1, [],
+ [m4_foreach([b4_value], m4_dquote(m4_shift($@)),
+ [m4_if(m4_indir([b4_percent_define(]$1[)]), b4_value,
+ [m4_define([b4_good_value], [1])])])])dnl
+ m4_if(b4_good_value, [0],
+ [b4_complain_at(b4_percent_define_get_loc([$1]),
+ [[invalid value for %%define variable `%s': `%s']],
+ [$1],
+ m4_dquote(m4_indir([b4_percent_define(]$1[)])))])dnl
+ m4_popdef([b4_good_value])],
+ [b4_fatal([[undefined %%define variable `%s' passed to b4_percent_define_check_values]], [$1])])])
+
+# b4_percent_code_get([QUALIFIER])
+# --------------------------------
+# If any %code blocks for QUALIFIER are defined, emit them beginning with a
+# comment and ending with synclines and a newline. If QUALIFIER is not
+# specified or empty, do this for the unqualified %code blocks. Also, record
+# Bison's usage of QUALIFIER (if specified) by defining
+# b4_percent_code_bison_qualifiers(QUALIFIER).
+#
+# For example, to emit any unqualified %code blocks followed by any %code
+# blocks for the qualifier foo:
+#
+# b4_percent_code_get
+# b4_percent_code_get([[foo]])
+m4_define([b4_percent_code_get],
+[m4_pushdef([b4_macro_name], [[b4_percent_code(]$1[)]])dnl
+m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl
+m4_ifdef(b4_macro_name,
+[b4_comment([m4_if([$#], [0], [[Unqualified %code]],
+ [["%code ]$1["]])[ blocks.]])
+b4_user_code([m4_indir(b4_macro_name)])
+])dnl
+m4_popdef([b4_macro_name])])
+
+# b4_percent_code_ifdef(QUALIFIER, IF-TRUE, [IF-FALSE])
+# -----------------------------------------------------
+# If any %code blocks for QUALIFIER (or unqualified %code blocks if
+# QUALIFIER is empty) are defined, expand IF-TRUE, else expand IF-FALSE.
+# Also, record Bison's usage of QUALIFIER (if specified) by defining
+# b4_percent_code_bison_qualifiers(QUALIFIER).
+m4_define([b4_percent_code_ifdef],
+[m4_ifdef([b4_percent_code(]$1[)],
+ [m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])$2],
+ [$3])])
+
+
+## ----------------------------------------------------------- ##
+## After processing the skeletons, check that all the user's ##
+## %define variables and %code qualifiers were used by Bison. ##
+## ----------------------------------------------------------- ##
+
+m4_define([b4_check_user_names_wrap],
+[m4_ifdef([b4_percent_]$1[_user_]$2[s],
+ [b4_check_user_names([[%]$1 $2],
+ [b4_percent_]$1[_user_]$2[s],
+ [[b4_percent_]$1[_bison_]$2[s]])])])
+
+m4_wrap_lifo([
+b4_check_user_names_wrap([[define]], [[variable]])
+b4_check_user_names_wrap([[code]], [[qualifier]])
+])
diff --git a/tools/mhmake/src/bisondata/c++.m4 b/tools/mhmake/src/bisondata/c++.m4
new file mode 100644
index 000000000..a27064d7b
--- /dev/null
+++ b/tools/mhmake/src/bisondata/c++.m4
@@ -0,0 +1,170 @@
+ -*- Autoconf -*-
+
+# C++ skeleton for Bison
+
+# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation,
+# Inc.
+
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+m4_include(b4_pkgdatadir/[c.m4])
+
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+# Default parser class name.
+b4_percent_define_default([[parser_class_name]], [[parser]])
+b4_percent_define_default([[location_type]], [[location]])
+b4_percent_define_default([[filename_type]], [[std::string]])
+b4_percent_define_default([[namespace]], m4_defn([b4_prefix]))
+b4_percent_define_default([[global_tokens_and_yystype]], [[false]])
+b4_percent_define_default([[define_location_comparison]],
+ [m4_if(b4_percent_define_get([[filename_type]]),
+ [std::string], [[true]], [[false]])])
+
+
+## ----------- ##
+## Namespace. ##
+## ----------- ##
+
+m4_define([b4_namespace_ref], [b4_percent_define_get([[namespace]])])
+
+# Don't permit an empty b4_namespace_ref. Any `::parser::foo' appended to it
+# would compile as an absolute reference with `parser' in the global namespace.
+# b4_namespace_open would open an anonymous namespace and thus establish
+# internal linkage. This would compile. However, it's cryptic, and internal
+# linkage for the parser would be specified in all translation units that
+# include the header, which is always generated. If we ever need to permit
+# internal linkage somehow, surely we can find a cleaner approach.
+m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [],
+[b4_complain_at(b4_percent_define_get_loc([[namespace]]),
+ [[namespace reference is empty]])])
+
+# Instead of assuming the C++ compiler will do it, Bison should reject any
+# invalid b4_namepsace_ref that would be converted to a valid
+# b4_namespace_open. The problem is that Bison doesn't always output
+# b4_namespace_ref to uncommented code but should reserve the ability to do so
+# in future releases without risking breaking any existing user grammars.
+# Specifically, don't allow empty names as b4_namespace_open would just convert
+# those into anonymous namespaces, and that might tempt some users.
+m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*::]), [-1], [],
+[b4_complain_at(b4_percent_define_get_loc([[namespace]]),
+ [[namespace reference has consecutive "::"]])])
+m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [],
+[b4_complain_at(b4_percent_define_get_loc([[namespace]]),
+ [[namespace reference has a trailing "::"]])])
+
+m4_define([b4_namespace_open],
+[b4_user_code([b4_percent_define_get_syncline([[namespace]])
+[namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref),
+ [^\(.\)[ ]*::], [\1])),
+ [::], [ { namespace ])[ {]])])
+
+m4_define([b4_namespace_close],
+[b4_user_code([b4_percent_define_get_syncline([[namespace]])
+m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref),
+ [^\(.\)[ ]*\(::\)?\([^][:]\|:[^][:]\)*],
+ [\1])),
+ [::\([^][:]\|:[^][:]\)*], [} ])[} // ]b4_namespace_ref])])
+
+
+# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
+# -----------------------------------------------------
+# Output the definition of the tokens as enums.
+m4_define([b4_token_enums],
+[/* Tokens. */
+ enum yytokentype {
+m4_map_sep([ b4_token_enum], [,
+],
+ [$@])
+ };
+])
+
+
+## ----------------- ##
+## Semantic Values. ##
+## ----------------- ##
+
+
+# b4_lhs_value([TYPE])
+# --------------------
+# Expansion of $<TYPE>$.
+m4_define([b4_lhs_value],
+[(yyval[]m4_ifval([$1], [.$1]))])
+
+
+# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
+# --------------------------------------
+# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
+# symbols on RHS.
+m4_define([b4_rhs_value],
+[(yysemantic_stack_@{($1) - ($2)@}m4_ifval([$3], [.$3]))])
+
+# b4_lhs_location()
+# -----------------
+# Expansion of @$.
+m4_define([b4_lhs_location],
+[(yyloc)])
+
+
+# b4_rhs_location(RULE-LENGTH, NUM)
+# ---------------------------------
+# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
+# on RHS.
+m4_define([b4_rhs_location],
+[(yylocation_stack_@{($1) - ($2)@})])
+
+
+# b4_parse_param_decl
+# -------------------
+# Extra formal arguments of the constructor.
+# Change the parameter names from "foo" into "foo_yyarg", so that
+# there is no collision bw the user chosen attribute name, and the
+# argument name in the constructor.
+m4_define([b4_parse_param_decl],
+[m4_ifset([b4_parse_param],
+ [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])])
+
+m4_define([b4_parse_param_decl_1],
+[$1_yyarg])
+
+
+
+# b4_parse_param_cons
+# -------------------
+# Extra initialisations of the constructor.
+m4_define([b4_parse_param_cons],
+ [m4_ifset([b4_parse_param],
+ [
+ b4_cc_constructor_calls(b4_parse_param)])])
+m4_define([b4_cc_constructor_calls],
+ [m4_map_sep([b4_cc_constructor_call], [,
+ ], [$@])])
+m4_define([b4_cc_constructor_call],
+ [$2 ($2_yyarg)])
+
+# b4_parse_param_vars
+# -------------------
+# Extra instance variables.
+m4_define([b4_parse_param_vars],
+ [m4_ifset([b4_parse_param],
+ [
+ /* User arguments. */
+b4_cc_var_decls(b4_parse_param)])])
+m4_define([b4_cc_var_decls],
+ [m4_map_sep([b4_cc_var_decl], [
+], [$@])])
+m4_define([b4_cc_var_decl],
+ [ $1;])
diff --git a/tools/mhmake/src/bisondata/c.m4 b/tools/mhmake/src/bisondata/c.m4
new file mode 100644
index 000000000..2b44b7e49
--- /dev/null
+++ b/tools/mhmake/src/bisondata/c.m4
@@ -0,0 +1,477 @@
+ -*- Autoconf -*-
+
+# C M4 Macros for Bison.
+# Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008 Free Software
+# Foundation, Inc.
+
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+## ---------------- ##
+## Identification. ##
+## ---------------- ##
+
+# b4_comment(TEXT)
+# ----------------
+m4_define([b4_comment], [/* m4_bpatsubst([$1], [
+], [
+ ]) */])
+
+# b4_identification
+# -----------------
+# Depends on individual skeletons to define b4_pure_flag, b4_push_flag, or
+# b4_pull_flag if they use the values of the %define variables api.pure or
+# api.push_pull.
+m4_define([b4_identification],
+[[/* Identify Bison output. */
+#define YYBISON 1
+
+/* Bison version. */
+#define YYBISON_VERSION "]b4_version["
+
+/* Skeleton name. */
+#define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[
+
+/* Pure parsers. */
+#define YYPURE ]b4_pure_flag])[]m4_ifdef([b4_push_flag], [[
+
+/* Push parsers. */
+#define YYPUSH ]b4_push_flag])[]m4_ifdef([b4_pull_flag], [[
+
+/* Pull parsers. */
+#define YYPULL ]b4_pull_flag])[
+
+/* Using locations. */
+#define YYLSP_NEEDED ]b4_locations_flag[
+]])
+
+
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+# If the %union is not named, its name is YYSTYPE.
+m4_define_default([b4_union_name], [YYSTYPE])
+
+# If the %name-prefix is not given, it is yy.
+m4_define_default([b4_prefix], [yy])
+
+## ------------------------ ##
+## Pure/impure interfaces. ##
+## ------------------------ ##
+
+# b4_user_args
+# ------------
+m4_define([b4_user_args],
+[m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])])
+
+
+# b4_parse_param
+# --------------
+# If defined, b4_parse_param arrives double quoted, but below we prefer
+# it to be single quoted.
+m4_define([b4_parse_param],
+b4_parse_param)
+
+
+# b4_parse_param_for(DECL, FORMAL, BODY)
+# ---------------------------------------
+# Iterate over the user parameters, binding the declaration to DECL,
+# the formal name to FORMAL, and evaluating the BODY.
+m4_define([b4_parse_param_for],
+[m4_foreach([$1_$2], m4_defn([b4_parse_param]),
+[m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl
+m4_pushdef([$2], m4_shift($1_$2))dnl
+$3[]dnl
+m4_popdef([$2])dnl
+m4_popdef([$1])dnl
+])])
+
+# b4_parse_param_use
+# ------------------
+# `YYUSE' all the parse-params.
+m4_define([b4_parse_param_use],
+[b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal);
+])dnl
+])
+
+
+## ------------ ##
+## Data Types. ##
+## ------------ ##
+
+# b4_int_type(MIN, MAX)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# MIN to MAX (included).
+m4_define([b4_int_type],
+[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
+ b4_ints_in($@, [-128], [127]), [1], [signed char],
+
+ b4_ints_in($@, [0], [65535]), [1], [unsigned short int],
+ b4_ints_in($@, [-32768], [32767]), [1], [short int],
+
+ m4_eval([0 <= $1]), [1], [unsigned int],
+
+ [int])])
+
+
+# b4_int_type_for(NAME)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# `NAME_min' to `NAME_max' (included).
+m4_define([b4_int_type_for],
+[b4_int_type($1_min, $1_max)])
+
+
+
+## ---------##
+## Values. ##
+## ---------##
+
+# b4_null
+---------
+# Return a null pointer constant. NULL infringes on the user name
+# space in C, so use 0 rather than NULL.
+m4_define([b4_null], [0])
+
+
+
+
+## ------------------------- ##
+## Assigning token numbers. ##
+## ------------------------- ##
+
+# b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
+# -----------------------------------------
+# Output the definition of this token as #define.
+m4_define([b4_token_define],
+[#define $1 $2
+])
+
+
+# b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
+# -------------------------------------------------------
+# Output the definition of the tokens (if there are) as #defines.
+m4_define([b4_token_defines],
+[m4_if([$#$1], [1], [],
+[/* Tokens. */
+m4_map([b4_token_define], [$@])])
+])
+
+
+# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
+# ---------------------------------------
+# Output the definition of this token as an enum.
+m4_define([b4_token_enum],
+[$1 = $2])
+
+
+# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
+# -----------------------------------------------------
+# Output the definition of the tokens (if there are) as enums.
+m4_define([b4_token_enums],
+[m4_if([$#$1], [1], [],
+[/* Tokens. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum yytokentype {
+m4_map_sep([ b4_token_enum], [,
+],
+ [$@])
+ };
+#endif
+])])
+
+
+# b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
+# -------------------------------------------------------------
+# Output the definition of the tokens (if there are any) as enums and, if POSIX
+# Yacc is enabled, as #defines.
+m4_define([b4_token_enums_defines],
+[b4_token_enums($@)b4_yacc_if([b4_token_defines($@)], [])
+])
+
+
+
+## --------------------------------------------- ##
+## Defining C functions in both K&R and ANSI-C. ##
+## --------------------------------------------- ##
+
+
+# b4_modern_c
+# -----------
+# A predicate useful in #if to determine whether C is ancient or modern.
+#
+# If __STDC__ is defined, the compiler is modern. IBM xlc 7.0 when run
+# as 'cc' doesn't define __STDC__ (or __STDC_VERSION__) for pedantic
+# reasons, but it defines __C99__FUNC__ so check that as well.
+# Microsoft C normally doesn't define these macros, but it defines _MSC_VER.
+# Consider a C++ compiler to be modern if it defines __cplusplus.
+#
+m4_define([b4_c_modern],
+ [[(defined __STDC__ || defined __C99__FUNC__ \
+ || defined __cplusplus || defined _MSC_VER)]])
+
+# b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# ----------------------------------------------------------
+# Declare the function NAME.
+m4_define([b4_c_function_def],
+[#if b4_c_modern
+b4_c_ansi_function_def($@)
+#else
+$2
+$1 (b4_c_knr_formal_names(m4_shift2($@)))
+b4_c_knr_formal_decls(m4_shift2($@))
+#endif[]dnl
+])
+
+
+# b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# ---------------------------------------------------------------
+# Declare the function NAME in ANSI.
+m4_define([b4_c_ansi_function_def],
+[$2
+$1 (b4_c_ansi_formals(m4_shift2($@)))[]dnl
+])
+
+
+# b4_c_ansi_formals([DECL1, NAME1], ...)
+# --------------------------------------
+# Output the arguments ANSI-C definition.
+m4_define([b4_c_ansi_formals],
+[m4_if([$#], [0], [void],
+ [$#$1], [1], [void],
+ [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
+
+m4_define([b4_c_ansi_formal],
+[$1])
+
+
+# b4_c_knr_formal_names([DECL1, NAME1], ...)
+# ------------------------------------------
+# Output the argument names.
+m4_define([b4_c_knr_formal_names],
+[m4_map_sep([b4_c_knr_formal_name], [, ], [$@])])
+
+m4_define([b4_c_knr_formal_name],
+[$2])
+
+
+# b4_c_knr_formal_decls([DECL1, NAME1], ...)
+# ------------------------------------------
+# Output the K&R argument declarations.
+m4_define([b4_c_knr_formal_decls],
+[m4_map_sep([b4_c_knr_formal_decl],
+ [
+],
+ [$@])])
+
+m4_define([b4_c_knr_formal_decl],
+[ $1;])
+
+
+
+## ------------------------------------------------------------ ##
+## Declaring (prototyping) C functions in both K&R and ANSI-C. ##
+## ------------------------------------------------------------ ##
+
+
+# b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# -----------------------------------------------------------
+# Declare the function NAME.
+m4_define([b4_c_function_decl],
+[#if defined __STDC__ || defined __cplusplus
+b4_c_ansi_function_decl($@)
+#else
+$2 $1 ();
+#endif[]dnl
+])
+
+
+# b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# ----------------------------------------------------------------
+# Declare the function NAME.
+m4_define([b4_c_ansi_function_decl],
+[$2 $1 (b4_c_ansi_formals(m4_shift2($@)));[]dnl
+])
+
+
+
+
+## --------------------- ##
+## Calling C functions. ##
+## --------------------- ##
+
+
+# b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# -----------------------------------------------------------
+# Call the function NAME with arguments NAME1, NAME2 etc.
+m4_define([b4_c_function_call],
+[$1 (b4_c_args(m4_shift2($@)))[]dnl
+])
+
+
+# b4_c_args([DECL1, NAME1], ...)
+# ------------------------------
+# Output the arguments NAME1, NAME2...
+m4_define([b4_c_args],
+[m4_map_sep([b4_c_arg], [, ], [$@])])
+
+m4_define([b4_c_arg],
+[$2])
+
+
+## ----------- ##
+## Synclines. ##
+## ----------- ##
+
+# b4_sync_start(LINE, FILE)
+# -----------------------
+m4_define([b4_sync_start], [[#]line $1 $2])
+
+
+## -------------- ##
+## User actions. ##
+## -------------- ##
+
+# b4_case(LABEL, STATEMENTS)
+# --------------------------
+m4_define([b4_case],
+[ case $1:
+$2
+ break;])
+
+# b4_symbol_actions(FILENAME, LINENO,
+# SYMBOL-TAG, SYMBOL-NUM,
+# SYMBOL-ACTION, SYMBOL-TYPENAME)
+# -------------------------------------------------
+m4_define([b4_symbol_actions],
+[m4_pushdef([b4_dollar_dollar],
+ [m4_ifval([$6], [(yyvaluep->$6)], [(*yyvaluep)])])dnl
+m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl
+ case $4: /* $3 */
+b4_syncline([$2], [$1])
+ $5;
+b4_syncline([@oline@], [@ofile@])
+ break;
+m4_popdef([b4_at_dollar])dnl
+m4_popdef([b4_dollar_dollar])dnl
+])
+
+
+# b4_yydestruct_generate(FUNCTION-DECLARATOR)
+# -------------------------------------------
+# Generate the "yydestruct" function, which declaration is issued using
+# FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
+# or "b4_c_function_def" for K&R.
+m4_define_default([b4_yydestruct_generate],
+[[/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+/*ARGSUSED*/
+]$1([yydestruct],
+ [static void],
+ [[const char *yymsg], [yymsg]],
+ [[int yytype], [yytype]],
+ [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
+b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
+m4_ifset([b4_parse_param], [, b4_parse_param]))[
+{
+ YYUSE (yyvaluep);
+]b4_locations_if([ YYUSE (yylocationp);
+])dnl
+b4_parse_param_use[]dnl
+[
+ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+ switch (yytype)
+ {
+]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
+ default:
+ break;
+ }
+}]dnl
+])
+
+
+# b4_yy_symbol_print_generate(FUNCTION-DECLARATOR)
+# ------------------------------------------------
+# Generate the "yy_symbol_print" function, which declaration is issued using
+# FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
+# or "b4_c_function_def" for K&R.
+m4_define_default([b4_yy_symbol_print_generate],
+[[
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+/*ARGSUSED*/
+]$1([yy_symbol_value_print],
+ [static void],
+ [[FILE *yyoutput], [yyoutput]],
+ [[int yytype], [yytype]],
+ [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
+b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
+m4_ifset([b4_parse_param], [, b4_parse_param]))[
+{
+ if (!yyvaluep)
+ return;
+]b4_locations_if([ YYUSE (yylocationp);
+])dnl
+b4_parse_param_use[]dnl
+[# ifdef YYPRINT
+ if (yytype < YYNTOKENS)
+ YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
+# else
+ YYUSE (yyoutput);
+# endif
+ switch (yytype)
+ {
+]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
+[ default:
+ break;
+ }
+}
+
+
+/*--------------------------------.
+| Print this symbol on YYOUTPUT. |
+`--------------------------------*/
+
+]$1([yy_symbol_print],
+ [static void],
+ [[FILE *yyoutput], [yyoutput]],
+ [[int yytype], [yytype]],
+ [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
+b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
+m4_ifset([b4_parse_param], [, b4_parse_param]))[
+{
+ if (yytype < YYNTOKENS)
+ YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
+ else
+ YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
+
+]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp);
+ YYFPRINTF (yyoutput, ": ");
+])dnl
+[ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl
+b4_locations_if([, yylocationp])[]b4_user_args[);
+ YYFPRINTF (yyoutput, ")");
+}]dnl
+])
diff --git a/tools/mhmake/src/bisondata/lalr1.cc b/tools/mhmake/src/bisondata/lalr1.cc
new file mode 100644
index 000000000..25dd01938
--- /dev/null
+++ b/tools/mhmake/src/bisondata/lalr1.cc
@@ -0,0 +1,1169 @@
+# C++ skeleton for Bison
+
+# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
+# Free Software Foundation, Inc.
+
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+m4_include(b4_pkgdatadir/[c++.m4])
+
+m4_define([b4_parser_class_name],
+ [b4_percent_define_get([[parser_class_name]])])
+
+m4_define([b4_parser_base_class_name],
+ [b4_percent_define_get([[parser_base_class_name]])])
+
+m4_define([b4_parser_class_constructor_init],
+ [b4_percent_define_get([[parser_class_constructor_init]])])
+
+m4_define([b4_parser_class_constructor_param],
+ [b4_percent_define_get([[parser_class_constructor_param]])])
+
+# The header is mandatory.
+b4_defines_if([],
+ [b4_fatal([b4_skeleton[: using %%defines is mandatory]])])
+
+# Backward compatibility.
+m4_define([b4_location_constructors])
+m4_include(b4_pkgdatadir/[location.cc])
+
+# We do want M4 expansion after # for CPP macros.
+m4_changecom()
+m4_divert_push(0)dnl
+b4_defines_if(
+[@output(b4_spec_defines_file@)
+b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++],
+ [2002, 2003, 2004, 2005, 2006, 2007, 2008])
+dnl FIXME: This is wrong, we want computed header guards.
+[
+/* C++ LALR(1) parser skeleton written by Akim Demaille. */
+
+#ifndef PARSER_HEADER_H
+# define PARSER_HEADER_H
+
+]b4_percent_code_get([[requires]])[
+
+#include <string>
+#include <iostream>
+#include "stack.hh"
+
+]b4_namespace_open[
+ class position;
+ class location;
+]b4_namespace_close[
+
+#include "location.hh"
+
+/* Enabling traces. */
+#ifndef YYDEBUG
+# define YYDEBUG ]b4_debug_flag[
+#endif
+
+/* Enabling verbose error messages. */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE ]b4_error_verbose_flag[
+#endif
+
+/* Enabling the token table. */
+#ifndef YYTOKEN_TABLE
+# define YYTOKEN_TABLE ]b4_token_table[
+#endif
+
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+#ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+do { \
+ if (N) \
+ { \
+ (Current).begin = (Rhs)[1].begin; \
+ (Current).end = (Rhs)[N].end; \
+ } \
+ else \
+ { \
+ (Current).begin = (Current).end = (Rhs)[0].end; \
+ } \
+} while (false)
+#endif
+
+]b4_namespace_open[
+
+ /// A Bison parser.
+ class ]b4_parser_class_name[ : public ]b4_parser_base_class_name[
+ {
+ public:
+ /// Symbol semantic values.
+#ifndef YYSTYPE
+]m4_ifdef([b4_stype],
+[ union semantic_type
+ {
+b4_user_stype
+ };],
+[m4_if(b4_tag_seen_flag, 0,
+[[ typedef int semantic_type;]],
+[[ typedef YYSTYPE semantic_type;]])])[
+#else
+ typedef YYSTYPE semantic_type;
+#endif
+ /// Symbol locations.
+ typedef ]b4_percent_define_get([[location_type]])[ location_type;
+ /// Tokens.
+ struct token
+ {
+ ]b4_token_enums(b4_tokens)[
+ };
+ /// Token type.
+ typedef token::yytokentype token_type;
+
+ /// Build a parser object.
+ ]b4_parser_class_name[ (]b4_parse_param_decl[ ]b4_parser_class_constructor_param[ );
+ virtual ~]b4_parser_class_name[ ();
+
+ /// Parse.
+ /// \returns 0 iff parsing succeeded.
+ virtual int parse ();
+
+#if YYDEBUG
+ /// The current debugging stream.
+ std::ostream& debug_stream () const;
+ /// Set the current debugging stream.
+ void set_debug_stream (std::ostream &);
+
+ /// Type for debugging levels.
+ typedef int debug_level_type;
+ /// The current debugging level.
+ debug_level_type debug_level () const;
+ /// Set the current debugging level.
+ void set_debug_level (debug_level_type l);
+#endif
+
+ private:
+ /// Report a syntax error.
+ /// \param loc where the syntax error is found.
+ /// \param msg a description of the syntax error.
+ virtual void error (const location_type& loc, const std::string& msg);
+
+ /// Generate an error message.
+ /// \param state the state where the error occurred.
+ /// \param tok the lookahead token.
+ virtual std::string yysyntax_error_ (int yystate]dnl
+b4_error_verbose_if([, int tok])[);
+
+#if YYDEBUG
+ /// \brief Report a symbol value on the debug stream.
+ /// \param yytype The token type.
+ /// \param yyvaluep Its semantic value.
+ /// \param yylocationp Its location.
+ virtual void yy_symbol_value_print_ (int yytype,
+ const semantic_type* yyvaluep,
+ const location_type* yylocationp);
+ /// \brief Report a symbol on the debug stream.
+ /// \param yytype The token type.
+ /// \param yyvaluep Its semantic value.
+ /// \param yylocationp Its location.
+ virtual void yy_symbol_print_ (int yytype,
+ const semantic_type* yyvaluep,
+ const location_type* yylocationp);
+#endif
+
+
+ /// State numbers.
+ typedef int state_type;
+ /// State stack type.
+ typedef stack<state_type> state_stack_type;
+ /// Semantic value stack type.
+ typedef stack<semantic_type> semantic_stack_type;
+ /// location stack type.
+ typedef stack<location_type> location_stack_type;
+
+ /// The state stack.
+ state_stack_type yystate_stack_;
+ /// The semantic value stack.
+ semantic_stack_type yysemantic_stack_;
+ /// The location stack.
+ location_stack_type yylocation_stack_;
+
+ /// Internal symbol numbers.
+ typedef ]b4_int_type_for([b4_translate])[ token_number_type;
+ /* Tables. */
+ /// For a state, the index in \a yytable_ of its portion.
+ static const ]b4_int_type_for([b4_pact])[ yypact_[];
+ static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
+
+ /// For a state, default rule to reduce.
+ /// Unless\a yytable_ specifies something else to do.
+ /// Zero means the default is an error.
+ static const ]b4_int_type_for([b4_defact])[ yydefact_[];
+
+ static const ]b4_int_type_for([b4_pgoto])[ yypgoto_[];
+ static const ]b4_int_type_for([b4_defgoto])[ yydefgoto_[];
+
+ /// What to do in a state.
+ /// \a yytable_[yypact_[s]]: what to do in state \a s.
+ /// - if positive, shift that token.
+ /// - if negative, reduce the rule which number is the opposite.
+ /// - if zero, do what YYDEFACT says.
+ static const ]b4_int_type_for([b4_table])[ yytable_[];
+ static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
+
+ static const ]b4_int_type_for([b4_check])[ yycheck_[];
+
+ /// For a state, its accessing symbol.
+ static const ]b4_int_type_for([b4_stos])[ yystos_[];
+
+ /// For a rule, its LHS.
+ static const ]b4_int_type_for([b4_r1])[ yyr1_[];
+ /// For a rule, its RHS length.
+ static const ]b4_int_type_for([b4_r2])[ yyr2_[];
+
+#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+ /// For a symbol, its name in clear.
+ static const char* const yytname_[];
+#endif
+
+#if YYERROR_VERBOSE
+ /// Convert the symbol name \a n to a form suitable for a diagnostic.
+ virtual std::string yytnamerr_ (const char *n);
+#endif
+
+#if YYDEBUG
+ /// A type to store symbol numbers and -1.
+ typedef ]b4_int_type_for([b4_rhs])[ rhs_number_type;
+ /// A `-1'-separated list of the rules' RHS.
+ static const rhs_number_type yyrhs_[];
+ /// For each rule, the index of the first RHS symbol in \a yyrhs_.
+ static const ]b4_int_type_for([b4_prhs])[ yyprhs_[];
+ /// For each rule, its source line number.
+ static const ]b4_int_type_for([b4_rline])[ yyrline_[];
+ /// For each scanner token number, its symbol number.
+ static const ]b4_int_type_for([b4_toknum])[ yytoken_number_[];
+ /// Report on the debug stream that the rule \a r is going to be reduced.
+ virtual void yy_reduce_print_ (int r);
+ /// Print the state stack on the debug stream.
+ virtual void yystack_print_ ();
+
+ /* Debugging. */
+ int yydebug_;
+ std::ostream* yycdebug_;
+#endif
+
+ /// Convert a scanner token number \a t to a symbol number.
+ token_number_type yytranslate_ (int t);
+
+ /// \brief Reclaim the memory associated to a symbol.
+ /// \param yymsg Why this token is reclaimed.
+ /// \param yytype The symbol type.
+ /// \param yyvaluep Its semantic value.
+ /// \param yylocationp Its location.
+ inline void yydestruct_ (const char* yymsg,
+ int yytype,
+ semantic_type* yyvaluep,
+ location_type* yylocationp);
+
+ /// Pop \a n symbols the three stacks.
+ inline void yypop_ (unsigned int n = 1);
+
+ /* Constants. */
+ static const int yyeof_;
+ /* LAST_ -- Last index in TABLE_. */
+ static const int yylast_;
+ static const int yynnts_;
+ static const int yyempty_;
+ static const int yyfinal_;
+ static const int yyterror_;
+ static const int yyerrcode_;
+ static const int yyntokens_;
+ static const unsigned int yyuser_token_number_max_;
+ static const token_number_type yyundef_token_;
+]b4_parse_param_vars[
+ };
+]b4_namespace_close[
+
+]b4_percent_define_flag_if([[global_tokens_and_yystype]],
+[b4_token_defines(b4_tokens)
+
+#ifndef YYSTYPE
+ /* Redirection for backward compatibility. */
+# define YYSTYPE b4_namespace_ref::b4_parser_class_name::semantic_type
+#endif
+])
+b4_percent_code_get([[provides]])[]dnl
+
+[#endif /* ! defined PARSER_HEADER_H */]
+])dnl
+@output(b4_parser_file_name@)
+b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
+ [2002, 2003, 2004, 2005, 2006, 2007, 2008])
+b4_percent_code_get([[top]])[]dnl
+m4_if(b4_prefix, [yy], [],
+[
+// Take the name prefix into account.
+#define yylex b4_prefix[]lex])[
+
+/* First part of user declarations. */
+]b4_user_pre_prologue
+
+b4_defines_if([[
+#include "@basename(]b4_spec_defines_file[@)"]])[
+
+/* User implementation prologue. */
+]b4_user_post_prologue
+b4_percent_code_get[]dnl
+
+[#ifndef YY_
+# if YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
+# define YY_(msgid) dgettext ("bison-runtime", msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(msgid) msgid
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#define YYUSE(e) ((void) (e))
+
+/* Enable debugging if requested. */
+#if YYDEBUG
+
+/* A pseudo ostream that takes yydebug_ into account. */
+# define YYCDEBUG if (yydebug_) (*yycdebug_)
+
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug_) \
+ { \
+ *yycdebug_ << Title << ' '; \
+ yy_symbol_print_ ((Type), (Value), (Location)); \
+ *yycdebug_ << std::endl; \
+ } \
+} while (false)
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug_) \
+ yy_reduce_print_ (Rule); \
+} while (false)
+
+# define YY_STACK_PRINT() \
+do { \
+ if (yydebug_) \
+ yystack_print_ (); \
+} while (false)
+
+#else /* !YYDEBUG */
+
+# define YYCDEBUG if (false) std::cerr
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
+# define YY_REDUCE_PRINT(Rule)
+# define YY_STACK_PRINT()
+
+#endif /* !YYDEBUG */
+
+#define yyerrok (yyerrstatus_ = 0)
+#define yyclearin (yychar = yyempty_)
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+#define YYRECOVERING() (!!yyerrstatus_)
+
+]b4_namespace_open[
+#if YYERROR_VERBOSE
+
+ /* Return YYSTR after stripping away unnecessary quotes and
+ backslashes, so that it's suitable for yyerror. The heuristic is
+ that double-quoting is unnecessary unless the string contains an
+ apostrophe, a comma, or backslash (other than backslash-backslash).
+ YYSTR is taken from yytname. */
+ std::string
+ ]b4_parser_class_name[::yytnamerr_ (const char *yystr)
+ {
+ if (*yystr == '"')
+ {
+ std::string yyr = "";
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ /* Fall through. */
+ default:
+ yyr += *yyp;
+ break;
+
+ case '"':
+ return yyr;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ return yystr;
+ }
+
+#endif
+
+ /// Build a parser object.
+ ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[ ]b4_parser_class_constructor_param[) ]b4_parser_class_constructor_init[ ]m4_ifset([b4_parse_param], [
+ :])[
+
+#if YYDEBUG
+ ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false),
+ yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[
+#endif]b4_parse_param_cons[
+ {
+ }
+
+ ]b4_parser_class_name::~b4_parser_class_name[ ()
+ {
+ }
+
+#if YYDEBUG
+ /*--------------------------------.
+ | Print this symbol on YYOUTPUT. |
+ `--------------------------------*/
+
+ inline void
+ ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype,
+ const semantic_type* yyvaluep, const location_type* yylocationp)
+ {
+ YYUSE (yylocationp);
+ YYUSE (yyvaluep);
+ switch (yytype)
+ {
+ ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
+[ default:
+ break;
+ }
+ }
+
+
+ void
+ ]b4_parser_class_name[::yy_symbol_print_ (int yytype,
+ const semantic_type* yyvaluep, const location_type* yylocationp)
+ {
+ *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
+ << ' ' << yytname_[yytype] << " ("
+ << *yylocationp << ": ";
+ yy_symbol_value_print_ (yytype, yyvaluep, yylocationp);
+ *yycdebug_ << ')';
+ }
+#endif
+
+ void
+ ]b4_parser_class_name[::yydestruct_ (const char* yymsg,
+ int yytype, semantic_type* yyvaluep, location_type* yylocationp)
+ {
+ YYUSE (yylocationp);
+ YYUSE (yymsg);
+ YYUSE (yyvaluep);
+
+ YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
+
+]m4_ifset([b4_symbol_actions], [ ], [
+ switch (yytype)
+ {
+ ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
+ default:
+ break;
+ }
+ ])[
+ }
+
+ void
+ ]b4_parser_class_name[::yypop_ (unsigned int n)
+ {
+ yystate_stack_.pop (n);
+ yysemantic_stack_.pop (n);
+ yylocation_stack_.pop (n);
+ }
+
+#if YYDEBUG
+ std::ostream&
+ ]b4_parser_class_name[::debug_stream () const
+ {
+ return *yycdebug_;
+ }
+
+ void
+ ]b4_parser_class_name[::set_debug_stream (std::ostream& o)
+ {
+ yycdebug_ = &o;
+ }
+
+
+ ]b4_parser_class_name[::debug_level_type
+ ]b4_parser_class_name[::debug_level () const
+ {
+ return yydebug_;
+ }
+
+ void
+ ]b4_parser_class_name[::set_debug_level (debug_level_type l)
+ {
+ yydebug_ = l;
+ }
+#endif
+
+ int
+ ]b4_parser_class_name[::parse ()
+ {
+ /// Lookahead and lookahead in internal form.
+ int yychar = yyempty_;
+ int yytoken = 0;
+
+ /* State. */
+ int yyn;
+ int yylen = 0;
+ int yystate = 0;
+
+ /* Error handling. */
+ int yynerrs_ = 0;
+ int yyerrstatus_ = 0;
+
+ /// Semantic value of the lookahead.
+ semantic_type yylval;
+ /// Location of the lookahead.
+ location_type yylloc;
+ /// The locations where the error started and ended.
+ location_type yyerror_range[2];
+
+ /// $$.
+ semantic_type yyval;
+ /// @@$.
+ location_type yyloc;
+
+ int yyresult;
+
+ YYCDEBUG << "Starting parse" << std::endl;
+
+]m4_ifdef([b4_initial_action], [
+m4_pushdef([b4_at_dollar], [yylloc])dnl
+m4_pushdef([b4_dollar_dollar], [yylval])dnl
+ /* User initialization code. */
+ b4_user_initial_action
+m4_popdef([b4_dollar_dollar])dnl
+m4_popdef([b4_at_dollar])])dnl
+
+ [ /* Initialize the stacks. The initial state will be pushed in
+ yynewstate, since the latter expects the semantical and the
+ location values to have been already stored, initialize these
+ stacks with a primary value. */
+ yystate_stack_ = state_stack_type (0);
+ yysemantic_stack_ = semantic_stack_type (0);
+ yylocation_stack_ = location_stack_type (0);
+ yysemantic_stack_.push (yylval);
+ yylocation_stack_.push (yylloc);
+
+ /* New state. */
+ yynewstate:
+ yystate_stack_.push (yystate);
+ YYCDEBUG << "Entering state " << yystate << std::endl;
+
+ /* Accept? */
+ if (yystate == yyfinal_)
+ goto yyacceptlab;
+
+ goto yybackup;
+
+ /* Backup. */
+ yybackup:
+
+ /* Try to take a decision without lookahead. */
+ yyn = yypact_[yystate];
+ if (yyn == yypact_ninf_)
+ goto yydefault;
+
+ /* Read a lookahead token. */
+ if (yychar == yyempty_)
+ {
+ YYCDEBUG << "Reading a token: ";
+ yychar = ]b4_c_function_call([yylex], [int],
+ [[YYSTYPE*], [&yylval]][]dnl
+b4_locations_if([, [[location*], [&yylloc]]])dnl
+m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
+ }
+
+
+ /* Convert token to internal form. */
+ if (yychar <= yyeof_)
+ {
+ yychar = yytoken = yyeof_;
+ YYCDEBUG << "Now at end of input." << std::endl;
+ }
+ else
+ {
+ yytoken = yytranslate_ (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
+ goto yydefault;
+
+ /* Reduce or error. */
+ yyn = yytable_[yyn];
+ if (yyn <= 0)
+ {
+ if (yyn == 0 || yyn == yytable_ninf_)
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ /* Shift the lookahead token. */
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+
+ /* Discard the token being shifted. */
+ yychar = yyempty_;
+
+ yysemantic_stack_.push (yylval);
+ yylocation_stack_.push (yylloc);
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus_)
+ --yyerrstatus_;
+
+ yystate = yyn;
+ goto yynewstate;
+
+ /*-----------------------------------------------------------.
+ | yydefault -- do the default action for the current state. |
+ `-----------------------------------------------------------*/
+ yydefault:
+ yyn = yydefact_[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+ /*-----------------------------.
+ | yyreduce -- Do a reduction. |
+ `-----------------------------*/
+ yyreduce:
+ yylen = yyr2_[yyn];
+ /* If YYLEN is nonzero, implement the default value of the action:
+ `$$ = $1'. Otherwise, use the top of the stack.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. */
+ if (yylen)
+ yyval = yysemantic_stack_[yylen - 1];
+ else
+ yyval = yysemantic_stack_[0];
+
+ {
+ slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
+ YYLLOC_DEFAULT (yyloc, slice, yylen);
+ }
+ YY_REDUCE_PRINT (yyn);
+ switch (yyn)
+ {
+ ]b4_user_actions[
+ default:
+ break;
+ }
+ YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
+
+ yypop_ (yylen);
+ yylen = 0;
+ YY_STACK_PRINT ();
+
+ yysemantic_stack_.push (yyval);
+ yylocation_stack_.push (yyloc);
+
+ /* Shift the result of the reduction. */
+ yyn = yyr1_[yyn];
+ yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
+ if (0 <= yystate && yystate <= yylast_
+ && yycheck_[yystate] == yystate_stack_[0])
+ yystate = yytable_[yystate];
+ else
+ yystate = yydefgoto_[yyn - yyntokens_];
+ goto yynewstate;
+
+ /*------------------------------------.
+ | yyerrlab -- here on detecting error |
+ `------------------------------------*/
+ yyerrlab:
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus_)
+ {
+ ++yynerrs_;
+ error (yylloc, yysyntax_error_ (yystate]dnl
+b4_error_verbose_if([, yytoken])[));
+ }
+
+ yyerror_range[0] = yylloc;
+ if (yyerrstatus_ == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ if (yychar <= yyeof_)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == yyeof_)
+ YYABORT;
+ }
+ else
+ {
+ yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
+ yychar = yyempty_;
+ }
+ }
+
+ /* Else will try to reuse lookahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+ /*---------------------------------------------------.
+ | yyerrorlab -- error raised explicitly by YYERROR. |
+ `---------------------------------------------------*/
+ yyerrorlab:
+
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (false)
+ goto yyerrorlab;
+
+ yyerror_range[0] = yylocation_stack_[yylen - 1];
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYERROR. */
+ yypop_ (yylen);
+ yylen = 0;
+ yystate = yystate_stack_[0];
+ goto yyerrlab1;
+
+ /*-------------------------------------------------------------.
+ | yyerrlab1 -- common code for both syntax error and YYERROR. |
+ `-------------------------------------------------------------*/
+ yyerrlab1:
+ yyerrstatus_ = 3; /* Each real token shifted decrements this. */
+
+ for (;;)
+ {
+ yyn = yypact_[yystate];
+ if (yyn != yypact_ninf_)
+ {
+ yyn += yyterror_;
+ if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
+ {
+ yyn = yytable_[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yystate_stack_.height () == 1)
+ YYABORT;
+
+ yyerror_range[0] = yylocation_stack_[0];
+ yydestruct_ ("Error: popping",
+ yystos_[yystate],
+ &yysemantic_stack_[0], &yylocation_stack_[0]);
+ yypop_ ();
+ yystate = yystate_stack_[0];
+ YY_STACK_PRINT ();
+ }
+
+ yyerror_range[1] = yylloc;
+ // Using YYLLOC is tempting, but would change the location of
+ // the lookahead. YYLOC is available though.
+ YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
+ yysemantic_stack_.push (yylval);
+ yylocation_stack_.push (yyloc);
+
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
+ &yysemantic_stack_[0], &yylocation_stack_[0]);
+
+ yystate = yyn;
+ goto yynewstate;
+
+ /* Accept. */
+ yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+ /* Abort. */
+ yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+ yyreturn:
+ if (yychar != yyempty_)
+ yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
+
+ /* Do not reclaim the symbols of the rule which action triggered
+ this YYABORT or YYACCEPT. */
+ yypop_ (yylen);
+ while (yystate_stack_.height () != 1)
+ {
+ yydestruct_ ("Cleanup: popping",
+ yystos_[yystate_stack_[0]],
+ &yysemantic_stack_[0],
+ &yylocation_stack_[0]);
+ yypop_ ();
+ }
+
+ return yyresult;
+ }
+
+ // Generate an error message.
+ std::string
+ ]b4_parser_class_name[::yysyntax_error_ (int yystate]dnl
+b4_error_verbose_if([, int tok])[)
+ {
+ std::string res;
+ YYUSE (yystate);
+#if YYERROR_VERBOSE
+ int yyn = yypact_[yystate];
+ if (yypact_ninf_ < yyn && yyn <= yylast_)
+ {
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = yylast_ - yyn + 1;
+ int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
+ int count = 0;
+ for (int x = yyxbegin; x < yyxend; ++x)
+ if (yycheck_[x + yyn] == x && x != yyterror_)
+ ++count;
+
+ // FIXME: This method of building the message is not compatible
+ // with internationalization. It should work like yacc.c does it.
+ // That is, first build a string that looks like this:
+ // "syntax error, unexpected %s or %s or %s"
+ // Then, invoke YY_ on this string.
+ // Finally, use the string as a format to output
+ // yytname_[tok], etc.
+ // Until this gets fixed, this message appears in English only.
+ res = "syntax error, unexpected ";
+ res += yytnamerr_ (yytname_[tok]);
+ if (count < 5)
+ {
+ count = 0;
+ for (int x = yyxbegin; x < yyxend; ++x)
+ if (yycheck_[x + yyn] == x && x != yyterror_)
+ {
+ res += (!count++) ? ", expecting " : " or ";
+ res += yytnamerr_ (yytname_[x]);
+ }
+ }
+ }
+ else
+#endif
+ res = YY_("syntax error");
+ return res;
+ }
+
+
+ /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+ const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[;
+ const ]b4_int_type_for([b4_pact])[
+ ]b4_parser_class_name[::yypact_[] =
+ {
+ ]b4_pact[
+ };
+
+ /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
+ doesn't specify something else to do. Zero means the default is an
+ error. */
+ const ]b4_int_type_for([b4_defact])[
+ ]b4_parser_class_name[::yydefact_[] =
+ {
+ ]b4_defact[
+ };
+
+ /* YYPGOTO[NTERM-NUM]. */
+ const ]b4_int_type_for([b4_pgoto])[
+ ]b4_parser_class_name[::yypgoto_[] =
+ {
+ ]b4_pgoto[
+ };
+
+ /* YYDEFGOTO[NTERM-NUM]. */
+ const ]b4_int_type_for([b4_defgoto])[
+ ]b4_parser_class_name[::yydefgoto_[] =
+ {
+ ]b4_defgoto[
+ };
+
+ /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule which
+ number is the opposite. If zero, do what YYDEFACT says. */
+ const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
+ const ]b4_int_type_for([b4_table])[
+ ]b4_parser_class_name[::yytable_[] =
+ {
+ ]b4_table[
+ };
+
+ /* YYCHECK. */
+ const ]b4_int_type_for([b4_check])[
+ ]b4_parser_class_name[::yycheck_[] =
+ {
+ ]b4_check[
+ };
+
+ /* STOS_[STATE-NUM] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+ const ]b4_int_type_for([b4_stos])[
+ ]b4_parser_class_name[::yystos_[] =
+ {
+ ]b4_stos[
+ };
+
+#if YYDEBUG
+ /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
+ to YYLEX-NUM. */
+ const ]b4_int_type_for([b4_toknum])[
+ ]b4_parser_class_name[::yytoken_number_[] =
+ {
+ ]b4_toknum[
+ };
+#endif
+
+ /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
+ const ]b4_int_type_for([b4_r1])[
+ ]b4_parser_class_name[::yyr1_[] =
+ {
+ ]b4_r1[
+ };
+
+ /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
+ const ]b4_int_type_for([b4_r2])[
+ ]b4_parser_class_name[::yyr2_[] =
+ {
+ ]b4_r2[
+ };
+
+#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+ /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at \a yyntokens_, nonterminals. */
+ const char*
+ const ]b4_parser_class_name[::yytname_[] =
+ {
+ ]b4_tname[
+ };
+#endif
+
+#if YYDEBUG
+ /* YYRHS -- A `-1'-separated list of the rules' RHS. */
+ const ]b4_parser_class_name[::rhs_number_type
+ ]b4_parser_class_name[::yyrhs_[] =
+ {
+ ]b4_rhs[
+ };
+
+ /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
+ YYRHS. */
+ const ]b4_int_type_for([b4_prhs])[
+ ]b4_parser_class_name[::yyprhs_[] =
+ {
+ ]b4_prhs[
+ };
+
+ /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
+ const ]b4_int_type_for([b4_rline])[
+ ]b4_parser_class_name[::yyrline_[] =
+ {
+ ]b4_rline[
+ };
+
+ // Print the state stack on the debug stream.
+ void
+ ]b4_parser_class_name[::yystack_print_ ()
+ {
+ *yycdebug_ << "Stack now";
+ for (state_stack_type::const_iterator i = yystate_stack_.begin ();
+ i != yystate_stack_.end (); ++i)
+ *yycdebug_ << ' ' << *i;
+ *yycdebug_ << std::endl;
+ }
+
+ // Report on the debug stream that the rule \a yyrule is going to be reduced.
+ void
+ ]b4_parser_class_name[::yy_reduce_print_ (int yyrule)
+ {
+ unsigned int yylno = yyrline_[yyrule];
+ int yynrhs = yyr2_[yyrule];
+ /* Print the symbols being reduced, and their result. */
+ *yycdebug_ << "Reducing stack by rule " << yyrule - 1
+ << " (line " << yylno << "):" << std::endl;
+ /* The symbols being reduced. */
+ for (int yyi = 0; yyi < yynrhs; yyi++)
+ YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
+ yyrhs_[yyprhs_[yyrule] + yyi],
+ &]b4_rhs_value(yynrhs, yyi + 1)[,
+ &]b4_rhs_location(yynrhs, yyi + 1)[);
+ }
+#endif // YYDEBUG
+
+ /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
+ ]b4_parser_class_name[::token_number_type
+ ]b4_parser_class_name[::yytranslate_ (int t)
+ {
+ static
+ const token_number_type
+ translate_table[] =
+ {
+ ]b4_translate[
+ };
+ if ((unsigned int) t <= yyuser_token_number_max_)
+ return translate_table[t];
+ else
+ return yyundef_token_;
+ }
+
+ const int ]b4_parser_class_name[::yyeof_ = 0;
+ const int ]b4_parser_class_name[::yylast_ = ]b4_last[;
+ const int ]b4_parser_class_name[::yynnts_ = ]b4_nterms_number[;
+ const int ]b4_parser_class_name[::yyempty_ = -2;
+ const int ]b4_parser_class_name[::yyfinal_ = ]b4_final_state_number[;
+ const int ]b4_parser_class_name[::yyterror_ = 1;
+ const int ]b4_parser_class_name[::yyerrcode_ = 256;
+ const int ]b4_parser_class_name[::yyntokens_ = ]b4_tokens_number[;
+
+ const unsigned int ]b4_parser_class_name[::yyuser_token_number_max_ = ]b4_user_token_number_max[;
+ const ]b4_parser_class_name[::token_number_type ]b4_parser_class_name[::yyundef_token_ = ]b4_undef_token_number[;
+
+]b4_namespace_close[
+
+]b4_epilogue
+dnl
+@output(b4_dir_prefix[]stack.hh@)
+b4_copyright([Stack handling for Bison parsers in C++],
+ [2002, 2003, 2004, 2005, 2006, 2007, 2008])[
+
+#ifndef BISON_STACK_HH
+# define BISON_STACK_HH
+
+#include <deque>
+
+]b4_namespace_open[
+ template <class T, class S = std::deque<T> >
+ class stack
+ {
+ public:
+
+ // Hide our reversed order.
+ typedef typename S::reverse_iterator iterator;
+ typedef typename S::const_reverse_iterator const_iterator;
+
+ stack () : seq_ ()
+ {
+ }
+
+ stack (unsigned int n) : seq_ (n)
+ {
+ }
+
+ inline
+ T&
+ operator [] (unsigned int i)
+ {
+ return seq_[i];
+ }
+
+ inline
+ const T&
+ operator [] (unsigned int i) const
+ {
+ return seq_[i];
+ }
+
+ inline
+ void
+ push (const T& t)
+ {
+ seq_.push_front (t);
+ }
+
+ inline
+ void
+ pop (unsigned int n = 1)
+ {
+ for (; n; --n)
+ seq_.pop_front ();
+ }
+
+ inline
+ unsigned int
+ height () const
+ {
+ return seq_.size ();
+ }
+
+ inline const_iterator begin () const { return seq_.rbegin (); }
+ inline const_iterator end () const { return seq_.rend (); }
+
+ private:
+
+ S seq_;
+ };
+
+ /// Present a slice of the top of a stack.
+ template <class T, class S = stack<T> >
+ class slice
+ {
+ public:
+
+ slice (const S& stack,
+ unsigned int range) : stack_ (stack),
+ range_ (range)
+ {
+ }
+
+ inline
+ const T&
+ operator [] (unsigned int i) const
+ {
+ return stack_[range_ - i];
+ }
+
+ private:
+
+ const S& stack_;
+ unsigned int range_;
+ };
+]b4_namespace_close[
+
+#endif // not BISON_STACK_HH[]dnl
+]
+m4_divert_pop(0)
diff --git a/tools/mhmake/src/bisondata/location.cc b/tools/mhmake/src/bisondata/location.cc
new file mode 100644
index 000000000..e142e5115
--- /dev/null
+++ b/tools/mhmake/src/bisondata/location.cc
@@ -0,0 +1,279 @@
+# C++ skeleton for Bison
+
+# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation,
+# Inc.
+
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# We do want M4 expansion after # for CPP macros.
+m4_changecom()
+m4_divert_push(0)dnl
+@output(b4_dir_prefix[]position.hh@)
+b4_copyright([Positions for Bison parsers in C++],
+ [2002, 2003, 2004, 2005, 2006])[
+
+/**
+ ** \file position.hh
+ ** Define the ]b4_namespace_ref[::position class.
+ */
+
+#ifndef BISON_POSITION_HH
+# define BISON_POSITION_HH
+
+# include <iostream>
+# include <string>
+# include <algorithm>
+
+]b4_namespace_open[
+ /// Abstract a position.
+ class position
+ {
+ public:
+]m4_ifdef([b4_location_constructors], [
+ /// Construct a position.
+ position ()
+ : filename (0), line (]b4_location_initial_line[), column (]b4_location_initial_column[)
+ {
+ }
+
+])[
+ /// Initialization.
+ inline void initialize (]b4_percent_define_get([[filename_type]])[* fn)
+ {
+ filename = fn;
+ line = ]b4_location_initial_line[;
+ column = ]b4_location_initial_column[;
+ }
+
+ /** \name Line and Column related manipulators
+ ** \{ */
+ public:
+ /// (line related) Advance to the COUNT next lines.
+ inline void lines (int count = 1)
+ {
+ column = ]b4_location_initial_column[;
+ line += count;
+ }
+ /// (column related) Advance to the COUNT next columns.
+ inline void columns (int count = 1)
+ {
+ column = std::max (]b4_location_initial_column[u, column + count);
+ }
+ /** \} */
+
+ public:
+ /// File name to which this position refers.
+ ]b4_percent_define_get([[filename_type]])[* filename;
+ /// Current line number.
+ unsigned int line;
+ /// Current column number.
+ unsigned int column;
+ };
+
+ /// Add and assign a position.
+ inline const position&
+ operator+= (position& res, const int width)
+ {
+ res.columns (width);
+ return res;
+ }
+
+ /// Add two position objects.
+ inline const position
+ operator+ (const position& begin, const int width)
+ {
+ position res = begin;
+ return res += width;
+ }
+
+ /// Add and assign a position.
+ inline const position&
+ operator-= (position& res, const int width)
+ {
+ return res += -width;
+ }
+
+ /// Add two position objects.
+ inline const position
+ operator- (const position& begin, const int width)
+ {
+ return begin + -width;
+ }
+]b4_percent_define_flag_if([[define_location_comparison]], [[
+ /// Compare two position objects.
+ inline bool
+ operator== (const position& pos1, const position& pos2)
+ {
+ return
+ (pos1.filename == pos2.filename
+ || pos1.filename && pos2.filename && *pos1.filename == *pos2.filename)
+ && pos1.line == pos2.line && pos1.column == pos2.column;
+ }
+
+ /// Compare two position objects.
+ inline bool
+ operator!= (const position& pos1, const position& pos2)
+ {
+ return !(pos1 == pos2);
+ }
+]])[
+ /** \brief Intercept output stream redirection.
+ ** \param ostr the destination output stream
+ ** \param pos a reference to the position to redirect
+ */
+ inline std::ostream&
+ operator<< (std::ostream& ostr, const position& pos)
+ {
+ if (pos.filename)
+ ostr << *pos.filename << ':';
+ return ostr << pos.line << '.' << pos.column;
+ }
+
+]b4_namespace_close[
+#endif // not BISON_POSITION_HH]
+@output(b4_dir_prefix[]location.hh@)
+b4_copyright([Locations for Bison parsers in C++],
+ [2002, 2003, 2004, 2005, 2006])[
+
+/**
+ ** \file location.hh
+ ** Define the ]b4_namespace_ref[::location class.
+ */
+
+#ifndef BISON_LOCATION_HH
+# define BISON_LOCATION_HH
+
+# include <iostream>
+# include <string>
+# include "position.hh"
+
+]b4_namespace_open[
+
+ /// Abstract a location.
+ class location
+ {
+ public:
+]m4_ifdef([b4_location_constructors], [
+ /// Construct a location.
+ location ()
+ : begin (), end ()
+ {
+ }
+
+])[
+ /// Initialization.
+ inline void initialize (]b4_percent_define_get([[filename_type]])[* fn)
+ {
+ begin.initialize (fn);
+ end = begin;
+ }
+
+ /** \name Line and Column related manipulators
+ ** \{ */
+ public:
+ /// Reset initial location to final location.
+ inline void step ()
+ {
+ begin = end;
+ }
+
+ /// Extend the current location to the COUNT next columns.
+ inline void columns (unsigned int count = 1)
+ {
+ end += count;
+ }
+
+ /// Extend the current location to the COUNT next lines.
+ inline void lines (unsigned int count = 1)
+ {
+ end.lines (count);
+ }
+ inline void incline ()
+ {
+ lines(1);
+ step();
+ }
+ /** \} */
+
+
+ public:
+ /// Beginning of the located region.
+ position begin;
+ /// End of the located region.
+ position end;
+ };
+
+ /// Join two location objects to create a location.
+ inline const location operator+ (const location& begin, const location& end)
+ {
+ location res = begin;
+ res.end = end.end;
+ return res;
+ }
+
+ /// Add two location objects.
+ inline const location operator+ (const location& begin, unsigned int width)
+ {
+ location res = begin;
+ res.columns (width);
+ return res;
+ }
+
+ /// Add and assign a location.
+ inline location& operator+= (location& res, unsigned int width)
+ {
+ res.columns (width);
+ return res;
+ }
+]b4_percent_define_flag_if([[define_location_comparison]], [[
+ /// Compare two location objects.
+ inline bool
+ operator== (const location& loc1, const location& loc2)
+ {
+ return loc1.begin == loc2.begin && loc1.end == loc2.end;
+ }
+
+ /// Compare two location objects.
+ inline bool
+ operator!= (const location& loc1, const location& loc2)
+ {
+ return !(loc1 == loc2);
+ }
+]])[
+ /** \brief Intercept output stream redirection.
+ ** \param ostr the destination output stream
+ ** \param loc a reference to the location to redirect
+ **
+ ** Avoid duplicate information.
+ */
+ inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
+ {
+ position last = loc.end - 1;
+ ostr << loc.begin;
+ if (last.filename
+ && (!loc.begin.filename
+ || *loc.begin.filename != *last.filename))
+ ostr << '-' << last;
+ else if (loc.begin.line != last.line)
+ ostr << '-' << last.line << '.' << last.column;
+ else if (loc.begin.column != last.column)
+ ostr << '-' << last.column;
+ return ostr;
+ }
+
+]b4_namespace_close[
+
+#endif // not BISON_LOCATION_HH]
+m4_divert_pop(0)
+m4_changecom([#])
diff --git a/tools/mhmake/src/bisondata/m4sugar/foreach.m4 b/tools/mhmake/src/bisondata/m4sugar/foreach.m4
new file mode 100644
index 000000000..f6b724d77
--- /dev/null
+++ b/tools/mhmake/src/bisondata/m4sugar/foreach.m4
@@ -0,0 +1,400 @@
+# -*- 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 Free Software Foundation, Inc.
+#
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception, the Free Software Foundation gives unlimited
+# permission to copy, distribute and modify the configure scripts that
+# are the output of Autoconf. You need not follow the terms of the GNU
+# General Public License when using or distributing such scripts, even
+# though portions of the text of Autoconf appear in them. The GNU
+# General Public License (GPL) does govern all other use of the material
+# that constitutes the Autoconf program.
+#
+# Certain portions of the Autoconf source text are designed to be copied
+# (in certain cases, depending on the input) into the output of
+# Autoconf. We call these the "data" portions. The rest of the Autoconf
+# source text consists of comments plus executable code that decides which
+# of the data portions to output in any given case. We call these
+# comments and executable code the "non-data" portions. Autoconf never
+# copies any of the non-data portions into its output.
+#
+# This special exception to the GPL applies to versions of Autoconf
+# released by the Free Software Foundation. When you make and
+# distribute a modified version of Autoconf, you may extend this special
+# exception to the GPL to apply to your modified version as well, *unless*
+# your modified version has the potential to copy into its output some
+# of the text that was the non-data portion of the version that you started
+# with. (In other words, unless your change moves or copies text from
+# the non-data portions to the data portions.) If your modification has
+# such potential, you must delete any notice of this special exception
+# to the GPL from your modified version.
+#
+# 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(VARIABLE, LIST, EXPRESSION)
+# --------------------------------------
+# Expand EXPRESSION assigning each value of the LIST to VARIABLE.
+# LIST should have the form `item_1, item_2, ..., item_n', i.e. the
+# whole list must *quoted*. Quote members too if you don't want them
+# to be expanded.
+#
+# This version minimizes the number of times that $@ is evaluated by
+# using m4_for to generate a boilerplate into VARIABLE 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]) defines i to be
+# m4_define([$1],[$3])$2[]m4_define([$1],[$4])$2[]m4_popdef([i])
+# then calls i([i],[i],[1],[2]).
+m4_define([m4_foreach],
+[m4_if([$2], [], [], [_$0([$1], [$3], $2)])])
+
+m4_define([_m4_foreach],
+[m4_define([$1], m4_pushdef([$1])_m4_for([$1], [3], [$#], [1],
+ [$0_([1], [2], _m4_defn([$1]))])[m4_popdef([$1])])m4_indir([$1], $@)])
+
+m4_define([_m4_foreach_],
+[[m4_define([$$1], [$$3])$$2[]]])
+
+# m4_case(SWITCH, VAL1, IF-VAL1, VAL2, IF-VAL2, ..., DEFAULT)
+# -----------------------------------------------------------
+# Find the first VAL that SWITCH matches, and expand the corresponding
+# IF-VAL. If there are no matches, expand DEFAULT.
+#
+# Use m4_for to create a temporary macro in terms of a boilerplate
+# m4_if with final cleanup. If $# is even, we have DEFAULT; if it is
+# odd, then rounding the last $# up in the temporary macro is
+# harmless. For example, both m4_case(1,2,3,4,5) and
+# m4_case(1,2,3,4,5,6) result in the intermediate _m4_case being
+# m4_if([$1],[$2],[$3],[$1],[$4],[$5],_m4_popdef([_m4_case])[$6])
+m4_define([m4_case],
+[m4_if(m4_eval([$# <= 2]), [1], [$2],
+[m4_pushdef([_$0], [m4_if(]m4_for([_m4_count], [2], m4_decr([$#]), [2],
+ [_$0_([1], _m4_count, m4_incr(_m4_count))])[_m4_popdef(
+ [_$0])]m4_dquote($m4_eval([($# + 1) & ~1]))[)])_$0($@)])])
+
+m4_define([_m4_case_],
+[[[$$1],[$$2],[$$3],]])
+
+# m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT)
+# -----------------------------------------------------
+# m4 equivalent of
+#
+# if (SWITCH =~ RE1)
+# VAL1;
+# elif (SWITCH =~ RE2)
+# VAL2;
+# elif ...
+# ...
+# else
+# DEFAULT
+#
+# We build the temporary macro _m4_b:
+# m4_define([_m4_b], _m4_defn([_m4_bmatch]))_m4_b([$1], [$2], [$3])...
+# _m4_b([$1], [$m-1], [$m])_m4_b([], [], [$m+1]_m4_popdef([_m4_b]))
+# then invoke m4_unquote(_m4_b($@)), for concatenation with later text.
+m4_define([m4_bmatch],
+[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
+ [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
+ [$#], 2, [$2],
+ [m4_define([_m4_b], m4_pushdef([_m4_b])[m4_define([_m4_b],
+ _m4_defn([_$0]))]_m4_for([_m4_b], [3], m4_eval([($# + 1) / 2 * 2 - 1]),
+ [2], [_$0_([1], m4_decr(_m4_b), _m4_b)])[_m4_b([], [],]m4_dquote(
+ [$]m4_incr(_m4_b))[_m4_popdef([_m4_b]))])m4_unquote(_m4_b($@))])])
+
+m4_define([_m4_bmatch],
+[m4_if(m4_bregexp([$1], [$2]), [-1], [], [[$3]m4_define([$0])])])
+
+m4_define([_m4_bmatch_],
+[[_m4_b([$$1], [$$2], [$$3])]])
+
+
+# m4_cond(TEST1, VAL1, IF-VAL1, TEST2, VAL2, IF-VAL2, ..., [DEFAULT])
+# -------------------------------------------------------------------
+# Similar to m4_if, except that each TEST is expanded when encountered.
+# If the expansion of TESTn matches the string VALn, the result is IF-VALn.
+# The result is DEFAULT if no tests passed. This macro allows
+# short-circuiting of expensive tests, where it pays to arrange quick
+# filter tests to run first.
+#
+# m4_cond already guarantees either 3*n or 3*n + 1 arguments, 1 <= n.
+# We only have to speed up _m4_cond, by building the temporary _m4_c:
+# m4_define([_m4_c], _m4_defn([m4_unquote]))_m4_c([m4_if(($1), [($2)],
+# [[$3]m4_define([_m4_c])])])_m4_c([m4_if(($4), [($5)],
+# [[$6]m4_define([_m4_c])])])..._m4_c([m4_if(($m-2), [($m-1)],
+# [[$m]m4_define([_m4_c])])])_m4_c([[$m+1]]_m4_popdef([_m4_c]))
+# We invoke m4_unquote(_m4_c($@)), for concatenation with later text.
+m4_define([_m4_cond],
+[m4_define([_m4_c], m4_pushdef([_m4_c])[m4_define([_m4_c],
+ _m4_defn([m4_unquote]))]_m4_for([_m4_c], [2], m4_eval([$# / 3 * 3 - 1]), [3],
+ [$0_(m4_decr(_m4_c), _m4_c, m4_incr(_m4_c))])[_m4_c(]m4_dquote(m4_dquote(
+ [$]m4_eval([$# / 3 * 3 + 1])))[_m4_popdef([_m4_c]))])m4_unquote(_m4_c($@))])
+
+m4_define([_m4_cond_],
+[[_m4_c([m4_if(($$1), [($$2)], [[$$3]m4_define([_m4_c])])])]])
+
+# m4_bpatsubsts(STRING, RE1, SUBST1, RE2, SUBST2, ...)
+# ----------------------------------------------------
+# m4 equivalent of
+#
+# $_ = STRING;
+# s/RE1/SUBST1/g;
+# s/RE2/SUBST2/g;
+# ...
+#
+# m4_bpatsubsts already validated an odd number of arguments; we only
+# need to speed up _m4_bpatsubsts. To avoid nesting, we build the
+# temporary _m4_p:
+# m4_define([_m4_p], [$1])m4_define([_m4_p],
+# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$2], [$3]))m4_define([_m4_p],
+# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$4], [$5]))m4_define([_m4_p],...
+# m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$m-1], [$m]))m4_unquote(
+# _m4_defn([_m4_p])_m4_popdef([_m4_p]))
+m4_define([_m4_bpatsubsts],
+[m4_define([_m4_p], m4_pushdef([_m4_p])[m4_define([_m4_p],
+ ]m4_dquote([$]1)[)]_m4_for([_m4_p], [3], [$#], [2], [$0_(m4_decr(_m4_p),
+ _m4_p)])[m4_unquote(_m4_defn([_m4_p])_m4_popdef([_m4_p]))])_m4_p($@)])
+
+m4_define([_m4_bpatsubsts_],
+[[m4_define([_m4_p],
+m4_bpatsubst(m4_dquote(_m4_defn([_m4_p])), [$$1], [$$2]))]])
+
+# m4_shiftn(N, ...)
+# -----------------
+# Returns ... shifted N times. Useful for recursive "varargs" constructs.
+#
+# m4_shiftn already validated arguments; we only need to speed up
+# _m4_shiftn. If N is 3, then we build the temporary _m4_s, defined as
+# ,[$5],[$6],...,[$m]_m4_popdef([_m4_s])
+# before calling m4_shift(_m4_s($@)).
+m4_define([_m4_shiftn],
+[m4_if(m4_incr([$1]), [$#], [], [m4_define([_m4_s],
+ m4_pushdef([_m4_s])_m4_for([_m4_s], m4_eval([$1 + 2]), [$#], [1],
+ [[,]m4_dquote([$]_m4_s)])[_m4_popdef([_m4_s])])m4_shift(_m4_s($@))])])
+
+# m4_do(STRING, ...)
+# ------------------
+# This macro invokes all its arguments (in sequence, of course). It is
+# useful for making your macros more structured and readable by dropping
+# unnecessary dnl's and have the macros indented properly.
+#
+# Here, we use the temporary macro _m4_do, defined as
+# $1[]$2[]...[]$n[]_m4_popdef([_m4_do])
+m4_define([m4_do],
+[m4_if([$#], [0], [],
+ [m4_define([_$0], m4_pushdef([_$0])_m4_for([_$0], [1], [$#], [1],
+ [$_$0[[]]])[_m4_popdef([_$0])])_$0($@)])])
+
+# m4_dquote_elt(ARGS)
+# -------------------
+# Return ARGS as an unquoted list of double-quoted arguments.
+#
+# m4_foreach to the rescue. It's easier to shift off the leading comma.
+m4_define([m4_dquote_elt],
+[m4_shift(m4_foreach([_m4_elt], [$@], [,m4_dquote(_m4_defn([_m4_elt]))]))])
+
+# m4_reverse(ARGS)
+# ----------------
+# Output ARGS in reverse order.
+#
+# Invoke _m4_r($@) with the temporary _m4_r built as
+# [$m], [$m-1], ..., [$2], [$1]_m4_popdef([_m4_r])
+m4_define([m4_reverse],
+[m4_if([$#], [0], [], [$#], [1], [[$1]],
+[m4_define([_m4_r], m4_dquote([$$#])m4_pushdef([_m4_r])_m4_for([_m4_r],
+ m4_decr([$#]), [1], [-1],
+ [[, ]m4_dquote([$]_m4_r)])[_m4_popdef([_m4_r])])_m4_r($@)])])
+
+
+# m4_map(MACRO, LIST)
+# -------------------
+# Invoke MACRO($1), MACRO($2) etc. where $1, $2... are the elements
+# of LIST. $1, $2... must in turn be lists, appropriate for m4_apply.
+#
+# m4_map/m4_map_sep only execute once; the speedup comes in fixing
+# _m4_map. The mismatch in () is intentional, since $1 supplies the
+# opening `(' (but it sure looks odd!). Build the temporary _m4_m:
+# $1, [$3])$1, [$4])...$1, [$m])_m4_popdef([_m4_m])
+m4_define([_m4_map],
+[m4_if([$#], [2], [],
+ [m4_define([_m4_m], m4_pushdef([_m4_m])_m4_for([_m4_m], [3], [$#], [1],
+ [$0_([1], _m4_m)])[_m4_popdef([_m4_m])])_m4_m($@)])])
+
+m4_define([_m4_map_],
+[[$$1, [$$2])]])
+
+# m4_transform(EXPRESSION, ARG...)
+# --------------------------------
+# Expand EXPRESSION([ARG]) for each argument. More efficient than
+# m4_foreach([var], [ARG...], [EXPRESSION(m4_defn([var]))])
+#
+# Invoke the temporary macro _m4_transform, defined as:
+# $1([$2])[]$1([$3])[]...$1([$m])[]_m4_popdef([_m4_transform])
+m4_define([m4_transform],
+[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
+ [$#], [1], [],
+ [m4_define([_$0], m4_pushdef([_$0])_m4_for([_$0], [2], [$#], [1],
+ [_$0_([1], _$0)])[_m4_popdef([_$0])])_$0($@)])])
+
+m4_define([_m4_transform_],
+[[$$1([$$2])[]]])
+
+# m4_transform_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...)
+# --------------------------------------------------------------
+# Perform a pairwise grouping of consecutive ARGs, by expanding
+# EXPRESSION([ARG1], [ARG2]). If there are an odd number of ARGs, the
+# final argument is expanded with END-EXPR([ARGn]).
+#
+# Build the temporary macro _m4_transform_pair, with the $2([$m+1])
+# only output if $# is odd:
+# $1([$3], [$4])[]$1([$5], [$6])[]...$1([$m-1],
+# [$m])[]m4_default([$2], [$1])([$m+1])[]_m4_popdef([_m4_transform_pair])
+m4_define([m4_transform_pair],
+[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
+ [$#], [1], [m4_fatal([$0: too few arguments: $#: $1])],
+ [$#], [2], [],
+ [$#], [3], [m4_default([$2], [$1])([$3])[]],
+ [m4_define([_$0], m4_pushdef([_$0])_m4_for([_$0], [3],
+ m4_eval([$# / 2 * 2 - 1]), [2], [_$0_([1], _$0, m4_incr(_$0))])_$0_end(
+ [1], [2], [$#])[_m4_popdef([_$0])])_$0($@)])])
+
+m4_define([_m4_transform_pair_],
+[[$$1([$$2], [$$3])[]]])
+
+m4_define([_m4_transform_pair_end],
+[m4_if(m4_eval([$3 & 1]), [1], [[m4_default([$$2], [$$1])([$$3])[]]])])
+
+# m4_join(SEP, ARG1, ARG2...)
+# ---------------------------
+# Produce ARG1SEPARG2...SEPARGn. Avoid back-to-back SEP when a given ARG
+# is the empty string. No expansion is performed on SEP or ARGs.
+#
+# Use a self-modifying separator, since we don't know how many
+# arguments might be skipped before a separator is first printed, but
+# be careful if the separator contains $. m4_foreach to the rescue.
+m4_define([m4_join],
+[m4_pushdef([_m4_sep], [m4_define([_m4_sep], _m4_defn([m4_echo]))])]dnl
+[m4_foreach([_m4_arg], [m4_shift($@)],
+ [m4_ifset([_m4_arg], [_m4_sep([$1])_m4_defn([_m4_arg])])])]dnl
+[_m4_popdef([_m4_sep])])
+
+# m4_joinall(SEP, ARG1, ARG2...)
+# ------------------------------
+# Produce ARG1SEPARG2...SEPARGn. An empty ARG results in back-to-back SEP.
+# No expansion is performed on SEP or ARGs.
+#
+# A bit easier than m4_join. m4_foreach to the rescue.
+m4_define([m4_joinall],
+[[$2]m4_if(m4_eval([$# <= 2]), [1], [],
+ [m4_foreach([_m4_arg], [m4_shift2($@)],
+ [[$1]_m4_defn([_m4_arg])])])])
+
+# m4_list_cmp(A, B)
+# -----------------
+# Compare the two lists of integer expressions A and B.
+#
+# m4_list_cmp takes care of any side effects; we only override
+# _m4_list_cmp_raw, where we can safely expand lists multiple times.
+# First, insert padding so that both lists are the same length; the
+# trailing +0 is necessary to handle a missing list. Next, create a
+# temporary macro to perform pairwise comparisons until an inequality
+# is found. For example, m4_list_cmp([1], [1,2]) creates _m4_cmp as
+# m4_if(m4_eval([($1) != ($3)]), [1], [m4_cmp([$1], [$3])],
+# m4_eval([($2) != ($4)]), [1], [m4_cmp([$2], [$4])],
+# [0]_m4_popdef([_m4_cmp], [_m4_size]))
+# then calls _m4_cmp([1+0], [0], [1], [2+0])
+m4_define([_m4_list_cmp_raw],
+[m4_if([$1], [$2], 0, [m4_pushdef(
+ [_m4_size])_m4_list_cmp($1+0_m4_list_pad(m4_count($1), m4_count($2)),
+ $2+0_m4_list_pad(m4_count($2), m4_count($1)))])])
+
+m4_define([_m4_list_pad],
+[m4_if(m4_eval($1 < $2), [1],
+ [_m4_for([_m4_size], m4_incr([$1]), [$2], [1], [,0])])])
+
+m4_define([_m4_list_cmp],
+[m4_define([_m4_size], m4_eval([$# >> 1]))]dnl
+[m4_define([_m4_cmp], m4_pushdef([_m4_cmp])[m4_if(]_m4_for([_m4_cmp],
+ [1], _m4_size, [1], [$0_(_m4_cmp, m4_eval(_m4_cmp + _m4_size))])[
+ [0]_m4_popdef([_m4_cmp], [_m4_size]))])_m4_cmp($@)])
+
+m4_define([_m4_list_cmp_],
+[[m4_eval([($$1) != ($$2)]), [1], [m4_cmp([$$1], [$$2])],
+]])
+
+# m4_max(EXPR, ...)
+# m4_min(EXPR, ...)
+# -----------------
+# Return the decimal value of the maximum (or minimum) in a series of
+# integer expressions.
+#
+# m4_foreach to the rescue; we only need to replace _m4_minmax. Here,
+# we need a temporary macro to track the best answer so far, so that
+# the foreach expression is tractable.
+m4_define([_m4_minmax],
+[m4_pushdef([_m4_best], m4_eval([$2]))m4_foreach([_m4_arg], [m4_shift2($@)],
+ [m4_define([_m4_best], $1(_m4_best, _m4_defn([_m4_arg])))])]dnl
+[_m4_best[]_m4_popdef([_m4_best])])
+
+# m4_set_add_all(SET, VALUE...)
+# -----------------------------
+# Add each VALUE into SET. This is O(n) in the number of VALUEs, and
+# can be faster than calling m4_set_add for each VALUE.
+#
+# m4_foreach to the rescue. If no deletions have occurred, then avoid
+# the speed penalty of m4_set_add.
+m4_define([m4_set_add_all],
+[m4_if([$#], [0], [], [$#], [1], [],
+ [m4_define([_m4_set_size($1)], m4_eval(m4_set_size([$1])
+ + m4_len(m4_foreach([_m4_arg], [m4_shift($@)],
+ m4_ifdef([_m4_set_cleanup($1)],
+ [[m4_set_add([$1], _m4_defn([_m4_arg]))]],
+ [[m4_ifdef([_m4_set([$1],]_m4_defn([_m4_arg])[)], [],
+ [m4_define([_m4_set([$1],]_m4_defn([_m4_arg])[)],
+ [1])m4_pushdef([_m4_set([$1])],
+ _m4_defn([_m4_arg]))-])]])))))])])
diff --git a/tools/mhmake/src/bisondata/m4sugar/m4sugar.m4 b/tools/mhmake/src/bisondata/m4sugar/m4sugar.m4
new file mode 100644
index 000000000..291267c33
--- /dev/null
+++ b/tools/mhmake/src/bisondata/m4sugar/m4sugar.m4
@@ -0,0 +1,2789 @@
+divert(-1)# -*- Autoconf -*-
+# This file is part of Autoconf.
+# Base M4 layer.
+# Requires GNU M4.
+#
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+# 2008 Free Software Foundation, Inc.
+#
+# 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception, the Free Software Foundation gives unlimited
+# permission to copy, distribute and modify the configure scripts that
+# are the output of Autoconf. You need not follow the terms of the GNU
+# General Public License when using or distributing such scripts, even
+# though portions of the text of Autoconf appear in them. The GNU
+# General Public License (GPL) does govern all other use of the material
+# that constitutes the Autoconf program.
+#
+# Certain portions of the Autoconf source text are designed to be copied
+# (in certain cases, depending on the input) into the output of
+# Autoconf. We call these the "data" portions. The rest of the Autoconf
+# source text consists of comments plus executable code that decides which
+# of the data portions to output in any given case. We call these
+# comments and executable code the "non-data" portions. Autoconf never
+# copies any of the non-data portions into its output.
+#
+# This special exception to the GPL applies to versions of Autoconf
+# released by the Free Software Foundation. When you make and
+# distribute a modified version of Autoconf, you may extend this special
+# exception to the GPL to apply to your modified version as well, *unless*
+# your modified version has the potential to copy into its output some
+# of the text that was the non-data portion of the version that you started
+# with. (In other words, unless your change moves or copies text from
+# the non-data portions to the data portions.) If your modification has
+# such potential, you must delete any notice of this special exception
+# to the GPL from your modified version.
+#
+# Written by Akim Demaille.
+#
+
+# Set the quotes, whatever the current quoting system.
+changequote()
+changequote([, ])
+
+# Some old m4's don't support m4exit. But they provide
+# equivalent functionality by core dumping because of the
+# long macros we define.
+ifdef([__gnu__], ,
+[errprint(M4sugar requires GNU M4. Install it before installing M4sugar or
+set the M4 environment variable to its absolute file name.)
+m4exit(2)])
+
+
+## ------------------------------- ##
+## 1. Simulate --prefix-builtins. ##
+## ------------------------------- ##
+
+# m4_define
+# m4_defn
+# m4_undefine
+define([m4_define], defn([define]))
+define([m4_defn], defn([defn]))
+define([m4_undefine], defn([undefine]))
+
+m4_undefine([define])
+m4_undefine([defn])
+m4_undefine([undefine])
+
+
+# m4_copy(SRC, DST)
+# -----------------
+# Define DST as the definition of SRC.
+# What's the difference between:
+# 1. m4_copy([from], [to])
+# 2. m4_define([to], [from($@)])
+# Well, obviously 1 is more expensive in space. Maybe 2 is more expensive
+# in time, but because of the space cost of 1, it's not that obvious.
+# Nevertheless, one huge difference is the handling of `$0'. If `from'
+# uses `$0', then with 1, `to''s `$0' is `to', while it is `from' in 2.
+# The user would certainly prefer to see `to'.
+m4_define([m4_copy],
+[m4_define([$2], m4_defn([$1]))])
+
+
+# m4_rename(SRC, DST)
+# -------------------
+# Rename the macro SRC to DST.
+m4_define([m4_rename],
+[m4_copy([$1], [$2])m4_undefine([$1])])
+
+
+# m4_rename_m4(MACRO-NAME)
+# ------------------------
+# Rename MACRO-NAME to m4_MACRO-NAME.
+m4_define([m4_rename_m4],
+[m4_rename([$1], [m4_$1])])
+
+
+# m4_copy_unm4(m4_MACRO-NAME)
+# ---------------------------
+# Copy m4_MACRO-NAME to MACRO-NAME.
+m4_define([m4_copy_unm4],
+[m4_copy([$1], m4_bpatsubst([$1], [^m4_\(.*\)], [[\1]]))])
+
+
+# Some m4 internals have names colliding with tokens we might use.
+# Rename them a` la `m4 --prefix-builtins'. Conditionals first, since
+# some subsequent renames are conditional.
+m4_rename_m4([ifdef])
+m4_rename([ifelse], [m4_if])
+
+m4_rename_m4([builtin])
+m4_rename_m4([changecom])
+m4_rename_m4([changequote])
+m4_ifdef([changeword],dnl conditionally available in 1.4.x
+[m4_undefine([changeword])])
+m4_rename_m4([debugfile])
+m4_rename_m4([debugmode])
+m4_rename_m4([decr])
+m4_undefine([divert])
+m4_rename_m4([divnum])
+m4_rename_m4([dumpdef])
+m4_rename_m4([errprint])
+m4_rename_m4([esyscmd])
+m4_rename_m4([eval])
+m4_rename_m4([format])
+m4_undefine([include])
+m4_rename_m4([incr])
+m4_rename_m4([index])
+m4_rename_m4([indir])
+m4_rename_m4([len])
+m4_rename([m4exit], [m4_exit])
+m4_undefine([m4wrap])
+m4_ifdef([mkstemp],dnl added in M4 1.4.8
+[m4_rename_m4([mkstemp])
+m4_copy([m4_mkstemp], [m4_maketemp])
+m4_undefine([maketemp])],
+[m4_rename_m4([maketemp])
+m4_copy([m4_maketemp], [m4_mkstemp])])
+m4_rename([patsubst], [m4_bpatsubst])
+m4_rename_m4([popdef])
+m4_rename_m4([pushdef])
+m4_rename([regexp], [m4_bregexp])
+m4_rename_m4([shift])
+m4_undefine([sinclude])
+m4_rename_m4([substr])
+m4_ifdef([symbols],dnl present only in alpha-quality 1.4o
+[m4_rename_m4([symbols])])
+m4_rename_m4([syscmd])
+m4_rename_m4([sysval])
+m4_rename_m4([traceoff])
+m4_rename_m4([traceon])
+m4_rename_m4([translit])
+m4_undefine([undivert])
+
+
+## ------------------- ##
+## 2. Error messages. ##
+## ------------------- ##
+
+
+# m4_location
+# -----------
+m4_define([m4_location],
+[__file__:__line__])
+
+
+# m4_errprintn(MSG)
+# -----------------
+# Same as `errprint', but with the missing end of line.
+m4_define([m4_errprintn],
+[m4_errprint([$1
+])])
+
+
+# m4_warning(MSG)
+# ---------------
+# Warn the user.
+m4_define([m4_warning],
+[m4_errprintn(m4_location[: warning: $1])])
+
+
+# m4_fatal(MSG, [EXIT-STATUS])
+# ----------------------------
+# 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_assert(EXPRESSION, [EXIT-STATUS = 1])
+# ----------------------------------------
+# This macro ensures that EXPRESSION evaluates to true, and exits if
+# EXPRESSION evaluates to false.
+m4_define([m4_assert],
+[m4_if(m4_eval([$1]), 0,
+ [m4_fatal([assert failed: $1], [$2])])])
+
+
+
+## ------------- ##
+## 3. Warnings. ##
+## ------------- ##
+
+
+# _m4_warn(CATEGORY, MESSAGE, STACK-TRACE)
+# ----------------------------------------
+# Report a MESSAGE to the user if the CATEGORY of warnings is enabled.
+# This is for traces only.
+# The STACK-TRACE is a \n-separated list of "LOCATION: MESSAGE".
+#
+# Within m4, the macro is a no-op. This macro really matters
+# when autom4te post-processes the trace output.
+m4_define([_m4_warn], [])
+
+
+# m4_warn(CATEGORY, MESSAGE)
+# --------------------------
+# 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_defn([m4_expansion_stack])
+m4_location[: the top level]]))dnl
+])
+
+
+
+## ------------------- ##
+## 4. File inclusion. ##
+## ------------------- ##
+
+
+# We also want to neutralize include (and sinclude for symmetry),
+# but we want to extend them slightly: warn when a file is included
+# several times. This is, in general, a dangerous operation, because
+# too many people forget to quote the first argument of m4_define.
+#
+# For instance in the following case:
+# m4_define(foo, [bar])
+# then a second reading will turn into
+# m4_define(bar, [bar])
+# which is certainly not what was meant.
+
+# m4_include_unique(FILE)
+# -----------------------
+# Declare that the FILE was loading; and warn if it has already
+# been included.
+m4_define([m4_include_unique],
+[m4_ifdef([m4_include($1)],
+ [m4_warn([syntax], [file `$1' included several times])])dnl
+m4_define([m4_include($1)])])
+
+
+# m4_include(FILE)
+# ----------------
+# Like the builtin include, but warns against multiple inclusions.
+m4_define([m4_include],
+[m4_include_unique([$1])dnl
+m4_builtin([include], [$1])])
+
+
+# m4_sinclude(FILE)
+# -----------------
+# Like the builtin sinclude, but warns against multiple inclusions.
+m4_define([m4_sinclude],
+[m4_include_unique([$1])dnl
+m4_builtin([sinclude], [$1])])
+
+
+
+## ------------------------------------ ##
+## 5. Additional branching constructs. ##
+## ------------------------------------ ##
+
+# Both `m4_ifval' and `m4_ifset' tests against the empty string. The
+# difference is that `m4_ifset' is specialized on macros.
+#
+# In case of arguments of macros, eg. $1, it makes little difference.
+# In the case of a macro `FOO', you don't want to check `m4_ifval(FOO,
+# TRUE)', because if `FOO' expands with commas, there is a shifting of
+# the arguments. So you want to run `m4_ifval([FOO])', but then you just
+# compare the *string* `FOO' against `', which, of course fails.
+#
+# So you want the variation `m4_ifset' that expects a macro name as $1.
+# If this macro is both defined and defined to a non empty value, then
+# it runs TRUE, etc.
+
+
+# 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],
+[m4_if([$1], [], [$3], [$2])])
+
+
+# m4_n(TEXT)
+# ----------
+# If TEXT is not empty, return TEXT and a new line, otherwise nothing.
+m4_define([m4_n],
+[m4_if([$1],
+ [], [],
+ [$1
+])])
+
+
+# m4_ifvaln(COND, [IF-TRUE], [IF-FALSE])
+# --------------------------------------
+# Same as `m4_ifval', but add an extra newline to IF-TRUE or IF-FALSE
+# unless that argument is empty.
+m4_define([m4_ifvaln],
+[m4_if([$1],
+ [], [m4_n([$3])],
+ [m4_n([$2])])])
+
+
+# m4_ifset(MACRO, [IF-TRUE], [IF-FALSE])
+# --------------------------------------
+# If MACRO has no definition, or of its definition is the empty string,
+# expand IF-FALSE, otherwise IF-TRUE.
+m4_define([m4_ifset],
+[m4_ifdef([$1],
+ [m4_ifval(_m4_defn([$1]), [$2], [$3])],
+ [$3])])
+
+
+# m4_ifndef(NAME, [IF-NOT-DEFINED], [IF-DEFINED])
+# -----------------------------------------------
+m4_define([m4_ifndef],
+[m4_ifdef([$1], [$3], [$2])])
+
+
+# m4_case(SWITCH, VAL1, IF-VAL1, VAL2, IF-VAL2, ..., DEFAULT)
+# -----------------------------------------------------------
+# m4 equivalent of
+# switch (SWITCH)
+# {
+# case VAL1:
+# IF-VAL1;
+# break;
+# case VAL2:
+# IF-VAL2;
+# break;
+# ...
+# default:
+# DEFAULT;
+# break;
+# }.
+# All the values are optional, and the macro is robust to active
+# symbols properly quoted.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_case],
+[m4_if([$#], 0, [],
+ [$#], 1, [],
+ [$#], 2, [$2],
+ [$1], [$2], [$3],
+ [$0([$1], m4_shift3($@))])])
+
+
+# m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT)
+# -----------------------------------------------------
+# m4 equivalent of
+#
+# if (SWITCH =~ RE1)
+# VAL1;
+# elif (SWITCH =~ RE2)
+# VAL2;
+# elif ...
+# ...
+# else
+# DEFAULT
+#
+# All the values are optional, and the macro is robust to active symbols
+# properly quoted.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_bmatch],
+[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
+ [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
+ [$#], 2, [$2],
+ [m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shift3($@))],
+ [$3])])])
+
+
+# m4_car(LIST)
+# m4_cdr(LIST)
+# ------------
+# Manipulate m4 lists.
+m4_define([m4_car], [[$1]])
+m4_define([m4_cdr],
+[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
+ [$#], 1, [],
+ [m4_dquote(m4_shift($@))])])
+
+# _m4_cdr(LIST)
+# -------------
+# Like m4_cdr, except include a leading comma unless only one element
+# remains. Why? Because comparing a large list against [] is more
+# expensive in expansion time than comparing the number of arguments; so
+# _m4_cdr can be used to reduce the number of arguments when it is time
+# to end recursion.
+m4_define([_m4_cdr],
+[m4_if([$#], 1, [],
+ [, m4_dquote(m4_shift($@))])])
+
+
+
+# m4_cond(TEST1, VAL1, IF-VAL1, TEST2, VAL2, IF-VAL2, ..., [DEFAULT])
+# -------------------------------------------------------------------
+# Similar to m4_if, except that each TEST is expanded when encountered.
+# If the expansion of TESTn matches the string VALn, the result is IF-VALn.
+# The result is DEFAULT if no tests passed. This macro allows
+# short-circuiting of expensive tests, where it pays to arrange quick
+# filter tests to run first.
+#
+# For an example, consider a previous implementation of _AS_QUOTE_IFELSE:
+#
+# m4_if(m4_index([$1], [\]), [-1], [$2],
+# m4_eval(m4_index([$1], [\\]) >= 0), [1], [$2],
+# m4_eval(m4_index([$1], [\$]) >= 0), [1], [$2],
+# m4_eval(m4_index([$1], [\`]) >= 0), [1], [$3],
+# m4_eval(m4_index([$1], [\"]) >= 0), [1], [$3],
+# [$2])
+#
+# Here, m4_index is computed 5 times, and m4_eval 4, even if $1 contains
+# no backslash. It is more efficient to do:
+#
+# m4_cond([m4_index([$1], [\])], [-1], [$2],
+# [m4_eval(m4_index([$1], [\\]) >= 0)], [1], [$2],
+# [m4_eval(m4_index([$1], [\$]) >= 0)], [1], [$2],
+# [m4_eval(m4_index([$1], [\`]) >= 0)], [1], [$3],
+# [m4_eval(m4_index([$1], [\"]) >= 0)], [1], [$3],
+# [$2])
+#
+# In the common case of $1 with no backslash, only one m4_index expansion
+# occurs, and m4_eval is avoided altogether.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_cond],
+[m4_if([$#], [0], [m4_fatal([$0: cannot be called without arguments])],
+ [$#], [1], [$1],
+ m4_eval([$# % 3]), [2], [m4_fatal([$0: missing an argument])],
+ [_$0($@)])])
+
+m4_define([_m4_cond],
+[m4_if(($1), [($2)], [$3],
+ [$#], [3], [],
+ [$#], [4], [$4],
+ [$0(m4_shift3($@))])])
+
+
+## ---------------------------------------- ##
+## 6. Enhanced version of some primitives. ##
+## ---------------------------------------- ##
+
+# m4_bpatsubsts(STRING, RE1, SUBST1, RE2, SUBST2, ...)
+# ----------------------------------------------------
+# m4 equivalent of
+#
+# $_ = STRING;
+# s/RE1/SUBST1/g;
+# s/RE2/SUBST2/g;
+# ...
+#
+# All the values are optional, and the macro is robust to active symbols
+# properly quoted.
+#
+# I would have liked to name this macro `m4_bpatsubst', unfortunately,
+# due to quotation problems, I need to double quote $1 below, therefore
+# the anchors are broken :( I can't let users be trapped by that.
+#
+# Recall that m4_shift3 always results in an argument. Hence, we need
+# to distinguish between a final deletion vs. ending recursion.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_bpatsubsts],
+[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
+ [$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
+ [$#], 2, [m4_unquote(m4_builtin([patsubst], [[$1]], [$2]))],
+ [$#], 3, [m4_unquote(m4_builtin([patsubst], [[$1]], [$2], [$3]))],
+ [_$0($@m4_if(m4_eval($# & 1), 0, [,]))])])
+m4_define([_m4_bpatsubsts],
+[m4_if([$#], 2, [$1],
+ [$0(m4_builtin([patsubst], [[$1]], [$2], [$3]),
+ m4_shift3($@))])])
+
+
+# m4_define_default(MACRO, VALUE)
+# -------------------------------
+# If MACRO is undefined, set it to VALUE.
+m4_define([m4_define_default],
+[m4_ifndef([$1], [m4_define($@)])])
+
+
+# m4_default(EXP1, EXP2)
+# ----------------------
+# Returns EXP1 if non empty, otherwise EXP2.
+#
+# This macro is called on hot paths, so inline the contents of m4_ifval,
+# for one less round of expansion.
+m4_define([m4_default],
+[m4_if([$1], [], [$2], [$1])])
+
+
+# m4_defn(NAME)
+# -------------
+# Like the original, except guarantee a warning when using something which is
+# undefined (unlike M4 1.4.x). This replacement is not a full-featured
+# replacement: if any of the defined macros contain unbalanced quoting, but
+# when pasted together result in a well-quoted string, then only native m4
+# support is able to get it correct. But that's where quadrigraphs come in
+# handy, if you really need unbalanced quotes inside your macros.
+#
+# This macro is called frequently, so minimize the amount of additional
+# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists,
+# (added in M4 1.6), then let m4 do the job for us (see m4_init).
+#
+# _m4_defn is for internal use only - it bypasses the wrapper, so it
+# must only be used on one argument at a time, and only on macros
+# known to be defined. Make sure this still works if the user renames
+# m4_defn but not _m4_defn.
+m4_copy([m4_defn], [_m4_defn])
+m4_define([m4_defn],
+[m4_if([$#], [0], [[$0]],
+ [$#], [1], [m4_ifdef([$1], [_m4_defn([$1])],
+ [m4_fatal([$0: undefined macro: $1])])],
+ [m4_foreach([_m4_macro], [$@], [$0(_m4_defn([_m4_macro]))])])])
+
+
+# _m4_dumpdefs_up(NAME)
+# ---------------------
+m4_define([_m4_dumpdefs_up],
+[m4_ifdef([$1],
+ [m4_pushdef([_m4_dumpdefs], _m4_defn([$1]))dnl
+m4_dumpdef([$1])dnl
+_m4_popdef([$1])dnl
+_m4_dumpdefs_up([$1])])])
+
+
+# _m4_dumpdefs_down(NAME)
+# -----------------------
+m4_define([_m4_dumpdefs_down],
+[m4_ifdef([_m4_dumpdefs],
+ [m4_pushdef([$1], _m4_defn([_m4_dumpdefs]))dnl
+_m4_popdef([_m4_dumpdefs])dnl
+_m4_dumpdefs_down([$1])])])
+
+
+# m4_dumpdefs(NAME)
+# -----------------
+# Similar to `m4_dumpdef(NAME)', but if NAME was m4_pushdef'ed, display its
+# value stack (most recent displayed first).
+m4_define([m4_dumpdefs],
+[_m4_dumpdefs_up([$1])dnl
+_m4_dumpdefs_down([$1])])
+
+
+# m4_popdef(NAME)
+# ---------------
+# Like the original, except guarantee a warning when using something which is
+# undefined (unlike M4 1.4.x).
+#
+# This macro is called frequently, so minimize the amount of additional
+# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists,
+# (added in M4 1.6), then let m4 do the job for us (see m4_init).
+#
+# _m4_popdef is for internal use only - it bypasses the wrapper, so it
+# must only be used on macros known to be defined. Make sure this
+# still works if the user renames m4_popdef but not _m4_popdef.
+m4_copy([m4_popdef], [_m4_popdef])
+m4_define([m4_popdef],
+[m4_if([$#], [0], [[$0]],
+ [$#], [1], [m4_ifdef([$1], [_m4_popdef([$1])],
+ [m4_fatal([$0: undefined macro: $1])])],
+ [m4_foreach([_m4_macro], [$@], [$0(_m4_defn([_m4_macro]))])])])
+
+
+# m4_shiftn(N, ...)
+# -----------------
+# Returns ... shifted N times. Useful for recursive "varargs" constructs.
+#
+# Autoconf does not use this macro, because it is inherently slower than
+# calling the common cases of m4_shift2 or m4_shift3 directly. But it
+# might as well be fast for other clients, such as Libtool. One way to
+# do this is to expand $@ only once in _m4_shiftn (otherwise, for long
+# lists, the expansion of m4_if takes twice as much memory as what the
+# list itself occupies, only to throw away the unused branch). The end
+# result is strictly equivalent to
+# m4_if([$1], 1, [m4_shift(,m4_shift(m4_shift($@)))],
+# [_m4_shiftn(m4_decr([$1]), m4_shift(m4_shift($@)))])
+# but with the final `m4_shift(m4_shift($@)))' shared between the two
+# paths. The first leg uses a no-op m4_shift(,$@) to balance out the ().
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_shiftn],
+[m4_assert(0 < $1 && $1 < $#)_$0($@)])
+
+m4_define([_m4_shiftn],
+[m4_if([$1], 1, [m4_shift(],
+ [$0(m4_decr([$1])]), m4_shift(m4_shift($@)))])
+
+# m4_shift2(...)
+# m4_shift3(...)
+# -----------------
+# Returns ... shifted twice, and three times. Faster than m4_shiftn.
+m4_define([m4_shift2], [m4_shift(m4_shift($@))])
+m4_define([m4_shift3], [m4_shift(m4_shift(m4_shift($@)))])
+
+# _m4_shift2(...)
+# _m4_shift3(...)
+# ---------------
+# Like m4_shift2 or m4_shift3, except include a leading comma unless shifting
+# consumes all arguments. Why? Because in recursion, it is nice to
+# distinguish between 1 element left and 0 elements left, based on how many
+# arguments this shift expands to.
+m4_define([_m4_shift2],
+[m4_if([$#], [2], [],
+ [, m4_shift(m4_shift($@))])])
+m4_define([_m4_shift3],
+[m4_if([$#], [3], [],
+ [, m4_shift(m4_shift(m4_shift($@)))])])
+
+
+# m4_undefine(NAME)
+# -----------------
+# Like the original, except guarantee a warning when using something which is
+# undefined (unlike M4 1.4.x).
+#
+# This macro is called frequently, so minimize the amount of additional
+# expansions by skipping m4_ifndef. Better yet, if __m4_version__ exists,
+# (added in M4 1.6), then let m4 do the job for us (see m4_init).
+#
+# _m4_undefine is for internal use only - it bypasses the wrapper, so
+# it must only be used on macros known to be defined. Make sure this
+# still works if the user renames m4_undefine but not _m4_undefine.
+m4_copy([m4_undefine], [_m4_undefine])
+m4_define([m4_undefine],
+[m4_if([$#], [0], [[$0]],
+ [$#], [1], [m4_ifdef([$1], [_m4_undefine([$1])],
+ [m4_fatal([$0: undefined macro: $1])])],
+ [m4_foreach([_m4_macro], [$@], [$0(_m4_defn([_m4_macro]))])])])
+
+# _m4_wrap(PRE, POST)
+# -------------------
+# Helper macro for m4_wrap and m4_wrap_lifo. Allows nested calls to
+# m4_wrap within wrapped text. Use _m4_defn and _m4_popdef for speed.
+m4_define([_m4_wrap],
+[m4_ifdef([$0_text],
+ [m4_define([$0_text], [$1]_m4_defn([$0_text])[$2])],
+ [m4_builtin([m4wrap], [m4_unquote(
+ _m4_defn([$0_text])_m4_popdef([$0_text]))])m4_define([$0_text], [$1$2])])])
+
+# m4_wrap(TEXT)
+# -------------
+# Append TEXT to the list of hooks to be executed at the end of input.
+# Whereas the order of the original may be LIFO in the underlying m4,
+# this version is always FIFO.
+m4_define([m4_wrap],
+[_m4_wrap([], [$1[]])])
+
+# m4_wrap_lifo(TEXT)
+# ------------------
+# Prepend TEXT to the list of hooks to be executed at the end of input.
+# Whereas the order of m4_wrap may be FIFO in the underlying m4, this
+# version is always LIFO.
+m4_define([m4_wrap_lifo],
+[_m4_wrap([$1[]])])
+
+## ------------------------- ##
+## 7. Quoting manipulation. ##
+## ------------------------- ##
+
+
+# m4_apply(MACRO, LIST)
+# ---------------------
+# Invoke MACRO, with arguments provided from the quoted list of
+# comma-separated quoted arguments. If LIST is empty, invoke MACRO
+# without arguments. The expansion will not be concatenated with
+# subsequent text.
+m4_define([m4_apply],
+[m4_if([$2], [], [$1], [$1($2)])[]])
+
+# _m4_apply(MACRO, LIST)
+# ----------------------
+# Like m4_apply, except do nothing if LIST is empty.
+m4_define([_m4_apply],
+[m4_if([$2], [], [], [$1($2)[]])])
+
+
+# m4_count(ARGS)
+# --------------
+# Return a count of how many ARGS are present.
+m4_define([m4_count], [$#])
+
+
+# m4_do(STRING, ...)
+# ------------------
+# This macro invokes all its arguments (in sequence, of course). It is
+# useful for making your macros more structured and readable by dropping
+# unnecessary dnl's and have the macros indented properly. No concatenation
+# occurs after a STRING; use m4_unquote(m4_join(,STRING)) for that.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_do],
+[m4_if([$#], 0, [],
+ [$#], 1, [$1[]],
+ [$1[]$0(m4_shift($@))])])
+
+
+# m4_dquote(ARGS)
+# ---------------
+# Return ARGS as a quoted list of quoted arguments.
+m4_define([m4_dquote], [[$@]])
+
+
+# m4_dquote_elt(ARGS)
+# -------------------
+# Return ARGS as an unquoted list of double-quoted arguments.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_dquote_elt],
+[m4_if([$#], [0], [],
+ [$#], [1], [[[$1]]],
+ [[[$1]],$0(m4_shift($@))])])
+
+
+# m4_echo(ARGS)
+# -------------
+# Return the ARGS, with the same level of quoting. Whitespace after
+# unquoted commas are consumed.
+m4_define([m4_echo], [$@])
+
+
+# m4_expand(ARG)
+# --------------
+# Return the expansion of ARG as a single string. Unlike m4_quote($1), this
+# correctly preserves whitespace following single-quoted commas that appeared
+# within ARG.
+#
+# m4_define([active], [ACT, IVE])
+# m4_define([active2], [[ACT, IVE]])
+# m4_quote(active, active2)
+# => ACT,IVE,ACT, IVE
+# m4_expand([active, active2])
+# => ACT, IVE, ACT, IVE
+#
+# Unfortunately, due to limitations in m4, ARG must expand to something
+# with balanced quotes (use quadrigraphs to get around this). The input
+# is not likely to have unbalanced -=<{(/)}>=- quotes, and it is possible
+# to have unbalanced (), provided it was specified with proper [] quotes.
+#
+# Exploit that extra () will group unquoted commas and the following
+# whitespace, then convert () to []. m4_bpatsubst can't handle newlines
+# inside $1, and m4_substr strips quoting. So we (ab)use m4_changequote.
+m4_define([m4_expand], [_$0(-=<{($1)}>=-)])
+m4_define([_m4_expand],
+[m4_changequote([-=<{(], [)}>=-])$1m4_changequote([, ])])
+
+
+# m4_ignore(ARGS)
+# ---------------
+# Expands to nothing. Useful for conditionally ignoring an arbitrary
+# number of arguments (see _m4_list_cmp for an example).
+m4_define([m4_ignore])
+
+
+# m4_make_list(ARGS)
+# ------------------
+# Similar to m4_dquote, this creates a quoted list of quoted ARGS. This
+# version is less efficient than m4_dquote, but separates each argument
+# with a comma and newline, rather than just comma, for readability.
+# When developing an m4sugar algorithm, you could temporarily use
+# m4_pushdef([m4_dquote],m4_defn([m4_make_list]))
+# around your code to make debugging easier.
+m4_define([m4_make_list], [m4_join([,
+], m4_dquote_elt($@))])
+
+
+# m4_noquote(STRING)
+# ------------------
+# Return the result of ignoring all quotes in STRING and invoking the
+# macros it contains. Amongst other things, this is useful for enabling
+# macro invocations inside strings with [] blocks (for instance regexps
+# and help-strings). On the other hand, since all quotes are disabled,
+# any macro expanded during this time that relies on nested [] quoting
+# will likely crash and burn. This macro is seldom useful; consider
+# m4_unquote or m4_expand instead.
+m4_define([m4_noquote],
+[m4_changequote([-=<{(],[)}>=-])$1-=<{()}>=-m4_changequote([,])])
+
+
+# m4_quote(ARGS)
+# --------------
+# Return ARGS as a single argument. Any whitespace after unquoted commas
+# is stripped. There is always output, even when there were no arguments.
+#
+# It is important to realize the difference between `m4_quote(exp)' and
+# `[exp]': in the first case you obtain the quoted *result* of the
+# expansion of EXP, while in the latter you just obtain the string
+# `exp'.
+m4_define([m4_quote], [[$*]])
+
+
+# _m4_quote(ARGS)
+# ---------------
+# Like m4_quote, except that when there are no arguments, there is no
+# output. For conditional scenarios (such as passing _m4_quote as the
+# macro name in m4_mapall), this feature can be used to distinguish between
+# one argument of the empty string vs. no arguments. However, in the
+# normal case with arguments present, this is less efficient than m4_quote.
+m4_define([_m4_quote],
+[m4_if([$#], [0], [], [[$*]])])
+
+
+# m4_reverse(ARGS)
+# ----------------
+# Output ARGS in reverse order.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_reverse],
+[m4_if([$#], [0], [], [$#], [1], [[$1]],
+ [$0(m4_shift($@)), [$1]])])
+
+
+# m4_unquote(ARGS)
+# ----------------
+# Remove one layer of quotes from each ARG, performing one level of
+# expansion. For one argument, m4_unquote([arg]) is more efficient than
+# m4_do([arg]), but for multiple arguments, the difference is that
+# m4_unquote separates arguments with commas while m4_do concatenates.
+# Follow this macro with [] if concatenation with subsequent text is
+# undesired.
+m4_define([m4_unquote], [$*])
+
+
+## -------------------------- ##
+## 8. Implementing m4 loops. ##
+## -------------------------- ##
+
+
+# m4_for(VARIABLE, FIRST, LAST, [STEP = +/-1], EXPRESSION)
+# --------------------------------------------------------
+# Expand EXPRESSION defining VARIABLE to FROM, FROM + 1, ..., TO with
+# increments of STEP. Both limits are included, and bounds are
+# checked for consistency. The algorithm is robust to indirect
+# VARIABLE names. Changing VARIABLE inside EXPRESSION will not impact
+# the number of iterations.
+#
+# Uses _m4_defn for speed, and avoid dnl in the macro body.
+m4_define([m4_for],
+[m4_pushdef([$1], m4_eval([$2]))]dnl
+[m4_cond([m4_eval(([$3]) > ([$2]))], 1,
+ [m4_pushdef([_m4_step], m4_eval(m4_default([$4],
+ 1)))m4_assert(_m4_step > 0)_$0([$1], _m4_defn([$1]),
+ m4_eval((([$3]) - ([$2])) / _m4_step * _m4_step + ([$2])),
+ _m4_step, [$5])],
+ [m4_eval(([$3]) < ([$2]))], 1,
+ [m4_pushdef([_m4_step], m4_eval(m4_default([$4],
+ -1)))m4_assert(_m4_step < 0)_$0([$1], _m4_defn([$1]),
+ m4_eval((([$2]) - ([$3])) / -(_m4_step) * _m4_step + ([$2])),
+ _m4_step, [$5])],
+ [m4_pushdef([_m4_step])$5])[]]dnl
+[m4_popdef([_m4_step], [$1])])
+
+
+# _m4_for(VARIABLE, COUNT, LAST, STEP, EXPRESSION)
+# ------------------------------------------------
+# Core of the loop, no consistency checks, all arguments are plain
+# numbers. Define VARIABLE to COUNT, expand EXPRESSION, then alter
+# COUNT by STEP and iterate if COUNT is not LAST.
+m4_define([_m4_for],
+[m4_define([$1], [$2])$5[]m4_if([$2], [$3], [],
+ [$0([$1], m4_eval([$2 + $4]), [$3], [$4], [$5])])])
+
+
+# Implementing `foreach' loops in m4 is much more tricky than it may
+# seem. For example, the old M4 1.4.4 manual had an incorrect example,
+# which looked like this (when translated to m4sugar):
+#
+# | # foreach(VAR, (LIST), STMT)
+# | m4_define([foreach],
+# | [m4_pushdef([$1])_foreach([$1], [$2], [$3])m4_popdef([$1])])
+# | m4_define([_arg1], [$1])
+# | m4_define([_foreach],
+# | [m4_if([$2], [()], ,
+# | [m4_define([$1], _arg1$2)$3[]_foreach([$1], (m4_shift$2), [$3])])])
+#
+# But then if you run
+#
+# | m4_define(a, 1)
+# | m4_define(b, 2)
+# | m4_define(c, 3)
+# | foreach([f], [([a], [(b], [c)])], [echo f
+# | ])
+#
+# it gives
+#
+# => echo 1
+# => echo (2,3)
+#
+# which is not what is expected.
+#
+# Of course the problem is that many quotes are missing. So you add
+# plenty of quotes at random places, until you reach the expected
+# result. Alternatively, if you are a quoting wizard, you directly
+# reach the following implementation (but if you really did, then
+# apply to the maintenance of m4sugar!).
+#
+# | # foreach(VAR, (LIST), STMT)
+# | m4_define([foreach], [m4_pushdef([$1])_foreach($@)m4_popdef([$1])])
+# | m4_define([_arg1], [[$1]])
+# | m4_define([_foreach],
+# | [m4_if($2, [()], ,
+# | [m4_define([$1], [_arg1$2])$3[]_foreach([$1], [(m4_shift$2)], [$3])])])
+#
+# which this time answers
+#
+# => echo a
+# => echo (b
+# => echo c)
+#
+# Bingo!
+#
+# Well, not quite.
+#
+# With a better look, you realize that the parens are more a pain than
+# a help: since anyway you need to quote properly the list, you end up
+# with always using an outermost pair of parens and an outermost pair
+# of quotes. Rejecting the parens both eases the implementation, and
+# simplifies the use:
+#
+# | # foreach(VAR, (LIST), STMT)
+# | m4_define([foreach], [m4_pushdef([$1])_foreach($@)m4_popdef([$1])])
+# | m4_define([_arg1], [$1])
+# | m4_define([_foreach],
+# | [m4_if($2, [], ,
+# | [m4_define([$1], [_arg1($2)])$3[]_foreach([$1], [m4_shift($2)], [$3])])])
+#
+#
+# Now, just replace the `$2' with `m4_quote($2)' in the outer `m4_if'
+# to improve robustness, and you come up with a nice implementation
+# that doesn't require extra parentheses in the user's LIST.
+#
+# But wait - now the algorithm is quadratic, because every recursion of
+# the algorithm keeps the entire LIST and merely adds another m4_shift to
+# the quoted text. If the user has a lot of elements in LIST, you can
+# bring the system to its knees with the memory m4 then requires, or trip
+# the m4 --nesting-limit recursion factor. The only way to avoid
+# quadratic growth is ensure m4_shift is expanded prior to the recursion.
+# Hence the design below.
+#
+# The M4 manual now includes a chapter devoted to this issue, with
+# the lessons learned from m4sugar. And still, this design is only
+# optimal for M4 1.6; see foreach.m4 for yet more comments on why
+# M4 1.4.x uses yet another implementation.
+
+
+# m4_foreach(VARIABLE, LIST, EXPRESSION)
+# --------------------------------------
+#
+# Expand EXPRESSION assigning each value of the LIST to VARIABLE.
+# LIST should have the form `item_1, item_2, ..., item_n', i.e. the
+# whole list must *quoted*. Quote members too if you don't want them
+# to be expanded.
+#
+# This macro is robust to active symbols:
+# | m4_define(active, [ACT, IVE])
+# | m4_foreach(Var, [active, active], [-Var-])
+# => -ACT--IVE--ACT--IVE-
+#
+# | m4_foreach(Var, [[active], [active]], [-Var-])
+# => -ACT, IVE--ACT, IVE-
+#
+# | m4_foreach(Var, [[[active]], [[active]]], [-Var-])
+# => -active--active-
+#
+# This macro is called frequently, so avoid extra expansions such as
+# m4_ifval and dnl. Also, since $2 might be quite large, try to use it
+# as little as possible in _m4_foreach; each extra use requires that much
+# more memory for expansion. So, rather than directly compare $2 against
+# [] and use m4_car/m4_cdr for recursion, we instead unbox the list (which
+# requires swapping the argument order in the helper), insert an ignored
+# third argument, and use m4_shift3 to detect when recursion is complete.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_foreach],
+[m4_if([$2], [], [],
+ [m4_pushdef([$1])_$0([$1], [$3], [], $2)m4_popdef([$1])])])
+
+m4_define([_m4_foreach],
+[m4_if([$#], [3], [],
+ [m4_define([$1], [$4])$2[]$0([$1], [$2], m4_shift3($@))])])
+
+
+# m4_foreach_w(VARIABLE, LIST, EXPRESSION)
+# ----------------------------------------
+#
+# Like m4_foreach, but the list is whitespace separated.
+#
+# This macro is robust to active symbols:
+# m4_foreach_w([Var], [ active
+# b act\
+# ive ], [-Var-])end
+# => -active--b--active-end
+#
+m4_define([m4_foreach_w],
+[m4_foreach([$1], m4_split(m4_normalize([$2]), [ ]), [$3])])
+
+
+# m4_map(MACRO, LIST)
+# m4_mapall(MACRO, LIST)
+# ----------------------
+# Invoke MACRO($1), MACRO($2) etc. where $1, $2... are the elements of
+# LIST. $1, $2... must in turn be lists, appropriate for m4_apply.
+# If LIST contains an empty sublist, m4_map skips the expansion of
+# MACRO, while m4_mapall expands MACRO with no arguments.
+#
+# Since LIST may be quite large, we want to minimize how often it
+# appears in the expansion. Rather than use m4_car/m4_cdr iteration,
+# we unbox the list, ignore the second argument, and use m4_shift2 to
+# detect the end of recursion. The mismatch in () is intentional; see
+# _m4_map. For m4_map, an empty list behaves like an empty sublist
+# and gets ignored; for m4_mapall, we must special-case the empty
+# list.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_map],
+[_m4_map([_m4_apply([$1]], [], $2)])
+
+m4_define([m4_mapall],
+[m4_if([$2], [], [],
+ [_m4_map([m4_apply([$1]], [], $2)])])
+
+
+# m4_map_sep(MACRO, SEPARATOR, LIST)
+# m4_mapall_sep(MACRO, SEPARATOR, LIST)
+# -------------------------------------
+# Invoke MACRO($1), SEPARATOR, MACRO($2), ..., MACRO($N) where $1,
+# $2... $N are the elements of LIST, and are in turn lists appropriate
+# for m4_apply. SEPARATOR is expanded, in order to allow the creation
+# of a list of arguments by using a single-quoted comma as the
+# separator. For each empty sublist, m4_map_sep skips the expansion
+# of MACRO and SEPARATOR, while m4_mapall_sep expands MACRO with no
+# arguments.
+#
+# For m4_mapall_sep, merely expand the first iteration without the
+# separator, then include separator as part of subsequent recursion;
+# but avoid extra expansion of LIST's side-effects via a helper macro.
+# For m4_map_sep, things are trickier - we don't know if the first
+# list element is an empty sublist, so we must define a self-modifying
+# helper macro and use that as the separator instead.
+m4_define([m4_map_sep],
+[m4_pushdef([m4_Sep], [m4_define([m4_Sep], _m4_defn([m4_unquote]))])]dnl
+[_m4_map([_m4_apply([m4_Sep([$2])[]$1]], [], $3)m4_popdef([m4_Sep])])
+
+m4_define([m4_mapall_sep],
+[m4_if([$3], [], [], [_$0([$1], [$2], $3)])])
+
+m4_define([_m4_mapall_sep],
+[m4_apply([$1], [$3])_m4_map([m4_apply([$2[]$1]], m4_shift2($@))])
+
+# _m4_map(PREFIX, IGNORED, SUBLIST, ...)
+# --------------------------------------
+# Common implementation for all four m4_map variants. The mismatch in
+# the number of () is intentional. PREFIX must supply a form of
+# m4_apply, the open `(', and the MACRO to be applied. Each iteration
+# then appends `,', the current SUBLIST and the closing `)', then
+# recurses to the next SUBLIST. IGNORED is an aid to ending recursion
+# efficiently.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([_m4_map],
+[m4_if([$#], [2], [],
+ [$1, [$3])$0([$1], m4_shift2($@))])])
+
+# m4_transform(EXPRESSION, ARG...)
+# --------------------------------
+# Expand EXPRESSION([ARG]) for each argument. More efficient than
+# m4_foreach([var], [ARG...], [EXPRESSION(m4_defn([var]))])
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_transform],
+[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
+ [$#], [1], [],
+ [$#], [2], [$1([$2])[]],
+ [$1([$2])[]$0([$1], m4_shift2($@))])])
+
+
+# m4_transform_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...)
+# --------------------------------------------------------------
+# Perform a pairwise grouping of consecutive ARGs, by expanding
+# EXPRESSION([ARG1], [ARG2]). If there are an odd number of ARGs, the
+# final argument is expanded with END-EXPR([ARGn]).
+#
+# For example:
+# m4_define([show], [($*)m4_newline])dnl
+# m4_transform_pair([show], [], [a], [b], [c], [d], [e])dnl
+# => (a,b)
+# => (c,d)
+# => (e)
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_transform_pair],
+[m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
+ [$#], [1], [m4_fatal([$0: too few arguments: $#: $1])],
+ [$#], [2], [],
+ [$#], [3], [m4_default([$2], [$1])([$3])[]],
+ [$#], [4], [$1([$3], [$4])[]],
+ [$1([$3], [$4])[]$0([$1], [$2], m4_shift(m4_shift3($@)))])])
+
+
+## --------------------------- ##
+## 9. More diversion support. ##
+## --------------------------- ##
+
+
+# _m4_divert(DIVERSION-NAME or NUMBER)
+# ------------------------------------
+# If DIVERSION-NAME is the name of a diversion, return its number,
+# otherwise if it is a NUMBER return it.
+m4_define([_m4_divert],
+[m4_ifdef([_m4_divert($1)],
+ [m4_indir([_m4_divert($1)])],
+ [$1])])
+
+# KILL is only used to suppress output.
+m4_define([_m4_divert(KILL)], -1)
+
+# The empty diversion name is a synonym for 0.
+m4_define([_m4_divert()], 0)
+
+
+# _m4_divert_n_stack
+# ------------------
+# Print m4_divert_stack with newline prepended, if it's nonempty.
+m4_define([_m4_divert_n_stack],
+[m4_ifdef([m4_divert_stack], [
+_m4_defn([m4_divert_stack])])])
+
+
+# m4_divert(DIVERSION-NAME)
+# -------------------------
+# Change the diversion stream to DIVERSION-NAME.
+m4_define([m4_divert],
+[m4_define([m4_divert_stack], m4_location[: $0: $1]_m4_divert_n_stack)]dnl
+[m4_builtin([divert], _m4_divert([$1]))])
+
+
+# m4_divert_push(DIVERSION-NAME)
+# ------------------------------
+# Change the diversion stream to DIVERSION-NAME, while stacking old values.
+m4_define([m4_divert_push],
+[m4_pushdef([m4_divert_stack], m4_location[: $0: $1]_m4_divert_n_stack)]dnl
+[m4_pushdef([_m4_divert_diversion], [$1])]dnl
+[m4_builtin([divert], _m4_divert([$1]))])
+
+
+# m4_divert_pop([DIVERSION-NAME])
+# -------------------------------
+# Change the diversion stream to its previous value, unstacking it.
+# If specified, verify we left DIVERSION-NAME.
+# When we pop the last value from the stack, we divert to -1.
+m4_define([m4_divert_pop],
+[m4_ifndef([_m4_divert_diversion],
+ [m4_fatal([too many m4_divert_pop])])]dnl
+[m4_if([$1], [], [],
+ [$1], _m4_defn([_m4_divert_diversion]), [],
+ [m4_fatal([$0($1): diversion mismatch: ]_m4_divert_n_stack)])]dnl
+[_m4_popdef([m4_divert_stack], [_m4_divert_diversion])]dnl
+[m4_builtin([divert],
+ m4_ifdef([_m4_divert_diversion],
+ [_m4_divert(_m4_defn([_m4_divert_diversion]))],
+ -1))])
+
+
+# m4_divert_text(DIVERSION-NAME, CONTENT)
+# ---------------------------------------
+# Output CONTENT into DIVERSION-NAME (which may be a number actually).
+# An end of line is appended for free to CONTENT.
+m4_define([m4_divert_text],
+[m4_divert_push([$1])$2
+m4_divert_pop([$1])])
+
+
+# m4_divert_once(DIVERSION-NAME, CONTENT)
+# ---------------------------------------
+# Output CONTENT into DIVERSION-NAME once, if not already there.
+# An end of line is appended for free to CONTENT.
+m4_define([m4_divert_once],
+[m4_expand_once([m4_divert_text([$1], [$2])])])
+
+
+# m4_undivert(DIVERSION-NAME)
+# ---------------------------
+# Undivert DIVERSION-NAME. Unlike the M4 version, this only takes a single
+# diversion identifier, and should not be used to undivert files.
+m4_define([m4_undivert],
+[m4_builtin([undivert], _m4_divert([$1]))])
+
+
+## --------------------------------------------- ##
+## 10. Defining macros with bells and whistles. ##
+## --------------------------------------------- ##
+
+# `m4_defun' is basically `m4_define' but it equips the macro with the
+# needed machinery for `m4_require'. A macro must be m4_defun'd if
+# either it is m4_require'd, or it m4_require's.
+#
+# Two things deserve attention and are detailed below:
+# 1. Implementation of m4_require
+# 2. Keeping track of the expansion stack
+#
+# 1. Implementation of m4_require
+# ===============================
+#
+# Of course m4_defun AC_PROVIDE's the macro, so that a macro which has
+# been expanded is not expanded again when m4_require'd, but the
+# difficult part is the proper expansion of macros when they are
+# m4_require'd.
+#
+# The implementation is based on two ideas, (i) using diversions to
+# prepare the expansion of the macro and its dependencies (by Franc,ois
+# Pinard), and (ii) expand the most recently m4_require'd macros _after_
+# the previous macros (by Axel Thimm).
+#
+#
+# The first idea: why use diversions?
+# -----------------------------------
+#
+# When a macro requires another, the other macro is expanded in new
+# diversion, GROW. When the outer macro is fully expanded, we first
+# undivert the most nested diversions (GROW - 1...), and finally
+# undivert GROW. To understand why we need several diversions,
+# consider the following example:
+#
+# | m4_defun([TEST1], [Test...REQUIRE([TEST2])1])
+# | m4_defun([TEST2], [Test...REQUIRE([TEST3])2])
+# | m4_defun([TEST3], [Test...3])
+#
+# Because m4_require is not required to be first in the outer macros, we
+# must keep the expansions of the various levels of m4_require separated.
+# Right before executing the epilogue of TEST1, we have:
+#
+# GROW - 2: Test...3
+# GROW - 1: Test...2
+# GROW: Test...1
+# BODY:
+#
+# Finally the epilogue of TEST1 undiverts GROW - 2, GROW - 1, and
+# GROW into the regular flow, BODY.
+#
+# GROW - 2:
+# GROW - 1:
+# GROW:
+# BODY: Test...3; Test...2; Test...1
+#
+# (The semicolons are here for clarification, but of course are not
+# emitted.) This is what Autoconf 2.0 (I think) to 2.13 (I'm sure)
+# implement.
+#
+#
+# The second idea: first required first out
+# -----------------------------------------
+#
+# The natural implementation of the idea above is buggy and produces
+# very surprising results in some situations. Let's consider the
+# following example to explain the bug:
+#
+# | m4_defun([TEST1], [REQUIRE([TEST2a])REQUIRE([TEST2b])])
+# | m4_defun([TEST2a], [])
+# | m4_defun([TEST2b], [REQUIRE([TEST3])])
+# | m4_defun([TEST3], [REQUIRE([TEST2a])])
+# |
+# | AC_INIT
+# | TEST1
+#
+# The dependencies between the macros are:
+#
+# 3 --- 2b
+# / \ is m4_require'd by
+# / \ left -------------------- right
+# 2a ------------ 1
+#
+# If you strictly apply the rules given in the previous section you get:
+#
+# GROW - 2: TEST3
+# GROW - 1: TEST2a; TEST2b
+# GROW: TEST1
+# BODY:
+#
+# (TEST2a, although required by TEST3 is not expanded in GROW - 3
+# because is has already been expanded before in GROW - 1, so it has
+# been AC_PROVIDE'd, so it is not expanded again) so when you undivert
+# the stack of diversions, you get:
+#
+# GROW - 2:
+# GROW - 1:
+# GROW:
+# BODY: TEST3; TEST2a; TEST2b; TEST1
+#
+# i.e., TEST2a is expanded after TEST3 although the latter required the
+# former.
+#
+# Starting from 2.50, we use an implementation provided by Axel Thimm.
+# The idea is simple: the order in which macros are emitted must be the
+# same as the one in which macros are expanded. (The bug above can
+# indeed be described as: a macro has been AC_PROVIDE'd before its
+# dependent, but it is emitted after: the lack of correlation between
+# emission and expansion order is guilty).
+#
+# How to do that? You keep the stack of diversions to elaborate the
+# macros, but each time a macro is fully expanded, emit it immediately.
+#
+# In the example above, when TEST2a is expanded, but it's epilogue is
+# not run yet, you have:
+#
+# GROW - 2:
+# GROW - 1: TEST2a
+# GROW: Elaboration of TEST1
+# BODY:
+#
+# The epilogue of TEST2a emits it immediately:
+#
+# GROW - 2:
+# GROW - 1:
+# GROW: Elaboration of TEST1
+# BODY: TEST2a
+#
+# TEST2b then requires TEST3, so right before the epilogue of TEST3, you
+# have:
+#
+# GROW - 2: TEST3
+# GROW - 1: Elaboration of TEST2b
+# GROW: Elaboration of TEST1
+# BODY: TEST2a
+#
+# The epilogue of TEST3 emits it:
+#
+# GROW - 2:
+# GROW - 1: Elaboration of TEST2b
+# GROW: Elaboration of TEST1
+# BODY: TEST2a; TEST3
+#
+# TEST2b is now completely expanded, and emitted:
+#
+# GROW - 2:
+# GROW - 1:
+# GROW: Elaboration of TEST1
+# BODY: TEST2a; TEST3; TEST2b
+#
+# and finally, TEST1 is finished and emitted:
+#
+# GROW - 2:
+# GROW - 1:
+# GROW:
+# BODY: TEST2a; TEST3; TEST2b: TEST1
+#
+# The idea is simple, but the implementation is a bit evolved. If you
+# are like me, you will want to see the actual functioning of this
+# implementation to be convinced. The next section gives the full
+# details.
+#
+#
+# The Axel Thimm implementation at work
+# -------------------------------------
+#
+# We consider the macros above, and this configure.ac:
+#
+# AC_INIT
+# TEST1
+#
+# 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
+# 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
+# the previous versions of Autoconf: you cannot use m4_require if you
+# are not inside an m4_defun'd macro, and especially, you cannot
+# m4_require directly from the top level.
+#
+# We have not tried to simulate the old behavior (better yet, we
+# diagnose it), because it is too dangerous: a macro m4_require'd from
+# the top level is expanded before the body of `configure', i.e., before
+# any other test was run. I let you imagine the result of requiring
+# AC_STDC_HEADERS for instance, before AC_PROG_CC was actually run....
+#
+# After AC_INIT was run, the current diversion is BODY.
+# * AC_INIT was run
+# DUMP: undefined
+# diversion stack: BODY |-
+#
+# * TEST1 is expanded
+# The prologue of TEST1 sets _m4_divert_dump, which is the diversion
+# where the current elaboration will be dumped, to the current
+# diversion. It also m4_divert_push to GROW, where the full
+# expansion of TEST1 and its dependencies will be elaborated.
+# DUMP: BODY
+# BODY: empty
+# diversions: GROW, BODY |-
+#
+# * TEST1 requires TEST2a
+# _m4_require_call m4_divert_pushes another temporary diversion,
+# GROW - 1, and expands TEST2a in there.
+# DUMP: BODY
+# BODY: empty
+# GROW - 1: TEST2a
+# diversions: GROW - 1, GROW, BODY |-
+# Than the content of the temporary diversion is moved to DUMP and the
+# temporary diversion is popped.
+# DUMP: BODY
+# BODY: TEST2a
+# diversions: GROW, BODY |-
+#
+# * TEST1 requires TEST2b
+# Again, _m4_require_call pushes GROW - 1 and heads to expand TEST2b.
+# DUMP: BODY
+# BODY: TEST2a
+# diversions: GROW - 1, GROW, BODY |-
+#
+# * TEST2b requires TEST3
+# _m4_require_call pushes GROW - 2 and expands TEST3 here.
+# (TEST3 requires TEST2a, but TEST2a has already been m4_provide'd, so
+# nothing happens.)
+# DUMP: BODY
+# BODY: TEST2a
+# GROW - 2: TEST3
+# diversions: GROW - 2, GROW - 1, GROW, BODY |-
+# Than the diversion is appended to DUMP, and popped.
+# DUMP: BODY
+# BODY: TEST2a; TEST3
+# diversions: GROW - 1, GROW, BODY |-
+#
+# * TEST1 requires TEST2b (contd.)
+# The content of TEST2b is expanded...
+# DUMP: BODY
+# BODY: TEST2a; TEST3
+# GROW - 1: TEST2b,
+# diversions: GROW - 1, GROW, BODY |-
+# ... and moved to DUMP.
+# DUMP: BODY
+# BODY: TEST2a; TEST3; TEST2b
+# diversions: GROW, BODY |-
+#
+# * TEST1 is expanded: epilogue
+# TEST1's own content is in GROW...
+# DUMP: BODY
+# BODY: TEST2a; TEST3; TEST2b
+# GROW: TEST1
+# diversions: BODY |-
+# ... and it's epilogue moves it to DUMP and then undefines DUMP.
+# DUMP: undefined
+# BODY: TEST2a; TEST3; TEST2b; TEST1
+# diversions: BODY |-
+#
+#
+# 2. Keeping track of the expansion stack
+# =======================================
+#
+# When M4 expansion goes wrong it is often extremely hard to find the
+# path amongst macros that drove to the failure. What is needed is
+# the stack of macro `calls'. One could imagine that GNU M4 would
+# maintain a stack of macro expansions, unfortunately it doesn't, so
+# we do it by hand. This is of course extremely costly, but the help
+# this stack provides is worth it. Nevertheless to limit the
+# performance penalty this is implemented only for m4_defun'd macros,
+# not for define'd macros.
+#
+# The scheme is simplistic: each time we enter an m4_defun'd macros,
+# 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 detect circular m4_require dependencies.
+# Each time we expand a macro FOO we define _m4_expanding(FOO); and
+# m4_require(BAR) simply checks whether _m4_expanding(BAR) is defined.
+
+
+# m4_expansion_stack_push(TEXT)
+# -----------------------------
+m4_define([m4_expansion_stack_push],
+[m4_pushdef([m4_expansion_stack],
+ [$1]m4_ifdef([m4_expansion_stack], [
+_m4_defn([m4_expansion_stack])]))])
+
+
+# m4_expansion_stack_pop
+# ----------------------
+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_ifdef([m4_expansion_stack],
+ [m4_errprintn(_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
+# important to keep room before GROW because for each nested
+# AC_REQUIRE we use an additional diversion (i.e., two m4_require's
+# will use GROW - 2. More than 3 levels has never seemed to be
+# needed.)
+#
+# ...
+# - GROW - 2
+# m4_require'd code, 2 level deep
+# - GROW - 1
+# m4_require'd code, 1 level deep
+# - GROW
+# m4_defun'd macros are elaborated here.
+
+m4_define([_m4_divert(GROW)], 10000)
+
+
+# _m4_defun_pro(MACRO-NAME)
+# -------------------------
+# The prologue for Autoconf macros.
+#
+# 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_define([_m4_defun_pro_outer],
+[m4_copy([_m4_divert_diversion], [_m4_divert_dump])m4_divert_push([GROW])])
+
+# _m4_defun_epi(MACRO-NAME)
+# -------------------------
+# The Epilogue for Autoconf macros. MACRO-NAME only helps tracing
+# the PRO/EPI pairs.
+#
+# 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_define([_m4_defun_epi_outer],
+[_m4_undefine([_m4_divert_dump])m4_divert_pop([GROW])m4_undivert([GROW])])
+
+
+# m4_defun(NAME, EXPANSION)
+# -------------------------
+# Define a macro which automatically provides itself. Add machinery
+# so the macro automatically switches expansion to the diversion
+# stack if it is not already using it. In this case, once finished,
+# it will bring back all the code accumulated in the diversion stack.
+# This, combined with m4_require, achieves the topological ordering of
+# macros. We don't use this macro to define some frequently called
+# macros that are not involved in ordering constraints, to save m4
+# processing.
+m4_define([m4_defun],
+[m4_define([m4_location($1)], m4_location)dnl
+m4_define([$1],
+ [_m4_defun_pro([$1])$2[]_m4_defun_epi([$1])])])
+
+
+# m4_defun_once(NAME, EXPANSION)
+# ------------------------------
+# As m4_defun, but issues the EXPANSION only once, and warns if used
+# several times.
+m4_define([m4_defun_once],
+[m4_define([m4_location($1)], m4_location)dnl
+m4_define([$1],
+ [m4_provide_if([$1],
+ [m4_warn([syntax], [$1 invoked multiple times])],
+ [_m4_defun_pro([$1])$2[]_m4_defun_epi([$1])])])])
+
+
+# m4_pattern_forbid(ERE, [WHY])
+# -----------------------------
+# Declare that no token matching the forbidden extended regular
+# expression ERE should be seen in the output unless...
+m4_define([m4_pattern_forbid], [])
+
+
+# m4_pattern_allow(ERE)
+# ---------------------
+# ... that token also matches the allowed extended regular expression ERE.
+# Both used via traces.
+m4_define([m4_pattern_allow], [])
+
+
+## --------------------------------- ##
+## 11. Dependencies between macros. ##
+## --------------------------------- ##
+
+
+# m4_before(THIS-MACRO-NAME, CALLED-MACRO-NAME)
+# ---------------------------------------------
+# Issue a warning if CALLED-MACRO-NAME was called before THIS-MACRO-NAME.
+m4_define([m4_before],
+[m4_provide_if([$2],
+ [m4_warn([syntax], [$2 was called before $1])])])
+
+
+# m4_require(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK])
+# -----------------------------------------------------------
+# 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.
+#
+# The normal cases are:
+#
+# - NAME-TO-CHECK == BODY-TO-EXPAND
+# Which you can use for regular macros with or without arguments, e.g.,
+# m4_require([AC_PROG_CC], [AC_PROG_CC])
+# m4_require([AC_CHECK_HEADERS(limits.h)], [AC_CHECK_HEADERS(limits.h)])
+# which is just the same as
+# m4_require([AC_PROG_CC])
+# m4_require([AC_CHECK_HEADERS(limits.h)])
+#
+# - BODY-TO-EXPAND == m4_indir([NAME-TO-CHECK])
+# In the case of macros with irregular names. For instance:
+# m4_require([AC_LANG_COMPILER(C)], [indir([AC_LANG_COMPILER(C)])])
+# which means `if the macro named `AC_LANG_COMPILER(C)' (the parens are
+# part of the name, it is not an argument) has not been run, then
+# call it.'
+# Had you used
+# m4_require([AC_LANG_COMPILER(C)], [AC_LANG_COMPILER(C)])
+# then m4_require would have tried to expand `AC_LANG_COMPILER(C)', i.e.,
+# call the macro `AC_LANG_COMPILER' with `C' as argument.
+#
+# You could argue that `AC_LANG_COMPILER', when it receives an argument
+# such as `C' should dispatch the call to `AC_LANG_COMPILER(C)'. But this
+# `extension' prevents `AC_LANG_COMPILER' from having actual arguments that
+# it passes to `AC_LANG_COMPILER(C)'.
+#
+# This is called frequently, so minimize the number of macro invocations
+# by avoiding dnl and other overhead on the common path.
+m4_define([m4_require],
+m4_do([[m4_ifdef([_m4_expanding($1)],
+ [m4_fatal([$0: circular dependency of $1])])]],
+ [[m4_ifdef([_m4_divert_dump], [],
+ [m4_fatal([$0($1): cannot be used outside of an ]dnl
+m4_bmatch([$0], [^AC_], [[AC_DEFUN]], [[m4_defun]])['d macro])])]],
+ [[m4_provide_if([$1],
+ [],
+ [_m4_require_call([$1], [$2])])]]))
+
+
+# _m4_require_call(NAME-TO-CHECK, [BODY-TO-EXPAND = NAME-TO-CHECK])
+# -----------------------------------------------------------------
+# If m4_require decides to expand the body, it calls this macro.
+#
+# This is called frequently, so minimize the number of macro invocations
+# by avoiding dnl and other overhead on the common path.
+m4_define([_m4_require_call],
+m4_do([[m4_define([_m4_divert_grow], m4_decr(_m4_divert_grow))]],
+ [[m4_divert_push(_m4_divert_grow)]],
+ [[m4_default([$2], [$1])
+m4_provide_if([$1],
+ [],
+ [m4_warn([syntax],
+ [$1 is m4_require'd but not m4_defun'd])])]],
+ [[m4_divert(_m4_defn([_m4_divert_dump]))]],
+ [[m4_undivert(_m4_divert_grow)]],
+ [[m4_divert_pop(_m4_divert_grow)]],
+ [[m4_define([_m4_divert_grow], m4_incr(_m4_divert_grow))]]))
+
+
+# _m4_divert_grow
+# ---------------
+# The counter for _m4_require_call.
+m4_define([_m4_divert_grow], _m4_divert([GROW]))
+
+
+# m4_expand_once(TEXT, [WITNESS = TEXT])
+# --------------------------------------
+# If TEXT has never been expanded, expand it *here*. Use WITNESS as
+# as a memory that TEXT has already been expanded.
+m4_define([m4_expand_once],
+[m4_provide_if(m4_ifval([$2], [[$2]], [[$1]]),
+ [],
+ [m4_provide(m4_ifval([$2], [[$2]], [[$1]]))[]$1])])
+
+
+# m4_provide(MACRO-NAME)
+# ----------------------
+m4_define([m4_provide],
+[m4_define([m4_provide($1)])])
+
+
+# m4_provide_if(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
+# -------------------------------------------------------
+# If MACRO-NAME is provided do IF-PROVIDED, else IF-NOT-PROVIDED.
+# The purpose of this macro is to provide the user with a means to
+# check macros which are provided without letting her know how the
+# information is coded.
+m4_define([m4_provide_if],
+[m4_ifdef([m4_provide($1)],
+ [$2], [$3])])
+
+
+## --------------------- ##
+## 12. Text processing. ##
+## --------------------- ##
+
+
+# m4_cr_letters
+# m4_cr_LETTERS
+# m4_cr_Letters
+# -------------
+m4_define([m4_cr_letters], [abcdefghijklmnopqrstuvwxyz])
+m4_define([m4_cr_LETTERS], [ABCDEFGHIJKLMNOPQRSTUVWXYZ])
+m4_define([m4_cr_Letters],
+m4_defn([m4_cr_letters])dnl
+m4_defn([m4_cr_LETTERS])dnl
+)
+
+
+# m4_cr_digits
+# ------------
+m4_define([m4_cr_digits], [0123456789])
+
+
+# m4_cr_alnum
+# -----------
+m4_define([m4_cr_alnum],
+m4_defn([m4_cr_Letters])dnl
+m4_defn([m4_cr_digits])dnl
+)
+
+
+# m4_cr_symbols1
+# m4_cr_symbols2
+# -------------------------------
+m4_define([m4_cr_symbols1],
+m4_defn([m4_cr_Letters])dnl
+_)
+
+m4_define([m4_cr_symbols2],
+m4_defn([m4_cr_symbols1])dnl
+m4_defn([m4_cr_digits])dnl
+)
+
+# m4_cr_all
+# ---------
+# The character range representing everything, with `-' as the last
+# character, since it is special to m4_translit. Use with care, because
+# it contains characters special to M4 (fortunately, both ASCII and EBCDIC
+# have [] in order, so m4_defn([m4_cr_all]) remains a valid string). It
+# also contains characters special to terminals, so it should never be
+# displayed in an error message. Also, attempts to map [ and ] to other
+# characters via m4_translit must deal with the fact that m4_translit does
+# not add quotes to the output.
+#
+# It is mainly useful in generating inverted character range maps, for use
+# in places where m4_translit is faster than an equivalent m4_bpatsubst;
+# the regex `[^a-z]' is equivalent to:
+# m4_translit(m4_dquote(m4_defn([m4_cr_all])), [a-z])
+m4_define([m4_cr_all],
+m4_translit(m4_dquote(m4_format(m4_dquote(m4_for(
+ ,1,255,,[[%c]]))m4_for([i],1,255,,[,i]))), [-])-)
+
+
+# _m4_define_cr_not(CATEGORY)
+# ---------------------------
+# Define m4_cr_not_CATEGORY as the inverse of m4_cr_CATEGORY.
+m4_define([_m4_define_cr_not],
+[m4_define([m4_cr_not_$1],
+ m4_translit(m4_dquote(m4_defn([m4_cr_all])),
+ m4_defn([m4_cr_$1])))])
+
+
+# m4_cr_not_letters
+# m4_cr_not_LETTERS
+# m4_cr_not_Letters
+# m4_cr_not_digits
+# m4_cr_not_alnum
+# m4_cr_not_symbols1
+# m4_cr_not_symbols2
+# ------------------
+# Inverse character sets
+_m4_define_cr_not([letters])
+_m4_define_cr_not([LETTERS])
+_m4_define_cr_not([Letters])
+_m4_define_cr_not([digits])
+_m4_define_cr_not([alnum])
+_m4_define_cr_not([symbols1])
+_m4_define_cr_not([symbols2])
+
+
+# m4_newline
+# ----------
+# Expands to a newline. Exists for formatting reasons.
+m4_define([m4_newline], [
+])
+
+
+# m4_re_escape(STRING)
+# --------------------
+# Escape RE active characters in STRING.
+m4_define([m4_re_escape],
+[m4_bpatsubst([$1],
+ [[][*+.?\^$]], [\\\&])])
+
+
+# m4_re_string
+# ------------
+# Regexp for `[a-zA-Z_0-9]*'
+# m4_dquote provides literal [] for the character class.
+m4_define([m4_re_string],
+m4_dquote(m4_defn([m4_cr_symbols2]))dnl
+[*]dnl
+)
+
+
+# m4_re_word
+# ----------
+# Regexp for `[a-zA-Z_][a-zA-Z_0-9]*'
+m4_define([m4_re_word],
+m4_dquote(m4_defn([m4_cr_symbols1]))dnl
+m4_defn([m4_re_string])dnl
+)
+
+
+# m4_tolower(STRING)
+# m4_toupper(STRING)
+# ------------------
+# These macros convert STRING to lowercase or uppercase.
+#
+# Rather than expand the m4_defn each time, we inline them up front.
+m4_define([m4_tolower],
+[m4_translit([$1], ]m4_dquote(m4_defn([m4_cr_LETTERS]))[,
+ ]m4_dquote(m4_defn([m4_cr_letters]))[)])
+m4_define([m4_toupper],
+[m4_translit([$1], ]m4_dquote(m4_defn([m4_cr_letters]))[,
+ ]m4_dquote(m4_defn([m4_cr_LETTERS]))[)])
+
+
+# m4_split(STRING, [REGEXP])
+# --------------------------
+#
+# Split STRING into an m4 list of quoted elements. The elements are
+# quoted with [ and ]. Beginning spaces and end spaces *are kept*.
+# Use m4_strip to remove them.
+#
+# REGEXP specifies where to split. Default is [\t ]+.
+#
+# If STRING is empty, the result is an empty list.
+#
+# Pay attention to the m4_changequotes. When m4 reads the definition of
+# m4_split, it still has quotes set to [ and ]. Luckily, these are matched
+# in the macro body, so the definition is stored correctly. Use the same
+# alternate quotes as m4_noquote; it must be unlikely to appear in $1.
+#
+# Also, notice that $1 is quoted twice, since we want the result to
+# be quoted. Then you should understand that the argument of
+# patsubst is -=<{(STRING)}>=- (i.e., with additional -=<{( and )}>=-).
+#
+# This macro is safe on active symbols, i.e.:
+# m4_define(active, ACTIVE)
+# m4_split([active active ])end
+# => [active], [active], []end
+#
+# Optimize on regex of ` ' (space), since m4_foreach_w already guarantees
+# that the list contains single space separators, and a common case is
+# splitting a single-element list. This macro is called frequently,
+# so avoid unnecessary dnl inside the definition.
+m4_define([m4_split],
+[m4_if([$1], [], [],
+ [$2], [ ], [m4_if(m4_index([$1], [ ]), [-1], [[[$1]]], [_$0($@)])],
+ [$2], [], [_$0([$1], [[ ]+])],
+ [_$0($@)])])
+
+m4_define([_m4_split],
+[m4_changequote([-=<{(],[)}>=-])]dnl
+[[m4_bpatsubst(-=<{(-=<{($1)}>=-)}>=-, -=<{($2)}>=-,
+ -=<{(], [)}>=-)]m4_changequote([, ])])
+
+
+
+# m4_flatten(STRING)
+# ------------------
+# If STRING contains end of lines, replace them with spaces. If there
+# are backslashed end of lines, remove them. This macro is safe with
+# active symbols.
+# m4_define(active, ACTIVE)
+# m4_flatten([active
+# act\
+# ive])end
+# => active activeend
+#
+# In m4, m4_bpatsubst is expensive, so first check for a newline.
+m4_define([m4_flatten],
+[m4_if(m4_index([$1], [
+]), [-1], [[$1]],
+ [m4_translit(m4_bpatsubst([[[$1]]], [\\
+]), [
+], [ ])])])
+
+
+# m4_strip(STRING)
+# ----------------
+# Expands into STRING with tabs and spaces singled out into a single
+# space, and removing leading and trailing spaces.
+#
+# This macro is robust to active symbols.
+# m4_define(active, ACTIVE)
+# m4_strip([ active <tab> <tab>active ])end
+# => active activeend
+#
+# First, notice that we guarantee trailing space. Why? Because regular
+# expressions are greedy, and `.* ?' would always group the space into the
+# .* portion. The algorithm is simpler by avoiding `?' at the end. The
+# algorithm correctly strips everything if STRING is just ` '.
+#
+# Then notice the second pattern: it is in charge of removing the
+# leading/trailing spaces. Why not just `[^ ]'? Because they are
+# applied to over-quoted strings, i.e. more or less [STRING], due
+# to the limitations of m4_bpatsubsts. So the leading space in STRING
+# is the *second* character; equally for the trailing space.
+m4_define([m4_strip],
+[m4_bpatsubsts([$1 ],
+ [[ ]+], [ ],
+ [^. ?\(.*\) .$], [[[\1]]])])
+
+
+# m4_normalize(STRING)
+# --------------------
+# Apply m4_flatten and m4_strip to STRING.
+#
+# The argument is quoted, so that the macro is robust to active symbols:
+#
+# m4_define(active, ACTIVE)
+# m4_normalize([ act\
+# ive
+# active ])end
+# => active activeend
+
+m4_define([m4_normalize],
+[m4_strip(m4_flatten([$1]))])
+
+
+
+# m4_join(SEP, ARG1, ARG2...)
+# ---------------------------
+# Produce ARG1SEPARG2...SEPARGn. Avoid back-to-back SEP when a given ARG
+# is the empty string. No expansion is performed on SEP or ARGs.
+#
+# Since the number of arguments to join can be arbitrarily long, we
+# want to avoid having more than one $@ in the macro definition;
+# otherwise, the expansion would require twice the memory of the already
+# long list. Hence, m4_join merely looks for the first non-empty element,
+# and outputs just that element; while _m4_join looks for all non-empty
+# elements, and outputs them following a separator. The final trick to
+# note is that we decide between recursing with $0 or _$0 based on the
+# nested m4_if ending with `_'.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_join],
+[m4_if([$#], [1], [],
+ [$#], [2], [[$2]],
+ [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift2($@))])])
+m4_define([_m4_join],
+[m4_if([$#$2], [2], [],
+ [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift2($@))])])
+
+# m4_joinall(SEP, ARG1, ARG2...)
+# ------------------------------
+# Produce ARG1SEPARG2...SEPARGn. An empty ARG results in back-to-back SEP.
+# No expansion is performed on SEP or ARGs.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_joinall], [[$2]_$0([$1], m4_shift($@))])
+m4_define([_m4_joinall],
+[m4_if([$#], [2], [], [[$1$3]$0([$1], m4_shift2($@))])])
+
+# m4_combine([SEPARATOR], PREFIX-LIST, [INFIX], SUFFIX...)
+# --------------------------------------------------------
+# Produce the pairwise combination of every element in the quoted,
+# comma-separated PREFIX-LIST with every element from the SUFFIX arguments.
+# Each pair is joined with INFIX, and pairs are separated by SEPARATOR.
+# No expansion occurs on SEPARATOR, INFIX, or elements of either list.
+#
+# For example:
+# m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
+# => a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
+#
+# In order to have the correct number of SEPARATORs, we use a temporary
+# variable that redefines itself after the first use. We must use defn
+# rather than overquoting in case PREFIX or SUFFIX contains $1, but use
+# _m4_defn for speed. Likewise, we compute the m4_shift3 only once,
+# rather than in each iteration of the outer m4_foreach.
+m4_define([m4_combine],
+[m4_if(m4_eval([$# > 3]), [1],
+ [m4_pushdef([m4_Separator], [m4_define([m4_Separator],
+ _m4_defn([m4_echo]))])]]dnl
+[[m4_foreach([m4_Prefix], [$2],
+ [m4_foreach([m4_Suffix], ]m4_dquote(m4_dquote(m4_shift3($@)))[,
+ [m4_Separator([$1])[]_m4_defn([m4_Prefix])[$3]_m4_defn(
+ [m4_Suffix])])])]]dnl
+[[_m4_popdef([m4_Separator])])])
+
+
+# m4_append(MACRO-NAME, STRING, [SEPARATOR])
+# ------------------------------------------
+# Redefine MACRO-NAME to hold its former content plus `SEPARATOR`'STRING'
+# at the end. It is valid to use this macro with MACRO-NAME undefined,
+# in which case no SEPARATOR is added. Be aware that the criterion is
+# `not being defined', and not `not being empty'.
+#
+# Note that neither STRING nor SEPARATOR are expanded here; rather, when
+# you expand MACRO-NAME, they will be expanded at that point in time.
+#
+# This macro is robust to active symbols. It can be used to grow
+# strings.
+#
+# | m4_define(active, ACTIVE)dnl
+# | m4_append([sentence], [This is an])dnl
+# | m4_append([sentence], [ active ])dnl
+# | m4_append([sentence], [symbol.])dnl
+# | sentence
+# | m4_undefine([active])dnl
+# | sentence
+# => This is an ACTIVE symbol.
+# => This is an active symbol.
+#
+# It can be used to define hooks.
+#
+# | m4_define(active, ACTIVE)dnl
+# | m4_append([hooks], [m4_define([act1], [act2])])dnl
+# | m4_append([hooks], [m4_define([act2], [active])])dnl
+# | m4_undefine([active])dnl
+# | act1
+# | hooks
+# | act1
+# => act1
+# =>
+# => active
+#
+# It can also be used to create lists, although this particular usage was
+# broken prior to autoconf 2.62.
+# | m4_append([list], [one], [, ])dnl
+# | m4_append([list], [two], [, ])dnl
+# | m4_append([list], [three], [, ])dnl
+# | list
+# | m4_dquote(list)
+# => one, two, three
+# => [one],[two],[three]
+#
+# Note that m4_append can benefit from amortized O(n) m4 behavior, if
+# the underlying m4 implementation is smart enough to avoid copying existing
+# contents when enlarging a macro's definition into any pre-allocated storage
+# (m4 1.4.x unfortunately does not implement this optimization). We do
+# not implement m4_prepend, since it is inherently O(n^2) (pre-allocated
+# storage only occurs at the end of a macro, so the existing contents must
+# always be moved).
+#
+# Use _m4_defn for speed.
+m4_define([m4_append],
+[m4_define([$1], m4_ifdef([$1], [_m4_defn([$1])[$3]])[$2])])
+
+
+# m4_append_uniq(MACRO-NAME, STRING, [SEPARATOR], [IF-UNIQ], [IF-DUP])
+# --------------------------------------------------------------------
+# Like `m4_append', but append only if not yet present. Additionally,
+# expand IF-UNIQ if STRING was appended, or IF-DUP if STRING was already
+# present. Also, warn if SEPARATOR is not empty and occurs within STRING,
+# as the algorithm no longer guarantees uniqueness.
+#
+# Note that while m4_append can be O(n) (depending on the quality of the
+# underlying M4 implementation), m4_append_uniq is inherently O(n^2)
+# because each append operation searches the entire string.
+m4_define([m4_append_uniq],
+[m4_ifval([$3], [m4_if(m4_index([$2], [$3]), [-1], [],
+ [m4_warn([syntax],
+ [$0: `$2' contains `$3'])])])_$0($@)])
+m4_define([_m4_append_uniq],
+[m4_ifdef([$1],
+ [m4_if(m4_index([$3]_m4_defn([$1])[$3], [$3$2$3]), [-1],
+ [m4_append([$1], [$2], [$3])$4], [$5])],
+ [m4_define([$1], [$2])$4])])
+
+# m4_append_uniq_w(MACRO-NAME, STRINGS)
+# -------------------------------------
+# For each of the words in the whitespace separated list STRINGS, append
+# only the unique strings to the definition of MACRO-NAME.
+#
+# Use _m4_defn for speed.
+m4_define([m4_append_uniq_w],
+[m4_foreach_w([m4_Word], [$2],
+ [_m4_append_uniq([$1], _m4_defn([m4_Word]), [ ])])])
+
+
+# m4_text_wrap(STRING, [PREFIX], [FIRST-PREFIX], [WIDTH])
+# -------------------------------------------------------
+# Expands into STRING wrapped to hold in WIDTH columns (default = 79).
+# If PREFIX is given, each line is prefixed with it. If FIRST-PREFIX is
+# specified, then the first line is prefixed with it. As a special case,
+# if the length of FIRST-PREFIX is greater than that of PREFIX, then
+# FIRST-PREFIX will be left alone on the first line.
+#
+# No expansion occurs on the contents STRING, PREFIX, or FIRST-PREFIX,
+# although quadrigraphs are correctly recognized.
+#
+# Typical outputs are:
+#
+# m4_text_wrap([Short string */], [ ], [/* ], 20)
+# => /* Short string */
+#
+# m4_text_wrap([Much longer string */], [ ], [/* ], 20)
+# => /* Much longer
+# => string */
+#
+# m4_text_wrap([Short doc.], [ ], [ --short ], 30)
+# => --short Short doc.
+#
+# m4_text_wrap([Short doc.], [ ], [ --too-wide ], 30)
+# => --too-wide
+# => Short doc.
+#
+# m4_text_wrap([Super long documentation.], [ ], [ --too-wide ], 30)
+# => --too-wide
+# => Super long
+# => documentation.
+#
+# FIXME: there is no checking of a longer PREFIX than WIDTH, but do
+# we really want to bother with people trying each single corner
+# of a software?
+#
+# This macro does not leave a trailing space behind the last word of a line,
+# which complicates it a bit. The algorithm is otherwise stupid and simple:
+# all the words are preceded by m4_Separator which is defined to empty for
+# the first word, and then ` ' (single space) for all the others.
+#
+# The algorithm uses a helper that uses $2 through $4 directly, rather than
+# using local variables, to avoid m4_defn overhead, or expansion swallowing
+# any $. It also bypasses m4_popdef overhead with _m4_popdef since no user
+# macro expansion occurs in the meantime. Also, the definition is written
+# with m4_do, to avoid time wasted on dnl during expansion (since this is
+# already a time-consuming macro).
+m4_define([m4_text_wrap],
+[_$0([$1], [$2], m4_if([$3], [], [[$2]], [[$3]]),
+ m4_if([$4], [], [79], [[$4]]))])
+m4_define([_m4_text_wrap],
+m4_do(dnl set up local variables, to avoid repeated calculations
+[[m4_pushdef([m4_Indent], m4_qlen([$2]))]],
+[[m4_pushdef([m4_Cursor], m4_qlen([$3]))]],
+[[m4_pushdef([m4_Separator], [m4_define([m4_Separator], [ ])])]],
+dnl expand the first prefix, then check its length vs. regular prefix
+dnl same length: nothing special
+dnl prefix1 longer: output on line by itself, and reset cursor
+dnl prefix1 shorter: pad to length of prefix, and reset cursor
+[[[$3]m4_cond([m4_Cursor], m4_Indent, [],
+ [m4_eval(m4_Cursor > m4_Indent)], [1], [
+[$2]m4_define([m4_Cursor], m4_Indent)],
+ [m4_format([%*s], m4_max([0],
+ m4_eval(m4_Indent - m4_Cursor)), [])m4_define([m4_Cursor], m4_Indent)])]],
+dnl now, for each word, compute the curser after the word is output, then
+dnl check if the cursor would exceed the wrap column
+dnl if so, reset cursor, and insert newline and prefix
+dnl if not, insert the separator (usually a space)
+dnl either way, insert the word
+[[m4_foreach_w([m4_Word], [$1],
+ [m4_define([m4_Cursor],
+ m4_eval(m4_Cursor + m4_qlen(_m4_defn([m4_Word]))
+ + 1))m4_if(m4_eval(m4_Cursor > ([$4])),
+ [1], [m4_define([m4_Cursor],
+ m4_eval(m4_Indent + m4_qlen(_m4_defn([m4_Word])) + 1))
+[$2]],
+ [m4_Separator[]])_m4_defn([m4_Word])])]],
+dnl finally, clean up the local variabls
+[[_m4_popdef([m4_Separator], [m4_Cursor], [m4_Indent])]]))
+
+
+# m4_text_box(MESSAGE, [FRAME-CHARACTER = `-'])
+# ---------------------------------------------
+# Turn MESSAGE into:
+# ## ------- ##
+# ## MESSAGE ##
+# ## ------- ##
+# using FRAME-CHARACTER in the border.
+m4_define([m4_text_box],
+[m4_pushdef([m4_Border],
+ m4_translit(m4_format([%*s], m4_qlen(m4_expand([$1])), []),
+ [ ], m4_if([$2], [], [[-]], [[$2]])))dnl
+@%:@@%:@ m4_Border @%:@@%:@
+@%:@@%:@ $1 @%:@@%:@
+@%:@@%:@ m4_Border @%:@@%:@_m4_popdef([m4_Border])dnl
+])
+
+
+# m4_qlen(STRING)
+# ---------------
+# Expands to the length of STRING after autom4te converts all quadrigraphs.
+#
+# Avoid bpatsubsts for the common case of no quadrigraphs.
+m4_define([m4_qlen],
+[m4_if(m4_index([$1], [@]), [-1], [m4_len([$1])],
+ [m4_len(m4_bpatsubst([[$1]],
+ [@\(\(<:\|:>\|S|\|%:\|\{:\|:\}\)\(@\)\|&t@\)],
+ [\3]))])])
+
+
+# m4_qdelta(STRING)
+# -----------------
+# Expands to the net change in the length of STRING from autom4te converting the
+# quadrigraphs in STRING. This number is always negative or zero.
+m4_define([m4_qdelta],
+[m4_eval(m4_qlen([$1]) - m4_len([$1]))])
+
+
+
+## ----------------------- ##
+## 13. Number processing. ##
+## ----------------------- ##
+
+# m4_cmp(A, B)
+# ------------
+# Compare two integer expressions.
+# A < B -> -1
+# A = B -> 0
+# A > B -> 1
+m4_define([m4_cmp],
+[m4_eval((([$1]) > ([$2])) - (([$1]) < ([$2])))])
+
+
+# m4_list_cmp(A, B)
+# -----------------
+#
+# Compare the two lists of integer expressions A and B. For instance:
+# m4_list_cmp([1, 0], [1]) -> 0
+# m4_list_cmp([1, 0], [1, 0]) -> 0
+# m4_list_cmp([1, 2], [1, 0]) -> 1
+# m4_list_cmp([1, 2, 3], [1, 2]) -> 1
+# m4_list_cmp([1, 2, -3], [1, 2]) -> -1
+# m4_list_cmp([1, 0], [1, 2]) -> -1
+# m4_list_cmp([1], [1, 2]) -> -1
+# m4_define([xa], [oops])dnl
+# m4_list_cmp([[0xa]], [5+5]) -> 0
+#
+# Rather than face the overhead of m4_case, we use a helper function whose
+# expansion includes the name of the macro to invoke on the tail, either
+# m4_ignore or m4_unquote. This is particularly useful when comparing
+# long lists, since less text is being expanded for deciding when to end
+# recursion. The recursion is between a pair of macros that alternate
+# which list is trimmed by one element; this is more efficient than
+# calling m4_cdr on both lists from a single macro. Guarantee exactly
+# one expansion of both lists' side effects.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_list_cmp],
+[_$0_raw(m4_dquote($1), m4_dquote($2))])
+
+m4_define([_m4_list_cmp_raw],
+[m4_if([$1], [$2], [0], [_m4_list_cmp_1([$1], $2)])])
+
+m4_define([_m4_list_cmp],
+[m4_if([$1], [], [0m4_ignore], [$2], [0], [m4_unquote], [$2m4_ignore])])
+
+m4_define([_m4_list_cmp_1],
+[_m4_list_cmp_2([$2], [m4_shift2($@)], $1)])
+
+m4_define([_m4_list_cmp_2],
+[_m4_list_cmp([$1$3], m4_cmp([$3+0], [$1+0]))(
+ [_m4_list_cmp_1(m4_dquote(m4_shift3($@)), $2)])])
+
+# m4_max(EXPR, ...)
+# m4_min(EXPR, ...)
+# -----------------
+# Return the decimal value of the maximum (or minimum) in a series of
+# integer expressions.
+#
+# M4 1.4.x doesn't provide ?:. Hence this huge m4_eval. Avoid m4_eval
+# if both arguments are identical, but be aware of m4_max(0xa, 10) (hence
+# the use of <=, not just <, in the second multiply).
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_max],
+[m4_if([$#], [0], [m4_fatal([too few arguments to $0])],
+ [$#], [1], [m4_eval([$1])],
+ [$#$1], [2$2], [m4_eval([$1])],
+ [$#], [2], [_$0($@)],
+ [_m4_minmax([_$0], $@)])])
+
+m4_define([_m4_max],
+[m4_eval((([$1]) > ([$2])) * ([$1]) + (([$1]) <= ([$2])) * ([$2]))])
+
+m4_define([m4_min],
+[m4_if([$#], [0], [m4_fatal([too few arguments to $0])],
+ [$#], [1], [m4_eval([$1])],
+ [$#$1], [2$2], [m4_eval([$1])],
+ [$#], [2], [_$0($@)],
+ [_m4_minmax([_$0], $@)])])
+
+m4_define([_m4_min],
+[m4_eval((([$1]) < ([$2])) * ([$1]) + (([$1]) >= ([$2])) * ([$2]))])
+
+# _m4_minmax(METHOD, ARG1, ARG2...)
+# ---------------------------------
+# Common recursion code for m4_max and m4_min. METHOD must be _m4_max
+# or _m4_min, and there must be at least two arguments to combine.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([_m4_minmax],
+[m4_if([$#], [3], [$1([$2], [$3])],
+ [$0([$1], $1([$2], [$3]), m4_shift3($@))])])
+
+
+# m4_sign(A)
+# ----------
+# The sign of the integer expression A.
+m4_define([m4_sign],
+[m4_eval((([$1]) > 0) - (([$1]) < 0))])
+
+
+
+## ------------------------ ##
+## 14. Version processing. ##
+## ------------------------ ##
+
+
+# m4_version_unletter(VERSION)
+# ----------------------------
+# Normalize beta version numbers with letters to numeric expressions, which
+# can then be handed to m4_eval for the purpose of comparison.
+#
+# Nl -> (N+1).-1.(l#)
+#
+# for example:
+# [2.14a] -> [2.14+1.-1.[0r36:a]] -> 2.15.-1.10
+# [2.14b] -> [2.15+1.-1.[0r36:b]] -> 2.15.-1.11
+# [2.61aa.b] -> [2.61+1.-1.[0r36:aa],+1.-1.[0r36:b]] -> 2.62.-1.370.1.-1.11
+#
+# This macro expects reasonable version numbers, but can handle double
+# letters and does not expand any macros. Original version strings can
+# use both `.' and `-' separators.
+#
+# Inline constant expansions, to avoid m4_defn overhead.
+# _m4_version_unletter is the real workhorse used by m4_version_compare,
+# but since [0r36:a] is less readable than 10, we provide a wrapper for
+# human use.
+m4_define([m4_version_unletter],
+[m4_map_sep([m4_eval], [.],
+ m4_dquote(m4_dquote_elt(m4_unquote(_$0([$1])))))])
+m4_define([_m4_version_unletter],
+[m4_bpatsubst(m4_translit([[[$1]]], [.-], [,,]),]dnl
+m4_dquote(m4_dquote(m4_defn([m4_cr_Letters])))[[+],
+ [+1,-1,[0r36:\&]])])
+
+
+# m4_version_compare(VERSION-1, VERSION-2)
+# ----------------------------------------
+# Compare the two version numbers and expand into
+# -1 if VERSION-1 < VERSION-2
+# 0 if =
+# 1 if >
+#
+# Since _m4_version_unletter does not output side effects, we can
+# safely bypass the overhead of m4_version_cmp.
+m4_define([m4_version_compare],
+[_m4_list_cmp_raw(_m4_version_unletter([$1]), _m4_version_unletter([$2]))])
+
+
+# m4_PACKAGE_NAME
+# m4_PACKAGE_TARNAME
+# m4_PACKAGE_VERSION
+# m4_PACKAGE_STRING
+# m4_PACKAGE_BUGREPORT
+# --------------------
+# If m4sugar/version.m4 is present, then define version strings. This
+# file is optional, provided by Autoconf but absent in Bison.
+m4_sinclude([m4sugar/version.m4])
+
+
+# m4_version_prereq(VERSION, [IF-OK], [IF-NOT = FAIL])
+# ----------------------------------------------------
+# Check this Autoconf version against VERSION.
+m4_define([m4_version_prereq],
+m4_ifdef([m4_PACKAGE_VERSION],
+[[m4_if(m4_version_compare(]m4_dquote(m4_defn([m4_PACKAGE_VERSION]))[, [$1]),
+ [-1],
+ [m4_default([$3],
+ [m4_fatal([Autoconf version $1 or higher is required],
+ [63])])],
+ [$2])]],
+[[m4_fatal([m4sugar/version.m4 not found])]]))
+
+
+## ------------------ ##
+## 15. Set handling. ##
+## ------------------ ##
+
+# Autoconf likes to create arbitrarily large sets; for example, as of
+# this writing, the configure.ac for coreutils tracks a set of more
+# than 400 AC_SUBST. How do we track all of these set members,
+# without introducing duplicates? We could use m4_append_uniq, with
+# the set NAME residing in the contents of the macro NAME.
+# Unfortunately, m4_append_uniq is quadratic for set creation, because
+# it costs O(n) to search the string for each of O(n) insertions; not
+# to mention that with m4 1.4.x, even using m4_append is slow, costing
+# O(n) rather than O(1) per insertion. Other set operations, not used
+# by Autoconf but still possible by manipulation of the definition
+# tracked in macro NAME, include O(n) deletion of one element and O(n)
+# computation of set size. Because the set is exposed to the user via
+# the definition of a single macro, we cannot cache any data about the
+# set without risking the cache being invalidated by the user
+# redefining NAME.
+#
+# Can we do better? Yes, because m4 gives us an O(1) search function
+# for free: ifdef. Additionally, even m4 1.4.x gives us an O(1)
+# insert operation for free: pushdef. But to use these, we must
+# represent the set via a group of macros; to keep the set consistent,
+# we must hide the set so that the user can only manipulate it through
+# accessor macros. The contents of the set are maintained through two
+# access points; _m4_set([name]) is a pushdef stack of values in the
+# set, useful for O(n) traversal of the set contents; while the
+# existence of _m4_set([name],value) with no particular value is
+# useful for O(1) querying of set membership. And since the user
+# cannot externally manipulate the set, we are free to add additional
+# caching macros for other performance improvements. Deletion can be
+# O(1) per element rather than O(n), by reworking the definition of
+# _m4_set([name],value) to be 0 or 1 based on current membership, and
+# adding _m4_set_cleanup(name) to defer the O(n) cleanup of
+# _m4_set([name]) until we have another reason to do an O(n)
+# traversal. The existence of _m4_set_cleanup(name) can then be used
+# elsewhere to determine if we must dereference _m4_set([name],value),
+# or assume that definition implies set membership. Finally, size can
+# be tracked in an O(1) fashion with _m4_set_size(name).
+#
+# The quoting in _m4_set([name],value) is chosen so that there is no
+# ambiguity with a set whose name contains a comma, and so that we can
+# supply the value via _m4_defn([_m4_set([name])]) without needing any
+# quote manipulation.
+
+# m4_set_add(SET, VALUE, [IF-UNIQ], [IF-DUP])
+# -------------------------------------------
+# Add VALUE as an element of SET. Expand IF-UNIQ on the first
+# addition, and IF-DUP if it is already in the set. Addition of one
+# element is O(1), such that overall set creation is O(n).
+#
+# We do not want to add a duplicate for a previously deleted but
+# unpruned element, but it is just as easy to check existence directly
+# as it is to query _m4_set_cleanup($1).
+m4_define([m4_set_add],
+[m4_ifdef([_m4_set([$1],$2)],
+ [m4_if(m4_indir([_m4_set([$1],$2)]), [0],
+ [m4_define([_m4_set([$1],$2)],
+ [1])_m4_set_size([$1], [m4_incr])$3], [$4])],
+ [m4_define([_m4_set([$1],$2)],
+ [1])m4_pushdef([_m4_set([$1])],
+ [$2])_m4_set_size([$1], [m4_incr])$3])])
+
+# m4_set_add_all(SET, VALUE...)
+# -----------------------------
+# Add each VALUE into SET. This is O(n) in the number of VALUEs, and
+# can be faster than calling m4_set_add for each VALUE.
+#
+# Implement two recursion helpers; the check variant is slower but
+# handles the case where an element has previously been removed but
+# not pruned. The recursion helpers ignore their second argument, so
+# that we can use the faster m4_shift2 and 2 arguments, rather than
+# _m4_shift2 and one argument, as the signal to end recursion.
+#
+# Please keep foreach.m4 in sync with any adjustments made here.
+m4_define([m4_set_add_all],
+[m4_define([_m4_set_size($1)], m4_eval(m4_set_size([$1])
+ + m4_len(m4_ifdef([_m4_set_cleanup($1)], [_$0_check], [_$0])([$1], $@))))])
+
+m4_define([_m4_set_add_all],
+[m4_if([$#], [2], [],
+ [m4_ifdef([_m4_set([$1],$3)], [],
+ [m4_define([_m4_set([$1],$3)], [1])m4_pushdef([_m4_set([$1])],
+ [$3])-])$0([$1], m4_shift2($@))])])
+
+m4_define([_m4_set_add_all_check],
+[m4_if([$#], [2], [],
+ [m4_set_add([$1], [$3])$0([$1], m4_shift2($@))])])
+
+# m4_set_contains(SET, VALUE, [IF-PRESENT], [IF-ABSENT])
+# ------------------------------------------------------
+# Expand IF-PRESENT if SET contains VALUE, otherwise expand IF-ABSENT.
+# This is always O(1).
+m4_define([m4_set_contains],
+[m4_ifdef([_m4_set_cleanup($1)],
+ [m4_if(m4_ifdef([_m4_set([$1],$2)],
+ [m4_indir([_m4_set([$1],$2)])], [0]), [1], [$3], [$4])],
+ [m4_ifdef([_m4_set([$1],$2)], [$3], [$4])])])
+
+# m4_set_contents(SET, [SEP])
+# ---------------------------
+# Expand to a single string containing all the elements in SET,
+# separated by SEP, without modifying SET. No provision is made for
+# disambiguating set elements that contain non-empty SEP as a
+# sub-string, or for recognizing a set that contains only the empty
+# string. Order of the output is not guaranteed. If any elements
+# have been previously removed from the set, this action will prune
+# the unused memory. This is O(n) in the size of the set before
+# pruning.
+#
+# Use _m4_popdef for speed. The existence of _m4_set_cleanup($1)
+# determines which version of _1 helper we use.
+m4_define([m4_set_contents],
+[m4_ifdef([_m4_set_cleanup($1)], [_$0_1c], [_$0_1])([$1])_$0_2([$1],
+ [_m4_defn([_m4_set_($1)])], [[$2]])])
+
+# _m4_set_contents_1(SET)
+# _m4_set_contents_1c(SET)
+# _m4_set_contents_2(SET, SEP, PREP)
+# ----------------------------------
+# Expand to a list of quoted elements currently in the set, separated
+# by SEP, and moving PREP in front of SEP on recursion. To avoid
+# nesting limit restrictions, the algorithm must be broken into two
+# parts; _1 destructively copies the stack in reverse into
+# _m4_set_($1), producing no output; then _2 destructively copies
+# _m4_set_($1) back into the stack in reverse. SEP is expanded while
+# _m4_set_($1) contains the current element, so a SEP containing
+# _m4_defn([_m4_set_($1)]) can produce output in the order the set was
+# created. Behavior is undefined if SEP tries to recursively list or
+# modify SET in any way other than calling m4_set_remove on the
+# current element. Use _1 if all entries in the stack are guaranteed
+# to be in the set, and _1c to prune removed entries. Uses _m4_defn
+# and _m4_popdef for speed.
+m4_define([_m4_set_contents_1],
+[m4_ifdef([_m4_set([$1])], [m4_pushdef([_m4_set_($1)],
+ _m4_defn([_m4_set([$1])]))_m4_popdef([_m4_set([$1])])$0([$1])])])
+
+m4_define([_m4_set_contents_1c],
+[m4_ifdef([_m4_set([$1])],
+ [m4_set_contains([$1], _m4_defn([_m4_set([$1])]),
+ [m4_pushdef([_m4_set_($1)], _m4_defn([_m4_set([$1])]))],
+ [_m4_popdef([_m4_set([$1],]_m4_defn(
+ [_m4_set([$1])])[)])])_m4_popdef([_m4_set([$1])])$0([$1])],
+ [_m4_popdef([_m4_set_cleanup($1)])])])
+
+m4_define([_m4_set_contents_2],
+[m4_ifdef([_m4_set_($1)], [m4_pushdef([_m4_set([$1])],
+ _m4_defn([_m4_set_($1)]))$2[]_m4_popdef([_m4_set_($1)])$0([$1], [$3$2])])])
+
+# m4_set_delete(SET)
+# ------------------
+# Delete all elements in SET, and reclaim any memory occupied by the
+# set. This is O(n) in the set size.
+#
+# Use _m4_defn and _m4_popdef for speed.
+m4_define([m4_set_delete],
+[m4_ifdef([_m4_set([$1])],
+ [_m4_popdef([_m4_set([$1],]_m4_defn([_m4_set([$1])])[)],
+ [_m4_set([$1])])$0([$1])],
+ [m4_ifdef([_m4_set_cleanup($1)],
+ [_m4_popdef([_m4_set_cleanup($1)])])m4_ifdef(
+ [_m4_set_size($1)],
+ [_m4_popdef([_m4_set_size($1)])])])])
+
+# m4_set_difference(SET1, SET2)
+# -----------------------------
+# Produce a LIST of quoted elements that occur in SET1 but not SET2.
+# Output a comma prior to any elements, to distinguish the empty
+# string from no elements. This can be directly used as a series of
+# arguments, such as for m4_join, or wrapped inside quotes for use in
+# m4_foreach. Order of the output is not guaranteed.
+#
+# Short-circuit the idempotence relation. Use _m4_defn for speed.
+m4_define([m4_set_difference],
+[m4_if([$1], [$2], [],
+ [m4_set_foreach([$1], [_m4_element],
+ [m4_set_contains([$2], _m4_defn([_m4_element]), [],
+ [,_m4_defn([_m4_element])])])])])
+
+# m4_set_dump(SET, [SEP])
+# -----------------------
+# Expand to a single string containing all the elements in SET,
+# separated by SEP, then delete SET. In general, if you only need to
+# list the contents once, this is faster than m4_set_contents. No
+# provision is made for disambiguating set elements that contain
+# non-empty SEP as a sub-string. Order of the output is not
+# guaranteed. This is O(n) in the size of the set before pruning.
+#
+# Use _m4_popdef for speed. Use existence of _m4_set_cleanup($1) to
+# decide if more expensive recursion is needed.
+m4_define([m4_set_dump],
+[m4_ifdef([_m4_set_size($1)],
+ [_m4_popdef([_m4_set_size($1)])])m4_ifdef([_m4_set_cleanup($1)],
+ [_$0_check], [_$0])([$1], [], [$2])])
+
+# _m4_set_dump(SET, SEP, PREP)
+# _m4_set_dump_check(SET, SEP, PREP)
+# ----------------------------------
+# Print SEP and the current element, then delete the element and
+# recurse with empty SEP changed to PREP. The check variant checks
+# whether the element has been previously removed. Use _m4_defn and
+# _m4_popdef for speed.
+m4_define([_m4_set_dump],
+[m4_ifdef([_m4_set([$1])],
+ [[$2]_m4_defn([_m4_set([$1])])_m4_popdef([_m4_set([$1],]_m4_defn(
+ [_m4_set([$1])])[)], [_m4_set([$1])])$0([$1], [$2$3])])])
+
+m4_define([_m4_set_dump_check],
+[m4_ifdef([_m4_set([$1])],
+ [m4_set_contains([$1], _m4_defn([_m4_set([$1])]),
+ [[$2]_m4_defn([_m4_set([$1])])])_m4_popdef(
+ [_m4_set([$1],]_m4_defn([_m4_set([$1])])[)],
+ [_m4_set([$1])])$0([$1], [$2$3])],
+ [_m4_popdef([_m4_set_cleanup($1)])])])
+
+# m4_set_empty(SET, [IF-EMPTY], [IF-ELEMENTS])
+# --------------------------------------------
+# Expand IF-EMPTY if SET has no elements, otherwise IF-ELEMENTS.
+m4_define([m4_set_empty],
+[m4_ifdef([_m4_set_size($1)],
+ [m4_if(m4_indir([_m4_set_size($1)]), [0], [$2], [$3])], [$2])])
+
+# m4_set_foreach(SET, VAR, ACTION)
+# --------------------------------
+# For each element of SET, define VAR to the element and expand
+# ACTION. ACTION should not recursively list SET's contents, add
+# elements to SET, nor delete any element from SET except the one
+# currently in VAR. The order that the elements are visited in is not
+# guaranteed. This is faster than the corresponding m4_foreach([VAR],
+# m4_indir([m4_dquote]m4_set_listc([SET])), [ACTION])
+m4_define([m4_set_foreach],
+[m4_pushdef([$2])m4_ifdef([_m4_set_cleanup($1)],
+ [_m4_set_contents_1c], [_m4_set_contents_1])([$1])_m4_set_contents_2([$1],
+ [m4_define([$2], _m4_defn([_m4_set_($1)]))$3[]])m4_popdef([$2])])
+
+# m4_set_intersection(SET1, SET2)
+# -------------------------------
+# Produce a LIST of quoted elements that occur in both SET1 or SET2.
+# Output a comma prior to any elements, to distinguish the empty
+# string from no elements. This can be directly used as a series of
+# arguments, such as for m4_join, or wrapped inside quotes for use in
+# m4_foreach. Order of the output is not guaranteed.
+#
+# Iterate over the smaller set, and short-circuit the idempotence
+# relation. Use _m4_defn for speed.
+m4_define([m4_set_intersection],
+[m4_if([$1], [$2], [m4_set_listc([$1])],
+ m4_eval(m4_set_size([$2]) < m4_set_size([$1])), [1], [$0([$2], [$1])],
+ [m4_set_foreach([$1], [_m4_element],
+ [m4_set_contains([$2], _m4_defn([_m4_element]),
+ [,_m4_defn([_m4_element])])])])])
+
+# m4_set_list(SET)
+# m4_set_listc(SET)
+# -----------------
+# Produce a LIST of quoted elements of SET. This can be directly used
+# as a series of arguments, such as for m4_join or m4_set_add_all, or
+# wrapped inside quotes for use in m4_foreach or m4_map. With
+# m4_set_list, there is no way to distinguish an empty set from a set
+# containing only the empty string; with m4_set_listc, a leading comma
+# is output if there are any elements.
+m4_define([m4_set_list],
+[m4_ifdef([_m4_set_cleanup($1)], [_m4_set_contents_1c],
+ [_m4_set_contents_1])([$1])_m4_set_contents_2([$1],
+ [_m4_defn([_m4_set_($1)])], [,])])
+
+m4_define([m4_set_listc],
+[m4_ifdef([_m4_set_cleanup($1)], [_m4_set_contents_1c],
+ [_m4_set_contents_1])([$1])_m4_set_contents_2([$1],
+ [,_m4_defn([_m4_set_($1)])])])
+
+# m4_set_remove(SET, VALUE, [IF-PRESENT], [IF-ABSENT])
+# ----------------------------------------------------
+# If VALUE is an element of SET, delete it and expand IF-PRESENT.
+# Otherwise expand IF-ABSENT. Deleting a single value is O(1),
+# although it leaves memory occupied until the next O(n) traversal of
+# the set which will compact the set.
+#
+# Optimize if the element being removed is the most recently added,
+# since defining _m4_set_cleanup($1) slows down so many other macros.
+# In particular, this plays well with m4_set_foreach.
+m4_define([m4_set_remove],
+[m4_set_contains([$1], [$2], [_m4_set_size([$1],
+ [m4_decr])m4_if(_m4_defn([_m4_set([$1])]), [$2],
+ [_m4_popdef([_m4_set([$1],$2)], [_m4_set([$1])])],
+ [m4_define([_m4_set_cleanup($1)])m4_define(
+ [_m4_set([$1],$2)], [0])])$3], [$4])])
+
+# m4_set_size(SET)
+# ----------------
+# Expand to the number of elements currently in SET. This operation
+# is O(1), and thus more efficient than m4_count(m4_set_list([SET])).
+m4_define([m4_set_size],
+[m4_ifdef([_m4_set_size($1)], [m4_indir([_m4_set_size($1)])], [0])])
+
+# _m4_set_size(SET, ACTION)
+# -------------------------
+# ACTION must be either m4_incr or m4_decr, and the size of SET is
+# changed accordingly. If the set is empty, ACTION must not be
+# m4_decr.
+m4_define([_m4_set_size],
+[m4_define([_m4_set_size($1)],
+ m4_ifdef([_m4_set_size($1)], [$2(m4_indir([_m4_set_size($1)]))],
+ [1]))])
+
+# m4_set_union(SET1, SET2)
+# ------------------------
+# Produce a LIST of double quoted elements that occur in either SET1
+# or SET2, without duplicates. Output a comma prior to any elements,
+# to distinguish the empty string from no elements. This can be
+# directly used as a series of arguments, such as for m4_join, or
+# wrapped inside quotes for use in m4_foreach. Order of the output is
+# not guaranteed.
+#
+# We can rely on the fact that m4_set_listc prunes SET1, so we don't
+# need to check _m4_set([$1],element) for 0. Use _m4_defn for speed.
+# Short-circuit the idempotence relation.
+m4_define([m4_set_union],
+[m4_set_listc([$1])m4_if([$1], [$2], [], [m4_set_foreach([$2], [_m4_element],
+ [m4_ifdef([_m4_set([$1],]_m4_defn([_m4_element])[)], [],
+ [,_m4_defn([_m4_element])])])])])
+
+
+## ------------------- ##
+## 16. File handling. ##
+## ------------------- ##
+
+
+# It is a real pity that M4 comes with no macros to bind a diversion
+# to a file. So we have to deal without, which makes us a lot more
+# fragile than we should.
+
+
+# m4_file_append(FILE-NAME, CONTENT)
+# ----------------------------------
+m4_define([m4_file_append],
+[m4_syscmd([cat >>$1 <<_m4eof
+$2
+_m4eof
+])
+m4_if(m4_sysval, [0], [],
+ [m4_fatal([$0: cannot write: $1])])])
+
+
+
+## ------------------------ ##
+## 17. Setting M4sugar up. ##
+## ------------------------ ##
+
+
+# m4_init
+# -------
+# Initialize the m4sugar language.
+m4_define([m4_init],
+[# All the M4sugar macros start with `m4_', except `dnl' kept as is
+# for sake of simplicity.
+m4_pattern_forbid([^_?m4_])
+m4_pattern_forbid([^dnl$])
+
+# If __m4_version__ is defined, we assume that we are being run by M4
+# 1.6 or newer, and thus that $@ recursion is linear and debugmode(d)
+# is available for faster checks of dereferencing undefined macros.
+# But if it is missing, we assume we are being run by M4 1.4.x, that
+# $@ recursion is quadratic, and that we need foreach-based
+# replacement macros. Use the raw builtin to avoid tripping up
+# include tracing.
+m4_ifdef([__m4_version__],
+[m4_debugmode([+d])
+m4_copy([_m4_defn], [m4_defn])
+m4_copy([_m4_popdef], [m4_popdef])
+m4_copy([_m4_undefine], [m4_undefine])],
+[m4_builtin([include], [m4sugar/foreach.m4])])
+
+# _m4_divert_diversion should be defined:
+m4_divert_push([KILL])
+
+# Check the divert push/pop perfect balance.
+m4_wrap([m4_divert_pop([])
+ m4_ifdef([_m4_divert_diversion],
+ [m4_fatal([$0: unbalanced m4_divert_push:]_m4_divert_n_stack)])[]])
+])
diff --git a/tools/mhmake/src/build.cpp b/tools/mhmake/src/build.cpp
index 9efa90932..185fdb2fb 100644
--- a/tools/mhmake/src/build.cpp
+++ b/tools/mhmake/src/build.cpp
@@ -21,7 +21,6 @@
#include "stdafx.h"
#include "mhmakefileparser.h"
-#include "mhmakeparser.h"
#include "rule.h"
#include "util.h"
@@ -834,7 +833,7 @@ static const string &GetComspec()
const char *pComspec=getenv(COMSPEC);
if (pComspec)
{
- Comspec=getenv(COMSPEC);
+ Comspec=pComspec;
#ifdef WIN32
Comspec+=" /c ";
#else
@@ -983,6 +982,35 @@ string mhmakefileparser::GetFullCommand(string Command)
return pFound->second;
}
+static void CommandSep(const string &Command, int &EndPos, int &NextBegin)
+{
+ while (1)
+ {
+ EndPos=Command.find('&',NextBegin);
+ if (EndPos==string::npos || !EndPos)
+ return;
+ EndPos--;
+ char C=Command[EndPos];
+ NextBegin=EndPos+2;
+ if (strchr("|<>",C))
+ {
+ continue;
+ }
+ if (NextBegin!=Command.length())
+ {
+ C=Command[NextBegin];
+ if (strchr("|<>",C))
+ {
+ continue;
+ }
+ }
+ while (strchr(" \t|<>",Command[NextBegin])) NextBegin++;
+ while (strchr(" \t|<>",Command[EndPos])) EndPos--;
+ break;
+ };
+
+}
+
mh_pid_t mhmakefileparser::OsExeCommand(const string &Command, const string &Params, bool IgnoreError, string *pOutput) const
{
string FullCommandLine;
@@ -997,7 +1025,44 @@ mh_pid_t mhmakefileparser::OsExeCommand(const string &Command, const string &Par
{
string tmpCommand=Command.substr(ComSpec.size(),Command.size());
FullCommandLine=ComSpec;
- FullCommandLine+=g_QuoteString+QuoteFileName(tmpCommand)+Params+g_QuoteString;
+
+ string ComspecCommandLine=QuoteFileName(tmpCommand)+Params;
+ int NextBegin=0;
+ int EndPos=0;
+ CommandSep(ComspecCommandLine,EndPos,NextBegin);
+ if (EndPos!=string::npos)
+ {
+ // We have multiple commands so create an temporary batch file
+ FILE *pFile=(FILE*)1;
+ char Filename[MAX_PATH];
+ int Nr=1;
+ while (1)
+ {
+ sprintf(Filename,"%s\\tmp%d.bat",m_MakeDir->GetFullFileName().c_str(),Nr);
+ pFile=fopen(Filename,"r");
+ if (!pFile)
+ break;
+ fclose(pFile);
+ Nr++;
+ }
+ pFile=fopen(Filename,"w");
+ fprintf(pFile,"@echo off\n");
+ int PrevPos=0;
+ while (EndPos!=string::npos)
+ {
+ string SubCommand=ComspecCommandLine.substr(PrevPos,EndPos-PrevPos+1);
+ fprintf(pFile,"%s\n",SubCommand.c_str());
+ PrevPos=NextBegin;
+ CommandSep(ComspecCommandLine,EndPos,NextBegin);
+ }
+ string SubCommand=ComspecCommandLine.substr(PrevPos);
+ fprintf(pFile,"%s\n",SubCommand.c_str());
+ fclose(pFile);
+ FullCommandLine+=QuoteFileName(Filename);
+ ((mhmakefileparser*)this)->m_FilesToRemoveAtEnd.push_back(string(Filename));
+ }
+ else
+ FullCommandLine+=ComspecCommandLine;
}
else
{
@@ -1132,8 +1197,16 @@ mh_pid_t mhmakefileparser::OsExeCommand(const string &Command, const string &Par
int pipeto[2]; /* pipe to feed the exec'ed program input */
int pipefrom[2]; /* pipe to get the exec'ed program output */
- pipe( pipeto );
- pipe( pipefrom );
+ if ( (-1==pipe(pipeto)) || (-1==pipe(pipefrom)) )
+ {
+ if (IgnoreError)
+ {
+ cerr << "Error creating pipe for : "<<Command<<", but ignoring error\n";
+ return (mh_pid_t)0; // Ignore error
+ }
+ else
+ return (mh_pid_t)-1;
+ }
pid_t ID=vfork();
if (ID==-1)
@@ -1160,7 +1233,8 @@ mh_pid_t mhmakefileparser::OsExeCommand(const string &Command, const string &Par
close( pipefrom[1] );
poptParseArgvString(FullCommandLine.c_str(), &argc, &pargv);
- chdir(m_MakeDir->GetFullFileName().c_str());
+ if (-1==chdir(m_MakeDir->GetFullFileName().c_str()))
+ throw string("Error changing current directory to ")+m_MakeDir->GetFullFileName();
if (m_pEnv)
execve(pargv[0],(char *const*)pargv,m_pEnv);
else
@@ -1249,7 +1323,8 @@ mh_pid_t mhmakefileparser::OsExeCommand(const string &Command, const string &Par
const char **pargv;
poptParseArgvString(FullCommandLine.c_str(), &argc, &pargv);
- chdir(m_MakeDir->GetFullFileName().c_str());
+ if (-1==chdir(m_MakeDir->GetFullFileName().c_str()))
+ throw string("Error changing current directory to ")+m_MakeDir->GetFullFileName();
if (m_pEnv)
execve(pargv[0],(char *const*)pargv,m_pEnv);
else
diff --git a/tools/mhmake/src/commandqueue.cpp b/tools/mhmake/src/commandqueue.cpp
index 6f3fd4d1a..8ca842362 100644
--- a/tools/mhmake/src/commandqueue.cpp
+++ b/tools/mhmake/src/commandqueue.cpp
@@ -21,7 +21,7 @@
#include "stdafx.h"
#include "commandqueue.h"
-#include "mhmakeparser.h"
+#include "mhmakefileparser.h"
#ifndef WIN32
@@ -64,24 +64,29 @@ commandqueue::commandqueue() :
m_DummyWaitHandle=(mh_pid_t)CreateEvent(NULL,TRUE,FALSE,NULL);
#else
FILE *pFile=fopen("/proc/cpuinfo","r");
- const char *pProc="\nprocessor";
- int cur=1;
+ const char szProc[]="processor";
+ int cur=0;
int NrProcs=0;
while (!feof(pFile))
{
char In=fgetc(pFile);
- if (In==pProc[cur])
+ if (In=='\n')
{
- cur++;
- if (!pProc[cur])
+ cur=0;
+ }
+ else
+ {
+ if (cur<=sizeof(szProc) && In==szProc[cur])
{
+ if (!szProc[cur+1])
+ {
NrProcs++;
- cur=0;
}
}
- else
- cur=0;
+ cur++;
+ }
}
+
m_MaxNrCommandsInParallel=NrProcs;
m_DummyWaitHandle=(mh_pid_t)-1;
diff --git a/tools/mhmake/src/curdir.cpp b/tools/mhmake/src/curdir.cpp
index 4b905a327..b87dc4f6f 100644
--- a/tools/mhmake/src/curdir.cpp
+++ b/tools/mhmake/src/curdir.cpp
@@ -31,7 +31,8 @@ curdir::initcurdir curdir::m_pCurrentDir;
curdir::initcurdir::initcurdir()
{
char CurDir[MAX_PATH];
- getcwd(CurDir,MAX_PATH);
+ if (!getcwd(CurDir,MAX_PATH))
+ throw string("Error getting current directory.");
string strCurDir=CurDir;
m_pDir=GetAbsFileInfo(NormalizePathName(strCurDir));
}
diff --git a/tools/mhmake/src/fileinfo.cpp b/tools/mhmake/src/fileinfo.cpp
index 7174c49a4..5ef044e41 100644
--- a/tools/mhmake/src/fileinfo.cpp
+++ b/tools/mhmake/src/fileinfo.cpp
@@ -23,7 +23,7 @@
#include "fileinfo.h"
#include "rule.h"
#include "util.h"
-#include "mhmakeparser.h"
+#include "mhmakefileparser.h"
#ifndef S_ISDIR
#define S_ISDIR(val) ((val)&_S_IFDIR)
@@ -242,13 +242,16 @@ string &NormalizePathName(string &Name)
while ((pPtr[0]=='\\' || pPtr[0]=='/') && pPtr[1]=='.' && pPtr[2]=='.')
{
pLastSlash--;
- while (*pLastSlash!='\\' && *pLastSlash!='/') pLastSlash--;
- if (pLastSlash<pBeg)
- pLastSlash=pBeg; // This is a fault in the file name, just put it back at the beginning
+ while (pLastSlash>pBeg && *pLastSlash!='\\' && *pLastSlash!='/') pLastSlash--; // Be dure to not go further then the beginning of the file name
pPtr+=3;
}
if (pLastSlash)
+ {
+ if (pLastSlash<pBeg)
+ pWr=(char*)pBeg;
+ else
pWr=(char*)pLastSlash;
+ }
}
else
{
diff --git a/tools/mhmake/src/flex.skl b/tools/mhmake/src/flex.skl
index 4d57bac46..6db7e1c5c 100644
--- a/tools/mhmake/src/flex.skl
+++ b/tools/mhmake/src/flex.skl
@@ -1472,7 +1472,6 @@ yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout )
yy_init = 0;
yy_start = 0;
yy_flex_debug = 0;
- yylineno = 1; // this will only get updated if %option yylineno
yy_did_buffer_switch_on_eof = 0;
diff --git a/tools/mhmake/src/flexlexer.h b/tools/mhmake/src/flexlexer.h
index 48dab04ae..08acef335 100644
--- a/tools/mhmake/src/flexlexer.h
+++ b/tools/mhmake/src/flexlexer.h
@@ -47,7 +47,18 @@
#ifndef __FLEX_LEXER_H
// Never included before - need to define base class.
#define __FLEX_LEXER_H
-#include "mhmakeparser.h"
+class mhmakefileparser;
+
+#include "refptr.h"
+
+struct YYSTYPE
+{
+ string theString;
+ int ival;
+};
+typedef struct YYSTYPE YYSTYPE;
+
+#include "location.hh"
#include <iostream>
# ifndef FLEX_STD
@@ -62,7 +73,7 @@ typedef int yy_state_type;
class FlexLexer {
public:
- FlexLexer() : yylineno(1), m_BraceIndent(0) {}
+ FlexLexer() : m_BraceIndent(0) {}
virtual ~FlexLexer() { }
const char* YYText() const { return yytext; }
@@ -75,23 +86,19 @@ public:
virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
virtual void yyrestart( FLEX_STD istream* s ) = 0;
- virtual int yylex(TOKENVALUE &theValue) = 0;
-
+ virtual int yylex(YYSTYPE *yylval, yy::location* yylloc) = 0;
// Switch to new input/output streams. A nil stream pointer
// indicates "keep the current one".
virtual void switch_streams( FLEX_STD istream* new_in = 0,
FLEX_STD ostream* new_out = 0 ) = 0;
- int lineno() const { return yylineno; }
-
int debug() const { return yy_flex_debug; }
void set_debug( int flag ) { yy_flex_debug = flag; }
protected:
char* yytext;
int yyleng;
- int yylineno; // only maintained if you use %option yylineno
int yy_flex_debug; // only has effect with -d or "%option debug"
public:
@@ -101,11 +108,11 @@ public:
YY_BUFFER_STATE m_BufferState;
ifstream m_Stream;
string m_FileName;
- int yylineno;
- INSTACK(YY_BUFFER_STATE BufferState, const string &FileToOpen, const string &PrevFileName, int Line) :
+ yy::location yylloc;
+ INSTACK(YY_BUFFER_STATE BufferState, const string &FileToOpen, const string &PrevFileName, yy::location *pLocInfo) :
m_BufferState(BufferState),
m_FileName(PrevFileName),
- yylineno(Line),
+ yylloc(*pLocInfo),
m_Stream(FileToOpen.c_str(), ios_base::in)
{
}
@@ -144,16 +151,19 @@ public:
string m_InputFileName;
string m_curtoken;
mystack m_IncludeStack;
- mhmakeparser *m_pParser;
- mhmakeparser *GetParser()
+ mhmakefileparser *m_pParser;
+ mhmakefileparser *GetParser()
{
return m_pParser;
}
-
+public:
+ string &GetInputFilename()
+ {
+ return m_InputFileName;
+ }
};
}
-#endif // FLEXLEXER_H
#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
// Either this is the first time through (yyFlexLexerOnce not defined),
@@ -179,7 +189,7 @@ public:
void yypush_buffer_state( struct yy_buffer_state* new_buffer );
void yypop_buffer_state();
- virtual int yylex(TOKENVALUE &theValue);
+ virtual int yylex(YYSTYPE* yylval, yy::location* yylloc);
virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 );
protected:
@@ -258,3 +268,4 @@ protected:
#endif // yyFlexLexer || ! yyFlexLexerOnce
+#endif // FLEXLEXER_H
diff --git a/tools/mhmake/src/md5.cpp b/tools/mhmake/src/md5.cpp
index 0ffba0d48..df3a006cb 100644
--- a/tools/mhmake/src/md5.cpp
+++ b/tools/mhmake/src/md5.cpp
@@ -304,7 +304,7 @@ struct WRITEMD5DB
map<uint32,string>::const_iterator It=g_Md5Database.begin();
while (It!=g_Md5Database.end())
{
- fprintf(pFile,"%08x: ",It->first);
+ fprintf(pFile,"%08lx: ",It->first);
fwrite(It->second.c_str(),It->second.length(),1,pFile);
fprintf(pFile,"\n");
It++;
diff --git a/tools/mhmake/src/mhmake.cpp b/tools/mhmake/src/mhmake.cpp
index 6d99e5f3d..ce2e8f7a7 100644
--- a/tools/mhmake/src/mhmake.cpp
+++ b/tools/mhmake/src/mhmake.cpp
@@ -20,7 +20,7 @@
#include "stdafx.h"
#include "fileinfo.h"
-#include "mhmakeparser.h"
+#include "mhmakefileparser.h"
#include "rule.h"
#include "util.h"
diff --git a/tools/mhmake/src/mhmakefileparser.cpp b/tools/mhmake/src/mhmakefileparser.cpp
index f281bc7dd..cf41b3c1c 100644
--- a/tools/mhmake/src/mhmakefileparser.cpp
+++ b/tools/mhmake/src/mhmakefileparser.cpp
@@ -29,19 +29,6 @@
commandqueue mhmakefileparser::sm_CommandQueue;
///////////////////////////////////////////////////////////////////////////////
-int mhmakefileparser::yylex(void)
-{
- m_yyloc=m_ptheLexer->lineno();
- return m_ptheLexer->yylex(m_theTokenValue);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-void mhmakefileparser::yyerror(const char *m)
-{
- cerr << this->m_ptheLexer->m_InputFileName<< " ("<<m_yyloc<<"): "<<m<<endl;
-}
-
-///////////////////////////////////////////////////////////////////////////////
int mhmakefileparser::ParseFile(const fileinfo *pFileInfo, const fileinfo *pMakeDir)
{
if (pMakeDir)
@@ -60,8 +47,8 @@ int mhmakefileparser::ParseFile(const fileinfo *pFileInfo, const fileinfo *pMake
mhmakeFlexLexer theLexer(&yyin);
m_ptheLexer=&theLexer;
theLexer.m_InputFileName=pFileInfo->GetFullFileName();
- theLexer.m_pParser=(mhmakeparser*)this;
- int Ret=yyparse();
+ theLexer.m_pParser=this;
+ int Ret=parse();
return Ret;
}
@@ -92,10 +79,15 @@ static inline size_t SkipUntilQuote(const string &Expr,size_t i,char Char)
static inline size_t SkipMakeExpr(const string &Expr,size_t i)
{
char Char=Expr[i++];
- if (Char!='(')
+ char EndChar;
+ if (Char=='(')
+ EndChar=')';
+ else if (Char=='{')
+ EndChar='}';
+ else
return i;
Char=Expr[i++];
- while (Char!=')')
+ while (Char!=EndChar)
{
if (Char=='$')
{
@@ -103,7 +95,7 @@ static inline size_t SkipMakeExpr(const string &Expr,size_t i)
}
#ifdef _DEBUG
if (i>=Expr.length())
- throw(string(") not found in ")+Expr);
+ throw(string(1,EndChar)+" not found in "+Expr);
#endif
Char=Expr[i++];
}
@@ -570,11 +562,11 @@ void mhmakefileparser::GetAutoDeps(const fileinfo *pFirstDep, deps_t &Autodeps)
{
if (Ret=='#')
{
- fscanf(pIn,"%*[ \t]");
- Ret=fscanf(pIn,"include %1[\"<]%254[^>\"]%*[\">]",&Type,IncludeList);
+ Ret=fscanf(pIn,"%*[ \t]");
+ Ret=fscanf(pIn,"include %1[\"<]%254[^>\"]%*[\">]",(char*)&Type,IncludeList);
}
else
- Ret=fscanf(pIn,"import %1[\"<]%254[^>\"]%*[\">]",&Type,IncludeList);
+ Ret=fscanf(pIn,"import %1[\"<]%254[^>\"]%*[\">]",(char*)&Type,IncludeList);
if (Ret==2)
{
bFound=true;
@@ -744,14 +736,17 @@ void mhmakefileparser::LoadAutoDepsFile(fileinfo *pDepFile)
m_AutoDepFileLoaded=pDepFile;
FILE *pIn=fopen(pDepFile->GetFullFileName().c_str(),"rb");
-#ifdef _DEBUG
if (!pIn)
{
cerr << "Error opening autodep file "<<pDepFile->GetQuotedFullFileName()<<endl;
return;
}
-#endif
- fread(&m_EnvMd5_32,sizeof(m_EnvMd5_32),1,pIn);
+ if (1!=fread(&m_EnvMd5_32,sizeof(m_EnvMd5_32),1,pIn))
+ {
+ cerr << "Wrong format of autodep file "<<pDepFile->GetQuotedFullFileName()<<endl;
+ fclose(pIn);
+ return;
+ }
#ifdef _DEBUG
if (g_PrintAdditionalInfo)
cout << "Reading Env Md5 from "<<pDepFile->GetQuotedFullFileName()<<": "<<hex<<m_EnvMd5_32<<endl;
@@ -1358,7 +1353,12 @@ string mhmakefileparser::ResolveExpression(const string &InExpr,string &Rest) co
switch (Expr[i])
{
case '!':
- if (Expr[i+1]!='=')
+ if (i==Expr.length()-1)
+ {
+ i++; // to break out of the loop
+ Ret=s_TrueString; /* the input was ! which means true */
+ }
+ else if (Expr[i+1]!='=')
{
Ret=ResolveExpression(Expr.substr(i+1),Expr);
Ret = Ret.empty() || Ret==s_FalseString ? s_TrueString : g_EmptyString;
@@ -1371,6 +1371,12 @@ string mhmakefileparser::ResolveExpression(const string &InExpr,string &Rest) co
}
break;
case '&':
+ #ifdef _DEBUG
+ if (i==Expr.length()-1)
+ {
+ throw(string("Error in expression near ")+Expr[i]+": "+InExpr);
+ } else
+ #endif
if (Expr[i+1]!='&')
{
Ret+=Expr[i++];
@@ -1382,6 +1388,12 @@ string mhmakefileparser::ResolveExpression(const string &InExpr,string &Rest) co
}
break;
case '|':
+ #ifdef _DEBUG
+ if (i==Expr.length()-1)
+ {
+ throw(string("Error in expression near ")+Expr[i]+": "+InExpr);
+ } else
+ #endif
if (Expr[i+1]!='|')
{
Ret+=Expr[i++];
@@ -1420,6 +1432,11 @@ string mhmakefileparser::ResolveExpression(const string &InExpr,string &Rest) co
}
break;
case '=':
+ if (i==Expr.length()-1)
+ {
+ i++; // To break out of the loop
+ }
+ else
if (Expr[i+1]!='=')
{
Ret+=Expr[i++];
diff --git a/tools/mhmake/src/mhmakefileparser.h b/tools/mhmake/src/mhmakefileparser.h
index f1c9cb280..49c8aedb3 100644
--- a/tools/mhmake/src/mhmakefileparser.h
+++ b/tools/mhmake/src/mhmakefileparser.h
@@ -27,13 +27,7 @@
class rule;
-class mhmakeFlexLexer;
-
-struct TOKENVALUE
-{
- string theString;
- int ival;
-};
+#include "flexlexer.h"
class mhmakefileparser;
typedef string (mhmakefileparser::*function_f)(const string &, const string *) const;
@@ -52,13 +46,18 @@ typedef set<fileinfo*> deps_t;
typedef pair< bool, deps_t > autodeps_entry_t;
typedef map<fileinfo*, autodeps_entry_t > autodeps_t;
-class mhmakefileparser : public refbase
+namespace yy
{
+ class location;
+}
+class mhmakefileparser : public refbase
+{
private:
static commandqueue sm_CommandQueue;
-
+protected:
mhmakeFlexLexer *m_ptheLexer;
+private:
int m_yyloc;
fileinfo *m_RuleThatIsBuild;
vector<string> m_ToBeIncludeAfterBuild;
@@ -74,7 +73,6 @@ private:
protected:
map<string,string> m_Variables;
map<string,string> m_CommandLineVars;
- TOKENVALUE m_theTokenValue;
const fileinfo *m_MakeDir;
refptr<rule> m_pCurrentRule;
refptr<fileinfoarray> m_pCurrentItems;
@@ -106,6 +104,8 @@ protected:
autodeps_t m_AutoDeps;
set< const fileinfo* > m_Targets; // List of targets that are build by this makefile
+ vector<string> m_FilesToRemoveAtEnd;
+
static mh_time_t m_sBuildTime;
private:
string ResolveExpression(const string &InExpr,string &Rest) const;
@@ -223,6 +223,13 @@ public:
virtual ~mhmakefileparser() /* virtual to be sure the correct destructor is called when we delete with a pointer to this class which in reality is a pointer to a derived class */
{
SaveAutoDepsFile();
+ /* remove generated temporary batch files */
+ vector<string>::const_iterator It=m_FilesToRemoveAtEnd.begin();
+ while (It!=m_FilesToRemoveAtEnd.end())
+ {
+ remove(It->c_str());
+ It++;
+ }
#ifndef WIN32
char **pEnv=m_pEnv;
if (pEnv)
@@ -230,9 +237,12 @@ public:
#endif
free(m_pEnv);
}
- virtual int yylex(void);
- virtual void yyerror(const char *m);
- virtual int yyparse()
+ int yylex (YYSTYPE* yylval, yy::location* yylloc)
+ {
+ return m_ptheLexer->yylex(yylval,yylloc);
+ }
+
+ virtual int parse()
{
throw("Please derive if you want to execute yyparse.");
}
diff --git a/tools/mhmake/src/mhmakelexer.l b/tools/mhmake/src/mhmakelexer.l
index 8cf0f1680..f27fec31a 100644
--- a/tools/mhmake/src/mhmakelexer.l
+++ b/tools/mhmake/src/mhmakelexer.l
@@ -27,15 +27,19 @@
static uint32 LoadMakMd5(fileinfo *pTarget)
{
+ uint32 Md5_32=0;
string FileName=pTarget->GetFullFileName();
FileName+=".md5_32";
FILE *pFile=fopen(FileName.c_str(),"rb");
if (!pFile)
- return 0;
- uint32 Md5_32=0;
- fread(&Md5_32,sizeof(Md5_32),1,pFile);
+ return Md5_32;
+ if (1!=fread(&Md5_32,sizeof(Md5_32),1,pFile))
+ {
fclose(pFile);
+ return Md5_32;
+ }
pTarget->SetCommandsMd5_32(Md5_32);
+ fclose(pFile);
return Md5_32;
}
@@ -70,7 +74,14 @@ static void ReplaceCurlyBraces(string &String)
}
}
-#define YY_DECL int mhmakeFlexLexer::yylex(TOKENVALUE &theValue)
+#include "mhmakeparser.hpp"
+
+#define YY_DECL int mhmakeFlexLexer::yylex(yy::mhmakeparser::semantic_type* yylval, yy::mhmakeparser::location_type* yylloc)
+
+/* By default yylex returns int, we use token_type.
+ Unfortunately yyterminate by default returns 0, which is
+ not of token_type. */
+#define yyterminate() return yy::mhmakeparser::token::END
%}
@@ -87,24 +98,36 @@ static void ReplaceCurlyBraces(string &String)
%x IFEQ IFNEQ ERRORMACRO MESSAGEMACRO REPARSEMACRO LOAD_MAKEFILE
%x DEFINE
+%{
+# define YY_USER_ACTION yylloc->columns (yyleng);
+
+#define inclineno() yylloc->incline()
+#define lineno() yylloc->end.line
+#define colno() yylloc->end.column
+
+
+%}
%%
+%{
+ yylloc->step ();
+%}
/*---------------------------------------------------------------------------*/
[ \t\r]*\n[ ][ \t]* {
yy_set_bol(1); // Make sure the next rule also matches the ^
- yylineno++;
- return mhmakeparser::NEWLINE;
+ inclineno();
+ return yy::mhmakeparser::token::NEWLINE;
}
[ \t\r]*\n {
- PRINTF(("%s %d: NEWLINE:\n",m_InputFileName.c_str(),yylineno));
- yylineno++;
- return mhmakeparser::NEWLINE;
+ PRINTF(("%s %d: NEWLINE:\n",m_InputFileName.c_str(),lineno()));
+ inclineno();
+ return yy::mhmakeparser::token::NEWLINE;
}
/*---------------------------------------------------------------------------*/
^[s\-]?include {
- PRINTF(("%s %d: INCLUDE: ",m_InputFileName.c_str(),yylineno));
+ PRINTF(("%s %d: INCLUDE: ",m_InputFileName.c_str(),lineno()));
BEGIN(INCLUDE);
unsigned i=0;
while (strchr(" \t",yytext[i])) i++;
@@ -112,14 +135,14 @@ static void ReplaceCurlyBraces(string &String)
m_IgnoreIncludeError=true;
else
m_IgnoreIncludeError=false;
- return mhmakeparser::INCLUDEMAK; // Return a newline to be sure that the previous line is completely parse by yacc (in case it is a variable definition)
+ return yy::mhmakeparser::token::INCLUDEMAK; // Return a newline to be sure that the previous line is completely parse by yacc (in case it is a variable definition)
}
/*****************************************************************************/
<INCLUDE>[ \t]* /* eat the whitespace */
/*---------------------------------------------------------------------------*/
<INCLUDE>[^\r\n]+ { /* got the include file name */
- mhmakeparser *pParser=GetParser();
+ mhmakefileparser *pParser=GetParser();
/* replace the {} by () before expanding */
string IncludeFileNames(yytext);
@@ -148,7 +171,7 @@ static void ReplaceCurlyBraces(string &String)
pParser->AddIncludedMakefile(pInclude);
string strToInclude=pInclude->GetFullFileName();
- INSTACK *pStackElem=new INSTACK(YY_CURRENT_BUFFER, strToInclude, m_InputFileName, yylineno);
+ INSTACK *pStackElem=new INSTACK(YY_CURRENT_BUFFER, strToInclude, m_InputFileName, yylloc);
if ( pStackElem->fail() )
{
delete pStackElem;
@@ -157,11 +180,11 @@ static void ReplaceCurlyBraces(string &String)
mystack::reverse_iterator StackIt=m_IncludeStack.rbegin();
while (StackIt!=m_IncludeStack.rend())
{
- cout<<" in "<<(*StackIt)->m_FileName<<" ("<<(*StackIt)->yylineno<<")";
+ cout<<" in "<<(*StackIt)->m_FileName<<" ("<<(*StackIt)->yylloc<<")";
StackIt++;
}
cout<<endl;
- cout<<"Warning error opening file "<<strToInclude<<" in "<<m_InputFileName<<" ("<<yylineno<<")\n";
+ cout<<"Warning error opening file "<<strToInclude<<" in "<<m_InputFileName<<" ("<<lineno()<<")\n";
pParser->IncludeAfterBuild(strToInclude);
}
else
@@ -170,9 +193,9 @@ static void ReplaceCurlyBraces(string &String)
else
{
m_IncludeStack.push(pStackElem);
- yylineno=1;
m_InputFileName=strToInclude;
+ yylloc->initialize(&m_InputFileName);
yypush_buffer_state(yy_create_buffer( pStackElem->GetStream(), YY_BUF_SIZE ));
yyrestart(pStackElem->GetStream());
@@ -186,9 +209,9 @@ static void ReplaceCurlyBraces(string &String)
/*---------------------------------------------------------------------------*/
load_makefile {
- PRINTF(("%s %d: LOAD_MAKEFILE:\n",m_InputFileName.c_str(),yylineno));
+ PRINTF(("%s %d: LOAD_MAKEFILE:\n",m_InputFileName.c_str(),lineno()));
BEGIN(LOAD_MAKEFILE);
- return mhmakeparser::NEWLINE; // Return a newline to be sure that the previous line is completely parse by yacc (in case it is a variable definition)
+ return yy::mhmakeparser::token::NEWLINE; // Return a newline to be sure that the previous line is completely parse by yacc (in case it is a variable definition)
}
/*****************************************************************************/
@@ -196,7 +219,7 @@ load_makefile {
string ListOfMakefiles((const char*)yytext);
ReplaceCurlyBraces(ListOfMakefiles);
ListOfMakefiles=GetParser()->ExpandExpression(ListOfMakefiles);
- PRINTF(("%s %d: LOAD_MAKEFILE: '%s'\n",m_InputFileName.c_str(),yylineno,ListOfMakefiles.c_str()));
+ PRINTF(("%s %d: LOAD_MAKEFILE: '%s'\n",m_InputFileName.c_str(),lineno(),ListOfMakefiles.c_str()));
const char *pTmp=ListOfMakefiles.c_str();
while (*pTmp)
@@ -205,7 +228,7 @@ load_makefile {
pTmp=NextCharItem(pTmp,Item,';');
if (Item.empty())
{
- throw m_InputFileName + "(" + stringify(yylineno) + "): Error in load_makefile statement";
+ throw m_InputFileName + "(" + stringify(lineno()) + "): Error in load_makefile statement";
}
GetParser()->AddMakefileToMakefilesToLoad(Item);
}
@@ -213,116 +236,116 @@ load_makefile {
}
/*---------------------------------------------------------------------------*/
<LOAD_MAKEFILE>\r?\n {
- yylineno++;
+ inclineno();
BEGIN(INITIAL);
- return mhmakeparser::NEWLINE;
+ return yy::mhmakeparser::token::NEWLINE;
}
/*---------------------------------------------------------------------------*/
[ \t]+ {
- PRINTF(("%s %d: SPACE:\n",m_InputFileName.c_str(),yylineno));
- return mhmakeparser::SPACE;
+ PRINTF(("%s %d: SPACE:\n",m_InputFileName.c_str(),lineno()));
+ return yy::mhmakeparser::token::SPACE;
}
/*---------------------------------------------------------------------------*/
[ \t]*=[ \t]*\\[ \t\r]*\n[ \t]* {
- PRINTF(("%s %d: EQUAL: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- yylineno++;
- theValue.theString=(const char *)yytext;
- return mhmakeparser::EQUAL;
+ PRINTF(("%s %d: EQUAL: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ inclineno();
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::EQUAL;
}
[ \t]*=[ \t]* {
- PRINTF(("%s %d: EQUAL: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- theValue.theString=(const char *)yytext;
- return mhmakeparser::EQUAL;
+ PRINTF(("%s %d: EQUAL: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::EQUAL;
}
/*---------------------------------------------------------------------------*/
[ \t]*:=[ \t]*\\[ \t\r]*\n[ \t]* {
- yylineno++;
- PRINTF(("%s %d: IMEQUAL: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- return mhmakeparser::IMEQUAL;
+ inclineno();
+ PRINTF(("%s %d: IMEQUAL: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ return yy::mhmakeparser::token::IMEQUAL;
}
[ \t]*:=[ \t]* {
- PRINTF(("%s %d: IMEQUAL: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- return mhmakeparser::IMEQUAL;
+ PRINTF(("%s %d: IMEQUAL: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ return yy::mhmakeparser::token::IMEQUAL;
}
/*---------------------------------------------------------------------------*/
[ \t]*\?=[ \t]*\\[ \t\r]*\n[ \t]* {
- yylineno++;
- PRINTF(("%s %d: OPTEQUAL: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- return mhmakeparser::OPTEQUAL;
+ inclineno();
+ PRINTF(("%s %d: OPTEQUAL: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ return yy::mhmakeparser::token::OPTEQUAL;
}
[ \t]*\?=[ \t]* {
- PRINTF(("%s %d: OPTEQUAL: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- return mhmakeparser::OPTEQUAL;
+ PRINTF(("%s %d: OPTEQUAL: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ return yy::mhmakeparser::token::OPTEQUAL;
}
/*---------------------------------------------------------------------------*/
[ \t]*\+=[ \t]*\\[ \t\r]*\n[ \t]* {
- PRINTF(("%s %d: PEQUAL: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- yylineno++;
- return mhmakeparser::PEQUAL;
+ PRINTF(("%s %d: PEQUAL: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ inclineno();
+ return yy::mhmakeparser::token::PEQUAL;
}
[ \t]*\+=[ \t]* {
- PRINTF(("%s %d: PEQUAL: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- return mhmakeparser::PEQUAL;
+ PRINTF(("%s %d: PEQUAL: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ return yy::mhmakeparser::token::PEQUAL;
}
/*---------------------------------------------------------------------------*/
[ \t]*;[ \t]*\\[ \t\r]*\n[ \t]* {
- PRINTF(("%s %d: -SEMICOLON (NEWLINE): %s\n",m_InputFileName.c_str(),yylineno,yytext));
+ PRINTF(("%s %d: -SEMICOLON (NEWLINE): %s\n",m_InputFileName.c_str(),lineno(),yytext));
m_curtoken=g_EmptyString;
- yylineno++;
+ inclineno();
BEGIN(COMMANDPARSE);
- return mhmakeparser::NEWLINE;
+ return yy::mhmakeparser::token::NEWLINE;
}
[ \t]*;[ \t]* {
- PRINTF(("%s %d: -SEMICOLON (NEWLINE): %s\n",m_InputFileName.c_str(),yylineno,yytext));
+ PRINTF(("%s %d: -SEMICOLON (NEWLINE): %s\n",m_InputFileName.c_str(),lineno(),yytext));
m_curtoken=g_EmptyString;
BEGIN(COMMANDPARSE);
- return mhmakeparser::NEWLINE;
+ return yy::mhmakeparser::token::NEWLINE;
}
/*---------------------------------------------------------------------------*/
[ \t]*::[ \t]*\\[ \t\r]*\n[ \t]* {
- PRINTF(("%s %d: DOUBLECOLON: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- yylineno++;
- theValue.theString=(const char *)yytext;
- return mhmakeparser::DOUBLECOLON;
+ PRINTF(("%s %d: DOUBLECOLON: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ inclineno();
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::DOUBLECOLON;
}
[ \t]*::[ \t]* {
- PRINTF(("%s %d: DOUBLECOLON: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- theValue.theString=(const char *)yytext;
- return mhmakeparser::DOUBLECOLON;
+ PRINTF(("%s %d: DOUBLECOLON: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::DOUBLECOLON;
}
/*---------------------------------------------------------------------------*/
[ \t]*:[ \t]*\\[ \t\r]*\n[ \t]* {
- PRINTF(("%s %d: COLON: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- yylineno++;
- theValue.theString=(const char *)yytext;
- return mhmakeparser::COLON;
+ PRINTF(("%s %d: COLON: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ inclineno();
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::COLON;
}
[ \t]*:[ \t]* {
- PRINTF(("%s %d: COLON: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- theValue.theString=(const char *)yytext;
- return mhmakeparser::COLON;
+ PRINTF(("%s %d: COLON: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::COLON;
}
/*---------------------------------------------------------------------------*/
, {
- PRINTF(("%s %d: COMMA: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- theValue.theString=(const char *)yytext;
- return mhmakeparser::COMMA;
+ PRINTF(("%s %d: COMMA: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::COMMA;
}
/*---------------------------------------------------------------------------*/
@@ -330,92 +353,92 @@ load_makefile {
if (m_IndentStack.size())
{
m_IndentStack.pop();
- PRINTF(("%s %d: %s: depth %d\n",m_InputFileName.c_str(),yylineno,yytext,m_IndentStack.size()));
+ PRINTF(("%s %d: %s: depth %d\n",m_InputFileName.c_str(),lineno(),yytext,m_IndentStack.size()));
}
else
{
- throw string("Unexpected endif at line ") + stringify(yylineno) + " of " + m_InputFileName;
+ throw string("Unexpected endif at line ") + stringify(lineno()) + " of " + m_InputFileName;
}
}
/*---------------------------------------------------------------------------*/
^ifdef[ \t]*\\[ \t\r]*\n[ \t]* {
BEGIN(IFDEF);
- yylineno++;
- return mhmakeparser::NEWLINE;
+ inclineno();
+ return yy::mhmakeparser::token::NEWLINE;
}
^ifdef[ \t]+ {
BEGIN(IFDEF);
- return mhmakeparser::NEWLINE;
+ return yy::mhmakeparser::token::NEWLINE;
}
/*---------------------------------------------------------------------------*/
^if[ \t]*\\[ \t\r]*\n[ \t]* {
BEGIN(IF);
- yylineno++;
+ inclineno();
m_curtoken=g_EmptyString;
- return mhmakeparser::NEWLINE;
+ return yy::mhmakeparser::token::NEWLINE;
}
^if[ \t]+ {
BEGIN(IF);
m_curtoken=g_EmptyString;
- return mhmakeparser::NEWLINE;
+ return yy::mhmakeparser::token::NEWLINE;
}
/*---------------------------------------------------------------------------*/
^ifndef[ \t]*\\[ \t\r]*\n[ \t]* {
BEGIN(IFNDEF);
- yylineno++;
- return mhmakeparser::NEWLINE;
+ inclineno();
+ return yy::mhmakeparser::token::NEWLINE;
}
^ifndef[ \t]+ {
BEGIN(IFNDEF);
- return mhmakeparser::NEWLINE;
+ return yy::mhmakeparser::token::NEWLINE;
}
/*---------------------------------------------------------------------------*/
^ifeq[ \t]*\\[ \t\r]*\n[ \t]* {
BEGIN(IFEQ);
m_curtoken=g_EmptyString;
- yylineno++;
- return mhmakeparser::NEWLINE;
+ inclineno();
+ return yy::mhmakeparser::token::NEWLINE;
}
^ifeq[ \t]+ {
BEGIN(IFEQ);
m_curtoken=g_EmptyString;
- return mhmakeparser::NEWLINE;
+ return yy::mhmakeparser::token::NEWLINE;
}
/*---------------------------------------------------------------------------*/
^ifneq[ \t]*\\[ \t\r]*\n[ \t]* {
BEGIN(IFNEQ);
m_curtoken=g_EmptyString;
- yylineno++;
- return mhmakeparser::NEWLINE;
+ inclineno();
+ return yy::mhmakeparser::token::NEWLINE;
}
^ifneq[ \t]+ {
BEGIN(IFNEQ);
m_curtoken=g_EmptyString;
- return mhmakeparser::NEWLINE;
+ return yy::mhmakeparser::token::NEWLINE;
}
/*---------------------------------------------------------------------------*/
^else[ \t]* {
if (m_IndentStack.size() && (!m_IndentStack.top()))
{
- PRINTF(("%s %d: skipping else: depth %d\n",m_InputFileName.c_str(),yylineno,m_IndentStack.size()));
+ PRINTF(("%s %d: skipping else: depth %d\n",m_InputFileName.c_str(),lineno(),m_IndentStack.size()));
m_IndentSkip=m_IndentStack.size();
m_IndentStack.top()=1;
BEGIN(SKIPUNTILELSEORENDIF);
}
else
{
- throw string("Unexpected else at line ") + stringify(yylineno) + " of file " + m_InputFileName;
+ throw string("Unexpected else at line ") + stringify(lineno()) + " of file " + m_InputFileName;
}
}
@@ -425,24 +448,23 @@ load_makefile {
m_IndentStack.push(0);
if (GetParser()->IsEqual(m_curtoken))
{
- PRINTF(("%s %d: Not Skipping ifeq %s: depth %d\n",m_InputFileName.c_str(),yylineno,m_curtoken.c_str(),m_IndentStack.size()));
+ PRINTF(("%s %d: Not Skipping ifeq %s: depth %d\n",m_InputFileName.c_str(),lineno(),m_curtoken.c_str(),m_IndentStack.size()));
BEGIN(INITIAL);
}
else
{
- PRINTF(("%s %d: Skipping ifeq %s: depth %d\n",m_InputFileName.c_str(),yylineno,m_curtoken.c_str(),m_IndentStack.size()));
+ PRINTF(("%s %d: Skipping ifeq %s: depth %d\n",m_InputFileName.c_str(),lineno(),m_curtoken.c_str(),m_IndentStack.size()));
m_IndentSkip=m_IndentStack.size();
BEGIN(SKIPUNTILELSEORENDIF);
}
}
-<IF,IFEQ,IFNEQ>[ \t]*\\[ \t\r]*\n[ \t]* { yylineno++; m_curtoken += g_SpaceString;}
+<IF,IFEQ,IFNEQ>[ \t]*\\[ \t\r]*\n[ \t]* { inclineno(); m_curtoken += g_SpaceString;}
<IF,IFEQ,IFNEQ>\r /* skip */
-<IF,IFEQ,IFNEQ>[^\\\r\n{}\$]+ |
-<IF,IFEQ,IFNEQ>\$ |
-<IF,IFEQ,IFNEQ>\\ { m_curtoken += (const char *)yytext; }
+<IF,IFEQ,IFNEQ>[^\\\r\n\$]+ |
+<IF,IFEQ,IFNEQ>[\\\$] { m_curtoken += (const char *)yytext; }
/*****************************************************************************/
<IFNEQ>\n {
@@ -450,12 +472,12 @@ load_makefile {
m_IndentStack.push(0);
if (!GetParser()->IsEqual(m_curtoken))
{
- PRINTF(("%s %d: Not Skipping ifneq %s: depth %d\n",m_InputFileName.c_str(),yylineno,m_curtoken.c_str(),m_IndentStack.size()));
+ PRINTF(("%s %d: Not Skipping ifneq %s: depth %d\n",m_InputFileName.c_str(),lineno(),m_curtoken.c_str(),m_IndentStack.size()));
BEGIN(INITIAL);
}
else
{
- PRINTF(("%s %d: Skipping ifneq %s: depth %d\n",m_InputFileName.c_str(),yylineno,m_curtoken.c_str(),m_IndentStack.size()));
+ PRINTF(("%s %d: Skipping ifneq %s: depth %d\n",m_InputFileName.c_str(),lineno(),m_curtoken.c_str(),m_IndentStack.size()));
m_IndentSkip=m_IndentStack.size();
BEGIN(SKIPUNTILELSEORENDIF);
}
@@ -473,13 +495,13 @@ load_makefile {
string Val=GetParser()->ExpandVar((const char *)yytext);
if (Val.empty() || Val=="0")
{
- PRINTF(("%s %d: Skipping if %s: depth %d\n",m_InputFileName.c_str(),yylineno,yytext,m_IndentStack.size()));
+ PRINTF(("%s %d: Skipping if %s: depth %d\n",m_InputFileName.c_str(),lineno(),yytext,m_IndentStack.size()));
m_IndentSkip=m_IndentStack.size();
BEGIN(SKIPUNTILELSEORENDIF);
}
else
{
- PRINTF(("%s %d: Not Skipping if %s: depth %d\n",m_InputFileName.c_str(),yylineno,yytext,m_IndentStack.size()));
+ PRINTF(("%s %d: Not Skipping if %s: depth %d\n",m_InputFileName.c_str(),lineno(),yytext,m_IndentStack.size()));
BEGIN(INITIAL);
}
}
@@ -490,12 +512,12 @@ load_makefile {
m_IndentStack.push(0);
if (GetParser()->IsExprTrue(m_curtoken))
{
- PRINTF(("%s %d: Not Skipping ifeq %s: depth %d\n",m_InputFileName.c_str(),yylineno,m_curtoken.c_str(),m_IndentStack.size()));
+ PRINTF(("%s %d: Not Skipping ifeq %s: depth %d\n",m_InputFileName.c_str(),lineno(),m_curtoken.c_str(),m_IndentStack.size()));
BEGIN(INITIAL);
}
else
{
- PRINTF(("%s %d: Skipping ifeq %s: depth %d\n",m_InputFileName.c_str(),yylineno,m_curtoken.c_str(),m_IndentStack.size()));
+ PRINTF(("%s %d: Skipping ifeq %s: depth %d\n",m_InputFileName.c_str(),lineno(),m_curtoken.c_str(),m_IndentStack.size()));
m_IndentSkip=m_IndentStack.size();
BEGIN(SKIPUNTILELSEORENDIF);
}
@@ -509,12 +531,12 @@ load_makefile {
m_IndentStack.push(0);
if (GetParser()->IsDefined((const char *)yytext))
{
- PRINTF(("%s %d: Not Skipping ifdef %s: depth %d\n",m_InputFileName.c_str(),yylineno,yytext,m_IndentStack.size()));
+ PRINTF(("%s %d: Not Skipping ifdef %s: depth %d\n",m_InputFileName.c_str(),lineno(),yytext,m_IndentStack.size()));
BEGIN(INITIAL);
}
else
{
- PRINTF(("%s %d: Skipping ifdef %s: depth %d\n",m_InputFileName.c_str(),yylineno,yytext,m_IndentStack.size()));
+ PRINTF(("%s %d: Skipping ifdef %s: depth %d\n",m_InputFileName.c_str(),lineno(),yytext,m_IndentStack.size()));
m_IndentSkip=m_IndentStack.size();
BEGIN(SKIPUNTILELSEORENDIF);
}
@@ -524,12 +546,12 @@ load_makefile {
<IFNDEF>[a-zA-Z0-9_]+ {
m_IndentStack.push(0);
if (!GetParser()->IsDefined((const char *)yytext)) {
- PRINTF(("%s %d: Not Skipping ifndef %s: depth %d\n",m_InputFileName.c_str(),yylineno,yytext,m_IndentStack.size()));
+ PRINTF(("%s %d: Not Skipping ifndef %s: depth %d\n",m_InputFileName.c_str(),lineno(),yytext,m_IndentStack.size()));
BEGIN(INITIAL);
}
else
{
- PRINTF(("%s %d: Skipping ifndef %s: depth %d\n",m_InputFileName.c_str(),yylineno,yytext,m_IndentStack.size()));
+ PRINTF(("%s %d: Skipping ifndef %s: depth %d\n",m_InputFileName.c_str(),lineno(),yytext,m_IndentStack.size()));
m_IndentSkip=m_IndentStack.size();
BEGIN(SKIPUNTILELSEORENDIF);
}
@@ -537,26 +559,26 @@ load_makefile {
/*****************************************************************************/
<SKIPUNTILELSEORENDIF>\n[ ]*endif {
- yylineno++;
+ inclineno();
if (!m_IndentStack.size())
{
- throw string("Unexpected endif at line ") + stringify(yylineno) + " of " + m_InputFileName;
+ throw string("Unexpected endif at line ") + stringify(lineno()) + " of " + m_InputFileName;
}
else
{
m_IndentStack.pop();
- PRINTF(("%s %d: endif: depth %d\n",m_InputFileName.c_str(),yylineno,m_IndentStack.size()));
+ PRINTF(("%s %d: endif: depth %d\n",m_InputFileName.c_str(),lineno(),m_IndentStack.size()));
if (m_IndentStack.size()==m_IndentSkip-1) BEGIN(INITIAL);
}
}
/*---------------------------------------------------------------------------*/
<SKIPUNTILELSEORENDIF>\n[ ]*else {
- yylineno++;
- PRINTF(("%s %d: else: depth %d\n",m_InputFileName.c_str(),yylineno,m_IndentStack.size()));
+ inclineno();
+ PRINTF(("%s %d: else: depth %d\n",m_InputFileName.c_str(),lineno(),m_IndentStack.size()));
if (m_IndentStack.top())
{
- throw string("Unexpected else at line ") + stringify(yylineno) + " of file " + m_InputFileName;
+ throw string("Unexpected else at line ") + stringify(lineno()) + " of file " + m_InputFileName;
}
m_IndentStack.top()=1;
if (m_IndentStack.size()==m_IndentSkip)
@@ -567,9 +589,9 @@ load_makefile {
/*---------------------------------------------------------------------------*/
<SKIPUNTILELSEORENDIF>\n[ ]*if(def|ndef|eq|neq)? {
- yylineno++;
+ inclineno();
m_IndentStack.push(0);
- PRINTF(("%s %d: %s: depth %d\n",m_InputFileName.c_str(),yylineno,yytext+1,m_IndentStack.size()));
+ PRINTF(("%s %d: %s: depth %d\n",m_InputFileName.c_str(),lineno(),yytext+1,m_IndentStack.size()));
}
/*---------------------------------------------------------------------------*/
@@ -577,46 +599,48 @@ load_makefile {
/*---------------------------------------------------------------------------*/
<SKIPUNTILELSEORENDIF>[^a-zA-Z\n]+ /* skip */
/*---------------------------------------------------------------------------*/
-<SKIPUNTILELSEORENDIF>\n[ ]*[a-zA-Z]+ yylineno++;
+<SKIPUNTILELSEORENDIF>\n[ ]*[a-zA-Z]+ {
+ inclineno();
+}
/*---------------------------------------------------------------------------*/
<SKIPUNTILELSEORENDIF>\n {
- yylineno++;
+ inclineno();
}
/*---------------------------------------------------------------------------*/
[ \t]*#[^\n]* {
- PRINTF(("%s %d: -COMMENT: %s\n",m_InputFileName.c_str(),yylineno,yytext));
+ PRINTF(("%s %d: -COMMENT: %s\n",m_InputFileName.c_str(),lineno(),yytext));
}
/*---------------------------------------------------------------------------*/
[ \t]*\\[ \t\r]*\n[ \t]* {
- PRINTF(("%s %d: SPACE:\n",m_InputFileName.c_str(),yylineno));
- yylineno++;
- return mhmakeparser::SPACE;
+ PRINTF(("%s %d: SPACE:\n",m_InputFileName.c_str(),lineno()));
+ inclineno();
+ return yy::mhmakeparser::token::SPACE;
}
/*---------------------------------------------------------------------------*/
\.PHONY {
- PRINTF(("%s %d: .PHONY: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- return mhmakeparser::PHONY;
+ PRINTF(("%s %d: .PHONY: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ return yy::mhmakeparser::token::PHONY;
}
/*---------------------------------------------------------------------------*/
\.AUTODEPS {
- PRINTF(("%s %d: .AUTODEPS: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- return mhmakeparser::AUTODEPS;
+ PRINTF(("%s %d: .AUTODEPS: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ return yy::mhmakeparser::token::AUTODEPS;
}
/*---------------------------------------------------------------------------*/
export {
- PRINTF(("%s %d: export: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- return mhmakeparser::EXPORT;
+ PRINTF(("%s %d: export: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ return yy::mhmakeparser::token::EXPORT;
}
/*---------------------------------------------------------------------------*/
^vpath {
- PRINTF(("%s %d: vpath\n",m_InputFileName.c_str(),yylineno));
- return mhmakeparser::VPATH;
+ PRINTF(("%s %d: vpath\n",m_InputFileName.c_str(),lineno()));
+ return yy::mhmakeparser::token::VPATH;
}
/*---------------------------------------------------------------------------*/
@@ -625,15 +649,15 @@ export {
while (strchr(" \t\r\n\\",yytext[--EndIndex]));
yyless(EndIndex+1);
- PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- theValue.theString=(const char *)yytext;
- return mhmakeparser::STRING;
+ PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::STRING;
}
[a-zA-Z]:[a-zA-Z0-9\\\._\~\-%\@<&/]+ {
- PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- theValue.theString=(const char *)yytext;
- return mhmakeparser::STRING;
+ PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::STRING;
}
/*---------------------------------------------------------------------------*/
@@ -642,38 +666,38 @@ export {
while (strchr(" \t\r\n\\",yytext[--EndIndex]));
yyless(EndIndex+1);
- PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- theValue.theString=(const char *)yytext;
- return mhmakeparser::STRING;
+ PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::STRING;
}
([a-zA-Z0-9\\\._\~\-\+%\@<&;/\*\|]|\\\ |\\#)+\+= {
- PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),yylineno,yytext));
+ PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),lineno(),yytext));
yyless(yyleng-2);
- theValue.theString=(const char *)yytext;
- return mhmakeparser::STRING;
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::STRING;
}
([a-zA-Z0-9\\\._\~\-\+%\@<&;/\*\|]|\\\ |\\#)+ {
- PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- theValue.theString=(const char *)yytext;
- return mhmakeparser::STRING;
+ PRINTF(("%s %d: STRING: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::STRING;
}
^define[ \t]+[a-zA-Z0-9_\.]+[ \t]*\n {
const char *pVar=(const char *)yytext;
while (strchr(" \t",*pVar)) pVar++;
pVar+=6;
- theValue.theString=pVar;
+ yylval->theString=pVar;
BEGIN(DEFINE);
m_curtoken=g_EmptyString;
- PRINTF(("%s %d: VARDEF: %s\n",m_InputFileName.c_str(),yylineno,m_curtoken.c_str()));
- yylineno++;
- return mhmakeparser::VARDEF;
+ PRINTF(("%s %d: VARDEF: %s\n",m_InputFileName.c_str(),lineno(),m_curtoken.c_str()));
+ inclineno();
+ return yy::mhmakeparser::token::VARDEF;
}
<DEFINE>[ \t]*\\[ \t\r]*\n[ \t]* {
- yylineno++;
+ inclineno();
m_curtoken+=g_SpaceString;
}
@@ -682,11 +706,11 @@ export {
}
<DEFINE>[ \t]*\n[ \t]*endef {
- yylineno++;
- theValue.theString=m_curtoken;
- PRINTF(("%s %d: VARVAL: %s\n",m_InputFileName.c_str(),yylineno,m_curtoken.c_str()));
+ inclineno();
+ yylval->theString=m_curtoken;
+ PRINTF(("%s %d: VARVAL: %s\n",m_InputFileName.c_str(),lineno(),m_curtoken.c_str()));
BEGIN(INITIAL);
- return mhmakeparser::VARVAL;
+ return yy::mhmakeparser::token::VARVAL;
}
/*---------------------------------------------------------------------------*/
@@ -702,106 +726,91 @@ export {
}
/*---------------------------------------------------------------------------*/
-\$\( {
+\$[\(\{] {
m_BraceIndent++;
- PRINTF(("%s %d: BEGIN MACRO $(: %d\n",m_InputFileName.c_str(),yylineno,m_BraceIndent));
+ PRINTF(("%s %d: BEGIN MACRO $(: %d\n",m_InputFileName.c_str(),lineno(),m_BraceIndent));
BEGIN(MAKEEXPRES);
m_curtoken=(const char *)yytext;
}
/*---------------------------------------------------------------------------*/
-\$\([ \t]*error[ \t]+ {
+\$[\(\{][ \t]*error[ \t]+ {
m_BraceIndent++;
- PRINTF(("%s %d: BEGIN ERROR MACRO $(: %d\n",m_InputFileName.c_str(),yylineno,m_BraceIndent));
+ PRINTF(("%s %d: BEGIN ERROR MACRO $(: %d\n",m_InputFileName.c_str(),lineno(),m_BraceIndent));
BEGIN(ERRORMACRO);
m_curtoken=g_EmptyString;
- return mhmakeparser::NEWLINE; // Make sure that the previous lines are matched by the bison parser (so that all variables until here are defined)
+ return yy::mhmakeparser::token::NEWLINE; // Make sure that the previous lines are matched by the bison parser (so that all variables until here are defined)
}
/*---------------------------------------------------------------------------*/
-\$\([ \t]*(message|info)[ \t]+ {
+\$[\(\{][ \t]*(message|info)[ \t]+ {
m_BraceIndent++;
- PRINTF(("%s %d: BEGIN MESSAGE MACRO $(: %d\n",m_InputFileName.c_str(),yylineno,m_BraceIndent));
+ PRINTF(("%s %d: BEGIN MESSAGE MACRO $(: %d\n",m_InputFileName.c_str(),lineno(),m_BraceIndent));
BEGIN(MESSAGEMACRO);
m_curtoken=g_EmptyString;
- return mhmakeparser::NEWLINE; // Make sure that the previous lines are matched by the bison parser (so that all variables until here are defined)
+ return yy::mhmakeparser::token::NEWLINE; // Make sure that the previous lines are matched by the bison parser (so that all variables until here are defined)
}
/*---------------------------------------------------------------------------*/
-\$\([ \t]*reparse[ \t]+ {
+\$[\(\{][ \t]*reparse[ \t]+ {
m_BraceIndent++;
- PRINTF(("%s %d: BEGIN REPARSE MACRO $(: %d\n",m_InputFileName.c_str(),yylineno,m_BraceIndent));
+ PRINTF(("%s %d: BEGIN REPARSE MACRO $(: %d\n",m_InputFileName.c_str(),lineno(),m_BraceIndent));
BEGIN(REPARSEMACRO);
m_curtoken=g_EmptyString;
- return mhmakeparser::NEWLINE;
-}
-
- /*---------------------------------------------------------------------------*/
-\( {
- PRINTF(("%s %d: OPENBRACE: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- return mhmakeparser::OPENBRACE;
-}
-
- /*---------------------------------------------------------------------------*/
-\) {
- PRINTF(("%s %d: CLOSEBRACE: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- return mhmakeparser::CLOSEBRACE;
+ return yy::mhmakeparser::token::NEWLINE;
}
/*---------------------------------------------------------------------------*/
\$[<@/$] {
- PRINTF(("%s %d: DOLLAREXPR: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- theValue.theString=(const char *)yytext;
- return mhmakeparser::DOLLAREXPR;
+ PRINTF(("%s %d: DOLLAREXPR: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::DOLLAREXPR;
}
/*---------------------------------------------------------------------------*/
[ \t\r]*\n\t[ \t]* {
/* token newline */
- PRINTF(("%s %d: NEWLINE\n",m_InputFileName.c_str(),yylineno));
- yylineno++;
+ PRINTF(("%s %d: NEWLINE\n",m_InputFileName.c_str(),lineno()));
+ inclineno();
m_curtoken=g_EmptyString;
BEGIN(COMMANDPARSE);
- return mhmakeparser::NEWLINE;
+ return yy::mhmakeparser::token::NEWLINE;
}
/*---------------------------------------------------------------------------*/
-<*>\$\{ {
- unput('(');
- unput('$');
-}
- /*---------------------------------------------------------------------------*/
-<*>\} {
- unput(')');
+[\(\)\{\}] {
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::STRING;
}
/*---------------------------------------------------------------------------*/
[^\n] {
- PRINTF(("%s %d: ANYCHAR: %d: %s\n",m_InputFileName.c_str(),yylineno,yylineno,yytext));
+ PRINTF(("%s %d: ANYCHAR: %d: %s\n",m_InputFileName.c_str(),lineno(),lineno(),yytext));
+ throw string("Unexpected character '")+yytext+"' in makefile '" + m_InputFileName + "' at line "+stringify(lineno()) + ", column " + stringify(colno()-1);
}
/*****************************************************************************/
<COMMANDPARSE>[ \t\r]*\n {
- PRINTF(("%s %d: COMMAND: %d: %s\n",m_InputFileName.c_str(),yylineno,yylineno,m_curtoken.c_str()));
- theValue.theString=m_curtoken;
- yylineno++;
+ PRINTF(("%s %d: COMMAND: %d: %s\n",m_InputFileName.c_str(),lineno(),lineno(),m_curtoken.c_str()));
+ yylval->theString=m_curtoken;
+ inclineno();
BEGIN(INITIAL);
- return mhmakeparser::COMMAND;
+ return yy::mhmakeparser::token::COMMAND;
}
/*---------------------------------------------------------------------------*/
<COMMANDPARSE>[ \t\r]*\n\t[ \t]* {
- PRINTF(("%s %d: COMMAND: %s\n",m_InputFileName.c_str(),yylineno,m_curtoken.c_str()));
- theValue.theString=m_curtoken;
- yylineno++;
+ PRINTF(("%s %d: COMMAND: %s\n",m_InputFileName.c_str(),lineno(),m_curtoken.c_str()));
+ yylval->theString=m_curtoken;
+ inclineno();
m_curtoken=g_EmptyString;
- return mhmakeparser::COMMAND;
+ return yy::mhmakeparser::token::COMMAND;
}
/*---------------------------------------------------------------------------*/
<COMMANDPARSE>[ \t]*\\[ \t\r]*\n[ \t]* {
- yylineno++;
+ inclineno();
m_curtoken+=g_SpaceString;
}
@@ -811,9 +820,8 @@ export {
}
/*---------------------------------------------------------------------------*/
-<COMMANDPARSE>[^ \r\n#\\{}$]+ |
-<COMMANDPARSE>\$ |
-<COMMANDPARSE>\\ {
+<COMMANDPARSE>[^ \r\n#\\$]+ |
+<COMMANDPARSE>[\\\$] {
m_curtoken+=(const char *)yytext;
}
@@ -827,23 +835,22 @@ export {
/*---------------------------------------------------------------------------*/
<COMMANDPARSE>[ \t]*#[^\n]* {
- PRINTF(("%s %d: -COMMENT: %s\n",m_InputFileName.c_str(),yylineno,yytext));
+ PRINTF(("%s %d: -COMMENT: %s\n",m_InputFileName.c_str(),lineno(),yytext));
}
/*****************************************************************************/
<QUOTE>\" {
- PRINTF(("%s %d: QUOTEDSTRING: %s\n",m_InputFileName.c_str(),yylineno,yytext));
+ PRINTF(("%s %d: QUOTEDSTRING: %s\n",m_InputFileName.c_str(),lineno(),yytext));
BEGIN(INITIAL);
- theValue.theString=(const char *)yytext;
- return mhmakeparser::STRING;
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::STRING;
}
/*---------------------------------------------------------------------------*/
<QUOTE>\r /* skip */
-<QUOTE>[^\\\"\r\n{}$]+ |
-<QUOTE>\$ |
-<QUOTE>\\ |
+<QUOTE>[^\\\"\r\n$]+ |
+<QUOTE>[\\\$] |
<QUOTE>\\\" |
<QUOTE>\\# {
yymore();
@@ -851,44 +858,43 @@ export {
/*****************************************************************************/
<SINGLEQUOTE>\' {
- PRINTF(("%s %d: QUOTEDSTRING: %s\n",m_InputFileName.c_str(),yylineno,yytext));
+ PRINTF(("%s %d: QUOTEDSTRING: %s\n",m_InputFileName.c_str(),lineno(),yytext));
BEGIN(INITIAL);
- theValue.theString=(const char *)yytext;
- return mhmakeparser::STRING;
+ yylval->theString=(const char *)yytext;
+ return yy::mhmakeparser::token::STRING;
}
/*---------------------------------------------------------------------------*/
<SINGLEQUOTE>\r /* skip */
-<SINGLEQUOTE>[^\\\'\r\n{}$]+ |
-<SINGLEQUOTE>\$ |
-<SINGLEQUOTE>\\ |
+<SINGLEQUOTE>[^\\\'\r\n$]+ |
+<SINGLEQUOTE>[\\\$] |
<SINGLEQUOTE>\\\' |
<SINGLEQUOTE>\\# {
yymore();
}
/*****************************************************************************/
-<ERRORMACRO>\) {
+<ERRORMACRO>[\)\}] {
m_BraceIndent--;
- PRINTF(("%s %d: CLOSE BRACE ERROR MACRO ): %d\n",m_InputFileName.c_str(),yylineno,m_BraceIndent));
+ PRINTF(("%s %d: CLOSE BRACE ERROR MACRO ): %d\n",m_InputFileName.c_str(),lineno(),m_BraceIndent));
if (!m_BraceIndent)
{
- PRINTF(("%s %d: ERRORMACRO: %s\n",m_InputFileName.c_str(),yylineno,m_curtoken.c_str()));
- throw string("\n-> ")+m_InputFileName.c_str()+"("+stringify(yylineno)+") : "+GetParser()->ExpandExpression(m_curtoken);
+ PRINTF(("%s %d: ERRORMACRO: %s\n",m_InputFileName.c_str(),lineno(),m_curtoken.c_str()));
+ throw string("\n-> ")+m_InputFileName.c_str()+"("+stringify(lineno())+") : "+GetParser()->ExpandExpression(m_curtoken);
} else {
m_curtoken+=(const char *)yytext;
}
}
/*****************************************************************************/
-<MESSAGEMACRO>\) {
+<MESSAGEMACRO>[\)\}] {
m_BraceIndent--;
- PRINTF(("%s %d: CLOSE BRACE MESSAGE MACRO ): %d\n",m_InputFileName.c_str(),yylineno,m_BraceIndent));
+ PRINTF(("%s %d: CLOSE BRACE MESSAGE MACRO ): %d\n",m_InputFileName.c_str(),lineno(),m_BraceIndent));
if (!m_BraceIndent)
{
- PRINTF(("%s %d: MESSAGEMACRO: %s\n",m_InputFileName.c_str(),yylineno,yytext));
- cerr<<m_InputFileName.c_str()<<"("<<stringify(yylineno)+") : "<<GetParser()->ExpandExpression(m_curtoken)<<endl;
+ PRINTF(("%s %d: MESSAGEMACRO: %s\n",m_InputFileName.c_str(),lineno(),yytext));
+ cerr<<m_InputFileName.c_str()<<"("<<stringify(lineno())+") : "<<GetParser()->ExpandExpression(m_curtoken)<<endl;
BEGIN(INITIAL);
} else {
m_curtoken+=(const char *)yytext;
@@ -896,14 +902,14 @@ export {
}
/*****************************************************************************/
-<REPARSEMACRO>\) {
+<REPARSEMACRO>[\)\}] {
m_BraceIndent--;
- PRINTF(("%s %d: CLOSE BRACE REPARSE MACRO ): %d\n",m_InputFileName.c_str(),yylineno,m_BraceIndent));
+ PRINTF(("%s %d: CLOSE BRACE REPARSE MACRO ): %d\n",m_InputFileName.c_str(),lineno(),m_BraceIndent));
if (!m_BraceIndent)
{
- PRINTF(("%s %d: REPARSEMACRO: %s\n",m_InputFileName.c_str(),yylineno,yytext));
+ PRINTF(("%s %d: REPARSEMACRO: %s\n",m_InputFileName.c_str(),lineno(),yytext));
string Deps=GetParser()->ExpandExpression(m_curtoken);
- PRINTF(("%s %d: REPARSEMACRO expanded: %s\n",m_InputFileName.c_str(),yylineno,Deps.c_str()));
+ PRINTF(("%s %d: REPARSEMACRO expanded: %s\n",m_InputFileName.c_str(),lineno(),Deps.c_str()));
string::const_reverse_iterator It=Deps.rbegin()+1; // +1 because we don't want the latest brace
string::const_reverse_iterator ItBeg=Deps.rend();
while (It!= ItBeg)
@@ -921,16 +927,16 @@ export {
}
/*****************************************************************************/
-<MAKEEXPRES>\) {
+<MAKEEXPRES>[\)\}] {
m_BraceIndent--;
- PRINTF(("%s %d: CLOSE BRACE MAKEEXPRES MACRO ): %d\n",m_InputFileName.c_str(),yylineno,m_BraceIndent));
+ PRINTF(("%s %d: CLOSE BRACE MAKEEXPRES MACRO ): %d\n",m_InputFileName.c_str(),lineno(),m_BraceIndent));
if (!m_BraceIndent)
{
BEGIN(INITIAL);
m_curtoken+=(const char *)yytext;
- theValue.theString=m_curtoken;
- PRINTF(("%s %d: DOLLAREXPR: %s\n",m_InputFileName.c_str(),yylineno,m_curtoken.c_str()));
- return mhmakeparser::DOLLAREXPR;
+ yylval->theString=m_curtoken;
+ PRINTF(("%s %d: DOLLAREXPR: %s\n",m_InputFileName.c_str(),lineno(),m_curtoken.c_str()));
+ return yy::mhmakeparser::token::DOLLAREXPR;
}
else
{
@@ -939,21 +945,19 @@ export {
}
/*---------------------------------------------------------------------------*/
-<MAKEEXPRES,ERRORMACRO,MESSAGEMACRO,REPARSEMACRO>\$\( {
+<MAKEEXPRES,ERRORMACRO,MESSAGEMACRO,REPARSEMACRO>\$[\(\{] {
m_BraceIndent++;
- PRINTF(("%s %d: MACRO extra $(: %d\n",m_InputFileName.c_str(),yylineno,m_BraceIndent));
+ PRINTF(("%s %d: MACRO extra $(: %d\n",m_InputFileName.c_str(),lineno(),m_BraceIndent));
m_curtoken+=(const char *)yytext;
}
/*---------------------------------------------------------------------------*/
-<MAKEEXPRES,ERRORMACRO,MESSAGEMACRO,REPARSEMACRO>[^$\(\){}\r\n\\]+ |
-<MAKEEXPRES,ERRORMACRO,MESSAGEMACRO,REPARSEMACRO>\$ |
-<MAKEEXPRES,ERRORMACRO,MESSAGEMACRO,REPARSEMACRO>\\ |
-<MAKEEXPRES,ERRORMACRO,MESSAGEMACRO,REPARSEMACRO>\( {
+<MAKEEXPRES,ERRORMACRO,MESSAGEMACRO,REPARSEMACRO>[^$\(\)\{\}\r\n\\]+ |
+<MAKEEXPRES,ERRORMACRO,MESSAGEMACRO,REPARSEMACRO>[\(\$\\\{] {
m_curtoken+=(const char *)yytext;
}
<MAKEEXPRES,ERRORMACRO,MESSAGEMACRO,REPARSEMACRO>[ \t\r]*\\[ \t\r]*\n[ \t\r]* {
- yylineno++;
+ inclineno();
m_curtoken+=g_SpaceString;
}
@@ -964,7 +968,7 @@ export {
<<EOF>> {
if (m_BraceIndent)
{
- throw string("Missing closing ) of macro usage in ") + m_InputFileName;
+ throw string("Missing closing ) or } of macro usage in ") + m_InputFileName;
}
if (!m_IncludeStack.size())
{
@@ -979,7 +983,7 @@ export {
INSTACK *pInStack=m_IncludeStack.top();
yypop_buffer_state();
m_InputFileName=pInStack->m_FileName;
- yylineno=pInStack->yylineno;
+ *yylloc=pInStack->yylloc;
m_IncludeStack.pop();
}
}
diff --git a/tools/mhmake/src/mhmakeparser.y b/tools/mhmake/src/mhmakeparser.y
index 515caf6e5..4c54ebd29 100644
--- a/tools/mhmake/src/mhmakeparser.y
+++ b/tools/mhmake/src/mhmakeparser.y
@@ -20,27 +20,38 @@
/* -------------- declaration section -------------- */
-%name mhmakeparser
-
-%define LLOC m_yyloc
-%define LTYPE int // This is the type of LLOC (defined in mhmakefileparser)
-
-%define LVAL m_theTokenValue
-%define STYPE TOKENVALUE // This is the type of LVAL (defined in mhmakefileparser)
-
-%define INHERIT : public mhmakefileparser
+%require "2.4.1"
+%defines
+%define parser_class_name "mhmakeparser"
+%define parser_base_class_name "mhmakefileparser"
+%define parser_class_constructor_init ": mhmakefileparser(CommandLineVariables)"
+%define parser_class_constructor_param "const map<string,string> &CommandLineVariables"
+%error-verbose
+
+%code requires {
+#include "mhmakefileparser.h"
+}
-%define CONSTRUCTOR_PARAM const map<string,string> &CommandLineVariables
-%define CONSTRUCTOR_INIT : mhmakefileparser(CommandLineVariables)
+%code provides {
+const char Test[]="dit is een test";
+}
-%header{
+%{
#include "mhmakefileparser.h"
#include "rule.h"
#include "util.h"
%}
+%locations
+%initial-action
+{
+ // Initialize the initial location.
+ @$.initialize(&m_ptheLexer->GetInputFilename());
+};
+
+%token END 0 "end of file"
%token <theString> COMMAND
-%token <theString> COMMA OPENBRACE CLOSEBRACE
+%token <theString> COMMA
%token <theString> STRING DOLLAREXPR EQUAL COLON DOUBLECOLON VARDEF VARVAL
%token IMEQUAL PEQUAL OPTEQUAL PHONY AUTODEPS EXPORT NEWLINE INCLUDEMAK SPACE VPATH
@@ -68,6 +79,10 @@ statements :
| statements statement
;
+space : SPACE |
+ space SPACE
+;
+
statement: NEWLINE |
SPACE |
includemak |
@@ -161,11 +176,11 @@ autodepsrule: AUTODEPS COLON expression
NEWLINE
;
-exportrule: EXPORT SPACE exportstrings NEWLINE
+exportrule: EXPORT space exportstrings NEWLINE
;
exportstrings : exportstring |
- exportstring SPACE exportstrings
+ exportstring space exportstrings
;
exportstring : STRING
@@ -175,7 +190,7 @@ exportstring : STRING
}
;
-vpathrule: VPATH SPACE nonspaceexpression SPACE expression NEWLINE
+vpathrule: VPATH space nonspaceexpression space expression NEWLINE
{
SetvPath(ExpandExpression($3),ExpandExpression($5));
PRINTF(("Setting vpath %s to %s\n",$3.c_str(),ExpandExpression($5).c_str()));
@@ -203,7 +218,7 @@ imvarassignment: STRING IMEQUAL maybeemptyexpression
pvarassignment: STRING PEQUAL maybeemptyexpression
{
- m_Variables[$1]=m_Variables[$1]+g_SpaceString+$3;
+ m_Variables[$1]=ExpandVar($1)+g_SpaceString+$3;
PRINTF(("Adding to variable %s: %s\n",$1.c_str(), $3.c_str()));
}
;
@@ -220,15 +235,15 @@ optvarassignment: STRING OPTEQUAL maybeemptyexpression
maybeemptyexpression: NEWLINE {$$=g_EmptyString;} |
expression NEWLINE |
- expression SPACE NEWLINE
+ expression space NEWLINE
;
expression: nonspaceexpression |
- expression SPACE nonspaceexpression {$$=$1+g_SpaceString+$3;}
+ expression space nonspaceexpression {$$=$1+g_SpaceString+$3;}
;
expression_nocolorequal: nonspaceexpression_nocolorequal |
- expression_nocolorequal SPACE nonspaceexpression_nocolorequal {$$=$1+g_SpaceString+$3;}
+ expression_nocolorequal space nonspaceexpression_nocolorequal {$$=$1+g_SpaceString+$3;}
;
nonspaceexpression: simpleexpression |
@@ -246,10 +261,14 @@ simpleexpression: simpleexpression_nocolorequal |
COMMA
;
-simpleexpression_nocolorequal: STRING {$$=$1;} |
- DOLLAREXPR {$$=$1;}
+simpleexpression_nocolorequal: STRING |
+ DOLLAREXPR
;
%%
/* -------------- body section -------------- */
+void yy::mhmakeparser::error (const yy::mhmakeparser::location_type& l, const std::string& m)
+{
+ cerr << l << " -> "<<m<<endl;
+}
diff --git a/tools/mhmake/src/rule.cpp b/tools/mhmake/src/rule.cpp
index 0beb29c39..35884e2f0 100644
--- a/tools/mhmake/src/rule.cpp
+++ b/tools/mhmake/src/rule.cpp
@@ -23,7 +23,7 @@
#include "fileinfo.h"
#include "rule.h"
#include "util.h"
-#include "mhmakeparser.h"
+#include "mhmakefileparser.h"
refptr<rule> NullRule;
diff --git a/tools/mhmake/src/stdafx.h b/tools/mhmake/src/stdafx.h
index 5d1ffedfb..e586ebb6b 100644
--- a/tools/mhmake/src/stdafx.h
+++ b/tools/mhmake/src/stdafx.h
@@ -75,6 +75,12 @@
#include <sys/stat.h>
#ifdef WIN32
#include <windows.h>
+#ifdef max
+#undef max
+#endif
+#ifdef min
+#undef min
+#endif
#endif
using namespace std;
diff --git a/tools/mhmake/src/util.cpp b/tools/mhmake/src/util.cpp
index 63bdb767b..b1298c91f 100644
--- a/tools/mhmake/src/util.cpp
+++ b/tools/mhmake/src/util.cpp
@@ -22,7 +22,7 @@
#include "rule.h"
#include "util.h"
-#include "mhmakeparser.h"
+#include "mhmakeparser.hpp"
#ifdef WIN32
@@ -114,7 +114,7 @@ void PrintVersionInfo(void)
static const char VersionStr[]="\
mhmake : GNU compatible make tool with extensions\n\
version: "MHMAKEVER"\n\
-Remarks and bug reports -> marha@sourceforge.net\n\
+Remarks and bug reports -> Marc Haesen\n\
";
cerr << VersionStr;
exit(1);
@@ -593,7 +593,7 @@ void loadedmakefile::LoadMakefile()
cout << "Loading makefile "<<m_Makefile->GetQuotedFullFileName()<<endl;
#endif
- m_pParser=refptr<mhmakefileparser>(new mhmakeparser(m_CommandLineVars));
+ m_pParser=refptr<mhmakefileparser>(new yy::mhmakeparser(m_CommandLineVars));
// Add the MAKECMDGOALS environment variable
string MakeCmdGoals;
@@ -660,7 +660,7 @@ void loadedmakefile::LoadMakefile()
md5_update(&ctx, (uint8*)m_Makefile->GetFullFileName().c_str(), m_Makefile->GetFullFileName().size());
char ID[10];
- sprintf(ID,"_%x",md5_finish32( &ctx));
+ sprintf(ID,"_%lx",md5_finish32( &ctx));
pDepFile=GetFileInfo(string(".") + m_Makefile->GetName()+ ".dep"+ID,m_MakeDir);
m_pParser->SetVariable(AUTODEPFILE,pDepFile->GetQuotedFullFileName());
diff --git a/tools/mhmake/src/util.h b/tools/mhmake/src/util.h
index 8676bd0d6..648ca01ee 100644
--- a/tools/mhmake/src/util.h
+++ b/tools/mhmake/src/util.h
@@ -50,7 +50,7 @@
#define PLATFORM "linux"
#endif
-#define MHMAKEVER "2.3.17"
+#define MHMAKEVER "2.3.28"
class makecommand
{