]> git.saurik.com Git - bison.git/blob - data/c.m4
api.value.type: use keyword/brace values
[bison.git] / data / c.m4
1 -*- Autoconf -*-
2
3 # C M4 Macros for Bison.
4
5 # Copyright (C) 2002, 2004-2013 Free Software Foundation, Inc.
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
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.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 m4_include(b4_pkgdatadir/[c-like.m4])
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 [[YY_]b4_tocpp(m4_defn([b4_prefix])/[$1])[_INCLUDED]])
34
35
36 # b4_cpp_guard_open(FILE)
37 # b4_cpp_guard_close(FILE)
38 # ------------------------
39 # If FILE does not expand to nothing, open/close CPP inclusion guards for FILE.
40 m4_define([b4_cpp_guard_open],
41 [m4_ifval(m4_quote($1),
42 [#ifndef b4_cpp_guard([$1])
43 # define b4_cpp_guard([$1])])])
44
45 m4_define([b4_cpp_guard_close],
46 [m4_ifval(m4_quote($1),
47 [#endif b4_comment([!b4_cpp_guard([$1])])])])
48
49
50 ## ---------------- ##
51 ## Identification. ##
52 ## ---------------- ##
53
54 # b4_identification
55 # -----------------
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
58 # api.push-pull.
59 m4_define([b4_identification],
60 [[/* Identify Bison output. */
61 #define YYBISON 1
62
63 /* Bison version. */
64 #define YYBISON_VERSION "]b4_version["
65
66 /* Skeleton name. */
67 #define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[
68
69 /* Pure parsers. */
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])[
77 ]])
78
79
80 ## ---------------- ##
81 ## Default values. ##
82 ## ---------------- ##
83
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
99 # If the %union is not named, its name is YYSTYPE.
100 m4_define_default([b4_union_name], [b4_api_PREFIX[]STYPE])
101
102
103 ## ------------------------ ##
104 ## Pure/impure interfaces. ##
105 ## ------------------------ ##
106
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
124 # b4_user_args
125 # ------------
126 m4_define([b4_user_args],
127 [m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])])
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.
134 m4_define([b4_parse_param],
135 b4_parse_param)
136
137
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]),
144 [m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl
145 m4_pushdef([$2], m4_shift($1_$2))dnl
146 $3[]dnl
147 m4_popdef([$2])dnl
148 m4_popdef([$1])dnl
149 ])])
150
151 # b4_parse_param_use([VAL], [LOC])
152 # --------------------------------
153 # 'YYUSE' VAL, LOC if locations are enabled, and all the parse-params.
154 m4_define([b4_parse_param_use],
155 [m4_ifvaln([$1], [ YYUSE ([$1]);])dnl
156 b4_locations_if([m4_ifvaln([$2], [ YYUSE ([$2]);])])dnl
157 b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal);
158 ])dnl
159 ])
160
161
162 ## ------------ ##
163 ## Data Types. ##
164 ## ------------ ##
165
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],
172 b4_ints_in($@, [-128], [127]), [1], [signed char],
173
174 b4_ints_in($@, [0], [65535]), [1], [unsigned short int],
175 b4_ints_in($@, [-32768], [32767]), [1], [short int],
176
177 m4_eval([0 <= $1]), [1], [unsigned int],
178
179 [int])])
180
181
182 # b4_int_type_for(NAME)
183 # ---------------------
184 # Return the smallest int type able to handle numbers ranging from
185 # 'NAME_min' to 'NAME_max' (included).
186 m4_define([b4_int_type_for],
187 [b4_int_type($1_min, $1_max)])
188
189
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
194 # TABLE_min and TABLE_max defined.
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],
198 [[0]],
199 [(!!(($2) == ($3)))])])
200
201
202 ## ---------##
203 ## Values. ##
204 ## ---------##
205
206
207 # b4_null_define
208 # --------------
209 # Portability issues: define a YY_NULL appropriate for the current
210 # language (C, C++98, or C++11).
211 m4_define([b4_null_define],
212 [# ifndef YY_NULL
213 # if defined __cplusplus && 201103L <= __cplusplus
214 # define YY_NULL nullptr
215 # else
216 # define YY_NULL 0
217 # endif
218 # endif[]dnl
219 ])
220
221
222 # b4_null
223 # -------
224 # Return a null pointer constant.
225 m4_define([b4_null], [YY_NULL])
226
227 # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
228 # -------------------------------------------------------------
229 # Define "yy<TABLE-NAME>" whose contents is CONTENT.
230 m4_define([b4_integral_parser_table_define],
231 [m4_ifvaln([$3], [b4_comment([$3], [ ])])dnl
232 static const b4_int_type_for([$2]) yy$1[[]] =
233 {
234 $2
235 };dnl
236 ])
237
238
239 ## ------------------------- ##
240 ## Assigning token numbers. ##
241 ## ------------------------- ##
242
243 # b4_token_define(TOKEN-NUM)
244 # --------------------------
245 # Output the definition of this token as #define.
246 m4_define([b4_token_define],
247 [b4_token_format([#define %s %s], [$1])])
248
249 # b4_token_defines
250 # ----------------
251 # Output the definition of the tokens.
252 m4_define([b4_token_defines],
253 [b4_any_token_visible_if([/* Tokens. */
254 m4_join([
255 ], b4_symbol_map([b4_token_define]))
256 ])])
257
258
259 # b4_token_enum(TOKEN-NUM)
260 # ------------------------
261 # Output the definition of this token as an enum.
262 m4_define([b4_token_enum],
263 [b4_token_format([%s = %s], [$1])])
264
265
266 # b4_token_enums
267 # --------------
268 # Output the definition of the tokens (if there are) as enums.
269 m4_define([b4_token_enums],
270 [b4_any_token_visible_if([[/* Token type. */
271 #ifndef ]b4_api_PREFIX[TOKENTYPE
272 # define ]b4_api_PREFIX[TOKENTYPE
273 enum ]b4_api_prefix[tokentype
274 {
275 ]m4_join([,
276 ],
277 b4_symbol_map([b4_token_enum]))[
278 };
279 #endif
280 ]])])
281
282
283 # b4_token_enums_defines
284 # ----------------------
285 # Output the definition of the tokens (if there are any) as enums and,
286 # if POSIX Yacc is enabled, as #defines.
287 m4_define([b4_token_enums_defines],
288 [b4_token_enums[]b4_yacc_if([b4_token_defines])])
289
290
291 ## ----------------- ##
292 ## Semantic Values. ##
293 ## ----------------- ##
294
295
296 # b4_symbol_value(VAL, [TYPE])
297 # ----------------------------
298 # Given a semantic value VAL ($$, $1 etc.), extract its value of type
299 # TYPE if TYPE is given, otherwise just return VAL. The result can be
300 # used safetly, it is put in parens to avoid nasty precedence issues.
301 # TYPE is *not* put in braces, provide some if needed.
302 m4_define([b4_symbol_value],
303 [($1[]m4_ifval([$2], [.$2]))])
304
305
306
307 ## ---------------------- ##
308 ## Defining C functions. ##
309 ## ---------------------- ##
310
311
312 # b4_function_define(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
313 # -----------------------------------------------------------
314 # Declare the function NAME in C.
315 m4_define([b4_function_define],
316 [$2
317 $1 (b4_formals(m4_shift2($@)))[]dnl
318 ])
319
320
321 # b4_formals([DECL1, NAME1], ...)
322 # -------------------------------
323 # The formal arguments of a C function definition.
324 m4_define([b4_formals],
325 [m4_if([$#], [0], [void],
326 [$#$1], [1], [void],
327 [m4_map_sep([b4_formal], [, ], [$@])])])
328
329 m4_define([b4_formal],
330 [$1])
331
332
333
334 ## ----------------------- ##
335 ## Declaring C functions. ##
336 ## ----------------------- ##
337
338
339 # b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
340 # ------------------------------------------------------------
341 # Declare the function NAME.
342 m4_define([b4_function_declare],
343 [$2 $1 (b4_formals(m4_shift2($@)));[]dnl
344 ])
345
346
347
348
349 ## --------------------- ##
350 ## Calling C functions. ##
351 ## --------------------- ##
352
353
354 # b4_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
355 # -----------------------------------------------------------
356 # Call the function NAME with arguments NAME1, NAME2 etc.
357 m4_define([b4_function_call],
358 [$1 (b4_args(m4_shift2($@)))[]dnl
359 ])
360
361
362 # b4_args([DECL1, NAME1], ...)
363 # ----------------------------
364 # Output the arguments NAME1, NAME2...
365 m4_define([b4_args],
366 [m4_map_sep([b4_arg], [, ], [$@])])
367
368 m4_define([b4_arg],
369 [$2])
370
371
372 ## ----------- ##
373 ## Synclines. ##
374 ## ----------- ##
375
376 # b4_sync_start(LINE, FILE)
377 # -------------------------
378 m4_define([b4_sync_start], [[#]line $1 $2])
379
380
381 ## -------------- ##
382 ## User actions. ##
383 ## -------------- ##
384
385 # b4_case(LABEL, STATEMENTS)
386 # --------------------------
387 m4_define([b4_case],
388 [ case $1:
389 $2
390 b4_syncline([@oline@], [@ofile@])
391 break;])
392
393
394 # b4_predicate_case(LABEL, CONDITIONS)
395 # ------------------------------------
396 m4_define([b4_predicate_case],
397 [ case $1:
398 if (! ($2)) YYERROR;
399 b4_syncline([@oline@], [@ofile@])
400 break;])
401
402
403 # b4_yydestruct_define
404 # --------------------
405 # Define the "yydestruct" function.
406 m4_define_default([b4_yydestruct_define],
407 [[/*-----------------------------------------------.
408 | Release the memory associated to this symbol. |
409 `-----------------------------------------------*/
410
411 ]b4_function_define([yydestruct],
412 [static void],
413 [[const char *yymsg], [yymsg]],
414 [[int yytype], [yytype]],
415 [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
416 b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
417 m4_ifset([b4_parse_param], [, b4_parse_param]))[
418 {
419 ]b4_parse_param_use([yyvaluep], [yylocationp])dnl
420 [ if (!yymsg)
421 yymsg = "Deleting";
422 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
423
424 switch (yytype)
425 {
426 ]b4_symbol_foreach([b4_symbol_destructor])dnl
427 [ default:
428 break;
429 }
430 }]dnl
431 ])
432
433
434 # b4_yy_symbol_print_define
435 # -------------------------
436 # Define the "yy_symbol_print" function.
437 m4_define_default([b4_yy_symbol_print_define],
438 [[
439 /*--------------------------------.
440 | Print this symbol on YYOUTPUT. |
441 `--------------------------------*/
442
443 ]b4_function_define([yy_symbol_value_print],
444 [static void],
445 [[FILE *yyoutput], [yyoutput]],
446 [[int yytype], [yytype]],
447 [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
448 b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
449 m4_ifset([b4_parse_param], [, b4_parse_param]))[
450 {
451 FILE *yyo = yyoutput;
452 ]b4_parse_param_use([yyo], [yylocationp])dnl
453 [ if (!yyvaluep)
454 return;]
455 dnl glr.c does not feature yytoknum.
456 m4_if(b4_skeleton, ["yacc.c"],
457 [[# ifdef YYPRINT
458 if (yytype < YYNTOKENS)
459 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
460 # endif
461 ]])dnl
462 [ switch (yytype)
463 {
464 ]b4_symbol_foreach([b4_symbol_printer])dnl
465 [ default:
466 break;
467 }
468 }
469
470
471 /*--------------------------------.
472 | Print this symbol on YYOUTPUT. |
473 `--------------------------------*/
474
475 ]b4_function_define([yy_symbol_print],
476 [static void],
477 [[FILE *yyoutput], [yyoutput]],
478 [[int yytype], [yytype]],
479 [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
480 b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
481 m4_ifset([b4_parse_param], [, b4_parse_param]))[
482 {
483 YYFPRINTF (yyoutput, "%s %s (",
484 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
485
486 ]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp);
487 YYFPRINTF (yyoutput, ": ");
488 ])dnl
489 [ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl
490 b4_locations_if([, yylocationp])[]b4_user_args[);
491 YYFPRINTF (yyoutput, ")");
492 }]dnl
493 ])
494
495
496 ## ---------------- ##
497 ## api.value.type. ##
498 ## ---------------- ##
499
500
501 # ---------------------- #
502 # api.value.type=union. #
503 # ---------------------- #
504
505 # b4_symbol_type_register(SYMBOL-NUM)
506 # -----------------------------------
507 # Symbol SYMBOL-NUM has a type (for variant) instead of a type-tag.
508 # Extend the definition of %union's body with a field of that type,
509 # and extend the symbol's "type" field to point to the field name,
510 # instead of the type name.
511 m4_define([b4_symbol_type_register],
512 [m4_define([b4_symbol($1, type_tag)],
513 [b4_symbol_if([$1], [has_id],
514 [b4_symbol([$1], [id])],
515 [yytype_[]b4_symbol([$1], [number])])])dnl
516 m4_append([b4_user_union_members],
517 m4_expand([
518 b4_symbol_tag_comment([$1])dnl
519 b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]))
520 ])
521
522
523 # b4_type_define_tag(SYMBOL1-NUM, ...)
524 # ------------------------------------
525 # For the batch of symbols SYMBOL1-NUM... (which all have the same
526 # type), enhance the %union definition for each of them, and set
527 # there "type" field to the field tag name, instead of the type name.
528 m4_define([b4_type_define_tag],
529 [b4_symbol_if([$1], [has_type],
530 [m4_map([b4_symbol_type_register], [$@])])
531 ])
532
533
534 # b4_symbol_value_union(VAL, [TYPE])
535 # ----------------------------------
536 # Same of b4_symbol_value, but when api.value.type=union.
537 m4_define([b4_symbol_value_union],
538 [m4_ifval([$2],
539 [(*($2*)(&$1))],
540 [$1])])
541 ])
542
543
544 # b4_value_type_setup_union
545 # -------------------------
546 # Setup support for api.value.type=union. Symbols are defined with a
547 # type instead of a union member name: build the corresponding union,
548 # and give the symbols their tag.
549 m4_define([b4_value_type_setup_union],
550 [m4_define([b4_union_members])
551 b4_type_foreach([b4_type_define_tag])
552 m4_copy_force([b4_symbol_value_union], [b4_symbol_value])
553 ])
554
555
556 # ---------------- #
557 # api.value.type. #
558 # ---------------- #
559
560
561 # b4_value_type_setup_variant
562 # ---------------------------
563 # Setup support for api.value.type=variant. By default, fail, specialized
564 # by other skeletons.
565 m4_define([b4_value_type_setup_variant],
566 [b4_complain_at(b4_percent_define_get_loc([[api.value.type]]),
567 [['%s' does not support '%s']],
568 [b4_skeleton],
569 [%define api.value.type variant])])
570
571
572 # _b4_value_type_setup_keyword
573 # ----------------------------
574 # api.value.type is defined with a keyword/string syntax. Check if
575 # that is properly defined, and prepare its use.
576 m4_define([_b4_value_type_setup_keyword],
577 [b4_percent_define_check_values([[[[api.value.type]],
578 [[none]],
579 [[union]],
580 [[union-directive]],
581 [[variant]],
582 [[yystype]]]])dnl
583 m4_case(b4_percent_define_get([[api.value.type]]),
584 [union], [b4_value_type_setup_union],
585 [variant], [b4_value_type_setup_variant])])
586
587
588 # b4_value_type_setup
589 # -------------------
590 # Check if api.value.type is properly defined, and possibly prepare
591 # its use.
592 b4_define_silent([b4_value_type_setup],
593 [# Define default value.
594 b4_percent_define_ifdef([[api.value.type]], [],
595 [# %union => api.value.type=union-directive
596 m4_ifdef([b4_union_members],
597 [m4_define([b4_percent_define_kind(api.value.type)], [keyword])
598 m4_define([b4_percent_define(api.value.type)], [union-directive])],
599 [# no tag seen => api.value.type={int}
600 m4_if(b4_tag_seen_flag, 0,
601 [m4_define([b4_percent_define_kind(api.value.type)], [code])
602 m4_define([b4_percent_define(api.value.type)], [int])],
603 [# otherwise api.value.type=yystype
604 m4_define([b4_percent_define_kind(api.value.type)], [keyword])
605 m4_define([b4_percent_define(api.value.type)], [yystype])])])])
606
607 # Set up.
608 m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
609 [keyword\|string], [_b4_value_type_setup_keyword])
610 ])
611
612
613 ## -------------- ##
614 ## Declarations. ##
615 ## -------------- ##
616
617
618 # b4_value_type_define
619 # --------------------
620 m4_define([b4_value_type_define],
621 [b4_value_type_setup[]dnl
622 /* Value type. */
623 m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
624 [code],
625 [[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED
626 typedef ]b4_percent_define_get([[api.value.type]])[ ]b4_api_PREFIX[STYPE;
627 # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1
628 # define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
629 #endif
630 ]],
631 [m4_bmatch(b4_percent_define_get([[api.value.type]]),
632 [union\|union-directive],
633 [[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED
634 typedef union ]b4_union_name[ ]b4_api_PREFIX[STYPE;
635 union ]b4_union_name[
636 {
637 ]b4_user_union_members[
638 };
639 # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1
640 # define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
641 #endif
642 ]])])])
643
644
645 # b4_location_type_define
646 # -----------------------
647 m4_define([b4_location_type_define],
648 [[/* Location type. */
649 #if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED
650 typedef struct ]b4_api_PREFIX[LTYPE ]b4_api_PREFIX[LTYPE;
651 struct ]b4_api_PREFIX[LTYPE
652 {
653 int first_line;
654 int first_column;
655 int last_line;
656 int last_column;
657 };
658 # define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1
659 # define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1
660 #endif
661 ]])
662
663
664 # b4_declare_yylstype
665 # -------------------
666 # Declarations that might either go into the header (if --defines) or
667 # in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc.
668 m4_define([b4_declare_yylstype],
669 [b4_value_type_define[]b4_locations_if([
670 b4_location_type_define])
671
672 b4_pure_if([], [[extern ]b4_api_PREFIX[STYPE ]b4_prefix[lval;
673 ]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl
674 ])
675
676
677 # b4_YYDEBUG_define
678 # -----------------
679 m4_define([b4_YYDEBUG_define],
680 [[/* Debug traces. */
681 ]m4_if(b4_api_prefix, [yy],
682 [[#ifndef YYDEBUG
683 # define YYDEBUG ]b4_parse_trace_if([1], [0])[
684 #endif]],
685 [[#ifndef ]b4_api_PREFIX[DEBUG
686 # if defined YYDEBUG
687 #if YYDEBUG
688 # define ]b4_api_PREFIX[DEBUG 1
689 # else
690 # define ]b4_api_PREFIX[DEBUG 0
691 # endif
692 # else /* ! defined YYDEBUG */
693 # define ]b4_api_PREFIX[DEBUG ]b4_parse_trace_if([1], [0])[
694 # endif /* ! defined YYDEBUG */
695 #endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl
696 ])
697
698 # b4_declare_yydebug
699 # ------------------
700 m4_define([b4_declare_yydebug],
701 [b4_YYDEBUG_define[
702 #if ]b4_api_PREFIX[DEBUG
703 extern int ]b4_prefix[debug;
704 #endif][]dnl
705 ])
706
707 # b4_yylloc_default_define
708 # ------------------------
709 # Define YYLLOC_DEFAULT.
710 m4_define([b4_yylloc_default_define],
711 [[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
712 If N is 0, then set CURRENT to the empty location which ends
713 the previous symbol: RHS[0] (always defined). */
714
715 #ifndef YYLLOC_DEFAULT
716 # define YYLLOC_DEFAULT(Current, Rhs, N) \
717 do \
718 if (N) \
719 { \
720 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
721 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
722 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
723 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
724 } \
725 else \
726 { \
727 (Current).first_line = (Current).last_line = \
728 YYRHSLOC (Rhs, 0).last_line; \
729 (Current).first_column = (Current).last_column = \
730 YYRHSLOC (Rhs, 0).last_column; \
731 } \
732 while (0)
733 #endif
734 ]])
735
736 # b4_yy_location_print_define
737 # ---------------------------
738 # Define YY_LOCATION_PRINT.
739 m4_define([b4_yy_location_print_define],
740 [b4_locations_if([[
741 /* YY_LOCATION_PRINT -- Print the location on the stream.
742 This macro was not mandated originally: define only if we know
743 we won't break user code: when these are the locations we know. */
744
745 #ifndef YY_LOCATION_PRINT
746 # if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
747
748 /* Print *YYLOCP on YYO. Private, do not rely on its existence. */
749
750 __attribute__((__unused__))
751 ]b4_function_define([yy_location_print_],
752 [static unsigned],
753 [[FILE *yyo], [yyo]],
754 [[YYLTYPE const * const yylocp], [yylocp]])[
755 {
756 unsigned res = 0;
757 int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
758 if (0 <= yylocp->first_line)
759 {
760 res += YYFPRINTF (yyo, "%d", yylocp->first_line);
761 if (0 <= yylocp->first_column)
762 res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
763 }
764 if (0 <= yylocp->last_line)
765 {
766 if (yylocp->first_line < yylocp->last_line)
767 {
768 res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
769 if (0 <= end_col)
770 res += YYFPRINTF (yyo, ".%d", end_col);
771 }
772 else if (0 <= end_col && yylocp->first_column < end_col)
773 res += YYFPRINTF (yyo, "-%d", end_col);
774 }
775 return res;
776 }
777
778 # define YY_LOCATION_PRINT(File, Loc) \
779 yy_location_print_ (File, &(Loc))
780
781 # else
782 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
783 # endif
784 #endif]],
785 [[/* This macro is provided for backward compatibility. */
786 #ifndef YY_LOCATION_PRINT
787 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
788 #endif]])
789 ])
790
791 # b4_yyloc_default
792 # ----------------
793 # Expand to a possible default value for yylloc.
794 m4_define([b4_yyloc_default],
795 [[
796 # if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
797 = { ]m4_join([, ],
798 m4_defn([b4_location_initial_line]),
799 m4_defn([b4_location_initial_column]),
800 m4_defn([b4_location_initial_line]),
801 m4_defn([b4_location_initial_column]))[ }
802 # endif
803 ]])