1 m4_divert(-1) -*- Autoconf -*-
3 # C M4 Macros for Bison.
4 # Copyright (C) 2002 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 # b4_copyright(TITLE, YEARS)
27 # --------------------------
28 m4_define([b4_copyright],
29 [/* A Bison parser, made from b4_filename, by GNU bison b4_version. */
32 Copyright (C) $2 Free Software Foundation, Inc.
34 This program is free software; you can redistribute it and/or modify
35 it under the terms of the GNU General Public License as published by
36 the Free Software Foundation; either version 2, or (at your option)
39 This program is distributed in the hope that it will be useful,
40 but WITHOUT ANY WARRANTY; without even the implied warranty of
41 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 GNU General Public License for more details.
44 You should have received a copy of the GNU General Public License
45 along with this program; if not, write to the Free Software
46 Foundation, Inc., 59 Temple Place - Suite 330,
47 Boston, MA 02111-1307, USA. */])
55 # b4_ints_in(INT1, INT2, LOW, HIGH)
56 # ---------------------------------
57 # Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
58 m4_define([b4_ints_in],
59 [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
62 # b4_int_type(MIN, MAX)
63 # ---------------------
64 # Return the smallest int type able to handle numbers ranging from
65 # MIN to MAX (included).
66 m4_define([b4_int_type],
67 [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
68 b4_ints_in($@, [-128], [127]), [1], [yysigned_char],
70 b4_ints_in($@, [0], [65535]), [1], [unsigned short],
71 b4_ints_in($@, [-32768], [32767]), [1], [short],
73 m4_eval([0 <= $1]), [1], [unsigned int],
77 # b4_int_type_for(NAME)
78 # ---------------------
79 # Return the smallest int type able to handle numbers ranging from
80 # `NAME_min' to `NAME_max' (included).
81 m4_define([b4_int_type_for],
82 [b4_int_type($1_min, $1_max)])
85 ## ------------------ ##
86 ## Decoding options. ##
87 ## ------------------ ##
90 # b4_location_if(IF-TRUE, IF-FALSE)
91 # ---------------------------------
92 # Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
93 m4_define([b4_location_if],
94 [m4_if(b4_locations_flag, [1],
99 # b4_pure_if(IF-TRUE, IF-FALSE)
100 # -----------------------------
101 # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
102 m4_define([b4_pure_if],
109 ## ------------------------- ##
110 ## Assigning token numbers. ##
111 ## ------------------------- ##
113 # b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
114 # -----------------------------------------
115 # Output the definition of this token as #define.
116 m4_define([b4_token_define],
121 # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
122 # ---------------------------------------
123 # Output the definition of this token as an enum.
124 m4_define([b4_token_enum],
128 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
129 # -------------------------------------------------------
130 # Output the definition of the tokens (if there are) as enums and #define.
131 m4_define([b4_token_defines],
132 [m4_if([$@], [[]], [],
136 /* Put the tokens into the symbol table, so that GDB and other debuggers
139 m4_map_sep([ b4_token_enum], [,
144 m4_map([b4_token_define], [$@])
150 ## --------------------------------------------- ##
151 ## Defining C functions in both K&R and ANSI-C. ##
152 ## --------------------------------------------- ##
155 # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
156 # ----------------------------------------------------------
157 # Declare the function NAME.
158 m4_define([b4_c_function_def],
159 [#if defined (__STDC__) || defined (__cplusplus)
160 b4_c_ansi_function_def($@)
163 $1 (b4_c_knr_formal_names(m4_shiftn(2, $@)))
164 b4_c_knr_formal_decls(m4_shiftn(2, $@))
169 # b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
170 # ---------------------------------------------------------------
171 # Declare the function NAME in ANSI.
172 m4_define([b4_c_ansi_function_def],
174 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)))[]dnl
178 # b4_c_ansi_formals([DECL1, NAME1], ...)
179 # --------------------------------------
180 # Output the arguments ANSI-C definition.
181 m4_define([b4_c_ansi_formals],
185 [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
187 m4_define([b4_c_ansi_formal],
191 # b4_c_knr_formal_names([DECL1, NAME1], ...)
192 # ------------------------------------------
193 # Output the argument names.
194 m4_define([b4_c_knr_formal_names],
195 [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])])
197 m4_define([b4_c_knr_formal_name],
201 # b4_c_knr_formal_decls([DECL1, NAME1], ...)
202 # ------------------------------------------
203 # Output the K&R argument declarations.
204 m4_define([b4_c_knr_formal_decls],
205 [m4_map_sep([b4_c_knr_formal_decl],
210 m4_define([b4_c_knr_formal_decl],
215 ## ------------------------------------------------------------ ##
216 ## Declaring (prototyping) C functions in both K&R and ANSI-C. ##
217 ## ------------------------------------------------------------ ##
220 # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
221 # -----------------------------------------------------------
222 # Declare the function NAME.
223 m4_define([b4_c_function_decl],
224 [#if defined (__STDC__) || defined (__cplusplus)
225 b4_c_ansi_function_decl($@)
232 # b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
233 # ----------------------------------------------------------------
234 # Declare the function NAME.
235 m4_define([b4_c_ansi_function_decl],
236 [$2 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)));[]dnl
242 ## --------------------- ##
243 ## Calling C functions. ##
244 ## --------------------- ##
247 # b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
248 # -----------------------------------------------------------
249 # Call the function NAME with arguments NAME1, NAME2 etc.
250 m4_define([b4_c_function_call],
251 [$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl
255 # b4_c_args([DECL1, NAME1], ...)
256 # ------------------------------
257 # Output the arguments NAME1, NAME2...
258 m4_define([b4_c_args],
259 [m4_map_sep([b4_c_arg], [, ], [$@])])
261 m4_define([b4_c_arg],