]> git.saurik.com Git - bison.git/blob - data/c.m4
a1dc2c583a4f5f6b654c10928648a708c7d2aa49
[bison.git] / data / c.m4
1 -*- Autoconf -*-
2
3 # C M4 Macros for Bison.
4
5 # Copyright (C) 2002, 2004-2012 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_comment(TEXT)
55 # ----------------
56 m4_define([b4_comment], [/* m4_bpatsubst([$1], [
57 ], [
58 ]) */])
59
60 # b4_identification
61 # -----------------
62 # Depends on individual skeletons to define b4_pure_flag, b4_push_flag, or
63 # b4_pull_flag if they use the values of the %define variables api.pure or
64 # api.push-pull.
65 m4_define([b4_identification],
66 [[/* Identify Bison output. */
67 #define YYBISON 1
68
69 /* Bison version. */
70 #define YYBISON_VERSION "]b4_version["
71
72 /* Skeleton name. */
73 #define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[
74
75 /* Pure parsers. */
76 #define YYPURE ]b4_pure_flag])[]m4_ifdef([b4_push_flag], [[
77
78 /* Push parsers. */
79 #define YYPUSH ]b4_push_flag])[]m4_ifdef([b4_pull_flag], [[
80
81 /* Pull parsers. */
82 #define YYPULL ]b4_pull_flag])[
83 ]])
84
85
86 ## ---------------- ##
87 ## Default values. ##
88 ## ---------------- ##
89
90 # b4_api_prefix, b4_api_PREFIX
91 # ----------------------------
92 # Corresponds to %define api.prefix
93 b4_percent_define_default([[api.prefix]], [[yy]])
94 m4_define([b4_api_prefix],
95 [b4_percent_define_get([[api.prefix]])])
96 m4_define([b4_api_PREFIX],
97 [m4_toupper(b4_api_prefix)])
98
99
100 # b4_prefix
101 # ---------
102 # If the %name-prefix is not given, it is api.prefix.
103 m4_define_default([b4_prefix], [b4_api_prefix])
104
105 # If the %union is not named, its name is YYSTYPE.
106 m4_define_default([b4_union_name], [b4_api_PREFIX[]STYPE])
107
108
109 ## ------------------------ ##
110 ## Pure/impure interfaces. ##
111 ## ------------------------ ##
112
113 # b4_user_args
114 # ------------
115 m4_define([b4_user_args],
116 [m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])])
117
118
119 # b4_parse_param
120 # --------------
121 # If defined, b4_parse_param arrives double quoted, but below we prefer
122 # it to be single quoted.
123 m4_define([b4_parse_param],
124 b4_parse_param)
125
126
127 # b4_parse_param_for(DECL, FORMAL, BODY)
128 # ---------------------------------------
129 # Iterate over the user parameters, binding the declaration to DECL,
130 # the formal name to FORMAL, and evaluating the BODY.
131 m4_define([b4_parse_param_for],
132 [m4_foreach([$1_$2], m4_defn([b4_parse_param]),
133 [m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl
134 m4_pushdef([$2], m4_shift($1_$2))dnl
135 $3[]dnl
136 m4_popdef([$2])dnl
137 m4_popdef([$1])dnl
138 ])])
139
140 # b4_parse_param_use
141 # ------------------
142 # `YYUSE' all the parse-params.
143 m4_define([b4_parse_param_use],
144 [b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal);
145 ])dnl
146 ])
147
148
149 ## ------------ ##
150 ## Data Types. ##
151 ## ------------ ##
152
153 # b4_int_type(MIN, MAX)
154 # ---------------------
155 # Return the smallest int type able to handle numbers ranging from
156 # MIN to MAX (included).
157 m4_define([b4_int_type],
158 [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
159 b4_ints_in($@, [-128], [127]), [1], [signed char],
160
161 b4_ints_in($@, [0], [65535]), [1], [unsigned short int],
162 b4_ints_in($@, [-32768], [32767]), [1], [short int],
163
164 m4_eval([0 <= $1]), [1], [unsigned int],
165
166 [int])])
167
168
169 # b4_int_type_for(NAME)
170 # ---------------------
171 # Return the smallest int type able to handle numbers ranging from
172 # `NAME_min' to `NAME_max' (included).
173 m4_define([b4_int_type_for],
174 [b4_int_type($1_min, $1_max)])
175
176
177 # b4_table_value_equals(TABLE, VALUE, LITERAL)
178 # --------------------------------------------
179 # Without inducing a comparison warning from the compiler, check if the
180 # literal value LITERAL equals VALUE from table TABLE, which must have
181 # TABLE_min and TABLE_max defined. YYID must be defined as an identity
182 # function that suppresses warnings about constant conditions.
183 m4_define([b4_table_value_equals],
184 [m4_if(m4_eval($3 < m4_indir([b4_]$1[_min])
185 || m4_indir([b4_]$1[_max]) < $3), [1],
186 [[YYID (0)]],
187 [(!!(($2) == ($3)))])])
188
189
190 ## ----------------- ##
191 ## Compiler issues. ##
192 ## ----------------- ##
193
194 # b4_attribute_define
195 # -------------------
196 # Provide portability for __attribute__.
197 m4_define([b4_attribute_define],
198 [#ifndef __attribute__
199 /* This feature is available in gcc versions 2.5 and later. */
200 # if (! defined __GNUC__ || __GNUC__ < 2 \
201 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
202 # define __attribute__(Spec) /* empty */
203 # endif
204 #endif
205
206 /* Suppress unused-variable warnings by "using" E. */
207 #if ! defined lint || defined __GNUC__
208 # define YYUSE(E) ((void) (E))
209 #else
210 # define YYUSE(E) /* empty */
211 #endif
212 ])
213
214
215 # b4_null_define
216 # --------------
217 # Portability issues: define a YY_NULL appropriate for the current
218 # language (C, C++98, or C++11).
219 m4_define([b4_null_define],
220 [# ifndef YY_NULL
221 # if defined __cplusplus && 201103L <= __cplusplus
222 # define YY_NULL nullptr
223 # else
224 # define YY_NULL 0
225 # endif
226 # endif[]dnl
227 ])
228
229
230 # b4_null
231 # -------
232 # Return a null pointer constant.
233 m4_define([b4_null], [YY_NULL])
234
235
236
237 ## ------------------------- ##
238 ## Assigning token numbers. ##
239 ## ------------------------- ##
240
241 # b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
242 # -----------------------------------------
243 # Output the definition of this token as #define.
244 m4_define([b4_token_define],
245 [#define $1 $2
246 ])
247
248
249 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
250 # -------------------------------------------------------
251 # Output the definition of the tokens (if there are) as #defines.
252 m4_define([b4_token_defines],
253 [m4_if([$#$1], [1], [],
254 [/* Tokens. */
255 m4_map([b4_token_define], [$@])])
256 ])
257
258
259 # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
260 # ---------------------------------------
261 # Output the definition of this token as an enum.
262 m4_define([b4_token_enum],
263 [$1 = $2])
264
265
266 # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
267 # -----------------------------------------------------
268 # Output the definition of the tokens (if there are) as enums.
269 m4_define([b4_token_enums],
270 [m4_if([$#$1], [1], [],
271 [[/* Tokens. */
272 #ifndef ]b4_api_PREFIX[TOKENTYPE
273 # define ]b4_api_PREFIX[TOKENTYPE
274 /* Put the tokens into the symbol table, so that GDB and other debuggers
275 know about them. */
276 enum ]b4_api_prefix[tokentype {
277 ]m4_map_sep([ b4_token_enum], [,
278 ],
279 [$@])[
280 };
281 #endif
282 ]])])
283
284
285 # b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
286 # -------------------------------------------------------------
287 # Output the definition of the tokens (if there are any) as enums and, if POSIX
288 # Yacc is enabled, as #defines.
289 m4_define([b4_token_enums_defines],
290 [b4_token_enums($@)b4_yacc_if([b4_token_defines($@)], [])
291 ])
292
293
294
295 ## --------------------------------------------- ##
296 ## Defining C functions in both K&R and ANSI-C. ##
297 ## --------------------------------------------- ##
298
299
300 # b4_modern_c
301 # -----------
302 # A predicate useful in #if to determine whether C is ancient or modern.
303 #
304 # If __STDC__ is defined, the compiler is modern. IBM xlc 7.0 when run
305 # as 'cc' doesn't define __STDC__ (or __STDC_VERSION__) for pedantic
306 # reasons, but it defines __C99__FUNC__ so check that as well.
307 # Microsoft C normally doesn't define these macros, but it defines _MSC_VER.
308 # Consider a C++ compiler to be modern if it defines __cplusplus.
309 #
310 m4_define([b4_c_modern],
311 [[(defined __STDC__ || defined __C99__FUNC__ \
312 || defined __cplusplus || defined _MSC_VER)]])
313
314 # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
315 # ----------------------------------------------------------
316 # Declare the function NAME.
317 m4_define([b4_c_function_def],
318 [#if b4_c_modern
319 b4_c_ansi_function_def($@)
320 #else
321 $2
322 $1 (b4_c_knr_formal_names(m4_shift2($@)))
323 b4_c_knr_formal_decls(m4_shift2($@))
324 #endif[]dnl
325 ])
326
327
328 # b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
329 # ---------------------------------------------------------------
330 # Declare the function NAME in ANSI.
331 m4_define([b4_c_ansi_function_def],
332 [$2
333 $1 (b4_c_ansi_formals(m4_shift2($@)))[]dnl
334 ])
335
336
337 # b4_c_ansi_formals([DECL1, NAME1], ...)
338 # --------------------------------------
339 # Output the arguments ANSI-C definition.
340 m4_define([b4_c_ansi_formals],
341 [m4_if([$#], [0], [void],
342 [$#$1], [1], [void],
343 [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
344
345 m4_define([b4_c_ansi_formal],
346 [$1])
347
348
349 # b4_c_knr_formal_names([DECL1, NAME1], ...)
350 # ------------------------------------------
351 # Output the argument names.
352 m4_define([b4_c_knr_formal_names],
353 [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])])
354
355 m4_define([b4_c_knr_formal_name],
356 [$2])
357
358
359 # b4_c_knr_formal_decls([DECL1, NAME1], ...)
360 # ------------------------------------------
361 # Output the K&R argument declarations.
362 m4_define([b4_c_knr_formal_decls],
363 [m4_map_sep([b4_c_knr_formal_decl],
364 [
365 ],
366 [$@])])
367
368 m4_define([b4_c_knr_formal_decl],
369 [ $1;])
370
371
372
373 ## ------------------------------------------------------------ ##
374 ## Declaring (prototyping) C functions in both K&R and ANSI-C. ##
375 ## ------------------------------------------------------------ ##
376
377
378 # b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
379 # ----------------------------------------------------------------
380 # Declare the function NAME ANSI C style.
381 m4_define([b4_c_ansi_function_decl],
382 [$2 $1 (b4_c_ansi_formals(m4_shift2($@)));[]dnl
383 ])
384
385
386
387 # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
388 # -----------------------------------------------------------
389 # Declare the function NAME in both K&R and ANSI C.
390 m4_define([b4_c_function_decl],
391 [#if defined __STDC__ || defined __cplusplus
392 b4_c_ansi_function_decl($@)
393 #else
394 $2 $1 ();
395 #endif[]dnl
396 ])
397
398
399
400 ## --------------------- ##
401 ## Calling C functions. ##
402 ## --------------------- ##
403
404
405 # b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
406 # -----------------------------------------------------------
407 # Call the function NAME with arguments NAME1, NAME2 etc.
408 m4_define([b4_c_function_call],
409 [$1 (b4_c_args(m4_shift2($@)))[]dnl
410 ])
411
412
413 # b4_c_args([DECL1, NAME1], ...)
414 # ------------------------------
415 # Output the arguments NAME1, NAME2...
416 m4_define([b4_c_args],
417 [m4_map_sep([b4_c_arg], [, ], [$@])])
418
419 m4_define([b4_c_arg],
420 [$2])
421
422
423 ## ----------- ##
424 ## Synclines. ##
425 ## ----------- ##
426
427 # b4_sync_start(LINE, FILE)
428 # -------------------------
429 m4_define([b4_sync_start], [[#]line $1 $2])
430
431
432 ## -------------- ##
433 ## User actions. ##
434 ## -------------- ##
435
436 # b4_case(LABEL, STATEMENTS)
437 # --------------------------
438 m4_define([b4_case],
439 [ case $1:
440 $2
441 break;])
442
443 # b4_symbol_actions(FILENAME, LINENO,
444 # SYMBOL-TAG, SYMBOL-NUM,
445 # SYMBOL-ACTION, SYMBOL-TYPENAME)
446 # -------------------------------------------------
447 # Issue the code for a symbol action (e.g., %printer).
448 #
449 # Define b4_dollar_dollar([TYPE-NAME]), and b4_at_dollar, which are
450 # invoked where $<TYPE-NAME>$ and @$ were specified by the user.
451 m4_define([b4_symbol_actions],
452 [b4_dollar_pushdef([(*yyvaluep)], [$6], [(*yylocationp)])dnl
453 case $4: /* $3 */
454 b4_syncline([$2], [$1])
455 $5;
456 b4_syncline([@oline@], [@ofile@])
457 break;
458 b4_dollar_popdef[]dnl
459 ])
460
461
462 # b4_yydestruct_generate(FUNCTION-DECLARATOR)
463 # -------------------------------------------
464 # Generate the "yydestruct" function, which declaration is issued using
465 # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
466 # or "b4_c_function_def" for K&R.
467 m4_define_default([b4_yydestruct_generate],
468 [[/*-----------------------------------------------.
469 | Release the memory associated to this symbol. |
470 `-----------------------------------------------*/
471
472 /*ARGSUSED*/
473 ]$1([yydestruct],
474 [static void],
475 [[const char *yymsg], [yymsg]],
476 [[int yytype], [yytype]],
477 [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
478 b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
479 m4_ifset([b4_parse_param], [, b4_parse_param]))[
480 {
481 YYUSE (yyvaluep);
482 ]b4_locations_if([ YYUSE (yylocationp);
483 ])dnl
484 b4_parse_param_use[]dnl
485 [
486 if (!yymsg)
487 yymsg = "Deleting";
488 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
489
490 switch (yytype)
491 {
492 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
493 default:
494 break;
495 }
496 }]dnl
497 ])
498
499
500 # b4_yy_symbol_print_generate(FUNCTION-DECLARATOR)
501 # ------------------------------------------------
502 # Generate the "yy_symbol_print" function, which declaration is issued using
503 # FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
504 # or "b4_c_function_def" for K&R.
505 m4_define_default([b4_yy_symbol_print_generate],
506 [[
507 /*--------------------------------.
508 | Print this symbol on YYOUTPUT. |
509 `--------------------------------*/
510
511 /*ARGSUSED*/
512 ]$1([yy_symbol_value_print],
513 [static void],
514 [[FILE *yyoutput], [yyoutput]],
515 [[int yytype], [yytype]],
516 [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
517 b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
518 m4_ifset([b4_parse_param], [, b4_parse_param]))[
519 {
520 FILE *yyo = yyoutput;
521 YYUSE (yyo);
522 if (!yyvaluep)
523 return;
524 ]b4_locations_if([ YYUSE (yylocationp);
525 ])dnl
526 b4_parse_param_use[]dnl
527 [# ifdef YYPRINT
528 if (yytype < YYNTOKENS)
529 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
530 # else
531 YYUSE (yyoutput);
532 # endif
533 switch (yytype)
534 {
535 ]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
536 [ default:
537 break;
538 }
539 }
540
541
542 /*--------------------------------.
543 | Print this symbol on YYOUTPUT. |
544 `--------------------------------*/
545
546 ]$1([yy_symbol_print],
547 [static void],
548 [[FILE *yyoutput], [yyoutput]],
549 [[int yytype], [yytype]],
550 [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
551 b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
552 m4_ifset([b4_parse_param], [, b4_parse_param]))[
553 {
554 if (yytype < YYNTOKENS)
555 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
556 else
557 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
558
559 ]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp);
560 YYFPRINTF (yyoutput, ": ");
561 ])dnl
562 [ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl
563 b4_locations_if([, yylocationp])[]b4_user_args[);
564 YYFPRINTF (yyoutput, ")");
565 }]dnl
566 ])
567
568 ## -------------- ##
569 ## Declarations. ##
570 ## -------------- ##
571
572 # b4_declare_yylstype
573 # -------------------
574 # Declarations that might either go into the header (if --defines) or
575 # in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc.
576 m4_define([b4_declare_yylstype],
577 [[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED
578 ]m4_ifdef([b4_stype],
579 [[typedef union ]b4_union_name[
580 {
581 ]b4_user_stype[
582 } ]b4_api_PREFIX[STYPE;
583 # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1]],
584 [m4_if(b4_tag_seen_flag, 0,
585 [[typedef int ]b4_api_PREFIX[STYPE;
586 # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1]])])[
587 # define ]b4_api_prefix[stype ]b4_api_PREFIX[STYPE /* obsolescent; will be withdrawn */
588 # define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
589 #endif]b4_locations_if([[
590
591 #if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED
592 typedef struct ]b4_api_PREFIX[LTYPE
593 {
594 int first_line;
595 int first_column;
596 int last_line;
597 int last_column;
598 } ]b4_api_PREFIX[LTYPE;
599 # define ]b4_api_prefix[ltype ]b4_api_PREFIX[LTYPE /* obsolescent; will be withdrawn */
600 # define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1
601 # define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1
602 #endif]])
603
604 b4_pure_if([], [[extern ]b4_api_PREFIX[STYPE ]b4_prefix[lval;
605 ]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl
606 ])
607
608 # b4_YYDEBUG_define
609 # ------------------
610 m4_define([b4_YYDEBUG_define],
611 [[/* Enabling traces. */
612 ]m4_if(b4_api_prefix, [yy],
613 [[#ifndef YYDEBUG
614 # define YYDEBUG ]b4_debug_flag[
615 #endif]],
616 [[#ifndef ]b4_api_PREFIX[DEBUG
617 # if defined YYDEBUG
618 # if YYDEBUG
619 # define ]b4_api_PREFIX[DEBUG 1
620 # else
621 # define ]b4_api_PREFIX[DEBUG 0
622 # endif
623 # else /* ! defined YYDEBUG */
624 # define ]b4_api_PREFIX[DEBUG ]b4_debug_flag[
625 # endif /* ! defined YYDEBUG */
626 #endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl
627 ])
628
629 # b4_declare_yydebug
630 # ------------------
631 m4_define([b4_declare_yydebug],
632 [b4_YYDEBUG_define[
633 #if ]b4_api_PREFIX[DEBUG
634 extern int ]b4_prefix[debug;
635 #endif][]dnl
636 ])
637
638 # b4_yylloc_default_define
639 # ------------------------
640 # Define YYLLOC_DEFAULT.
641 m4_define([b4_yylloc_default_define],
642 [[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
643 If N is 0, then set CURRENT to the empty location which ends
644 the previous symbol: RHS[0] (always defined). */
645
646 #ifndef YYLLOC_DEFAULT
647 # define YYLLOC_DEFAULT(Current, Rhs, N) \
648 do \
649 if (YYID (N)) \
650 { \
651 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
652 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
653 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
654 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
655 } \
656 else \
657 { \
658 (Current).first_line = (Current).last_line = \
659 YYRHSLOC (Rhs, 0).last_line; \
660 (Current).first_column = (Current).last_column = \
661 YYRHSLOC (Rhs, 0).last_column; \
662 } \
663 while (YYID (0))
664 #endif
665 ]])
666
667 # b4_yy_location_print_define
668 # ---------------------------
669 # Define YY_LOCATION_PRINT.
670 m4_define([b4_yy_location_print_define],
671 [b4_locations_if([[
672 /* YY_LOCATION_PRINT -- Print the location on the stream.
673 This macro was not mandated originally: define only if we know
674 we won't break user code: when these are the locations we know. */
675
676 #ifndef YY_LOCATION_PRINT
677 # if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
678
679 /* Print *YYLOCP on YYO. Private, do not rely on its existence. */
680
681 __attribute__((__unused__))
682 ]b4_c_function_def([yy_location_print_],
683 [static unsigned],
684 [[FILE *yyo], [yyo]],
685 [[YYLTYPE const * const yylocp], [yylocp]])[
686 {
687 unsigned res = 0;
688 int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
689 if (0 <= yylocp->first_line)
690 {
691 res += fprintf (yyo, "%d", yylocp->first_line);
692 if (0 <= yylocp->first_column)
693 res += fprintf (yyo, ".%d", yylocp->first_column);
694 }
695 if (0 <= yylocp->last_line)
696 {
697 if (yylocp->first_line < yylocp->last_line)
698 {
699 res += fprintf (yyo, "-%d", yylocp->last_line);
700 if (0 <= end_col)
701 res += fprintf (yyo, ".%d", end_col);
702 }
703 else if (0 <= end_col && yylocp->first_column < end_col)
704 res += fprintf (yyo, "-%d", end_col);
705 }
706 return res;
707 }
708
709 # define YY_LOCATION_PRINT(File, Loc) \
710 yy_location_print_ (File, &(Loc))
711
712 # else
713 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
714 # endif
715 #endif]],
716 [[/* This macro is provided for backward compatibility. */
717 #ifndef YY_LOCATION_PRINT
718 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
719 #endif]])
720 ])
721
722 # b4_yyloc_default
723 # ----------------
724 # Expand to a possible default value for yylloc.
725 m4_define([b4_yyloc_default],
726 [[
727 # if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
728 = { ]m4_join([, ],
729 m4_defn([b4_location_initial_line]),
730 m4_defn([b4_location_initial_column]),
731 m4_defn([b4_location_initial_line]),
732 m4_defn([b4_location_initial_column]))[ }
733 # endif
734 ]])