X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/6574576cfb6e5039e8a21714e8d9bf482ae7c32f..3afe18fd1fdc467e6662158275c5d8c3b7121e83:/data/c.m4 diff --git a/data/c.m4 b/data/c.m4 index eb469cdf..b1b43948 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -199,6 +199,50 @@ m4_define([b4_table_value_equals], [(!!(($2) == ($3)))])]) +## ----------------- ## +## 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 + +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +# define YY_INITIAL_VALUE(Value) Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif +]) + + ## ---------## ## Values. ## ## ---------## @@ -421,12 +465,9 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[ yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); - switch (yytype) - { -]b4_symbol_foreach([b4_symbol_destructor])dnl -[ default: - break; - } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + ]b4_symbol_actions([destructor])[ + YY_IGNORE_MAYBE_UNINITIALIZED_END }]dnl ]) @@ -436,9 +477,9 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[ # Define the "yy_symbol_print" function. m4_define_default([b4_yy_symbol_print_define], [[ -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ +/*----------------------------------------. +| Print this symbol's value on YYOUTPUT. | +`----------------------------------------*/ ]b4_function_define([yy_symbol_value_print], [static void], @@ -459,12 +500,7 @@ m4_if(b4_skeleton, ["yacc.c"], YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); # endif ]])dnl -[ switch (yytype) - { -]b4_symbol_foreach([b4_symbol_printer])dnl -[ default: - break; - } + b4_symbol_actions([printer])[ } @@ -563,25 +599,51 @@ m4_copy_force([b4_symbol_value_union], [b4_symbol_value]) # Setup support for api.value.type=variant. By default, fail, specialized # by other skeletons. m4_define([b4_value_type_setup_variant], -[b4_complain_at(b4_percent_define_get_loc([api.value.type]), +[b4_complain_at(b4_percent_define_get_loc([[api.value.type]]), [['%s' does not support '%s']], [b4_skeleton], [%define api.value.type variant])]) +# _b4_value_type_setup_keyword +# ---------------------------- +# api.value.type is defined with a keyword/string syntax. Check if +# that is properly defined, and prepare its use. +m4_define([_b4_value_type_setup_keyword], +[b4_percent_define_check_values([[[[api.value.type]], + [[none]], + [[union]], + [[union-directive]], + [[variant]], + [[yystype]]]])dnl +m4_case(b4_percent_define_get([[api.value.type]]), + [union], [b4_value_type_setup_union], + [variant], [b4_value_type_setup_variant])]) + + # b4_value_type_setup # ------------------- # Check if api.value.type is properly defined, and possibly prepare # its use. -m4_define([b4_value_type_setup], -[b4_percent_define_default([[api.value.type]], -[m4_ifdef([b4_union_members], [%union], - [m4_if(b4_tag_seen_flag, 0, [int], - [])])])dnl -m4_case(b4_percent_define_get([api.value.type]), - [union], [b4_value_type_setup_union], - [variant], [b4_value_type_setup_variant])]) - +b4_define_silent([b4_value_type_setup], +[# Define default value. +b4_percent_define_ifdef([[api.value.type]], [], +[# %union => api.value.type=union-directive +m4_ifdef([b4_union_members], +[m4_define([b4_percent_define_kind(api.value.type)], [keyword]) +m4_define([b4_percent_define(api.value.type)], [union-directive])], +[# no tag seen => api.value.type={int} +m4_if(b4_tag_seen_flag, 0, +[m4_define([b4_percent_define_kind(api.value.type)], [code]) +m4_define([b4_percent_define(api.value.type)], [int])], +[# otherwise api.value.type=yystype +m4_define([b4_percent_define_kind(api.value.type)], [keyword]) +m4_define([b4_percent_define(api.value.type)], [yystype])])])]) + +# Set up. +m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), + [keyword\|string], [_b4_value_type_setup_keyword]) +]) ## -------------- ## @@ -594,25 +656,26 @@ m4_case(b4_percent_define_get([api.value.type]), m4_define([b4_value_type_define], [b4_value_type_setup[]dnl /* Value type. */ -m4_bmatch(b4_percent_define_get([api.value.type]), -[^%?union$], +m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), +[code], [[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED -typedef union ]b4_union_name[ ]b4_api_PREFIX[STYPE; -union ]b4_union_name[ -{ -]b4_user_union_members[ -}; +typedef ]b4_percent_define_get([[api.value.type]])[ ]b4_api_PREFIX[STYPE; # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1 # define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 #endif ]], -[^$], [], +[m4_bmatch(b4_percent_define_get([[api.value.type]]), +[union\|union-directive], [[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED -typedef ]b4_percent_define_get([api.value.type])[ ]b4_api_PREFIX[STYPE; +typedef union ]b4_union_name[ ]b4_api_PREFIX[STYPE; +union ]b4_union_name[ +{ +]b4_user_union_members[ +}; # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1 # define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 #endif -]])]) +]])])]) # b4_location_type_define