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