1 -*- Autoconf -*- 2 3# C M4 Macros for Bison. 4 5# Copyright (C) 2002, 2004-2015, 2018-2019 Free Software Foundation, 6# Inc. 7 8# This program is free software: you can redistribute it and/or modify 9# it under the terms of the GNU General Public License as published by 10# the Free Software Foundation, either version 3 of the License, or 11# (at your option) any later version. 12# 13# This program is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16# GNU General Public License for more details. 17# 18# You should have received a copy of the GNU General Public License 19# along with this program. If not, see <http://www.gnu.org/licenses/>. 20 21m4_include(b4_skeletonsdir/[c-like.m4]) 22 23# b4_tocpp(STRING) 24# ---------------- 25# Convert STRING into a valid C macro name. 26m4_define([b4_tocpp], 27[m4_toupper(m4_bpatsubst(m4_quote($1), [[^a-zA-Z0-9]+], [_]))]) 28 29 30# b4_cpp_guard(FILE) 31# ------------------ 32# A valid C macro name to use as a CPP header guard for FILE. 33m4_define([b4_cpp_guard], 34[[YY_]b4_tocpp(m4_defn([b4_prefix])/[$1])[_INCLUDED]]) 35 36 37# b4_cpp_guard_open(FILE) 38# b4_cpp_guard_close(FILE) 39# ------------------------ 40# If FILE does not expand to nothing, open/close CPP inclusion guards for FILE. 41m4_define([b4_cpp_guard_open], 42[m4_ifval(m4_quote($1), 43[#ifndef b4_cpp_guard([$1]) 44# define b4_cpp_guard([$1])])]) 45 46m4_define([b4_cpp_guard_close], 47[m4_ifval(m4_quote($1), 48[#endif b4_comment([!b4_cpp_guard([$1])])])]) 49 50 51## ---------------- ## 52## Identification. ## 53## ---------------- ## 54 55# b4_identification 56# ----------------- 57# Depends on individual skeletons to define b4_pure_flag, b4_push_flag, or 58# b4_pull_flag if they use the values of the %define variables api.pure or 59# api.push-pull. 60m4_define([b4_identification], 61[[/* Identify Bison output. */ 62#define YYBISON 1 63 64/* Bison version. */ 65#define YYBISON_VERSION "]b4_version[" 66 67/* Skeleton name. */ 68#define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[ 69 70/* Pure parsers. */ 71#define YYPURE ]b4_pure_flag])[]m4_ifdef([b4_push_flag], [[ 72 73/* Push parsers. */ 74#define YYPUSH ]b4_push_flag])[]m4_ifdef([b4_pull_flag], [[ 75 76/* Pull parsers. */ 77#define YYPULL ]b4_pull_flag])[ 78]]) 79 80 81## ---------------- ## 82## Default values. ## 83## ---------------- ## 84 85# b4_api_prefix, b4_api_PREFIX 86# ---------------------------- 87# Corresponds to %define api.prefix 88b4_percent_define_default([[api.prefix]], [[yy]]) 89m4_define([b4_api_prefix], 90[b4_percent_define_get([[api.prefix]])]) 91m4_define([b4_api_PREFIX], 92[m4_toupper(b4_api_prefix)]) 93 94 95# b4_prefix 96# --------- 97# If the %name-prefix is not given, it is api.prefix. 98m4_define_default([b4_prefix], [b4_api_prefix]) 99 100# If the %union is not named, its name is YYSTYPE. 101b4_percent_define_default([[api.value.union.name]], 102 [b4_api_PREFIX[][STYPE]]) 103 104 105## ------------------------ ## 106## Pure/impure interfaces. ## 107## ------------------------ ## 108 109# b4_lex_formals 110# -------------- 111# All the yylex formal arguments. 112# b4_lex_param arrives quoted twice, but we want to keep only one level. 113m4_define([b4_lex_formals], 114[b4_pure_if([[[[YYSTYPE *yylvalp]], [[&yylval]]][]dnl 115b4_locations_if([, [[YYLTYPE *yyllocp], [&yylloc]]])])dnl 116m4_ifdef([b4_lex_param], [, ]b4_lex_param)]) 117 118 119# b4_lex 120# ------ 121# Call yylex. 122m4_define([b4_lex], 123[b4_function_call([yylex], [int], b4_lex_formals)]) 124 125 126# b4_user_args 127# ------------ 128m4_define([b4_user_args], 129[m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])]) 130 131 132# b4_parse_param 133# -------------- 134# If defined, b4_parse_param arrives double quoted, but below we prefer 135# it to be single quoted. 136m4_define([b4_parse_param], 137b4_parse_param) 138 139 140# b4_parse_param_for(DECL, FORMAL, BODY) 141# --------------------------------------- 142# Iterate over the user parameters, binding the declaration to DECL, 143# the formal name to FORMAL, and evaluating the BODY. 144m4_define([b4_parse_param_for], 145[m4_foreach([$1_$2], m4_defn([b4_parse_param]), 146[m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl 147m4_pushdef([$2], m4_shift($1_$2))dnl 148$3[]dnl 149m4_popdef([$2])dnl 150m4_popdef([$1])dnl 151])]) 152 153# b4_parse_param_use([VAL], [LOC]) 154# -------------------------------- 155# 'YYUSE' VAL, LOC if locations are enabled, and all the parse-params. 156m4_define([b4_parse_param_use], 157[m4_ifvaln([$1], [ YYUSE ([$1]);])dnl 158b4_locations_if([m4_ifvaln([$2], [ YYUSE ([$2]);])])dnl 159b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal); 160])dnl 161]) 162 163 164## ------------ ## 165## Data Types. ## 166## ------------ ## 167 168# b4_int_type(MIN, MAX) 169# --------------------- 170# Return the smallest int type able to handle numbers ranging from 171# MIN to MAX (included). 172m4_define([b4_int_type], 173[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], 174 b4_ints_in($@, [-128], [127]), [1], [signed char], 175 176 b4_ints_in($@, [0], [65535]), [1], [unsigned short], 177 b4_ints_in($@, [-32768], [32767]), [1], [short], 178 179 m4_eval([0 <= $1]), [1], [unsigned], 180 181 [int])]) 182 183 184# b4_int_type_for(NAME) 185# --------------------- 186# Return the smallest int type able to handle numbers ranging from 187# 'NAME_min' to 'NAME_max' (included). 188m4_define([b4_int_type_for], 189[b4_int_type($1_min, $1_max)]) 190 191 192# b4_table_value_equals(TABLE, VALUE, LITERAL) 193# -------------------------------------------- 194# Without inducing a comparison warning from the compiler, check if the 195# literal value LITERAL equals VALUE from table TABLE, which must have 196# TABLE_min and TABLE_max defined. 197m4_define([b4_table_value_equals], 198[m4_if(m4_eval($3 < m4_indir([b4_]$1[_min]) 199 || m4_indir([b4_]$1[_max]) < $3), [1], 200 [[0]], 201 [(!!(($2) == ($3)))])]) 202 203 204## ----------------- ## 205## Compiler issues. ## 206## ----------------- ## 207 208# b4_attribute_define([noreturn]) 209# ------------------------------- 210# Provide portable compiler "attributes". If "noreturn" is passed, define 211# _Noreturn. 212m4_define([b4_attribute_define], 213[[#ifndef YY_ATTRIBUTE 214# if (defined __GNUC__ \ 215 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ 216 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C 217# define YY_ATTRIBUTE(Spec) __attribute__(Spec) 218# else 219# define YY_ATTRIBUTE(Spec) /* empty */ 220# endif 221#endif 222 223#ifndef YY_ATTRIBUTE_PURE 224# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) 225#endif 226 227#ifndef YY_ATTRIBUTE_UNUSED 228# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) 229#endif 230 231]m4_bmatch([$1], [\bnoreturn\b], [[/* The _Noreturn keyword of C11. */ 232#if ! defined _Noreturn 233# if defined __cplusplus && 201103L <= __cplusplus 234# define _Noreturn [[noreturn]] 235# elif !(defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__) 236# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \ 237 || 0x5110 <= __SUNPRO_C) 238# define _Noreturn __attribute__ ((__noreturn__)) 239# elif defined _MSC_VER && 1200 <= _MSC_VER 240# define _Noreturn __declspec (noreturn) 241# else 242# define _Noreturn 243# endif 244# endif 245#endif 246 247]])[/* Suppress unused-variable warnings by "using" E. */ 248#if ! defined lint || defined __GNUC__ 249# define YYUSE(E) ((void) (E)) 250#else 251# define YYUSE(E) /* empty */ 252#endif 253 254#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ 255/* Suppress an incorrect diagnostic about yylval being uninitialized. */ 256# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ 257 _Pragma ("GCC diagnostic push") \ 258 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ 259 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") 260# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ 261 _Pragma ("GCC diagnostic pop") 262#else 263# define YY_INITIAL_VALUE(Value) Value 264#endif 265#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 266# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 267# define YY_IGNORE_MAYBE_UNINITIALIZED_END 268#endif 269#ifndef YY_INITIAL_VALUE 270# define YY_INITIAL_VALUE(Value) /* Nothing. */ 271#endif 272]]) 273 274 275# b4_null_define 276# -------------- 277# Portability issues: define a YY_NULLPTR appropriate for the current 278# language (C, C++98, or C++11). 279# 280# In C++ pre C++11 it is standard practice to use 0 (not NULL) for the 281# null pointer. In C, prefer ((void*)0) to avoid having to include stdlib.h. 282m4_define([b4_null_define], 283[# ifndef YY_NULLPTR 284# if defined __cplusplus 285# if 201103L <= __cplusplus 286# define YY_NULLPTR nullptr 287# else 288# define YY_NULLPTR 0 289# endif 290# else 291# define YY_NULLPTR ((void*)0) 292# endif 293# endif[]dnl 294]) 295 296 297# b4_null 298# ------- 299# Return a null pointer constant. 300m4_define([b4_null], [YY_NULLPTR]) 301 302 303 304## ---------## 305## Values. ## 306## ---------## 307 308# b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) 309# ------------------------------------------------------------- 310# Define "yy<TABLE-NAME>" whose contents is CONTENT. 311m4_define([b4_integral_parser_table_define], 312[m4_ifvaln([$3], [b4_comment([$3], [ ])])dnl 313static const b4_int_type_for([$2]) yy$1[[]] = 314{ 315 $2 316};dnl 317]) 318 319 320## ------------------------- ## 321## Assigning token numbers. ## 322## ------------------------- ## 323 324# b4_token_define(TOKEN-NUM) 325# -------------------------- 326# Output the definition of this token as #define. 327m4_define([b4_token_define], 328[b4_token_format([#define %s %s], [$1])]) 329 330# b4_token_defines 331# ---------------- 332# Output the definition of the tokens. 333m4_define([b4_token_defines], 334[b4_any_token_visible_if([/* Tokens. */ 335m4_join([ 336], b4_symbol_map([b4_token_define])) 337])]) 338 339 340# b4_token_enum(TOKEN-NUM) 341# ------------------------ 342# Output the definition of this token as an enum. 343m4_define([b4_token_enum], 344[b4_token_format([%s = %s], [$1])]) 345 346 347# b4_token_enums 348# -------------- 349# Output the definition of the tokens (if there are) as enums. 350m4_define([b4_token_enums], 351[b4_any_token_visible_if([[/* Token type. */ 352#ifndef ]b4_api_PREFIX[TOKENTYPE 353# define ]b4_api_PREFIX[TOKENTYPE 354 enum ]b4_api_prefix[tokentype 355 { 356 ]m4_join([, 357 ], 358 b4_symbol_map([b4_token_enum]))[ 359 }; 360#endif 361]])]) 362 363 364# b4_token_enums_defines 365# ---------------------- 366# Output the definition of the tokens (if there are any) as enums and, 367# if POSIX Yacc is enabled, as #defines. 368m4_define([b4_token_enums_defines], 369[b4_token_enums[]b4_yacc_if([b4_token_defines])]) 370 371 372## ----------------- ## 373## Semantic Values. ## 374## ----------------- ## 375 376 377# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG]) 378# ---------------------------------------------- 379# See README. 380m4_define([b4_symbol_value], 381[m4_ifval([$3], 382 [($1.$3)], 383 [m4_ifval([$2], 384 [b4_symbol_if([$2], [has_type], 385 [($1.b4_symbol([$2], [type]))], 386 [$1])], 387 [$1])])]) 388 389 390## ---------------------- ## 391## Defining C functions. ## 392## ---------------------- ## 393 394 395# b4_function_define(NAME, RETURN-VALUE, [DECL1, NAME1], ...) 396# ----------------------------------------------------------- 397# Declare the function NAME in C. 398m4_define([b4_function_define], 399[$2 400$1 (b4_formals(m4_shift2($@)))[]dnl 401]) 402 403 404# b4_formals([DECL1, NAME1], ...) 405# ------------------------------- 406# The formal arguments of a C function definition. 407m4_define([b4_formals], 408[m4_if([$#], [0], [void], 409 [$#$1], [1], [void], 410 [m4_map_sep([b4_formal], [, ], [$@])])]) 411 412m4_define([b4_formal], 413[$1]) 414 415 416 417## ----------------------- ## 418## Declaring C functions. ## 419## ----------------------- ## 420 421 422# b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...) 423# ------------------------------------------------------------ 424# Declare the function NAME. 425m4_define([b4_function_declare], 426[$2 $1 (b4_formals(m4_shift2($@)));[]dnl 427]) 428 429 430 431 432## --------------------- ## 433## Calling C functions. ## 434## --------------------- ## 435 436 437# b4_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...) 438# ----------------------------------------------------------- 439# Call the function NAME with arguments NAME1, NAME2 etc. 440m4_define([b4_function_call], 441[$1 (b4_args(m4_shift2($@)))[]dnl 442]) 443 444 445# b4_args([DECL1, NAME1], ...) 446# ---------------------------- 447# Output the arguments NAME1, NAME2... 448m4_define([b4_args], 449[m4_map_sep([b4_arg], [, ], [$@])]) 450 451m4_define([b4_arg], 452[$2]) 453 454 455## ----------- ## 456## Synclines. ## 457## ----------- ## 458 459# b4_sync_start(LINE, FILE) 460# ------------------------- 461m4_define([b4_sync_start], [[#]line $1 $2]) 462 463 464## -------------- ## 465## User actions. ## 466## -------------- ## 467 468# b4_case(LABEL, STATEMENTS) 469# -------------------------- 470m4_define([b4_case], 471[ case $1: 472$2 473b4_syncline([@oline@], [@ofile@]) 474 break;]) 475 476 477# b4_predicate_case(LABEL, CONDITIONS) 478# ------------------------------------ 479m4_define([b4_predicate_case], 480[ case $1: 481 if (! ( 482$2)) YYERROR; 483b4_syncline([@oline@], [@ofile@]) 484 break;]) 485 486 487# b4_yydestruct_define 488# -------------------- 489# Define the "yydestruct" function. 490m4_define_default([b4_yydestruct_define], 491[[/*-----------------------------------------------. 492| Release the memory associated to this symbol. | 493`-----------------------------------------------*/ 494 495]b4_function_define([yydestruct], 496 [static void], 497 [[const char *yymsg], [yymsg]], 498 [[int yytype], [yytype]], 499 [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl 500b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl 501m4_ifset([b4_parse_param], [, b4_parse_param]))[ 502{ 503]b4_parse_param_use([yyvaluep], [yylocationp])dnl 504[ if (!yymsg) 505 yymsg = "Deleting"; 506 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); 507 508 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 509 ]b4_symbol_actions([destructor])[ 510 YY_IGNORE_MAYBE_UNINITIALIZED_END 511}]dnl 512]) 513 514 515# b4_yy_symbol_print_define 516# ------------------------- 517# Define the "yy_symbol_print" function. 518m4_define_default([b4_yy_symbol_print_define], 519[[ 520/*-----------------------------------. 521| Print this symbol's value on YYO. | 522`-----------------------------------*/ 523 524]b4_function_define([yy_symbol_value_print], 525 [static void], 526 [[FILE *yyo], [yyo]], 527 [[int yytype], [yytype]], 528 [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl 529b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl 530m4_ifset([b4_parse_param], [, b4_parse_param]))[ 531{ 532 FILE *yyoutput = yyo; 533]b4_parse_param_use([yyoutput], [yylocationp])dnl 534[ if (!yyvaluep) 535 return;] 536dnl glr.c does not feature yytoknum. 537m4_if(b4_skeleton, ["yacc.c"], 538[[# ifdef YYPRINT 539 if (yytype < YYNTOKENS) 540 YYPRINT (yyo, yytoknum[yytype], *yyvaluep); 541# endif 542]])dnl 543 b4_symbol_actions([printer])[ 544} 545 546 547/*---------------------------. 548| Print this symbol on YYO. | 549`---------------------------*/ 550 551]b4_function_define([yy_symbol_print], 552 [static void], 553 [[FILE *yyo], [yyo]], 554 [[int yytype], [yytype]], 555 [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl 556b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl 557m4_ifset([b4_parse_param], [, b4_parse_param]))[ 558{ 559 YYFPRINTF (yyo, "%s %s (", 560 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); 561 562]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp); 563 YYFPRINTF (yyo, ": "); 564])dnl 565[ yy_symbol_value_print (yyo, yytype, yyvaluep]dnl 566b4_locations_if([, yylocationp])[]b4_user_args[); 567 YYFPRINTF (yyo, ")"); 568}]dnl 569]) 570 571 572## ---------------- ## 573## api.value.type. ## 574## ---------------- ## 575 576 577# ---------------------- # 578# api.value.type=union. # 579# ---------------------- # 580 581# b4_symbol_type_register(SYMBOL-NUM) 582# ----------------------------------- 583# Symbol SYMBOL-NUM has a type (for variant) instead of a type-tag. 584# Extend the definition of %union's body (b4_union_members) with a 585# field of that type, and extend the symbol's "type" field to point to 586# the field name, instead of the type name. 587m4_define([b4_symbol_type_register], 588[m4_define([b4_symbol($1, type_tag)], 589 [b4_symbol_if([$1], [has_id], 590 [b4_symbol([$1], [id])], 591 [yytype_[]b4_symbol([$1], [number])])])dnl 592m4_append([b4_union_members], 593m4_expand([ 594 b4_symbol_tag_comment([$1])dnl 595 b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);])) 596]) 597 598 599# b4_type_define_tag(SYMBOL1-NUM, ...) 600# ------------------------------------ 601# For the batch of symbols SYMBOL1-NUM... (which all have the same 602# type), enhance the %union definition for each of them, and set 603# there "type" field to the field tag name, instead of the type name. 604m4_define([b4_type_define_tag], 605[b4_symbol_if([$1], [has_type], 606 [m4_map([b4_symbol_type_register], [$@])]) 607]) 608 609 610# b4_symbol_value_union(VAL, SYMBOL-NUM, [TYPE]) 611# ---------------------------------------------- 612# Same of b4_symbol_value, but when api.value.type=union. 613m4_define([b4_symbol_value_union], 614[m4_ifval([$3], 615 [(*($3*)(&$1))], 616 [m4_ifval([$2], 617 [b4_symbol_if([$2], [has_type], 618 [($1.b4_symbol([$2], [type_tag]))], 619 [$1])], 620 [$1])])]) 621 622 623# b4_value_type_setup_union 624# ------------------------- 625# Setup support for api.value.type=union. Symbols are defined with a 626# type instead of a union member name: build the corresponding union, 627# and give the symbols their tag. 628m4_define([b4_value_type_setup_union], 629[m4_define([b4_union_members]) 630b4_type_foreach([b4_type_define_tag]) 631m4_copy_force([b4_symbol_value_union], [b4_symbol_value]) 632]) 633 634 635# -------------------------- # 636# api.value.type = variant. # 637# -------------------------- # 638 639# b4_value_type_setup_variant 640# --------------------------- 641# Setup support for api.value.type=variant. By default, fail, specialized 642# by other skeletons. 643m4_define([b4_value_type_setup_variant], 644[b4_complain_at(b4_percent_define_get_loc([[api.value.type]]), 645 [['%s' does not support '%s']], 646 [b4_skeleton], 647 [%define api.value.type variant])]) 648 649 650# _b4_value_type_setup_keyword 651# ---------------------------- 652# api.value.type is defined with a keyword/string syntax. Check if 653# that is properly defined, and prepare its use. 654m4_define([_b4_value_type_setup_keyword], 655[b4_percent_define_check_values([[[[api.value.type]], 656 [[none]], 657 [[union]], 658 [[union-directive]], 659 [[variant]], 660 [[yystype]]]])dnl 661m4_case(b4_percent_define_get([[api.value.type]]), 662 [union], [b4_value_type_setup_union], 663 [variant], [b4_value_type_setup_variant])]) 664 665 666# b4_value_type_setup 667# ------------------- 668# Check if api.value.type is properly defined, and possibly prepare 669# its use. 670b4_define_silent([b4_value_type_setup], 671[# Define default value. 672b4_percent_define_ifdef([[api.value.type]], [], 673[# %union => api.value.type=union-directive 674m4_ifdef([b4_union_members], 675[m4_define([b4_percent_define_kind(api.value.type)], [keyword]) 676m4_define([b4_percent_define(api.value.type)], [union-directive])], 677[# no tag seen => api.value.type={int} 678m4_if(b4_tag_seen_flag, 0, 679[m4_define([b4_percent_define_kind(api.value.type)], [code]) 680m4_define([b4_percent_define(api.value.type)], [int])], 681[# otherwise api.value.type=yystype 682m4_define([b4_percent_define_kind(api.value.type)], [keyword]) 683m4_define([b4_percent_define(api.value.type)], [yystype])])])]) 684 685# Set up. 686m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), 687 [keyword\|string], [_b4_value_type_setup_keyword]) 688]) 689 690 691## -------------- ## 692## Declarations. ## 693## -------------- ## 694 695 696# b4_value_type_define 697# -------------------- 698m4_define([b4_value_type_define], 699[b4_value_type_setup[]dnl 700/* Value type. */ 701m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), 702[code], 703[[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED 704typedef ]b4_percent_define_get([[api.value.type]])[ ]b4_api_PREFIX[STYPE; 705# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1 706# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 707#endif 708]], 709[m4_bmatch(b4_percent_define_get([[api.value.type]]), 710[union\|union-directive], 711[[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED 712]b4_percent_define_get_syncline([[api.value.union.name]])[ 713union ]b4_percent_define_get([[api.value.union.name]])[ 714{ 715]b4_user_union_members[ 716}; 717]b4_percent_define_get_syncline([[api.value.union.name]])[ 718typedef union ]b4_percent_define_get([[api.value.union.name]])[ ]b4_api_PREFIX[STYPE; 719# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1 720# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 721#endif 722]])])]) 723 724 725# b4_location_type_define 726# ----------------------- 727m4_define([b4_location_type_define], 728[[/* Location type. */ 729#if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED 730typedef struct ]b4_api_PREFIX[LTYPE ]b4_api_PREFIX[LTYPE; 731struct ]b4_api_PREFIX[LTYPE 732{ 733 int first_line; 734 int first_column; 735 int last_line; 736 int last_column; 737}; 738# define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1 739# define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1 740#endif 741]]) 742 743 744# b4_declare_yylstype 745# ------------------- 746# Declarations that might either go into the header (if --defines) or 747# in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc. 748m4_define([b4_declare_yylstype], 749[b4_value_type_define[]b4_locations_if([ 750b4_location_type_define]) 751 752b4_pure_if([], [[extern ]b4_api_PREFIX[STYPE ]b4_prefix[lval; 753]b4_locations_if([[extern ]b4_api_PREFIX[LTYPE ]b4_prefix[lloc;]])])[]dnl 754]) 755 756 757# b4_YYDEBUG_define 758# ----------------- 759m4_define([b4_YYDEBUG_define], 760[[/* Debug traces. */ 761]m4_if(b4_api_prefix, [yy], 762[[#ifndef YYDEBUG 763# define YYDEBUG ]b4_parse_trace_if([1], [0])[ 764#endif]], 765[[#ifndef ]b4_api_PREFIX[DEBUG 766# if defined YYDEBUG 767#if YYDEBUG 768# define ]b4_api_PREFIX[DEBUG 1 769# else 770# define ]b4_api_PREFIX[DEBUG 0 771# endif 772# else /* ! defined YYDEBUG */ 773# define ]b4_api_PREFIX[DEBUG ]b4_parse_trace_if([1], [0])[ 774# endif /* ! defined YYDEBUG */ 775#endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl 776]) 777 778# b4_declare_yydebug 779# ------------------ 780m4_define([b4_declare_yydebug], 781[b4_YYDEBUG_define[ 782#if ]b4_api_PREFIX[DEBUG 783extern int ]b4_prefix[debug; 784#endif][]dnl 785]) 786 787# b4_yylloc_default_define 788# ------------------------ 789# Define YYLLOC_DEFAULT. 790m4_define([b4_yylloc_default_define], 791[[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. 792 If N is 0, then set CURRENT to the empty location which ends 793 the previous symbol: RHS[0] (always defined). */ 794 795#ifndef YYLLOC_DEFAULT 796# define YYLLOC_DEFAULT(Current, Rhs, N) \ 797 do \ 798 if (N) \ 799 { \ 800 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ 801 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ 802 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ 803 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ 804 } \ 805 else \ 806 { \ 807 (Current).first_line = (Current).last_line = \ 808 YYRHSLOC (Rhs, 0).last_line; \ 809 (Current).first_column = (Current).last_column = \ 810 YYRHSLOC (Rhs, 0).last_column; \ 811 } \ 812 while (0) 813#endif 814]]) 815 816# b4_yy_location_print_define 817# --------------------------- 818# Define YY_LOCATION_PRINT. 819m4_define([b4_yy_location_print_define], 820[b4_locations_if([[ 821/* YY_LOCATION_PRINT -- Print the location on the stream. 822 This macro was not mandated originally: define only if we know 823 we won't break user code: when these are the locations we know. */ 824 825#ifndef YY_LOCATION_PRINT 826# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 827 828/* Print *YYLOCP on YYO. Private, do not rely on its existence. */ 829 830YY_ATTRIBUTE_UNUSED 831]b4_function_define([yy_location_print_], 832 [static int], 833 [[FILE *yyo], [yyo]], 834 [[YYLTYPE const * const yylocp], [yylocp]])[ 835{ 836 int res = 0; 837 int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; 838 if (0 <= yylocp->first_line) 839 { 840 res += YYFPRINTF (yyo, "%d", yylocp->first_line); 841 if (0 <= yylocp->first_column) 842 res += YYFPRINTF (yyo, ".%d", yylocp->first_column); 843 } 844 if (0 <= yylocp->last_line) 845 { 846 if (yylocp->first_line < yylocp->last_line) 847 { 848 res += YYFPRINTF (yyo, "-%d", yylocp->last_line); 849 if (0 <= end_col) 850 res += YYFPRINTF (yyo, ".%d", end_col); 851 } 852 else if (0 <= end_col && yylocp->first_column < end_col) 853 res += YYFPRINTF (yyo, "-%d", end_col); 854 } 855 return res; 856 } 857 858# define YY_LOCATION_PRINT(File, Loc) \ 859 yy_location_print_ (File, &(Loc)) 860 861# else 862# define YY_LOCATION_PRINT(File, Loc) ((void) 0) 863# endif 864#endif]], 865[[/* This macro is provided for backward compatibility. */ 866#ifndef YY_LOCATION_PRINT 867# define YY_LOCATION_PRINT(File, Loc) ((void) 0) 868#endif]]) 869]) 870 871# b4_yyloc_default 872# ---------------- 873# Expand to a possible default value for yylloc. 874m4_define([b4_yyloc_default], 875[[ 876# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 877 = { ]m4_join([, ], 878 m4_defn([b4_location_initial_line]), 879 m4_defn([b4_location_initial_column]), 880 m4_defn([b4_location_initial_line]), 881 m4_defn([b4_location_initial_column]))[ } 882# endif 883]]) 884