diff --git a/NEWS b/NEWS index cdbd53f0..61534bc0 100644 --- a/NEWS +++ b/NEWS @@ -4,22 +4,27 @@ GNU Bison NEWS ** Changes +*** C++ value_type + + Prefer value_type to semantic_type to denote the semantic value type, + specified by the `api.value.type` %define variable. + ** New features *** Option -H, --header and directive %header - The option -H/--header supersedes the option --defines, and the directive - %header supersedes %defines. Both --defines and %defines are, of course, - maintained for backward compatibility. + The option `-H`/`--header` supersedes the option `--defines`, and the + directive %header supersedes %defines. Both `--defines` and `%defines` + are, of course, maintained for backward compatibility. *** Option --html Since version 2.4 Bison can be used to generate HTML reports. However it - was a two-step process: first bison must be invoked with option --xml, and - then xsltproc must be run to the convert the XML reports into HTML. + was a two-step process: first bison must be invoked with option `--xml`, + and then xsltproc must be run to the convert the XML reports into HTML. - The new option --html combines these steps. The xsltproc program must be - available. + The new option `--html` combines these steps. The xsltproc program must + be available. *** A C++ native GLR parser @@ -51,8 +56,8 @@ GNU Bison NEWS *** Lookahead correction in Java - The Java skeleton (lalr1.java) now supports LAC, via the %define variable - parse.lac. + The Java skeleton (lalr1.java) now supports LAC, via the `parse.lac` + %define variable. * Noteworthy changes in release 3.7.4 (2020-11-14) [stable] @@ -795,7 +800,7 @@ GNU Bison NEWS Also, because string aliases need not be defined, typos such as "baz" instead of "bar" will be not reported. - The option -Wdangling-alias catches these situations. On + The option `-Wdangling-alias` catches these situations. On %token BAR "bar" %type foo "foo" @@ -811,7 +816,7 @@ GNU Bison NEWS | foo: "baz" {} | ^~~~~ - The -Wall option does not (yet?) include -Wdangling-alias. + The `-Wall` option does not (yet?) include `-Wdangling-alias`. *** Better POSIX Yacc compatibility diagnostics diff --git a/data/skeletons/c++.m4 b/data/skeletons/c++.m4 index b458af3f..2ae34baf 100644 --- a/data/skeletons/c++.m4 +++ b/data/skeletons/c++.m4 @@ -206,16 +206,16 @@ m4_define([b4_declare_symbol_enum], # b4_value_type_declare # --------------------- -# Declare semantic_type. +# Declare value_type. m4_define([b4_value_type_declare], [b4_value_type_setup[]dnl [ /// Symbol semantic values. ]m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), [code], -[[ typedef ]b4_percent_define_get([[api.value.type]])[ semantic_type;]], +[[ typedef ]b4_percent_define_get([[api.value.type]])[ value_type;]], [m4_bmatch(b4_percent_define_get([[api.value.type]]), [union\|union-directive], -[[ union semantic_type +[[ union value_type { ]b4_user_union_members[ };]])])dnl @@ -230,8 +230,10 @@ m4_define([b4_public_types_declare], [[#ifndef ]b4_api_PREFIX[STYPE ]b4_value_type_declare[ #else - typedef ]b4_api_PREFIX[STYPE semantic_type; -#endif]b4_locations_if([ + typedef ]b4_api_PREFIX[STYPE value_type; +#endif + /// Backward compatibility (Bison 3.8). + typedef value_type semantic_type;]b4_locations_if([ /// Symbol locations. typedef b4_percent_define_get([[api.location.type]], [[location]]) location_type;])[ @@ -329,7 +331,7 @@ m4_define([b4_symbol_type_define], /// Constructor for symbols with semantic value. basic_symbol (typename Base::kind_type t, - YY_RVREF (semantic_type) v]b4_locations_if([, + YY_RVREF (value_type) v]b4_locations_if([, YY_RVREF (location_type) l])[); ]])[ /// Destroy the symbol. @@ -390,7 +392,7 @@ m4_define([b4_symbol_type_define], void move (basic_symbol& s); /// The semantic value. - semantic_type value;]b4_locations_if([ + value_type value;]b4_locations_if([ /// The location. location_type location;])[ @@ -487,7 +489,7 @@ m4_define([b4_public_types_define], template ]b4_parser_class[::basic_symbol::basic_symbol (]b4_join( [typename Base::kind_type t], - [YY_RVREF (semantic_type) v], + [YY_RVREF (value_type) v], b4_locations_if([YY_RVREF (location_type) l]))[) : Base (t) , value (]b4_variant_if([], [YY_MOVE (v)])[)]b4_locations_if([ diff --git a/data/skeletons/glr.cc b/data/skeletons/glr.cc index 2dcff7e5..1f850baa 100644 --- a/data/skeletons/glr.cc +++ b/data/skeletons/glr.cc @@ -78,7 +78,7 @@ m4_define([b4_yy_symbol_print_define], static void yy_symbol_print (FILE *, ]b4_namespace_ref::b4_parser_class[::symbol_kind_type yytoken, - const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep]b4_locations_if([[, + const ]b4_namespace_ref::b4_parser_class[::value_type *yyvaluep]b4_locations_if([[, const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp]])[]b4_user_formals[) { ]b4_parse_param_use[]dnl @@ -154,7 +154,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl void ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind, - const semantic_type* yyvaluep]b4_locations_if([[, + const value_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) const {]b4_locations_if([[ YYUSE (yylocationp);]])[ @@ -168,7 +168,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl void ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind, - const semantic_type* yyvaluep]b4_locations_if([[, + const value_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) const { *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm") @@ -247,7 +247,7 @@ m4_define([b4_glr_cc_setup], #define ]b4_symbol(error, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(error, [id])[ #ifndef ]b4_api_PREFIX[STYPE -# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type +# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::value_type #endif #ifndef ]b4_api_PREFIX[LTYPE # define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type @@ -355,14 +355,14 @@ b4_percent_code_get([[requires]])[ /// \param yyvaluep Its semantic value.]b4_locations_if([[ /// \param yylocationp Its location.]])[ virtual void yy_symbol_value_print_ (symbol_kind_type yykind, - const semantic_type* yyvaluep]b4_locations_if([[, + const value_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) const; /// \brief Report a symbol on the debug stream. /// \param yykind The symbol kind. /// \param yyvaluep Its semantic value.]b4_locations_if([[ /// \param yylocationp Its location.]])[ virtual void yy_symbol_print_ (symbol_kind_type yykind, - const semantic_type* yyvaluep]b4_locations_if([[, + const value_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) const; private: /// Debug stream. diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc index af68077e..61df35b9 100644 --- a/data/skeletons/glr2.cc +++ b/data/skeletons/glr2.cc @@ -250,14 +250,14 @@ const std::ptrdiff_t strong_index_alias::INVALID_INDEX = /// \param yyvaluep Its semantic value.]b4_locations_if([[ /// \param yylocationp Its location.]])[ virtual void yy_symbol_value_print_ (symbol_kind_type yykind, - const semantic_type* yyvaluep]b4_locations_if([[, + const value_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) const; /// \brief Report a symbol on the debug stream. /// \param yykind The symbol kind. /// \param yyvaluep Its semantic value.]b4_locations_if([[ /// \param yylocationp Its location.]])[ virtual void yy_symbol_print_ (symbol_kind_type yykind, - const semantic_type* yyvaluep]b4_locations_if([[, + const value_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) const; private: /// Debug stream. @@ -285,7 +285,7 @@ const std::ptrdiff_t strong_index_alias::INVALID_INDEX = /// If null, print nothing. /// \param yykind The symbol kind. void yy_destroy_ (const char* yymsg, symbol_kind_type yykind, - const semantic_type* yyvaluep]b4_locations_if([[, + const value_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[); ]b4_parse_param_vars[ @@ -434,7 +434,7 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C], [b4_shared_declarations])[ #ifndef ]b4_api_PREFIX[STYPE -# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type +# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::value_type #endif #ifndef ]b4_api_PREFIX[LTYPE # define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type @@ -763,7 +763,7 @@ yyrhsLength (rule_num yyrule); class glr_state { public: - typedef ]b4_namespace_ref[::]b4_parser_class[::semantic_type value_type;]b4_locations_if([[ + typedef ]b4_namespace_ref[::]b4_parser_class[::value_type value_type;]b4_locations_if([[ typedef ]b4_namespace_ref[::]b4_parser_class[::location_type location_type;]])[ glr_state () @@ -3238,7 +3238,7 @@ b4_dollar_popdef])[]dnl void ]b4_parser_class[::yy_destroy_ (const char* yymsg, symbol_kind_type yykind, - const semantic_type* yyvaluep]b4_locations_if([[, + const value_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) { YYUSE (yyvaluep);]b4_locations_if([[ @@ -3261,7 +3261,7 @@ b4_dollar_popdef])[]dnl void ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind, - const semantic_type* yyvaluep]b4_locations_if([[, + const value_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) const {]b4_locations_if([[ YYUSE (yylocationp);]])[ @@ -3274,7 +3274,7 @@ b4_dollar_popdef])[]dnl void ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind, - const semantic_type* yyvaluep]b4_locations_if([[, + const value_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) const { *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm") diff --git a/data/skeletons/variant.hh b/data/skeletons/variant.hh index 13c07674..187327cb 100644 --- a/data/skeletons/variant.hh +++ b/data/skeletons/variant.hh @@ -94,28 +94,28 @@ m4_define([b4_variant_includes], # b4_value_type_declare # --------------------- -# Define semantic_type. +# Define value_type. m4_define([b4_value_type_declare], [[ /// A buffer to store and retrieve objects. /// /// Sort of a variant, but does not keep track of the nature /// of the stored data, since that knowledge is available /// via the current parser state. - class semantic_type + class value_type { public: /// Type of *this. - typedef semantic_type self_type; + typedef value_type self_type; /// Empty construction. - semantic_type () YY_NOEXCEPT + value_type () YY_NOEXCEPT : yyraw_ ()]b4_parse_assert_if([ , yytypeid_ (YY_NULLPTR)])[ {} /// Construct and fill. template - semantic_type (YY_RVREF (T) t)]b4_parse_assert_if([ + value_type (YY_RVREF (T) t)]b4_parse_assert_if([ : yytypeid_ (&typeid (T))])[ {]b4_parse_assert_if([[ ]b4_assert[ (sizeof (T) <= size);]])[ @@ -124,13 +124,13 @@ m4_define([b4_value_type_declare], #if 201103L <= YY_CPLUSPLUS /// Non copyable. - semantic_type (const self_type&) = delete; + value_type (const self_type&) = delete; /// Non copyable. self_type& operator= (const self_type&) = delete; #endif /// Destruction, allowed only if empty. - ~semantic_type () YY_NOEXCEPT + ~value_type () YY_NOEXCEPT {]b4_parse_assert_if([ ]b4_assert[ (!yytypeid_); ])[} @@ -274,7 +274,7 @@ m4_define([b4_value_type_declare], private: #if YY_CPLUSPLUS < 201103L /// Non copyable. - semantic_type (const self_type&); + value_type (const self_type&); /// Non copyable. self_type& operator= (const self_type&); #endif diff --git a/doc/bison.texi b/doc/bison.texi index a272b387..f6ac5f86 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -3864,7 +3864,7 @@ type, define the @code{%define} variable @code{api.value.type} like this: or @example -%define api.value.type @{struct semantic_type@} +%define api.value.type @{struct semantic_value_type@} @end example The value of @code{api.value.type} should be a type name that does not @@ -6259,7 +6259,7 @@ For example, if you specify: Bison uses @code{foo::bar} verbatim in references such as: @example -foo::bar::parser::semantic_type +foo::bar::parser::value_type @end example However, to open a namespace, Bison removes any leading @code{::} and then @@ -12302,7 +12302,7 @@ typedef token::token_kind_type token_kind_type; @end example @end defcv -@defcv {Type} {parser} {semantic_type} +@defcv {Type} {parser} {value_type} The types for semantic values. @xref{C++ Semantic Values}. @end defcv @@ -12393,7 +12393,7 @@ features in C++. @item The type @code{YYSTYPE} is defined but its use is discouraged: rather you should refer to the parser's encapsulated type -@code{yy::parser::semantic_type}. +@code{yy::parser::value_type}. @item Non POD (Plain Old Data) types cannot be used. C++98 forbids any instance of classes with constructors in unions: only @emph{pointers} to such objects @@ -12453,14 +12453,14 @@ of alternative types such as @samp{$2} or @samp{$$}, even in midrule actions. It is mandatory to use typed midrule actions (@pxref{Typed Midrule Actions}). -@deftypemethod {semantic_type} {T&} {emplace} () -@deftypemethodx {semantic_type} {T&} {emplace} (@code{const T&} @var{t}) +@deftypemethod {value_type} {T&} {emplace} () +@deftypemethodx {value_type} {T&} {emplace} (@code{const T&} @var{t}) Available in C++98/C++03 only. Default construct/copy-construct from @var{t}. Return a reference to where the actual value may be stored. Requires that the variant was not initialized yet. @end deftypemethod -@deftypemethod {semantic_type} {T&} {emplace} (@code{U&&...} @var{u}) +@deftypemethod {value_type} {T&} {emplace} (@code{U&&...} @var{u}) Available in C++11 and later only. Build a variant of type @code{T} from the variadic forwarding references @var{u...}. @end deftypemethod @@ -12872,8 +12872,8 @@ depends whether you use unions, or variants. The generated parser expects @code{yylex} to have the following prototype. -@deftypefun {int} yylex (@code{semantic_type*} @var{yylval}, @code{location_type*} @var{yylloc}, @var{type1} @var{arg1}, @dots{}) -@deftypefunx {int} yylex (@code{semantic_type*} @var{yylval}, @var{type1} @var{arg1}, @dots{}) +@deftypefun {int} yylex (@code{value_type*} @var{yylval}, @code{location_type*} @var{yylloc}, @var{type1} @var{arg1}, @dots{}) +@deftypefunx {int} yylex (@code{value_type*} @var{yylval}, @var{type1} @var{arg1}, @dots{}) Return the next token. Its kind is the return value, its semantic value and location (if enabled) being @var{yylval} and @var{yylloc}. Invocations of @samp{%lex-param @{@var{type1} @var{arg1}@}} yield additional arguments. diff --git a/examples/c++/glr/c++-types.yy b/examples/c++/glr/c++-types.yy index 1fc26166..ce6ae4f1 100644 --- a/examples/c++/glr/c++-types.yy +++ b/examples/c++/glr/c++-types.yy @@ -46,11 +46,11 @@ # define nullptr 0 #endif - static yy::parser::semantic_type - stmtMerge (const yy::parser::semantic_type& x0, const yy::parser::semantic_type& x1); + static yy::parser::value_type + stmtMerge (const yy::parser::value_type& x0, const yy::parser::value_type& x1); static int - yylex (yy::parser::semantic_type* val, yy::parser::location_type* loc); + yylex (yy::parser::value_type* val, yy::parser::location_type* loc); } %expect-rr 1 @@ -103,7 +103,7 @@ yy::parser::error (const location_type& l, const std::string& m) } static int -yylex (yy::parser::semantic_type* lvalp, yy::parser::location_type* llocp) +yylex (yy::parser::value_type* lvalp, yy::parser::location_type* llocp) { static int lineNum = 1; static int colNum = 0; @@ -162,8 +162,8 @@ yylex (yy::parser::semantic_type* lvalp, yy::parser::location_type* llocp) } } -static yy::parser::semantic_type -stmtMerge (const yy::parser::semantic_type& x0, const yy::parser::semantic_type& x1) +static yy::parser::value_type +stmtMerge (const yy::parser::value_type& x0, const yy::parser::value_type& x1) { return Nterm ("", x0, x1); }