X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/cd735a8c6caab8f705fe551cc0316d0292eef11d..3cf3393bd419f907902034272d6a4b930c62b542:/data/c.m4 diff --git a/data/c.m4 b/data/c.m4 index 45468e3c..bcafe422 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -30,19 +30,21 @@ m4_define([b4_tocpp], # ------------------ # 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])]) +[[YY_]b4_tocpp(m4_defn([b4_prefix])/[$1])[_INCLUDED]]) # b4_cpp_guard_open(FILE) # b4_cpp_guard_close(FILE) # ------------------------ -# Open/close CPP inclusion guards for FILE. +# If FILE does not expand to nothing, open/close CPP inclusion guards for FILE. m4_define([b4_cpp_guard_open], +[m4_ifval(m4_quote($1), [#ifndef b4_cpp_guard([$1]) -# define b4_cpp_guard([$1])]) +# define b4_cpp_guard([$1])])]) m4_define([b4_cpp_guard_close], -[#endif b4_comment([!b4_cpp_guard([$1])])]) +[m4_ifval(m4_quote($1), +[#endif b4_comment([!b4_cpp_guard([$1])])])]) ## ---------------- ## @@ -161,7 +163,7 @@ m4_define([b4_int_type], m4_eval([0 <= $1]), [1], [unsigned int], - [int])]) + [int])]) # b4_int_type_for(NAME) @@ -182,12 +184,32 @@ m4_define([b4_table_value_equals], [m4_if(m4_eval($3 < m4_indir([b4_]$1[_min]) || m4_indir([b4_]$1[_max]) < $3), [1], [[YYID (0)]], - [[((]$2[) == (]$3[))]])]) + [(!!(($2) == ($3)))])]) -## ---------## -## Values. ## -## ---------## +## ----------------- ## +## Compiler issues. ## +## ----------------- ## + +# b4_attribute_define +# ------------------- +# Provide portability for __attribute__. +m4_define([b4_attribute_define], +[#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if (! defined __GNUC__ || __GNUC__ < 2 \ + || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)) +# define __attribute__(Spec) /* empty */ +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(E) ((void) (E)) +#else +# define YYUSE(E) /* empty */ +#endif +]) # b4_null_define @@ -254,7 +276,7 @@ m4_define([b4_token_enums], enum ]b4_api_prefix[tokentype { ]m4_map_sep([ b4_token_enum], [, ], - [$@])[ + [$@])[ }; #endif ]])]) @@ -318,7 +340,7 @@ $1 (b4_c_ansi_formals(m4_shift2($@)))[]dnl m4_define([b4_c_ansi_formals], [m4_if([$#], [0], [void], [$#$1], [1], [void], - [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])]) + [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])]) m4_define([b4_c_ansi_formal], [$1]) @@ -339,9 +361,9 @@ m4_define([b4_c_knr_formal_name], # Output the K&R argument declarations. m4_define([b4_c_knr_formal_decls], [m4_map_sep([b4_c_knr_formal_decl], - [ + [ ], - [$@])]) + [$@])]) m4_define([b4_c_knr_formal_decl], [ $1;]) @@ -353,9 +375,18 @@ m4_define([b4_c_knr_formal_decl], ## ------------------------------------------------------------ ## +# b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) +# ---------------------------------------------------------------- +# Declare the function NAME ANSI C style. +m4_define([b4_c_ansi_function_decl], +[$2 $1 (b4_c_ansi_formals(m4_shift2($@)));[]dnl +]) + + + # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) # ----------------------------------------------------------- -# Declare the function NAME. +# Declare the function NAME in both K&R and ANSI C. m4_define([b4_c_function_decl], [#if defined __STDC__ || defined __cplusplus b4_c_ansi_function_decl($@) @@ -365,15 +396,6 @@ $2 $1 (); ]) -# b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) -# ---------------------------------------------------------------- -# Declare the function NAME. -m4_define([b4_c_ansi_function_decl], -[$2 $1 (b4_c_ansi_formals(m4_shift2($@)));[]dnl -]) - - - ## --------------------- ## ## Calling C functions. ## @@ -403,7 +425,7 @@ m4_define([b4_c_arg], ## ----------- ## # b4_sync_start(LINE, FILE) -# ----------------------- +# ------------------------- m4_define([b4_sync_start], [[#]line $1 $2]) @@ -418,24 +440,38 @@ m4_define([b4_case], $2 break;]) -# b4_symbol_actions(FILENAME, LINENO, -# SYMBOL-TAG, SYMBOL-NUM, -# SYMBOL-ACTION, SYMBOL-TYPENAME) -# ------------------------------------------------- +# _b4_symbol_actions(FILENAME, LINENO, +# SYMBOL-TAG, SYMBOL-NUM, +# SYMBOL-ACTION, SYMBOL-TYPENAME) +# -------------------------------------------------- # Issue the code for a symbol action (e.g., %printer). # # Define b4_dollar_dollar([TYPE-NAME]), and b4_at_dollar, which are # invoked where $$ and @$ were specified by the user. -m4_define([b4_symbol_actions], +m4_define([_b4_symbol_actions], [b4_dollar_pushdef([(*yyvaluep)], [$6], [(*yylocationp)])dnl case $4: /* $3 */ b4_syncline([$2], [$1]) - $5; + $5; b4_syncline([@oline@], [@ofile@]) - break; + break; b4_dollar_popdef[]dnl ]) +# b4_symbol_actions(KIND) +# ----------------------- +# Emit the symbol actions for KIND ("printers" or "destructors"). +# Dispatch on "yytype". +m4_define([b4_symbol_actions], +[m4_ifval(m4_defn([b4_symbol_$1]), +[[switch (yytype) + { +]m4_map([_b4_symbol_actions], m4_defn([b4_symbol_$1]))[ + default: + break; + }]], +[YYUSE (yytype);])]) + # b4_yydestruct_generate(FUNCTION-DECLARATOR) # ------------------------------------------- @@ -465,12 +501,7 @@ b4_parse_param_use[]dnl yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - switch (yytype) - { -]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[ - default: - break; - } + ]b4_symbol_actions([destructors])[ }]dnl ]) @@ -489,9 +520,9 @@ m4_define_default([b4_yy_symbol_print_generate], /*ARGSUSED*/ ]$1([yy_symbol_value_print], [static void], - [[FILE *yyoutput], [yyoutput]], - [[int yytype], [yytype]], - [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl + [[FILE *yyoutput], [yyoutput]], + [[int yytype], [yytype]], + [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl m4_ifset([b4_parse_param], [, b4_parse_param]))[ { @@ -508,12 +539,7 @@ b4_parse_param_use[]dnl # else YYUSE (yyoutput); # endif - switch (yytype) - { -]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl -[ default: - break; - } + ]b4_symbol_actions([printers])[ } @@ -523,9 +549,9 @@ b4_parse_param_use[]dnl ]$1([yy_symbol_print], [static void], - [[FILE *yyoutput], [yyoutput]], - [[int yytype], [yytype]], - [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl + [[FILE *yyoutput], [yyoutput]], + [[int yytype], [yytype]], + [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl m4_ifset([b4_parse_param], [, b4_parse_param]))[ { @@ -600,7 +626,7 @@ m4_define([b4_YYDEBUG_define], # endif # else /* ! defined YYDEBUG */ # define ]b4_api_PREFIX[DEBUG ]b4_debug_flag[ -# endif /* ! defined ]b4_api_PREFIX[DEBUG */ +# endif /* ! defined YYDEBUG */ #endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl ]) @@ -641,3 +667,72 @@ m4_define([b4_yylloc_default_define], while (YYID (0)) #endif ]]) + +# b4_yy_location_print_define +# --------------------------- +# Define YY_LOCATION_PRINT. +m4_define([b4_yy_location_print_define], +[b4_locations_if([[ +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL + +/* Print *YYLOCP on YYO. Private, do not rely on its existence. */ + +__attribute__((__unused__)) +]b4_c_function_def([yy_location_print_], + [static unsigned], + [[FILE *yyo], [yyo]], + [[YYLTYPE const * const yylocp], [yylocp]])[ +{ + unsigned res = 0; + int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; + if (0 <= yylocp->first_line) + { + res += fprintf (yyo, "%d", yylocp->first_line); + if (0 <= yylocp->first_column) + res += fprintf (yyo, ".%d", yylocp->first_column); + } + if (0 <= yylocp->last_line) + { + if (yylocp->first_line < yylocp->last_line) + { + res += fprintf (yyo, "-%d", yylocp->last_line); + if (0 <= end_col) + res += fprintf (yyo, ".%d", end_col); + } + else if (0 <= end_col && yylocp->first_column < end_col) + res += fprintf (yyo, "-%d", end_col); + } + return res; + } + +# define YY_LOCATION_PRINT(File, Loc) \ + yy_location_print_ (File, &(Loc)) + +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif]], +[[/* This macro is provided for backward compatibility. */ +#ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +#endif]]) +]) + +# b4_yyloc_default +# ---------------- +# Expand to a possible default value for yylloc. +m4_define([b4_yyloc_default], +[[ +# if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL + = { ]m4_join([, ], + m4_defn([b4_location_initial_line]), + m4_defn([b4_location_initial_column]), + m4_defn([b4_location_initial_line]), + m4_defn([b4_location_initial_column]))[ } +# endif +]])