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