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