X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/3e75a2c92b12766add442d00a86d5ec1c67ce560..22b081deb7ab1d0ec7a279e5213fa7fdc2c85207:/data/c.m4 diff --git a/data/c.m4 b/data/c.m4 index 14db807b..9bd82956 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -17,6 +17,33 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . + +# b4_tocpp(STRING) +# ---------------- +# Convert STRING into a valid C macro name. +m4_define([b4_tocpp], +[m4_toupper(m4_bpatsubst(m4_quote($1), [[^a-zA-Z0-9]+], [_]))]) + + +# b4_cpp_guard(FILE) +# ------------------ +# A valid C macro name to use as a CPP header guard for FILE. +m4_define([b4_cpp_guard], +[b4_tocpp(m4_defn([b4_prefix])/[$1])]) + + +# b4_cpp_guard_open(FILE) +# b4_cpp_guard_close(FILE) +# ------------------------ +# Open/close CPP inclusion guards for FILE. +m4_define([b4_cpp_guard_open], +[#ifndef b4_cpp_guard([$1]) +# define b4_cpp_guard([$1])]) + +m4_define([b4_cpp_guard_close], +[#endif b4_comment([!b4_cpp_guard([$1])])]) + + ## ---------------- ## ## Identification. ## ## ---------------- ## @@ -495,7 +522,8 @@ m4_define_default([b4_yy_symbol_print_generate], b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl m4_ifset([b4_parse_param], [, b4_parse_param]))[ { -]b4_parse_param_use([yyoutput], [yylocationp])dnl + FILE *yyo = yyoutput; +]b4_parse_param_use([yyo], [yylocationp])dnl [ if (!yyvaluep) return;] dnl glr.c does not feature yytoknum. @@ -539,3 +567,55 @@ b4_locations_if([, yylocationp])[]b4_user_args[); YYFPRINTF (yyoutput, ")"); }]dnl ]) + +## -------------- ## +## Declarations. ## +## -------------- ## + +# b4_declare_yylstype +# ------------------ +# Declarations that might either go into the header (if --defines) or +# in the parser body. Declare YYSTYPE/YYLTYPE, and yylval/yylloc. +m4_define([b4_declare_yylstype], +[[#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +]m4_ifdef([b4_stype], +[[typedef union ]b4_union_name[ +{ +]b4_user_stype[ +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1]], +[m4_if(b4_tag_seen_flag, 0, +[[typedef int YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1]])])[ +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif]b4_locations_if([[ + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif]]) + +b4_pure_if([], [[extern YYSTYPE ]b4_prefix[lval; +]b4_locations_if([[extern YYLTYPE ]b4_prefix[lloc;]])])[]dnl +]) + +# b4_declare_yydebug +# ------------------ +m4_define([b4_declare_yydebug], +[[/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG ]b4_parse_trace_if([1], [0])[ +#endif +#if YYDEBUG +extern int ]b4_prefix[debug; +#endif][]dnl +])