]>
Commit | Line | Data |
---|---|---|
55b929ca | 1 | m4_divert(-1) -*- Autoconf -*- |
fb8135fa AD |
2 | |
3 | # C M4 Macros for Bison. | |
9662b512 | 4 | # Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. |
fb8135fa AD |
5 | |
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. | |
10 | ||
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. | |
15 | ||
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 | |
0fb669f9 PE |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | # 02110-1301 USA | |
fb8135fa AD |
20 | |
21 | ||
2a8d363a AD |
22 | ## ---------------- ## |
23 | ## Identification. ## | |
24 | ## ---------------- ## | |
fb8135fa AD |
25 | |
26 | # b4_copyright(TITLE, YEARS) | |
27 | # -------------------------- | |
28 | m4_define([b4_copyright], | |
fa3f2a88 | 29 | [/* A Bison parser, made by GNU Bison b4_version. */ |
fb8135fa AD |
30 | |
31 | /* $1, | |
c76e14da | 32 | Copyright (C) $2 Free Software Foundation, Inc. |
fb8135fa AD |
33 | |
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) | |
37 | any later version. | |
38 | ||
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. | |
43 | ||
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 | |
0fb669f9 PE |
46 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
47 | Boston, MA 02110-1301, USA. */]) | |
fb8135fa AD |
48 | |
49 | ||
2a8d363a AD |
50 | # b4_identification |
51 | # ----------------- | |
52 | m4_define([b4_identification], | |
53 | [/* Identify Bison output. */ | |
54 | [#]define YYBISON 1 | |
55 | ||
55f64b82 PE |
56 | /* Bison version. */ |
57 | [#]define YYBISON_VERSION "b4_version" | |
58 | ||
2a8d363a | 59 | /* Skeleton name. */ |
fa3f2a88 | 60 | [#]define YYSKELETON_NAME b4_skeleton |
2a8d363a AD |
61 | |
62 | /* Pure parsers. */ | |
63 | [#]define YYPURE b4_pure | |
64 | ||
65 | /* Using locations. */ | |
66 | [#]define YYLSP_NEEDED b4_locations_flag | |
67 | ]) | |
68 | ||
69 | ||
70 | ||
7ec2d4cd AD |
71 | ## ---------------- ## |
72 | ## Default values. ## | |
73 | ## ---------------- ## | |
74 | ||
75 | m4_define_default([b4_epilogue], []) | |
76 | ||
77 | ||
78 | ||
2a8d363a AD |
79 | ## ------------------------ ## |
80 | ## Pure/impure interfaces. ## | |
81 | ## ------------------------ ## | |
82 | ||
83 | ||
84 | # b4_user_args | |
85 | # ------------ | |
86 | m4_define([b4_user_args], | |
87 | [m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])]) | |
88 | ||
89 | ||
90 | # b4_parse_param | |
91 | # -------------- | |
92 | # If defined, b4_parse_param arrives double quoted, but below we prefer | |
93 | # it to be single quoted. | |
94 | m4_define_default([b4_parse_param]) | |
95 | m4_define([b4_parse_param], | |
96 | b4_parse_param)) | |
97 | ||
613d8952 AD |
98 | # b4_parse_param_for(DECL, FORMAL, BODY) |
99 | # --------------------------------------- | |
100 | # Iterate over the user parameters, binding the declaration to DECL, | |
101 | # the formal name to FORMAL, and evaluating the BODY. | |
102 | m4_define([b4_parse_param_for], | |
103 | [m4_foreach([$1_$2], m4_defn([b4_parse_param]), | |
104 | [m4_pushdef([$1], m4_fst($1_$2))dnl | |
105 | m4_pushdef([$2], m4_shift($1_$2))dnl | |
106 | $3[]dnl | |
107 | m4_popdef([$2])dnl | |
108 | m4_popdef([$1])dnl | |
109 | ])]) | |
110 | ||
111 | # b4_parse_param_use | |
112 | # ------------------ | |
113 | # `YYUSE' all the parse-params. | |
613d8952 AD |
114 | m4_define([b4_parse_param_use], |
115 | [b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal); | |
116 | ])dnl | |
117 | ]) | |
2a8d363a | 118 | |
fb8135fa AD |
119 | ## ------------ ## |
120 | ## Data Types. ## | |
121 | ## ------------ ## | |
122 | ||
fb8135fa | 123 | |
a762e609 AD |
124 | # b4_ints_in(INT1, INT2, LOW, HIGH) |
125 | # --------------------------------- | |
126 | # Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise. | |
127 | m4_define([b4_ints_in], | |
128 | [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])]) | |
129 | ||
130 | ||
131 | # b4_int_type(MIN, MAX) | |
132 | # --------------------- | |
133 | # Return the smallest int type able to handle numbers ranging from | |
134 | # MIN to MAX (included). | |
135 | m4_define([b4_int_type], | |
136 | [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], | |
f1886bb2 | 137 | b4_ints_in($@, [-128], [127]), [1], [signed char], |
a762e609 | 138 | |
779e7ceb PE |
139 | b4_ints_in($@, [0], [65535]), [1], [unsigned short int], |
140 | b4_ints_in($@, [-32768], [32767]), [1], [short int], | |
a762e609 AD |
141 | |
142 | m4_eval([0 <= $1]), [1], [unsigned int], | |
143 | ||
04098407 | 144 | [int])]) |
a762e609 | 145 | |
f1886bb2 | 146 | |
a762e609 AD |
147 | # b4_int_type_for(NAME) |
148 | # --------------------- | |
149 | # Return the smallest int type able to handle numbers ranging from | |
150 | # `NAME_min' to `NAME_max' (included). | |
151 | m4_define([b4_int_type_for], | |
152 | [b4_int_type($1_min, $1_max)]) | |
fb8135fa AD |
153 | |
154 | ||
0245f82d AD |
155 | ## ------------------ ## |
156 | ## Decoding options. ## | |
157 | ## ------------------ ## | |
158 | ||
159 | ||
d4fb5e3c AD |
160 | # b4_error_verbose_if(IF-TRUE, IF-FALSE) |
161 | # -------------------------------------- | |
162 | # Expand IF-TRUE, if errors are verbose, IF-FALSE otherwise. | |
163 | m4_define([b4_error_verbose_if], | |
164 | [m4_if(b4_error_verbose, [1], | |
165 | [$1], | |
166 | [$2])]) | |
167 | ||
168 | ||
0245f82d AD |
169 | # b4_location_if(IF-TRUE, IF-FALSE) |
170 | # --------------------------------- | |
171 | # Expand IF-TRUE, if locations are used, IF-FALSE otherwise. | |
172 | m4_define([b4_location_if], | |
173 | [m4_if(b4_locations_flag, [1], | |
174 | [$1], | |
175 | [$2])]) | |
176 | ||
177 | ||
178 | # b4_pure_if(IF-TRUE, IF-FALSE) | |
179 | # ----------------------------- | |
180 | # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise. | |
181 | m4_define([b4_pure_if], | |
182 | [m4_if(b4_pure, [1], | |
183 | [$1], | |
184 | [$2])]) | |
185 | ||
186 | ||
187 | ||
fb8135fa AD |
188 | ## ------------------------- ## |
189 | ## Assigning token numbers. ## | |
190 | ## ------------------------- ## | |
191 | ||
192 | # b4_token_define(TOKEN-NAME, TOKEN-NUMBER) | |
193 | # ----------------------------------------- | |
194 | # Output the definition of this token as #define. | |
195 | m4_define([b4_token_define], | |
196 | [#define $1 $2 | |
197 | ]) | |
198 | ||
199 | ||
cf147260 AD |
200 | # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) |
201 | # ------------------------------------------------------- | |
202 | # Output the definition of the tokens (if there are) as #defines. | |
203 | m4_define([b4_token_defines], | |
204 | [m4_if([$@], [[]], [], | |
205 | [/* Tokens. */ | |
206 | m4_map([b4_token_define], [$@])]) | |
207 | ]) | |
208 | ||
209 | ||
fb8135fa AD |
210 | # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) |
211 | # --------------------------------------- | |
212 | # Output the definition of this token as an enum. | |
213 | m4_define([b4_token_enum], | |
214 | [$1 = $2]) | |
215 | ||
216 | ||
cf147260 AD |
217 | # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) |
218 | # ----------------------------------------------------- | |
219 | # Output the definition of the tokens (if there are) as enums. | |
220 | m4_define([b4_token_enums], | |
fb8135fa AD |
221 | [m4_if([$@], [[]], [], |
222 | [/* Tokens. */ | |
6b8c3254 PE |
223 | #ifndef YYTOKENTYPE |
224 | # define YYTOKENTYPE | |
fb8135fa AD |
225 | /* Put the tokens into the symbol table, so that GDB and other debuggers |
226 | know about them. */ | |
227 | enum yytokentype { | |
228 | m4_map_sep([ b4_token_enum], [, | |
229 | ], | |
230 | [$@]) | |
231 | }; | |
095b9f05 | 232 | #endif |
cf147260 AD |
233 | ])]) |
234 | ||
235 | ||
236 | # b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) | |
237 | # ------------------------------------------------------------- | |
238 | # Output the definition of the tokens (if there are) as enums and #defines. | |
239 | m4_define([b4_token_enums_defines], | |
240 | [b4_token_enums($@)b4_token_defines($@) | |
fb8135fa | 241 | ]) |
4a2a22f4 AD |
242 | |
243 | ||
ae7453f2 | 244 | |
0245f82d AD |
245 | ## --------------------------------------------- ## |
246 | ## Defining C functions in both K&R and ANSI-C. ## | |
247 | ## --------------------------------------------- ## | |
4a2a22f4 AD |
248 | |
249 | ||
0245f82d AD |
250 | # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
251 | # ---------------------------------------------------------- | |
4a2a22f4 | 252 | # Declare the function NAME. |
0245f82d | 253 | m4_define([b4_c_function_def], |
ba0fe3c7 | 254 | [#if defined (__STDC__) || defined (__C99__FUNC__) || defined (__cplusplus) |
0245f82d | 255 | b4_c_ansi_function_def($@) |
4a2a22f4 | 256 | #else |
0245f82d AD |
257 | $2 |
258 | $1 (b4_c_knr_formal_names(m4_shiftn(2, $@))) | |
259 | b4_c_knr_formal_decls(m4_shiftn(2, $@)) | |
4a2a22f4 AD |
260 | #endif[]dnl |
261 | ]) | |
262 | ||
263 | ||
0245f82d AD |
264 | # b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
265 | # --------------------------------------------------------------- | |
266 | # Declare the function NAME in ANSI. | |
267 | m4_define([b4_c_ansi_function_def], | |
268 | [$2 | |
269 | $1 (b4_c_ansi_formals(m4_shiftn(2, $@)))[]dnl | |
270 | ]) | |
271 | ||
272 | ||
273 | # b4_c_ansi_formals([DECL1, NAME1], ...) | |
274 | # -------------------------------------- | |
4a2a22f4 | 275 | # Output the arguments ANSI-C definition. |
0245f82d AD |
276 | m4_define([b4_c_ansi_formals], |
277 | [m4_case([$@], | |
278 | [], [void], | |
279 | [[]], [void], | |
280 | [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])]) | |
4a2a22f4 | 281 | |
0245f82d AD |
282 | m4_define([b4_c_ansi_formal], |
283 | [$1]) | |
4a2a22f4 AD |
284 | |
285 | ||
0245f82d AD |
286 | # b4_c_knr_formal_names([DECL1, NAME1], ...) |
287 | # ------------------------------------------ | |
4a2a22f4 | 288 | # Output the argument names. |
0245f82d AD |
289 | m4_define([b4_c_knr_formal_names], |
290 | [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])]) | |
4a2a22f4 | 291 | |
0245f82d | 292 | m4_define([b4_c_knr_formal_name], |
4a2a22f4 AD |
293 | [$2]) |
294 | ||
295 | ||
0245f82d AD |
296 | # b4_c_knr_formal_decls([DECL1, NAME1], ...) |
297 | # ------------------------------------------ | |
4a2a22f4 | 298 | # Output the K&R argument declarations. |
0245f82d AD |
299 | m4_define([b4_c_knr_formal_decls], |
300 | [m4_map_sep([b4_c_knr_formal_decl], | |
4a2a22f4 AD |
301 | [ |
302 | ], | |
303 | [$@])]) | |
304 | ||
0245f82d AD |
305 | m4_define([b4_c_knr_formal_decl], |
306 | [ $1;]) | |
21964f43 AD |
307 | |
308 | ||
309 | ||
0245f82d AD |
310 | ## ------------------------------------------------------------ ## |
311 | ## Declaring (prototyping) C functions in both K&R and ANSI-C. ## | |
312 | ## ------------------------------------------------------------ ## | |
21964f43 AD |
313 | |
314 | ||
0245f82d AD |
315 | # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
316 | # ----------------------------------------------------------- | |
317 | # Declare the function NAME. | |
318 | m4_define([b4_c_function_decl], | |
319 | [#if defined (__STDC__) || defined (__cplusplus) | |
320 | b4_c_ansi_function_decl($@) | |
321 | #else | |
322 | $2 $1 (); | |
323 | #endif[]dnl | |
324 | ]) | |
21964f43 AD |
325 | |
326 | ||
0245f82d AD |
327 | # b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
328 | # ---------------------------------------------------------------- | |
329 | # Declare the function NAME. | |
330 | m4_define([b4_c_ansi_function_decl], | |
331 | [$2 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)));[]dnl | |
332 | ]) | |
333 | ||
334 | ||
335 | ||
336 | ||
337 | ## --------------------- ## | |
338 | ## Calling C functions. ## | |
339 | ## --------------------- ## | |
340 | ||
341 | ||
342 | # b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...) | |
343 | # ----------------------------------------------------------- | |
344 | # Call the function NAME with arguments NAME1, NAME2 etc. | |
345 | m4_define([b4_c_function_call], | |
346 | [$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl | |
347 | ]) | |
348 | ||
349 | ||
350 | # b4_c_args([DECL1, NAME1], ...) | |
351 | # ------------------------------ | |
352 | # Output the arguments NAME1, NAME2... | |
353 | m4_define([b4_c_args], | |
354 | [m4_map_sep([b4_c_arg], [, ], [$@])]) | |
355 | ||
356 | m4_define([b4_c_arg], | |
357 | [$2]) | |
437c2d80 AD |
358 | |
359 | ||
360 | ## ----------- ## | |
361 | ## Synclines. ## | |
362 | ## ----------- ## | |
363 | ||
437c2d80 AD |
364 | # b4_syncline(LINE, FILE) |
365 | # ----------------------- | |
366 | m4_define([b4_syncline], | |
367 | [m4_if(b4_synclines_flag, 1, | |
fa3f2a88 | 368 | [[#]line $1 $2])]) |
b0400cc6 AD |
369 | |
370 | ||
613d8952 AD |
371 | |
372 | ## -------------- ## | |
373 | ## User actions. ## | |
374 | ## -------------- ## | |
375 | ||
b0400cc6 AD |
376 | # b4_symbol_actions(FILENAME, LINENO, |
377 | # SYMBOL-TAG, SYMBOL-NUM, | |
378 | # SYMBOL-ACTION, SYMBOL-TYPENAME) | |
379 | # ------------------------------------------------- | |
380 | m4_define([b4_symbol_actions], | |
60c82948 PE |
381 | [m4_pushdef([b4_dollar_dollar], |
382 | [m4_ifval([$6], [(yyvaluep->$6)], [(*yyvaluep)])])dnl | |
7bd6c77e | 383 | m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl |
b0400cc6 AD |
384 | case $4: /* $3 */ |
385 | b4_syncline([$2], [$1]) | |
386 | $5; | |
387 | b4_syncline([@oline@], [@ofile@]) | |
388 | break; | |
389 | m4_popdef([b4_at_dollar])dnl | |
390 | m4_popdef([b4_dollar_dollar])dnl | |
391 | ]) | |
392 | ||
393 | ||
14740648 PE |
394 | # b4_yydestruct_generate(FUNCTION-DECLARATOR) |
395 | # ------------------------------------------- | |
b0400cc6 | 396 | # Generate the "yydestruct" function, which declaration is issued using |
14740648 | 397 | # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C |
b0400cc6 | 398 | # or "b4_c_function_def" for K&R. |
cf147260 | 399 | m4_define_default([b4_yydestruct_generate], |
b0400cc6 AD |
400 | [[/*-----------------------------------------------. |
401 | | Release the memory associated to this symbol. | | |
402 | `-----------------------------------------------*/ | |
403 | ||
12ce2df6 | 404 | /*ARGSUSED*/ |
b0400cc6 AD |
405 | ]$1([yydestruct], |
406 | [static void], | |
a0e68930 | 407 | [[const char *yymsg], [yymsg]], |
7bd6c77e | 408 | [[int yytype], [yytype]], |
4b367315 AD |
409 | [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl |
410 | b4_location_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl | |
411 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ | |
b0400cc6 | 412 | { |
2a4647a3 PE |
413 | YYUSE (yyvaluep); |
414 | ]b4_location_if([ YYUSE (yylocationp); | |
613d8952 AD |
415 | ])dnl |
416 | b4_parse_param_use[]dnl | |
417 | [ | |
a0e68930 AD |
418 | if (!yymsg) |
419 | yymsg = "Deleting"; | |
420 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); | |
421 | ||
b0400cc6 AD |
422 | switch (yytype) |
423 | { | |
424 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[ | |
425 | default: | |
426 | break; | |
427 | } | |
428 | }]dnl | |
429 | ]) | |
7bd6c77e AD |
430 | |
431 | ||
a0af42fc AD |
432 | # b4_yy_symbol_print_generate(FUNCTION-DECLARATOR) |
433 | # ------------------------------------------------ | |
434 | # Generate the "yy_symbol_print" function, which declaration is issued using | |
14740648 | 435 | # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C |
7bd6c77e | 436 | # or "b4_c_function_def" for K&R. |
a0af42fc AD |
437 | m4_define_default([b4_yy_symbol_print_generate], |
438 | [[ | |
439 | /*--------------------------------. | |
14740648 PE |
440 | | Print this symbol on YYOUTPUT. | |
441 | `--------------------------------*/ | |
7bd6c77e | 442 | |
12ce2df6 | 443 | /*ARGSUSED*/ |
a0af42fc | 444 | ]$1([yy_symbol_value_print], |
7bd6c77e | 445 | [static void], |
62b08cfc AD |
446 | [[FILE *yyoutput], [yyoutput]], |
447 | [[int yytype], [yytype]], | |
448 | [[const YYSTYPE * const yyvaluep], [yyvaluep]][]dnl | |
449 | b4_location_if([, [[const YYLTYPE * const yylocationp], [yylocationp]]])[]dnl | |
4b367315 | 450 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
7bd6c77e | 451 | { |
2a4647a3 | 452 | YYUSE (yyvaluep); |
4b367315 | 453 | ]b4_location_if([ YYUSE (yylocationp); |
7bd6c77e | 454 | ])dnl |
613d8952 | 455 | b4_parse_param_use[]dnl |
a0af42fc | 456 | [# ifdef YYPRINT |
619404e3 AD |
457 | if (yytype < YYNTOKENS) |
458 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); | |
459 | # endif | |
7bd6c77e AD |
460 | switch (yytype) |
461 | { | |
3fc16193 AD |
462 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl |
463 | [ default: | |
7bd6c77e AD |
464 | break; |
465 | } | |
a0af42fc AD |
466 | } |
467 | ||
468 | ||
469 | /*--------------------------------. | |
470 | | Print this symbol on YYOUTPUT. | | |
471 | `--------------------------------*/ | |
472 | ||
473 | ]$1([yy_symbol_print], | |
474 | [static void], | |
475 | [[FILE *yyoutput], [yyoutput]], | |
476 | [[int yytype], [yytype]], | |
477 | [[const YYSTYPE * const yyvaluep], [yyvaluep]][]dnl | |
478 | b4_location_if([, [[const YYLTYPE * const yylocationp], [yylocationp]]])[]dnl | |
479 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ | |
480 | { | |
481 | if (yytype < YYNTOKENS) | |
482 | YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); | |
483 | else | |
484 | YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); | |
485 | ||
486 | ]b4_location_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp); | |
487 | YYFPRINTF (yyoutput, ": "); | |
488 | ])dnl | |
489 | [ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl | |
490 | b4_location_if([, yylocationp])[]b4_user_args[); | |
2f4f028d | 491 | YYFPRINTF (yyoutput, ")"); |
4b367315 AD |
492 | }]dnl |
493 | ]) |