Merge branch 'maint'

* maint:
  c++: shorten the assertions that check whether tokens are correct
  c++: don't glue functions together
  lalr1.cc: YY_ASSERT should use api.prefix
  c++: don't use YY_ASSERT at all if parse.assert is disabled
  c++: style: follow the Bison m4 quoting pattern
  yacc.c: provide the Bison version as an integral macro
  regen
  style: make conversion of version string to int public
  %require: accept version numbers with three parts ("3.7.4")
  yacc.c: fix #definition of YYEMPTY
  gnulib: update
  doc: fix incorrect section title
  doc: minor grammar fixes in counterexamples section
This commit is contained in:
Akim Demaille
2020-11-13 07:01:19 +01:00
21 changed files with 314 additions and 165 deletions

View File

@@ -49,7 +49,7 @@ m4_define([m4_shift4], [m4_shift(m4_shift(m4_shift(m4_shift($@))))])
# b4_generated_by
# ---------------
m4_define([b4_generated_by],
[b4_comment([A Bison parser, made by GNU Bison b4_version.])
[b4_comment([A Bison parser, made by GNU Bison b4_version_string.])
])
# b4_copyright(TITLE, [YEARS])
@@ -651,11 +651,11 @@ m4_define([_b4_type_action],
])])
# b4_type_foreach(MACRO)
# ----------------------
# b4_type_foreach(MACRO, [SEP])
# -----------------------------
# Invoke MACRO(SYMBOL-NUMS) for each set of SYMBOL-NUMS for each type set.
m4_define([b4_type_foreach],
[m4_map([$1], m4_defn([b4_type_names]))])
[m4_map_sep([$1], [$2], m4_defn([b4_type_names]))])

View File

