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