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