@@ -320,8 +320,9 @@ m4_define([b4_symbol_type_define],
/// Copy constructor.
basic_symbol (const basic_symbol& that);]b4_variant_if([[
/// Constructor for valueless symbols, and symbols from each type.
]b4_type_foreach([b4_basic_symbol_constructor_define])], [[
/// Constructors for typed symbols.
]b4_type_foreach([b4_basic_symbol_constructor_define], [
])], [[
/// Constructor for valueless symbols.
basic_symbol (typename Base::kind_type t]b4_locations_if([,
YY_MOVE_REF (location_type) l])[);

View File

@@ -58,11 +58,11 @@ m4_define([b4_cpp_guard_close],
# b4_pull_flag if they use the values of the %define variables api.pure or
# api.push-pull.
m4_define([b4_identification],
[[/* Identify Bison output. */
#define YYBISON 1
[[/* Identify Bison output, and Bison version. */
#define YYBISON ]b4_version[
/* Bison version. */
#define YYBISON_VERSION "]b4_version["
/* Bison version string. */
#define YYBISON_VERSION "]b4_version_string["
/* Skeleton name. */
#define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[
@@ -520,10 +520,11 @@ m4_define([b4_token_define],
# ----------------
# Output the definition of the tokens.
m4_define([b4_token_defines],
[b4_any_token_visible_if([/* Token kinds. */
m4_join([
[[/* Token kinds. */
#define ]b4_symbol([-2], [id])[ -2
]m4_join([
], b4_symbol_map([b4_token_define]))
])])
])
# b4_token_enum(TOKEN-NUM)

View File

@@ -122,12 +122,12 @@ m4_define([b4_location_type_if],
# b4_identification
# -----------------
m4_define([b4_identification],
[/** Version number for the Bison executable that generated this parser. */
public static immutable string yy_bison_version = "b4_version";
[[/** Version number for the Bison executable that generated this parser. */
public static immutable string yy_bison_version = "]b4_version_string[";
/** Name of the skeleton that generated this parser. */
public static immutable string yy_bison_skeleton = b4_skeleton;
])
public static immutable string yy_bison_skeleton = ]b4_skeleton[;
]])
## ------------ ##

View File

@@ -71,12 +71,12 @@ m4_define([b4_lexer_if],
# b4_identification
# -----------------
m4_define([b4_identification],
[ /** Version number for the Bison executable that generated this parser. */
public static final String bisonVersion = "b4_version";
[[ /** Version number for the Bison executable that generated this parser. */
public static final String bisonVersion = "]b4_version_string[";
/** Name of the skeleton that generated this parser. */
public static final String bisonSkeleton = b4_skeleton;
])
public static final String bisonSkeleton = ]b4_skeleton[;
]])
## ------------ ##

View File

@@ -22,8 +22,8 @@ m4_pushdef([b4_copyright_years],
# b4_position_file
# ----------------
# Name of the file containing the position class, if we want this file.
b4_header_if([b4_required_version_if([302], [],
[m4_define([b4_position_file], [position.hh])])])])
b4_header_if([b4_required_version_if([30200], [],
[m4_define([b4_position_file], [position.hh])])])])
# b4_location_file

View File

@@ -19,8 +19,8 @@
# b4_stack_file
# -------------
# Name of the file containing the stack class, if we want this file.
b4_header_if([b4_required_version_if([302], [],
[m4_define([b4_stack_file], [stack.hh])])])
b4_header_if([b4_required_version_if([30200], [],
[m4_define([b4_stack_file], [stack.hh])])])
# b4_stack_define

View File

@@ -20,6 +20,13 @@
## variant. ##
## --------- ##
# b4_assert
# ---------
# The name of YY_ASSERT.
m4_define([b4_assert],
[b4_api_PREFIX[]_ASSERT])
# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS])
# ------------------------------------------------
# Run some ACTION ("build", or "destroy") on YYVAL of symbol type
@@ -71,12 +78,12 @@ m4_map([ b4_symbol_tag_comment], [$@])dnl
# -------------------
# The needed includes for variants support.
m4_define([b4_variant_includes],
[b4_parse_assert_if([[#include <typeinfo>]])[
#ifndef YY_ASSERT
[b4_parse_assert_if([[#include <typeinfo>
#ifndef ]b4_assert[
# include <cassert>
# define YY_ASSERT assert
# define ]b4_assert[ assert
#endif
]])
]])])
@@ -110,8 +117,8 @@ m4_define([b4_value_type_declare],
template <typename T>
semantic_type (YY_RVREF (T) t)]b4_parse_assert_if([
: yytypeid_ (&typeid (T))])[
{
YY_ASSERT (sizeof (T) <= size);
{]b4_parse_assert_if([[
]b4_assert[ (sizeof (T) <= size);]])[
new (yyas_<T> ()) T (YY_MOVE (t));
}
@@ -125,7 +132,7 @@ m4_define([b4_value_type_declare],
/// Destruction, allowed only if empty.
~semantic_type () YY_NOEXCEPT
{]b4_parse_assert_if([
YY_ASSERT (!yytypeid_);
]b4_assert[ (!yytypeid_);
])[}
# if 201103L <= YY_CPLUSPLUS
@@ -133,10 +140,10 @@ m4_define([b4_value_type_declare],
template <typename T, typename... U>
T&
emplace (U&&... u)
{]b4_parse_assert_if([
YY_ASSERT (!yytypeid_);
YY_ASSERT (sizeof (T) <= size);
yytypeid_ = & typeid (T);])[
{]b4_parse_assert_if([[
]b4_assert[ (!yytypeid_);
]b4_assert[ (sizeof (T) <= size);
yytypeid_ = & typeid (T);]])[
return *new (yyas_<T> ()) T (std::forward <U>(u)...);
}
# else
@@ -144,10 +151,10 @@ m4_define([b4_value_type_declare],
template <typename T>
T&
emplace ()
{]b4_parse_assert_if([
YY_ASSERT (!yytypeid_);
YY_ASSERT (sizeof (T) <= size);
yytypeid_ = & typeid (T);])[
{]b4_parse_assert_if([[
]b4_assert[ (!yytypeid_);
]b4_assert[ (sizeof (T) <= size);
yytypeid_ = & typeid (T);]])[
return *new (yyas_<T> ()) T ();
}
@@ -155,10 +162,10 @@ m4_define([b4_value_type_declare],
template <typename T>
T&
emplace (const T& t)
{]b4_parse_assert_if([
YY_ASSERT (!yytypeid_);
YY_ASSERT (sizeof (T) <= size);
yytypeid_ = & typeid (T);])[
{]b4_parse_assert_if([[
]b4_assert[ (!yytypeid_);
]b4_assert[ (sizeof (T) <= size);
yytypeid_ = & typeid (T);]])[
return *new (yyas_<T> ()) T (t);
}
# endif
@@ -185,10 +192,10 @@ m4_define([b4_value_type_declare],
template <typename T>
T&
as () YY_NOEXCEPT
{]b4_parse_assert_if([
YY_ASSERT (yytypeid_);
YY_ASSERT (*yytypeid_ == typeid (T));
YY_ASSERT (sizeof (T) <= size);])[
{]b4_parse_assert_if([[
]b4_assert[ (yytypeid_);
]b4_assert[ (*yytypeid_ == typeid (T));
]b4_assert[ (sizeof (T) <= size);]])[
return *yyas_<T> ();
}
@@ -196,10 +203,10 @@ m4_define([b4_value_type_declare],
template <typename T>
const T&
as () const YY_NOEXCEPT
{]b4_parse_assert_if([
YY_ASSERT (yytypeid_);
YY_ASSERT (*yytypeid_ == typeid (T));
YY_ASSERT (sizeof (T) <= size);])[
{]b4_parse_assert_if([[
]b4_assert[ (yytypeid_);
]b4_assert[ (*yytypeid_ == typeid (T));
]b4_assert[ (sizeof (T) <= size);]])[
return *yyas_<T> ();
}
@@ -214,9 +221,9 @@ m4_define([b4_value_type_declare],
template <typename T>
void
swap (self_type& that) YY_NOEXCEPT
{]b4_parse_assert_if([
YY_ASSERT (yytypeid_);
YY_ASSERT (*yytypeid_ == *that.yytypeid_);])[
{]b4_parse_assert_if([[
]b4_assert[ (yytypeid_);
]b4_assert[ (*yytypeid_ == *that.yytypeid_);]])[
std::swap (as<T> (), that.as<T> ());
}
@@ -388,11 +395,67 @@ m4_define([_b4_token_maker_define],
])])
m4_define([_b4_type_clause],
[b4_symbol_if([$1], [is_token],
[b4_symbol_if([$1], [has_id],
[tok == token::b4_symbol([$1], [id])],
[tok == b4_symbol([$1], [code])])])])
# b4_token_kind(SYMBOL-NUM)
# -------------------------
# Some tokens don't have an ID.
m4_define([b4_token_kind],
[b4_symbol_if([$1], [has_id],
[token::b4_symbol([$1], [id])],
[b4_symbol([$1], [code])])])
# _b4_tok_in(SYMBOL-NUM, ...)
# ---------------------------
# See b4_tok_in below. The SYMBOL-NUMs... are tokens only.
#
# We iterate over the tokens to group them by "range" of token numbers (not
# symbols numbers!).
#
# b4_fst is the start of that range.
# b4_prev is the previous value.
# b4_val is the current value.
# If b4_val is the successor of b4_prev in token numbers, update the latter,
# otherwise emit the code for range b4_fst .. b4_prev.
# $1 is also used as a terminator in the foreach, but it will not be printed.
#
m4_define([_b4_tok_in],
[m4_pushdef([b4_prev], [$1])dnl
m4_pushdef([b4_fst], [$1])dnl
m4_pushdef([b4_sep], [])dnl
m4_foreach([b4_val], m4_dquote(m4_shift($@, $1)),
[m4_if(b4_symbol(b4_val, [code]), m4_eval(b4_symbol(b4_prev, [code]) + 1), [],
[b4_sep[]m4_if(b4_fst, b4_prev,
[tok == b4_token_kind(b4_fst)],
[(b4_token_kind(b4_fst) <= tok && tok <= b4_token_kind(b4_prev))])[]dnl
m4_define([b4_fst], b4_val)dnl
m4_define([b4_sep], [
|| ])])dnl
m4_define([b4_prev], b4_val)])dnl
m4_popdef([b4_sep])dnl
m4_popdef([b4_fst])dnl
m4_popdef([b4_prev])dnl
])
# _b4_filter_tokens(SYMBOL-NUM, ...)
# ----------------------------------
# Expand as the list of tokens amongst SYMBOL-NUM.
m4_define([_b4_filter_tokens],
[m4_pushdef([b4_sep])dnl
m4_foreach([b4_val], [$@],
[b4_symbol_if(b4_val, [is_token], [b4_sep[]b4_val[]m4_define([b4_sep], [,])])])dnl
m4_popdef([b4_sep])dnl
])
# b4_tok_in(SYMBOL-NUM, ...)
# ---------------------------
# A C++ conditional that checks that `tok` is a member of this list of symbol
# numbers.
m4_define([b4_tok_in],
[_$0(_b4_filter_tokens($@))])
# _b4_token_constructor_define(SYMBOL-NUM...)
@@ -410,9 +473,6 @@ m4_define([_b4_token_constructor_define],
: super_type(]b4_join([token_type (tok)],
b4_symbol_if([$1], [has_type], [std::move (v)]),
b4_locations_if([std::move (l)]))[)
{
YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
}
#else
symbol_type (]b4_join(
[int tok],
@@ -422,10 +482,10 @@ m4_define([_b4_token_constructor_define],
: super_type(]b4_join([token_type (tok)],
b4_symbol_if([$1], [has_type], [v]),
b4_locations_if([l]))[)
{
YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[);
}
#endif
{]b4_parse_assert_if([[
]b4_assert[ (]b4_tok_in($@)[);
]])[}
]])])