mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
api.value.type: use keyword/brace values
Suggested by Joel E. Denny. http://lists.gnu.org/archive/html/bison-patches/2013-03/msg00016.html * data/bison.m4 (b4_percent_define_get_kind): New. (b4_variant_flag): Check that api.value.type is defined as the 'variant' keyword value. * data/c.m4 (_b4_value_type_setup_keyword): New. (b4_value_type_setup): Use it to simplify reading. Use b4_define_silent. Decode api.value.type, including its type. (b4_value_type_define): Likewise. * data/c++.m4 (b4_value_type_declare): Adjust the decoding of api.value.type, taking its kind into account. * doc/bison.texi: Adjust all the examples to the new syntax. * NEWS: Ditto. * tests/types.at: Adjust
This commit is contained in:
@@ -707,6 +707,20 @@ b4_loc[]dnl
|
||||
m4_popdef([b4_loc])],
|
||||
[b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
|
||||
|
||||
# b4_percent_define_get_kind(VARIABLE)
|
||||
# ------------------------------------
|
||||
# Get the kind (code, keyword, string) of VARIABLE, i.e., how its
|
||||
# value was defined (braces, not delimiters, quotes).
|
||||
#
|
||||
# If the %define variable VARIABLE is undefined, complain fatally
|
||||
# since that's a Bison or skeleton error. Don't record this as a
|
||||
# Bison usage of VARIABLE as there's no reason to suspect that the
|
||||
# user-supplied value has yet influenced the output.
|
||||
m4_define([b4_percent_define_get_kind],
|
||||
[m4_ifdef([b4_percent_define_kind(]$1[)],
|
||||
[m4_indir([b4_percent_define_kind(]$1[)])],
|
||||
[b4_fatal([[$0: undefined %%define variable '%s']], [$1])])])
|
||||
|
||||
# b4_percent_define_get_syncline(VARIABLE)
|
||||
# ----------------------------------------
|
||||
# Mimic muscle_percent_define_get_syncline in ../src/muscle-tab.h exactly.
|
||||
@@ -923,9 +937,11 @@ b4_error_verbose_if([m4_define([b4_token_table_flag], [1])])
|
||||
# b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT])
|
||||
# ----------------------------------------------
|
||||
b4_percent_define_if_define([variant])
|
||||
m4_case(b4_percent_define_get([[api.value.type]]),
|
||||
[variant], [m4_define([b4_variant_flag], [[1]])],
|
||||
[m4_define([b4_variant_flag], [[0]])])
|
||||
m4_define([b4_variant_flag], [[0]])
|
||||
b4_percent_define_ifdef([[api.value.type]],
|
||||
[m4_case(b4_percent_define_get_kind([[api.value.type]]), [keyword],
|
||||
[m4_case(b4_percent_define_get([[api.value.type]]), [variant],
|
||||
[m4_define([b4_variant_flag], [[1]])])])])
|
||||
b4_define_flag_if([variant])
|
||||
|
||||
|
||||
|
||||
14
data/c++.m4
14
data/c++.m4
@@ -120,14 +120,16 @@ m4_define([b4_token_enums],
|
||||
m4_define([b4_value_type_declare],
|
||||
[b4_value_type_setup[]dnl
|
||||
[ /// Symbol semantic values.
|
||||
]m4_bmatch(b4_percent_define_get([api.value.type]),
|
||||
[^%union\|union$],
|
||||
]m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
|
||||
[code],
|
||||
[[ typedef ]b4_percent_define_get([[api.value.type]])[ semantic_type;]],
|
||||
[m4_bmatch(b4_percent_define_get([[api.value.type]]),
|
||||
[union\|union-directive],
|
||||
[[ union semantic_type
|
||||
{
|
||||
]b4_user_union_members[
|
||||
};]],
|
||||
[^$], [],
|
||||
[[ typedef ]b4_percent_define_get([api.value.type])[ semantic_type;]])])
|
||||
]b4_user_union_members[
|
||||
};]])])dnl
|
||||
])
|
||||
|
||||
|
||||
# b4_public_types_declare
|
||||
|
||||
65
data/c.m4
65
data/c.m4
@@ -563,25 +563,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,8 +620,16 @@ 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 ]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 union ]b4_union_name[ ]b4_api_PREFIX[STYPE;
|
||||
union ]b4_union_name[
|
||||
@@ -605,14 +639,7 @@ union ]b4_union_name[
|
||||
# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1
|
||||
# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
|
||||
#endif
|
||||
]],
|
||||
[^$], [],
|
||||
[[#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;
|
||||
# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1
|
||||
# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
|
||||
#endif
|
||||
]])])
|
||||
]])])])
|
||||
|
||||
|
||||
# b4_location_type_define
|
||||
|
||||
Reference in New Issue
Block a user