]>
Commit | Line | Data |
---|---|---|
08af01c2 | 1 | -*- Autoconf -*- |
fb8135fa AD |
2 | |
3 | # C M4 Macros for Bison. | |
7d424de1 | 4 | |
fc51acdd | 5 | # Copyright (C) 2002, 2004-2014 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], | |
c9d5bcc9 | 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 | |
2a8d363a AD |
54 | # b4_identification |
55 | # ----------------- | |
d9df47b6 JD |
56 | # Depends on individual skeletons to define b4_pure_flag, b4_push_flag, or |
57 | # b4_pull_flag if they use the values of the %define variables api.pure or | |
67212941 | 58 | # api.push-pull. |
2a8d363a | 59 | m4_define([b4_identification], |
d9df47b6 JD |
60 | [[/* Identify Bison output. */ |
61 | #define YYBISON 1 | |
2a8d363a | 62 | |
55f64b82 | 63 | /* Bison version. */ |
d9df47b6 | 64 | #define YYBISON_VERSION "]b4_version[" |
55f64b82 | 65 | |
2a8d363a | 66 | /* Skeleton name. */ |
d9df47b6 | 67 | #define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[ |
2a8d363a AD |
68 | |
69 | /* Pure parsers. */ | |
d9df47b6 JD |
70 | #define YYPURE ]b4_pure_flag])[]m4_ifdef([b4_push_flag], [[ |
71 | ||
72 | /* Push parsers. */ | |
73 | #define YYPUSH ]b4_push_flag])[]m4_ifdef([b4_pull_flag], [[ | |
74 | ||
75 | /* Pull parsers. */ | |
76 | #define YYPULL ]b4_pull_flag])[ | |
d9df47b6 | 77 | ]]) |
2a8d363a AD |
78 | |
79 | ||
7ec2d4cd AD |
80 | ## ---------------- ## |
81 | ## Default values. ## | |
82 | ## ---------------- ## | |
83 | ||
4b3847c3 AD |
84 | # b4_api_prefix, b4_api_PREFIX |
85 | # ---------------------------- | |
86 | # Corresponds to %define api.prefix | |
87 | b4_percent_define_default([[api.prefix]], [[yy]]) | |
88 | m4_define([b4_api_prefix], | |
89 | [b4_percent_define_get([[api.prefix]])]) | |
90 | m4_define([b4_api_PREFIX], | |
91 | [m4_toupper(b4_api_prefix)]) | |
92 | ||
93 | ||
94 | # b4_prefix | |
95 | # --------- | |
96 | # If the %name-prefix is not given, it is api.prefix. | |
97 | m4_define_default([b4_prefix], [b4_api_prefix]) | |
98 | ||
1b818f33 | 99 | # If the %union is not named, its name is YYSTYPE. |
4b3847c3 | 100 | m4_define_default([b4_union_name], [b4_api_PREFIX[]STYPE]) |
7ec2d4cd | 101 | |
cd48d21d | 102 | |
2a8d363a AD |
103 | ## ------------------------ ## |
104 | ## Pure/impure interfaces. ## | |
105 | ## ------------------------ ## | |
106 | ||
64b3612a AD |
107 | # b4_lex_formals |
108 | # -------------- | |
109 | # All the yylex formal arguments. | |
110 | # b4_lex_param arrives quoted twice, but we want to keep only one level. | |
111 | m4_define([b4_lex_formals], | |
112 | [b4_pure_if([[[[YYSTYPE *yylvalp]], [[&yylval]]][]dnl | |
113 | b4_locations_if([, [[YYLTYPE *yyllocp], [&yylloc]]])])dnl | |
114 | m4_ifdef([b4_lex_param], [, ]b4_lex_param)]) | |
115 | ||
116 | ||
117 | # b4_lex | |
118 | # ------ | |
119 | # Call yylex. | |
120 | m4_define([b4_lex], | |
121 | [b4_function_call([yylex], [int], b4_lex_formals)]) | |
122 | ||
123 | ||
2a8d363a AD |
124 | # b4_user_args |
125 | # ------------ | |
126 | m4_define([b4_user_args], | |
15f66669 | 127 | [m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])]) |
2a8d363a AD |
128 | |
129 | ||
130 | # b4_parse_param | |
131 | # -------------- | |
132 | # If defined, b4_parse_param arrives double quoted, but below we prefer | |
133 | # it to be single quoted. | |
2a8d363a | 134 | m4_define([b4_parse_param], |
7ecec4dd | 135 | b4_parse_param) |
2a8d363a | 136 | |
8f7e3cf9 | 137 | |
613d8952 AD |
138 | # b4_parse_param_for(DECL, FORMAL, BODY) |
139 | # --------------------------------------- | |
140 | # Iterate over the user parameters, binding the declaration to DECL, | |
141 | # the formal name to FORMAL, and evaluating the BODY. | |
142 | m4_define([b4_parse_param_for], | |
143 | [m4_foreach([$1_$2], m4_defn([b4_parse_param]), | |
6bbb2ed5 | 144 | [m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl |
613d8952 AD |
145 | m4_pushdef([$2], m4_shift($1_$2))dnl |
146 | $3[]dnl | |
147 | m4_popdef([$2])dnl | |
148 | m4_popdef([$1])dnl | |
149 | ])]) | |
150 | ||
beadb220 AD |
151 | # b4_parse_param_use([VAL], [LOC]) |
152 | # -------------------------------- | |
45eebca4 | 153 | # 'YYUSE' VAL, LOC if locations are enabled, and all the parse-params. |
613d8952 | 154 | m4_define([b4_parse_param_use], |
1092d69c | 155 | [m4_ifvaln([$1], [ YYUSE ([$1]);])dnl |
1e5d6540 | 156 | b4_locations_if([m4_ifvaln([$2], [ YYUSE ([$2]);])])dnl |
beadb220 | 157 | b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal); |
613d8952 AD |
158 | ])dnl |
159 | ]) | |
2a8d363a | 160 | |
8e1687ae | 161 | |
fb8135fa AD |
162 | ## ------------ ## |
163 | ## Data Types. ## | |
164 | ## ------------ ## | |
165 | ||
a762e609 AD |
166 | # b4_int_type(MIN, MAX) |
167 | # --------------------- | |
168 | # Return the smallest int type able to handle numbers ranging from | |
169 | # MIN to MAX (included). | |
170 | m4_define([b4_int_type], | |
171 | [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], | |
f1886bb2 | 172 | b4_ints_in($@, [-128], [127]), [1], [signed char], |
a762e609 | 173 | |
779e7ceb PE |
174 | b4_ints_in($@, [0], [65535]), [1], [unsigned short int], |
175 | b4_ints_in($@, [-32768], [32767]), [1], [short int], | |
a762e609 AD |
176 | |
177 | m4_eval([0 <= $1]), [1], [unsigned int], | |
178 | ||
e9690142 | 179 | [int])]) |
a762e609 | 180 | |
f1886bb2 | 181 | |
a762e609 AD |
182 | # b4_int_type_for(NAME) |
183 | # --------------------- | |
184 | # Return the smallest int type able to handle numbers ranging from | |
45eebca4 | 185 | # 'NAME_min' to 'NAME_max' (included). |
a762e609 AD |
186 | m4_define([b4_int_type_for], |
187 | [b4_int_type($1_min, $1_max)]) | |
fb8135fa | 188 | |
cf98343c | 189 | |
87412882 JD |
190 | # b4_table_value_equals(TABLE, VALUE, LITERAL) |
191 | # -------------------------------------------- | |
192 | # Without inducing a comparison warning from the compiler, check if the | |
193 | # literal value LITERAL equals VALUE from table TABLE, which must have | |
56f8d560 | 194 | # TABLE_min and TABLE_max defined. |
87412882 JD |
195 | m4_define([b4_table_value_equals], |
196 | [m4_if(m4_eval($3 < m4_indir([b4_]$1[_min]) | |
197 | || m4_indir([b4_]$1[_max]) < $3), [1], | |
56f8d560 | 198 | [[0]], |
34076080 | 199 | [(!!(($2) == ($3)))])]) |
cf98343c | 200 | |
ef51bfa7 | 201 | |
80a2826e AD |
202 | ## ----------------- ## |
203 | ## Compiler issues. ## | |
204 | ## ----------------- ## | |
205 | ||
206 | # b4_attribute_define | |
207 | # ------------------- | |
3cc83855 | 208 | # Provide portable compiler "attributes". |
80a2826e | 209 | m4_define([b4_attribute_define], |
3cc83855 AD |
210 | [#ifndef YY_ATTRIBUTE |
211 | # if (defined __GNUC__ \ | |
212 | && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ | |
213 | || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C | |
214 | # define YY_ATTRIBUTE(Spec) __attribute__(Spec) | |
215 | # else | |
216 | # define YY_ATTRIBUTE(Spec) /* empty */ | |
217 | # endif | |
218 | #endif | |
219 | ||
220 | #ifndef YY_ATTRIBUTE_PURE | |
221 | # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) | |
222 | #endif | |
223 | ||
224 | #ifndef YY_ATTRIBUTE_UNUSED | |
225 | # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) | |
226 | #endif | |
227 | ||
228 | #if !defined _Noreturn \ | |
229 | && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) | |
230 | # if defined _MSC_VER && 1200 <= _MSC_VER | |
231 | # define _Noreturn __declspec (noreturn) | |
232 | # else | |
233 | # define _Noreturn YY_ATTRIBUTE ((__noreturn__)) | |
80a2826e AD |
234 | # endif |
235 | #endif | |
236 | ||
237 | /* Suppress unused-variable warnings by "using" E. */ | |
238 | #if ! defined lint || defined __GNUC__ | |
239 | # define YYUSE(E) ((void) (E)) | |
240 | #else | |
241 | # define YYUSE(E) /* empty */ | |
242 | #endif | |
d3ae5af6 AD |
243 | |
244 | #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ | |
245 | /* Suppress an incorrect diagnostic about yylval being uninitialized. */ | |
246 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ | |
247 | _Pragma ("GCC diagnostic push") \ | |
248 | _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ | |
249 | _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") | |
250 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ | |
251 | _Pragma ("GCC diagnostic pop") | |
252 | #else | |
253 | # define YY_INITIAL_VALUE(Value) Value | |
254 | #endif | |
255 | #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN | |
256 | # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN | |
257 | # define YY_IGNORE_MAYBE_UNINITIALIZED_END | |
258 | #endif | |
259 | #ifndef YY_INITIAL_VALUE | |
260 | # define YY_INITIAL_VALUE(Value) /* Nothing. */ | |
261 | #endif | |
80a2826e | 262 | ]) |
8e1687ae | 263 | |
8e1687ae | 264 | |
8e1687ae PE |
265 | ## ---------## |
266 | ## Values. ## | |
267 | ## ---------## | |
268 | ||
8e1687ae | 269 | |
ef51bfa7 AD |
270 | # b4_null_define |
271 | # -------------- | |
8d0b7cef | 272 | # Portability issues: define a YY_NULLPTR appropriate for the current |
ef51bfa7 AD |
273 | # language (C, C++98, or C++11). |
274 | m4_define([b4_null_define], | |
8d0b7cef | 275 | [# ifndef YY_NULLPTR |
ef51bfa7 | 276 | # if defined __cplusplus && 201103L <= __cplusplus |
8d0b7cef | 277 | # define YY_NULLPTR nullptr |
ef51bfa7 | 278 | # else |
8d0b7cef | 279 | # define YY_NULLPTR 0 |
ef51bfa7 AD |
280 | # endif |
281 | # endif[]dnl | |
282 | ]) | |
283 | ||
284 | ||
285 | # b4_null | |
286 | # ------- | |
287 | # Return a null pointer constant. | |
8d0b7cef | 288 | m4_define([b4_null], [YY_NULLPTR]) |
8e1687ae | 289 | |
ba206cf4 AD |
290 | # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) |
291 | # ------------------------------------------------------------- | |
e672a4ba | 292 | # Define "yy<TABLE-NAME>" whose contents is CONTENT. |
ba206cf4 | 293 | m4_define([b4_integral_parser_table_define], |
15f66669 | 294 | [m4_ifvaln([$3], [b4_comment([$3], [ ])])dnl |
0991e29b AD |
295 | static const b4_int_type_for([$2]) yy$1[[]] = |
296 | { | |
297 | $2 | |
298 | };dnl | |
299 | ]) | |
cf98343c AD |
300 | |
301 | ||
fb8135fa AD |
302 | ## ------------------------- ## |
303 | ## Assigning token numbers. ## | |
304 | ## ------------------------- ## | |
305 | ||
e3990e3c AD |
306 | # b4_token_define(TOKEN-NUM) |
307 | # -------------------------- | |
fb8135fa AD |
308 | # Output the definition of this token as #define. |
309 | m4_define([b4_token_define], | |
e3990e3c | 310 | [b4_token_format([#define %s %s], [$1])]) |
fb8135fa | 311 | |
e3990e3c AD |
312 | # b4_token_defines |
313 | # ---------------- | |
314 | # Output the definition of the tokens. | |
cf147260 | 315 | m4_define([b4_token_defines], |
e3990e3c AD |
316 | [b4_any_token_visible_if([/* Tokens. */ |
317 | m4_join([ | |
318 | ], b4_symbol_map([b4_token_define])) | |
319 | ])]) | |
cf147260 AD |
320 | |
321 | ||
e3990e3c AD |
322 | # b4_token_enum(TOKEN-NUM) |
323 | # ------------------------ | |
fb8135fa AD |
324 | # Output the definition of this token as an enum. |
325 | m4_define([b4_token_enum], | |
e3990e3c | 326 | [b4_token_format([%s = %s], [$1])]) |
fb8135fa AD |
327 | |
328 | ||
e3990e3c AD |
329 | # b4_token_enums |
330 | # -------------- | |
cf147260 AD |
331 | # Output the definition of the tokens (if there are) as enums. |
332 | m4_define([b4_token_enums], | |
4d9bdbe3 | 333 | [b4_any_token_visible_if([[/* Token type. */ |
4b3847c3 AD |
334 | #ifndef ]b4_api_PREFIX[TOKENTYPE |
335 | # define ]b4_api_PREFIX[TOKENTYPE | |
e3990e3c AD |
336 | enum ]b4_api_prefix[tokentype |
337 | { | |
338 | ]m4_join([, | |
339 | ], | |
340 | b4_symbol_map([b4_token_enum]))[ | |
341 | }; | |
095b9f05 | 342 | #endif |
4b3847c3 | 343 | ]])]) |
cf147260 AD |
344 | |
345 | ||
e3990e3c AD |
346 | # b4_token_enums_defines |
347 | # ---------------------- | |
348 | # Output the definition of the tokens (if there are any) as enums and, | |
349 | # if POSIX Yacc is enabled, as #defines. | |
cf147260 | 350 | m4_define([b4_token_enums_defines], |
e3990e3c | 351 | [b4_token_enums[]b4_yacc_if([b4_token_defines])]) |
4a2a22f4 AD |
352 | |
353 | ||
1fa5d8bb AD |
354 | ## ----------------- ## |
355 | ## Semantic Values. ## | |
356 | ## ----------------- ## | |
357 | ||
358 | ||
359 | # b4_symbol_value(VAL, [TYPE]) | |
360 | # ---------------------------- | |
361 | # Given a semantic value VAL ($$, $1 etc.), extract its value of type | |
362 | # TYPE if TYPE is given, otherwise just return VAL. The result can be | |
363 | # used safetly, it is put in parens to avoid nasty precedence issues. | |
364 | # TYPE is *not* put in braces, provide some if needed. | |
365 | m4_define([b4_symbol_value], | |
366 | [($1[]m4_ifval([$2], [.$2]))]) | |
367 | ||
368 | ||
ae7453f2 | 369 | |
71b56f46 AD |
370 | ## ---------------------- ## |
371 | ## Defining C functions. ## | |
372 | ## ---------------------- ## | |
4a2a22f4 AD |
373 | |
374 | ||
15f66669 AD |
375 | # b4_function_define(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
376 | # ----------------------------------------------------------- | |
71b56f46 | 377 | # Declare the function NAME in C. |
15f66669 | 378 | m4_define([b4_function_define], |
0245f82d | 379 | [$2 |
15f66669 | 380 | $1 (b4_formals(m4_shift2($@)))[]dnl |
0245f82d AD |
381 | ]) |
382 | ||
383 | ||
15f66669 AD |
384 | # b4_formals([DECL1, NAME1], ...) |
385 | # ------------------------------- | |
71b56f46 | 386 | # The formal arguments of a C function definition. |
15f66669 | 387 | m4_define([b4_formals], |
6bbb2ed5 EB |
388 | [m4_if([$#], [0], [void], |
389 | [$#$1], [1], [void], | |
15f66669 | 390 | [m4_map_sep([b4_formal], [, ], [$@])])]) |
4a2a22f4 | 391 | |
15f66669 | 392 | m4_define([b4_formal], |
0245f82d | 393 | [$1]) |
4a2a22f4 AD |
394 | |
395 | ||
4a2a22f4 | 396 | |
71b56f46 AD |
397 | ## ----------------------- ## |
398 | ## Declaring C functions. ## | |
399 | ## ----------------------- ## | |
21964f43 AD |
400 | |
401 | ||
15f66669 AD |
402 | # b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
403 | # ------------------------------------------------------------ | |
0245f82d | 404 | # Declare the function NAME. |
15f66669 AD |
405 | m4_define([b4_function_declare], |
406 | [$2 $1 (b4_formals(m4_shift2($@)));[]dnl | |
0245f82d AD |
407 | ]) |
408 | ||
409 | ||
410 | ||
411 | ||
412 | ## --------------------- ## | |
413 | ## Calling C functions. ## | |
414 | ## --------------------- ## | |
415 | ||
416 | ||
15f66669 | 417 | # b4_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
0245f82d AD |
418 | # ----------------------------------------------------------- |
419 | # Call the function NAME with arguments NAME1, NAME2 etc. | |
15f66669 AD |
420 | m4_define([b4_function_call], |
421 | [$1 (b4_args(m4_shift2($@)))[]dnl | |
0245f82d AD |
422 | ]) |
423 | ||
424 | ||
15f66669 AD |
425 | # b4_args([DECL1, NAME1], ...) |
426 | # ---------------------------- | |
0245f82d | 427 | # Output the arguments NAME1, NAME2... |
15f66669 AD |
428 | m4_define([b4_args], |
429 | [m4_map_sep([b4_arg], [, ], [$@])]) | |
0245f82d | 430 | |
15f66669 | 431 | m4_define([b4_arg], |
0245f82d | 432 | [$2]) |
437c2d80 AD |
433 | |
434 | ||
435 | ## ----------- ## | |
436 | ## Synclines. ## | |
437 | ## ----------- ## | |
438 | ||
90b9908d | 439 | # b4_sync_start(LINE, FILE) |
15f66669 | 440 | # ------------------------- |
90b9908d | 441 | m4_define([b4_sync_start], [[#]line $1 $2]) |
8ec0a172 | 442 | |
613d8952 AD |
443 | |
444 | ## -------------- ## | |
445 | ## User actions. ## | |
446 | ## -------------- ## | |
447 | ||
8e1687ae PE |
448 | # b4_case(LABEL, STATEMENTS) |
449 | # -------------------------- | |
450 | m4_define([b4_case], | |
451 | [ case $1: | |
452 | $2 | |
2141aded | 453 | b4_syncline([@oline@], [@ofile@]) |
8e1687ae PE |
454 | break;]) |
455 | ||
b0400cc6 | 456 | |
ca2a6d15 PH |
457 | # b4_predicate_case(LABEL, CONDITIONS) |
458 | # ------------------------------------ | |
459 | m4_define([b4_predicate_case], | |
460 | [ case $1: | |
461 | if (! ($2)) YYERROR; | |
462 | b4_syncline([@oline@], [@ofile@]) | |
463 | break;]) | |
464 | ||
465 | ||
e3f12e08 AD |
466 | # b4_yydestruct_define |
467 | # -------------------- | |
d00ff612 | 468 | # Define the "yydestruct" function. |
e3f12e08 | 469 | m4_define_default([b4_yydestruct_define], |
b0400cc6 AD |
470 | [[/*-----------------------------------------------. |
471 | | Release the memory associated to this symbol. | | |
472 | `-----------------------------------------------*/ | |
473 | ||
d00ff612 | 474 | ]b4_function_define([yydestruct], |
b0400cc6 | 475 | [static void], |
a0e68930 | 476 | [[const char *yymsg], [yymsg]], |
7bd6c77e | 477 | [[int yytype], [yytype]], |
4b367315 | 478 | [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl |
327afc7c | 479 | b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl |
4b367315 | 480 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
b0400cc6 | 481 | { |
1e5d6540 AD |
482 | ]b4_parse_param_use([yyvaluep], [yylocationp])dnl |
483 | [ if (!yymsg) | |
a0e68930 AD |
484 | yymsg = "Deleting"; |
485 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); | |
486 | ||
d3ae5af6 | 487 | YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN |
cc8962bd | 488 | ]b4_symbol_actions([destructor])[ |
d3ae5af6 | 489 | YY_IGNORE_MAYBE_UNINITIALIZED_END |
b0400cc6 AD |
490 | }]dnl |
491 | ]) | |
7bd6c77e AD |
492 | |
493 | ||
e3f12e08 AD |
494 | # b4_yy_symbol_print_define |
495 | # ------------------------- | |
d00ff612 | 496 | # Define the "yy_symbol_print" function. |
e3f12e08 | 497 | m4_define_default([b4_yy_symbol_print_define], |
a0af42fc | 498 | [[ |
d3ae5af6 AD |
499 | /*----------------------------------------. |
500 | | Print this symbol's value on YYOUTPUT. | | |
501 | `----------------------------------------*/ | |
7bd6c77e | 502 | |
d00ff612 | 503 | ]b4_function_define([yy_symbol_value_print], |
7bd6c77e | 504 | [static void], |
e9690142 JD |
505 | [[FILE *yyoutput], [yyoutput]], |
506 | [[int yytype], [yytype]], | |
507 | [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl | |
50cce58e | 508 | b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl |
4b367315 | 509 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
7bd6c77e | 510 | { |
c5026327 AD |
511 | FILE *yyo = yyoutput; |
512 | ]b4_parse_param_use([yyo], [yylocationp])dnl | |
1e5d6540 | 513 | [ if (!yyvaluep) |
fc257703 AD |
514 | return;] |
515 | dnl glr.c does not feature yytoknum. | |
516 | m4_if(b4_skeleton, ["yacc.c"], | |
517 | [[# ifdef YYPRINT | |
619404e3 AD |
518 | if (yytype < YYNTOKENS) |
519 | YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); | |
520 | # endif | |
fc257703 | 521 | ]])dnl |
cc8962bd | 522 | b4_symbol_actions([printer])[ |
a0af42fc AD |
523 | } |
524 | ||
525 | ||
526 | /*--------------------------------. | |
527 | | Print this symbol on YYOUTPUT. | | |
528 | `--------------------------------*/ | |
529 | ||
d00ff612 | 530 | ]b4_function_define([yy_symbol_print], |
a0af42fc | 531 | [static void], |
e9690142 JD |
532 | [[FILE *yyoutput], [yyoutput]], |
533 | [[int yytype], [yytype]], | |
534 | [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl | |
50cce58e | 535 | b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl |
a0af42fc AD |
536 | m4_ifset([b4_parse_param], [, b4_parse_param]))[ |
537 | { | |
d9fa1b7c AD |
538 | YYFPRINTF (yyoutput, "%s %s (", |
539 | yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); | |
a0af42fc | 540 | |
327afc7c | 541 | ]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp); |
a0af42fc AD |
542 | YYFPRINTF (yyoutput, ": "); |
543 | ])dnl | |
544 | [ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl | |
327afc7c | 545 | b4_locations_if([, yylocationp])[]b4_user_args[); |
2f4f028d | 546 | YYFPRINTF (yyoutput, ")"); |
4b367315 AD |
547 | }]dnl |
548 | ]) | |
c0828abf | 549 | |
6574576c AD |
550 | |
551 | ## ---------------- ## | |
552 | ## api.value.type. ## | |
553 | ## ---------------- ## | |
554 | ||
555 | ||
556 | # ---------------------- # | |
557 | # api.value.type=union. # | |
558 | # ---------------------- # | |
559 | ||
560 | # b4_symbol_type_register(SYMBOL-NUM) | |
561 | # ----------------------------------- | |
562 | # Symbol SYMBOL-NUM has a type (for variant) instead of a type-tag. | |
563 | # Extend the definition of %union's body with a field of that type, | |
564 | # and extend the symbol's "type" field to point to the field name, | |
565 | # instead of the type name. | |
566 | m4_define([b4_symbol_type_register], | |
567 | [m4_define([b4_symbol($1, type_tag)], | |
568 | [b4_symbol_if([$1], [has_id], | |
569 | [b4_symbol([$1], [id])], | |
570 | [yytype_[]b4_symbol([$1], [number])])])dnl | |
571 | m4_append([b4_user_union_members], | |
572 | m4_expand([ | |
573 | b4_symbol_tag_comment([$1])dnl | |
574 | b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);])) | |
575 | ]) | |
576 | ||
577 | ||
578 | # b4_type_define_tag(SYMBOL1-NUM, ...) | |
579 | # ------------------------------------ | |
580 | # For the batch of symbols SYMBOL1-NUM... (which all have the same | |
581 | # type), enhance the %union definition for each of them, and set | |
582 | # there "type" field to the field tag name, instead of the type name. | |
583 | m4_define([b4_type_define_tag], | |
584 | [b4_symbol_if([$1], [has_type], | |
585 | [m4_map([b4_symbol_type_register], [$@])]) | |
586 | ]) | |
587 | ||
588 | ||
589 | # b4_symbol_value_union(VAL, [TYPE]) | |
590 | # ---------------------------------- | |
591 | # Same of b4_symbol_value, but when api.value.type=union. | |
592 | m4_define([b4_symbol_value_union], | |
593 | [m4_ifval([$2], | |
594 | [(*($2*)(&$1))], | |
595 | [$1])]) | |
596 | ]) | |
597 | ||
598 | ||
599 | # b4_value_type_setup_union | |
600 | # ------------------------- | |
601 | # Setup support for api.value.type=union. Symbols are defined with a | |
602 | # type instead of a union member name: build the corresponding union, | |
603 | # and give the symbols their tag. | |
604 | m4_define([b4_value_type_setup_union], | |
605 | [m4_define([b4_union_members]) | |
606 | b4_type_foreach([b4_type_define_tag]) | |
607 | m4_copy_force([b4_symbol_value_union], [b4_symbol_value]) | |
608 | ]) | |
609 | ||
610 | ||
611 | # ---------------- # | |
612 | # api.value.type. # | |
613 | # ---------------- # | |
614 | ||
615 | ||
616 | # b4_value_type_setup_variant | |
617 | # --------------------------- | |
618 | # Setup support for api.value.type=variant. By default, fail, specialized | |
619 | # by other skeletons. | |
620 | m4_define([b4_value_type_setup_variant], | |
435575cb | 621 | [b4_complain_at(b4_percent_define_get_loc([[api.value.type]]), |
6574576c AD |
622 | [['%s' does not support '%s']], |
623 | [b4_skeleton], | |
624 | [%define api.value.type variant])]) | |
625 | ||
626 | ||
435575cb AD |
627 | # _b4_value_type_setup_keyword |
628 | # ---------------------------- | |
629 | # api.value.type is defined with a keyword/string syntax. Check if | |
630 | # that is properly defined, and prepare its use. | |
631 | m4_define([_b4_value_type_setup_keyword], | |
632 | [b4_percent_define_check_values([[[[api.value.type]], | |
633 | [[none]], | |
634 | [[union]], | |
635 | [[union-directive]], | |
636 | [[variant]], | |
637 | [[yystype]]]])dnl | |
638 | m4_case(b4_percent_define_get([[api.value.type]]), | |
639 | [union], [b4_value_type_setup_union], | |
640 | [variant], [b4_value_type_setup_variant])]) | |
641 | ||
642 | ||
6574576c AD |
643 | # b4_value_type_setup |
644 | # ------------------- | |
645 | # Check if api.value.type is properly defined, and possibly prepare | |
646 | # its use. | |
435575cb AD |
647 | b4_define_silent([b4_value_type_setup], |
648 | [# Define default value. | |
649 | b4_percent_define_ifdef([[api.value.type]], [], | |
650 | [# %union => api.value.type=union-directive | |
651 | m4_ifdef([b4_union_members], | |
652 | [m4_define([b4_percent_define_kind(api.value.type)], [keyword]) | |
653 | m4_define([b4_percent_define(api.value.type)], [union-directive])], | |
654 | [# no tag seen => api.value.type={int} | |
655 | m4_if(b4_tag_seen_flag, 0, | |
656 | [m4_define([b4_percent_define_kind(api.value.type)], [code]) | |
657 | m4_define([b4_percent_define(api.value.type)], [int])], | |
658 | [# otherwise api.value.type=yystype | |
659 | m4_define([b4_percent_define_kind(api.value.type)], [keyword]) | |
660 | m4_define([b4_percent_define(api.value.type)], [yystype])])])]) | |
661 | ||
662 | # Set up. | |
663 | m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), | |
664 | [keyword\|string], [_b4_value_type_setup_keyword]) | |
665 | ]) | |
6574576c AD |
666 | |
667 | ||
c0828abf AD |
668 | ## -------------- ## |
669 | ## Declarations. ## | |
670 | ## -------------- ## | |
671 | ||
6574576c | 672 | |
4d9bdbe3 AD |
673 | # b4_value_type_define |
674 | # -------------------- | |
675 | m4_define([b4_value_type_define], | |
6574576c AD |
676 | [b4_value_type_setup[]dnl |
677 | /* Value type. */ | |
435575cb AD |
678 | m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), |
679 | [code], | |
6574576c | 680 | [[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED |
435575cb | 681 | typedef ]b4_percent_define_get([[api.value.type]])[ ]b4_api_PREFIX[STYPE; |
6574576c | 682 | # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1 |
4b3847c3 | 683 | # define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 |
4d9bdbe3 | 684 | #endif |
6574576c | 685 | ]], |
435575cb AD |
686 | [m4_bmatch(b4_percent_define_get([[api.value.type]]), |
687 | [union\|union-directive], | |
6574576c | 688 | [[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED |
435575cb AD |
689 | typedef union ]b4_union_name[ ]b4_api_PREFIX[STYPE; |
690 | union ]b4_union_name[ | |
691 | { | |
692 | ]b4_user_union_members[ | |
693 | }; | |
6574576c AD |
694 | # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1 |
695 | # define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 | |
696 | #endif | |
435575cb | 697 | ]])])]) |
c0828abf | 698 | |
4d9bdbe3 AD |
699 | |
700 | # b4_location_type_define | |
701 | # ----------------------- | |
702 | m4_define([b4_location_type_define], | |
703 | [[/* Location type. */ | |
4b3847c3 | 704 | #if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED |
4d9bdbe3 AD |
705 | typedef struct ]b4_api_PREFIX[LTYPE ]b4_api_PREFIX[LTYPE; |
706 | struct ]b4_api_PREFIX[LTYPE | |
c0828abf AD |
707 | { |
708 | int first_line; | |
709 | int first_column; | |
710 | int last_line; | |
711 | int last_column; | |
4d9bdbe3 | 712 | }; |
4b3847c3 AD |
713 | # define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1 |
714 | # define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1 | |
4d9bdbe3 AD |
715 | #endif |
716 | ]]) | |
717 | ||
718 | ||
719 | # b4_declare_yylstype | |
720 | # ------------------- | |
721 | # Declarations that might either go into the header (if --defines) or | |
722 | # in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc. | |
723 | m4_define([b4_declare_yylstype], | |
724 | [b4_value_type_define[]b4_locations_if([ | |
725 | b4_location_type_define]) | |
756257ee | 726 | |
4b3847c3 AD |
727 | b4_pure_if([], [[extern ]b4_api_PREFIX[STYPE ]b4_prefix[lval; |
728 | ]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl | |
c0828abf | 729 | ]) |
56ca3d8f | 730 | |
4d9bdbe3 | 731 | |
5f108727 | 732 | # b4_YYDEBUG_define |
dde95ca4 | 733 | # ----------------- |
5f108727 | 734 | m4_define([b4_YYDEBUG_define], |
4d9bdbe3 | 735 | [[/* Debug traces. */ |
5f108727 AD |
736 | ]m4_if(b4_api_prefix, [yy], |
737 | [[#ifndef YYDEBUG | |
e436fa67 | 738 | # define YYDEBUG ]b4_parse_trace_if([1], [0])[ |
5f108727 AD |
739 | #endif]], |
740 | [[#ifndef ]b4_api_PREFIX[DEBUG | |
741 | # if defined YYDEBUG | |
56ca3d8f | 742 | #if YYDEBUG |
5f108727 AD |
743 | # define ]b4_api_PREFIX[DEBUG 1 |
744 | # else | |
745 | # define ]b4_api_PREFIX[DEBUG 0 | |
746 | # endif | |
747 | # else /* ! defined YYDEBUG */ | |
ccdc1577 | 748 | # define ]b4_api_PREFIX[DEBUG ]b4_parse_trace_if([1], [0])[ |
851e3f84 | 749 | # endif /* ! defined YYDEBUG */ |
5f108727 AD |
750 | #endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl |
751 | ]) | |
752 | ||
753 | # b4_declare_yydebug | |
754 | # ------------------ | |
755 | m4_define([b4_declare_yydebug], | |
756 | [b4_YYDEBUG_define[ | |
757 | #if ]b4_api_PREFIX[DEBUG | |
56ca3d8f AD |
758 | extern int ]b4_prefix[debug; |
759 | #endif][]dnl | |
760 | ]) | |
426903aa AD |
761 | |
762 | # b4_yylloc_default_define | |
763 | # ------------------------ | |
764 | # Define YYLLOC_DEFAULT. | |
765 | m4_define([b4_yylloc_default_define], | |
766 | [[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. | |
767 | If N is 0, then set CURRENT to the empty location which ends | |
768 | the previous symbol: RHS[0] (always defined). */ | |
769 | ||
770 | #ifndef YYLLOC_DEFAULT | |
771 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
772 | do \ | |
56f8d560 | 773 | if (N) \ |
426903aa AD |
774 | { \ |
775 | (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ | |
776 | (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ | |
777 | (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ | |
778 | (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ | |
779 | } \ | |
780 | else \ | |
781 | { \ | |
782 | (Current).first_line = (Current).last_line = \ | |
783 | YYRHSLOC (Rhs, 0).last_line; \ | |
784 | (Current).first_column = (Current).last_column = \ | |
785 | YYRHSLOC (Rhs, 0).last_column; \ | |
786 | } \ | |
56f8d560 | 787 | while (0) |
426903aa AD |
788 | #endif |
789 | ]]) | |
a68b1f23 | 790 | |
3237f570 AD |
791 | # b4_yy_location_print_define |
792 | # --------------------------- | |
793 | # Define YY_LOCATION_PRINT. | |
794 | m4_define([b4_yy_location_print_define], | |
795 | [b4_locations_if([[ | |
796 | /* YY_LOCATION_PRINT -- Print the location on the stream. | |
797 | This macro was not mandated originally: define only if we know | |
798 | we won't break user code: when these are the locations we know. */ | |
799 | ||
800 | #ifndef YY_LOCATION_PRINT | |
801 | # if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL | |
3804aa26 AD |
802 | |
803 | /* Print *YYLOCP on YYO. Private, do not rely on its existence. */ | |
804 | ||
3cc83855 | 805 | YY_ATTRIBUTE_UNUSED |
064e42b0 | 806 | ]b4_function_define([yy_location_print_], |
3804aa26 AD |
807 | [static unsigned], |
808 | [[FILE *yyo], [yyo]], | |
809 | [[YYLTYPE const * const yylocp], [yylocp]])[ | |
810 | { | |
811 | unsigned res = 0; | |
812 | int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; | |
813 | if (0 <= yylocp->first_line) | |
814 | { | |
f0f95a50 | 815 | res += YYFPRINTF (yyo, "%d", yylocp->first_line); |
3804aa26 | 816 | if (0 <= yylocp->first_column) |
f0f95a50 | 817 | res += YYFPRINTF (yyo, ".%d", yylocp->first_column); |
3804aa26 AD |
818 | } |
819 | if (0 <= yylocp->last_line) | |
820 | { | |
821 | if (yylocp->first_line < yylocp->last_line) | |
822 | { | |
f0f95a50 | 823 | res += YYFPRINTF (yyo, "-%d", yylocp->last_line); |
3804aa26 | 824 | if (0 <= end_col) |
f0f95a50 | 825 | res += YYFPRINTF (yyo, ".%d", end_col); |
3804aa26 AD |
826 | } |
827 | else if (0 <= end_col && yylocp->first_column < end_col) | |
f0f95a50 | 828 | res += YYFPRINTF (yyo, "-%d", end_col); |
3804aa26 AD |
829 | } |
830 | return res; | |
831 | } | |
832 | ||
f0f95a50 | 833 | # define YY_LOCATION_PRINT(File, Loc) \ |
3804aa26 AD |
834 | yy_location_print_ (File, &(Loc)) |
835 | ||
3237f570 AD |
836 | # else |
837 | # define YY_LOCATION_PRINT(File, Loc) ((void) 0) | |
838 | # endif | |
839 | #endif]], | |
840 | [[/* This macro is provided for backward compatibility. */ | |
841 | #ifndef YY_LOCATION_PRINT | |
842 | # define YY_LOCATION_PRINT(File, Loc) ((void) 0) | |
843 | #endif]]) | |
844 | ]) | |
845 | ||
a1d1ab50 AD |
846 | # b4_yyloc_default |
847 | # ---------------- | |
848 | # Expand to a possible default value for yylloc. | |
849 | m4_define([b4_yyloc_default], | |
850 | [[ | |
a68b1f23 AD |
851 | # if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL |
852 | = { ]m4_join([, ], | |
853 | m4_defn([b4_location_initial_line]), | |
854 | m4_defn([b4_location_initial_column]), | |
855 | m4_defn([b4_location_initial_line]), | |
856 | m4_defn([b4_location_initial_column]))[ } | |
857 | # endif | |
a1d1ab50 | 858 | ]]) |