X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/4c36bc2b8d65cb76480a30b3fcd2d7824ea12de9..a565f732762ab6f5918805a306c7a4d17e2b8da7:/data/c.m4 diff --git a/data/c.m4 b/data/c.m4 index c2f1a053..bcafe422 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -187,9 +187,29 @@ m4_define([b4_table_value_equals], [(!!(($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 @@ -405,7 +425,7 @@ m4_define([b4_c_arg], ## ----------- ## # b4_sync_start(LINE, FILE) -# ----------------------- +# ------------------------- m4_define([b4_sync_start], [[#]line $1 $2]) @@ -420,15 +440,15 @@ 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]) @@ -438,6 +458,20 @@ b4_syncline([@oline@], [@ofile@]) 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) # ------------------------------------------- @@ -467,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 ]) @@ -510,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])[ } @@ -655,14 +679,40 @@ m4_define([b4_yy_location_print_define], #ifndef YY_LOCATION_PRINT # if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - do { \ - fprintf (File, "%d.%d", (Loc).first_line, (Loc).first_column); \ - if ((Loc).first_line < (Loc).last_line) \ - fprintf (File, "-%d.%d", (Loc).last_line, (Loc).last_column - 1); \ - else if ((Loc).first_column < (Loc).last_column - 1) \ - fprintf (File, "-%d", (Loc).last_column - 1); \ - } while (0) + +/* 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