]>
Commit | Line | Data |
---|---|---|
08af01c2 | 1 | -*- Autoconf -*- |
fb8135fa AD |
2 | |
3 | # C M4 Macros for Bison. | |
6e30ede8 | 4 | |
c932d613 | 5 | # Copyright (C) 2002, 2004-2012 Free Software Foundation, Inc. |
fb8135fa | 6 | |
f16b0819 | 7 | # This program is free software: you can redistribute it and/or modify |
fb8135fa | 8 | # it under the terms of the GNU General Public License as published by |
f16b0819 | 9 | # the Free Software Foundation, either version 3 of the License, or |
fb8135fa | 10 | # (at your option) any later version. |
f16b0819 | 11 | # |
fb8135fa AD |
12 | # This program is distributed in the hope that it will be useful, |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
f16b0819 | 16 | # |
fb8135fa | 17 | # You should have received a copy of the GNU General Public License |
f16b0819 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
fb8135fa | 19 | |
cd735a8c | 20 | m4_include(b4_pkgdatadir/[c-like.m4]) |
22172d47 AD |
21 | |
22 | # b4_tocpp(STRING) | |
23 | # ---------------- | |
24 | # Convert STRING into a valid C macro name. | |
25 | m4_define([b4_tocpp], | |
26 | [m4_toupper(m4_bpatsubst(m4_quote($1), [[^a-zA-Z0-9]+], [_]))]) | |
27 | ||
28 | ||
29 | # b4_cpp_guard(FILE) | |
30 | # ------------------ | |
31 | # A valid C macro name to use as a CPP header guard for FILE. | |
32 | m4_define([b4_cpp_guard], | |
33 | [b4_tocpp(m4_defn([b4_prefix])/[$1])]) | |
34 | ||
35 | ||
36 | # b4_cpp_guard_open(FILE) | |
37 | # b4_cpp_guard_close(FILE) | |
38 | # ------------------------ | |
39 | # Open/close CPP inclusion guards for FILE. | |
40 | m4_define([b4_cpp_guard_open], | |
41 | [#ifndef b4_cpp_guard([$1]) | |
42 | # define b4_cpp_guard([$1])]) | |
43 | ||
44 | m4_define([b4_cpp_guard_close], | |
45 | [#endif b4_comment([!b4_cpp_guard([$1])])]) | |
46 | ||
47 | ||
2a8d363a AD |
48 | ## ---------------- ## |
49 | ## Identification. ## | |
50 | ## ---------------- ## | |
fb8135fa | 51 | |
90b9908d PB |
52 | # b4_comment(TEXT) |
53 | # ---------------- | |
54 | m4_define([b4_comment], [/* m4_bpatsubst([$1], [ | |
55 | ], [ | |
56 | ]) */]) | |
fb8135fa | 57 | |
2a8d363a AD |
58 | # b4_identification |
59 | # ----------------- | |
d9df47b6 JD |
60 | # Depends on individual skeletons to define b4_pure_flag, b4_push_flag, or |
61 | # b4_pull_flag if they use the values of the %define variables api.pure or | |
812775a0 | 62 | # api.push-pull. |
2a8d363a | 63 | m4_define([b4_identification], |
d9df47b6 JD |
64 | [[/* Identify Bison output. */ |
65 | #define YYBISON 1 | |
2a8d363a | 66 | |
55f64b82 | 67 | /* Bison version. */ |
d9df47b6 | 68 | #define YYBISON_VERSION "]b4_version[" |
55f64b82 | 69 | |
2a8d363a | 70 | /* Skeleton name. */ |
d9df47b6 | 71 | #define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[ |
2a8d363a AD |
72 | |
73 | /* Pure parsers. */ | |
d9df47b6 JD |
74 | #define YYPURE ]b4_pure_flag])[]m4_ifdef([b4_push_flag], [[ |
75 | ||
76 | /* Push parsers. */ | |
77 | #define YYPUSH ]b4_push_flag])[]m4_ifdef([b4_pull_flag], [[ | |
78 | ||
79 | /* Pull parsers. */ | |
80 | #define YYPULL ]b4_pull_flag])[ | |
d9df47b6 | 81 | ]]) |
2a8d363a AD |
82 | |
83 | ||
7ec2d4cd AD |
84 | ## ---------------- ## |
85 | ## Default values. ## | |
86 | ## ---------------- ## | |
87 | ||
4b3847c3 AD |
88 | # b4_api_prefix, b4_api_PREFIX |
89 | # ---------------------------- | |
90 | # Corresponds to %define api.prefix | |
91 | b4_percent_define_default([[api.prefix]], [[yy]]) | |
92 | m4_define([b4_api_prefix], | |
93 | [b4_percent_define_get([[api.prefix]])]) | |
94 | m4_define([b4_api_PREFIX], | |
95 | [m4_toupper(b4_api_prefix)]) | |
96 | ||
97 | ||
98 | # b4_prefix | |
99 | # --------- | |
100 | # If the %name-prefix is not given, it is api.prefix. | |
101 | m4_define_default([b4_prefix], [b4_api_prefix]) | |
102 | ||
1b818f33 | 103 | # If the %union is not named, its name is YYSTYPE. |
4b3847c3 | 104 | m4_define_default([b4_union_name], [b4_api_PREFIX[]STYPE]) |
7ec2d4cd | 105 | |
cd48d21d | 106 | |
2a8d363a AD |
107 | ## ------------------------ ## |
108 | ## Pure/impure interfaces. ## | |
109 | ## ------------------------ ## | |
110 | ||
2a8d363a AD |
111 | # b4_user_args |
112 | # ------------ | |
113 | m4_define([b4_user_args], | |
114 | [m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])]) | |
115 | ||
116 | ||
117 | # b4_parse_param | |
118 | # -------------- | |
119 | # If defined, b4_parse_param arrives double quoted, but below we prefer | |
120 | # it to be single quoted. | |
2a8d363a | 121 | m4_define([b4_parse_param], |
7ecec4dd | 122 | b4_parse_param) |
2a8d363a | 123 | |
8f7e3cf9 | 124 | |
613d8952 AD |
125 | # b4_parse_param_for(DECL, FORMAL, BODY) |
126 | # --------------------------------------- | |
127 | # Iterate over the user parameters, binding the declaration to DECL, | |
128 | # the formal name to FORMAL, and evaluating the BODY. | |
129 | m4_define([b4_parse_param_for], | |
130 | [m4_foreach([$1_$2], m4_defn([b4_parse_param]), | |
6bbb2ed5 | 131 | [m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl |
613d8952 AD |
132 | m4_pushdef([$2], m4_shift($1_$2))dnl |
133 | $3[]dnl | |
134 | m4_popdef([$2])dnl | |
135 | m4_popdef([$1])dnl | |
136 | ])]) | |
137 | ||
138 | # b4_parse_param_use | |
139 | # ------------------ | |
140 | # `YYUSE' all the parse-params. | |
613d8952 AD |
141 | m4_define([b4_parse_param_use], |
142 | [b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal); | |
143 | ])dnl | |
144 | ]) | |
2a8d363a | 145 | |
8e1687ae | 146 | |
fb8135fa AD |
147 | ## ------------ ## |
148 | ## Data Types. ## | |
149 | ## ------------ ## | |
150 | ||
a762e609 AD |
151 | # b4_int_type(MIN, MAX) |
152 | # --------------------- | |
153 | # Return the smallest int type able to handle numbers ranging from | |
154 | # MIN to MAX (included). | |
155 | m4_define([b4_int_type], | |
156 | [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], | |
f1886bb2 | 157 | b4_ints_in($@, [-128], [127]), [1], [signed char], |
a762e609 | 158 | |
779e7ceb PE |
159 | b4_ints_in($@, [0], [65535]), [1], [unsigned short int], |
160 | b4_ints_in($@, [-32768], [32767]), [1], [short int], | |
a762e609 AD |
161 | |
162 | m4_eval([0 <= $1]), [1], [unsigned int], | |
163 | ||
02650b7f | 164 | [int])]) |
a762e609 | 165 | |
f1886bb2 | 166 | |
a762e609 AD |
167 | # b4_int_type_for(NAME) |
168 | # --------------------- | |
169 | # Return the smallest int type able to handle numbers ranging from | |
170 | # `NAME_min' to `NAME_max' (included). | |
171 | m4_define([b4_int_type_for], | |
172 | [b4_int_type($1_min, $1_max)]) | |
fb8135fa | 173 | |
cf98343c | 174 | |
77373efa JD |
175 | # b4_table_value_equals(TABLE, VALUE, LITERAL) |
176 | # -------------------------------------------- | |
177 | # Without inducing a comparison warning from the compiler, check if the | |
178 | # literal value LITERAL equals VALUE from table TABLE, which must have | |
d5eb0826 JD |
179 | # TABLE_min and TABLE_max defined. YYID must be defined as an identity |
180 | # function that suppresses warnings about constant conditions. | |
77373efa JD |
181 | m4_define([b4_table_value_equals], |
182 | [m4_if(m4_eval($3 < m4_indir([b4_]$1[_min]) | |
183 | || m4_indir([b4_]$1[_max]) < $3), [1], | |
184 | [[YYID (0)]], | |
185 | [[((]$2[) == (]$3[))]])]) | |
cf98343c | 186 | |
ef51bfa7 | 187 | |
8e1687ae PE |
188 | ## ---------## |
189 | ## Values. ## | |
190 | ## ---------## | |
191 | ||
8e1687ae | 192 | |
ef51bfa7 AD |
193 | # b4_null_define |
194 | # -------------- | |
195 | # Portability issues: define a YY_NULL appropriate for the current | |
196 | # language (C, C++98, or C++11). | |
197 | m4_define([b4_null_define], | |
198 | [# ifndef YY_NULL | |
199 | # if defined __cplusplus && 201103L <= __cplusplus | |
200 | # define YY_NULL nullptr | |
201 | # else | |
202 | # define YY_NULL 0 | |
203 | # endif | |
204 | # endif[]dnl | |
205 | ]) | |
206 | ||
207 | ||
208 | # b4_null | |
209 | # ------- | |
210 | # Return a null pointer constant. | |
211 | m4_define([b4_null], [YY_NULL]) | |
8e1687ae | 212 | |
cf98343c AD |
213 | |
214 | ||
fb8135fa AD |
215 | ## ------------------------- ## |
216 | ## Assigning token numbers. ## | |
217 | ## ------------------------- ## | |
218 | ||
219 | # b4_token_define(TOKEN-NAME, TOKEN-NUMBER) | |
220 | # ----------------------------------------- | |
221 | # Output the definition of this token as #define. | |
222 | m4_define([b4_token_define], | |
223 | [#define $1 $2 | |
224 | ]) | |
225 | ||
226 | ||
cf147260 AD |
227 | # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) |
228 | # ------------------------------------------------------- | |
229 | # Output the definition of the tokens (if there are) as #defines. | |
230 | m4_define([b4_token_defines], | |
6bbb2ed5 | 231 | [m4_if([$#$1], [1], [], |
cf147260 AD |
232 | [/* Tokens. */ |
233 | m4_map([b4_token_define], [$@])]) | |
234 | ]) | |
235 | ||
236 | ||
fb8135fa AD |
237 | # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) |
238 | # --------------------------------------- | |
239 | # Output the definition of this token as an enum. | |
240 | m4_define([b4_token_enum], | |
241 | [$1 = $2]) | |
242 | ||
243 | ||
cf147260 AD |
244 | # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) |
245 | # ----------------------------------------------------- | |
246 | # Output the definition of the tokens (if there are) as enums. | |
247 | m4_define([b4_token_enums], | |
6bbb2ed5 | 248 | [m4_if([$#$1], [1], [], |
4b3847c3 AD |
249 | [[/* Tokens. */ |
250 | #ifndef ]b4_api_PREFIX[TOKENTYPE | |
251 | # define ]b4_api_PREFIX[TOKENTYPE | |
fb8135fa AD |
252 | /* Put the tokens into the symbol table, so that GDB and other debuggers |
253 | know about them. */ | |
4b3847c3 AD |
254 | enum ]b4_api_prefix[tokentype { |
255 | ]m4_map_sep([ b4_token_enum], [, | |
fb8135fa | 256 | ], |
4b3847c3 | 257 | [$@])[ |
fb8135fa | 258 | }; |
095b9f05 | 259 | #endif |
4b3847c3 | 260 | ]])]) |
cf147260 AD |
261 | |
262 | ||
263 | # b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) | |
264 | # ------------------------------------------------------------- | |
b931235e JD |
265 | # Output the definition of the tokens (if there are any) as enums and, if POSIX |
266 | # Yacc is enabled, as #defines. | |
cf147260 | 267 | m4_define([b4_token_enums_defines], |
b931235e | 268 | [b4_token_enums($@)b4_yacc_if([b4_token_defines($@)], []) |
fb8135fa | 269 | ]) |
4a2a22f4 AD |
270 | |
271 | ||
ae7453f2 | 272 | |
0245f82d AD |
273 | ## --------------------------------------------- ## |
274 | ## Defining C functions in both K&R and ANSI-C. ## | |
275 | ## --------------------------------------------- ## | |
4a2a22f4 AD |
276 | |
277 | ||
1b9c21fb PE |
278 | # b4_modern_c |
279 | # ----------- | |
280 | # A predicate useful in #if to determine whether C is ancient or modern. | |
281 | # | |
282 | # If __STDC__ is defined, the compiler is modern. IBM xlc 7.0 when run | |
283 | # as 'cc' doesn't define __STDC__ (or __STDC_VERSION__) for pedantic | |
284 | # reasons, but it defines __C99__FUNC__ so check that as well. | |
285 | # Microsoft C normally doesn't define these macros, but it defines _MSC_VER. | |
7a0db73e | 286 | # Consider a C++ compiler to be modern if it defines __cplusplus. |
1b9c21fb PE |
287 | # |
288 | m4_define([b4_c_modern], | |
02650b7f PE |
289 | [[(defined __STDC__ || defined __C99__FUNC__ \ |
290 | || defined __cplusplus || defined _MSC_VER)]]) | |
1b9c21fb | 291 | |
0245f82d AD |
292 | # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
293 | # ---------------------------------------------------------- | |
4a2a22f4 | 294 | # Declare the function NAME. |
0245f82d | 295 | m4_define([b4_c_function_def], |
1b9c21fb | 296 | [#if b4_c_modern |
0245f82d | 297 | b4_c_ansi_function_def($@) |
4a2a22f4 | 298 | #else |
0245f82d | 299 | $2 |
a3764451 EB |
300 | $1 (b4_c_knr_formal_names(m4_shift2($@))) |
301 | b4_c_knr_formal_decls(m4_shift2($@)) | |
4a2a22f4 AD |
302 | #endif[]dnl |
303 | ]) | |
304 | ||
305 | ||
0245f82d AD |
306 | # b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
307 | # --------------------------------------------------------------- | |
308 | # Declare the function NAME in ANSI. | |
309 | m4_define([b4_c_ansi_function_def], | |
310 | [$2 | |
a3764451 | 311 | $1 (b4_c_ansi_formals(m4_shift2($@)))[]dnl |
0245f82d AD |
312 | ]) |
313 | ||
314 | ||
315 | # b4_c_ansi_formals([DECL1, NAME1], ...) | |
316 | # -------------------------------------- | |
4a2a22f4 | 317 | # Output the arguments ANSI-C definition. |
0245f82d | 318 | m4_define([b4_c_ansi_formals], |
6bbb2ed5 EB |
319 | [m4_if([$#], [0], [void], |
320 | [$#$1], [1], [void], | |
02650b7f | 321 | [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])]) |
4a2a22f4 | 322 | |
0245f82d AD |
323 | m4_define([b4_c_ansi_formal], |
324 | [$1]) | |
4a2a22f4 AD |
325 | |
326 | ||
0245f82d AD |
327 | # b4_c_knr_formal_names([DECL1, NAME1], ...) |
328 | # ------------------------------------------ | |
4a2a22f4 | 329 | # Output the argument names. |
0245f82d AD |
330 | m4_define([b4_c_knr_formal_names], |
331 | [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])]) | |
4a2a22f4 | 332 | |
0245f82d | 333 | m4_define([b4_c_knr_formal_name], |
4a2a22f4 AD |
334 | [$2]) |
335 | ||
336 | ||
0245f82d AD |
337 | # b4_c_knr_formal_decls([DECL1, NAME1], ...) |
338 | # ------------------------------------------ | |
4a2a22f4 | 339 | # Output the K&R argument declarations. |
0245f82d AD |
340 | m4_define([b4_c_knr_formal_decls], |
341 | [m4_map_sep([b4_c_knr_formal_decl], | |
02650b7f | 342 | [ |
4a2a22f4 | 343 | ], |
02650b7f | 344 | [$@])]) |
4a2a22f4 | 345 | |
0245f82d AD |
346 | m4_define([b4_c_knr_formal_decl], |
347 | [ $1;]) | |
21964f43 AD |
348 | |
349 | ||
350 | ||
0245f82d AD |
351 | ## ------------------------------------------------------------ ## |
352 | ## Declaring (prototyping) C functions in both K&R and ANSI-C. ## | |
353 | ## ------------------------------------------------------------ ## | |
21964f43 AD |
354 | |
355 | ||
0245f82d AD |
356 | # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
357 | # ----------------------------------------------------------- | |
358 | # Declare the function NAME. | |
359 | m4_define([b4_c_function_decl], | |
02650b7f | 360 | [#if defined __STDC__ || defined __cplusplus |
0245f82d AD |
361 | b4_c_ansi_function_decl($@) |
362 | #else | |
363 | $2 $1 (); | |
364 | #endif[]dnl | |
365 | ]) | |
21964f43 AD |
366 | |
367 | ||
0245f82d AD |
368 | # b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
369 | # ---------------------------------------------------------------- | |
370 | # Declare the function NAME. | |
371 | m4_define([b4_c_ansi_function_decl], | |
a3764451 | 372 | [$2 $1 (b4_c_ansi_formals(m4_shift2($@)));[]dnl |
0245f82d AD |
373 | ]) |
374 | ||
375 | ||
376 | ||
377 | ||
378 | ## --------------------- ## | |
379 | ## Calling C functions. ## | |
380 | ## --------------------- ## | |
381 | ||
382 | ||
383 | # b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...) | |
384 | # ----------------------------------------------------------- | |
385 | # Call the function NAME with arguments NAME1, NAME2 etc. | |
386 | m4_define([b4_c_function_call], | |
a3764451 | 387 | [$1 (b4_c_args(m4_shift2($@)))[]dnl |
0245f82d AD |
388 | ]) |
389 | ||
390 | ||
391 | # b4_c_args([DECL1, NAME1], ...) | |
392 | # ------------------------------ | |
393 | # Output the arguments NAME1, NAME2... | |
394 | m4_define([b4_c_args], | |
395 | [m4_map_sep([b4_c_arg], [, ], [$@])]) | |
396 | ||
397 | m4_define([b4_c_arg], | |
398 | [$2]) | |
437c2d80 AD |
399 | |
400 | ||
401 | ## ----------- ## | |
402 | ## Synclines. ## | |
403 | ## ----------- ## | |
404 | ||
90b9908d | 405 | # b4_sync_start(LINE, FILE) |
8ec0a172 | 406 | # ----------------------- |
90b9908d | 407 | m4_define([b4_sync_start], [[#]line $1 $2]) |
8ec0a172 | 408 | |
613d8952 AD |
409 | |
410 | ## -------------- ## | |
411 | ## User actions. ## | |
412 | ## -------------- ## | |
413 | ||
8e1687ae PE |
414 | # b4_case(LABEL, STATEMENTS) |
415 | # -------------------------- | |
416 | m4_define([b4_case], | |
417 | [ case $1: | |
418 | $2 | |
419 | break;]) | |
420 | ||
b0400cc6 AD |
421 | # b4_symbol_actions(FILENAME, LINENO, |
422 | # SYMBOL-TAG, SYMBOL-NUM, | |
423 | # SYMBOL-ACTION, SYMBOL-TYPENAME) | |
424 | # ------------------------------------------------- | |
4982f078 AD |
425 | # Issue the code for a symbol action (e.g., %printer). |
426 | # | |
427 | # Define b4_dollar_dollar([TYPE-NAME]), and b4_at_dollar, which are | |
428 | # invoked where $<TYPE-NAME>$ and @$ were specified by the user. | |
b0400cc6 | 429 | m4_define([b4_symbol_actions], |
cd735a8c | 430 | [b4_dollar_pushdef([(*yyvaluep)], [$6], [(*yylocationp)])dnl |
b0400cc6 AD |
431 | case $4: /* $3 */ |
432 | b4_syncline([$2], [$1]) | |
02650b7f | 433 | $5; |
b0400cc6 | 434 | b4_syncline([@oline@], [@ofile@]) |
02650b7f | 435 | break; |
d6a44ffd | 436 | b4_dollar_popdef[]dnl |
b0400cc6 AD |
437 | ]) |
438 | ||
439 | ||
14740648 PE |
440 | # b4_yydestruct_generate(FUNCTION-DECLARATOR) |
441 | # ------------------------------------------- | |
b0400cc6 | 442 | # Generate the "yydestruct" function, which declaration is issued using |
14740648 | 443 | # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C |
b0400cc6 | 444 | # or "b4_c_function_def" for K&R. |
cf147260 | 445 | m4_define_default([b4_yydestruct_generate], |
b0400cc6 AD |
446 | [[/*-----------------------------------------------. |
447 | | Release the memory associated to this symbol. | | |
448 | `-----------------------------------------------*/ | |
449 | ||
12ce2df6 | 450 | /*ARGSUSED*/ |
b0400cc6 AD |
451 | ]$1([yydestruct], |
452 | [static void], | |
a0e68930 | 453 | [[const char *yymsg], [yymsg]], |
7bd6c77e | 454 | [[int yytype], [yytype]], |
4b367315 | 455 | [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl |
327afc7c | 456 | b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl |
4b367315 | 457 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
b0400cc6 | 458 | { |
2a4647a3 | 459 | YYUSE (yyvaluep); |
327afc7c | 460 | ]b4_locations_if([ YYUSE (yylocationp); |
613d8952 AD |
461 | ])dnl |
462 | b4_parse_param_use[]dnl | |
463 | [ | |
a0e68930 AD |
464 | if (!yymsg) |
465 | yymsg = "Deleting"; | |
466 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); | |
467 | ||
b0400cc6 AD |
468 | switch (yytype) |
469 | { | |
470 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[ | |
471 | default: | |
02650b7f | 472 | break; |
b0400cc6 AD |
473 | } |
474 | }]dnl | |
475 | ]) | |
7bd6c77e AD |
476 | |
477 | ||
a0af42fc AD |
478 | # b4_yy_symbol_print_generate(FUNCTION-DECLARATOR) |
479 | # ------------------------------------------------ | |
480 | # Generate the "yy_symbol_print" function, which declaration is issued using | |
14740648 | 481 | # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C |
7bd6c77e | 482 | # or "b4_c_function_def" for K&R. |
a0af42fc AD |
483 | m4_define_default([b4_yy_symbol_print_generate], |
484 | [[ | |
485 | /*--------------------------------. | |
14740648 PE |
486 | | Print this symbol on YYOUTPUT. | |
487 | `--------------------------------*/ | |
7bd6c77e | 488 | |
12ce2df6 | 489 | /*ARGSUSED*/ |
a0af42fc | 490 | ]$1([yy_symbol_value_print], |
7bd6c77e | 491 | [static void], |
02650b7f PE |
492 | [[FILE *yyoutput], [yyoutput]], |
493 | [[int yytype], [yytype]], | |
50cce58e PE |
494 | [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl |
495 | b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl | |
4b367315 | 496 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
7bd6c77e | 497 | { |
68fff38a AD |
498 | FILE *yyo = yyoutput; |
499 | YYUSE (yyo); | |
05449a2c JD |
500 | if (!yyvaluep) |
501 | return; | |
327afc7c | 502 | ]b4_locations_if([ YYUSE (yylocationp); |
7bd6c77e | 503 | ])dnl |
613d8952 | 504 | b4_parse_param_use[]dnl |
a0af42fc | 505 | [# ifdef YYPRINT |
619404e3 AD |
506 | if (yytype < YYNTOKENS) |
507 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); | |
c66dfadd PE |
508 | # else |
509 | YYUSE (yyoutput); | |
619404e3 | 510 | # endif |
7bd6c77e AD |
511 | switch (yytype) |
512 | { | |
3fc16193 AD |
513 | ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl |
514 | [ default: | |
02650b7f | 515 | break; |
7bd6c77e | 516 | } |
a0af42fc AD |
517 | } |
518 | ||
519 | ||
520 | /*--------------------------------. | |
521 | | Print this symbol on YYOUTPUT. | | |
522 | `--------------------------------*/ | |
523 | ||
524 | ]$1([yy_symbol_print], | |
525 | [static void], | |
02650b7f PE |
526 | [[FILE *yyoutput], [yyoutput]], |
527 | [[int yytype], [yytype]], | |
50cce58e PE |
528 | [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl |
529 | b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl | |
a0af42fc AD |
530 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
531 | { | |
532 | if (yytype < YYNTOKENS) | |
533 | YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); | |
534 | else | |
535 | YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); | |
536 | ||
327afc7c | 537 | ]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp); |
a0af42fc AD |
538 | YYFPRINTF (yyoutput, ": "); |
539 | ])dnl | |
540 | [ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl | |
327afc7c | 541 | b4_locations_if([, yylocationp])[]b4_user_args[); |
2f4f028d | 542 | YYFPRINTF (yyoutput, ")"); |
4b367315 AD |
543 | }]dnl |
544 | ]) | |
c0828abf AD |
545 | |
546 | ## -------------- ## | |
547 | ## Declarations. ## | |
548 | ## -------------- ## | |
549 | ||
550 | # b4_declare_yylstype | |
4b3847c3 | 551 | # ------------------- |
756257ee AD |
552 | # Declarations that might either go into the header (if --defines) or |
553 | # in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc. | |
c0828abf | 554 | m4_define([b4_declare_yylstype], |
4b3847c3 | 555 | [[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED |
c0828abf AD |
556 | ]m4_ifdef([b4_stype], |
557 | [[typedef union ]b4_union_name[ | |
558 | { | |
559 | ]b4_user_stype[ | |
4b3847c3 AD |
560 | } ]b4_api_PREFIX[STYPE; |
561 | # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1]], | |
c0828abf | 562 | [m4_if(b4_tag_seen_flag, 0, |
4b3847c3 AD |
563 | [[typedef int ]b4_api_PREFIX[STYPE; |
564 | # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1]])])[ | |
565 | # define ]b4_api_prefix[stype ]b4_api_PREFIX[STYPE /* obsolescent; will be withdrawn */ | |
566 | # define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 | |
c0828abf AD |
567 | #endif]b4_locations_if([[ |
568 | ||
4b3847c3 AD |
569 | #if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED |
570 | typedef struct ]b4_api_PREFIX[LTYPE | |
c0828abf AD |
571 | { |
572 | int first_line; | |
573 | int first_column; | |
574 | int last_line; | |
575 | int last_column; | |
4b3847c3 AD |
576 | } ]b4_api_PREFIX[LTYPE; |
577 | # define ]b4_api_prefix[ltype ]b4_api_PREFIX[LTYPE /* obsolescent; will be withdrawn */ | |
578 | # define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1 | |
579 | # define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1 | |
c0828abf | 580 | #endif]]) |
756257ee | 581 | |
4b3847c3 AD |
582 | b4_pure_if([], [[extern ]b4_api_PREFIX[STYPE ]b4_prefix[lval; |
583 | ]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl | |
c0828abf | 584 | ]) |
56ca3d8f | 585 | |
5f108727 | 586 | # b4_YYDEBUG_define |
56ca3d8f | 587 | # ------------------ |
5f108727 | 588 | m4_define([b4_YYDEBUG_define], |
56ca3d8f | 589 | [[/* Enabling traces. */ |
5f108727 AD |
590 | ]m4_if(b4_api_prefix, [yy], |
591 | [[#ifndef YYDEBUG | |
56ca3d8f | 592 | # define YYDEBUG ]b4_debug_flag[ |
5f108727 AD |
593 | #endif]], |
594 | [[#ifndef ]b4_api_PREFIX[DEBUG | |
595 | # if defined YYDEBUG | |
596 | # if YYDEBUG | |
597 | # define ]b4_api_PREFIX[DEBUG 1 | |
598 | # else | |
599 | # define ]b4_api_PREFIX[DEBUG 0 | |
600 | # endif | |
601 | # else /* ! defined YYDEBUG */ | |
602 | # define ]b4_api_PREFIX[DEBUG ]b4_debug_flag[ | |
603 | # endif /* ! defined ]b4_api_PREFIX[DEBUG */ | |
604 | #endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl | |
605 | ]) | |
606 | ||
607 | # b4_declare_yydebug | |
608 | # ------------------ | |
609 | m4_define([b4_declare_yydebug], | |
610 | [b4_YYDEBUG_define[ | |
611 | #if ]b4_api_PREFIX[DEBUG | |
56ca3d8f AD |
612 | extern int ]b4_prefix[debug; |
613 | #endif][]dnl | |
614 | ]) | |
426903aa AD |
615 | |
616 | # b4_yylloc_default_define | |
617 | # ------------------------ | |
618 | # Define YYLLOC_DEFAULT. | |
619 | m4_define([b4_yylloc_default_define], | |
620 | [[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. | |
621 | If N is 0, then set CURRENT to the empty location which ends | |
622 | the previous symbol: RHS[0] (always defined). */ | |
623 | ||
624 | #ifndef YYLLOC_DEFAULT | |
625 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
626 | do \ | |
627 | if (YYID (N)) \ | |
628 | { \ | |
629 | (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ | |
630 | (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ | |
631 | (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ | |
632 | (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ | |
633 | } \ | |
634 | else \ | |
635 | { \ | |
636 | (Current).first_line = (Current).last_line = \ | |
637 | YYRHSLOC (Rhs, 0).last_line; \ | |
638 | (Current).first_column = (Current).last_column = \ | |
639 | YYRHSLOC (Rhs, 0).last_column; \ | |
640 | } \ | |
641 | while (YYID (0)) | |
642 | #endif | |
643 | ]]) |