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