X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/1462fcee1ed295b24f47758b370068aa6304bb41..95361618dee181507d53f47de2dd50c667b84007:/data/c.m4 diff --git a/data/c.m4 b/data/c.m4 index 964fc2e0..1f266a47 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -1,7 +1,8 @@ -*- Autoconf -*- # C M4 Macros for Bison. -# Copyright (C) 2002, 2004-2010 Free Software Foundation, Inc. + +# Copyright (C) 2002, 2004-2012 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,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. ## ## ---------------- ## @@ -49,9 +77,6 @@ m4_define([b4_identification], /* Pull parsers. */ #define YYPULL ]b4_pull_flag])[ - -/* Using locations. */ -#define YYLSP_NEEDED ]b4_locations_flag[ ]]) @@ -145,16 +170,31 @@ m4_define([b4_table_value_equals], [[YYID (0)]], [[((]$2[) == (]$3[))]])]) + ## ---------## ## Values. ## ## ---------## -# b4_null ---------- -# Return a null pointer constant. NULL infringes on the user name -# space in C, so use 0 rather than NULL. -m4_define([b4_null], [0]) +# b4_null_define +# -------------- +# Portability issues: define a YY_NULL appropriate for the current +# language (C, C++98, or C++11). +m4_define([b4_null_define], +[# ifndef YY_NULL +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULL nullptr +# else +# define YY_NULL 0 +# endif +# endif[]dnl +]) + + +# b4_null +# ------- +# Return a null pointer constant. +m4_define([b4_null], [YY_NULL]) @@ -440,6 +480,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]))[ { + FILE *yyo = yyoutput; + YYUSE (yyo); if (!yyvaluep) return; ]b4_locations_if([ YYUSE (yylocationp); @@ -485,3 +527,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_debug_flag[ +#endif +#if YYDEBUG +extern int ]b4_prefix[debug; +#endif][]dnl +])