diff options
author | thegeorg <thegeorg@yandex-team.com> | 2024-06-29 11:45:54 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2024-06-29 11:54:41 +0300 |
commit | 9158d9115725ca7f4ada745ec55eddd5747bc61e (patch) | |
tree | f262cd6d7a98bb367943a4918b6963a7800f3937 /contrib/tools/bison/data | |
parent | 632b3cedb8e12fbbb0bcd1bdbf7ec5686725b7e9 (diff) | |
download | ydb-9158d9115725ca7f4ada745ec55eddd5747bc61e.tar.gz |
Update contrib/tools/bison to 3.2.4
78e59a97f3fde03511ddb9969cd1daabbaf998bd
Diffstat (limited to 'contrib/tools/bison/data')
-rw-r--r-- | contrib/tools/bison/data/bison.m4 | 145 | ||||
-rw-r--r-- | contrib/tools/bison/data/c++.m4 | 149 | ||||
-rw-r--r-- | contrib/tools/bison/data/c-like.m4 | 12 | ||||
-rw-r--r-- | contrib/tools/bison/data/c.m4 | 94 | ||||
-rw-r--r-- | contrib/tools/bison/data/glr.cc | 45 | ||||
-rw-r--r-- | contrib/tools/bison/data/lalr1.cc | 153 | ||||
-rw-r--r-- | contrib/tools/bison/data/location.cc | 109 | ||||
-rw-r--r-- | contrib/tools/bison/data/stack.hh | 90 | ||||
-rw-r--r-- | contrib/tools/bison/data/variant.hh | 145 | ||||
-rw-r--r-- | contrib/tools/bison/data/yacc.c | 91 |
10 files changed, 671 insertions, 362 deletions
diff --git a/contrib/tools/bison/data/bison.m4 b/contrib/tools/bison/data/bison.m4 index 80e025c9b4..d2db2c86ee 100644 --- a/contrib/tools/bison/data/bison.m4 +++ b/contrib/tools/bison/data/bison.m4 @@ -22,12 +22,17 @@ ## Identification. ## ## ---------------- ## +# b4_generated_by +# --------------- +m4_define([b4_generated_by], +[b4_comment([A Bison parser, made by GNU Bison b4_version.]) +]) + # b4_copyright(TITLE, [YEARS]) # ---------------------------- # If YEARS are not defined, use b4_copyright_years. m4_define([b4_copyright], -[b4_comment([A Bison parser, made by GNU Bison b4_version.]) - +[b4_generated_by b4_comment([$1 ]m4_dquote(m4_text_wrap([Copyright (C) @@ -58,26 +63,49 @@ Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in -version 2.2 of Bison.])]) +version 2.2 of Bison.]) +]) + + +# b4_disclaimer +# ------------- +# Issue a warning about private implementation details. +m4_define([b4_disclaimer], +[b4_comment([Undocumented macros, especially those whose name start with YY_, +are private implementation details. Do not rely on them.]) +]) + + + +# b4_required_version_if(VERSION, IF_NEWER, IF_OLDER) +# --------------------------------------------------- +# If the version %require'd by the user is VERSION (or newer) expand +# IF_NEWER, otherwise IF_OLDER. VERSION should be an integer, e.g., +# 302 for 3.2. +m4_define([b4_required_version_if], +[m4_if(m4_eval($1 <= b4_required_version), + [1], [$2], [$3])]) ## -------- ## ## Output. ## ## -------- ## -# b4_output_begin(FILE) -# --------------------- +# b4_output_begin(FILE1, FILE2) +# ----------------------------- # Enable output, i.e., send to diversion 0, expand after "#", and # generate the tag to output into FILE. Must be followed by EOL. +# FILE is FILE1 concatenated to FILE2. FILE2 can be empty, or be +# absolute: do the right thing. m4_define([b4_output_begin], [m4_changecom() m4_divert_push(0)dnl -@output(m4_unquote([$1])@)@dnl +@output(m4_unquote([$1])@,m4_unquote([$2])@)@dnl ]) -# b4_output_end() -# --------------- +# b4_output_end +# ------------- # Output nothing, restore # as comment character (no expansions after #). m4_define([b4_output_end], [m4_divert_pop(0) @@ -389,11 +417,11 @@ b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. # # The following macros provide access to these values. -# b4_symbol_(NUM, FIELD) +# _b4_symbol(NUM, FIELD) # ---------------------- # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if # undefined. -m4_define([b4_symbol_], +m4_define([_b4_symbol], [m4_indir([b4_symbol($1, $2)])]) @@ -404,8 +432,8 @@ m4_define([b4_symbol_], m4_define([b4_symbol], [m4_case([$2], [id], [m4_do([b4_percent_define_get([api.token.prefix])], - [b4_symbol_([$1], [id])])], - [b4_symbol_($@)])]) + [_b4_symbol([$1], [id])])], + [_b4_symbol($@)])]) # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE) @@ -443,7 +471,7 @@ m4_define([b4_symbol_action], b4_symbol_if([$1], [has_type], [m4_dquote(b4_symbol([$1], [type]))]), [(*yylocationp)])dnl - b4_symbol_case_([$1])[]dnl + _b4_symbol_case([$1])[]dnl b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])]) b4_symbol([$1], [$2]) b4_syncline([@oline@], [@ofile@]) @@ -478,10 +506,10 @@ m4_ifval(m4_defn([b4_actions_]), m4_popdef([b4_actions_])dnl ]) -# b4_symbol_case_(SYMBOL-NUM) +# _b4_symbol_case(SYMBOL-NUM) # --------------------------- # Issue a "case NUM" for SYMBOL-NUM. -m4_define([b4_symbol_case_], +m4_define([_b4_symbol_case], [case b4_symbol([$1], [number]): b4_symbol_tag_comment([$1])]) ]) @@ -536,16 +564,16 @@ m4_define([b4_token_format], ## Types. ## ## ------- ## -# b4_type_action_(NUMS) +# _b4_type_action(NUMS) # --------------------- # Run actions for the symbol NUMS that all have the same type-name. # Skip NUMS that have no type-name. # # To specify the action to run, define b4_dollar_dollar(NUMBER, # TAG, TYPE). -m4_define([b4_type_action_], +m4_define([_b4_type_action], [b4_symbol_if([$1], [has_type], -[m4_map([ b4_symbol_case_], [$@])[]dnl +[m4_map([ _b4_symbol_case], [$@])[]dnl b4_dollar_dollar([b4_symbol([$1], [number])], [b4_symbol([$1], [tag])], [b4_symbol([$1], [type])]); @@ -601,13 +629,15 @@ m4_define([b4_user_code], b4_syncline([@oline@], [@ofile@])]) -# b4_define_user_code(MACRO) -# -------------------------- -# From b4_MACRO, build b4_user_MACRO that includes the synclines. +# b4_define_user_code(MACRO, COMMENT) +# ----------------------------------- +# From b4_MACRO, if defined, build b4_user_MACRO that includes the synclines. m4_define([b4_define_user_code], [m4_define([b4_user_$1], -[b4_user_code([b4_$1])])]) - + [m4_ifdef([b4_$1], + [m4_ifval([$2], + [b4_comment([$2]) +])b4_user_code([b4_$1])])])]) # b4_user_actions # b4_user_initial_action @@ -617,9 +647,9 @@ m4_define([b4_define_user_code], # ---------------------- # Macros that issue user code, ending with synclines. b4_define_user_code([actions]) -b4_define_user_code([initial_action]) -b4_define_user_code([post_prologue]) -b4_define_user_code([pre_prologue]) +b4_define_user_code([initial_action], [User initialization code.]) +b4_define_user_code([post_prologue], [Second part of user prologue.]) +b4_define_user_code([pre_prologue], [First part of user prologue.]) b4_define_user_code([union_members]) @@ -701,7 +731,7 @@ m4_define([b4_percent_define_use], # b4_percent_define_get([[foo]]) m4_define([b4_percent_define_get], [b4_percent_define_use([$1])dnl -b4_percent_define_ifdef_([$1], +_b4_percent_define_ifdef([$1], [m4_indir([b4_percent_define(]$1[)])], [$2])]) @@ -710,7 +740,7 @@ b4_percent_define_ifdef_([$1], # Mimic muscle_percent_define_get_loc in ../src/muscle-tab.h exactly. That is, # if the %define variable VARIABLE is undefined, complain fatally since that's # a Bison or skeleton error. Otherwise, return its definition location in a -# form approriate for the first two arguments of b4_warn_at, b4_complain_at, or +# form appropriate for the first two arguments of b4_warn_at, b4_complain_at, or # b4_fatal_at. 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. # @@ -755,15 +785,15 @@ m4_define([b4_percent_define_get_syncline], [m4_indir([b4_percent_define_syncline(]$1[)])], [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) -# b4_percent_define_ifdef_(VARIABLE, IF-TRUE, [IF-FALSE]) +# _b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE]) # ------------------------------------------------------ # If the %define variable VARIABLE is defined, expand IF-TRUE, else expand # IF-FALSE. Don't record usage of VARIABLE. # # For example: # -# b4_percent_define_ifdef_([[foo]], [[it's defined]], [[it's undefined]]) -m4_define([b4_percent_define_ifdef_], +# _b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]]) +m4_define([_b4_percent_define_ifdef], [m4_ifdef([b4_percent_define(]$1[)], [$2], [$3])]) @@ -779,11 +809,44 @@ m4_define([b4_percent_define_ifdef_], # # b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]]) m4_define([b4_percent_define_ifdef], -[b4_percent_define_ifdef_([$1], +[_b4_percent_define_ifdef([$1], [b4_percent_define_use([$1])$2], [$3])]) +# b4_percent_define_check_file_complain(VARIABLE) +# ----------------------------------------------- +# Warn about %define variable VARIABLE having an incorrect +# value. +m4_define([b4_percent_define_check_file_complain], +[b4_complain_at(b4_percent_define_get_loc([$1]), + [[%%define variable '%s' requires 'none' or '"..."' values]], + [$1])]) + + +# b4_percent_define_check_file(MACRO, VARIABLE, DEFAULT) +# ------------------------------------------------------ +# If the %define variable VARIABLE: +# - is undefined, then if DEFAULT is non-empty, define MACRO to DEFAULT +# - is a string, define MACRO to its value +# - is the keyword 'none', do nothing +# - otherwise, warn about the incorrect value. +m4_define([b4_percent_define_check_file], +[b4_percent_define_ifdef([$2], + [m4_case(b4_percent_define_get_kind([$2]), + [string], + [m4_define([$1], b4_percent_define_get([$2]))], + [keyword], + [m4_if(b4_percent_define_get([$2]), [none], [], + [b4_percent_define_check_file_complain([$2])])], + [b4_percent_define_check_file_complain([$2])]) + ], + [m4_ifval([$3], + [m4_define([$1], [$3])])]) +]) + + + ## --------- ## ## Options. ## ## --------- ## @@ -824,7 +887,7 @@ m4_define([b4_percent_define_flag_if], # # b4_percent_define_default([[foo]], [[default value]]) m4_define([b4_percent_define_default], -[b4_percent_define_ifdef_([$1], [], +[_b4_percent_define_ifdef([$1], [], [m4_define([b4_percent_define(]$1[)], [$2])dnl m4_define([b4_percent_define_kind(]$1[)], [m4_default([$3], [keyword])])dnl @@ -839,26 +902,26 @@ m4_define([b4_percent_define_default], # Define b4_NAME_if that executes its $1 or $2 depending whether # VARIABLE was %defined. The characters '.' and `-' in VARIABLE are mapped # to '_'. -m4_define([b4_percent_define_if_define_], +m4_define([_b4_percent_define_if_define], [m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]), [b4_percent_define_flag_if(m4_default([$2], [$1]), [$3], [$4])])]) m4_define([b4_percent_define_if_define], [b4_percent_define_default([m4_default([$2], [$1])], [[false]]) -b4_percent_define_if_define_([$1], [$2], $[1], $[2])]) +_b4_percent_define_if_define([$1], [$2], $[1], $[2])]) # b4_percent_define_check_kind(VARIABLE, KIND, [DIAGNOSTIC = complain]) # --------------------------------------------------------------------- m4_define([b4_percent_define_check_kind], -[b4_percent_define_ifdef_([$1], +[_b4_percent_define_ifdef([$1], [m4_if(b4_percent_define_get_kind([$1]), [$2], [], [b4_error([m4_default([$3], [complain])], b4_percent_define_get_loc([$1]), [m4_case([$2], - [code], [[%%define variable '%s' requires '{...}' values]], + [code], [[%%define variable '%s' requires '{...}' values]], [keyword], [[%%define variable '%s' requires keyword values]], - [string], [[%%define variable '%s' requires '"..."' values]])], + [string], [[%%define variable '%s' requires '"..."' values]])], [$1])])])dnl ]) @@ -884,7 +947,7 @@ m4_define([b4_percent_define_check_values], [_b4_percent_define_check_values(b4_sublist)])]) m4_define([_b4_percent_define_check_values], -[b4_percent_define_ifdef_([$1], +[_b4_percent_define_ifdef([$1], [b4_percent_define_check_kind(]$1[, [keyword], [deprecated])dnl m4_pushdef([b4_good_value], [0])dnl m4_if($#, 1, [], @@ -946,7 +1009,7 @@ m4_define([b4_percent_code_ifdef], # b4_parse_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT]) # b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT]) # b4_token_ctor_if([IF-YYLEX-RETURNS-A-TOKEN], [IF-NOT]) -# ---------------------------------------------- +# ---------------------------------------------------------- b4_percent_define_if_define([token_ctor], [api.token.constructor]) b4_percent_define_if_define([locations]) # Whether locations are tracked. b4_percent_define_if_define([parse.assert]) @@ -1011,8 +1074,6 @@ b4_check_user_names_wrap([[code]], [[qualifier]]) ## ---------------- ## # m4_define_default([b4_lex_param], []) dnl breaks other skeletons -m4_define_default([b4_pre_prologue], []) -m4_define_default([b4_post_prologue], []) m4_define_default([b4_epilogue], []) m4_define_default([b4_parse_param], []) diff --git a/contrib/tools/bison/data/c++.m4 b/contrib/tools/bison/data/c++.m4 index 396d86132d..9783293bfe 100644 --- a/contrib/tools/bison/data/c++.m4 +++ b/contrib/tools/bison/data/c++.m4 @@ -24,11 +24,20 @@ b4_percent_define_ifdef([[api.value.union.name]], m4_include(b4_pkgdatadir/[c.m4]) +b4_percent_define_check_kind([api.namespace], [code], [deprecated]) +b4_percent_define_check_kind([parser_class_name], [code], [deprecated]) + + +## ----- ## +## C++. ## +## ----- ## + # b4_comment(TEXT, [PREFIX]) # -------------------------- # Put TEXT in comment. Prefix all the output lines with PREFIX. m4_define([b4_comment], -[b4_comment_([$1], [$2// ], [$2// ])]) +[_b4_comment([$1], [$2// ], [$2// ])]) + # b4_inline(hh|cc) # ---------------- @@ -40,12 +49,32 @@ m4_define([b4_inline], ]], [m4_fatal([$0: invalid argument: $1])])]) -## -------- ## -## Checks. ## -## -------- ## -b4_percent_define_check_kind([api.namespace], [code], [deprecated]) -b4_percent_define_check_kind([parser_class_name], [code], [deprecated]) +# b4_cxx_portability +# ------------------ +m4_define([b4_cxx_portability], +[#if defined __cplusplus +# define YY_CPLUSPLUS __cplusplus +#else +# define YY_CPLUSPLUS 199711L +#endif + +// Support move semantics when possible. +#if 201103L <= YY_CPLUSPLUS +# define YY_MOVE std::move +# define YY_MOVE_OR_COPY move +# define YY_MOVE_REF(Type) Type&& +# define YY_RVREF(Type) Type&& +# define YY_COPY(Type) Type +#else +# define YY_MOVE +# define YY_MOVE_OR_COPY copy +# define YY_MOVE_REF(Type) Type& +# define YY_RVREF(Type) const Type& +# define YY_COPY(Type) const Type& +#endif[]dnl +]) + ## ---------------- ## ## Default values. ## @@ -88,7 +117,7 @@ m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [], [[namespace reference is empty]])]) # Instead of assuming the C++ compiler will do it, Bison should reject any -# invalid b4_namepsace_ref that would be converted to a valid +# invalid b4_namespace_ref that would be converted to a valid # b4_namespace_open. The problem is that Bison doesn't always output # b4_namespace_ref to uncommented code but should reserve the ability to do so # in future releases without risking breaking any existing user grammars. @@ -192,11 +221,18 @@ m4_define([b4_public_types_declare], /// Internal symbol number for tokens (subsumed by symbol_number_type). typedef ]b4_int_type_for([b4_translate])[ token_number_type; +]]) + - /// A complete symbol. +# b4_symbol_type_declare +# ---------------------- +# Define symbol_type, the external type for symbols used for symbol +# constructors. +m4_define([b4_symbol_type_declare], +[[ /// A complete symbol. /// /// Expects its Base type to provide access to the symbol type - /// via type_get(). + /// via type_get (). /// /// Provide access to semantic value]b4_locations_if([ and location])[. template <typename Base> @@ -208,19 +244,25 @@ m4_define([b4_public_types_declare], /// Default constructor. basic_symbol (); +#if 201103L <= YY_CPLUSPLUS + /// Move constructor. + basic_symbol (basic_symbol&& that); +#endif + /// Copy constructor. - basic_symbol (const basic_symbol& other); + 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_declare])], [[ /// Constructor for valueless symbols. basic_symbol (typename Base::kind_type t]b4_locations_if([, - const location_type& l])[);]])[ + YY_MOVE_REF (location_type) l])[); /// Constructor for symbols with semantic value. basic_symbol (typename Base::kind_type t, - const semantic_type& v]b4_locations_if([, - const location_type& l])[); + YY_RVREF (semantic_type) v]b4_locations_if([, + YY_RVREF (location_type) l])[);]])[ /// Destroy the symbol. ~basic_symbol (); @@ -241,8 +283,10 @@ m4_define([b4_public_types_declare], location_type location;])[ private: +#if YY_CPLUSPLUS < 201103L /// Assignment operator. - basic_symbol& operator= (const basic_symbol& other); + basic_symbol& operator= (const basic_symbol& that); +#endif }; /// Type access provider for token (enum) based symbols. @@ -251,8 +295,13 @@ m4_define([b4_public_types_declare], /// Default constructor. by_type (); +#if 201103L <= YY_CPLUSPLUS + /// Move constructor. + by_type (by_type&& that); +#endif + /// Copy constructor. - by_type (const by_type& other); + by_type (const by_type& that); /// The symbol type as needed by the constructor. typedef token_type kind_type; @@ -281,8 +330,7 @@ m4_define([b4_public_types_declare], /// "External" symbols: returned by the scanner. typedef basic_symbol<by_type> symbol_type; - -]b4_symbol_constructor_declare]) +]]) # b4_public_types_define(hh|cc) @@ -301,27 +349,27 @@ m4_define([b4_public_types_define], , location ()])[ {} +#if 201103L <= YY_CPLUSPLUS template <typename Base> - ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (const basic_symbol& other) - : Base (other) - , value (]b4_variant_if([], [other.value])[)]b4_locations_if([ - , location (other.location)])[ + ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (basic_symbol&& that) + : Base (std::move (that)) + , value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([ + , location (std::move (that.location))])[ {]b4_variant_if([ - b4_symbol_variant([other.type_get ()], [value], [copy], - [other.value])])[ + b4_symbol_variant([this->type_get ()], [value], [move], + [std::move (that.value)])])[ } +#endif template <typename Base> - ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join( - [typename Base::kind_type t], - [const semantic_type& v], - b4_locations_if([const location_type& l]))[) - : Base (t) - , value (]b4_variant_if([], [v])[)]b4_locations_if([ - , location (l)])[ - {]b4_variant_if([[ - (void) v; - ]b4_symbol_variant([this->type_get ()], [value], [copy], [v])])[} + ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (const basic_symbol& that) + : Base (that) + , value (]b4_variant_if([], [that.value]))b4_locations_if([ + , location (that.location)])[ + {]b4_variant_if([ + b4_symbol_variant([this->type_get ()], [value], [copy], + [that.value])])[ + } ]b4_variant_if([[ // Implementation of basic_symbol constructor for each type. @@ -330,11 +378,23 @@ m4_define([b4_public_types_define], template <typename Base> ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join( [typename Base::kind_type t], - b4_locations_if([const location_type& l]))[) + b4_locations_if([YY_MOVE_REF (location_type) l]))[) : Base (t) , value ()]b4_locations_if([ , location (l)])[ - {}]])[ + {} + + template <typename Base> + ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join( + [typename Base::kind_type t], + [YY_RVREF (semantic_type) v], + b4_locations_if([YY_RVREF (location_type) l]))[) + : Base (t) + , value (]b4_variant_if([], [YY_MOVE (v)])[)]b4_locations_if([ + , location (YY_MOVE (l))])[ + {]b4_variant_if([[ + (void) v; + ]b4_symbol_variant([this->type_get ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[ template <typename Base> ]b4_parser_class_name[::basic_symbol<Base>::~basic_symbol () @@ -375,9 +435,9 @@ m4_define([b4_public_types_define], { super_type::move (s); ]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [move], - [s.value])], - [value = s.value;])[]b4_locations_if([ - location = s.location;])[ + [YY_MOVE (s.value)])], + [value = YY_MOVE (s.value);])[]b4_locations_if([ + location = YY_MOVE (s.location);])[ } // by_type. @@ -385,8 +445,16 @@ m4_define([b4_public_types_define], : type (empty_symbol) {} - ]b4_inline([$1])b4_parser_class_name[::by_type::by_type (const by_type& other) - : type (other.type) +#if 201103L <= YY_CPLUSPLUS + ]b4_inline([$1])b4_parser_class_name[::by_type::by_type (by_type&& that) + : type (that.type) + { + that.clear (); + } +#endif + + ]b4_inline([$1])b4_parser_class_name[::by_type::by_type (const by_type& that) + : type (that.type) {} ]b4_inline([$1])b4_parser_class_name[::by_type::by_type (token_type t) @@ -426,6 +494,7 @@ m4_define([b4_public_types_define], return static_cast<token_type> (yytoken_number_[type]); } ]])[]dnl + b4_symbol_constructor_define]) diff --git a/contrib/tools/bison/data/c-like.m4 b/contrib/tools/bison/data/c-like.m4 index 26bab42eae..4e476ac88e 100644 --- a/contrib/tools/bison/data/c-like.m4 +++ b/contrib/tools/bison/data/c-like.m4 @@ -17,14 +17,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -# b4_comment_(TEXT, OPEN, CONTINUE, END) +# _b4_comment(TEXT, OPEN, CONTINUE, END) # -------------------------------------- # Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. # Avoid adding indentation to the first line, as the indentation comes # from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]). # # Prefix all the output lines with PREFIX. -m4_define([b4_comment_], +m4_define([_b4_comment], [$2[]m4_bpatsubst(m4_expand([[$1]]), [ \(.\)], [ $3\1])$4]) @@ -34,17 +34,17 @@ $3\1])$4]) # -------------------------- # Put TEXT in comment. Prefix all the output lines with PREFIX. m4_define([b4_comment], -[b4_comment_([$1], [$2/* ], [$2 ], [ */])]) +[_b4_comment([$1], [$2/* ], [$2 ], [ */])]) -# b4_dollar_dollar_(VALUE, FIELD, DEFAULT-FIELD) +# _b4_dollar_dollar(VALUE, FIELD, DEFAULT-FIELD) # ---------------------------------------------- # If FIELD (or DEFAULT-FIELD) is non-null, return "VALUE.FIELD", # otherwise just VALUE. Be sure to pass "(VALUE)" is VALUE is a # pointer. -m4_define([b4_dollar_dollar_], +m4_define([_b4_dollar_dollar], [b4_symbol_value([$1], m4_if([$2], [[]], [[$3]], [[$2]]))]) @@ -56,7 +56,7 @@ m4_define([b4_dollar_dollar_], # and b4_at_dollar for LOCATION. m4_define([b4_dollar_pushdef], [m4_pushdef([b4_dollar_dollar], - [b4_dollar_dollar_([$1], m4_dquote($][1), [$2])])dnl + [_b4_dollar_dollar([$1], m4_dquote($][1), [$2])])dnl m4_pushdef([b4_at_dollar], [$3])dnl ]) m4_define([b4_dollar_popdef], diff --git a/contrib/tools/bison/data/c.m4 b/contrib/tools/bison/data/c.m4 index 346b8fd30c..bb19b34826 100644 --- a/contrib/tools/bison/data/c.m4 +++ b/contrib/tools/bison/data/c.m4 @@ -204,11 +204,12 @@ m4_define([b4_table_value_equals], ## Compiler issues. ## ## ----------------- ## -# b4_attribute_define -# ------------------- -# Provide portable compiler "attributes". +# b4_attribute_define([noreturn]) +# ------------------------------- +# Provide portable compiler "attributes". If "noreturn" is passed, define +# _Noreturn. m4_define([b4_attribute_define], -[#ifndef YY_ATTRIBUTE +[[#ifndef YY_ATTRIBUTE # if (defined __GNUC__ \ && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C @@ -226,16 +227,23 @@ m4_define([b4_attribute_define], # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) #endif -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) +]m4_bmatch([$1], [\bnoreturn\b], [[/* The _Noreturn keyword of C11. */ +#if ! defined _Noreturn +# if defined __cplusplus && 201103L <= __cplusplus +# define _Noreturn [[noreturn]] +# elif !(defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__) +# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \ + || 0x5110 <= __SUNPRO_C) +# define _Noreturn __attribute__ ((__noreturn__)) +# elif defined _MSC_VER && 1200 <= _MSC_VER +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn +# endif # endif #endif -/* Suppress unused-variable warnings by "using" E. */ +]])[/* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ # define YYUSE(E) ((void) (E)) #else @@ -260,24 +268,26 @@ m4_define([b4_attribute_define], #ifndef YY_INITIAL_VALUE # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif -]) - - -## ---------## -## Values. ## -## ---------## +]]) # b4_null_define # -------------- # Portability issues: define a YY_NULLPTR appropriate for the current # language (C, C++98, or C++11). +# +# In C++ pre C++11 it is standard practice to use 0 (not NULL) for the +# null pointer. In C, prefer ((void*)0) to avoid having to include stdlib.h. m4_define([b4_null_define], [# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif # else -# define YY_NULLPTR 0 +# define YY_NULLPTR ((void*)0) # endif # endif[]dnl ]) @@ -288,6 +298,12 @@ m4_define([b4_null_define], # Return a null pointer constant. m4_define([b4_null], [YY_NULLPTR]) + + +## ---------## +## Values. ## +## ---------## + # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) # ------------------------------------------------------------- # Define "yy<TABLE-NAME>" whose contents is CONTENT. @@ -361,7 +377,7 @@ m4_define([b4_token_enums_defines], # ---------------------------- # Given a semantic value VAL ($$, $1 etc.), extract its value of type # TYPE if TYPE is given, otherwise just return VAL. The result can be -# used safetly, it is put in parens to avoid nasty precedence issues. +# used safely, it is put in parens to avoid nasty precedence issues. # TYPE is *not* put in braces, provide some if needed. m4_define([b4_symbol_value], [($1[]m4_ifval([$2], [.$2]))]) @@ -498,54 +514,54 @@ 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's value on YYOUTPUT. | -`----------------------------------------*/ +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ ]b4_function_define([yy_symbol_value_print], [static void], - [[FILE *yyoutput], [yyoutput]], + [[FILE *yyo], [yyo]], [[int yytype], [yytype]], [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl m4_ifset([b4_parse_param], [, b4_parse_param]))[ { - FILE *yyo = yyoutput; -]b4_parse_param_use([yyo], [yylocationp])dnl + FILE *yyoutput = yyo; +]b4_parse_param_use([yyoutput], [yylocationp])dnl [ if (!yyvaluep) return;] dnl glr.c does not feature yytoknum. m4_if(b4_skeleton, ["yacc.c"], [[# ifdef YYPRINT if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); + YYPRINT (yyo, yytoknum[yytype], *yyvaluep); # endif ]])dnl b4_symbol_actions([printer])[ } -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ ]b4_function_define([yy_symbol_print], [static void], - [[FILE *yyoutput], [yyoutput]], + [[FILE *yyo], [yyo]], [[int yytype], [yytype]], [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl m4_ifset([b4_parse_param], [, b4_parse_param]))[ { - YYFPRINTF (yyoutput, "%s %s (", + YYFPRINTF (yyo, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); -]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp); - YYFPRINTF (yyoutput, ": "); +]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp); + YYFPRINTF (yyo, ": "); ])dnl -[ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl +[ yy_symbol_value_print (yyo, yytype, yyvaluep]dnl b4_locations_if([, yylocationp])[]b4_user_args[); - YYFPRINTF (yyoutput, ")"); + YYFPRINTF (yyo, ")"); }]dnl ]) @@ -807,11 +823,11 @@ m4_define([b4_yy_location_print_define], YY_ATTRIBUTE_UNUSED ]b4_function_define([yy_location_print_], - [static unsigned], + [static int], [[FILE *yyo], [yyo]], [[YYLTYPE const * const yylocp], [yylocp]])[ { - unsigned res = 0; + int res = 0; int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; if (0 <= yylocp->first_line) { diff --git a/contrib/tools/bison/data/glr.cc b/contrib/tools/bison/data/glr.cc index 2ce14bc090..0401b8492c 100644 --- a/contrib/tools/bison/data/glr.cc +++ b/contrib/tools/bison/data/glr.cc @@ -44,7 +44,7 @@ # filename member). # We require a pure interface. -m4_define([b4_pure_flag], [1]) +m4_define([b4_pure_flag], [1]) m4_include(b4_pkgdatadir/[c++.m4]) b4_bison_locations_if([m4_include(b4_pkgdatadir/[location.cc])]) @@ -167,6 +167,12 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl } int + ]b4_parser_class_name[::operator() () + { + return parse (); + } + + int ]b4_parser_class_name[::parse () { return ::yyparse (*this]b4_user_args[); @@ -184,9 +190,9 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl {]b4_locations_if([[ YYUSE (yylocationp);]])[ YYUSE (yyvaluep); - std::ostream& yyoutput = debug_stream (); - std::ostream& yyo = yyoutput; - YYUSE (yyo); + std::ostream& yyo = debug_stream (); + std::ostream& yyoutput = yyo; + YYUSE (yyoutput); ]b4_symbol_actions([printer])[ } @@ -234,25 +240,28 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl b4_namespace_close ]) -# b4_shared_declarations -# ---------------------- -# Declaration that might either go into the header (if --defines) -# or open coded in the parser body. + +# b4_shared_declarations(hh|cc) +# ----------------------------- +# Declaration that might either go into the header (if --defines, $1 = hh) +# or in the implementation file. m4_define([b4_shared_declarations], [m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl b4_percent_code_get([[requires]])[ - +#include <iostream> #include <stdexcept> #include <string> -#include <iostream>]b4_defines_if([ -b4_bison_locations_if([[#include "location.hh"]])])[ + +]m4_ifdef([b4_location_file], + [[# include ]b4_location_include])[ + +]b4_null_define[ ]b4_YYDEBUG_define[ ]b4_namespace_open[ -]b4_defines_if([], -[b4_bison_locations_if([b4_position_define -b4_location_define])])[ +]b4_bison_locations_if([m4_ifndef([b4_location_file], + [b4_location_define])])[ /// A Bison parser. class ]b4_parser_class_name[ @@ -264,6 +273,10 @@ b4_location_define])])[ ]b4_parser_class_name[ (]b4_parse_param_decl[); virtual ~]b4_parser_class_name[ (); + /// Parse. An alias for parse (). + /// \returns 0 iff parsing succeeded. + int operator() (); + /// Parse. /// \returns 0 iff parsing succeeded. virtual int parse (); @@ -330,13 +343,13 @@ b4_defines_if( [b4_output_begin([b4_spec_defines_file]) b4_copyright([Skeleton interface for Bison GLR parsers in C++], [2002-2015, 2018])[ - // C++ GLR parser skeleton written by Akim Demaille. +]b4_disclaimer[ ]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_shared_declarations[ ]b4_cpp_guard_close([b4_spec_defines_file])[ -]b4_output_end()]) +]b4_output_end]) # Let glr.c (and b4_shared_declarations) believe that the user # arguments include the parser itself. diff --git a/contrib/tools/bison/data/lalr1.cc b/contrib/tools/bison/data/lalr1.cc index 143f3d4b18..b40769d8d6 100644 --- a/contrib/tools/bison/data/lalr1.cc +++ b/contrib/tools/bison/data/lalr1.cc @@ -20,6 +20,7 @@ m4_include(b4_pkgdatadir/[c++.m4]) # api.value.type=variant is valid. m4_define([b4_value_type_setup_variant]) + # b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT) # -------------------------------------------------------------- # Declare "parser::yy<TABLE-NAME>_" whose contents is CONTENT. @@ -83,9 +84,14 @@ m4_define([b4_rhs_state], # -------------------------------------- # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH # symbols on RHS. -m4_define([b4_rhs_value], +m4_define([_b4_rhs_value], [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3])]) +m4_define([b4_rhs_value], +[b4_percent_define_ifdef([api.value.automove], + [YY_MOVE (_b4_rhs_value($@))], + [_b4_rhs_value($@)])]) + # b4_rhs_location(RULE-LENGTH, NUM) # --------------------------------- @@ -106,7 +112,7 @@ b4_dollar_pushdef([yysym.value], b4_symbol_if([$1], [has_type], [m4_dquote(b4_symbol([$1], [type]))]), [yysym.location])dnl - b4_symbol_case_([$1]) + _b4_symbol_case([$1]) b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])]) b4_symbol([$1], [$2]) b4_syncline([@oline@], [@ofile@]) @@ -142,10 +148,11 @@ b4_bison_locations_if([# Backward compatibility. m4_include(b4_pkgdatadir/[stack.hh]) b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])]) + # b4_shared_declarations(hh|cc) # ----------------------------- # Declaration that might either go into the header (if --defines, $1 = hh) -# or open coded in the parser body. +# or in the implementation file. m4_define([b4_shared_declarations], [b4_percent_code_get([[requires]])[ ]b4_parse_assert_if([# include <cassert>])[ @@ -153,21 +160,23 @@ m4_define([b4_shared_declarations], # include <iostream> # include <stdexcept> # include <string> -# include <vector>]b4_defines_if([[ -# include "stack.hh" -]b4_bison_locations_if([[# include "location.hh"]])])[ +# include <vector> + +]b4_cxx_portability[ +]m4_ifdef([b4_location_include], + [[# include ]b4_location_include])[ ]b4_variant_if([b4_variant_includes])[ ]b4_attribute_define[ ]b4_null_define[ + ]b4_YYDEBUG_define[ ]b4_namespace_open[ -]b4_defines_if([], -[b4_stack_define -b4_bison_locations_if([b4_position_define -b4_location_define])])[ +]b4_stack_define[ +]b4_bison_locations_if([m4_ifndef([b4_location_file], + [b4_location_define])])[ ]b4_variant_if([b4_variant_define])[ @@ -176,10 +185,15 @@ b4_location_define])])[ { public: ]b4_public_types_declare[ +]b4_symbol_type_declare[ /// Build a parser object. ]b4_parser_class_name[ (]b4_parse_param_decl[); virtual ~]b4_parser_class_name[ (); + /// Parse. An alias for parse (). + /// \returns 0 iff parsing succeeded. + int operator() (); + /// Parse. /// \returns 0 iff parsing succeeded. virtual int parse (); @@ -206,6 +220,8 @@ b4_location_define])])[ /// Report a syntax error. void error (const syntax_error& err); +]b4_symbol_constructor_declare[ + private: /// This class is not copyable. ]b4_parser_class_name[ (const ]b4_parser_class_name[&); @@ -256,8 +272,9 @@ b4_location_define])])[ /// Print the state stack on the debug stream. virtual void yystack_print_ (); - // Debugging. + /// Debugging level. int yydebug_; + /// Debug stream. std::ostream* yycdebug_; /// \brief Display a symbol type, value and location. @@ -315,12 +332,15 @@ b4_location_define])])[ typedef basic_symbol<by_state> super_type; /// Construct an empty symbol. stack_symbol_type (); - /// Copy construct (for efficiency). - stack_symbol_type (const stack_symbol_type& that); + /// Move or copy construction. + stack_symbol_type (YY_RVREF (stack_symbol_type) that); /// Steal the contents from \a sym to build this. - stack_symbol_type (state_type s, symbol_type& sym); - /// Assignment, needed by push_back. - stack_symbol_type& operator= (const stack_symbol_type& that); + stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) sym); +#if YY_CPLUSPLUS < 201103L + /// Assignment, needed by push_back by some old implementations. + /// Moves the contents of that. + stack_symbol_type& operator= (stack_symbol_type& that); +#endif }; /// Stack type. @@ -332,20 +352,20 @@ b4_location_define])])[ /// Push a new state on the stack. /// \param m a debug message to display /// if null, no trace is output. - /// \param s the symbol + /// \param sym the symbol /// \warning the contents of \a s.value is stolen. - void yypush_ (const char* m, stack_symbol_type& s); + void yypush_ (const char* m, YY_MOVE_REF (stack_symbol_type) sym); /// Push a new look ahead token on the state on the stack. /// \param m a debug message to display /// if null, no trace is output. /// \param s the state /// \param sym the symbol (for its value and location). - /// \warning the contents of \a s.value is stolen. - void yypush_ (const char* m, state_type s, symbol_type& sym); + /// \warning the contents of \a sym.value is stolen. + void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym); - /// Pop \a n symbols the three stacks. - void yypop_ (unsigned n = 1); + /// Pop \a n symbols from the stack. + void yypop_ (int n = 1); /// Constants. enum @@ -377,6 +397,10 @@ b4_location_define])])[ ]b4_percent_code_get([[provides]])[ ]]) +## -------------- ## +## Output files. ## +## -------------- ## + b4_defines_if( [b4_output_begin([b4_spec_defines_file]) b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++]) @@ -388,30 +412,28 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++]) // C++ LALR(1) parser skeleton written by Akim Demaille. +]b4_disclaimer[ ]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_shared_declarations(hh)[ ]b4_cpp_guard_close([b4_spec_defines_file]) -b4_output_end() +b4_output_end ]) -b4_output_begin([b4_parser_file_name]) -b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++]) -b4_percent_code_get([[top]])[]dnl +b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])[ +]b4_disclaimer[ +]b4_percent_code_get([[top]])[]dnl m4_if(b4_prefix, [yy], [], [ // Take the name prefix into account. -#define yylex b4_prefix[]lex])[ +[#]define yylex b4_prefix[]lex])[ -// First part of user declarations. ]b4_user_pre_prologue[ -]b4_null_define[ - ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], [b4_shared_declarations([cc])])[ -// User implementation prologue. ]b4_user_post_prologue[ ]b4_percent_code_get[ @@ -585,34 +607,40 @@ m4_if(b4_prefix, [yy], [], ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type () {} - ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (const stack_symbol_type& that) - : super_type (that.state]b4_locations_if([, that.location])[) - { - ]b4_variant_if([b4_symbol_variant([that.type_get ()], - [value], [copy], [that.value])], - [[value = that.value;]])[ + ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (YY_RVREF (stack_symbol_type) that) + : super_type (YY_MOVE (that.state)]b4_variant_if([], [, YY_MOVE (that.value)])b4_locations_if([, YY_MOVE (that.location)])[) + {]b4_variant_if([ + b4_symbol_variant([that.type_get ()], + [value], [YY_MOVE_OR_COPY], [YY_MOVE (that.value)])])[ +#if 201103L <= YY_CPLUSPLUS + // that is emptied. + that.state = empty_state; +#endif } - ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (state_type s, symbol_type& that) - : super_type (s]b4_variant_if([], [, that.value])[]b4_locations_if([, that.location])[) + ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) that) + : super_type (s]b4_variant_if([], [, YY_MOVE (that.value)])[]b4_locations_if([, YY_MOVE (that.location)])[) {]b4_variant_if([ b4_symbol_variant([that.type_get ()], - [value], [move], [that.value])])[ + [value], [move], [YY_MOVE (that.value)])])[ // that is emptied. that.type = empty_symbol; } +#if YY_CPLUSPLUS < 201103L ]b4_parser_class_name[::stack_symbol_type& - ]b4_parser_class_name[::stack_symbol_type::operator= (const stack_symbol_type& that) + ]b4_parser_class_name[::stack_symbol_type::operator= (stack_symbol_type& that) { state = that.state; ]b4_variant_if([b4_symbol_variant([that.type_get ()], - [value], [copy], [that.value])], + [value], [move], [that.value])], [[value = that.value;]])[]b4_locations_if([ location = that.location;])[ + // that is emptied. + that.state = empty_state; return *this; } - +#endif template <typename Base> void @@ -647,22 +675,26 @@ m4_if(b4_prefix, [yy], [], #endif void - ]b4_parser_class_name[::yypush_ (const char* m, state_type s, symbol_type& sym) + ]b4_parser_class_name[::yypush_ (const char* m, YY_MOVE_REF (stack_symbol_type) sym) { - stack_symbol_type t (s, sym); - yypush_ (m, t); + if (m) + YY_SYMBOL_PRINT (m, sym); + yystack_.push (YY_MOVE (sym)); } void - ]b4_parser_class_name[::yypush_ (const char* m, stack_symbol_type& s) + ]b4_parser_class_name[::yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym) { - if (m) - YY_SYMBOL_PRINT (m, s); - yystack_.push (s); +#if 201103L <= YY_CPLUSPLUS + yypush_ (m, stack_symbol_type (s, std::move (sym))); +#else + stack_symbol_type ss (s, sym); + yypush_ (m, ss); +#endif } void - ]b4_parser_class_name[::yypop_ (unsigned n) + ]b4_parser_class_name[::yypop_ (int n) { yystack_.pop (n); } @@ -717,6 +749,12 @@ m4_if(b4_prefix, [yy], [], } int + ]b4_parser_class_name[::operator() () + { + return parse (); + } + + int ]b4_parser_class_name[::parse () { // State. @@ -745,7 +783,6 @@ m4_if(b4_prefix, [yy], [], ]m4_ifdef([b4_initial_action], [ b4_dollar_pushdef([yyla.value], [], [yyla.location])dnl - // User initialization code. b4_user_initial_action b4_dollar_popdef])[]dnl @@ -754,7 +791,7 @@ b4_dollar_popdef])[]dnl location values to have been already stored, initialize these stacks with a primary value. */ yystack_.clear (); - yypush_ (YY_NULLPTR, 0, yyla); + yypush_ (YY_NULLPTR, 0, YY_MOVE (yyla)); // A new symbol was pushed on the stack. yynewstate: @@ -816,7 +853,7 @@ b4_dollar_popdef])[]dnl --yyerrstatus_; // Shift the lookahead token. - yypush_ ("Shifting", yyn, yyla); + yypush_ ("Shifting", yyn, YY_MOVE (yyla)); goto yynewstate; /*-----------------------------------------------------------. @@ -839,7 +876,7 @@ b4_dollar_popdef])[]dnl /* Variants are always initialized to an empty instance of the correct type. The default '$$ = $1' action is NOT applied when using variants. */ - b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])], [ + b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [emplace])], [ /* If YYLEN is nonzero, implement the default value of the action: '$$ = $1'. Otherwise, use the top of the stack. @@ -885,7 +922,7 @@ b4_dollar_popdef])[]dnl YY_STACK_PRINT (); // Shift the result of the reduction. - yypush_ (YY_NULLPTR, yylhs); + yypush_ (YY_NULLPTR, YY_MOVE (yylhs)); } goto yynewstate; @@ -974,7 +1011,7 @@ b4_dollar_popdef])[]dnl // Shift the error token. error_token.state = yyn; - yypush_ ("Shifting", error_token); + yypush_ ("Shifting", YY_MOVE (error_token)); } goto yynewstate; @@ -1180,7 +1217,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], ]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[ ]b4_namespace_close[ ]b4_epilogue[]dnl -b4_output_end() +b4_output_end m4_popdef([b4_copyright_years])dnl diff --git a/contrib/tools/bison/data/location.cc b/contrib/tools/bison/data/location.cc index 07f1ca62fb..906939d42d 100644 --- a/contrib/tools/bison/data/location.cc +++ b/contrib/tools/bison/data/location.cc @@ -18,11 +18,48 @@ m4_pushdef([b4_copyright_years], [2002-2015, 2018]) -# b4_position_define + +# b4_position_file +# ---------------- +# Name of the file containing the position class, if we want this file. +b4_defines_if([b4_required_version_if([302], [], + [m4_define([b4_position_file], [position.hh])])])]) + + +# b4_location_file +# ---------------- +# Name of the file containing the position/location class, +# if we want this file. +b4_percent_define_check_file([b4_location_file], + [[api.location.file]], + b4_defines_if([[location.hh]])) + +# b4_location_include +# ------------------- +# If location.hh is to be generated, the name under which should it be +# included. +# +# b4_location_path +# ---------------- +# The path to use for the CPP guard. +m4_ifdef([b4_location_file], +[m4_define([b4_location_include], + [b4_percent_define_get([[api.location.include]], + ["b4_location_file"])]) + m4_define([b4_location_path], + b4_percent_define_get([[api.location.include]], + ["b4_dir_prefix[]b4_location_file"])) + m4_define([b4_location_path], + m4_substr(m4_defn([b4_location_path]), 1, m4_eval(m4_len(m4_defn([b4_location_path])) - 2))) + ]) + + + +# b4_location_define # ------------------ -# Define class position. -m4_define([b4_position_define], -[[ /// Abstract a position. +# Define the position and location classes. +m4_define([b4_location_define], +[[ /// A point in a source file. class position { public:]m4_ifdef([b4_location_constructors], [[ @@ -73,10 +110,11 @@ m4_define([b4_position_define], unsigned column; private: - /// Compute max(min, lhs+rhs). + /// Compute max (min, lhs+rhs). static unsigned add_ (unsigned lhs, int rhs, int min) { - return static_cast<unsigned>(std::max(min, static_cast<int>(lhs) + rhs)); + return static_cast<unsigned> (std::max (min, + static_cast<int> (lhs) + rhs)); } }; @@ -139,13 +177,8 @@ m4_define([b4_position_define], ostr << *pos.filename << ':'; return ostr << pos.line << '.' << pos.column; } -]]) - -# b4_location_define -# ------------------ -m4_define([b4_location_define], -[[ /// Abstract a location. + /// Two points in a source file. class location { public: @@ -287,16 +320,31 @@ m4_define([b4_location_define], ]]) -b4_defines_if([ -b4_output_begin([b4_dir_prefix[]position.hh]) -b4_copyright([Positions for Bison parsers in C++])[ +m4_ifdef([b4_position_file], [[ +]b4_output_begin([b4_dir_prefix], [b4_position_file])[ +]b4_generated_by[ +// Starting with Bison 3.2, this file is useless: the structure it +// used to define is now defined in "]b4_location_file[". +// +// To get rid of this file: +// 1. add 'require "3.2"' (or newer) to your grammar file +// 2. remove references to this file from your build system +// 3. if you used to include it, include "]b4_location_file[" instead. + +#include ]b4_location_include[ +]b4_output_end[ +]]) + +m4_ifdef([b4_location_file], [[ +]b4_output_begin([b4_dir_prefix], [b4_location_file])[ +]b4_copyright([Locations for Bison parsers in C++])[ /** - ** \file ]b4_dir_prefix[position.hh - ** Define the ]b4_namespace_ref[::position class. + ** \file ]b4_location_path[ + ** Define the ]b4_namespace_ref[::location class. */ -]b4_cpp_guard_open([b4_dir_prefix[]position.hh])[ +]b4_cpp_guard_open([b4_location_path])[ # include <algorithm> // std::max # include <iostream> @@ -305,30 +353,11 @@ b4_copyright([Positions for Bison parsers in C++])[ ]b4_null_define[ ]b4_namespace_open[ -]b4_position_define[ -]b4_namespace_close[ -]b4_cpp_guard_close([b4_dir_prefix[]position.hh]) -b4_output_end() - - -b4_output_begin([b4_dir_prefix[]location.hh]) -b4_copyright([Locations for Bison parsers in C++])[ - -/** - ** \file ]b4_dir_prefix[location.hh - ** Define the ]b4_namespace_ref[::location class. - */ - -]b4_cpp_guard_open([b4_dir_prefix[]location.hh])[ - -# include "position.hh" - -]b4_namespace_open[ ]b4_location_define[ ]b4_namespace_close[ -]b4_cpp_guard_close([b4_dir_prefix[]location.hh]) -b4_output_end() -]) +]b4_cpp_guard_close([b4_location_path])[ +]b4_output_end[ +]]) m4_popdef([b4_copyright_years]) diff --git a/contrib/tools/bison/data/stack.hh b/contrib/tools/bison/data/stack.hh index f3ac21f949..9ea5be158b 100644 --- a/contrib/tools/bison/data/stack.hh +++ b/contrib/tools/bison/data/stack.hh @@ -15,14 +15,19 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -m4_pushdef([b4_copyright_years], - [2002-2015, 2018]) + +# b4_stack_file +# ------------- +# Name of the file containing the stack class, if we want this file. +b4_defines_if([b4_required_version_if([302], [], + [m4_define([b4_stack_file], [stack.hh])])]) + # b4_stack_define # --------------- m4_define([b4_stack_define], [[ /// A stack with random access from its top. - template <class T, class S = std::vector<T> > + template <typename T, typename S = std::vector<T> > class stack { public: @@ -31,12 +36,7 @@ m4_define([b4_stack_define], typedef typename S::const_reverse_iterator const_iterator; typedef typename S::size_type size_type; - stack () - { - seq_.reserve (200); - } - - stack (size_type n) + stack (size_type n = 200) : seq_ (n) {} @@ -46,7 +46,16 @@ m4_define([b4_stack_define], T& operator[] (size_type i) { - return seq_[seq_.size () - 1 - i]; + return seq_[size () - 1 - i]; + } + + /// Random access. + /// + /// Index 0 returns the topmost element. + T& + operator[] (int i) + { + return operator[] (size_type (i)); } /// Random access. @@ -55,23 +64,32 @@ m4_define([b4_stack_define], const T& operator[] (size_type i) const { - return seq_[seq_.size () - 1 - i]; + return seq_[size () - 1 - i]; + } + + /// Random access. + /// + /// Index 0 returns the topmost element. + const T& + operator[] (int i) const + { + return operator[] (size_type (i)); } /// Steal the contents of \a t. /// /// Close to move-semantics. void - push (T& t) + push (YY_MOVE_REF (T) t) { - seq_.push_back (T()); + seq_.push_back (T ()); operator[](0).move (t); } void - pop (size_type n = 1) + pop (int n = 1) { - for (; n; --n) + for (; 0 < n; --n) seq_.pop_back (); } @@ -107,47 +125,35 @@ m4_define([b4_stack_define], }; /// Present a slice of the top of a stack. - template <class T, class S = stack<T> > + template <typename T, typename S = stack<T> > class slice { public: - typedef typename S::size_type size_type; - slice (const S& stack, size_type range) + slice (const S& stack, int range) : stack_ (stack) , range_ (range) {} const T& - operator[] (size_type i) const + operator[] (int i) const { return stack_[range_ - i]; } private: const S& stack_; - size_type range_; + int range_; }; ]]) -b4_defines_if( -[b4_output_begin([b4_dir_prefix[]stack.hh]) -b4_copyright([Stack handling for Bison parsers in C++])[ - -/** - ** \file ]b4_dir_prefix[stack.hh - ** Define the ]b4_namespace_ref[::stack class. - */ - -]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[ - -# include <vector> - -]b4_namespace_open[ -]b4_stack_define[ -]b4_namespace_close[ - -]b4_cpp_guard_close([b4_dir_prefix[]stack.hh]) -b4_output_end() -]) - -m4_popdef([b4_copyright_years]) +m4_ifdef([b4_stack_file], +[b4_output_begin([b4_dir_prefix], [b4_stack_file])[ +]b4_generated_by[ +// Starting with Bison 3.2, this file is useless: the structure it +// used to define is now defined with the parser itself. +// +// To get rid of this file: +// 1. add 'require "3.2"' (or newer) to your grammar file +// 2. remove references to this file from your build system. +]b4_output_end[ +]]) diff --git a/contrib/tools/bison/data/variant.hh b/contrib/tools/bison/data/variant.hh index 8d0f06f6e3..553bd0d611 100644 --- a/contrib/tools/bison/data/variant.hh +++ b/contrib/tools/bison/data/variant.hh @@ -29,7 +29,7 @@ m4_define([b4_symbol_variant], [$2.$3< $][3 > (m4_shift3($@))])dnl switch ($1) { -b4_type_foreach([b4_type_action_])[]dnl +b4_type_foreach([_b4_type_action])[]dnl default: break; } @@ -55,15 +55,15 @@ dummy[]_b4_char_sizeof_counter]) # --------------------------- # To be mapped on the list of type names to produce: # -# char dummy1[sizeof(type_name_1)]; -# char dummy2[sizeof(type_name_2)]; +# char dummy1[sizeof (type_name_1)]; +# char dummy2[sizeof (type_name_2)]; # # for defined type names. m4_define([b4_char_sizeof], [b4_symbol_if([$1], [has_type], [ m4_map([ b4_symbol_tag_comment], [$@])dnl - char _b4_char_sizeof_dummy@{sizeof(b4_symbol([$1], [type]))@}; + char _b4_char_sizeof_dummy@{sizeof (b4_symbol([$1], [type]))@}; ])]) @@ -101,11 +101,11 @@ m4_define([b4_variant_define], /// Construct and fill. template <typename T> - variant (const T& t)]b4_parse_assert_if([ + variant (YY_RVREF (T) t)]b4_parse_assert_if([ : yytypeid_ (&typeid (T))])[ { YYASSERT (sizeof (T) <= S); - new (yyas_<T> ()) T (t); + new (yyas_<T> ()) T (YY_MOVE (t)); } /// Destruction, allowed only if empty. @@ -117,7 +117,7 @@ m4_define([b4_variant_define], /// Instantiate an empty \a T in here. template <typename T> T& - build () + emplace () {]b4_parse_assert_if([ YYASSERT (!yytypeid_); YYASSERT (sizeof (T) <= S); @@ -125,16 +125,47 @@ m4_define([b4_variant_define], return *new (yyas_<T> ()) T (); } +# if 201103L <= YY_CPLUSPLUS + /// Instantiate a \a T in here from \a t. + template <typename T, typename U> + T& + emplace (U&& u) + {]b4_parse_assert_if([ + YYASSERT (!yytypeid_); + YYASSERT (sizeof (T) <= S); + yytypeid_ = & typeid (T);])[ + return *new (yyas_<T> ()) T (std::forward <U>(u)); + } +# else /// Instantiate a \a T in here from \a t. template <typename T> T& - build (const T& t) + emplace (const T& t) {]b4_parse_assert_if([ YYASSERT (!yytypeid_); YYASSERT (sizeof (T) <= S); yytypeid_ = & typeid (T);])[ return *new (yyas_<T> ()) T (t); } +# endif + + /// Instantiate an empty \a T in here. + /// Obsolete, use emplace. + template <typename T> + T& + build () + { + return emplace<T> (); + } + + /// Instantiate a \a T in here from \a t. + /// Obsolete, use emplace. + template <typename T> + T& + build (const T& t) + { + return emplace<T> (t); + } /// Accessor to a built \a T. template <typename T> @@ -163,7 +194,7 @@ m4_define([b4_variant_define], /// Both variants must be built beforehand, because swapping the actual /// data requires reading it (with as()), and this is not possible on /// unconstructed variants: it would require some dynamic testing, which - /// should not be the variant's responsability. + /// should not be the variant's responsibility. /// Swapping between built and (possibly) non-built is done with /// variant::move (). template <typename T> @@ -182,17 +213,32 @@ m4_define([b4_variant_define], void move (self_type& other) { - build<T> (); +# if 201103L <= YY_CPLUSPLUS + emplace<T> (std::move (other.as<T> ())); +# else + emplace<T> (); swap<T> (other); +# endif other.destroy<T> (); } +# if 201103L <= YY_CPLUSPLUS + /// Move the content of \a other to this. + template <typename T> + void + move (self_type&& other) + { + emplace<T> (std::move (other.as<T> ())); + other.destroy<T> (); + } +#endif + /// Copy the content of \a other to this. template <typename T> void copy (const self_type& other) { - build<T> (other.as<T> ()); + emplace<T> (other.as<T> ()); } /// Destroy the stored \a T. @@ -206,7 +252,7 @@ m4_define([b4_variant_define], private: /// Prohibit blind copies. - self_type& operator=(const self_type&); + self_type& operator= (const self_type&); variant (const self_type&); /// Accessor to raw memory as \a T. @@ -255,7 +301,7 @@ m4_define([b4_value_type_declare], {]b4_type_foreach([b4_char_sizeof])[}; /// Symbol semantic values. - typedef variant<sizeof(union_type)> semantic_type;][]dnl + typedef variant<sizeof (union_type)> semantic_type;][]dnl ]) @@ -283,19 +329,27 @@ m4_define([b4_symbol_value_template], ## ------------- ## -# b4_symbol_constructor_declare_(SYMBOL-NUMBER) +# _b4_symbol_constructor_declare(SYMBOL-NUMBER) # --------------------------------------------- # Declare the overloaded version of make_symbol for the (common) type of # these SYMBOL-NUMBERS. Use at class-level. -m4_define([b4_symbol_constructor_declare_], +m4_define([_b4_symbol_constructor_declare], [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id], -[ static inline +[#if 201103L <= YY_CPLUSPLUS + static symbol_type - make_[]b4_symbol_([$1], [id]) (dnl + make_[]_b4_symbol([$1], [id]) (dnl +b4_join(b4_symbol_if([$1], [has_type], + [b4_symbol([$1], [type]) v]), + b4_locations_if([location_type l]))); +#else + static + symbol_type + make_[]_b4_symbol([$1], [id]) (dnl b4_join(b4_symbol_if([$1], [has_type], [const b4_symbol([$1], [type])& v]), b4_locations_if([const location_type& l]))); - +#endif ])])]) @@ -305,17 +359,31 @@ b4_join(b4_symbol_if([$1], [has_type], # Use at class-level. m4_define([b4_symbol_constructor_declare], [ // Symbol constructors declarations. -b4_symbol_foreach([b4_symbol_constructor_declare_])]) +b4_symbol_foreach([_b4_symbol_constructor_declare])]) -# b4_symbol_constructor_define_(SYMBOL-NUMBER) +# _b4_symbol_constructor_define(SYMBOL-NUMBER) # -------------------------------------------- # Define symbol constructor for this SYMBOL-NUMBER. -m4_define([b4_symbol_constructor_define_], +m4_define([_b4_symbol_constructor_define], [b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id], -[ b4_parser_class_name::symbol_type - b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl +[# if 201103L <= YY_CPLUSPLUS + inline + b4_parser_class_name::symbol_type + b4_parser_class_name::make_[]_b4_symbol([$1], [id]) (dnl +b4_join(b4_symbol_if([$1], [has_type], + [b4_symbol([$1], [type]) v]), + b4_locations_if([location_type l]))) + { + return symbol_type (b4_join([token::b4_symbol([$1], [id])], + b4_symbol_if([$1], [has_type], [std::move (v)]), + b4_locations_if([std::move (l)]))); + } +#else + inline + b4_parser_class_name::symbol_type + b4_parser_class_name::make_[]_b4_symbol([$1], [id]) (dnl b4_join(b4_symbol_if([$1], [has_type], [const b4_symbol([$1], [type])& v]), b4_locations_if([const location_type& l]))) @@ -324,7 +392,7 @@ b4_join(b4_symbol_if([$1], [has_type], b4_symbol_if([$1], [has_type], [v]), b4_locations_if([l]))); } - +#endif ])])]) @@ -332,27 +400,44 @@ b4_join(b4_symbol_if([$1], [has_type], # ----------------------------------- # Generate a constructor declaration for basic_symbol from given type. m4_define([b4_basic_symbol_constructor_declare], -[[ - basic_symbol (]b4_join( +[[# if 201103L <= YY_CPLUSPLUS + basic_symbol (]b4_join( + [typename Base::kind_type t], + b4_symbol_if([$1], [has_type], [b4_symbol([$1], [type])&& v]), + b4_locations_if([location_type&& l]))[); +#else + basic_symbol (]b4_join( [typename Base::kind_type t], - b4_symbol_if([$1], [has_type], const b4_symbol([$1], [type])[& v]), + b4_symbol_if([$1], [has_type], [const b4_symbol([$1], [type])& v]), b4_locations_if([const location_type& l]))[); +#endif ]]) # b4_basic_symbol_constructor_define # ---------------------------------- # Generate a constructor implementation for basic_symbol from given type. m4_define([b4_basic_symbol_constructor_define], -[[ +[[# if 201103L <= YY_CPLUSPLUS template <typename Base> ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join( [typename Base::kind_type t], - b4_symbol_if([$1], [has_type], const b4_symbol([$1], [type])[& v]), + b4_symbol_if([$1], [has_type], [b4_symbol([$1], [type])&& v]), + b4_locations_if([location_type&& l]))[) + : Base (t)]b4_symbol_if([$1], [has_type], [ + , value (std::move (v))])[]b4_locations_if([ + , location (std::move (l))])[ + {} +#else + template <typename Base> + ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join( + [typename Base::kind_type t], + b4_symbol_if([$1], [has_type], [const b4_symbol([$1], [type])& v]), b4_locations_if([const location_type& l]))[) : Base (t)]b4_symbol_if([$1], [has_type], [ , value (v)])[]b4_locations_if([ , location (l)])[ {} +#endif ]]) # b4_symbol_constructor_define @@ -360,4 +445,4 @@ m4_define([b4_basic_symbol_constructor_define], # Define the overloaded versions of make_symbol for all the value types. m4_define([b4_symbol_constructor_define], [ // Implementation of make_symbol for each symbol type. -b4_symbol_foreach([b4_symbol_constructor_define_])]) +b4_symbol_foreach([_b4_symbol_constructor_define])]) diff --git a/contrib/tools/bison/data/yacc.c b/contrib/tools/bison/data/yacc.c index e72b098b7a..d8021ef67d 100644 --- a/contrib/tools/bison/data/yacc.c +++ b/contrib/tools/bison/data/yacc.c @@ -237,11 +237,11 @@ m4_define([b4_declare_parser_state_variables], [b4_pure_if([[ YYSIZE_T yyes_capacity;]])]) -# b4_declare_yyparse_push_ +# _b4_declare_yyparse_push # ------------------------ # Declaration of yyparse (and dependencies) when using the push parser # (including in pull mode). -m4_define([b4_declare_yyparse_push_], +m4_define([_b4_declare_yyparse_push], [[#ifndef YYPUSH_MORE_DEFINED # define YYPUSH_MORE_DEFINED enum { YYPUSH_MORE = 4 }; @@ -265,18 +265,18 @@ b4_function_declare([b4_prefix[pstate_delete]], [[void]], [[b4_prefix[pstate *ps]], [[ps]]])dnl ]) -# b4_declare_yyparse_ +# _b4_declare_yyparse # ------------------- # When not the push parser. -m4_define([b4_declare_yyparse_], +m4_define([_b4_declare_yyparse], [b4_function_declare(b4_prefix[parse], [int], b4_parse_param)]) # b4_declare_yyparse # ------------------ m4_define([b4_declare_yyparse], -[b4_push_if([b4_declare_yyparse_push_], - [b4_declare_yyparse_])[]dnl +[b4_push_if([_b4_declare_yyparse_push], + [_b4_declare_yyparse])[]dnl ]) @@ -299,9 +299,8 @@ m4_define([b4_shared_declarations], ## Output files. ## ## -------------- ## -b4_output_begin([b4_parser_file_name]) -b4_copyright([Bison implementation for Yacc-like parsers in C])[ - +b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Bison implementation for Yacc-like parsers in C])[ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ @@ -312,8 +311,9 @@ b4_copyright([Bison implementation for Yacc-like parsers in C])[ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -]b4_identification -b4_percent_code_get([[top]])[]dnl +]b4_disclaimer[ +]b4_identification[ +]b4_percent_code_get([[top]])[]dnl m4_if(b4_api_prefix, [yy], [], [[/* Substitute the type names. */ #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[ @@ -335,9 +335,7 @@ m4_if(b4_api_prefix, [yy], [], #define yychar ]b4_prefix[char]b4_locations_if([[ #define yylloc ]b4_prefix[lloc]])]))[ -/* Copy the first part of user declarations. */ ]b4_user_pre_prologue[ - ]b4_null_define[ /* Enabling verbose error messages. */ @@ -354,9 +352,8 @@ m4_if(b4_api_prefix, [yy], [], ]])dnl b4_shared_declarations[ -/* Copy the second part of user declarations. */ -]b4_user_post_prologue -b4_percent_code_get[]dnl +]b4_user_post_prologue[ +]b4_percent_code_get[]dnl [#ifdef short # undef short @@ -791,7 +788,7 @@ yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, yytype_int16 **yytop, yytype_int16 *yytop_empty) { YYSIZE_T yysize_old = - *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1; + (YYSIZE_T) (*yytop == yytop_empty ? 0 : *yytop - *yybottom + 1); YYSIZE_T yysize_new = yysize_old + yyadd; if (*yycapacity < yysize_new) { @@ -957,7 +954,7 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, YYDPRINTF ((stderr, " R%d", yyrule - 1)); if (yyesp != yyes_prev) { - YYSIZE_T yysize = yyesp - *yyes + 1; + YYSIZE_T yysize = (YYSIZE_T) (yyesp - *yyes + 1); if (yylen < yysize) { yyesp -= yylen; @@ -973,15 +970,14 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, yyesp = yyes_prev -= yylen; } { - int yystate; + yytype_int16 yystate; { - int yylhs = yyr1[yyrule] - YYNTOKENS; - yystate = yypgoto[yylhs] + *yyesp; - if (yystate < 0 || YYLAST < yystate - || yycheck[yystate] != *yyesp) - yystate = yydefgoto[yylhs]; - else - yystate = yytable[yystate]; + const int yylhs = yyr1[yyrule] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyesp; + yystate = ((yytype_int16) + (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp + ? yytable[yyi] + : yydefgoto[yylhs])); } if (yyesp == yyes_prev) { @@ -1001,7 +997,7 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, } *++yyesp = yystate; } - YYDPRINTF ((stderr, " G%d", yystate)); + YYDPRINTF ((stderr, " G%d", (int) yystate)); } } }]])[ @@ -1089,7 +1085,7 @@ yytnamerr (char *yyres, const char *yystr) if (! yyres) return yystrlen (yystr); - return yystpcpy (yyres, yystr) - yyres; + return (YYSIZE_T) (yystpcpy (yyres, yystr) - yyres); } # endif @@ -1433,7 +1429,6 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ ]m4_ifdef([b4_initial_action], [ b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [], [b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])])dnl -/* User initialization code. */ b4_user_initial_action b4_dollar_popdef[]dnl m4_ifdef([b4_dollar_dollar_used],[[ yyvsp[0] = yylval; @@ -1451,12 +1446,12 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo yyssp++; yysetstate: - *yyssp = yystate; + *yyssp = (yytype_int16) yystate; if (yyss + yystacksize - 1 <= yyssp) { /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; + YYSIZE_T yysize = (YYSIZE_T) (yyssp - yyss + 1); #ifdef yyoverflow { @@ -1476,10 +1471,9 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo &yyvs1, yysize * sizeof (*yyvsp),]b4_locations_if([ &yyls1, yysize * sizeof (*yylsp),])[ &yystacksize); -]b4_locations_if([ - yyls = yyls1;])[ yyss = yyss1; - yyvs = yyvs1; + yyvs = yyvs1;]b4_locations_if([ + yyls = yyls1;])[ } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE @@ -1653,7 +1647,7 @@ yyreduce: int yychar_backup = yychar; switch (yyn) { - ]b4_user_actions[ +]b4_user_actions[ default: break; } if (yychar_backup != yychar) @@ -1687,14 +1681,13 @@ yyreduce: /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } goto yynewstate; @@ -1908,12 +1901,12 @@ yypushreturn:]])[ return yyresult; } ]b4_epilogue[]dnl -b4_output_end() +b4_output_end -b4_defines_if( -[b4_output_begin([b4_spec_defines_file])[ +b4_defines_if([[ +]b4_output_begin([b4_spec_defines_file])[ ]b4_copyright([Bison interface for Yacc-like parsers in C])[ - +]b4_disclaimer[ ]b4_shared_declarations[ -]b4_output_end() -])# b4_defines_if +]b4_output_end[ +]])# b4_defines_if |