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 | |
parent | 632b3cedb8e12fbbb0bcd1bdbf7ec5686725b7e9 (diff) | |
download | ydb-9158d9115725ca7f4ada745ec55eddd5747bc61e.tar.gz |
Update contrib/tools/bison to 3.2.4
78e59a97f3fde03511ddb9969cd1daabbaf998bd
Diffstat (limited to 'contrib/tools/bison')
88 files changed, 3962 insertions, 3442 deletions
diff --git a/contrib/tools/bison/NEWS b/contrib/tools/bison/NEWS index 6a7cd39dcd..56cac0418a 100644 --- a/contrib/tools/bison/NEWS +++ b/contrib/tools/bison/NEWS @@ -1,5 +1,199 @@ GNU Bison NEWS +* Noteworthy changes in release 3.2.4 (2018-12-24) [stable] + +** Bug fixes + + Fix the move constructor of symbol_type. + + Always provide a copy constructor for symbol_type, even in modern C++. + +* Noteworthy changes in release 3.2.3 (2018-12-18) [stable] + +** Bug fixes + + Properly support token constructors in C++ with types that include commas + (e.g., std::pair<int, int>). A regression introduced in Bison 3.2. + +* Noteworthy changes in release 3.2.2 (2018-11-21) [stable] + +** Bug fixes + + C++ portability issues. + +* Noteworthy changes in release 3.2.1 (2018-11-09) [stable] + +** Bug fixes + + Several portability issues have been fixed in the build system, in the + test suite, and in the generated parsers in C++. + +* Noteworthy changes in release 3.2 (2018-10-29) [stable] + +** Backward incompatible changes + + Support for DJGPP, which have been unmaintained and untested for years, is + obsolete. Unless there is activity to revive it, it will be removed. + +** Changes + + %printers should use yyo rather than yyoutput to denote the output stream. + + Variant-based symbols in C++ should use emplace() rather than build(). + + In C++ parsers, parser::operator() is now a synonym for the parser::parse. + +** Documentation + + A new section, "A Simple C++ Example", is a tutorial for parsers in C++. + + A comment in the generated code now emphasizes that users should not + depend upon non-documented implementation details, such as macros starting + with YY_. + +** New features + +*** C++: Support for move semantics (lalr1.cc) + + The lalr1.cc skeleton now fully supports C++ move semantics, while + maintaining compatibility with C++98. You may now store move-only types + when using Bison's variants. For instance: + + %code { + #include <memory> + #include <vector> + } + + %skeleton "lalr1.cc" + %define api.value.type variant + + %% + + %token <int> INT "int"; + %type <std::unique_ptr<int>> int; + %type <std::vector<std::unique_ptr<int>>> list; + + list: + %empty {} + | list int { $$ = std::move($1); $$.emplace_back(std::move($2)); } + + int: "int" { $$ = std::make_unique<int>($1); } + +*** C++: Implicit move of right-hand side values (lalr1.cc) + + In modern C++ (C++11 and later), you should always use 'std::move' with + the values of the right-hand side symbols ($1, $2, etc.), as they will be + popped from the stack anyway. Using 'std::move' is mandatory for + move-only types such as unique_ptr, and it provides a significant speedup + for large types such as std::string, or std::vector, etc. + + If '%define api.value.automove' is set, every occurrence '$n' is replaced + by 'std::move ($n)'. The second rule in the previous grammar can be + simplified to: + + list: list int { $$ = $1; $$.emplace_back($2); } + + With automove enabled, the semantic values are no longer lvalues, so do + not use the swap idiom: + + list: list int { std::swap($$, $1); $$.emplace_back($2); } + + This idiom is anyway obsolete: it is preferable to move than to swap. + + A warning is issued when automove is enabled, and a value is used several + times. + + input.yy:16.31-32: warning: multiple occurrences of $2 with api.value.automove enabled [-Wother] + exp: "twice" exp { $$ = $2 + $2; } + ^^ + + Enabling api.value.automove does not require support for modern C++. The + generated code is valid C++98/03, but will use copies instead of moves. + + The new examples/c++/variant-11.yy shows these features in action. + +*** C++: The implicit default semantic action is always run + + When variants are enabled, the default action was not run, so + + exp: "number" + + was equivalent to + + exp: "number" {} + + It now behaves like in all the other cases, as + + exp: "number" { $$ = $1; } + + possibly using std::move if automove is enabled. + + We do not expect backward compatibility issues. However, beware of + forward compatibility issues: if you rely on default actions with + variants, be sure to '%require "3.2"' to avoid older versions of Bison to + generate incorrect parsers. + +*** C++: Renaming location.hh + + When both %defines and %locations are enabled, Bison generates a + location.hh file. If you don't use locations outside of the parser, you + may avoid its creation with: + + %define api.location.file none + + However this file is useful if, for instance, your parser builds an AST + decorated with locations: you may use Bison's location independently of + Bison's parser. You can now give it another name, for instance: + + %define api.location.file "my-location.hh" + + This name can have directory components, and even be absolute. The name + under which the location file is included is controlled by + api.location.include. + + This way it is possible to have several parsers share the same location + file. + + For instance, in src/foo/parser.hh, generate the include/ast/loc.hh file: + + %locations + %define api.namespace {foo} + %define api.location.file "include/ast/loc.hh" + %define api.location.include {<ast/loc.hh>} + + and use it in src/bar/parser.hh: + + %locations + %define api.namespace {bar} + %code requires {#include <ast/loc.hh>} + %define api.location.type {bar::location} + + Absolute file names are supported, so in your Makefile, passing the flag + -Dapi.location.file='"$(top_srcdir)/include/ast/location.hh"' to bison is + safe. + +*** C++: stack.hh and position.hh are deprecated + + When asked to generate a header file (%defines), the lalr1.cc skeleton + generates a stack.hh file. This file had no interest for users; it is now + made useless: its content is included in the parser definition. It is + still generated for backward compatibility. + + When in addition to %defines, location support is requested (%locations), + the file position.hh is also generated. It is now also useless: its + content is now included in location.hh. + + These files are no longer generated when your grammar file requires at + least Bison 3.2 (%require "3.2"). + +** Bug fixes + + Portability issues on MinGW and VS2015. + + Portability issues in the test suite. + + Portability/warning issues with Flex. + * Noteworthy changes in release 3.1 (2018-08-27) [stable] ** Backward incompatible changes @@ -698,9 +892,9 @@ GNU Bison NEWS fixed, and introducing tokens with any of %token, %left, %right, %precedence, or %nonassoc yields the same result. - When mixing declarations of tokens with a litteral character (e.g., 'a') - or with an identifier (e.g., B) in a precedence declaration, Bison - numbered the litteral characters first. For example + When mixing declarations of tokens with a literal character (e.g., 'a') or + with an identifier (e.g., B) in a precedence declaration, Bison numbered + the literal characters first. For example %right A B 'c' 'd' @@ -1021,7 +1215,7 @@ GNU Bison NEWS Although introduced more than four years ago, XML and Graphviz reports were not properly documented. - The translation of mid-rule actions is now described. + The translation of midrule actions is now described. * Noteworthy changes in release 2.6.5 (2012-11-07) [stable] @@ -2017,16 +2211,16 @@ GNU Bison NEWS The prologue alternatives are experimental. More user feedback will help to determine whether they should become permanent features. -** Revised warning: unset or unused mid-rule values +** Revised warning: unset or unused midrule values - Since Bison 2.2, Bison has warned about mid-rule values that are set but not + Since Bison 2.2, Bison has warned about midrule values that are set but not used within any of the actions of the parent rule. For example, Bison warns about unused $2 in: exp: '1' { $$ = 1; } '+' exp { $$ = $1 + $4; }; - Now, Bison also warns about mid-rule values that are used but not set. For - example, Bison warns about unset $$ in the mid-rule action in: + Now, Bison also warns about midrule values that are used but not set. For + example, Bison warns about unset $$ in the midrule action in: exp: '1' { $1 = 1; } '+' exp { $$ = $2 + $4; }; @@ -2052,7 +2246,7 @@ GNU Bison NEWS Bison no longer supports the "%symbol-default" notation from Bison 2.3a. "<*>" and "<>" combined achieve the same effect with one exception: Bison no - longer applies any %destructor to a mid-rule value if that mid-rule value is + longer applies any %destructor to a midrule value if that midrule value is not actually ever referenced using either $$ or $n in a semantic action. The default %destructor's and %printer's are experimental. More user @@ -2230,7 +2424,7 @@ GNU Bison NEWS | exp "+" exp { $$ = $1; (void) $3; } ; - If there are mid-rule actions, the warning is issued if no action + If there are midrule actions, the warning is issued if no action uses it. The following triggers no warning: $1 and $3 are used. exp: exp { push ($1); } '+' exp { push ($3); sum (); }; @@ -2505,13 +2699,13 @@ GNU Bison NEWS typed: ... untyped; -** Values of mid-rule actions +** Values of midrule actions The following code: foo: { ... } { $$ = $1; } ... - was incorrectly rejected: $1 is defined in the second mid-rule - action, and is equal to the $$ of the first mid-rule action. + was incorrectly rejected: $1 is defined in the second midrule + action, and is equal to the $$ of the first midrule action. * Changes in version 1.50, 2002-10-04: @@ -2647,7 +2841,7 @@ GNU Bison NEWS ** Type clashes Previous versions don't complain when there is a type clash on - the default action if the rule has a mid-rule action, such as in: + the default action if the rule has a midrule action, such as in: %type <foo> bar %% @@ -2958,7 +3152,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. LocalWords: Wprecedence Rassoul Wempty Paolo Bonzini parser's Michiel loc LocalWords: redeclaration sval fcaret reentrant XSLT xsl Wmaybe yyvsp Tedi LocalWords: pragmas noreturn untyped Rozenman unexpanded Wojciech Polak - LocalWords: Alexandre MERCHANTABILITY yytype + LocalWords: Alexandre MERCHANTABILITY yytype emplace ptr automove lvalues + LocalWords: nonterminal yy args Pragma dereference yyformat rhs docdir + LocalWords: Redeclarations rpcalc Autoconf YFLAGS Makefiles outout PROG + LocalWords: Heimbigner AST src ast Makefile srcdir MinGW Local Variables: mode: outline diff --git a/contrib/tools/bison/README b/contrib/tools/bison/README index 8689bab8ee..9f266533b3 100644 --- a/contrib/tools/bison/README +++ b/contrib/tools/bison/README @@ -10,7 +10,7 @@ Bison requires GNU m4 1.4.6 or later. See: https://ftp.gnu.org/gnu/m4/m4-1.4.6.tar.gz ** Internationalization -Bison supports two catalogues: one for Bison itself (i.e., for the +Bison supports two catalogs: one for Bison itself (i.e., for the maintainer-side parser generation), and one for the generated parsers (i.e., for the user-side parser execution). The requirements between both differ: bison needs ngettext, the generated parsers do not. To @@ -29,9 +29,9 @@ If you have questions about using Bison and the documentation does not answer them, please send mail to <help-bison@gnu.org>. * Bug reports -Please send bug reports to <bug-bison@gnu.org>. Please include the -version number from 'bison --version', and a complete, self-contained -test case in each bug report. +Please send bug reports to <bug-bison@gnu.org>. Be sure to include the +version number from 'bison --version', and a complete, self-contained test +case in each bug report. * Copyright statements For any copyright year range specified as YYYY-ZZZZ in this package, @@ -42,12 +42,13 @@ note that the range specifies every single year in that closed interval. Local Variables: mode: outline fill-column: 76 +ispell-dictionary: "american" End: Copyright (C) 1992, 1998-1999, 2003-2005, 2008-2015, 2018 Free Software Foundation, Inc. -This file is part of Bison, the GNU Compiler Compiler. +This file is part of GNU bison, the GNU Compiler Compiler. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -61,3 +62,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. + +# LocalWords: parsers ngettext Texinfo pdf html YYYY ZZZZ ispell american +# LocalWords: MERCHANTABILITY diff --git a/contrib/tools/bison/README-alpha b/contrib/tools/bison/README-alpha new file mode 100644 index 0000000000..8c1742ce89 --- /dev/null +++ b/contrib/tools/bison/README-alpha @@ -0,0 +1,30 @@ +-*- text -*- + +This is a test release of this package. Using it more or less +implicitly signs you up to help us find whatever problems you report. + +The documentation still needs more work. Suggestions welcome. +Patches even more welcome. + +Please send comments and problem reports about this test release to +<bug-bison@gnu.org>. This program will get better only if you report +the problems you encounter. + +----- + +Copyright (C) 2002, 2004, 2009-2015, 2018 Free Software Foundation, Inc. + +This file is part of GNU Bison. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. 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 diff --git a/contrib/tools/bison/lib/abitset.c b/contrib/tools/bison/lib/abitset.c index 830fdefcfc..0d6b9a5d8a 100644 --- a/contrib/tools/bison/lib/abitset.c +++ b/contrib/tools/bison/lib/abitset.c @@ -35,33 +35,28 @@ static bitset_bindex abitset_resize (bitset src, bitset_bindex size) { - /* These bitsets have a fixed size. */ - if (BITSET_SIZE_ (src) != size) - abort (); + /* These bitsets have a fixed size. */ + if (BITSET_SIZE_ (src) != size) + abort (); - return size; + return size; } /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex abitset_small_list (bitset src, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex count; - bitset_windex size; - bitset_word word; - - word = ABITSET_WORDS (src)[0]; + bitset_word word = ABITSET_WORDS (src)[0]; /* Short circuit common case. */ if (!word) return 0; - size = BITSET_SIZE_ (src); - bitno = *next; + bitset_windex size = BITSET_SIZE_ (src); + bitset_bindex bitno = *next; if (bitno >= size) return 0; @@ -70,6 +65,7 @@ abitset_small_list (bitset src, bitset_bindex *list, /* If num is 1, we could speed things up with a binary search of the word of interest. */ + bitset_bindex count; if (num >= BITSET_WORD_BITS) { for (count = 0; word; bitno++) @@ -142,36 +138,27 @@ static bitset_bindex abitset_list_reverse (bitset src, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex rbitno; - bitset_bindex count; - bitset_windex windex; - unsigned bitcnt; - bitset_bindex bitoff; + bitset_bindex rbitno = *next; bitset_word *srcp = ABITSET_WORDS (src); bitset_bindex n_bits = BITSET_SIZE_ (src); - rbitno = *next; - /* If num is 1, we could speed things up with a binary search of the word of interest. */ if (rbitno >= n_bits) return 0; - count = 0; + bitset_bindex count = 0; - bitno = n_bits - (rbitno + 1); + bitset_bindex bitno = n_bits - (rbitno + 1); - windex = bitno / BITSET_WORD_BITS; - bitcnt = bitno % BITSET_WORD_BITS; - bitoff = windex * BITSET_WORD_BITS; + bitset_windex windex = bitno / BITSET_WORD_BITS; + unsigned bitcnt = bitno % BITSET_WORD_BITS; + bitset_bindex bitoff = windex * BITSET_WORD_BITS; do { - bitset_word word; - - word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt); + bitset_word word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt); for (; word; bitcnt--) { if (word & BITSET_MSB) @@ -196,23 +183,20 @@ abitset_list_reverse (bitset src, bitset_bindex *list, /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex abitset_list (bitset src, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex count; bitset_windex windex; bitset_bindex bitoff; bitset_windex size = src->b.csize; bitset_word *srcp = ABITSET_WORDS (src); - bitset_word word; - bitno = *next; + bitset_bindex bitno = *next; - count = 0; + bitset_bindex count = 0; if (!bitno) { /* Many bitsets are zero, so make this common case fast. */ @@ -242,7 +226,7 @@ abitset_list (bitset src, bitset_bindex *list, on the previous call to this function. */ bitoff = windex * BITSET_WORD_BITS; - word = srcp[windex] >> bitno; + bitset_word word = srcp[windex] >> bitno; for (bitno = bitoff + bitno; word; bitno++) { if (word & 1) @@ -263,7 +247,8 @@ abitset_list (bitset src, bitset_bindex *list, for (; windex < size; windex++, bitoff += BITSET_WORD_BITS) { - if (!(word = srcp[windex])) + bitset_word word = srcp[windex]; + if (!word) continue; if ((count + BITSET_WORD_BITS) < num) @@ -302,9 +287,7 @@ abitset_list (bitset src, bitset_bindex *list, static inline void abitset_unused_clear (bitset dst) { - unsigned last_bit; - - last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS; + unsigned last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS; if (last_bit) ABITSET_WORDS (dst)[dst->b.csize - 1] &= ((bitset_word) 1 << last_bit) - 1; @@ -315,9 +298,7 @@ static void abitset_ones (bitset dst) { bitset_word *dstp = ABITSET_WORDS (dst); - size_t bytes; - - bytes = sizeof (bitset_word) * dst->b.csize; + size_t bytes = sizeof (bitset_word) * dst->b.csize; memset (dstp, -1, bytes); abitset_unused_clear (dst); @@ -328,9 +309,7 @@ static void abitset_zero (bitset dst) { bitset_word *dstp = ABITSET_WORDS (dst); - size_t bytes; - - bytes = sizeof (bitset_word) * dst->b.csize; + size_t bytes = sizeof (bitset_word) * dst->b.csize; memset (dstp, 0, bytes); } @@ -339,13 +318,11 @@ abitset_zero (bitset dst) static bool abitset_empty_p (bitset dst) { - bitset_windex i; bitset_word *dstp = ABITSET_WORDS (dst); - for (i = 0; i < dst->b.csize; i++) + for (bitset_windex i = 0; i < dst->b.csize; i++) if (dstp[i]) return false; - return true; } @@ -355,10 +332,9 @@ abitset_copy1 (bitset dst, bitset src) { bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); - bitset_windex size = dst->b.csize; - if (srcp == dstp) - return; + return; + bitset_windex size = dst->b.csize; memcpy (dstp, srcp, sizeof (bitset_word) * size); } @@ -366,13 +342,12 @@ abitset_copy1 (bitset dst, bitset src) static void abitset_not (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = ~(*srcp++); + for (bitset_windex i = 0; i < size; i++) + *dstp++ = ~(*srcp++); abitset_unused_clear (dst); } @@ -380,14 +355,13 @@ abitset_not (bitset dst, bitset src) static bool abitset_equal_p (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - if (*srcp++ != *dstp++) - return false; + for (bitset_windex i = 0; i < size; i++) + if (*srcp++ != *dstp++) + return false; return true; } @@ -395,14 +369,13 @@ abitset_equal_p (bitset dst, bitset src) static bool abitset_subset_p (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++, srcp++) - if (*dstp != (*srcp | *dstp)) - return false; + for (bitset_windex i = 0; i < size; i++, dstp++, srcp++) + if (*dstp != (*srcp | *dstp)) + return false; return true; } @@ -410,15 +383,13 @@ abitset_subset_p (bitset dst, bitset src) static bool abitset_disjoint_p (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - if (*srcp++ & *dstp++) - return false; - + for (bitset_windex i = 0; i < size; i++) + if (*srcp++ & *dstp++) + return false; return true; } @@ -426,31 +397,28 @@ abitset_disjoint_p (bitset dst, bitset src) static void abitset_and (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ & *src2p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ & *src2p++; } static bool abitset_and_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ & *src2p++; - if (*dstp != tmp) { changed = true; @@ -464,31 +432,28 @@ abitset_and_cmp (bitset dst, bitset src1, bitset src2) static void abitset_andn (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ & ~(*src2p++); + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ & ~(*src2p++); } static bool abitset_andn_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ & ~(*src2p++); - if (*dstp != tmp) { changed = true; @@ -502,28 +467,26 @@ abitset_andn_cmp (bitset dst, bitset src1, bitset src2) static void abitset_or (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ | *src2p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ | *src2p++; } static bool abitset_or_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ | *src2p++; @@ -540,28 +503,26 @@ abitset_or_cmp (bitset dst, bitset src1, bitset src2) static void abitset_xor (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ ^ *src2p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ ^ *src2p++; } static bool abitset_xor_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ ^ *src2p++; @@ -578,22 +539,20 @@ abitset_xor_cmp (bitset dst, bitset src1, bitset src2) static void abitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ & *src2p++) | *src3p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = (*src1p++ & *src2p++) | *src3p++; } static bool abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); @@ -601,10 +560,9 @@ abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ & *src2p++) | *src3p++; - if (*dstp != tmp) { changed = true; @@ -618,22 +576,20 @@ abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) static void abitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++; } static bool abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); @@ -641,10 +597,9 @@ abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++; - if (*dstp != tmp) { changed = true; @@ -658,22 +613,20 @@ abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) static void abitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ | *src2p++) & *src3p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = (*src1p++ | *src2p++) & *src3p++; } static bool abitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); @@ -681,10 +634,9 @@ abitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ | *src2p++) & *src3p++; - if (*dstp != tmp) { changed = true; @@ -699,9 +651,9 @@ static void abitset_copy (bitset dst, bitset src) { if (BITSET_COMPATIBLE_ (dst, src)) - abitset_copy1 (dst, src); + abitset_copy1 (dst, src); else - bitset_copy_ (dst, src); + bitset_copy_ (dst, src); } @@ -784,14 +736,12 @@ struct bitset_vtable abitset_vtable = { size_t abitset_bytes (bitset_bindex n_bits) { - bitset_windex size; - size_t bytes; size_t header_size = offsetof (union bitset_union, a.words); struct bitset_align_struct { char a; union bitset_union b; }; size_t bitset_alignment = offsetof (struct bitset_align_struct, b); - size = ABITSET_N_WORDS (n_bits); - bytes = header_size + size * sizeof (bitset_word); + bitset_windex size = ABITSET_N_WORDS (n_bits); + size_t bytes = header_size + size * sizeof (bitset_word); /* Align the size properly for a vector of abitset objects. */ if (header_size % bitset_alignment != 0 @@ -808,19 +758,13 @@ abitset_bytes (bitset_bindex n_bits) bitset abitset_init (bitset bset, bitset_bindex n_bits) { - bitset_windex size; - - size = ABITSET_N_WORDS (n_bits); + bitset_windex size = ABITSET_N_WORDS (n_bits); BITSET_NBITS_ (bset) = n_bits; /* Use optimized routines if bitset fits within a single word. There is probably little merit if using caching since the small bitset will always fit in the cache. */ - if (size == 1) - bset->b.vtable = &abitset_small_vtable; - else - bset->b.vtable = &abitset_vtable; - + bset->b.vtable = size == 1 ? &abitset_small_vtable : &abitset_vtable; bset->b.cindex = 0; bset->b.csize = size; bset->b.cdata = ABITSET_WORDS (bset); diff --git a/contrib/tools/bison/lib/abitset.h b/contrib/tools/bison/lib/abitset.h index 65d4842751..821eed9d96 100644 --- a/contrib/tools/bison/lib/abitset.h +++ b/contrib/tools/bison/lib/abitset.h @@ -23,8 +23,8 @@ #include "bitset.h" -extern size_t abitset_bytes (bitset_bindex); +size_t abitset_bytes (bitset_bindex); -extern bitset abitset_init (bitset, bitset_bindex); +bitset abitset_init (bitset, bitset_bindex); #endif diff --git a/contrib/tools/bison/lib/arg-nonnull.h b/contrib/tools/bison/lib/arg-nonnull.h new file mode 100644 index 0000000000..5f03408312 --- /dev/null +++ b/contrib/tools/bison/lib/arg-nonnull.h @@ -0,0 +1,26 @@ +/* A C macro for declaring that specific arguments must not be NULL. + Copyright (C) 2009-2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* _GL_ARG_NONNULL((n,...,m)) tells the compiler and static analyzer tools + that the values passed as arguments n, ..., m must be non-NULL pointers. + n = 1 stands for the first argument, n = 2 for the second argument etc. */ +#ifndef _GL_ARG_NONNULL +# if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ > 3 +# define _GL_ARG_NONNULL(params) __attribute__ ((__nonnull__ params)) +# else +# define _GL_ARG_NONNULL(params) +# endif +#endif diff --git a/contrib/tools/bison/lib/bbitset.h b/contrib/tools/bison/lib/bbitset.h index d0e7c17c26..29502a5b1d 100644 --- a/contrib/tools/bison/lib/bbitset.h +++ b/contrib/tools/bison/lib/bbitset.h @@ -21,12 +21,20 @@ #ifndef _BBITSET_H #define _BBITSET_H -#include "libiberty.h" - -#include <stdbool.h> #include <limits.h> +#include <stdbool.h> #include <stddef.h> +#include "xalloc.h" + +#ifndef __attribute__ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) +# define __attribute__(x) +# endif +#endif + +#define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) + /* Currently we support five flavours of bitsets: BITSET_ARRAY: Array of bits (fixed size, fast for dense bitsets). Memory for bit array and bitset structure allocated @@ -281,24 +289,24 @@ if (!BITSET_COMPATIBLE_ (DST, SRC1) || !BITSET_COMPATIBLE_ (DST, SRC2) \ /* Private functions for bitset implementations. */ -extern bool bitset_toggle_ (bitset, bitset_bindex); +bool bitset_toggle_ (bitset, bitset_bindex); -extern bitset_bindex bitset_count_ (bitset); +bitset_bindex bitset_count_ (bitset); -extern bitset_bindex bitset_size_ (bitset); +bitset_bindex bitset_size_ (bitset); -extern bool bitset_copy_ (bitset, bitset); +bool bitset_copy_ (bitset, bitset); -extern void bitset_and_or_ (bitset, bitset, bitset, bitset); +void bitset_and_or_ (bitset, bitset, bitset, bitset); -extern bool bitset_and_or_cmp_ (bitset, bitset, bitset, bitset); +bool bitset_and_or_cmp_ (bitset, bitset, bitset, bitset); -extern void bitset_andn_or_ (bitset, bitset, bitset, bitset); +void bitset_andn_or_ (bitset, bitset, bitset, bitset); -extern bool bitset_andn_or_cmp_ (bitset, bitset, bitset, bitset); +bool bitset_andn_or_cmp_ (bitset, bitset, bitset, bitset); -extern void bitset_or_and_ (bitset, bitset, bitset, bitset); +void bitset_or_and_ (bitset, bitset, bitset, bitset); -extern bool bitset_or_and_cmp_ (bitset, bitset, bitset, bitset); +bool bitset_or_and_cmp_ (bitset, bitset, bitset, bitset); #endif /* _BBITSET_H */ diff --git a/contrib/tools/bison/lib/bitset.c b/contrib/tools/bison/lib/bitset.c index 97a60ef4e3..325213777b 100644 --- a/contrib/tools/bison/lib/bitset.c +++ b/contrib/tools/bison/lib/bitset.c @@ -24,12 +24,14 @@ #include <stdlib.h> #include <string.h> + +#include "obstack.h" + #include "abitset.h" #include "lbitset.h" #include "ebitset.h" #include "vbitset.h" #include "bitset_stats.h" -#include "obstack.h" const char * const bitset_type_names[] = BITSET_TYPE_NAMES; @@ -39,8 +41,6 @@ const char * const bitset_type_names[] = BITSET_TYPE_NAMES; size_t bitset_bytes (enum bitset_type type, bitset_bindex n_bits) { - size_t bytes; - if (bitset_stats_enabled) return bitset_stats_bytes (); @@ -50,23 +50,17 @@ bitset_bytes (enum bitset_type type, bitset_bindex n_bits) abort (); case BITSET_ARRAY: - bytes = abitset_bytes (n_bits); - break; + return abitset_bytes (n_bits); case BITSET_LIST: - bytes = lbitset_bytes (n_bits); - break; + return lbitset_bytes (n_bits); case BITSET_TABLE: - bytes = ebitset_bytes (n_bits); - break; + return ebitset_bytes (n_bits); case BITSET_VARRAY: - bytes = vbitset_bytes (n_bits); - break; + return vbitset_bytes (n_bits); } - - return bytes; } @@ -134,12 +128,9 @@ bitset_type_choose (bitset_bindex n_bits ATTRIBUTE_UNUSED, unsigned attr) bitset bitset_alloc (bitset_bindex n_bits, enum bitset_type type) { - size_t bytes; - bitset bset; - - bytes = bitset_bytes (type, n_bits); + size_t bytes = bitset_bytes (type, n_bits); - bset = xcalloc (1, bytes); + bitset bset = xcalloc (1, bytes); /* The cache is disabled until some elements are allocated. If we have variable length arrays, then we may need to allocate a dummy @@ -154,12 +145,9 @@ bitset bitset_obstack_alloc (struct obstack *bobstack, bitset_bindex n_bits, enum bitset_type type) { - size_t bytes; - bitset bset; + size_t bytes = bitset_bytes (type, n_bits); - bytes = bitset_bytes (type, n_bits); - - bset = obstack_alloc (bobstack, bytes); + bitset bset = obstack_alloc (bobstack, bytes); memset (bset, 0, bytes); return bitset_init (bset, n_bits, type); @@ -171,9 +159,7 @@ bitset_obstack_alloc (struct obstack *bobstack, bitset bitset_create (bitset_bindex n_bits, unsigned attr) { - enum bitset_type type; - - type = bitset_type_choose (n_bits, attr); + enum bitset_type type = bitset_type_choose (n_bits, attr); return bitset_alloc (n_bits, type); } @@ -200,11 +186,9 @@ bitset_obstack_free (bitset bset) enum bitset_type bitset_type_get (bitset bset) { - enum bitset_type type; - - type = BITSET_TYPE_ (bset); + enum bitset_type type = BITSET_TYPE_ (bset); if (type != BITSET_STATS) - return type; + return type; return bitset_stats_type_get (bset); } @@ -214,9 +198,7 @@ bitset_type_get (bitset bset) const char * bitset_type_name_get (bitset bset) { - enum bitset_type type; - - type = bitset_type_get (bset); + enum bitset_type type = bitset_type_get (bset); return bitset_type_names[type]; } @@ -227,9 +209,8 @@ bitset_type_name_get (bitset bset) bitset_bindex bitset_next (bitset src, bitset_bindex bitno) { - bitset_bindex val; bitset_bindex next = bitno; - + bitset_bindex val; if (!bitset_list (src, &val, 1, &next)) return BITSET_BINDEX_MAX; return val; @@ -240,7 +221,7 @@ bitset_next (bitset src, bitset_bindex bitno) extern bool bitset_compatible_p (bitset bset1, bitset bset2) { - return BITSET_COMPATIBLE_ (bset1, bset2); + return BITSET_COMPATIBLE_ (bset1, bset2); } @@ -249,9 +230,8 @@ bitset_compatible_p (bitset bset1, bitset bset2) bitset_bindex bitset_prev (bitset src, bitset_bindex bitno) { - bitset_bindex val; bitset_bindex next = bitno; - + bitset_bindex val; if (!bitset_list_reverse (src, &val, 1, &next)) return BITSET_BINDEX_MAX; return val; @@ -291,15 +271,13 @@ bitset_only_set_p (bitset src, bitset_bindex bitno) static void bitset_print (FILE *file, bitset bset, bool verbose) { - unsigned pos; - bitset_bindex i; - bitset_iterator iter; - if (verbose) fprintf (file, "n_bits = %lu, set = {", (unsigned long) bitset_size (bset)); - pos = 30; + unsigned pos = 30; + bitset_bindex i; + bitset_iterator iter; BITSET_FOR_EACH (iter, bset, i, 0) { if (pos > 70) @@ -310,7 +288,7 @@ bitset_print (FILE *file, bitset bset, bool verbose) fprintf (file, "%lu ", (unsigned long) i); pos += 1 + (i >= 10) + (i >= 100); - }; + } if (verbose) fprintf (file, "}\n"); @@ -357,7 +335,7 @@ bitset_toggle_ (bitset bset, bitset_bindex bitno) bitset_bindex bitset_size_ (bitset src) { - return BITSET_NBITS_ (src); + return BITSET_NBITS_ (src); } @@ -366,18 +344,18 @@ bitset_bindex bitset_count_ (bitset src) { bitset_bindex list[BITSET_LIST_SIZE]; - bitset_bindex next; - bitset_bindex num; - bitset_bindex count; + bitset_bindex count = 0; /* This could be greatly sped up by adding a count method for each bitset implementation that uses a direct technique (based on masks) for counting the number of bits set in a word. */ - next = 0; - for (count = 0; (num = bitset_list (src, list, BITSET_LIST_SIZE, &next)); - count += num) - continue; + { + bitset_bindex next = 0; + bitset_bindex num; + while ((num = bitset_list (src, list, BITSET_LIST_SIZE, &next))) + count += num; + } return count; } @@ -398,7 +376,7 @@ bitset_copy_ (bitset dst, bitset src) BITSET_FOR_EACH (iter, src, i, 0) { bitset_set (dst, i); - }; + } return true; } @@ -411,13 +389,11 @@ bitset_op4_cmp (bitset dst, bitset src1, bitset src2, bitset src3, enum bitset_ops op) { bool changed = false; - bool stats_enabled_save; - bitset tmp; /* Create temporary bitset. */ - stats_enabled_save = bitset_stats_enabled; + bool stats_enabled_save = bitset_stats_enabled; bitset_stats_enabled = false; - tmp = bitset_alloc (0, bitset_type_get (dst)); + bitset tmp = bitset_alloc (0, bitset_type_get (dst)); bitset_stats_enabled = stats_enabled_save; switch (op) diff --git a/contrib/tools/bison/lib/bitset.h b/contrib/tools/bison/lib/bitset.h index 48bd2300b9..f7b2cd0bfa 100644 --- a/contrib/tools/bison/lib/bitset.h +++ b/contrib/tools/bison/lib/bitset.h @@ -24,14 +24,14 @@ /* This file is the public interface to the bitset abstract data type. Only use the functions and macros defined in this file. */ -#include "bbitset.h" -#include "obstack.h" #include <stdio.h> - #if USE_UNLOCKED_IO # include "unlocked-io.h" #endif +#include "bbitset.h" +#include "obstack.h" + /* Attributes used to select a bitset implementation. */ enum bitset_attr {BITSET_FIXED = 1, /* Bitset size fixed. */ BITSET_VARIABLE = 2, /* Bitset size variable. */ @@ -83,7 +83,6 @@ union bitset_union struct bbitset_struct b; bitset_windex size; /* Allocated size of array. */ } v; - }; @@ -99,37 +98,37 @@ typedef struct /* Return bytes required for bitset of desired type and size. */ -extern size_t bitset_bytes (enum bitset_type, bitset_bindex); +size_t bitset_bytes (enum bitset_type, bitset_bindex); /* Initialise a bitset with desired type and size. */ -extern bitset bitset_init (bitset, bitset_bindex, enum bitset_type); +bitset bitset_init (bitset, bitset_bindex, enum bitset_type); /* Select an implementation type based on the desired bitset size and attributes. */ -extern enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs); +enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs); /* Create a bitset of desired type and size. The bitset is zeroed. */ -extern bitset bitset_alloc (bitset_bindex, enum bitset_type); +bitset bitset_alloc (bitset_bindex, enum bitset_type); /* Free bitset. */ -extern void bitset_free (bitset); +void bitset_free (bitset); /* Create a bitset of desired type and size using an obstack. The bitset is zeroed. */ -extern bitset bitset_obstack_alloc (struct obstack *bobstack, - bitset_bindex, enum bitset_type); +bitset bitset_obstack_alloc (struct obstack *bobstack, + bitset_bindex, enum bitset_type); /* Free bitset allocated on obstack. */ -extern void bitset_obstack_free (bitset); +void bitset_obstack_free (bitset); /* Create a bitset of desired size and attributes. The bitset is zeroed. */ -extern bitset bitset_create (bitset_bindex, bitset_attrs); +bitset bitset_create (bitset_bindex, bitset_attrs); /* Return bitset type. */ -extern enum bitset_type bitset_type_get (bitset); +enum bitset_type bitset_type_get (bitset); /* Return bitset type name. */ -extern const char *bitset_type_name_get (bitset); +const char *bitset_type_name_get (bitset); /* Set bit BITNO in bitset BSET. */ @@ -181,7 +180,7 @@ bitset_test (bitset bset, bitset_bindex bitno) #define bitset_size(SRC) BITSET_SIZE_ (SRC) /* Change size of bitset. */ -extern void bitset_resize (bitset, bitset_bindex); +void bitset_resize (bitset, bitset_bindex); /* Return number of bits set in bitset SRC. */ #define bitset_count(SRC) BITSET_COUNT_ (SRC) @@ -281,25 +280,25 @@ extern void bitset_resize (bitset, bitset_bindex); BITSET_LIST_REVERSE_ (BSET, LIST, NUM, NEXT) /* Return true if both bitsets are of the same type and size. */ -extern bool bitset_compatible_p (bitset bset1, bitset bset2); +bool bitset_compatible_p (bitset bset1, bitset bset2); /* Find next set bit from the given bit index. */ -extern bitset_bindex bitset_next (bitset, bitset_bindex); +bitset_bindex bitset_next (bitset, bitset_bindex); /* Find previous set bit from the given bit index. */ -extern bitset_bindex bitset_prev (bitset, bitset_bindex); +bitset_bindex bitset_prev (bitset, bitset_bindex); /* Find first set bit. */ -extern bitset_bindex bitset_first (bitset); +bitset_bindex bitset_first (bitset); /* Find last set bit. */ -extern bitset_bindex bitset_last (bitset); +bitset_bindex bitset_last (bitset); /* Return nonzero if this is the only set bit. */ -extern bool bitset_only_set_p (bitset, bitset_bindex); +bool bitset_only_set_p (bitset, bitset_bindex); /* Dump bitset. */ -extern void bitset_dump (FILE *, bitset); +void bitset_dump (FILE *, bitset); /* Loop over all elements of BSET, starting with MIN, setting INDEX to the index of each set bit. For example, the following will print @@ -309,9 +308,7 @@ extern void bitset_dump (FILE *, bitset); bitset_iterator iter; BITSET_FOR_EACH (iter, src, i, 0) - { - printf ("%lu ", (unsigned long) i); - }; + printf ("%lu ", (unsigned long) i); */ #define BITSET_FOR_EACH(ITER, BSET, INDEX, MIN) \ for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \ @@ -331,9 +328,7 @@ extern void bitset_dump (FILE *, bitset); bitset_iterator iter; BITSET_FOR_EACH_REVERSE (iter, src, i, 0) - { - printf ("%lu ", (unsigned long) i); - }; + printf ("%lu ", (unsigned long) i); */ #define BITSET_FOR_EACH_REVERSE(ITER, BSET, INDEX, MIN) \ for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \ @@ -368,13 +363,13 @@ extern void bitset_dump (FILE *, bitset); /* Release any memory tied up with bitsets. */ -extern void bitset_release_memory (void); +void bitset_release_memory (void); /* Enable bitset stats gathering. */ -extern void bitset_stats_enable (void); +void bitset_stats_enable (void); /* Disable bitset stats gathering. */ -extern void bitset_stats_disable (void); +void bitset_stats_disable (void); /* Read bitset stats file of accummulated stats. */ void bitset_stats_read (const char *file_name); @@ -383,12 +378,12 @@ void bitset_stats_read (const char *file_name); void bitset_stats_write (const char *file_name); /* Dump bitset stats. */ -extern void bitset_stats_dump (FILE *); +void bitset_stats_dump (FILE *); /* Function to debug bitset from debugger. */ -extern void debug_bitset (bitset); +void debug_bitset (bitset); /* Function to debug bitset stats from debugger. */ -extern void debug_bitset_stats (void); +void debug_bitset_stats (void); #endif /* _BITSET_H */ diff --git a/contrib/tools/bison/lib/bitset_stats.c b/contrib/tools/bison/lib/bitset_stats.c index dc8aae50d7..d0967348e7 100644 --- a/contrib/tools/bison/lib/bitset_stats.c +++ b/contrib/tools/bison/lib/bitset_stats.c @@ -29,18 +29,19 @@ #include "bitset_stats.h" -#include "bbitset.h" -#include "abitset.h" -#include "ebitset.h" -#include "lbitset.h" -#include "vbitset.h" +#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <stdio.h> #include "gettext.h" #define _(Msgid) gettext (Msgid) +#include "abitset.h" +#include "bbitset.h" +#include "ebitset.h" +#include "lbitset.h" +#include "vbitset.h" + /* Configuration macros. */ #define BITSET_STATS_FILE "bitset.dat" #define BITSET_LOG_COUNT_BINS 10 @@ -108,18 +109,15 @@ static void bitset_percent_histogram_print (FILE *file, const char *name, const char *msg, unsigned n_bins, unsigned *bins) { - unsigned i; - unsigned total; - - total = 0; - for (i = 0; i < n_bins; i++) + unsigned total = 0; + for (unsigned i = 0; i < n_bins; i++) total += bins[i]; if (!total) return; fprintf (file, "%s %s", name, msg); - for (i = 0; i < n_bins; i++) + for (unsigned i = 0; i < n_bins; i++) fprintf (file, "%.0f-%.0f%%\t%8u (%5.1f%%)\n", i * 100.0 / n_bins, (i + 1) * 100.0 / n_bins, bins[i], @@ -132,37 +130,39 @@ static void bitset_log_histogram_print (FILE *file, const char *name, const char *msg, unsigned n_bins, unsigned *bins) { - unsigned i; - unsigned total; - unsigned max_width; - - total = 0; - for (i = 0; i < n_bins; i++) + unsigned total = 0; + for (unsigned i = 0; i < n_bins; i++) total += bins[i]; if (!total) return; /* Determine number of useful bins. */ - for (i = n_bins; i > 3 && ! bins[i - 1]; i--) - continue; - n_bins = i; + { + unsigned i; + for (i = n_bins; i > 3 && ! bins[i - 1]; i--) + continue; + n_bins = i; + } /* 2 * ceil (log10 (2) * (N - 1)) + 1. */ - max_width = 2 * (unsigned) (0.30103 * (n_bins - 1) + 0.9999) + 1; + unsigned max_width = 2 * (unsigned) (0.30103 * (n_bins - 1) + 0.9999) + 1; fprintf (file, "%s %s", name, msg); - for (i = 0; i < 2; i++) - fprintf (file, "%*d\t%8u (%5.1f%%)\n", - max_width, i, bins[i], 100.0 * bins[i] / total); - - for (; i < n_bins; i++) - fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n", - max_width - ((unsigned) (0.30103 * (i) + 0.9999) + 1), - 1UL << (i - 1), - (1UL << i) - 1, - bins[i], - (100.0 * bins[i]) / total); + { + unsigned i; + for (i = 0; i < 2; i++) + fprintf (file, "%*d\t%8u (%5.1f%%)\n", + max_width, i, bins[i], 100.0 * bins[i] / total); + + for (; i < n_bins; i++) + fprintf (file, "%*lu-%lu\t%8u (%5.1f%%)\n", + max_width - ((unsigned) (0.30103 * (i) + 0.9999) + 1), + 1UL << (i - 1), + (1UL << i) - 1, + bins[i], + (100.0 * bins[i]) / total); + } } @@ -205,8 +205,6 @@ bitset_stats_print_1 (FILE *file, const char *name, static void bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED) { - int i; - if (!bitset_stats_info) return; @@ -215,7 +213,7 @@ bitset_stats_print (FILE *file, bool verbose ATTRIBUTE_UNUSED) if (bitset_stats_info->runs > 1) fprintf (file, _("Accumulated runs = %u\n"), bitset_stats_info->runs); - for (i = 0; i < BITSET_TYPE_NUM; i++) + for (int i = 0; i < BITSET_TYPE_NUM; i++) bitset_stats_print_1 (file, bitset_type_names[i], &bitset_stats_info->types[i]); } @@ -242,15 +240,13 @@ bitset_stats_disable (void) void bitset_stats_read (const char *file_name) { - FILE *file; - if (!bitset_stats_info) return; if (!file_name) file_name = BITSET_STATS_FILE; - file = fopen (file_name, "r"); + FILE *file = fopen (file_name, "r"); if (file) { if (fread (&bitset_stats_info_data, sizeof (bitset_stats_info_data), @@ -272,15 +268,13 @@ bitset_stats_read (const char *file_name) void bitset_stats_write (const char *file_name) { - FILE *file; - if (!bitset_stats_info) return; if (!file_name) file_name = BITSET_STATS_FILE; - file = fopen (file_name, "w"); + FILE *file = fopen (file_name, "w"); if (file) { if (fwrite (&bitset_stats_info_data, sizeof (bitset_stats_info_data), @@ -352,7 +346,7 @@ bitset_stats_reset (bitset dst, bitset_bindex bitno) static bool bitset_stats_toggle (bitset src, bitset_bindex bitno) { - return BITSET_TOGGLE_ (src->s.bset, bitno); + return BITSET_TOGGLE_ (src->s.bset, bitno); } @@ -378,7 +372,7 @@ bitset_stats_test (bitset src, bitset_bindex bitno) static bitset_bindex bitset_stats_resize (bitset src, bitset_bindex size) { - return BITSET_RESIZE_ (src->s.bset, size); + return BITSET_RESIZE_ (src->s.bset, size); } @@ -573,35 +567,40 @@ static bitset_bindex bitset_stats_list (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex count; - bitset_bindex tmp; - bitset_bindex size; - bitset_bindex i; - - count = BITSET_LIST_ (bset->s.bset, list, num, next); + bitset_bindex count = BITSET_LIST_ (bset->s.bset, list, num, next); BITSET_STATS_LISTS_INC (bset->s.bset); /* Log histogram of number of set bits. */ - for (i = 0, tmp = count; tmp; tmp >>= 1, i++) - continue; - if (i >= BITSET_LOG_COUNT_BINS) - i = BITSET_LOG_COUNT_BINS - 1; - BITSET_STATS_LIST_COUNTS_INC (bset->s.bset, i); + { + bitset_bindex i; + bitset_bindex tmp; + for (i = 0, tmp = count; tmp; tmp >>= 1, i++) + continue; + if (i >= BITSET_LOG_COUNT_BINS) + i = BITSET_LOG_COUNT_BINS - 1; + BITSET_STATS_LIST_COUNTS_INC (bset->s.bset, i); + } /* Log histogram of number of bits in set. */ - size = BITSET_SIZE_ (bset->s.bset); - for (i = 0, tmp = size; tmp; tmp >>= 1, i++) - continue; - if (i >= BITSET_LOG_SIZE_BINS) - i = BITSET_LOG_SIZE_BINS - 1; - BITSET_STATS_LIST_SIZES_INC (bset->s.bset, i); + bitset_bindex size = BITSET_SIZE_ (bset->s.bset); + { + bitset_bindex i; + bitset_bindex tmp; + for (i = 0, tmp = size; tmp; tmp >>= 1, i++) + continue; + if (i >= BITSET_LOG_SIZE_BINS) + i = BITSET_LOG_SIZE_BINS - 1; + BITSET_STATS_LIST_SIZES_INC (bset->s.bset, i); + } /* Histogram of fraction of bits set. */ - i = size ? (count * BITSET_DENSITY_BINS) / size : 0; - if (i >= BITSET_DENSITY_BINS) - i = BITSET_DENSITY_BINS - 1; - BITSET_STATS_LIST_DENSITY_INC (bset->s.bset, i); + { + bitset_bindex i = size ? (count * BITSET_DENSITY_BINS) / size : 0; + if (i >= BITSET_DENSITY_BINS) + i = BITSET_DENSITY_BINS - 1; + BITSET_STATS_LIST_DENSITY_INC (bset->s.bset, i); + } return count; } @@ -663,7 +662,7 @@ struct bitset_vtable bitset_stats_vtable = { enum bitset_type bitset_stats_type_get (bitset bset) { - return BITSET_TYPE_ (bset->s.bset); + return BITSET_TYPE_ (bset->s.bset); } @@ -677,9 +676,6 @@ bitset_stats_bytes (void) bitset bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) { - size_t bytes; - bitset sbset; - bset->b.vtable = &bitset_stats_vtable; /* Disable cache. */ @@ -697,32 +693,38 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) abort (); case BITSET_ARRAY: - bytes = abitset_bytes (n_bits); - sbset = xcalloc (1, bytes); - abitset_init (sbset, n_bits); + { + size_t bytes = abitset_bytes (n_bits); + bset->s.bset = xcalloc (1, bytes); + abitset_init (bset->s.bset, n_bits); + } break; case BITSET_LIST: - bytes = lbitset_bytes (n_bits); - sbset = xcalloc (1, bytes); - lbitset_init (sbset, n_bits); + { + size_t bytes = lbitset_bytes (n_bits); + bset->s.bset = xcalloc (1, bytes); + lbitset_init (bset->s.bset, n_bits); + } break; case BITSET_TABLE: - bytes = ebitset_bytes (n_bits); - sbset = xcalloc (1, bytes); - ebitset_init (sbset, n_bits); + { + size_t bytes = ebitset_bytes (n_bits); + bset->s.bset = xcalloc (1, bytes); + ebitset_init (bset->s.bset, n_bits); + } break; case BITSET_VARRAY: - bytes = vbitset_bytes (n_bits); - sbset = xcalloc (1, bytes); - vbitset_init (sbset, n_bits); + { + size_t bytes = vbitset_bytes (n_bits); + bset->s.bset = xcalloc (1, bytes); + vbitset_init (bset->s.bset, n_bits); + } break; } - bset->s.bset = sbset; - BITSET_STATS_ALLOCS_INC (type); return bset; diff --git a/contrib/tools/bison/lib/bitset_stats.h b/contrib/tools/bison/lib/bitset_stats.h index f1e213f984..3a12ab3680 100644 --- a/contrib/tools/bison/lib/bitset_stats.h +++ b/contrib/tools/bison/lib/bitset_stats.h @@ -25,10 +25,10 @@ extern bool bitset_stats_enabled; -extern enum bitset_type bitset_stats_type_get (bitset); +enum bitset_type bitset_stats_type_get (bitset); -extern size_t bitset_stats_bytes (void); +size_t bitset_stats_bytes (void); -extern bitset bitset_stats_init (bitset, bitset_bindex, enum bitset_type); +bitset bitset_stats_init (bitset, bitset_bindex, enum bitset_type); #endif diff --git a/contrib/tools/bison/lib/bitsetv-print.c b/contrib/tools/bison/lib/bitsetv-print.c index 798a81acc3..d229c7d613 100644 --- a/contrib/tools/bison/lib/bitsetv-print.c +++ b/contrib/tools/bison/lib/bitsetv-print.c @@ -29,7 +29,6 @@ void bitsetv_matrix_dump (FILE * out, const char *title, bitsetv bset) { - bitset_bindex i, j; bitset_bindex hsize = bitset_size (bset[0]); /* Title. */ @@ -37,32 +36,32 @@ bitsetv_matrix_dump (FILE * out, const char *title, bitsetv bset) /* Column numbers. */ fputs (" ", out); - for (i = 0; i < hsize; ++i) + for (bitset_bindex i = 0; i < hsize; ++i) putc (i / 10 ? '0' + i / 10 : ' ', out); putc ('\n', out); fputs (" ", out); - for (i = 0; i < hsize; ++i) + for (bitset_bindex i = 0; i < hsize; ++i) fprintf (out, "%d", (int) (i % 10)); putc ('\n', out); /* Bar. */ fputs (" .", out); - for (i = 0; i < hsize; ++i) + for (bitset_bindex i = 0; i < hsize; ++i) putc ('-', out); fputs (".\n", out); /* Contents. */ - for (i = 0; bset[i]; ++i) + for (bitset_bindex i = 0; bset[i]; ++i) { fprintf (out, "%2lu|", (unsigned long) i); - for (j = 0; j < hsize; ++j) + for (bitset_bindex j = 0; j < hsize; ++j) fputs (bitset_test (bset[i], j) ? "1" : " ", out); fputs ("|\n", out); } /* Bar. */ fputs (" `", out); - for (i = 0; i < hsize; ++i) + for (bitset_bindex i = 0; i < hsize; ++i) putc ('-', out); fputs ("'\n", out); diff --git a/contrib/tools/bison/lib/bitsetv-print.h b/contrib/tools/bison/lib/bitsetv-print.h index f1ba11829a..b706b04a8d 100644 --- a/contrib/tools/bison/lib/bitsetv-print.h +++ b/contrib/tools/bison/lib/bitsetv-print.h @@ -24,6 +24,6 @@ #include "bitsetv.h" /* Dump vector of bitsets as a matrix. */ -extern void bitsetv_matrix_dump (FILE *, const char *, bitsetv); +void bitsetv_matrix_dump (FILE *, const char *, bitsetv); #endif /* _BITSETV_H */ diff --git a/contrib/tools/bison/lib/bitsetv.c b/contrib/tools/bison/lib/bitsetv.c index 1d3213bf38..7077795d6d 100644 --- a/contrib/tools/bison/lib/bitsetv.c +++ b/contrib/tools/bison/lib/bitsetv.c @@ -29,23 +29,19 @@ bitset * bitsetv_alloc (bitset_bindex n_vecs, bitset_bindex n_bits, enum bitset_type type) { - size_t vector_bytes; - size_t bytes; - bitset *bsetv; - bitset_bindex i; - /* Determine number of bytes for each set. */ - bytes = bitset_bytes (type, n_bits); + size_t bytes = bitset_bytes (type, n_bits); /* If size calculation overflows, memory is exhausted. */ if (BITSET_SIZE_MAX / (sizeof (bitset) + bytes) <= n_vecs) xalloc_die (); /* Allocate vector table at head of bitset array. */ - vector_bytes = (n_vecs + 1) * sizeof (bitset) + bytes - 1; + size_t vector_bytes = (n_vecs + 1) * sizeof (bitset) + bytes - 1; vector_bytes -= vector_bytes % bytes; - bsetv = xcalloc (1, vector_bytes + bytes * n_vecs); + bitset *bsetv = xcalloc (1, vector_bytes + bytes * n_vecs); + bitset_bindex i = 0; for (i = 0; i < n_vecs; i++) { bsetv[i] = (bitset) (void *) ((char *) bsetv + vector_bytes + i * bytes); @@ -64,9 +60,7 @@ bitsetv_alloc (bitset_bindex n_vecs, bitset_bindex n_bits, bitset * bitsetv_create (bitset_bindex n_vecs, bitset_bindex n_bits, unsigned attr) { - enum bitset_type type; - - type = bitset_type_choose (n_bits, attr); + enum bitset_type type = bitset_type_choose (n_bits, attr); return bitsetv_alloc (n_vecs, n_bits, type); } @@ -75,10 +69,8 @@ bitsetv_create (bitset_bindex n_vecs, bitset_bindex n_bits, unsigned attr) void bitsetv_free (bitsetv bsetv) { - bitset_bindex i; - - for (i = 0; bsetv[i]; i++) - BITSET_FREE_ (bsetv[i]); + for (bitset_bindex i = 0; bsetv[i]; i++) + BITSET_FREE_ (bsetv[i]); free (bsetv); } @@ -87,9 +79,7 @@ bitsetv_free (bitsetv bsetv) void bitsetv_zero (bitsetv bsetv) { - bitset_bindex i; - - for (i = 0; bsetv[i]; i++) + for (bitset_bindex i = 0; bsetv[i]; i++) bitset_zero (bsetv[i]); } @@ -98,9 +88,7 @@ bitsetv_zero (bitsetv bsetv) void bitsetv_ones (bitsetv bsetv) { - bitset_bindex i; - - for (i = 0; bsetv[i]; i++) + for (bitset_bindex i = 0; bsetv[i]; i++) bitset_ones (bsetv[i]); } @@ -110,11 +98,8 @@ bitsetv_ones (bitsetv bsetv) void bitsetv_transitive_closure (bitsetv bsetv) { - bitset_bindex i; - bitset_bindex j; - - for (i = 0; bsetv[i]; i++) - for (j = 0; bsetv[j]; j++) + for (bitset_bindex i = 0; bsetv[i]; i++) + for (bitset_bindex j = 0; bsetv[j]; j++) if (bitset_test (bsetv[j], i)) bitset_or (bsetv[j], bsetv[j], bsetv[i]); } @@ -127,10 +112,8 @@ bitsetv_transitive_closure (bitsetv bsetv) void bitsetv_reflexive_transitive_closure (bitsetv bsetv) { - bitset_bindex i; - bitsetv_transitive_closure (bsetv); - for (i = 0; bsetv[i]; i++) + for (bitset_bindex i = 0; bsetv[i]; i++) bitset_set (bsetv[i], i); } @@ -141,10 +124,8 @@ void bitsetv_dump (FILE *file, char const *title, char const *subtitle, bitsetv bsetv) { - bitset_windex i; - fprintf (file, "%s\n", title); - for (i = 0; bsetv[i]; i++) + for (bitset_windex i = 0; bsetv[i]; i++) { fprintf (file, "%s %lu\n", subtitle, (unsigned long) i); bitset_dump (file, bsetv[i]); @@ -157,9 +138,7 @@ bitsetv_dump (FILE *file, char const *title, char const *subtitle, void debug_bitsetv (bitsetv bsetv) { - bitset_windex i; - - for (i = 0; bsetv[i]; i++) + for (bitset_windex i = 0; bsetv[i]; i++) { fprintf (stderr, "%lu: ", (unsigned long) i); debug_bitset (bsetv[i]); diff --git a/contrib/tools/bison/lib/bitsetv.h b/contrib/tools/bison/lib/bitsetv.h index 56e0de7dca..60777a21e0 100644 --- a/contrib/tools/bison/lib/bitsetv.h +++ b/contrib/tools/bison/lib/bitsetv.h @@ -27,35 +27,35 @@ typedef bitset * bitsetv; /* Create a vector of N_VECS bitsets, each of N_BITS, and of type TYPE. */ -extern bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum bitset_type); +bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum bitset_type); /* Create a vector of N_VECS bitsets, each of N_BITS, and with attribute hints specified by ATTR. */ -extern bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned); +bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned); /* Free vector of bitsets. */ -extern void bitsetv_free (bitsetv); +void bitsetv_free (bitsetv); /* Zero vector of bitsets. */ -extern void bitsetv_zero (bitsetv); +void bitsetv_zero (bitsetv); /* Set vector of bitsets. */ -extern void bitsetv_ones (bitsetv); +void bitsetv_ones (bitsetv); /* Given a vector BSETV of N bitsets of size N, modify its contents to be the transitive closure of what was given. */ -extern void bitsetv_transitive_closure (bitsetv); +void bitsetv_transitive_closure (bitsetv); /* Given a vector BSETV of N bitsets of size N, modify its contents to be the reflexive transitive closure of what was given. This is the same as transitive closure but with all bits on the diagonal of the bit matrix set. */ -extern void bitsetv_reflexive_transitive_closure (bitsetv); +void bitsetv_reflexive_transitive_closure (bitsetv); /* Dump vector of bitsets. */ -extern void bitsetv_dump (FILE *, const char *, const char *, bitsetv); +void bitsetv_dump (FILE *, const char *, const char *, bitsetv); /* Function to debug vector of bitsets from debugger. */ -extern void debug_bitsetv (bitsetv); +void debug_bitsetv (bitsetv); #endif /* _BITSETV_H */ diff --git a/contrib/tools/bison/lib/config-linux.h b/contrib/tools/bison/lib/config-linux.h index 5322cd67cf..7c6759f463 100644 --- a/contrib/tools/bison/lib/config-linux.h +++ b/contrib/tools/bison/lib/config-linux.h @@ -1,111 +1,6 @@ /* lib/config.h. Generated from config.in.h by configure. */ /* lib/config.in.h. Generated from configure.ac by autoheader. */ -/* CPU and C ABI indicator */ -#ifndef __i386__ -/* #undef __i386__ */ -#endif -#ifndef __x86_64_x32__ -/* #undef __x86_64_x32__ */ -#endif -#ifndef __alpha__ -/* #undef __alpha__ */ -#endif -#ifndef __arm__ -/* #undef __arm__ */ -#endif -#ifndef __armhf__ -/* #undef __armhf__ */ -#endif -#ifndef __arm64_ilp32__ -/* #undef __arm64_ilp32__ */ -#endif -#ifndef __arm64__ -/* #undef __arm64__ */ -#endif -#ifndef __hppa__ -/* #undef __hppa__ */ -#endif -#ifndef __hppa64__ -/* #undef __hppa64__ */ -#endif -#ifndef __ia64_ilp32__ -/* #undef __ia64_ilp32__ */ -#endif -#ifndef __ia64__ -/* #undef __ia64__ */ -#endif -#ifndef __m68k__ -/* #undef __m68k__ */ -#endif -#ifndef __mips__ -/* #undef __mips__ */ -#endif -#ifndef __mipsn32__ -/* #undef __mipsn32__ */ -#endif -#ifndef __mips64__ -/* #undef __mips64__ */ -#endif -#ifndef __powerpc__ -/* #undef __powerpc__ */ -#endif -#ifndef __powerpc64__ -/* #undef __powerpc64__ */ -#endif -#ifndef __powerpc64_elfv2__ -/* #undef __powerpc64_elfv2__ */ -#endif -#ifndef __riscv32__ -/* #undef __riscv32__ */ -#endif -#ifndef __riscv64__ -/* #undef __riscv64__ */ -#endif -#ifndef __riscv32_ilp32__ -/* #undef __riscv32_ilp32__ */ -#endif -#ifndef __riscv32_ilp32f__ -/* #undef __riscv32_ilp32f__ */ -#endif -#ifndef __riscv32_ilp32d__ -/* #undef __riscv32_ilp32d__ */ -#endif -#ifndef __riscv64_ilp32__ -/* #undef __riscv64_ilp32__ */ -#endif -#ifndef __riscv64_ilp32f__ -/* #undef __riscv64_ilp32f__ */ -#endif -#ifndef __riscv64_ilp32d__ -/* #undef __riscv64_ilp32d__ */ -#endif -#ifndef __riscv64_lp64__ -/* #undef __riscv64_lp64__ */ -#endif -#ifndef __riscv64_lp64f__ -/* #undef __riscv64_lp64f__ */ -#endif -#ifndef __riscv64_lp64d__ -/* #undef __riscv64_lp64d__ */ -#endif -#ifndef __s390__ -/* #undef __s390__ */ -#endif -#ifndef __s390x__ -/* #undef __s390x__ */ -#endif -#ifndef __sh__ -/* #undef __sh__ */ -#endif -#ifndef __sparc__ -/* #undef __sparc__ */ -#endif -#ifndef __sparc64__ -/* #undef __sparc64__ */ -#endif - - /* Define if building universal (internal helper macro) */ /* #undef AC_APPLE_UNIVERSAL_BUILD */ @@ -178,6 +73,13 @@ /* Define to 1 if fopen() fails to recognize a trailing slash. */ /* #undef FOPEN_TRAILING_SLASH_BUG */ +/* Define if gettimeofday clobbers the localtime buffer. */ +/* #undef GETTIMEOFDAY_CLOBBERS_LOCALTIME */ + +/* Define this to 'void' or 'struct timezone' to match the system's + declaration of the second argument to gettimeofday. */ +#define GETTIMEOFDAY_TIMEZONE void + /* Define to a C preprocessor expression that evaluates to 1 or 0, depending whether the gnulib module close-stream shall be considered present. */ #define GNULIB_CLOSE_STREAM 1 @@ -270,6 +172,12 @@ /* Define to 1 when the gnulib module getdtablesize should be tested. */ #define GNULIB_TEST_GETDTABLESIZE 1 +/* Define to 1 when the gnulib module getrusage should be tested. */ +#define GNULIB_TEST_GETRUSAGE 1 + +/* Define to 1 when the gnulib module gettimeofday should be tested. */ +#define GNULIB_TEST_GETTIMEOFDAY 1 + /* Define to 1 when the gnulib module isnan should be tested. */ #define GNULIB_TEST_ISNAN 1 @@ -434,6 +342,9 @@ */ #define HAVE_ALLOCA_H 1 +/* Define if you have an arithmetic hrtime_t type. */ +/* #undef HAVE_ARITHMETIC_HRTIME_T */ + /* Define to 1 if you have the <bp-sym.h> header file. */ /* #undef HAVE_BP_SYM_H */ @@ -447,12 +358,19 @@ CoreFoundation framework. */ /* #undef HAVE_CFLOCALECOPYCURRENT */ +/* Define to 1 if you have the Mac OS X function + CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */ +/* #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES */ + /* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in the CoreFoundation framework. */ /* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */ -/* Define to 1 if the system has the type `clock_t'. */ -#define HAVE_CLOCK_T 1 +/* Define to 1 if you have the `clock_gettime' function. */ +#define HAVE_CLOCK_GETTIME 1 + +/* Define to 1 if you have the `clock_settime' function. */ +#define HAVE_CLOCK_SETTIME 1 /* Define to 1 if you have the `confstr' function. */ /* #undef HAVE_CONFSTR */ @@ -484,10 +402,6 @@ you don't. */ #define HAVE_DECL_CLEARERR_UNLOCKED 1 -/* Define to 1 if you have the declaration of `clock', and to 0 if you don't. - */ -#define HAVE_DECL_CLOCK 0 - /* Define to 1 if you have the declaration of `copysign', and to 0 if you don't. */ /* #undef HAVE_DECL_COPYSIGN */ @@ -544,9 +458,9 @@ don't. */ #define HAVE_DECL_GETDTABLESIZE 1 -/* Define to 1 if you have the declaration of `getrusage', and to 0 if you +/* Define to 1 if you have the declaration of `gethrtime', and to 0 if you don't. */ -#define HAVE_DECL_GETRUSAGE 1 +#define HAVE_DECL_GETHRTIME 0 /* Define to 1 if you have the declaration of `mbrtowc', and to 0 if you don't. */ @@ -600,14 +514,6 @@ don't. */ #define HAVE_DECL_STRNLEN 1 -/* Define to 1 if you have the declaration of `sysconf', and to 0 if you - don't. */ -#define HAVE_DECL_SYSCONF 1 - -/* Define to 1 if you have the declaration of `times', and to 0 if you don't. - */ -#define HAVE_DECL_TIMES 1 - /* Define to 1 if you have the declaration of `towlower', and to 0 if you don't. */ /* #undef HAVE_DECL_TOWLOWER */ @@ -669,9 +575,15 @@ /* Define to 1 if you have the `getprogname' function. */ /* #undef HAVE_GETPROGNAME */ +/* Define to 1 if you have the `getrusage' function. */ +#define HAVE_GETRUSAGE 1 + /* Define if the GNU gettext() function is already present or preinstalled. */ /* #undef HAVE_GETTEXT */ +/* Define to 1 if you have the `gettimeofday' function. */ +#define HAVE_GETTIMEOFDAY 1 + /* Define if you have the iconv() function and it works. */ /* #undef HAVE_ICONV */ @@ -750,6 +662,9 @@ /* Define to 1 if you have the <memory.h> header file. */ #define HAVE_MEMORY_H 1 +/* Define to 1 if you have the `microuptime' function. */ +/* #undef HAVE_MICROUPTIME */ + /* Define to 1 if <limits.h> defines the MIN and MAX macros. */ /* #undef HAVE_MINMAX_IN_LIMITS_H */ @@ -763,6 +678,9 @@ concept. */ /* #undef HAVE_MSVC_INVALID_PARAMETER_HANDLER */ +/* Define to 1 if you have the `nanouptime' function. */ +/* #undef HAVE_NANOUPTIME */ + /* Define to 1 if you have the `nl_langinfo' function. */ /* #undef HAVE_NL_LANGINFO */ @@ -977,9 +895,6 @@ /* Define to 1 if you have the <sys/wait.h> header file. */ #define HAVE_SYS_WAIT_H 1 -/* Define to 1 if you have the `times' function. */ -#define HAVE_TIMES 1 - /* Define to 1 if you have the `towlower' function. */ #define HAVE_TOWLOWER 1 @@ -1040,10 +955,6 @@ /* Define to 1 if O_NOFOLLOW works. */ #define HAVE_WORKING_O_NOFOLLOW 1 -/* Define if you have the posix_spawn and posix_spawnp functions and they - work. */ -#define HAVE_WORKING_POSIX_SPAWN 1 - /* Define to 1 if the system has the type `_Bool'. */ #define HAVE__BOOL 1 @@ -1175,7 +1086,7 @@ #define PACKAGE_NAME "GNU Bison" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "GNU Bison 3.1" +#define PACKAGE_STRING "GNU Bison 3.2.4" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "bison" @@ -1184,7 +1095,7 @@ #define PACKAGE_URL "http://www.gnu.org/software/bison/" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.1" +#define PACKAGE_VERSION "3.2.4" /* Define if <inttypes.h> exists and defines unusable PRI* macros. */ /* #undef PRI_MACROS_BROKEN */ @@ -1208,6 +1119,9 @@ slash */ /* #undef REPLACE_FUNC_STAT_FILE */ +/* Define if gnulib uses its own posix_spawn and posix_spawnp functions. */ +/* #undef REPLACE_POSIX_SPAWN */ + /* Define if printf is overridden by a POSIX compliant gnulib implementation. */ #define REPLACE_PRINTF_POSIX 1 @@ -1222,6 +1136,15 @@ implementation. */ #define REPLACE_VFPRINTF_POSIX 1 +/* File name of the Bourne shell. */ +#if defined __CYGWIN__ +/* Omit the directory part because for 32-bit Cygwin programs in a + 64-bit Cygwin environment, the Cygwin mounts are not visible. */ +# define BOURNE_SHELL "sh" +#else +# define BOURNE_SHELL "/bin/sh" +#endif + /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type 'sig_atomic_t'. */ /* #undef SIG_ATOMIC_T_SUFFIX */ @@ -1367,7 +1290,7 @@ /* #undef USE_WINDOWS_THREADS */ /* Version number of package */ -#define VERSION "3.1" +#define VERSION "3.2.4" /* Define to 1 if unsetenv returns void instead of int. */ /* #undef VOID_UNSETENV */ @@ -1418,12 +1341,15 @@ #define _NETBSD_SOURCE 1 /* The _Noreturn keyword of C11. */ -#if ! (defined _Noreturn \ - || (defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__)) -# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \ - || 0x5110 <= __SUNPRO_C) +#ifndef _Noreturn +# if 201103 <= (defined __cplusplus ? __cplusplus : 0) +# define _Noreturn [[noreturn]] +# elif (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ + || 4 < __GNUC__ + (7 <= __GNUC_MINOR__)) + /* _Noreturn works as-is. */ +# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C # define _Noreturn __attribute__ ((__noreturn__)) -# elif defined _MSC_VER && 1200 <= _MSC_VER +# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0) # define _Noreturn __declspec (noreturn) # else # define _Noreturn diff --git a/contrib/tools/bison/lib/config-win.h b/contrib/tools/bison/lib/config-win.h index cb0268bf50..25076ea809 100644 --- a/contrib/tools/bison/lib/config-win.h +++ b/contrib/tools/bison/lib/config-win.h @@ -1226,7 +1226,7 @@ char *strsignal (int signum); /* #undef PACKAGE_PACKAGER_VERSION */ /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "GNU Bison 3.1" +#define PACKAGE_STRING "GNU Bison 3.2.4" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "m4" @@ -1235,7 +1235,7 @@ char *strsignal (int signum); #define PACKAGE_URL "http://www.gnu.org/software/m4/" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.1" +#define PACKAGE_VERSION "3.2.4" /* Define if <inttypes.h> exists and defines unusable PRI* macros. */ /* #undef PRI_MACROS_BROKEN */ @@ -1398,7 +1398,7 @@ char *strsignal (int signum); /* #undef USE_WINDOWS_THREADS */ /* Version number of package */ -#define VERSION "3.1" +#define VERSION "3.2.4" /* Define to 1 if unsetenv returns void instead of int. */ /* #undef VOID_UNSETENV */ diff --git a/contrib/tools/bison/lib/configmake-linux.h b/contrib/tools/bison/lib/configmake-linux.h index bc0a0399a3..bd096ef005 100644 --- a/contrib/tools/bison/lib/configmake-linux.h +++ b/contrib/tools/bison/lib/configmake-linux.h @@ -1,28 +1,28 @@ /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ -#define PREFIX "/var/empty/bison-3.1" -#define EXEC_PREFIX "/var/empty/bison-3.1" -#define BINDIR "/var/empty/bison-3.1/bin" -#define SBINDIR "/var/empty/bison-3.1/sbin" -#define LIBEXECDIR "/var/empty/bison-3.1/libexec" -#define DATAROOTDIR "/var/empty/bison-3.1/share" -#define DATADIR "/var/empty/bison-3.1/share" -#define SYSCONFDIR "/var/empty/bison-3.1/etc" -#define SHAREDSTATEDIR "/var/empty/bison-3.1/com" -#define LOCALSTATEDIR "/var/empty/bison-3.1/var" -#define RUNSTATEDIR "/var/empty/bison-3.1/var/run" -#define INCLUDEDIR "/var/empty/bison-3.1/include" +#define PREFIX "/var/empty/bison-3.2.4" +#define EXEC_PREFIX "/var/empty/bison-3.2.4" +#define BINDIR "/var/empty/bison-3.2.4/bin" +#define SBINDIR "/var/empty/bison-3.2.4/sbin" +#define LIBEXECDIR "/var/empty/bison-3.2.4/libexec" +#define DATAROOTDIR "/var/empty/bison-3.2.4/share" +#define DATADIR "/var/empty/bison-3.2.4/share" +#define SYSCONFDIR "/var/empty/bison-3.2.4/etc" +#define SHAREDSTATEDIR "/var/empty/bison-3.2.4/com" +#define LOCALSTATEDIR "/var/empty/bison-3.2.4/var" +#define RUNSTATEDIR "/var/empty/bison-3.2.4/var/run" +#define INCLUDEDIR "/var/empty/bison-3.2.4/include" #define OLDINCLUDEDIR "/usr/include" -#define DOCDIR "/var/empty/bison-3.1/share/doc/bison" -#define INFODIR "/var/empty/bison-3.1/share/info" -#define HTMLDIR "/var/empty/bison-3.1/share/doc/bison" -#define DVIDIR "/var/empty/bison-3.1/share/doc/bison" -#define PDFDIR "/var/empty/bison-3.1/share/doc/bison" -#define PSDIR "/var/empty/bison-3.1/share/doc/bison" -#define LIBDIR "/var/empty/bison-3.1/lib" -#define LISPDIR "/var/empty/bison-3.1/share/emacs/site-lisp" -#define LOCALEDIR "/var/empty/bison-3.1/share/locale" -#define MANDIR "/var/empty/bison-3.1/share/man" -#define PKGDATADIR "/var/empty/bison-3.1/share/bison" -#define PKGINCLUDEDIR "/var/empty/bison-3.1/include/bison" -#define PKGLIBDIR "/var/empty/bison-3.1/lib/bison" -#define PKGLIBEXECDIR "/var/empty/bison-3.1/libexec/bison" +#define DOCDIR "/var/empty/bison-3.2.4/share/doc/bison" +#define INFODIR "/var/empty/bison-3.2.4/share/info" +#define HTMLDIR "/var/empty/bison-3.2.4/share/doc/bison" +#define DVIDIR "/var/empty/bison-3.2.4/share/doc/bison" +#define PDFDIR "/var/empty/bison-3.2.4/share/doc/bison" +#define PSDIR "/var/empty/bison-3.2.4/share/doc/bison" +#define LIBDIR "/var/empty/bison-3.2.4/lib" +#define LISPDIR "/var/empty/bison-3.2.4/share/emacs/site-lisp" +#define LOCALEDIR "/var/empty/bison-3.2.4/share/locale" +#define MANDIR "/var/empty/bison-3.2.4/share/man" +#define PKGDATADIR "/var/empty/bison-3.2.4/share/bison" +#define PKGINCLUDEDIR "/var/empty/bison-3.2.4/include/bison" +#define PKGLIBDIR "/var/empty/bison-3.2.4/lib/bison" +#define PKGLIBEXECDIR "/var/empty/bison-3.2.4/libexec/bison" diff --git a/contrib/tools/bison/lib/ebitset.c b/contrib/tools/bison/lib/ebitset.c index 06da3cc6ce..561816b132 100644 --- a/contrib/tools/bison/lib/ebitset.c +++ b/contrib/tools/bison/lib/ebitset.c @@ -22,10 +22,11 @@ #include "ebitset.h" -#include "obstack.h" #include <stdlib.h> #include <string.h> +#include "obstack.h" + /* This file implements expandable bitsets. These bitsets can be of arbitrary length and are more efficient than arrays of bits for large sparse sets. @@ -73,7 +74,7 @@ typedef ebitset_elt *ebitset_elts; /* Number of elements to initially allocate. */ #ifndef EBITSET_INITIAL_SIZE -#define EBITSET_INITIAL_SIZE 2 +# define EBITSET_INITIAL_SIZE 2 #endif @@ -123,19 +124,14 @@ static ebitset_elt *ebitset_free_list; /* Free list of bitset elements. */ static bitset_bindex ebitset_resize (bitset src, bitset_bindex n_bits) { - bitset_windex oldsize; - bitset_windex newsize; - if (n_bits == BITSET_NBITS_ (src)) return n_bits; - oldsize = EBITSET_SIZE (src); - newsize = EBITSET_N_ELTS (n_bits); + bitset_windex oldsize = EBITSET_SIZE (src); + bitset_windex newsize = EBITSET_N_ELTS (n_bits); if (oldsize < newsize) { - bitset_windex size; - /* The bitset needs to grow. If we already have enough memory allocated, then just zero what we need. */ if (newsize > EBITSET_ASIZE (src)) @@ -145,11 +141,7 @@ ebitset_resize (bitset src, bitset_bindex n_bits) grow the bitset 25% larger than requested to reduce number of reallocations. */ - if (oldsize == 0) - size = newsize; - else - size = newsize + newsize / 4; - + bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4; EBITSET_ELTS (src) = realloc (EBITSET_ELTS (src), size * sizeof (ebitset_elt *)); EBITSET_ASIZE (src) = size; @@ -234,9 +226,7 @@ ebitset_elt_alloc (void) static inline ebitset_elt * ebitset_elt_calloc (void) { - ebitset_elt *elt; - - elt = ebitset_elt_alloc (); + ebitset_elt *elt = ebitset_elt_alloc (); memset (EBITSET_WORDS (elt), 0, sizeof (EBITSET_WORDS (elt))); return elt; } @@ -254,12 +244,8 @@ ebitset_elt_free (ebitset_elt *elt) static inline void ebitset_elt_remove (bitset bset, bitset_windex eindex) { - ebitset_elts *elts; - ebitset_elt *elt; - - elts = EBITSET_ELTS (bset); - - elt = elts[eindex]; + ebitset_elts *elts = EBITSET_ELTS (bset); + ebitset_elt *elt = elts[eindex]; elts[eindex] = 0; ebitset_elt_free (elt); @@ -270,9 +256,7 @@ ebitset_elt_remove (bitset bset, bitset_windex eindex) static inline void ebitset_elt_add (bitset bset, ebitset_elt *elt, bitset_windex eindex) { - ebitset_elts *elts; - - elts = EBITSET_ELTS (bset); + ebitset_elts *elts = EBITSET_ELTS (bset); /* Assume that the elts entry not allocated. */ elts[eindex] = elt; } @@ -282,12 +266,9 @@ ebitset_elt_add (bitset bset, ebitset_elt *elt, bitset_windex eindex) static inline bool ebitset_elt_zero_p (ebitset_elt *elt) { - int i; - - for (i = 0; i < EBITSET_ELT_WORDS; i++) + for (int i = 0; i < EBITSET_ELT_WORDS; i++) if (EBITSET_WORDS (elt)[i]) return false; - return true; } @@ -296,24 +277,18 @@ static ebitset_elt * ebitset_elt_find (bitset bset, bitset_bindex bindex, enum ebitset_find_mode mode) { - ebitset_elt *elt; - bitset_windex size; - bitset_windex eindex; - ebitset_elts *elts; + bitset_windex eindex = bindex / EBITSET_ELT_BITS; - eindex = bindex / EBITSET_ELT_BITS; - - elts = EBITSET_ELTS (bset); - size = EBITSET_SIZE (bset); + ebitset_elts *elts = EBITSET_ELTS (bset); + bitset_windex size = EBITSET_SIZE (bset); if (eindex < size) { - if ((elt = elts[eindex])) + ebitset_elt *elt = elts[eindex]; + if (elt) { - if (EBITSET_WORDS (elt) == bset->b.cdata) - return elt; - - EBITSET_CACHE_SET (bset, eindex); + if (EBITSET_WORDS (elt) != bset->b.cdata) + EBITSET_CACHE_SET (bset, eindex); return elt; } } @@ -333,10 +308,12 @@ ebitset_elt_find (bitset bset, bitset_bindex bindex, ebitset_resize (bset, bindex); /* Create a new element. */ - elt = ebitset_elt_calloc (); - ebitset_elt_add (bset, elt, eindex); - EBITSET_CACHE_SET (bset, eindex); - return elt; + { + ebitset_elt *elt = ebitset_elt_calloc (); + ebitset_elt_add (bset, elt, eindex); + EBITSET_CACHE_SET (bset, eindex); + return elt; + } case EBITSET_SUBST: return &ebitset_zero_elts[0]; @@ -348,15 +325,12 @@ ebitset_elt_find (bitset bset, bitset_bindex bindex, static inline bitset_windex ebitset_weed (bitset bset) { - ebitset_elts *elts; - bitset_windex j; - bitset_windex count; - if (EBITSET_ZERO_P (bset)) return 0; - elts = EBITSET_ELTS (bset); - count = 0; + ebitset_elts *elts = EBITSET_ELTS (bset); + bitset_windex count = 0; + bitset_windex j; for (j = 0; j < EBITSET_SIZE (bset); j++) { ebitset_elt *elt = elts[j]; @@ -391,17 +365,13 @@ ebitset_weed (bitset bset) static inline void ebitset_zero (bitset bset) { - ebitset_elts *elts; - bitset_windex j; - if (EBITSET_ZERO_P (bset)) return; - elts = EBITSET_ELTS (bset); - for (j = 0; j < EBITSET_SIZE (bset); j++) + ebitset_elts *elts = EBITSET_ELTS (bset); + for (bitset_windex j = 0; j < EBITSET_SIZE (bset); j++) { ebitset_elt *elt = elts[j]; - if (elt) ebitset_elt_remove (bset, j); } @@ -415,10 +385,6 @@ ebitset_zero (bitset bset) static inline bool ebitset_equal_p (bitset dst, bitset src) { - ebitset_elts *selts; - ebitset_elts *delts; - bitset_windex j; - if (src == dst) return true; @@ -428,12 +394,11 @@ ebitset_equal_p (bitset dst, bitset src) if (EBITSET_SIZE (src) != EBITSET_SIZE (dst)) return false; - selts = EBITSET_ELTS (src); - delts = EBITSET_ELTS (dst); + ebitset_elts *selts = EBITSET_ELTS (src); + ebitset_elts *delts = EBITSET_ELTS (dst); - for (j = 0; j < EBITSET_SIZE (src); j++) + for (bitset_windex j = 0; j < EBITSET_SIZE (src); j++) { - unsigned i; ebitset_elt *selt = selts[j]; ebitset_elt *delt = delts[j]; @@ -442,7 +407,7 @@ ebitset_equal_p (bitset dst, bitset src) if ((selt && !delt) || (!selt && delt)) return false; - for (i = 0; i < EBITSET_ELT_WORDS; i++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++) if (EBITSET_WORDS (selt)[i] != EBITSET_WORDS (delt)[i]) return false; } @@ -454,10 +419,6 @@ ebitset_equal_p (bitset dst, bitset src) static inline void ebitset_copy_ (bitset dst, bitset src) { - ebitset_elts *selts; - ebitset_elts *delts; - bitset_windex j; - if (src == dst) return; @@ -466,17 +427,14 @@ ebitset_copy_ (bitset dst, bitset src) if (BITSET_NBITS_ (dst) != BITSET_NBITS_ (src)) ebitset_resize (dst, BITSET_NBITS_ (src)); - selts = EBITSET_ELTS (src); - delts = EBITSET_ELTS (dst); - for (j = 0; j < EBITSET_SIZE (src); j++) + ebitset_elts *selts = EBITSET_ELTS (src); + ebitset_elts *delts = EBITSET_ELTS (dst); + for (bitset_windex j = 0; j < EBITSET_SIZE (src); j++) { ebitset_elt *selt = selts[j]; - if (selt) { - ebitset_elt *tmp; - - tmp = ebitset_elt_alloc (); + ebitset_elt *tmp = ebitset_elt_alloc (); delts[j] = tmp; memcpy (EBITSET_WORDS (tmp), EBITSET_WORDS (selt), sizeof (EBITSET_WORDS (selt))); @@ -567,60 +525,41 @@ static bitset_bindex ebitset_list_reverse (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex n_bits; - bitset_bindex bitno; - bitset_bindex rbitno; - unsigned bcount; - bitset_bindex boffset; - bitset_windex windex; - bitset_windex eindex; - bitset_windex woffset; - bitset_bindex count; - bitset_windex size; - ebitset_elts *elts; - if (EBITSET_ZERO_P (bset)) return 0; - size = EBITSET_SIZE (bset); - n_bits = size * EBITSET_ELT_BITS; - rbitno = *next; + bitset_windex size = EBITSET_SIZE (bset); + bitset_bindex n_bits = size * EBITSET_ELT_BITS; + bitset_bindex rbitno = *next; if (rbitno >= n_bits) return 0; - elts = EBITSET_ELTS (bset); + ebitset_elts *elts = EBITSET_ELTS (bset); - bitno = n_bits - (rbitno + 1); + bitset_bindex bitno = n_bits - (rbitno + 1); - windex = bitno / BITSET_WORD_BITS; - eindex = bitno / EBITSET_ELT_BITS; - woffset = windex - eindex * EBITSET_ELT_WORDS; + bitset_windex windex = bitno / BITSET_WORD_BITS; + bitset_windex eindex = bitno / EBITSET_ELT_BITS; + bitset_windex woffset = windex - eindex * EBITSET_ELT_WORDS; /* If num is 1, we could speed things up with a binary search of the word of interest. */ - - count = 0; - bcount = bitno % BITSET_WORD_BITS; - boffset = windex * BITSET_WORD_BITS; + bitset_bindex count = 0; + unsigned bcount = bitno % BITSET_WORD_BITS; + bitset_bindex boffset = windex * BITSET_WORD_BITS; do { - ebitset_elt *elt; - bitset_word *srcp; - - elt = elts[eindex]; + ebitset_elt *elt = elts[eindex]; if (elt) { - srcp = EBITSET_WORDS (elt); + bitset_word *srcp = EBITSET_WORDS (elt); do { - bitset_word word; - - word = srcp[woffset] << (BITSET_WORD_BITS - 1 - bcount); - - for (; word; bcount--) + for (bitset_word word = srcp[woffset] << (BITSET_WORD_BITS - 1 - bcount); + word; bcount--) { if (word & BITSET_MSB) { @@ -656,41 +595,32 @@ static bitset_bindex ebitset_list (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_windex windex; - bitset_windex eindex; - bitset_bindex count; - bitset_windex size; - ebitset_elt *elt; - bitset_word word; - ebitset_elts *elts; - if (EBITSET_ZERO_P (bset)) return 0; - bitno = *next; - count = 0; + bitset_bindex bitno = *next; + bitset_bindex count = 0; - elts = EBITSET_ELTS (bset); - size = EBITSET_SIZE (bset); - eindex = bitno / EBITSET_ELT_BITS; + ebitset_elts *elts = EBITSET_ELTS (bset); + bitset_windex size = EBITSET_SIZE (bset); + bitset_windex eindex = bitno / EBITSET_ELT_BITS; if (bitno % EBITSET_ELT_BITS) { /* We need to start within an element. This is not very common. */ - elt = elts[eindex]; + ebitset_elt *elt = elts[eindex]; if (elt) { bitset_windex woffset; bitset_word *srcp = EBITSET_WORDS (elt); - windex = bitno / BITSET_WORD_BITS; + bitset_windex windex = bitno / BITSET_WORD_BITS; woffset = eindex * EBITSET_ELT_WORDS; for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++) { - word = srcp[windex - woffset] >> (bitno % BITSET_WORD_BITS); + bitset_word word = srcp[windex - woffset] >> (bitno % BITSET_WORD_BITS); for (; word; bitno++) { @@ -718,22 +648,21 @@ ebitset_list (bitset bset, bitset_bindex *list, for (; eindex < size; eindex++) { - int i; bitset_word *srcp; - elt = elts[eindex]; + ebitset_elt *elt = elts[eindex]; if (!elt) continue; srcp = EBITSET_WORDS (elt); - windex = eindex * EBITSET_ELT_WORDS; + bitset_windex windex = eindex * EBITSET_ELT_WORDS; if ((count + EBITSET_ELT_BITS) < num) { /* The coast is clear, plant boot! */ #if EBITSET_ELT_WORDS == 2 - word = srcp[0]; + bitset_word word = srcp[0]; if (word) { if (!(word & 0xffff)) @@ -774,7 +703,7 @@ ebitset_list (bitset bset, bitset_bindex *list, windex++; bitno = windex * BITSET_WORD_BITS; #else - for (i = 0; i < EBITSET_ELT_WORDS; i++, windex++) + for (int i = 0; i < EBITSET_ELT_WORDS; i++, windex++) { bitno = windex * BITSET_WORD_BITS; @@ -806,11 +735,11 @@ ebitset_list (bitset bset, bitset_bindex *list, /* Tread more carefully since we need to check if array overflows. */ - for (i = 0; i < EBITSET_ELT_WORDS; i++, windex++) + for (int i = 0; i < EBITSET_ELT_WORDS; i++, windex++) { bitno = windex * BITSET_WORD_BITS; - for (word = srcp[i]; word; bitno++) + for (bitset_word word = srcp[i]; word; bitno++) { if (word & 1) { @@ -836,31 +765,22 @@ ebitset_list (bitset bset, bitset_bindex *list, static inline void ebitset_unused_clear (bitset dst) { - unsigned last_bit; - bitset_bindex n_bits; - - n_bits = BITSET_NBITS_ (dst); - last_bit = n_bits % EBITSET_ELT_BITS; + bitset_bindex n_bits = BITSET_NBITS_ (dst); + unsigned last_bit = n_bits % EBITSET_ELT_BITS; if (last_bit) { - bitset_windex eindex; - ebitset_elts *elts; - ebitset_elt *elt; + ebitset_elts *elts = EBITSET_ELTS (dst); - elts = EBITSET_ELTS (dst); + bitset_windex eindex = n_bits / EBITSET_ELT_BITS; - eindex = n_bits / EBITSET_ELT_BITS; - - elt = elts[eindex]; + ebitset_elt *elt = elts[eindex]; if (elt) { - bitset_windex windex; - bitset_windex woffset; bitset_word *srcp = EBITSET_WORDS (elt); - windex = n_bits / BITSET_WORD_BITS; - woffset = eindex * EBITSET_ELT_WORDS; + bitset_windex windex = n_bits / BITSET_WORD_BITS; + bitset_windex woffset = eindex * EBITSET_ELT_WORDS; srcp[windex - woffset] &= ((bitset_word) 1 << last_bit) - 1; windex++; @@ -874,14 +794,11 @@ ebitset_unused_clear (bitset dst) static void ebitset_ones (bitset dst) { - bitset_windex j; - ebitset_elt *elt; - - for (j = 0; j < EBITSET_SIZE (dst); j++) + for (bitset_windex j = 0; j < EBITSET_SIZE (dst); j++) { /* Create new elements if they cannot be found. Perhaps we should just add pointers to a ones element? */ - elt = + ebitset_elt *elt = ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_CREATE); memset (EBITSET_WORDS (elt), -1, sizeof (EBITSET_WORDS (elt))); } @@ -893,14 +810,11 @@ ebitset_ones (bitset dst) static bool ebitset_empty_p (bitset dst) { - ebitset_elts *elts; - bitset_windex j; - if (EBITSET_ZERO_P (dst)) return 1; - elts = EBITSET_ELTS (dst); - for (j = 0; j < EBITSET_SIZE (dst); j++) + ebitset_elts *elts = EBITSET_ELTS (dst); + for (bitset_windex j = 0; j < EBITSET_SIZE (dst); j++) { ebitset_elt *elt = elts[j]; @@ -923,23 +837,18 @@ ebitset_empty_p (bitset dst) static void ebitset_not (bitset dst, bitset src) { - unsigned i; - ebitset_elt *selt; - ebitset_elt *delt; - bitset_windex j; - ebitset_resize (dst, BITSET_NBITS_ (src)); - for (j = 0; j < EBITSET_SIZE (src); j++) + for (bitset_windex j = 0; j < EBITSET_SIZE (src); j++) { /* Create new elements for dst if they cannot be found or substitute zero elements if src elements not found. */ - selt = + ebitset_elt *selt = ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_SUBST); - delt = + ebitset_elt *delt = ebitset_elt_find (dst, j * EBITSET_ELT_BITS, EBITSET_CREATE); - for (i = 0; i < EBITSET_ELT_WORDS; i++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++) EBITSET_WORDS (delt)[i] = ~EBITSET_WORDS (selt)[i]; } EBITSET_NONZERO_SET (dst); @@ -951,26 +860,16 @@ ebitset_not (bitset dst, bitset src) static bool ebitset_subset_p (bitset dst, bitset src) { - bitset_windex j; - ebitset_elts *selts; - ebitset_elts *delts; - bitset_windex ssize; - bitset_windex dsize; - - selts = EBITSET_ELTS (src); - delts = EBITSET_ELTS (dst); + ebitset_elts *selts = EBITSET_ELTS (src); + ebitset_elts *delts = EBITSET_ELTS (dst); - ssize = EBITSET_SIZE (src); - dsize = EBITSET_SIZE (dst); + bitset_windex ssize = EBITSET_SIZE (src); + bitset_windex dsize = EBITSET_SIZE (dst); - for (j = 0; j < ssize; j++) + for (bitset_windex j = 0; j < ssize; j++) { - unsigned i; - ebitset_elt *selt; - ebitset_elt *delt; - - selt = j < ssize ? selts[j] : 0; - delt = j < dsize ? delts[j] : 0; + ebitset_elt *selt = j < ssize ? selts[j] : 0; + ebitset_elt *delt = j < dsize ? delts[j] : 0; if (!selt && !delt) continue; @@ -980,7 +879,7 @@ ebitset_subset_p (bitset dst, bitset src) if (!delt) delt = &ebitset_zero_elts[0]; - for (i = 0; i < EBITSET_ELT_WORDS; i++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++) if (EBITSET_WORDS (delt)[i] != (EBITSET_WORDS (selt)[i] | EBITSET_WORDS (delt)[i])) return false; @@ -993,31 +892,21 @@ ebitset_subset_p (bitset dst, bitset src) static bool ebitset_disjoint_p (bitset dst, bitset src) { - bitset_windex j; - ebitset_elts *selts; - ebitset_elts *delts; - bitset_windex ssize; - bitset_windex dsize; + ebitset_elts *selts = EBITSET_ELTS (src); + ebitset_elts *delts = EBITSET_ELTS (dst); - selts = EBITSET_ELTS (src); - delts = EBITSET_ELTS (dst); + bitset_windex ssize = EBITSET_SIZE (src); + bitset_windex dsize = EBITSET_SIZE (dst); - ssize = EBITSET_SIZE (src); - dsize = EBITSET_SIZE (dst); - - for (j = 0; j < ssize; j++) + for (bitset_windex j = 0; j < ssize; j++) { - unsigned i; - ebitset_elt *selt; - ebitset_elt *delt; - - selt = j < ssize ? selts[j] : 0; - delt = j < dsize ? delts[j] : 0; + ebitset_elt *selt = j < ssize ? selts[j] : 0; + ebitset_elt *delt = j < dsize ? delts[j] : 0; if (!selt || !delt) continue; - for (i = 0; i < EBITSET_ELT_WORDS; i++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++) if ((EBITSET_WORDS (selt)[i] & EBITSET_WORDS (delt)[i])) return false; } @@ -1029,42 +918,27 @@ ebitset_disjoint_p (bitset dst, bitset src) static bool ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) { - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - bitset_windex size; - ebitset_elts *selts1; - ebitset_elts *selts2; - ebitset_elts *delts; - bitset_word *srcp1; - bitset_word *srcp2; - bitset_word *dstp; bool changed = false; - unsigned i; - bitset_windex j; ebitset_resize (dst, max (BITSET_NBITS_ (src1), BITSET_NBITS_ (src2))); - ssize1 = EBITSET_SIZE (src1); - ssize2 = EBITSET_SIZE (src2); - dsize = EBITSET_SIZE (dst); - size = ssize1; + bitset_windex ssize1 = EBITSET_SIZE (src1); + bitset_windex ssize2 = EBITSET_SIZE (src2); + bitset_windex dsize = EBITSET_SIZE (dst); + bitset_windex size = ssize1; if (size < ssize2) size = ssize2; - selts1 = EBITSET_ELTS (src1); - selts2 = EBITSET_ELTS (src2); - delts = EBITSET_ELTS (dst); + ebitset_elts *selts1 = EBITSET_ELTS (src1); + ebitset_elts *selts2 = EBITSET_ELTS (src2); + ebitset_elts *delts = EBITSET_ELTS (dst); + bitset_windex j = 0; for (j = 0; j < size; j++) { - ebitset_elt *selt1; - ebitset_elt *selt2; - ebitset_elt *delt; - - selt1 = j < ssize1 ? selts1[j] : 0; - selt2 = j < ssize2 ? selts2[j] : 0; - delt = j < dsize ? delts[j] : 0; + ebitset_elt *selt1 = j < ssize1 ? selts1[j] : 0; + ebitset_elt *selt2 = j < ssize2 ? selts2[j] : 0; + ebitset_elt *delt = j < dsize ? delts[j] : 0; if (!selt1 && !selt2) { @@ -1085,16 +959,16 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) else delts[j] = 0; - srcp1 = EBITSET_WORDS (selt1); - srcp2 = EBITSET_WORDS (selt2); - dstp = EBITSET_WORDS (delt); + bitset_word *srcp1 = EBITSET_WORDS (selt1); + bitset_word *srcp2 = EBITSET_WORDS (selt2); + bitset_word *dstp = EBITSET_WORDS (delt); switch (op) { default: abort (); case BITSET_OP_OR: - for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ | *srcp2++; @@ -1107,7 +981,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_AND: - for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ & *srcp2++; @@ -1120,7 +994,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_XOR: - for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ ^ *srcp2++; @@ -1133,7 +1007,7 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_ANDN: - for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ & ~(*srcp2++); @@ -1159,12 +1033,9 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) /* If we have elements of DST left over, free them all. */ for (; j < dsize; j++) { - ebitset_elt *delt; - changed = true; - delt = delts[j]; - + ebitset_elt *delt = delts[j]; if (delt) ebitset_elt_remove (dst, j); } @@ -1177,19 +1048,17 @@ ebitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) static bool ebitset_and_cmp (bitset dst, bitset src1, bitset src2) { - bool changed; - if (EBITSET_ZERO_P (src2)) { ebitset_weed (dst); - changed = EBITSET_ZERO_P (dst); + bool changed = EBITSET_ZERO_P (dst); ebitset_zero (dst); return changed; } else if (EBITSET_ZERO_P (src1)) { ebitset_weed (dst); - changed = EBITSET_ZERO_P (dst); + bool changed = EBITSET_ZERO_P (dst); ebitset_zero (dst); return changed; } @@ -1207,8 +1076,6 @@ ebitset_and (bitset dst, bitset src1, bitset src2) static bool ebitset_andn_cmp (bitset dst, bitset src1, bitset src2) { - bool changed; - if (EBITSET_ZERO_P (src2)) { return ebitset_copy_cmp (dst, src1); @@ -1216,7 +1083,7 @@ ebitset_andn_cmp (bitset dst, bitset src1, bitset src2) else if (EBITSET_ZERO_P (src1)) { ebitset_weed (dst); - changed = EBITSET_ZERO_P (dst); + bool changed = EBITSET_ZERO_P (dst); ebitset_zero (dst); return changed; } @@ -1279,9 +1146,9 @@ static void ebitset_copy (bitset dst, bitset src) { if (BITSET_COMPATIBLE_ (dst, src)) - ebitset_copy_ (dst, src); + ebitset_copy_ (dst, src); else - bitset_copy_ (dst, src); + bitset_copy_ (dst, src); } diff --git a/contrib/tools/bison/lib/ebitset.h b/contrib/tools/bison/lib/ebitset.h index e8036cd45e..97b9ee1522 100644 --- a/contrib/tools/bison/lib/ebitset.h +++ b/contrib/tools/bison/lib/ebitset.h @@ -23,10 +23,10 @@ #include "bitset.h" -extern size_t ebitset_bytes (bitset_bindex); +size_t ebitset_bytes (bitset_bindex); -extern bitset ebitset_init (bitset, bitset_bindex); +bitset ebitset_init (bitset, bitset_bindex); -extern void ebitset_release_memory (void); +void ebitset_release_memory (void); #endif diff --git a/contrib/tools/bison/lib/fcntl.c b/contrib/tools/bison/lib/fcntl.c index d09e6b180c..bdf1e5bbda 100644 --- a/contrib/tools/bison/lib/fcntl.c +++ b/contrib/tools/bison/lib/fcntl.c @@ -27,10 +27,10 @@ #include <stdarg.h> #include <unistd.h> -#if !HAVE_FCNTL -# define rpl_fcntl fcntl +#ifdef __KLIBC__ +# define INCL_DOS +# error #include <os2.h> #endif -#undef fcntl #if defined _WIN32 && ! defined __CYGWIN__ /* Get declarations of the native Windows API functions. */ @@ -166,93 +166,18 @@ dupfd (int oldfd, int newfd, int flags) } #endif /* W32 */ +/* Forward declarations, because we '#undef fcntl' in the middle of this + compilation unit. */ +/* Our implementation of fcntl (fd, F_DUPFD, target). */ +static int rpl_fcntl_DUPFD (int fd, int target); +/* Our implementation of fcntl (fd, F_DUPFD_CLOEXEC, target). */ +static int rpl_fcntl_DUPFD_CLOEXEC (int fd, int target); #ifdef __KLIBC__ - -# define INCL_DOS -# error #include <os2.h> - -static int -klibc_fcntl (int fd, int action, /* arg */...) -{ - va_list arg_ptr; - int arg; - struct stat sbuf; - int result = -1; - - va_start (arg_ptr, action); - arg = va_arg (arg_ptr, int); - result = fcntl (fd, action, arg); - /* EPERM for F_DUPFD, ENOTSUP for others */ - if (result == -1 && (errno == EPERM || errno == ENOTSUP) - && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode)) - { - ULONG ulMode; - - switch (action) - { - case F_DUPFD: - /* Find available fd */ - while (fcntl (arg, F_GETFL) != -1 || errno != EBADF) - arg++; - - result = dup2 (fd, arg); - break; - - /* Using underlying APIs is right ? */ - case F_GETFD: - if (DosQueryFHState (fd, &ulMode)) - break; - - result = (ulMode & OPEN_FLAGS_NOINHERIT) ? FD_CLOEXEC : 0; - break; - - case F_SETFD: - if (arg & ~FD_CLOEXEC) - break; - - if (DosQueryFHState (fd, &ulMode)) - break; - - if (arg & FD_CLOEXEC) - ulMode |= OPEN_FLAGS_NOINHERIT; - else - ulMode &= ~OPEN_FLAGS_NOINHERIT; - - /* Filter supported flags. */ - ulMode &= (OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR - | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT); - - if (DosSetFHState (fd, ulMode)) - break; - - result = 0; - break; - - case F_GETFL: - result = 0; - break; - - case F_SETFL: - if (arg != 0) - break; - - result = 0; - break; - - default : - errno = EINVAL; - break; - } - } - - va_end (arg_ptr); - - return result; -} - -# define fcntl klibc_fcntl +/* Adds support for fcntl on directories. */ +static int klibc_fcntl (int fd, int action, /* arg */...); #endif + /* Perform the specified ACTION on the file descriptor FD, possibly using the argument ARG further described below. This replacement handles the following actions, and forwards all others on to the @@ -273,105 +198,30 @@ klibc_fcntl (int fd, int action, /* arg */...) return -1 and set errno. */ int -rpl_fcntl (int fd, int action, /* arg */...) +fcntl (int fd, int action, /* arg */...) +#undef fcntl +#ifdef __KLIBC__ +# define fcntl klibc_fcntl +#endif { va_list arg; int result = -1; va_start (arg, action); switch (action) { - -#if !HAVE_FCNTL case F_DUPFD: { int target = va_arg (arg, int); - result = dupfd (fd, target, 0); + result = rpl_fcntl_DUPFD (fd, target); break; } -#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR - case F_DUPFD: - { - int target = va_arg (arg, int); - /* Detect invalid target; needed for cygwin 1.5.x. */ - if (target < 0 || getdtablesize () <= target) - errno = EINVAL; - else - { - /* Haiku alpha 2 loses fd flags on original. */ - int flags = fcntl (fd, F_GETFD); - if (flags < 0) - { - result = -1; - break; - } - result = fcntl (fd, action, target); - if (0 <= result && fcntl (fd, F_SETFD, flags) == -1) - { - int saved_errno = errno; - close (result); - result = -1; - errno = saved_errno; - } -# if REPLACE_FCHDIR - if (0 <= result) - result = _gl_register_dup (fd, result); -# endif - } - break; - } /* F_DUPFD */ -#endif /* FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR */ case F_DUPFD_CLOEXEC: { int target = va_arg (arg, int); - -#if !HAVE_FCNTL - result = dupfd (fd, target, O_CLOEXEC); - break; -#else /* HAVE_FCNTL */ - /* Try the system call first, if the headers claim it exists - (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we - may be running with a glibc that has the macro but with an - older kernel that does not support it. Cache the - information on whether the system call really works, but - avoid caching failure if the corresponding F_DUPFD fails - for any reason. 0 = unknown, 1 = yes, -1 = no. */ - static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0; - if (0 <= have_dupfd_cloexec) - { - result = fcntl (fd, action, target); - if (0 <= result || errno != EINVAL) - { - have_dupfd_cloexec = 1; -# if REPLACE_FCHDIR - if (0 <= result) - result = _gl_register_dup (fd, result); -# endif - } - else - { - result = rpl_fcntl (fd, F_DUPFD, target); - if (result < 0) - break; - have_dupfd_cloexec = -1; - } - } - else - result = rpl_fcntl (fd, F_DUPFD, target); - if (0 <= result && have_dupfd_cloexec == -1) - { - int flags = fcntl (result, F_GETFD); - if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1) - { - int saved_errno = errno; - close (result); - errno = saved_errno; - result = -1; - } - } + result = rpl_fcntl_DUPFD_CLOEXEC (fd, target); break; -#endif /* HAVE_FCNTL */ - } /* F_DUPFD_CLOEXEC */ + } #if !HAVE_FCNTL case F_GETFD: @@ -405,8 +255,183 @@ rpl_fcntl (int fd, int action, /* arg */...) default: { #if HAVE_FCNTL - void *p = va_arg (arg, void *); - result = fcntl (fd, action, p); + switch (action) + { + #ifdef F_BARRIERFSYNC /* macOS */ + case F_BARRIERFSYNC: + #endif + #ifdef F_CHKCLEAN /* macOS */ + case F_CHKCLEAN: + #endif + #ifdef F_CLOSEM /* NetBSD, HP-UX */ + case F_CLOSEM: + #endif + #ifdef F_FLUSH_DATA /* macOS */ + case F_FLUSH_DATA: + #endif + #ifdef F_FREEZE_FS /* macOS */ + case F_FREEZE_FS: + #endif + #ifdef F_FULLFSYNC /* macOS */ + case F_FULLFSYNC: + #endif + #ifdef F_GETCONFINED /* macOS */ + case F_GETCONFINED: + #endif + #ifdef F_GETDEFAULTPROTLEVEL /* macOS */ + case F_GETDEFAULTPROTLEVEL: + #endif + #ifdef F_GETFD /* POSIX */ + case F_GETFD: + #endif + #ifdef F_GETFL /* POSIX */ + case F_GETFL: + #endif + #ifdef F_GETLEASE /* Linux */ + case F_GETLEASE: + #endif + #ifdef F_GETNOSIGPIPE /* macOS */ + case F_GETNOSIGPIPE: + #endif + #ifdef F_GETOWN /* POSIX */ + case F_GETOWN: + #endif + #ifdef F_GETPIPE_SZ /* Linux */ + case F_GETPIPE_SZ: + #endif + #ifdef F_GETPROTECTIONCLASS /* macOS */ + case F_GETPROTECTIONCLASS: + #endif + #ifdef F_GETPROTECTIONLEVEL /* macOS */ + case F_GETPROTECTIONLEVEL: + #endif + #ifdef F_GET_SEALS /* Linux */ + case F_GET_SEALS: + #endif + #ifdef F_GETSIG /* Linux */ + case F_GETSIG: + #endif + #ifdef F_MAXFD /* NetBSD */ + case F_MAXFD: + #endif + #ifdef F_RECYCLE /* macOS */ + case F_RECYCLE: + #endif + #ifdef F_SETFIFOENH /* HP-UX */ + case F_SETFIFOENH: + #endif + #ifdef F_THAW_FS /* macOS */ + case F_THAW_FS: + #endif + /* These actions take no argument. */ + result = fcntl (fd, action); + break; + + #ifdef F_ADD_SEALS /* Linux */ + case F_ADD_SEALS: + #endif + #ifdef F_BADFD /* Solaris */ + case F_BADFD: + #endif + #ifdef F_CHECK_OPENEVT /* macOS */ + case F_CHECK_OPENEVT: + #endif + #ifdef F_DUP2FD /* FreeBSD, AIX, Solaris */ + case F_DUP2FD: + #endif + #ifdef F_DUP2FD_CLOEXEC /* FreeBSD, Solaris */ + case F_DUP2FD_CLOEXEC: + #endif + #ifdef F_DUP2FD_CLOFORK /* Solaris */ + case F_DUP2FD_CLOFORK: + #endif + #ifdef F_DUPFD /* POSIX */ + case F_DUPFD: + #endif + #ifdef F_DUPFD_CLOEXEC /* POSIX */ + case F_DUPFD_CLOEXEC: + #endif + #ifdef F_DUPFD_CLOFORK /* Solaris */ + case F_DUPFD_CLOFORK: + #endif + #ifdef F_GETXFL /* Solaris */ + case F_GETXFL: + #endif + #ifdef F_GLOBAL_NOCACHE /* macOS */ + case F_GLOBAL_NOCACHE: + #endif + #ifdef F_MAKECOMPRESSED /* macOS */ + case F_MAKECOMPRESSED: + #endif + #ifdef F_MOVEDATAEXTENTS /* macOS */ + case F_MOVEDATAEXTENTS: + #endif + #ifdef F_NOCACHE /* macOS */ + case F_NOCACHE: + #endif + #ifdef F_NODIRECT /* macOS */ + case F_NODIRECT: + #endif + #ifdef F_NOTIFY /* Linux */ + case F_NOTIFY: + #endif + #ifdef F_OPLKACK /* IRIX */ + case F_OPLKACK: + #endif + #ifdef F_OPLKREG /* IRIX */ + case F_OPLKREG: + #endif + #ifdef F_RDAHEAD /* macOS */ + case F_RDAHEAD: + #endif + #ifdef F_SETBACKINGSTORE /* macOS */ + case F_SETBACKINGSTORE: + #endif + #ifdef F_SETCONFINED /* macOS */ + case F_SETCONFINED: + #endif + #ifdef F_SETFD /* POSIX */ + case F_SETFD: + #endif + #ifdef F_SETFL /* POSIX */ + case F_SETFL: + #endif + #ifdef F_SETLEASE /* Linux */ + case F_SETLEASE: + #endif + #ifdef F_SETNOSIGPIPE /* macOS */ + case F_SETNOSIGPIPE: + #endif + #ifdef F_SETOWN /* POSIX */ + case F_SETOWN: + #endif + #ifdef F_SETPIPE_SZ /* Linux */ + case F_SETPIPE_SZ: + #endif + #ifdef F_SETPROTECTIONCLASS /* macOS */ + case F_SETPROTECTIONCLASS: + #endif + #ifdef F_SETSIG /* Linux */ + case F_SETSIG: + #endif + #ifdef F_SINGLE_WRITER /* macOS */ + case F_SINGLE_WRITER: + #endif + /* These actions take an 'int' argument. */ + { + int x = va_arg (arg, int); + result = fcntl (fd, action, x); + } + break; + + default: + /* Other actions take a pointer argument. */ + { + void *p = va_arg (arg, void *); + result = fcntl (fd, action, p); + } + break; + } #else errno = EINVAL; #endif @@ -416,3 +441,186 @@ rpl_fcntl (int fd, int action, /* arg */...) va_end (arg); return result; } + +static int +rpl_fcntl_DUPFD (int fd, int target) +{ + int result; +#if !HAVE_FCNTL + result = dupfd (fd, target, 0); +#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR + /* Detect invalid target; needed for cygwin 1.5.x. */ + if (target < 0 || getdtablesize () <= target) + { + result = -1; + errno = EINVAL; + } + else + { + /* Haiku alpha 2 loses fd flags on original. */ + int flags = fcntl (fd, F_GETFD); + if (flags < 0) + result = -1; + else + { + result = fcntl (fd, F_DUPFD, target); + if (0 <= result && fcntl (fd, F_SETFD, flags) == -1) + { + int saved_errno = errno; + close (result); + result = -1; + errno = saved_errno; + } +# if REPLACE_FCHDIR + if (0 <= result) + result = _gl_register_dup (fd, result); +# endif + } + } +#else + result = fcntl (fd, F_DUPFD, target); +#endif + return result; +} + +static int +rpl_fcntl_DUPFD_CLOEXEC (int fd, int target) +{ + int result; +#if !HAVE_FCNTL + result = dupfd (fd, target, O_CLOEXEC); +#else /* HAVE_FCNTL */ +# if defined __HAIKU__ + /* On Haiku, the system fcntl (fd, F_DUPFD_CLOEXEC, target) sets + the FD_CLOEXEC flag on fd, not on target. Therefore avoid the + system fcntl in this case. */ +# define have_dupfd_cloexec -1 +# else + /* Try the system call first, if the headers claim it exists + (that is, if GNULIB_defined_F_DUPFD_CLOEXEC is 0), since we + may be running with a glibc that has the macro but with an + older kernel that does not support it. Cache the + information on whether the system call really works, but + avoid caching failure if the corresponding F_DUPFD fails + for any reason. 0 = unknown, 1 = yes, -1 = no. */ + static int have_dupfd_cloexec = GNULIB_defined_F_DUPFD_CLOEXEC ? -1 : 0; + if (0 <= have_dupfd_cloexec) + { + result = fcntl (fd, F_DUPFD_CLOEXEC, target); + if (0 <= result || errno != EINVAL) + { + have_dupfd_cloexec = 1; +# if REPLACE_FCHDIR + if (0 <= result) + result = _gl_register_dup (fd, result); +# endif + } + else + { + result = rpl_fcntl_DUPFD (fd, target); + if (result >= 0) + have_dupfd_cloexec = -1; + } + } + else +# endif + result = rpl_fcntl_DUPFD (fd, target); + if (0 <= result && have_dupfd_cloexec == -1) + { + int flags = fcntl (result, F_GETFD); + if (flags < 0 || fcntl (result, F_SETFD, flags | FD_CLOEXEC) == -1) + { + int saved_errno = errno; + close (result); + errno = saved_errno; + result = -1; + } + } +#endif /* HAVE_FCNTL */ + return result; +} + +#undef fcntl + +#ifdef __KLIBC__ + +static int +klibc_fcntl (int fd, int action, /* arg */...); +{ + va_list arg_ptr; + int arg; + struct stat sbuf; + int result; + + va_start (arg_ptr, action); + arg = va_arg (arg_ptr, int); + result = fcntl (fd, action, arg); + /* EPERM for F_DUPFD, ENOTSUP for others */ + if (result == -1 && (errno == EPERM || errno == ENOTSUP) + && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode)) + { + ULONG ulMode; + + switch (action) + { + case F_DUPFD: + /* Find available fd */ + while (fcntl (arg, F_GETFL) != -1 || errno != EBADF) + arg++; + + result = dup2 (fd, arg); + break; + + /* Using underlying APIs is right ? */ + case F_GETFD: + if (DosQueryFHState (fd, &ulMode)) + break; + + result = (ulMode & OPEN_FLAGS_NOINHERIT) ? FD_CLOEXEC : 0; + break; + + case F_SETFD: + if (arg & ~FD_CLOEXEC) + break; + + if (DosQueryFHState (fd, &ulMode)) + break; + + if (arg & FD_CLOEXEC) + ulMode |= OPEN_FLAGS_NOINHERIT; + else + ulMode &= ~OPEN_FLAGS_NOINHERIT; + + /* Filter supported flags. */ + ulMode &= (OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR + | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT); + + if (DosSetFHState (fd, ulMode)) + break; + + result = 0; + break; + + case F_GETFL: + result = 0; + break; + + case F_SETFL: + if (arg != 0) + break; + + result = 0; + break; + + default: + errno = EINVAL; + break; + } + } + + va_end (arg_ptr); + + return result; +} + +#endif diff --git a/contrib/tools/bison/lib/gethrxtime.c b/contrib/tools/bison/lib/gethrxtime.c new file mode 100644 index 0000000000..97e57ad577 --- /dev/null +++ b/contrib/tools/bison/lib/gethrxtime.c @@ -0,0 +1,72 @@ +/* gethrxtime -- get high resolution real time + + Copyright (C) 2005-2007, 2009-2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#include <config.h> + +#define GETHRXTIME_INLINE _GL_EXTERN_INLINE +#include "gethrxtime.h" + +#if ! (HAVE_ARITHMETIC_HRTIME_T && HAVE_DECL_GETHRTIME) + +#include "timespec.h" + +/* Get the current time, as a count of the number of nanoseconds since + an arbitrary epoch (e.g., the system boot time). Prefer a + high-resolution clock that is not subject to resetting or + drifting. */ + +xtime_t +gethrxtime (void) +{ +# if HAVE_NANOUPTIME + { + struct timespec ts; + nanouptime (&ts); + return xtime_make (ts.tv_sec, ts.tv_nsec); + } +# else + +# if defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME + { + struct timespec ts; + if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0) + return xtime_make (ts.tv_sec, ts.tv_nsec); + } +# endif + +# if HAVE_MICROUPTIME + { + struct timeval tv; + microuptime (&tv); + return xtime_make (tv.tv_sec, 1000 * tv.tv_usec); + } + +# else + /* No monotonically increasing clocks are available; fall back on a + clock that might jump backwards, since it's the best we can do. */ + { + struct timespec ts; + timespec_get(&ts, TIME_UTC); + return xtime_make (ts.tv_sec, ts.tv_nsec); + } +# endif +# endif +} + +#endif diff --git a/contrib/tools/bison/lib/gethrxtime.h b/contrib/tools/bison/lib/gethrxtime.h new file mode 100644 index 0000000000..bb781911e2 --- /dev/null +++ b/contrib/tools/bison/lib/gethrxtime.h @@ -0,0 +1,55 @@ +/* gethrxtime -- get high resolution real time + + Copyright (C) 2005, 2009-2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#ifndef GETHRXTIME_H_ +#define GETHRXTIME_H_ 1 + +#include "xtime.h" + +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef GETHRXTIME_INLINE +# define GETHRXTIME_INLINE _GL_INLINE +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Get the current time, as a count of the number of nanoseconds since + an arbitrary epoch (e.g., the system boot time). Prefer a + high-resolution clock that is not subject to resetting or + drifting. */ + +#if HAVE_ARITHMETIC_HRTIME_T && HAVE_DECL_GETHRTIME +# include <time.h> +GETHRXTIME_INLINE xtime_t gethrxtime (void) { return gethrtime (); } +# else +xtime_t gethrxtime (void); +#endif + +_GL_INLINE_HEADER_END + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/contrib/tools/bison/lib/getprogname.c b/contrib/tools/bison/lib/getprogname.c index 43f37505ea..284581da24 100644 --- a/contrib/tools/bison/lib/getprogname.c +++ b/contrib/tools/bison/lib/getprogname.c @@ -110,9 +110,73 @@ getprogname (void) first = 0; pid_t pid = getpid (); struct pst_status status; - p = (0 < pstat_getproc (&status, sizeof status, 0, pid) - ? strdup (status.pst_ucomm) - : NULL); + if (pstat_getproc (&status, sizeof status, 0, pid) > 0) + { + char *ucomm = status.pst_ucomm; + char *cmd = status.pst_cmd; + if (strlen (ucomm) < PST_UCOMMLEN - 1) + p = ucomm; + else + { + /* ucomm is truncated to length PST_UCOMMLEN - 1. + Look at cmd instead. */ + char *space = strchr (cmd, ' '); + if (space != NULL) + *space = '\0'; + p = strrchr (cmd, '/'); + if (p != NULL) + p++; + else + p = cmd; + if (strlen (p) > PST_UCOMMLEN - 1 + && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0) + /* p is less truncated than ucomm. */ + ; + else + p = ucomm; + } + p = strdup (p); + } + else + { +# if !defined __LP64__ + /* Support for 32-bit programs running in 64-bit HP-UX. + The documented way to do this is to use the same source code + as above, but in a compilation unit where '#define _PSTAT64 1' + is in effect. I prefer a single compilation unit; the struct + size and the offsets are not going to change. */ + char status64[1216]; + if (__pstat_getproc64 (status64, sizeof status64, 0, pid) > 0) + { + char *ucomm = status64 + 288; + char *cmd = status64 + 168; + if (strlen (ucomm) < PST_UCOMMLEN - 1) + p = ucomm; + else + { + /* ucomm is truncated to length PST_UCOMMLEN - 1. + Look at cmd instead. */ + char *space = strchr (cmd, ' '); + if (space != NULL) + *space = '\0'; + p = strrchr (cmd, '/'); + if (p != NULL) + p++; + else + p = cmd; + if (strlen (p) > PST_UCOMMLEN - 1 + && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0) + /* p is less truncated than ucomm. */ + ; + else + p = ucomm; + } + p = strdup (p); + } + else +# endif + p = NULL; + } if (!p) p = "?"; } diff --git a/contrib/tools/bison/lib/intprops.h b/contrib/tools/bison/lib/intprops.h index 15e470cbc6..cdaf6586cb 100644 --- a/contrib/tools/bison/lib/intprops.h +++ b/contrib/tools/bison/lib/intprops.h @@ -22,12 +22,13 @@ #include <limits.h> -/* Return a value with the common real type of E and V and the value of V. */ -#define _GL_INT_CONVERT(e, v) (0 * (e) + (v)) +/* Return a value with the common real type of E and V and the value of V. + Do not evaluate E. */ +#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v)) /* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00406.html>. */ -#define _GL_INT_NEGATE_CONVERT(e, v) (0 * (e) - (v)) +#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v)) /* The extra casts in the following macros work around compiler bugs, e.g., in Cray C 5.0.3.0. */ @@ -40,13 +41,14 @@ #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) /* Return 1 if the real expression E, after promotion, has a - signed or floating type. */ + signed or floating type. Do not evaluate E. */ #define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0) /* Minimum and maximum values for integer types and expressions. */ /* The width in bits of the integer type or expression T. + Do not evaluate T. Padding bits are not supported; this is checked at compile-time below. */ #define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT) @@ -58,7 +60,7 @@ : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1))) /* The maximum and minimum values for the type of the expression E, - after integer promotion. E should not have side effects. */ + after integer promotion. E is not evaluated. */ #define _GL_INT_MINIMUM(e) \ (EXPR_SIGNED (e) \ ? ~ _GL_SIGNED_INT_MAXIMUM (e) \ @@ -340,8 +342,8 @@ Arguments should be free of side effects. */ #define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ op_result_overflow (a, b, \ - _GL_INT_MINIMUM (0 * (b) + (a)), \ - _GL_INT_MAXIMUM (0 * (b) + (a))) + _GL_INT_MINIMUM (_GL_INT_CONVERT (a, b)), \ + _GL_INT_MAXIMUM (_GL_INT_CONVERT (a, b))) /* Store the low-order bits of A + B, A - B, A * B, respectively, into *R. Return 1 if the result overflows. See above for restrictions. */ diff --git a/contrib/tools/bison/lib/lbitset.c b/contrib/tools/bison/lib/lbitset.c index 2ad6957d8b..705000929f 100644 --- a/contrib/tools/bison/lib/lbitset.c +++ b/contrib/tools/bison/lib/lbitset.c @@ -22,12 +22,13 @@ #include "lbitset.h" -#include "obstack.h" #include <stddef.h> -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> +#include "obstack.h" + /* This file implements linked-list bitsets. These bitsets can be of arbitrary length and are more efficient than arrays of bits for large sparse sets. @@ -108,21 +109,21 @@ lbitset_elt_alloc (void) /* Let particular systems override the size of a chunk. */ #ifndef OBSTACK_CHUNK_SIZE -#define OBSTACK_CHUNK_SIZE 0 +# define OBSTACK_CHUNK_SIZE 0 #endif /* Let them override the alloc and free routines too. */ #ifndef OBSTACK_CHUNK_ALLOC -#define OBSTACK_CHUNK_ALLOC xmalloc +# define OBSTACK_CHUNK_ALLOC xmalloc #endif #ifndef OBSTACK_CHUNK_FREE -#define OBSTACK_CHUNK_FREE free +# define OBSTACK_CHUNK_FREE free #endif #if ! defined __GNUC__ || __GNUC__ < 2 -#define __alignof__(type) 0 +# define __alignof__(type) 0 #endif obstack_specify_allocation (&lbitset_obstack, OBSTACK_CHUNK_SIZE, @@ -145,9 +146,7 @@ lbitset_elt_alloc (void) static inline lbitset_elt * lbitset_elt_calloc (void) { - lbitset_elt *elt; - - elt = lbitset_elt_alloc (); + lbitset_elt *elt = lbitset_elt_alloc (); memset (elt->words, 0, sizeof (elt->words)); return elt; } @@ -210,8 +209,6 @@ lbitset_elt_unlink (bitset bset, lbitset_elt *elt) static inline void lbitset_prune (bitset bset, lbitset_elt *elt) { - lbitset_elt *next; - if (!elt) return; @@ -230,6 +227,7 @@ lbitset_prune (bitset bset, lbitset_elt *elt) bset->b.csize = 0; } + lbitset_elt *next; for (; elt; elt = next) { next = elt->next; @@ -242,12 +240,9 @@ lbitset_prune (bitset bset, lbitset_elt *elt) static inline bool lbitset_elt_zero_p (lbitset_elt *elt) { - int i; - - for (i = 0; i < LBITSET_ELT_WORDS; i++) + for (int i = 0; i < LBITSET_ELT_WORDS; i++) if (elt->words[i]) return false; - return true; } @@ -257,13 +252,8 @@ static inline void lbitset_elt_link (bitset bset, lbitset_elt *elt) { bitset_windex windex = elt->index; - lbitset_elt *ptr; - lbitset_elt *current; - if (bset->b.csize) - current = LBITSET_CURRENT (bset); - else - current = LBITSET_HEAD (bset); + lbitset_elt *current = bset->b.csize ? LBITSET_CURRENT (bset) : LBITSET_HEAD (bset); /* If this is the first and only element, add it in. */ if (LBITSET_HEAD (bset) == 0) @@ -277,6 +267,7 @@ lbitset_elt_link (bitset bset, lbitset_elt *elt) somewhere before the current element. */ else if (windex < bset->b.cindex) { + lbitset_elt *ptr; for (ptr = current; ptr->prev && ptr->prev->index > windex; ptr = ptr->prev) continue; @@ -294,6 +285,7 @@ lbitset_elt_link (bitset bset, lbitset_elt *elt) /* Otherwise, it must go somewhere after the current element. */ else { + lbitset_elt *ptr; for (ptr = current; ptr->next && ptr->next->index < windex; ptr = ptr->next) continue; @@ -319,7 +311,6 @@ static lbitset_elt * lbitset_elt_find (bitset bset, bitset_windex windex, enum lbitset_find_mode mode) { - lbitset_elt *elt; lbitset_elt *current; if (bset->b.csize) @@ -336,6 +327,7 @@ lbitset_elt_find (bitset bset, bitset_windex windex, if (current) { + lbitset_elt *elt; if (windex < bset->b.cindex) { for (elt = current; @@ -371,8 +363,7 @@ lbitset_elt_find (bitset bset, bitset_windex windex, case LBITSET_CREATE: windex -= windex % LBITSET_ELT_WORDS; - - elt = lbitset_elt_calloc (); + lbitset_elt *elt = lbitset_elt_calloc (); elt->index = windex; lbitset_elt_link (bset, elt); return elt; @@ -387,10 +378,8 @@ lbitset_elt_find (bitset bset, bitset_windex windex, static inline void lbitset_weed (bitset bset) { - lbitset_elt *elt; lbitset_elt *next; - - for (elt = LBITSET_HEAD (bset); elt; elt = next) + for (lbitset_elt *elt = LBITSET_HEAD (bset); elt; elt = next) { next = elt->next; if (lbitset_elt_zero_p (elt)) @@ -403,9 +392,7 @@ lbitset_weed (bitset bset) static void lbitset_zero (bitset bset) { - lbitset_elt *head; - - head = LBITSET_HEAD (bset); + lbitset_elt *head = LBITSET_HEAD (bset); if (!head) return; @@ -418,22 +405,20 @@ lbitset_zero (bitset bset) static inline bool lbitset_equal_p (bitset dst, bitset src) { - lbitset_elt *selt; - lbitset_elt *delt; - int j; - if (src == dst) return true; lbitset_weed (src); lbitset_weed (dst); + lbitset_elt *selt; + lbitset_elt *delt; for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst); selt && delt; selt = selt->next, delt = delt->next) { if (selt->index != delt->index) return false; - for (j = 0; j < LBITSET_ELT_WORDS; j++) + for (int j = 0; j < LBITSET_ELT_WORDS; j++) if (delt->words[j] != selt->words[j]) return false; } @@ -445,22 +430,18 @@ lbitset_equal_p (bitset dst, bitset src) static inline void lbitset_copy (bitset dst, bitset src) { - lbitset_elt *elt; - lbitset_elt *head; - lbitset_elt *prev; - lbitset_elt *tmp; - if (src == dst) return; lbitset_zero (dst); - head = LBITSET_HEAD (src); + lbitset_elt *head = LBITSET_HEAD (src); if (!head) return; - prev = 0; - for (elt = head; elt; elt = elt->next) + lbitset_elt *prev = 0; + lbitset_elt *tmp; + for (lbitset_elt *elt = head; elt; elt = elt->next) { tmp = lbitset_elt_alloc (); tmp->index = elt->index; @@ -507,10 +488,10 @@ lbitset_copy_cmp (bitset dst, bitset src) static bitset_bindex lbitset_resize (bitset src, bitset_bindex size) { - BITSET_NBITS_ (src) = size; + BITSET_NBITS_ (src) = size; - /* Need to prune any excess bits. FIXME. */ - return size; + /* Need to prune any excess bits. FIXME. */ + return size; } /* Set bit BITNO in bitset DST. */ @@ -569,29 +550,19 @@ static bitset_bindex lbitset_list_reverse (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex rbitno; - bitset_bindex bitno; - unsigned bcount; - bitset_bindex boffset; - bitset_windex windex; - bitset_bindex count; - lbitset_elt *elt; - bitset_word word; - bitset_bindex n_bits; - - elt = LBITSET_TAIL (bset); + lbitset_elt *elt = LBITSET_TAIL (bset); if (!elt) return 0; - n_bits = (elt->index + LBITSET_ELT_WORDS) * BITSET_WORD_BITS; - rbitno = *next; + bitset_bindex n_bits = (elt->index + LBITSET_ELT_WORDS) * BITSET_WORD_BITS; + bitset_bindex rbitno = *next; if (rbitno >= n_bits) return 0; - bitno = n_bits - (rbitno + 1); + bitset_bindex bitno = n_bits - (rbitno + 1); - windex = bitno / BITSET_WORD_BITS; + bitset_windex windex = bitno / BITSET_WORD_BITS; /* Skip back to starting element. */ for (; elt && elt->index > windex; elt = elt->prev) @@ -600,6 +571,7 @@ lbitset_list_reverse (bitset bset, bitset_bindex *list, if (!elt) return 0; + unsigned bcount; if (windex >= elt->index + LBITSET_ELT_WORDS) { /* We are trying to start in no-mans land so start @@ -612,8 +584,8 @@ lbitset_list_reverse (bitset bset, bitset_bindex *list, bcount = bitno % BITSET_WORD_BITS; } - count = 0; - boffset = windex * BITSET_WORD_BITS; + bitset_bindex count = 0; + bitset_bindex boffset = windex * BITSET_WORD_BITS; /* If num is 1, we could speed things up with a binary search of the word of interest. */ @@ -626,7 +598,7 @@ lbitset_list_reverse (bitset bset, bitset_bindex *list, windex--, boffset -= BITSET_WORD_BITS, bcount = BITSET_WORD_BITS - 1) { - word = + bitset_word word = srcp[windex - elt->index] << (BITSET_WORD_BITS - 1 - bcount); for (; word; bcount--) @@ -658,25 +630,21 @@ lbitset_list_reverse (bitset bset, bitset_bindex *list, /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex lbitset_list (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_windex windex; - bitset_bindex count; - lbitset_elt *elt; - lbitset_elt *head; - bitset_word word; - - head = LBITSET_HEAD (bset); + lbitset_elt *head = LBITSET_HEAD (bset); if (!head) return 0; - bitno = *next; - count = 0; + bitset_windex windex; + lbitset_elt *elt; + + bitset_bindex bitno = *next; + bitset_bindex count = 0; if (!bitno) { @@ -713,7 +681,7 @@ lbitset_list (bitset bset, bitset_bindex *list, for (; (windex - elt->index) < LBITSET_ELT_WORDS; windex++) { - word = srcp[windex - elt->index] >> (bitno % BITSET_WORD_BITS); + bitset_word word = srcp[windex - elt->index] >> (bitno % BITSET_WORD_BITS); for (; word; bitno++) { @@ -746,7 +714,6 @@ lbitset_list (bitset bset, bitset_bindex *list, while (elt) { - int i; bitset_word *srcp = elt->words; if ((count + LBITSET_ELT_BITS) < num) @@ -754,7 +721,7 @@ lbitset_list (bitset bset, bitset_bindex *list, /* The coast is clear, plant boot! */ #if LBITSET_ELT_WORDS == 2 - word = srcp[0]; + bitset_word word = srcp[0]; if (word) { if (!(word & 0xffff)) @@ -795,9 +762,9 @@ lbitset_list (bitset bset, bitset_bindex *list, windex++; bitno = windex * BITSET_WORD_BITS; #else - for (i = 0; i < LBITSET_ELT_WORDS; i++) + for (int i = 0; i < LBITSET_ELT_WORDS; i++) { - word = srcp[i]; + bitset_word word = srcp[i]; if (word) { if (!(word & 0xffff)) @@ -827,9 +794,9 @@ lbitset_list (bitset bset, bitset_bindex *list, /* Tread more carefully since we need to check if array overflows. */ - for (i = 0; i < LBITSET_ELT_WORDS; i++) + for (int i = 0; i < LBITSET_ELT_WORDS; i++) { - for (word = srcp[i]; word; bitno++) + for (bitset_word word = srcp[i]; word; bitno++) { if (word & 1) { @@ -870,12 +837,12 @@ lbitset_empty_p (bitset dst) { next = elt->next; if (!lbitset_elt_zero_p (elt)) - return 0; + return false; /* Weed as we go. */ lbitset_elt_unlink (dst, elt); } - return 1; + return true; } @@ -883,21 +850,14 @@ lbitset_empty_p (bitset dst) static inline void lbitset_unused_clear (bitset dst) { - unsigned last_bit; - bitset_bindex n_bits; - - n_bits = BITSET_SIZE_ (dst); - last_bit = n_bits % LBITSET_ELT_BITS; + bitset_bindex n_bits = BITSET_SIZE_ (dst); + unsigned last_bit = n_bits % LBITSET_ELT_BITS; if (last_bit) { - lbitset_elt *elt; - bitset_windex windex; - bitset_word *srcp; - - elt = LBITSET_TAIL (dst); - srcp = elt->words; - windex = n_bits / BITSET_WORD_BITS; + lbitset_elt *elt = LBITSET_TAIL (dst); + bitset_word *srcp = elt->words; + bitset_windex windex = n_bits / BITSET_WORD_BITS; srcp[windex - elt->index] &= ((bitset_word) 1 << last_bit) - 1; windex++; @@ -911,21 +871,18 @@ lbitset_unused_clear (bitset dst) static void lbitset_ones (bitset dst) { - bitset_windex i; - bitset_windex windex; - lbitset_elt *elt; - /* This is a decidedly unfriendly operation for a linked list - bitset! It makes a sparse bitset become dense. An alternative - is to have a flag that indicates that the bitset stores the - complement of what it indicates. */ + bitset! It makes a sparse bitset become dense. An alternative + is to have a flag that indicates that the bitset stores the + complement of what it indicates. */ - windex = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS; + bitset_windex windex + = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS; - for (i = 0; i < windex; i += LBITSET_ELT_WORDS) + for (bitset_windex i = 0; i < windex; i += LBITSET_ELT_WORDS) { /* Create new elements if they cannot be found. */ - elt = lbitset_elt_find (dst, i, LBITSET_CREATE); + lbitset_elt *elt = lbitset_elt_find (dst, i, LBITSET_CREATE); memset (elt->words, -1, sizeof (elt->words)); } @@ -936,27 +893,21 @@ lbitset_ones (bitset dst) static void lbitset_not (bitset dst, bitset src) { - lbitset_elt *selt; - lbitset_elt *delt; - bitset_windex i; - unsigned j; - bitset_windex windex; + bitset_windex windex + = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS; - windex = (BITSET_SIZE_ (dst) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS; - - for (i = 0; i < windex; i += LBITSET_ELT_WORDS) + for (bitset_windex i = 0; i < windex; i += LBITSET_ELT_WORDS) { /* Create new elements for dst if they cannot be found or substitute zero elements if src elements not found. */ - selt = lbitset_elt_find (src, i, LBITSET_SUBST); - delt = lbitset_elt_find (dst, i, LBITSET_CREATE); + lbitset_elt *selt = lbitset_elt_find (src, i, LBITSET_SUBST); + lbitset_elt *delt = lbitset_elt_find (dst, i, LBITSET_CREATE); - for (j = 0; j < LBITSET_ELT_WORDS; j++) + for (unsigned j = 0; j < LBITSET_ELT_WORDS; j++) delt->words[j] = ~selt->words[j]; } lbitset_unused_clear (dst); lbitset_weed (dst); - return; } @@ -964,11 +915,7 @@ lbitset_not (bitset dst, bitset src) static bool lbitset_subset_p (bitset dst, bitset src) { - lbitset_elt *selt; - lbitset_elt *delt; - unsigned j; - - for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst); + for (lbitset_elt *selt = LBITSET_HEAD (src), *delt = LBITSET_HEAD (dst); selt || delt; selt = selt->next, delt = delt->next) { if (!selt) @@ -989,7 +936,7 @@ lbitset_subset_p (bitset dst, bitset src) } } - for (j = 0; j < LBITSET_ELT_WORDS; j++) + for (unsigned j = 0; j < LBITSET_ELT_WORDS; j++) if (delt->words[j] != (selt->words[j] | delt->words[j])) return false; } @@ -1001,11 +948,7 @@ lbitset_subset_p (bitset dst, bitset src) static bool lbitset_disjoint_p (bitset dst, bitset src) { - lbitset_elt *selt; - lbitset_elt *delt; - unsigned j; - - for (selt = LBITSET_HEAD (src), delt = LBITSET_HEAD (dst); + for (lbitset_elt *selt = LBITSET_HEAD (src), *delt = LBITSET_HEAD (dst); selt && delt; selt = selt->next, delt = delt->next) { if (selt->index != delt->index) @@ -1025,7 +968,7 @@ lbitset_disjoint_p (bitset dst, bitset src) continue; } - for (j = 0; j < LBITSET_ELT_WORDS; j++) + for (unsigned j = 0; j < LBITSET_ELT_WORDS; j++) if (selt->words[j] & delt->words[j]) return false; } @@ -1039,26 +982,20 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) lbitset_elt *selt1 = LBITSET_HEAD (src1); lbitset_elt *selt2 = LBITSET_HEAD (src2); lbitset_elt *delt = LBITSET_HEAD (dst); - bitset_windex windex1; - bitset_windex windex2; - bitset_windex windex; - lbitset_elt *stmp1; - lbitset_elt *stmp2; - lbitset_elt *dtmp; - bitset_word *srcp1; - bitset_word *srcp2; - bitset_word *dstp; bool changed = false; - unsigned i; LBITSET_HEAD (dst) = 0; dst->b.csize = 0; - windex1 = (selt1) ? selt1->index : BITSET_WINDEX_MAX; - windex2 = (selt2) ? selt2->index : BITSET_WINDEX_MAX; + bitset_windex windex1 = (selt1) ? selt1->index : BITSET_WINDEX_MAX; + bitset_windex windex2 = (selt2) ? selt2->index : BITSET_WINDEX_MAX; while (selt1 || selt2) { + bitset_windex windex; + lbitset_elt *stmp1; + lbitset_elt *stmp2; + /* Figure out whether we need to substitute zero elements for missing links. */ if (windex1 == windex2) @@ -1090,6 +1027,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) /* Find the appropriate element from DST. Begin by discarding elements that we've skipped. */ + lbitset_elt *dtmp; while (delt && delt->index < windex) { changed = true; @@ -1107,16 +1045,16 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) /* Do the operation, and if any bits are set, link it into the linked list. */ - srcp1 = stmp1->words; - srcp2 = stmp2->words; - dstp = dtmp->words; + bitset_word *srcp1 = stmp1->words; + bitset_word *srcp2 = stmp2->words; + bitset_word *dstp = dtmp->words; switch (op) { default: abort (); case BITSET_OP_OR: - for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ | *srcp2++; @@ -1129,7 +1067,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_AND: - for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ & *srcp2++; @@ -1142,7 +1080,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_XOR: - for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ ^ *srcp2++; @@ -1155,7 +1093,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) break; case BITSET_OP_ANDN: - for (i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) + for (unsigned i = 0; i < LBITSET_ELT_WORDS; i++, dstp++) { bitset_word tmp = *srcp1++ & ~(*srcp2++); @@ -1196,23 +1134,23 @@ lbitset_and_cmp (bitset dst, bitset src1, bitset src2) { lbitset_elt *selt1 = LBITSET_HEAD (src1); lbitset_elt *selt2 = LBITSET_HEAD (src2); - bool changed; if (!selt2) { lbitset_weed (dst); - changed = !LBITSET_HEAD (dst); + bool changed = !LBITSET_HEAD (dst); lbitset_zero (dst); return changed; } else if (!selt1) { lbitset_weed (dst); - changed = !LBITSET_HEAD (dst); + bool changed = !LBITSET_HEAD (dst); lbitset_zero (dst); return changed; } - return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND); + else + return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND); } @@ -1228,7 +1166,6 @@ lbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { lbitset_elt *selt1 = LBITSET_HEAD (src1); lbitset_elt *selt2 = LBITSET_HEAD (src2); - bool changed; if (!selt2) { @@ -1237,11 +1174,12 @@ lbitset_andn_cmp (bitset dst, bitset src1, bitset src2) else if (!selt1) { lbitset_weed (dst); - changed = !LBITSET_HEAD (dst); + bool changed = !LBITSET_HEAD (dst); lbitset_zero (dst); return changed; } - return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN); + else + return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN); } @@ -1259,14 +1197,11 @@ lbitset_or_cmp (bitset dst, bitset src1, bitset src2) lbitset_elt *selt2 = LBITSET_HEAD (src2); if (!selt2) - { - return lbitset_copy_cmp (dst, src1); - } + return lbitset_copy_cmp (dst, src1); else if (!selt1) - { - return lbitset_copy_cmp (dst, src2); - } - return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR); + return lbitset_copy_cmp (dst, src2); + else + return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR); } @@ -1284,14 +1219,11 @@ lbitset_xor_cmp (bitset dst, bitset src1, bitset src2) lbitset_elt *selt2 = LBITSET_HEAD (src2); if (!selt2) - { - return lbitset_copy_cmp (dst, src1); - } + return lbitset_copy_cmp (dst, src1); else if (!selt1) - { - return lbitset_copy_cmp (dst, src2); - } - return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR); + return lbitset_copy_cmp (dst, src2); + else + return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR); } @@ -1375,24 +1307,18 @@ lbitset_release_memory (void) void debug_lbitset (bitset bset) { - lbitset_elt *elt; - unsigned i; - if (!bset) return; - for (elt = LBITSET_HEAD (bset); elt; elt = elt->next) + for (lbitset_elt *elt = LBITSET_HEAD (bset); elt; elt = elt->next) { fprintf (stderr, "Elt %lu\n", (unsigned long) elt->index); - for (i = 0; i < LBITSET_ELT_WORDS; i++) + for (unsigned i = 0; i < LBITSET_ELT_WORDS; i++) { - unsigned j; - bitset_word word; - - word = elt->words[i]; + bitset_word word = elt->words[i]; fprintf (stderr, " Word %u:", i); - for (j = 0; j < LBITSET_WORD_BITS; j++) + for (unsigned j = 0; j < LBITSET_WORD_BITS; j++) if ((word & ((bitset_word) 1 << j))) fprintf (stderr, " %u", j); fprintf (stderr, "\n"); diff --git a/contrib/tools/bison/lib/lbitset.h b/contrib/tools/bison/lib/lbitset.h index 4aced06d65..b9d266dafb 100644 --- a/contrib/tools/bison/lib/lbitset.h +++ b/contrib/tools/bison/lib/lbitset.h @@ -23,10 +23,10 @@ #include "bitset.h" -extern size_t lbitset_bytes (bitset_bindex); +size_t lbitset_bytes (bitset_bindex); -extern bitset lbitset_init (bitset, bitset_bindex); +bitset lbitset_init (bitset, bitset_bindex); -extern void lbitset_release_memory (void); +void lbitset_release_memory (void); #endif diff --git a/contrib/tools/bison/lib/libiberty.h b/contrib/tools/bison/lib/libiberty.h deleted file mode 100644 index 7628fc1298..0000000000 --- a/contrib/tools/bison/lib/libiberty.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Fake libiberty.h for Bison. - - Copyright (C) 2002-2004, 2009-2015, 2018 Free Software Foundation, - Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. */ - - -/* Bison depends on libiberty's implementation of bitsets, which - requires a 'libiberty.h' file. This file provides the minimum - services. */ - -#ifndef BISON_LIBIBERTY_H_ -# define BISON_LIBIBERTY_H_ 1 - -# ifndef __attribute__ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) -# define __attribute__(x) -# endif -# endif - -# define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) - -# include "xalloc.h" - -#endif /* ! BISON_LIBIBERTY_H_ */ diff --git a/contrib/tools/bison/lib/localtime-buffer.c b/contrib/tools/bison/lib/localtime-buffer.c new file mode 100644 index 0000000000..df11f4321d --- /dev/null +++ b/contrib/tools/bison/lib/localtime-buffer.c @@ -0,0 +1,58 @@ +/* Provide access to the last buffer returned by localtime() or gmtime(). + + Copyright (C) 2001-2003, 2005-2007, 2009-2018 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <https://www.gnu.org/licenses/>. */ + +/* written by Jim Meyering */ + +#include <config.h> + +/* Specification. */ +#include "localtime-buffer.h" + +#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME + +static struct tm tm_zero_buffer; +struct tm *localtime_buffer_addr = &tm_zero_buffer; + +/* This is a wrapper for localtime. + + On the first call, record the address of the static buffer that + localtime uses for its result. */ + +struct tm * +rpl_localtime (time_t const *timep) +{ + struct tm *tm = localtime (timep); + + if (localtime_buffer_addr == &tm_zero_buffer) + localtime_buffer_addr = tm; + + return tm; +} + +/* Same as above, since gmtime and localtime use the same buffer. */ +struct tm * +rpl_gmtime (time_t const *timep) +{ + struct tm *tm = gmtime (timep); + + if (localtime_buffer_addr == &tm_zero_buffer) + localtime_buffer_addr = tm; + + return tm; +} + +#endif diff --git a/contrib/tools/bison/lib/localtime-buffer.h b/contrib/tools/bison/lib/localtime-buffer.h new file mode 100644 index 0000000000..f381ff0e6d --- /dev/null +++ b/contrib/tools/bison/lib/localtime-buffer.h @@ -0,0 +1,27 @@ +/* Provide access to the last buffer returned by localtime() or gmtime(). + + Copyright (C) 2001-2003, 2005-2007, 2009-2018 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <https://www.gnu.org/licenses/>. */ + +/* written by Jim Meyering */ + +#include <time.h> + +#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME + +/* The address of the last buffer returned by localtime() or gmtime(). */ +extern struct tm *localtime_buffer_addr; + +#endif diff --git a/contrib/tools/bison/lib/path-join.c b/contrib/tools/bison/lib/path-join.c new file mode 100644 index 0000000000..73560b445d --- /dev/null +++ b/contrib/tools/bison/lib/path-join.c @@ -0,0 +1,37 @@ +/* Concatenate path components. + Copyright (C) 2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Akim Demaille <akim@lrde.epita.fr>. */ + +#include <config.h> + +/* Specification. */ +#include "path-join.h" + +#include <concat-filename.h> /* xconcatenated_filename */ +#include <filename.h> /* IS_ABSOLUTE_PATH */ +#include <xalloc.h> /* xstrdup */ + +char * +xpath_join (const char *path1, const char *path2) +{ + if (!path2 || !*path2) + return xstrdup (path1); + else if (IS_ABSOLUTE_PATH (path2)) + return xstrdup (path2); + else + return xconcatenated_filename (path1, path2, NULL); +} diff --git a/contrib/tools/bison/lib/path-join.h b/contrib/tools/bison/lib/path-join.h new file mode 100644 index 0000000000..baa472a97c --- /dev/null +++ b/contrib/tools/bison/lib/path-join.h @@ -0,0 +1,38 @@ +/* Concatenate path components. + Copyright (C) 2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Akim Demaille <akim@lrde.epita.fr>. */ + +#ifndef _PATH_JOIN_H +# define _PATH_JOIN_H + +# ifdef __cplusplus +extern "C" { +# endif + + +/* Concatenate two paths together. PATH2 may be null, or empty, or + absolute: do what is right. Return a freshly allocated + filename. */ +char * +xpath_join (const char *path1, const char *path2); + + +# ifdef __cplusplus +} +# endif + +#endif /* _PATH_JOIN_H */ diff --git a/contrib/tools/bison/lib/raise.c b/contrib/tools/bison/lib/raise.c index 3a29339a66..8a93bea7f7 100644 --- a/contrib/tools/bison/lib/raise.c +++ b/contrib/tools/bison/lib/raise.c @@ -31,27 +31,9 @@ # include "msvc-inval.h" # endif -# undef raise - # if HAVE_MSVC_INVALID_PARAMETER_HANDLER -static int -raise_nothrow (int sig) -{ - int result; - - TRY_MSVC_INVAL - { - result = raise (sig); - } - CATCH_MSVC_INVAL - { - result = -1; - errno = EINVAL; - } - DONE_MSVC_INVAL; - - return result; -} +/* Forward declaration. */ +static int raise_nothrow (int sig); # else # define raise_nothrow raise # endif @@ -61,12 +43,11 @@ raise_nothrow (int sig) # include <unistd.h> -# define rpl_raise raise - #endif int -rpl_raise (int sig) +raise (int sig) +#undef raise { #if GNULIB_defined_signal_blocking && GNULIB_defined_SIGPIPE if (sig == SIGPIPE) @@ -79,3 +60,24 @@ rpl_raise (int sig) return kill (getpid (), sig); #endif } + +#if HAVE_RAISE && HAVE_MSVC_INVALID_PARAMETER_HANDLER +static int +raise_nothrow (int sig) +{ + int result; + + TRY_MSVC_INVAL + { + result = raise (sig); + } + CATCH_MSVC_INVAL + { + result = -1; + errno = EINVAL; + } + DONE_MSVC_INVAL; + + return result; +} +#endif diff --git a/contrib/tools/bison/lib/stat-time.h b/contrib/tools/bison/lib/stat-time.h index 8e787bd3b2..69ebe85df1 100644 --- a/contrib/tools/bison/lib/stat-time.h +++ b/contrib/tools/bison/lib/stat-time.h @@ -213,7 +213,7 @@ stat_time_normalize (int result, struct stat *st _GL_UNUSED) #if defined __sun && defined STAT_TIMESPEC if (result == 0) { - long int timespec_resolution = 1000000000; + long int timespec_hz = 1000000000; short int const ts_off[] = { offsetof (struct stat, st_atim), offsetof (struct stat, st_mtim), offsetof (struct stat, st_ctim) }; @@ -221,11 +221,11 @@ stat_time_normalize (int result, struct stat *st _GL_UNUSED) for (i = 0; i < sizeof ts_off / sizeof *ts_off; i++) { struct timespec *ts = (struct timespec *) ((char *) st + ts_off[i]); - long int q = ts->tv_nsec / timespec_resolution; - long int r = ts->tv_nsec % timespec_resolution; + long int q = ts->tv_nsec / timespec_hz; + long int r = ts->tv_nsec % timespec_hz; if (r < 0) { - r += timespec_resolution; + r += timespec_hz; q--; } ts->tv_nsec = r; diff --git a/contrib/tools/bison/lib/timespec.c b/contrib/tools/bison/lib/timespec.c new file mode 100644 index 0000000000..2b6098ed7b --- /dev/null +++ b/contrib/tools/bison/lib/timespec.c @@ -0,0 +1,3 @@ +#include <config.h> +#define _GL_TIMESPEC_INLINE _GL_EXTERN_INLINE +#include "timespec.h" diff --git a/contrib/tools/bison/lib/timespec.h b/contrib/tools/bison/lib/timespec.h new file mode 100644 index 0000000000..cc49668f42 --- /dev/null +++ b/contrib/tools/bison/lib/timespec.h @@ -0,0 +1,136 @@ +/* timespec -- System time interface + + Copyright (C) 2000, 2002, 2004-2005, 2007, 2009-2018 Free Software + Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +#if ! defined TIMESPEC_H +#define TIMESPEC_H + +#include <time.h> + +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef _GL_TIMESPEC_INLINE +# define _GL_TIMESPEC_INLINE _GL_INLINE +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#include "arg-nonnull.h" +#include "verify.h" + +/* Inverse resolution of timespec timestamps (in units per second), + and log base 10 of the inverse resolution. */ + +enum { TIMESPEC_HZ = 1000000000 }; +enum { LOG10_TIMESPEC_HZ = 9 }; + +/* Obsolescent names for backward compatibility. + They are misnomers, because TIMESPEC_RESOLUTION is not a resolution. */ + +enum { TIMESPEC_RESOLUTION = TIMESPEC_HZ }; +enum { LOG10_TIMESPEC_RESOLUTION = LOG10_TIMESPEC_HZ }; + +/* Return a timespec with seconds S and nanoseconds NS. */ + +_GL_TIMESPEC_INLINE struct timespec +make_timespec (time_t s, long int ns) +{ + struct timespec r; + r.tv_sec = s; + r.tv_nsec = ns; + return r; +} + +/* Return negative, zero, positive if A < B, A == B, A > B, respectively. + + For each timestamp T, this code assumes that either: + + * T.tv_nsec is in the range 0..999999999; or + * T.tv_sec corresponds to a valid leap second on a host that supports + leap seconds, and T.tv_nsec is in the range 1000000000..1999999999; or + * T.tv_sec is the minimum time_t value and T.tv_nsec is -1; or + T.tv_sec is the maximum time_t value and T.tv_nsec is 2000000000. + This allows for special struct timespec values that are less or + greater than all possible valid timestamps. + + In all these cases, it is safe to subtract two tv_nsec values and + convert the result to integer without worrying about overflow on + any platform of interest to the GNU project, since all such + platforms have 32-bit int or wider. + + Replacing "a.tv_nsec - b.tv_nsec" with something like + "a.tv_nsec < b.tv_nsec ? -1 : a.tv_nsec > b.tv_nsec" would cause + this function to work in some cases where the above assumption is + violated, but not in all cases (e.g., a.tv_sec==1, a.tv_nsec==-2, + b.tv_sec==0, b.tv_nsec==999999999) and is arguably not worth the + extra instructions. Using a subtraction has the advantage of + detecting some invalid cases on platforms that detect integer + overflow. */ + +_GL_TIMESPEC_INLINE int _GL_ATTRIBUTE_PURE +timespec_cmp (struct timespec a, struct timespec b) +{ + if (a.tv_sec < b.tv_sec) + return -1; + if (a.tv_sec > b.tv_sec) + return 1; + + /* Pacify gcc -Wstrict-overflow (bleeding-edge circa 2017-10-02). See: + https://lists.gnu.org/r/bug-gnulib/2017-10/msg00006.html */ + assume (-1 <= a.tv_nsec && a.tv_nsec <= 2 * TIMESPEC_HZ); + assume (-1 <= b.tv_nsec && b.tv_nsec <= 2 * TIMESPEC_HZ); + + return a.tv_nsec - b.tv_nsec; +} + +/* Return -1, 0, 1, depending on the sign of A. A.tv_nsec must be + nonnegative. */ +_GL_TIMESPEC_INLINE int _GL_ATTRIBUTE_PURE +timespec_sign (struct timespec a) +{ + return a.tv_sec < 0 ? -1 : a.tv_sec || a.tv_nsec; +} + +struct timespec timespec_add (struct timespec, struct timespec) + _GL_ATTRIBUTE_CONST; +struct timespec timespec_sub (struct timespec, struct timespec) + _GL_ATTRIBUTE_CONST; +struct timespec dtotimespec (double) + _GL_ATTRIBUTE_CONST; + +/* Return an approximation to A, of type 'double'. */ +_GL_TIMESPEC_INLINE double +timespectod (struct timespec a) +{ + return a.tv_sec + a.tv_nsec / 1e9; +} + +struct timespec current_timespec (void); +void gettime (struct timespec *) _GL_ARG_NONNULL ((1)); +int settime (struct timespec const *) _GL_ARG_NONNULL ((1)); + +#ifdef __cplusplus +} +#endif + +_GL_INLINE_HEADER_END + +#endif diff --git a/contrib/tools/bison/lib/timevar.c b/contrib/tools/bison/lib/timevar.c index e780c303fc..46b8a689b4 100644 --- a/contrib/tools/bison/lib/timevar.c +++ b/contrib/tools/bison/lib/timevar.c @@ -20,121 +20,21 @@ #include <config.h> -#if IN_GCC - -#error #include "system.h" -#include "intl.h" -#include "rtl.h" - -#else - -/* This source file is taken from the GCC source code, with slight - modifications that are under control of the IN_GCC preprocessor - variable. The !IN_GCC part of this file is specific to Bison. */ - -# include "../src/system.h" -# if HAVE_SYS_TIME_H -# include <sys/time.h> -# endif -int timevar_report = 0; - -#endif - - -#ifdef HAVE_SYS_TIMES_H -# include <sys/times.h> -#endif -#ifdef HAVE_SYS_RESOURCE_H -#include <sys/resource.h> -#endif +/* Specification. */ +#include "timevar.h" -#ifndef HAVE_CLOCK_T -typedef int clock_t; -#endif +#include <stdio.h> +#include <stdlib.h> +#include <string.h> -#ifndef HAVE_STRUCT_TMS -struct tms -{ - clock_t tms_utime; - clock_t tms_stime; - clock_t tms_cutime; - clock_t tms_cstime; -}; -#endif - -#if defined HAVE_DECL_GETRUSAGE && !HAVE_DECL_GETRUSAGE -extern int getrusage (int, struct rusage *); -#endif -#if defined HAVE_DECL_TIMES && !HAVE_DECL_TIMES -extern clock_t times (struct tms *); -#endif -#if defined HAVE_DECL_CLOCK && !HAVE_DECL_CLOCK -extern clock_t clock (void); -#endif - -#ifndef RUSAGE_SELF -# define RUSAGE_SELF 0 -#endif - -/* Calculation of scale factor to convert ticks to microseconds. - We mustn't use CLOCKS_PER_SEC except with clock(). */ -#if HAVE_SYSCONF && defined _SC_CLK_TCK -# define TICKS_PER_SECOND sysconf (_SC_CLK_TCK) /* POSIX 1003.1-1996 */ -#else -# ifdef CLK_TCK -# define TICKS_PER_SECOND CLK_TCK /* POSIX 1003.1-1988; obsolescent */ -# else -# ifdef HZ -# define TICKS_PER_SECOND HZ /* traditional UNIX */ -# else -# define TICKS_PER_SECOND 100 /* often the correct value */ -# endif -# endif -#endif - -/* Prefer times to getrusage to clock (each gives successively less - information). */ -#ifdef HAVE_TIMES -# define USE_TIMES -# define HAVE_USER_TIME -# define HAVE_SYS_TIME -# define HAVE_WALL_TIME -#else -#ifdef HAVE_GETRUSAGE -# define USE_GETRUSAGE -# define HAVE_USER_TIME -# define HAVE_SYS_TIME -#else -#ifdef HAVE_CLOCK -# define USE_CLOCK -# define HAVE_USER_TIME -#endif -#endif -#endif - -/* libc is very likely to have snuck a call to sysconf() into one of - the underlying constants, and that can be very slow, so we have to - precompute them. Whose wonderful idea was it to make all those - _constants_ variable at run time, anyway? */ -#ifdef USE_TIMES -static float ticks_to_msec; -#define TICKS_TO_MSEC (1.0 / TICKS_PER_SECOND) -#endif - -#ifdef USE_CLOCK -static float clocks_to_msec; -#define CLOCKS_TO_MSEC (1.0 / CLOCKS_PER_SEC) -#endif - -#if IN_GCC -#include "flags.h" -#endif -#include "timevar.h" +#include "gethrxtime.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) +#include "xalloc.h" /* See timevar.h for an explanation of timing variables. */ -/* This macro evaluates to nonzero if timing variables are enabled. */ -#define TIMEVAR_ENABLE (timevar_report) +int timevar_enabled = 0; /* A timing variable. */ @@ -187,73 +87,60 @@ static struct timevar_stack_def *unused_stack_instances; element. */ static struct timevar_time_def start_time; -static void get_time (struct timevar_time_def *); -static void timevar_accumulate (struct timevar_time_def *, - struct timevar_time_def *, - struct timevar_time_def *); - -/* Fill the current times into TIME. The definition of this function - also defines any or all of the HAVE_USER_TIME, HAVE_SYS_TIME, and - HAVE_WALL_TIME macros. */ +/* Fill the current times into TIME. */ static void -get_time (now) - struct timevar_time_def *now; +set_to_current_time (struct timevar_time_def *now) { now->user = 0; now->sys = 0; now->wall = 0; - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; + /* + struct rusage self; + getrusage (RUSAGE_SELF, &self); + struct rusage chld; + getrusage (RUSAGE_CHILDREN, &chld); + + now->user = + xtime_make (self.ru_utime.tv_sec + chld.ru_utime.tv_sec, + (self.ru_utime.tv_usec + chld.ru_utime.tv_usec) * 1000); + + now->sys = + xtime_make (self.ru_stime.tv_sec + chld.ru_stime.tv_sec, + (self.ru_stime.tv_usec + chld.ru_stime.tv_usec) * 1000); + */ + now->wall = gethrxtime(); +} + +/* Return the current time. */ - { -#ifdef USE_TIMES - struct tms tms; - now->wall = times (&tms) * ticks_to_msec; -#if IN_GCC - now->user = tms.tms_utime * ticks_to_msec; - now->sys = tms.tms_stime * ticks_to_msec; -#else - now->user = (tms.tms_utime + tms.tms_cutime) * ticks_to_msec; - now->sys = (tms.tms_stime + tms.tms_cstime) * ticks_to_msec; -#endif -#endif -#ifdef USE_GETRUSAGE - struct rusage rusage; -#if IN_GCC - getrusage (RUSAGE_SELF, &rusage); -#else - getrusage (RUSAGE_CHILDREN, &rusage); -#endif - now->user = rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6; - now->sys = rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6; -#endif -#ifdef USE_CLOCK - now->user = clock () * clocks_to_msec; -#endif - } +static struct timevar_time_def +get_current_time (void) +{ + struct timevar_time_def now; + set_to_current_time (&now); + return now; } /* Add the difference between STOP and START to TIMER. */ static void -timevar_accumulate (timer, start, stop) - struct timevar_time_def *timer; - struct timevar_time_def *start; - struct timevar_time_def *stop; +timevar_accumulate (struct timevar_time_def *timer, + const struct timevar_time_def *start, + const struct timevar_time_def *stop) { timer->user += stop->user - start->user; timer->sys += stop->sys - start->sys; timer->wall += stop->wall - start->wall; } -/* Initialize timing variables. */ - void -init_timevar () +timevar_init () { - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; /* Zero all elapsed times. */ @@ -264,33 +151,16 @@ init_timevar () timevars[identifier__].name = name__; #include "timevar.def" #undef DEFTIMEVAR - -#ifdef USE_TIMES - ticks_to_msec = TICKS_TO_MSEC; -#endif -#ifdef USE_CLOCK - clocks_to_msec = CLOCKS_TO_MSEC; -#endif } -/* Push TIMEVAR onto the timing stack. No further elapsed time is - attributed to the previous topmost timing variable on the stack; - subsequent elapsed time is attributed to TIMEVAR, until it is - popped or another element is pushed on top. - - TIMEVAR cannot be running as a standalone timer. */ - void -timevar_push (timevar) - timevar_id_t timevar; +timevar_push (timevar_id_t timevar) { - struct timevar_def *tv = &timevars[timevar]; - struct timevar_stack_def *context; - struct timevar_time_def now; - - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; + struct timevar_def *tv = &timevars[timevar]; + /* Mark this timing variable as used. */ tv->used = 1; @@ -299,7 +169,7 @@ timevar_push (timevar) abort (); /* What time is it? */ - get_time (&now); + struct timevar_time_def const now = get_current_time (); /* If the stack isn't empty, attribute the current elapsed time to the old topmost element. */ @@ -312,6 +182,7 @@ timevar_push (timevar) /* See if we have a previously-allocated stack instance. If so, take it off the list. If not, malloc a new one. */ + struct timevar_stack_def *context = NULL; if (unused_stack_instances != NULL) { context = unused_stack_instances; @@ -327,29 +198,20 @@ timevar_push (timevar) stack = context; } -/* Pop the topmost timing variable element off the timing stack. The - popped variable must be TIMEVAR. Elapsed time since the that - element was pushed on, or since it was last exposed on top of the - stack when the element above it was popped off, is credited to that - timing variable. */ - void -timevar_pop (timevar) - timevar_id_t timevar; +timevar_pop (timevar_id_t timevar) { - struct timevar_time_def now; - struct timevar_stack_def *popped = stack; - - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; if (&timevars[timevar] != stack->timevar) abort (); /* What time is it? */ - get_time (&now); + struct timevar_time_def const now = get_current_time (); /* Attribute the elapsed time to the element we're popping. */ + struct timevar_stack_def *popped = stack; timevar_accumulate (&popped->timevar->elapsed, &start_time, &now); /* Reset the start time; from now on, time is attributed to the @@ -365,19 +227,14 @@ timevar_pop (timevar) unused_stack_instances = popped; } -/* Start timing TIMEVAR independently of the timing stack. Elapsed - time until timevar_stop is called for the same timing variable is - attributed to TIMEVAR. */ - void -timevar_start (timevar) - timevar_id_t timevar; +timevar_start (timevar_id_t timevar) { - struct timevar_def *tv = &timevars[timevar]; - - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; + struct timevar_def *tv = &timevars[timevar]; + /* Mark this timing variable as used. */ tv->used = 1; @@ -387,72 +244,50 @@ timevar_start (timevar) abort (); tv->standalone = 1; - get_time (&tv->start_time); + set_to_current_time (&tv->start_time); } -/* Stop timing TIMEVAR. Time elapsed since timevar_start was called - is attributed to it. */ - void -timevar_stop (timevar) - timevar_id_t timevar; +timevar_stop (timevar_id_t timevar) { - struct timevar_def *tv = &timevars[timevar]; - struct timevar_time_def now; - - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; + struct timevar_def *tv = &timevars[timevar]; + /* TIMEVAR must have been started via timevar_start. */ if (!tv->standalone) abort (); - get_time (&now); + struct timevar_time_def const now = get_current_time (); timevar_accumulate (&tv->elapsed, &tv->start_time, &now); } -/* Fill the elapsed time for TIMEVAR into ELAPSED. Returns - update-to-date information even if TIMEVAR is currently running. */ - void -timevar_get (timevar, elapsed) - timevar_id_t timevar; - struct timevar_time_def *elapsed; +timevar_get (timevar_id_t timevar, + struct timevar_time_def *elapsed) { struct timevar_def *tv = &timevars[timevar]; - struct timevar_time_def now; - *elapsed = tv->elapsed; /* Is TIMEVAR currently running as a standalone timer? */ if (tv->standalone) { - get_time (&now); + struct timevar_time_def const now = get_current_time (); timevar_accumulate (elapsed, &tv->start_time, &now); } /* Or is TIMEVAR at the top of the timer stack? */ else if (stack->timevar == tv) { - get_time (&now); + struct timevar_time_def const now = get_current_time (); timevar_accumulate (elapsed, &start_time, &now); } } -/* Summarize timing variables to FP. The timing variable TV_TOTAL has - a special meaning -- it's considered to be the total elapsed time, - for normalizing the others, and is displayed last. */ - void -timevar_print (fp) - FILE *fp; +timevar_print (FILE *fp) { - /* Only print stuff if we have some sort of time information. */ -#if defined HAVE_USER_TIME || defined HAVE_SYS_TIME || defined HAVE_WALL_TIME - unsigned /* timevar_id_t */ id; - struct timevar_time_def *total = &timevars[TV_TOTAL].elapsed; - struct timevar_time_def now; - - if (!TIMEVAR_ENABLE) + if (!timevar_enabled) return; /* Update timing information in case we're calling this from GDB. */ @@ -461,7 +296,7 @@ timevar_print (fp) fp = stderr; /* What time is it? */ - get_time (&now); + struct timevar_time_def const now = get_current_time (); /* If the stack isn't empty, attribute the current elapsed time to the old topmost element. */ @@ -472,94 +307,42 @@ timevar_print (fp) TIMEVAR. */ start_time = now; - fputs (_("\nExecution times (seconds)\n"), fp); - for (id = 0; id < (unsigned) TIMEVAR_LAST; ++id) - { - struct timevar_def *tv = &timevars[(timevar_id_t) id]; - const float tiny = 5e-3; + struct timevar_time_def const* total = &timevars[tv_total].elapsed; + fprintf (fp, "%-22s\n", + _("Execution times (seconds)")); + fprintf (fp, " %-22s %-13s %-13s %-16s\n", + "", _("CPU user"), _("CPU system"), _("wall clock")); + for (unsigned /* timevar_id_t */ id = 0; id < (unsigned) TIMEVAR_LAST; ++id) + { /* Don't print the total execution time here; that goes at the end. */ - if ((timevar_id_t) id == TV_TOTAL) + if ((timevar_id_t) id == tv_total) continue; /* Don't print timing variables that were never used. */ + struct timevar_def *tv = &timevars[(timevar_id_t) id]; if (!tv->used) continue; - /* Don't print timing variables if we're going to get a row of - zeroes. */ - if (tv->elapsed.user < tiny - && tv->elapsed.sys < tiny - && tv->elapsed.wall < tiny) + /* Percentages. */ + const int usr = total->user ? tv->elapsed.user * 100 / total->user : 0; + const int sys = total->sys ? tv->elapsed.sys * 100 / total->sys : 0; + const int wall = total->wall ? tv->elapsed.wall * 100 / total->wall : 0; + + /* Ignore insignificant lines. */ + if (!usr && !sys && !wall) continue; - /* The timing variable name. */ - fprintf (fp, " %-22s:", tv->name); - -#ifdef HAVE_USER_TIME - /* Print user-mode time for this process. */ - fprintf (fp, "%7.2f (%2.0f%%) usr", - tv->elapsed.user, - (total->user == 0 ? 0 : tv->elapsed.user / total->user) * 100); -#endif /* HAVE_USER_TIME */ - -#ifdef HAVE_SYS_TIME - /* Print system-mode time for this process. */ - fprintf (fp, "%7.2f (%2.0f%%) sys", - tv->elapsed.sys, - (total->sys == 0 ? 0 : tv->elapsed.sys / total->sys) * 100); -#endif /* HAVE_SYS_TIME */ - -#ifdef HAVE_WALL_TIME - /* Print wall clock time elapsed. */ - fprintf (fp, "%7.2f (%2.0f%%) wall", - tv->elapsed.wall, - (total->wall == 0 ? 0 : tv->elapsed.wall / total->wall) * 100); -#endif /* HAVE_WALL_TIME */ - - putc ('\n', fp); + fprintf (fp, " %-22s", tv->name); + fprintf (fp, "%8.3f (%2d%%)", tv->elapsed.user * 1e-9, usr); + fprintf (fp, "%8.3f (%2d%%)", tv->elapsed.sys * 1e-9, sys); + fprintf (fp, "%11.6f (%2d%%)\n", tv->elapsed.wall * 1e-9, wall); } /* Print total time. */ - fputs (_(" TOTAL :"), fp); -#ifdef HAVE_USER_TIME - fprintf (fp, "%7.2f ", total->user); -#endif -#ifdef HAVE_SYS_TIME - fprintf (fp, "%7.2f ", total->sys); -#endif -#ifdef HAVE_WALL_TIME - fprintf (fp, "%7.2f\n", total->wall); -#endif - -#endif /* defined (HAVE_USER_TIME) || defined (HAVE_SYS_TIME) - || defined (HAVE_WALL_TIME) */ -} - -/* Returns time (user + system) used so far by the compiler process, - in microseconds. */ - -long -get_run_time () -{ - struct timevar_time_def total_elapsed; - timevar_get (TV_TOTAL, &total_elapsed); - return total_elapsed.user + total_elapsed.sys; -} - -/* Prints a message to stderr stating that time elapsed in STR is - TOTAL (given in microseconds). */ - -void -print_time (str, total) - const char *str; - long total; -{ - long all_time = get_run_time (); - fprintf (stderr, - _("time in %s: %ld.%06ld (%ld%%)\n"), - str, total / 1000000, total % 1000000, - all_time == 0 ? 0 - : (long) (((100.0 * (double) total) / (double) all_time) + .5)); + fprintf (fp, " %-22s", timevars[tv_total].name); + fprintf (fp, "%8.3f ", total->user * 1e-9); + fprintf (fp, "%8.3f ", total->sys * 1e-9); + fprintf (fp, "%11.6f\n", total->wall * 1e-9); } diff --git a/contrib/tools/bison/lib/timevar.def b/contrib/tools/bison/lib/timevar.def index 01eaba7076..00d0cd3391 100644 --- a/contrib/tools/bison/lib/timevar.def +++ b/contrib/tools/bison/lib/timevar.def @@ -28,35 +28,35 @@ DEFTIMEVAR (id, name) - where ID is the enumeral value used to identify the timing + where ID is the enum value used to identify the timing variable, and NAME is a character string describing its purpose. */ /* The total execution time. */ -DEFTIMEVAR (TV_TOTAL , "total time") +DEFTIMEVAR (tv_total , "total time") /* Time spent in the reader. */ -DEFTIMEVAR (TV_READER , "reader") -DEFTIMEVAR (TV_SCANNING , "scanner") -DEFTIMEVAR (TV_PARSING , "parser") +DEFTIMEVAR (tv_reader , "reader") +DEFTIMEVAR (tv_scanning , "scanner") +DEFTIMEVAR (tv_parsing , "parser") /* Time spent handling the grammar. */ -DEFTIMEVAR (TV_REDUCE , "reducing the grammar") -DEFTIMEVAR (TV_SETS , "computing the sets") -DEFTIMEVAR (TV_LR0 , "LR(0)") -DEFTIMEVAR (TV_LALR , "LALR(1)") -DEFTIMEVAR (TV_IELR_PHASE1 , "IELR(1) Phase 1") -DEFTIMEVAR (TV_IELR_PHASE2 , "IELR(1) Phase 2") -DEFTIMEVAR (TV_IELR_PHASE3 , "IELR(1) Phase 3") -DEFTIMEVAR (TV_IELR_PHASE4 , "IELR(1) Phase 4") -DEFTIMEVAR (TV_CONFLICTS , "conflicts") - -/* Time spent outputing results. */ -DEFTIMEVAR (TV_REPORT , "outputing report") -DEFTIMEVAR (TV_GRAPH , "outputing graph") -DEFTIMEVAR (TV_XML , "outputing xml") -DEFTIMEVAR (TV_ACTIONS , "parser action tables") -DEFTIMEVAR (TV_PARSER , "outputing parser") -DEFTIMEVAR (TV_M4 , "running m4") +DEFTIMEVAR (tv_reduce , "reducing the grammar") +DEFTIMEVAR (tv_sets , "computing the sets") +DEFTIMEVAR (tv_lr0 , "LR(0)") +DEFTIMEVAR (tv_lalr , "LALR(1)") +DEFTIMEVAR (tv_ielr_phase1 , "IELR(1) Phase 1") +DEFTIMEVAR (tv_ielr_phase2 , "IELR(1) Phase 2") +DEFTIMEVAR (tv_ielr_phase3 , "IELR(1) Phase 3") +DEFTIMEVAR (tv_ielr_phase4 , "IELR(1) Phase 4") +DEFTIMEVAR (tv_conflicts , "conflicts") + +/* Time spent outputting results. */ +DEFTIMEVAR (tv_report , "outputting report") +DEFTIMEVAR (tv_graph , "outputting graph") +DEFTIMEVAR (tv_xml , "outputting xml") +DEFTIMEVAR (tv_actions , "parser action tables") +DEFTIMEVAR (tv_parser , "outputting parser") +DEFTIMEVAR (tv_m4 , "running m4") /* Time spent by freeing the memory :). */ -DEFTIMEVAR (TV_FREE , "freeing") +DEFTIMEVAR (tv_free , "freeing") diff --git a/contrib/tools/bison/lib/timevar.h b/contrib/tools/bison/lib/timevar.h index 14366c9628..cf9e0830d1 100644 --- a/contrib/tools/bison/lib/timevar.h +++ b/contrib/tools/bison/lib/timevar.h @@ -1,4 +1,4 @@ -/* Timing variables for measuring compiler performance. +/* Timing variables for measuring application performance. Copyright (C) 2000, 2002, 2004, 2009-2015, 2018 Free Software Foundation, Inc. @@ -18,11 +18,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/>. */ -#ifndef GCC_TIMEVAR_H -#define GCC_TIMEVAR_H +#ifndef _TIMEVAR_H +# define _TIMEVAR_H 1 + +# include <stdio.h> + +# include "xtime.h" + +# ifdef __cplusplus +extern "C" { +# endif /* Timing variables are used to measure elapsed time in various - portions of the compiler. Each measures elapsed user, system, and + portions of the application. Each measures elapsed user, system, and wall-clock time, as appropriate to and supported by the host system. @@ -52,14 +60,14 @@ struct timevar_time_def { /* User time in this process. */ - float user; + xtime_t user; /* System time (if applicable for this host platform) in this process. */ - float sys; + xtime_t sys; /* Wall clock time. */ - float wall; + xtime_t wall; }; /* An enumeration of timing variable identifiers. Constructed from @@ -75,18 +83,56 @@ typedef enum timevar_id_t; #undef DEFTIMEVAR -extern void init_timevar (void); -extern void timevar_push (timevar_id_t); -extern void timevar_pop (timevar_id_t); -extern void timevar_start (timevar_id_t); -extern void timevar_stop (timevar_id_t); -extern void timevar_get (timevar_id_t, struct timevar_time_def *); -extern void timevar_print (FILE *); +/* Initialize timing variables. */ + +void timevar_init (void); + +/* Push TIMEVAR onto the timing stack. No further elapsed time is + attributed to the previous topmost timing variable on the stack; + subsequent elapsed time is attributed to TIMEVAR, until it is + popped or another element is pushed on top. + + TIMEVAR cannot be running as a standalone timer. */ + +void timevar_push (timevar_id_t timevar); + +/* Pop the topmost timing variable element off the timing stack. The + popped variable must be TIMEVAR. Elapsed time since the that + element was pushed on, or since it was last exposed on top of the + stack when the element above it was popped off, is credited to that + timing variable. */ + +void timevar_pop (timevar_id_t timevar); + +/* Start timing TIMEVAR independently of the timing stack. Elapsed + time until timevar_stop is called for the same timing variable is + attributed to TIMEVAR. */ -/* Provided for backward compatibility. */ -extern long get_run_time (void); -extern void print_time (const char *, long); +void timevar_start (timevar_id_t timevar); -extern int timevar_report; +/* Stop timing TIMEVAR. Time elapsed since timevar_start was called + is attributed to it. */ + +void timevar_stop (timevar_id_t timevar); + +/* Fill the elapsed time for TIMEVAR into ELAPSED. Returns + update-to-date information even if TIMEVAR is currently running. */ + +void timevar_get (timevar_id_t timevar, struct timevar_time_def *elapsed); + +/* Summarize timing variables to FP. The timing variable TV_TOTAL has + a special meaning -- it's considered to be the total elapsed time, + for normalizing the others, and is displayed last. */ + +void timevar_print (FILE *fp); + +/* Set to to nonzero to enable timing variables. All the timevar + functions make an early exit if timevar is disabled. */ + +extern int timevar_enabled; + +# ifdef __cplusplus +} +# endif -#endif /* ! GCC_TIMEVAR_H */ +#endif /* ! _TIMEVAR_H */ diff --git a/contrib/tools/bison/lib/vasnprintf.c b/contrib/tools/bison/lib/vasnprintf.c index 3b441d03b7..57571750a0 100644 --- a/contrib/tools/bison/lib/vasnprintf.c +++ b/contrib/tools/bison/lib/vasnprintf.c @@ -860,7 +860,9 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes) size_t a_len = a.nlimbs; /* 0.03345 is slightly larger than log(2)/(9*log(10)). */ size_t c_len = 9 * ((size_t)(a_len * (GMP_LIMB_BITS * 0.03345f)) + 1); - char *c_ptr = (char *) malloc (xsum (c_len, extra_zeroes)); + /* We need extra_zeroes bytes for zeroes, followed by c_len bytes for the + digits of a, followed by 1 byte for the terminating NUL. */ + char *c_ptr = (char *) malloc (xsum (xsum (extra_zeroes, c_len), 1)); if (c_ptr != NULL) { char *d_ptr = c_ptr; @@ -2694,7 +2696,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, errno = EILSEQ; return NULL; } - if (precision < count) + if (precision < (unsigned int) count) break; arg_end++; characters += count; @@ -5125,7 +5127,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, { /* Verify that snprintf() has NUL-terminated its result. */ - if (count < maxlen + if ((unsigned int) count < maxlen && ((TCHAR_T *) (result + length)) [count] != '\0') abort (); /* Portability hack. */ diff --git a/contrib/tools/bison/lib/vbitset.c b/contrib/tools/bison/lib/vbitset.c index 69d1b76231..f715f9b4f1 100644 --- a/contrib/tools/bison/lib/vbitset.c +++ b/contrib/tools/bison/lib/vbitset.c @@ -56,19 +56,14 @@ static bitset_bindex vbitset_list_reverse (bitset, bitset_bindex *, static bitset_bindex vbitset_resize (bitset src, bitset_bindex n_bits) { - bitset_windex oldsize; - bitset_windex newsize; - if (n_bits == BITSET_NBITS_ (src)) return n_bits; - oldsize = VBITSET_SIZE (src); - newsize = VBITSET_N_WORDS (n_bits); + bitset_windex oldsize = VBITSET_SIZE (src); + bitset_windex newsize = VBITSET_N_WORDS (n_bits); if (oldsize < newsize) { - bitset_windex size; - /* The bitset needs to grow. If we already have enough memory allocated, then just zero what we need. */ if (newsize > VBITSET_ASIZE (src)) @@ -78,11 +73,7 @@ vbitset_resize (bitset src, bitset_bindex n_bits) grow the bitset 25% larger than requested to reduce number of reallocations. */ - if (oldsize == 0) - size = newsize; - else - size = newsize + newsize / 4; - + bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4; VBITSET_WORDS (src) = realloc (VBITSET_WORDS (src), size * sizeof (bitset_word)); VBITSET_ASIZE (src) = size; @@ -115,9 +106,7 @@ vbitset_resize (bitset src, bitset_bindex n_bits) /* Set bit BITNO in bitset DST. */ static void -vbitset_set (dst, bitno) - bitset dst; - bitset_bindex bitno; +vbitset_set (bitset dst, bitset_bindex bitno) { bitset_windex windex = bitno / BITSET_WORD_BITS; @@ -134,9 +123,7 @@ vbitset_set (dst, bitno) /* Reset bit BITNO in bitset DST. */ static void -vbitset_reset (dst, bitno) - bitset dst ATTRIBUTE_UNUSED; - bitset_bindex bitno ATTRIBUTE_UNUSED; +vbitset_reset (bitset dst ATTRIBUTE_UNUSED, bitset_bindex bitno ATTRIBUTE_UNUSED) { /* We must be accessing outside the cache so the bit is zero anyway. */ @@ -145,13 +132,12 @@ vbitset_reset (dst, bitno) /* Test bit BITNO in bitset SRC. */ static bool -vbitset_test (src, bitno) - bitset src ATTRIBUTE_UNUSED; - bitset_bindex bitno ATTRIBUTE_UNUSED; +vbitset_test (bitset src ATTRIBUTE_UNUSED, + bitset_bindex bitno ATTRIBUTE_UNUSED) { /* We must be accessing outside the cache so the bit is zero anyway. */ - return 0; + return false; } @@ -160,22 +146,13 @@ vbitset_test (src, bitno) actual number of bits found and with *NEXT indicating where search stopped. */ static bitset_bindex -vbitset_list_reverse (src, list, num, next) - bitset src; - bitset_bindex *list; - bitset_bindex num; - bitset_bindex *next; +vbitset_list_reverse (bitset src, bitset_bindex *list, + bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex rbitno; - bitset_bindex count; - bitset_windex windex; - unsigned bitcnt; - bitset_bindex bitoff; bitset_word *srcp = VBITSET_WORDS (src); bitset_bindex n_bits = BITSET_SIZE_ (src); - rbitno = *next; + bitset_bindex rbitno = *next; /* If num is 1, we could speed things up with a binary search of the word of interest. */ @@ -183,19 +160,17 @@ vbitset_list_reverse (src, list, num, next) if (rbitno >= n_bits) return 0; - count = 0; + bitset_bindex count = 0; - bitno = n_bits - (rbitno + 1); + bitset_bindex bitno = n_bits - (rbitno + 1); - windex = bitno / BITSET_WORD_BITS; - bitcnt = bitno % BITSET_WORD_BITS; - bitoff = windex * BITSET_WORD_BITS; + bitset_windex windex = bitno / BITSET_WORD_BITS; + unsigned bitcnt = bitno % BITSET_WORD_BITS; + bitset_bindex bitoff = windex * BITSET_WORD_BITS; do { - bitset_word word; - - word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt); + bitset_word word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt); for (; word; bitcnt--) { if (word & BITSET_MSB) @@ -220,26 +195,21 @@ vbitset_list_reverse (src, list, num, next) /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex -vbitset_list (src, list, num, next) - bitset src; - bitset_bindex *list; - bitset_bindex num; - bitset_bindex *next; +vbitset_list (bitset src, bitset_bindex *list, + bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex count; - bitset_windex windex; - bitset_bindex bitoff; bitset_windex size = VBITSET_SIZE (src); bitset_word *srcp = VBITSET_WORDS (src); - bitset_word word; + bitset_bindex bitno = *next; + bitset_bindex count = 0; - bitno = *next; + bitset_windex windex; + bitset_bindex bitoff; + bitset_word word; - count = 0; if (!bitno) { /* Many bitsets are zero, so make this common case fast. */ @@ -327,12 +297,9 @@ vbitset_list (src, list, num, next) /* Ensure that any unused bits within the last word are clear. */ static inline void -vbitset_unused_clear (dst) - bitset dst; +vbitset_unused_clear (bitset dst) { - unsigned last_bit; - - last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS; + unsigned last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS; if (last_bit) VBITSET_WORDS (dst)[VBITSET_SIZE (dst) - 1] &= ((bitset_word) 1 << last_bit) - 1; @@ -343,9 +310,7 @@ static void vbitset_ones (bitset dst) { bitset_word *dstp = VBITSET_WORDS (dst); - unsigned bytes; - - bytes = sizeof (bitset_word) * VBITSET_SIZE (dst); + unsigned bytes = sizeof (bitset_word) * VBITSET_SIZE (dst); memset (dstp, -1, bytes); vbitset_unused_clear (dst); @@ -356,9 +321,7 @@ static void vbitset_zero (bitset dst) { bitset_word *dstp = VBITSET_WORDS (dst); - unsigned bytes; - - bytes = sizeof (bitset_word) * VBITSET_SIZE (dst); + unsigned bytes = sizeof (bitset_word) * VBITSET_SIZE (dst); memset (dstp, 0, bytes); } @@ -367,34 +330,27 @@ vbitset_zero (bitset dst) static bool vbitset_empty_p (bitset dst) { - unsigned i; bitset_word *dstp = VBITSET_WORDS (dst); - for (i = 0; i < VBITSET_SIZE (dst); i++) + for (unsigned i = 0; i < VBITSET_SIZE (dst); i++) if (dstp[i]) - return 0; - - return 1; + return false; + return true; } static void vbitset_copy1 (bitset dst, bitset src) { - bitset_word *srcp; - bitset_word *dstp; - bitset_windex ssize; - bitset_windex dsize; - if (src == dst) - return; + return; vbitset_resize (dst, BITSET_SIZE_ (src)); - srcp = VBITSET_WORDS (src); - dstp = VBITSET_WORDS (dst); - ssize = VBITSET_SIZE (src); - dsize = VBITSET_SIZE (dst); + bitset_word *srcp = VBITSET_WORDS (src); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex ssize = VBITSET_SIZE (src); + bitset_windex dsize = VBITSET_SIZE (dst); memcpy (dstp, srcp, sizeof (bitset_word) * ssize); @@ -406,21 +362,15 @@ vbitset_copy1 (bitset dst, bitset src) static void vbitset_not (bitset dst, bitset src) { - unsigned i; - bitset_word *srcp; - bitset_word *dstp; - bitset_windex ssize; - bitset_windex dsize; - vbitset_resize (dst, BITSET_SIZE_ (src)); - srcp = VBITSET_WORDS (src); - dstp = VBITSET_WORDS (dst); - ssize = VBITSET_SIZE (src); - dsize = VBITSET_SIZE (dst); + bitset_word *srcp = VBITSET_WORDS (src); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex ssize = VBITSET_SIZE (src); + bitset_windex dsize = VBITSET_SIZE (dst); - for (i = 0; i < ssize; i++) - *dstp++ = ~(*srcp++); + for (unsigned i = 0; i < ssize; i++) + *dstp++ = ~(*srcp++); vbitset_unused_clear (dst); memset (dstp + sizeof (bitset_word) * ssize, 0, @@ -431,96 +381,87 @@ vbitset_not (bitset dst, bitset src) static bool vbitset_equal_p (bitset dst, bitset src) { - unsigned i; bitset_word *srcp = VBITSET_WORDS (src); bitset_word *dstp = VBITSET_WORDS (dst); bitset_windex ssize = VBITSET_SIZE (src); bitset_windex dsize = VBITSET_SIZE (dst); + unsigned i; for (i = 0; i < min (ssize, dsize); i++) - if (*srcp++ != *dstp++) - return 0; + if (*srcp++ != *dstp++) + return false; if (ssize > dsize) { for (; i < ssize; i++) if (*srcp++) - return 0; + return false; } else { for (; i < dsize; i++) if (*dstp++) - return 0; + return false; } - return 1; + return true; } static bool vbitset_subset_p (bitset dst, bitset src) { - unsigned i; bitset_word *srcp = VBITSET_WORDS (src); bitset_word *dstp = VBITSET_WORDS (dst); bitset_windex ssize = VBITSET_SIZE (src); bitset_windex dsize = VBITSET_SIZE (dst); + unsigned i; for (i = 0; i < min (ssize, dsize); i++, dstp++, srcp++) - if (*dstp != (*srcp | *dstp)) - return 0; + if (*dstp != (*srcp | *dstp)) + return 0; if (ssize > dsize) { for (; i < ssize; i++) if (*srcp++) - return 0; + return false; } - return 1; + return true; } static bool vbitset_disjoint_p (bitset dst, bitset src) { - unsigned i; bitset_word *srcp = VBITSET_WORDS (src); bitset_word *dstp = VBITSET_WORDS (dst); bitset_windex ssize = VBITSET_SIZE (src); bitset_windex dsize = VBITSET_SIZE (dst); - for (i = 0; i < min (ssize, dsize); i++) - if (*srcp++ & *dstp++) - return 0; + for (unsigned i = 0; i < min (ssize, dsize); i++) + if (*srcp++ & *dstp++) + return false; - return 1; + return true; } static void vbitset_and (bitset dst, bitset src1, bitset src2) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); - for (i = 0; i < min (ssize1, ssize2); i++) - *dstp++ = *src1p++ & *src2p++; + for (unsigned i = 0; i < min (ssize1, ssize2); i++) + *dstp++ = *src1p++ & *src2p++; memset (dstp, 0, sizeof (bitset_word) * (dsize - min (ssize1, ssize2))); } @@ -529,31 +470,24 @@ vbitset_and (bitset dst, bitset src1, bitset src2) static bool vbitset_and_cmp (bitset dst, bitset src1, bitset src2) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - + bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { bitset_word tmp = *src1p++ & *src2p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -568,7 +502,7 @@ vbitset_and_cmp (bitset dst, bitset src1, bitset src2) { if (*dstp != 0) { - changed = 1; + changed = true; *dstp = 0; } } @@ -582,25 +516,18 @@ vbitset_and_cmp (bitset dst, bitset src1, bitset src2) static void vbitset_andn (bitset dst, bitset src1, bitset src2) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++) - *dstp++ = *src1p++ & ~(*src2p++); + *dstp++ = *src1p++ & ~(*src2p++); if (ssize2 > ssize1) { @@ -622,31 +549,24 @@ vbitset_andn (bitset dst, bitset src1, bitset src2) static bool vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - + bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { bitset_word tmp = *src1p++ & ~(*src2p++); if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -657,7 +577,7 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { if (*dstp != 0) { - changed = 1; + changed = true; *dstp = 0; } } @@ -672,7 +592,7 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -687,25 +607,18 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) static void vbitset_or (bitset dst, bitset src1, bitset src2) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++) - *dstp++ = *src1p++ | *src2p++; + *dstp++ = *src1p++ | *src2p++; if (ssize2 > ssize1) { @@ -723,31 +636,25 @@ vbitset_or (bitset dst, bitset src1, bitset src2) static bool vbitset_or_cmp (bitset dst, bitset src1, bitset src2) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; + bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { bitset_word tmp = *src1p++ | *src2p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -764,7 +671,7 @@ vbitset_or_cmp (bitset dst, bitset src1, bitset src2) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -778,25 +685,18 @@ vbitset_or_cmp (bitset dst, bitset src1, bitset src2) static void vbitset_xor (bitset dst, bitset src1, bitset src2) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++) - *dstp++ = *src1p++ ^ *src2p++; + *dstp++ = *src1p++ ^ *src2p++; if (ssize2 > ssize1) { @@ -814,31 +714,24 @@ vbitset_xor (bitset dst, bitset src1, bitset src2) static bool vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *dstp; - bitset_windex ssize1; - bitset_windex ssize2; - bitset_windex dsize; - + bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); - dsize = VBITSET_SIZE (dst); - ssize1 = VBITSET_SIZE (src1); - ssize2 = VBITSET_SIZE (src2); - dstp = VBITSET_WORDS (dst); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); + bitset_windex dsize = VBITSET_SIZE (dst); + bitset_windex ssize1 = VBITSET_SIZE (src1); + bitset_windex ssize2 = VBITSET_SIZE (src2); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { bitset_word tmp = *src1p++ ^ *src2p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -855,7 +748,7 @@ vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -872,13 +765,6 @@ vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) static void vbitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) { @@ -888,47 +774,40 @@ vbitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3) vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ & *src2p++) | *src3p++; + for (unsigned i = 0; i < size; i++) + *dstp++ = (*src1p++ & *src2p++) | *src3p++; } static bool vbitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) return bitset_and_or_cmp_ (dst, src1, src2, src3); vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); - for (i = 0; i < size; i++, dstp++) + bool changed = false; + for (unsigned i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ & *src2p++) | *src3p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -939,13 +818,6 @@ vbitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) static void vbitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) { @@ -955,47 +827,40 @@ vbitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3) vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++; + for (unsigned i = 0; i < size; i++) + *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++; } static bool vbitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) return bitset_andn_or_cmp_ (dst, src1, src2, src3); vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); - for (i = 0; i < size; i++, dstp++) + bool changed = false; + for (unsigned i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1006,13 +871,6 @@ vbitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) static void vbitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) { @@ -1022,47 +880,41 @@ vbitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3) vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ | *src2p++) & *src3p++; + for (unsigned i = 0; i < size; i++) + *dstp++ = (*src1p++ | *src2p++) & *src3p++; } static bool vbitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - unsigned i; - int changed = 0; - bitset_word *src1p; - bitset_word *src2p; - bitset_word *src3p; - bitset_word *dstp; - bitset_windex size; - if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2) || BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3)) return bitset_or_and_cmp_ (dst, src1, src2, src3); vbitset_resize (dst, BITSET_NBITS_ (src1)); - src1p = VBITSET_WORDS (src1); - src2p = VBITSET_WORDS (src2); - src3p = VBITSET_WORDS (src3); - dstp = VBITSET_WORDS (dst); - size = VBITSET_SIZE (dst); + bitset_word *src1p = VBITSET_WORDS (src1); + bitset_word *src2p = VBITSET_WORDS (src2); + bitset_word *src3p = VBITSET_WORDS (src3); + bitset_word *dstp = VBITSET_WORDS (dst); + bitset_windex size = VBITSET_SIZE (dst); + unsigned i; + bool changed = false; for (i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ | *src2p++) & *src3p++; if (*dstp != tmp) { - changed = 1; + changed = true; *dstp = tmp; } } @@ -1074,9 +926,9 @@ static void vbitset_copy (bitset dst, bitset src) { if (BITSET_COMPATIBLE_ (dst, src)) - vbitset_copy1 (dst, src); + vbitset_copy1 (dst, src); else - bitset_copy_ (dst, src); + bitset_copy_ (dst, src); } @@ -1119,22 +971,17 @@ struct bitset_vtable vbitset_vtable = { size_t -vbitset_bytes (n_bits) - bitset_bindex n_bits ATTRIBUTE_UNUSED; +vbitset_bytes (bitset_bindex n_bits ATTRIBUTE_UNUSED) { return sizeof (struct vbitset_struct); } bitset -vbitset_init (bset, n_bits) - bitset bset; - bitset_bindex n_bits; +vbitset_init (bitset bset, bitset_bindex n_bits) { bset->b.vtable = &vbitset_vtable; - bset->b.cindex = 0; - VBITSET_SIZE (bset) = 0; vbitset_resize (bset, n_bits); return bset; diff --git a/contrib/tools/bison/lib/vbitset.h b/contrib/tools/bison/lib/vbitset.h index 6f7d7137d3..23b4652b87 100644 --- a/contrib/tools/bison/lib/vbitset.h +++ b/contrib/tools/bison/lib/vbitset.h @@ -23,8 +23,8 @@ #include "bitset.h" -extern size_t vbitset_bytes (bitset_bindex); +size_t vbitset_bytes (bitset_bindex); -extern bitset vbitset_init (bitset, bitset_bindex); +bitset vbitset_init (bitset, bitset_bindex); #endif diff --git a/contrib/tools/bison/lib/xtime.c b/contrib/tools/bison/lib/xtime.c new file mode 100644 index 0000000000..e608f69fdf --- /dev/null +++ b/contrib/tools/bison/lib/xtime.c @@ -0,0 +1,3 @@ +#include <config.h> +#define XTIME_INLINE _GL_EXTERN_INLINE +#include "xtime.h" diff --git a/contrib/tools/bison/lib/xtime.h b/contrib/tools/bison/lib/xtime.h new file mode 100644 index 0000000000..aabcee9e68 --- /dev/null +++ b/contrib/tools/bison/lib/xtime.h @@ -0,0 +1,105 @@ +/* xtime -- extended-resolution integer timestamps + + Copyright (C) 2005-2006, 2009-2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert. */ + +#ifndef XTIME_H_ +#define XTIME_H_ 1 + +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef XTIME_INLINE +# define XTIME_INLINE _GL_INLINE +#endif + +/* xtime_t is a signed type used for timestamps. It is an integer + type that is a count of nanoseconds -- except for obsolescent hosts + without sufficiently-wide integers, where it is a count of + seconds. */ +#if HAVE_LONG_LONG_INT +typedef long long int xtime_t; +# define XTIME_PRECISION 1000000000 +#else +# include <limits.h> +typedef long int xtime_t; +# if LONG_MAX >> 31 >> 31 == 0 +# define XTIME_PRECISION 1 +# else +# define XTIME_PRECISION 1000000000 +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Return an extended time value that contains S seconds and NS + nanoseconds. */ +XTIME_INLINE xtime_t +xtime_make (xtime_t s, long int ns) +{ + const long int giga = 1000 * 1000 * 1000; + s += ns / giga; + ns %= giga; + if (XTIME_PRECISION == 1) + return s; + else + return XTIME_PRECISION * s + ns; +} + +/* Return the number of seconds in T, which must be nonnegative. */ +XTIME_INLINE xtime_t +xtime_nonnegative_sec (xtime_t t) +{ + return t / XTIME_PRECISION; +} + +/* Return the number of seconds in T. */ +XTIME_INLINE xtime_t +xtime_sec (xtime_t t) +{ + return (XTIME_PRECISION == 1 + ? t + : t < 0 + ? (t + XTIME_PRECISION - 1) / XTIME_PRECISION - 1 + : xtime_nonnegative_sec (t)); +} + +/* Return the number of nanoseconds in T, which must be nonnegative. */ +XTIME_INLINE long int +xtime_nonnegative_nsec (xtime_t t) +{ + return t % XTIME_PRECISION; +} + +/* Return the number of nanoseconds in T. */ +XTIME_INLINE long int +xtime_nsec (xtime_t t) +{ + long int ns = t % XTIME_PRECISION; + if (ns < 0) + ns += XTIME_PRECISION; + return ns; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/contrib/tools/bison/lib/ya.make b/contrib/tools/bison/lib/ya.make index 2bb7d5a261..adda78c9fd 100644 --- a/contrib/tools/bison/lib/ya.make +++ b/contrib/tools/bison/lib/ya.make @@ -47,6 +47,7 @@ SRCS( fopen-safer.c fseterr.c get-errno.c + gethrxtime.c getprogname.c glthread/lock.c glthread/threadlib.c @@ -54,10 +55,12 @@ SRCS( hash.c lbitset.c localcharset.c + localtime-buffer.c malloca.c math.c mbrtowc.c mbswidth.c + path-join.c pipe-safer.c pipe2-safer.c pipe2.c @@ -71,6 +74,7 @@ SRCS( spawn-pipe.c stat-time.c stripslash.c + timespec.c timevar.c unistd.c uniwidth/width.c @@ -84,6 +88,7 @@ SRCS( xmemdup0.c xsize.c xstrndup.c + xtime.c ) IF (OS_DARWIN) diff --git a/contrib/tools/bison/src/AnnotationList.c b/contrib/tools/bison/src/AnnotationList.c index a78deb8ac9..34b9231068 100644 --- a/contrib/tools/bison/src/AnnotationList.c +++ b/contrib/tools/bison/src/AnnotationList.c @@ -168,10 +168,9 @@ AnnotationList__compute_conflicted_tokens (bitset shift_tokens, bitset conflicted_tokens = bitset_create (ntokens, BITSET_FIXED); bitset conflicted_tokens_rule = bitset_create (ntokens, BITSET_FIXED); bitset tokens = bitset_create (ntokens, BITSET_FIXED); - int i; bitset_copy (tokens, shift_tokens); - for (i = 0; i < reds->num; ++i) + for (int i = 0; i < reds->num; ++i) { bitset_and (conflicted_tokens_rule, tokens, reds->lookahead_tokens[i]); bitset_or (conflicted_tokens, @@ -215,20 +214,17 @@ AnnotationList__compute_lhs_contributions (state *s, rule *the_rule, } static void -AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s, - bitsetv follow_kernel_items, - bitsetv always_follows, - state ***predecessors, - bitset **item_lookahead_sets, - AnnotationList - **annotation_lists, - AnnotationIndex - *annotation_counts, - struct obstack - *annotations_obstackp) +AnnotationList__computePredecessorAnnotations ( + AnnotationList *self, state *s, + bitsetv follow_kernel_items, + bitsetv always_follows, + state ***predecessors, + bitset **item_lookahead_sets, + AnnotationList **annotation_lists, + AnnotationIndex *annotation_counts, + struct obstack *annotations_obstackp) { - state **predecessor; - for (predecessor = predecessors[s->number]; *predecessor; ++predecessor) + for (state **predecessor = predecessors[s->number]; *predecessor; ++predecessor) { AnnotationList *annotation_node = AnnotationList__alloc_on_obstack ( @@ -237,8 +233,7 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s, bool potential_contribution = false; bitset *lookaheads = NULL; { - ContributionIndex ci; - for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci) + for (ContributionIndex ci = 0; ci < self->inadequacyNode->contributionCount; ++ci) { symbol_number contribution_token = InadequacyList__getContributionToken (self->inadequacyNode, ci) @@ -274,12 +269,12 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s, if (item_number_is_rule_number (ritem[s->items[self_item] - 2])) { - Sbitset items; unsigned rulei; for (rulei = s->items[self_item]; !item_number_is_rule_number (ritem[rulei]); ++rulei) - ; + continue; + Sbitset items; if (AnnotationList__compute_lhs_contributions ( *predecessor, &rules[item_number_as_rule_number (ritem[rulei])], @@ -334,10 +329,9 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s, potential_contribution = true; if (!lookaheads) { - size_t j; lookaheads = xnmalloc ((*predecessor)->nitems, sizeof *lookaheads); - for (j = 0; j < (*predecessor)->nitems; ++j) + for (size_t j = 0; j < (*predecessor)->nitems; ++j) lookaheads[j] = NULL; } if (!lookaheads[i]) @@ -377,8 +371,7 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s, annotation_node = NULL; } { - size_t i; - for (i = 0; i < (*predecessor)->nitems; ++i) + for (size_t i = 0; i < (*predecessor)->nitems; ++i) if (lookaheads[i]) bitset_free (lookaheads[i]); free (lookaheads); @@ -416,23 +409,19 @@ AnnotationList__compute_from_inadequacies ( struct obstack *annotations_obstackp, InadequacyListNodeCount *inadequacy_list_node_count) { - bitsetv all_lookaheads; - bitset shift_tokens; - bitset conflicted_tokens; - bitset_iterator biter_conflict; - bitset_bindex conflicted_token; - /* Return an empty list if s->lookahead_tokens = NULL. */ if (s->consistent) return; - all_lookaheads = bitsetv_create (s->nitems, ntokens, BITSET_FIXED); + bitsetv all_lookaheads = bitsetv_create (s->nitems, ntokens, BITSET_FIXED); bitsetv_ones (all_lookaheads); - shift_tokens = AnnotationList__compute_shift_tokens (s->transitions); - conflicted_tokens = + bitset shift_tokens = AnnotationList__compute_shift_tokens (s->transitions); + bitset conflicted_tokens = AnnotationList__compute_conflicted_tokens (shift_tokens, s->reductions); /* Add an inadequacy annotation for each conflicted_token. */ + bitset_iterator biter_conflict; + bitset_bindex conflicted_token; BITSET_FOR_EACH (biter_conflict, conflicted_tokens, conflicted_token, 0) { AnnotationList *annotation_node; @@ -444,8 +433,7 @@ AnnotationList__compute_from_inadequacies ( /* Allocate the annotation node. */ { - int rule_i; - for (rule_i = 0; rule_i < s->reductions->num; ++rule_i) + for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i) if (bitset_test (s->reductions->lookahead_tokens[rule_i], conflicted_token)) ++contribution_count; @@ -461,8 +449,7 @@ AnnotationList__compute_from_inadequacies ( { ContributionIndex ci = 0; int item_i = 0; - int rule_i; - for (rule_i = 0; rule_i < s->reductions->num; ++rule_i) + for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i) { rule *the_rule = s->reductions->rules[rule_i]; if (bitset_test (s->reductions->lookahead_tokens[rule_i], @@ -584,27 +571,20 @@ AnnotationList__debug (AnnotationList const *self, size_t nitems, int spaces) AnnotationIndex ai; for (a = self, ai = 0; a; a = a->next, ++ai) { - { - int j; - for (j = 0; j < spaces; ++j) - putc (' ', stderr); - } + for (int j = 0; j < spaces; ++j) + putc (' ', stderr); fprintf (stderr, "Annotation %d (manifesting state %d):\n", ai, a->inadequacyNode->manifestingState->number); { - ContributionIndex ci; - bitset_bindex rulei = 0; /* init suppresses compiler warning */ - rulei = bitset_first (a->inadequacyNode->inadequacy.conflict.actions); - for (ci = 0; ci < a->inadequacyNode->contributionCount; ++ci) + bitset_bindex rulei + = bitset_first (a->inadequacyNode->inadequacy.conflict.actions); + for (ContributionIndex ci = 0; ci < a->inadequacyNode->contributionCount; ++ci) { symbol_number token = InadequacyList__getContributionToken (a->inadequacyNode, ci) ->content->number; - { - int j; - for (j = 0; j < spaces+2; ++j) - putc (' ', stderr); - } + for (int j = 0; j < spaces+2; ++j) + putc (' ', stderr); if (ci == InadequacyList__getShiftContributionIndex ( a->inadequacyNode)) fprintf (stderr, "Contributes shift of token %d.\n", token); @@ -639,20 +619,17 @@ AnnotationList__computeLookaheadFilter (AnnotationList const *self, { bitsetv_zero (lookahead_filter); for (; self; self = self->next) - { - ContributionIndex ci; - for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci) - if (!AnnotationList__isContributionAlways (self, ci)) - { - Sbitset__Index item; - Sbitset biter; - symbol_number token = - InadequacyList__getContributionToken (self->inadequacyNode, ci) - ->content->number; - SBITSET__FOR_EACH (self->contributions[ci], nitems, biter, item) - bitset_set (lookahead_filter[item], token); - } - } + for (ContributionIndex ci = 0; ci < self->inadequacyNode->contributionCount; ++ci) + if (!AnnotationList__isContributionAlways (self, ci)) + { + symbol_number token = + InadequacyList__getContributionToken (self->inadequacyNode, ci) + ->content->number; + Sbitset__Index item; + Sbitset biter; + SBITSET__FOR_EACH (self->contributions[ci], nitems, biter, item) + bitset_set (lookahead_filter[item], token); + } } /** @@ -699,11 +676,10 @@ AnnotationList__computeDominantContribution (AnnotationList const *self, size_t nitems, bitset *lookaheads, bool require_split_stable) { - symbol *token; ContributionIndex const ci_shift = InadequacyList__getShiftContributionIndex (self->inadequacyNode); - token = self->inadequacyNode->inadequacy.conflict.token; + symbol *token = self->inadequacyNode->inadequacy.conflict.token; /* S/R conflict. */ if (ci_shift != ContributionIndex__none) @@ -711,9 +687,6 @@ AnnotationList__computeDominantContribution (AnnotationList const *self, bool find_stable_domination_over_shift = false; bool find_stable_error_action_domination = false; { - ContributionIndex ci; - int actioni; - ContributionIndex ci_rr_dominator = ContributionIndex__none; int shift_precedence = token->content->prec; /* If the token has no precedence set, shift is always chosen. */ @@ -723,11 +696,16 @@ AnnotationList__computeDominantContribution (AnnotationList const *self, /* Figure out which reductions contribute, which of those would dominate in a R/R comparison, and whether any reduction dominates the shift so that the R/R comparison is actually needed. */ - for (ci = 0, actioni = bitset_first (self->inadequacyNode->inadequacy - .conflict.actions); + ContributionIndex ci_rr_dominator = ContributionIndex__none; + int actioni; + ContributionIndex ci; + for (ci = 0, + actioni = bitset_first (self->inadequacyNode->inadequacy + .conflict.actions); ci < self->inadequacyNode->contributionCount; - ++ci, actioni = bitset_next (self->inadequacyNode->inadequacy - .conflict.actions, actioni+1)) + ++ci, + actioni = bitset_next (self->inadequacyNode->inadequacy + .conflict.actions, actioni+1)) { int reduce_precedence = 0; if (ci == ci_shift) @@ -796,17 +774,14 @@ AnnotationList__computeDominantContribution (AnnotationList const *self, /* R/R conflict, so the reduction with the lowest rule number dominates. Fortunately, contributions are sorted by rule number. */ - { - ContributionIndex ci; - for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci) - if (AnnotationList__stateMakesContribution (self, nitems, ci, - lookaheads)) - { - if (require_split_stable - && !AnnotationList__isContributionAlways (self, ci)) - return ContributionIndex__none; - return ci; - } - } + for (ContributionIndex ci = 0; ci < self->inadequacyNode->contributionCount; ++ci) + if (AnnotationList__stateMakesContribution (self, nitems, ci, + lookaheads)) + { + if (require_split_stable + && !AnnotationList__isContributionAlways (self, ci)) + return ContributionIndex__none; + return ci; + } return ContributionIndex__none; } diff --git a/contrib/tools/bison/src/LR0.c b/contrib/tools/bison/src/LR0.c index 35eaf563ee..023f395552 100644 --- a/contrib/tools/bison/src/LR0.c +++ b/contrib/tools/bison/src/LR0.c @@ -89,10 +89,6 @@ static item_number *kernel_items; static void allocate_itemsets (void) { - symbol_number i; - rule_number r; - item_number *rhsp; - /* Count the number of occurrences of all the symbols in RITEMS. Note that useless productions (hence useless nonterminals) are browsed too, hence we need to allocate room for _all_ the @@ -101,8 +97,8 @@ allocate_itemsets (void) size_t *symbol_count = xcalloc (nsyms + nuseless_nonterminals, sizeof *symbol_count); - for (r = 0; r < nrules; ++r) - for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) + for (rule_number r = 0; r < nrules; ++r) + for (item_number *rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) { count++; symbol_count[*rhsp]++; @@ -118,7 +114,7 @@ allocate_itemsets (void) kernel_items = xnmalloc (count, sizeof *kernel_items); count = 0; - for (i = 0; i < nsyms; i++) + for (symbol_number i = 0; i < nsyms; i++) { kernel_base[i] = kernel_items + count; count += symbol_count[i]; @@ -174,8 +170,6 @@ free_storage (void) static void new_itemsets (state *s) { - size_t i; - if (trace_flag & trace_automaton) fprintf (stderr, "Entering new_itemsets, state = %d\n", s->number); @@ -183,7 +177,7 @@ new_itemsets (state *s) nshifts = 0; - for (i = 0; i < nitemset; ++i) + for (size_t i = 0; i < nitemset; ++i) if (item_number_is_symbol_number (ritem[itemset[i]])) { symbol_number sym = item_number_as_symbol_number (ritem[itemset[i]]); @@ -209,13 +203,11 @@ new_itemsets (state *s) static state * get_state (symbol_number sym, size_t core_size, item_number *core) { - state *s; - if (trace_flag & trace_automaton) fprintf (stderr, "Entering get_state, symbol = %d (%s)\n", sym, symbols[sym]->tag); - s = state_hash_lookup (core_size, core); + state *s = state_hash_lookup (core_size, core); if (!s) s = state_list_append (sym, core_size, core); @@ -235,25 +227,23 @@ get_state (symbol_number sym, size_t core_size, item_number *core) static void append_states (state *s) { - int i; - if (trace_flag & trace_automaton) fprintf (stderr, "Entering append_states, state = %d\n", s->number); /* First sort shift_symbol into increasing order. */ - for (i = 1; i < nshifts; i++) + for (int i = 1; i < nshifts; i++) { - symbol_number sym = shift_symbol[i]; - int j; - for (j = i; 0 < j && sym < shift_symbol[j - 1]; j--) + const symbol_number sym = shift_symbol[i]; + int j = i; + for (; 0 < j && sym < shift_symbol[j - 1]; j--) shift_symbol[j] = shift_symbol[j - 1]; shift_symbol[j] = sym; } - for (i = 0; i < nshifts; i++) + for (int i = 0; i < nshifts; i++) { - symbol_number sym = shift_symbol[i]; + const symbol_number sym = shift_symbol[i]; shiftset[i] = get_state (sym, kernel_size[sym], kernel_base[sym]); } } @@ -269,10 +259,9 @@ static void save_reductions (state *s) { int count = 0; - size_t i; /* Find and count the active items that represent ends of rules. */ - for (i = 0; i < nitemset; ++i) + for (size_t i = 0; i < nitemset; ++i) { item_number item = ritem[itemset[i]]; if (item_number_is_rule_number (item)) @@ -334,17 +323,16 @@ set_states (void) void generate_states (void) { - item_number initial_core = 0; - state_list *list = NULL; allocate_storage (); new_closure (nritems); /* Create the initial state. The 0 at the lhs is the index of the item of this initial rule. */ + item_number initial_core = 0; state_list_append (0, 1, &initial_core); /* States are queued when they are created; process them all. */ - for (list = first_state; list; list = list->next) + for (state_list *list = first_state; list; list = list->next) { state *s = list->state; if (trace_flag & trace_automaton) diff --git a/contrib/tools/bison/src/complain.c b/contrib/tools/bison/src/complain.c index e39626a3f3..6c1acf392e 100644 --- a/contrib/tools/bison/src/complain.c +++ b/contrib/tools/bison/src/complain.c @@ -83,7 +83,7 @@ static const char * const warnings_args[] = 0 }; -static const int warnings_types[] = +static const warnings warnings_types[] = { Wnone, Wmidrule_values, @@ -114,8 +114,7 @@ warning_argmatch (char const *arg, size_t no, size_t err) no = !no; } - size_t b; - for (b = 0; b < warnings_size; ++b) + for (size_t b = 0; b < warnings_size; ++b) if (value & 1 << b) { if (err && no) @@ -176,8 +175,7 @@ complain_init (void) warnings warnings_default = Wconflicts_sr | Wconflicts_rr | Wdeprecated | Wother; - size_t b; - for (b = 0; b < warnings_size; ++b) + for (size_t b = 0; b < warnings_size; ++b) { warnings_flag[b] = (1 << b & warnings_default ? severity_warning @@ -204,8 +202,7 @@ warning_severity (warnings flags) { /* Diagnostics about warnings. */ severity res = severity_disabled; - size_t b; - for (b = 0; b < warnings_size; ++b) + for (size_t b = 0; b < warnings_size; ++b) if (flags & 1 << b) { res = res < warnings_flag[b] ? warnings_flag[b] : res; @@ -225,8 +222,7 @@ warning_severity (warnings flags) bool warning_is_unset (warnings flags) { - size_t b; - for (b = 0; b < warnings_size; ++b) + for (size_t b = 0; b < warnings_size; ++b) if (flags & 1 << b && warnings_flag[b] != severity_unset) return false; return true; @@ -238,8 +234,7 @@ static void warnings_print_categories (warnings warn_flags, FILE *f) { /* Display only the first match, the second is "-Wall". */ - size_t i; - for (i = 0; warnings_args[i]; ++i) + for (size_t i = 0; warnings_args[i]; ++i) if (warn_flags & warnings_types[i]) { severity s = warning_severity (warnings_types[i]); diff --git a/contrib/tools/bison/src/files.c b/contrib/tools/bison/src/files.c index e2920b41d7..87136908ca 100644 --- a/contrib/tools/bison/src/files.c +++ b/contrib/tools/bison/src/files.c @@ -191,7 +191,7 @@ static void compute_exts_from_src (const char *ext) { /* We use this function when the user specifies `-o' or `--output', - so the extenions must be computed unconditionally from the file name + so the extensions must be computed unconditionally from the file name given by this option. */ src_extension = xstrdup (ext); /* diff --git a/contrib/tools/bison/src/flex-scanner.h b/contrib/tools/bison/src/flex-scanner.h index e09a1c04fa..66b6098e13 100644 --- a/contrib/tools/bison/src/flex-scanner.h +++ b/contrib/tools/bison/src/flex-scanner.h @@ -27,6 +27,32 @@ + (YY_FLEX_MINOR_VERSION) * 1000 \ + (YY_FLEX_SUBMINOR_VERSION)) +// Pacify warnings in yy_init_buffer (observed with Flex 2.6.4 and GCC +// 6.4.0 and 7.3.0). +// +// ./src/scan-skel.c: In function 'skel_restart': +// ./src/scan-skel.c:2035:20: error: potential null pointer dereference [-Werror=null-dereference] +// b->yy_fill_buffer = 1; +// ~~~~~~~~~~~~~~~~~~^~~ +// ./src/scan-skel.c:2031:19: error: potential null pointer dereference [-Werror=null-dereference] +// b->yy_input_file = file; +// ~~~~~~~~~~~~~~~~~^~~~~~ +#if defined __GNUC__ && ! defined __clang__ && 6 <= __GNUC__ +# pragma GCC diagnostic ignored "-Wnull-dereference" +#endif + +// Old versions of Flex (2.5.35) generate an incomplete documentation comment. +// +// In file included from src/scan-code-c.c:3: +// src/scan-code.c:2198:21: error: empty paragraph passed to '@param' command +// [-Werror,-Wdocumentation] +// * @param line_number +// ~~~~~~~~~~~~~~~~~^ +// 1 error generated. +#if FLEX_VERSION <= 20060000 && defined __clang__ +# pragma clang diagnostic ignored "-Wdocumentation" +#endif + /* Pacify "gcc -Wmissing-prototypes" when flex 2.5.31 is used. */ #if FLEX_VERSION <= 2005031 int FLEX_PREFIX (get_lineno) (void); @@ -44,20 +70,6 @@ int FLEX_PREFIX (lex_destroy) (void); #define last_string FLEX_PREFIX (last_string) -// Pacify warnings in yy_init_buffer (observed with Flex 2.6.4 and GCC -// 7.3.0). -// -// ./src/scan-skel.c: In function 'skel_restart': -// ./src/scan-skel.c:2035:20: error: potential null pointer dereference [-Werror=null-dereference] -// b->yy_fill_buffer = 1; -// ~~~~~~~~~~~~~~~~~~^~~ -// ./src/scan-skel.c:2031:19: error: potential null pointer dereference [-Werror=null-dereference] -// b->yy_input_file = file; -// ~~~~~~~~~~~~~~~~~^~~~~~ -#if defined __GNUC__ && 7 <= __GNUC__ -# pragma GCC diagnostic ignored "-Wnull-dereference" -#endif - /* It seems to be a nice "feature" of Flex that one cannot use yytext, yyleng etc. when a prefix is given, since there is no longer a #define, but rather the token is actually changed in the output. diff --git a/contrib/tools/bison/src/getargs.c b/contrib/tools/bison/src/getargs.c index 9bca42fd60..69486abff9 100644 --- a/contrib/tools/bison/src/getargs.c +++ b/contrib/tools/bison/src/getargs.c @@ -51,8 +51,9 @@ int report_flag = report_none; int trace_flag = trace_none; static struct bison_language const valid_languages[] = { - { "c", "c-skel.m4", ".c", ".h", true }, - { "c++", "c++-skel.m4", ".cc", ".hh", true }, + /* lang, skeleton, ext, hdr, add_tab */ + { "c", "c-skel.m4", ".c", ".h", true }, + { "c++", "c++-skel.m4", ".cc", ".hh", true }, { "java", "java-skel.m4", ".java", ".java", false }, { "", "", "", "", false } }; @@ -129,7 +130,7 @@ flags_argmatch (const char *opt, /** Decode a set of sub arguments. * - * \param FlagName the flag familly to update. + * \param FlagName the flag family to update. * \param Args the effective sub arguments to decode. * \param All the "all" value. * @@ -362,9 +363,21 @@ FEATURE is a list of comma separated words that can include:\n\ fputs (_("General help using GNU software: " "<http://www.gnu.org/gethelp/>.\n"), stdout); + +#if (defined __GLIBC__ && __GLIBC__ >= 2) && !defined __UCLIBC__ /* Don't output this redundant message for English locales. Note we still output for 'C' so that it gets included in the man page. */ + const char *lc_messages = setlocale (LC_MESSAGES, NULL); + if (lc_messages && !STREQ (lc_messages, "en_")) + /* TRANSLATORS: Replace LANG_CODE in this URL with your language + code <http://translationproject.org/team/LANG_CODE.html> to + form one of the URLs at http://translationproject.org/team/. + Otherwise, replace the entire URL with your translation team's + email address. */ + fputs (_("Report translation bugs to " + "<http://translationproject.org/team/>.\n"), stdout); +#endif fputs (_("For complete documentation, run: info bison.\n"), stdout); } @@ -422,8 +435,7 @@ language_argmatch (char const *arg, int prio, location loc) if (prio < language_prio) { - int i; - for (i = 0; valid_languages[i].language[0]; i++) + for (int i = 0; valid_languages[i].language[0]; ++i) if (c_strcasecmp (arg, valid_languages[i].language) == 0) { language_prio = prio; @@ -720,7 +732,7 @@ getargs (int argc, char *argv[]) if (argc - optind != 1) { if (argc - optind < 1) - error (0, 0, _("%s: missing operand"), quotearg_colon (argv[argc - 1])); + error (0, 0, _("missing operand")); else error (0, 0, _("extra operand %s"), quote (argv[optind + 1])); usage (EXIT_FAILURE); diff --git a/contrib/tools/bison/src/gram.c b/contrib/tools/bison/src/gram.c index 1dbe88e779..fd07719e86 100644 --- a/contrib/tools/bison/src/gram.c +++ b/contrib/tools/bison/src/gram.c @@ -46,6 +46,8 @@ symbol_number *token_translations = NULL; int max_user_token_number = 256; +int required_version = 0; + bool rule_useful_in_grammar_p (rule const *r) { @@ -84,8 +86,7 @@ size_t rule_rhs_length (rule const *r) { size_t res = 0; - item_number *rhsp; - for (rhsp = r->rhs; *rhsp >= 0; ++rhsp) + for (item_number *rhsp = r->rhs; *rhsp >= 0; ++rhsp) ++res; return res; } @@ -94,11 +95,8 @@ void rule_rhs_print (rule const *r, FILE *out) { if (0 <= *r->rhs) - { - item_number *rp; - for (rp = r->rhs; *rp >= 0; rp++) - fprintf (out, " %s", symbols[*rp]->tag); - } + for (item_number *rp = r->rhs; *rp >= 0; rp++) + fprintf (out, " %s", symbols[*rp]->tag); else fputs (" %empty", out); } @@ -108,9 +106,8 @@ rule_rhs_print_xml (rule const *r, FILE *out, int level) { if (*r->rhs >= 0) { - item_number *rp; xml_puts (out, level, "<rhs>"); - for (rp = r->rhs; *rp >= 0; rp++) + for (item_number *rp = r->rhs; *rp >= 0; rp++) xml_printf (out, level + 1, "<symbol>%s</symbol>", xml_escape (symbols[*rp]->tag)); xml_puts (out, level, "</rhs>"); @@ -126,9 +123,8 @@ rule_rhs_print_xml (rule const *r, FILE *out, int level) void ritem_print (FILE *out) { - unsigned i; fputs ("RITEM\n", out); - for (i = 0; i < nritems; ++i) + for (unsigned i = 0; i < nritems; ++i) if (ritem[i] >= 0) fprintf (out, " %s", symbols[ritem[i]]->tag); else @@ -140,9 +136,7 @@ size_t ritem_longest_rhs (void) { int max = 0; - rule_number r; - - for (r = 0; r < nrules; ++r) + for (rule_number r = 0; r < nrules; ++r) { int length = rule_rhs_length (&rules[r]); if (length > max) @@ -156,12 +150,11 @@ void grammar_rules_partial_print (FILE *out, const char *title, rule_filter filter) { - rule_number r; bool first = true; sym_content *previous_lhs = NULL; /* rule # : LHS -> RHS */ - for (r = 0; r < nrules + nuseless_productions; r++) + for (rule_number r = 0; r < nrules + nuseless_productions; r++) { if (filter && !filter (&rules[r])) continue; @@ -188,10 +181,9 @@ grammar_rules_print (FILE *out) void grammar_rules_print_xml (FILE *out, int level) { - rule_number r; bool first = true; - for (r = 0; r < nrules + nuseless_productions; r++) + for (rule_number r = 0; r < nrules + nuseless_productions; r++) { if (first) xml_puts (out, level + 1, "<rules>"); @@ -233,10 +225,9 @@ grammar_dump (FILE *out, const char *title) fprintf (out, "Variables\n---------\n\n"); { - symbol_number i; fprintf (out, "Value Sprec Sassoc Tag\n"); - for (i = ntokens; i < nsyms; i++) + for (symbol_number i = ntokens; i < nsyms; i++) fprintf (out, "%5d %5d %5d %s\n", i, symbols[i]->content->prec, symbols[i]->content->assoc, @@ -246,18 +237,16 @@ grammar_dump (FILE *out, const char *title) fprintf (out, "Rules\n-----\n\n"); { - rule_number i; fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs" " -> Rhs (Ritem range) [Num]\n"); - for (i = 0; i < nrules + nuseless_productions; i++) + for (rule_number i = 0; i < nrules + nuseless_productions; i++) { rule const *rule_i = &rules[i]; - item_number *rp = NULL; - unsigned rhs_itemno = rule_i->rhs - ritem; - unsigned rhs_count = 0; + unsigned const rhs_itemno = rule_i->rhs - ritem; /* Find the last RHS index in ritems. */ - for (rp = rule_i->rhs; *rp >= 0; ++rp) + unsigned rhs_count = 0; + for (item_number *rp = rule_i->rhs; *rp >= 0; ++rp) ++rhs_count; fprintf (out, "%3d (%2d, %2d, %2d, %2u-%2u) %2d ->", i, @@ -268,31 +257,28 @@ grammar_dump (FILE *out, const char *title) rhs_itemno + rhs_count - 1, rule_i->lhs->number); /* Dumped the RHS. */ - for (rp = rule_i->rhs; *rp >= 0; rp++) + for (item_number *rp = rule_i->rhs; *rp >= 0; ++rp) fprintf (out, " %3d", *rp); - fprintf (out, " [%d]\n", item_number_as_rule_number (*rp)); + fprintf (out, " [%d]\n", + item_number_as_rule_number (rule_i->rhs[rhs_count+1])); } } fprintf (out, "\n\n"); fprintf (out, "Rules interpreted\n-----------------\n\n"); - { - rule_number r; - for (r = 0; r < nrules + nuseless_productions; r++) - { - fprintf (out, "%-5d %s:", r, rules[r].lhs->symbol->tag); - rule_rhs_print (&rules[r], out); - fprintf (out, "\n"); - } - } + for (rule_number r = 0; r < nrules + nuseless_productions; r++) + { + fprintf (out, "%-5d %s:", r, rules[r].lhs->symbol->tag); + rule_rhs_print (&rules[r], out); + fprintf (out, "\n"); + } fprintf (out, "\n\n"); } void grammar_rules_useless_report (const char *message) { - rule_number r; - for (r = 0; r < nrules ; ++r) + for (rule_number r = 0; r < nrules ; ++r) /* Don't complain about rules whose LHS is useless, we already complained about it. */ if (!reduce_nonterminal_useless_in_grammar (rules[r].lhs) diff --git a/contrib/tools/bison/src/gram.h b/contrib/tools/bison/src/gram.h index bbae54b48a..4ecf4bf2b5 100644 --- a/contrib/tools/bison/src/gram.h +++ b/contrib/tools/bison/src/gram.h @@ -271,4 +271,8 @@ void grammar_rules_useless_report (const char *message); /* Free the packed grammar. */ void grammar_free (void); +/* The version %required by the grammar file, as an int (100 * major + + minor). 0 if unspecified. */ +extern int required_version; + #endif /* !GRAM_H_ */ diff --git a/contrib/tools/bison/src/graphviz.c b/contrib/tools/bison/src/graphviz.c index d85b23de15..a5e3a5e9ab 100644 --- a/contrib/tools/bison/src/graphviz.c +++ b/contrib/tools/bison/src/graphviz.c @@ -87,12 +87,14 @@ escape (char const *name) static void no_reduce_bitset_init (state const *s, bitset *no_reduce_set) { - int n; *no_reduce_set = bitset_create (ntokens, BITSET_FIXED); bitset_zero (*no_reduce_set); - FOR_EACH_SHIFT (s->transitions, n) - bitset_set (*no_reduce_set, TRANSITION_SYMBOL (s->transitions, n)); - for (n = 0; n < s->errs->num; ++n) + { + int n; + FOR_EACH_SHIFT (s->transitions, n) + bitset_set (*no_reduce_set, TRANSITION_SYMBOL (s->transitions, n)); + } + for (int n = 0; n < s->errs->num; ++n) if (s->errs->symbols[n]) bitset_set (*no_reduce_set, s->errs->symbols[n]->content->number); } @@ -145,11 +147,9 @@ conclude_red (struct obstack *out, int source, rule_number ruleno, static bool print_token (struct obstack *out, bool first, char const *tok) { - char const *q = escape (tok); - if (! first) obstack_sgrow (out, ", "); - obstack_sgrow (out, q); + obstack_sgrow (out, escape (tok)); return false; } @@ -157,8 +157,7 @@ void output_red (state const *s, reductions const *reds, FILE *fout) { bitset no_reduce_set; - int j; - int source = s->number; + no_reduce_bitset_init (s, &no_reduce_set); /* Two obstacks are needed: one for the enabled reductions, and one for the disabled reductions, because in the end we want two @@ -166,42 +165,38 @@ output_red (state const *s, reductions const *reds, FILE *fout) be printed. */ struct obstack dout; struct obstack eout; - - no_reduce_bitset_init (s, &no_reduce_set); obstack_init (&dout); obstack_init (&eout); - for (j = 0; j < reds->num; ++j) + const int source = s->number; + for (int j = 0; j < reds->num; ++j) { - bool defaulted = false; + rule *default_reduction = + yydefact[s->number] + ? &rules[yydefact[s->number] - 1] + : NULL; + + bool defaulted = default_reduction && default_reduction == reds->rules[j]; + + /* Build the lookahead tokens lists, one for enabled transitions + and one for disabled transitions. */ bool firstd = true; bool firste = true; rule_number ruleno = reds->rules[j]->number; - rule *default_reduction = NULL; - - if (yydefact[s->number] != 0) - default_reduction = &rules[yydefact[s->number] - 1]; - /* Build the lookahead tokens lists, one for enabled transitions and one - for disabled transistions. */ - if (default_reduction && default_reduction == reds->rules[j]) - defaulted = true; if (reds->lookahead_tokens) - { - int i; - for (i = 0; i < ntokens; i++) - if (bitset_test (reds->lookahead_tokens[j], i)) - { - if (bitset_test (no_reduce_set, i)) - firstd = print_token (&dout, firstd, symbols[i]->tag); - else - { - if (! defaulted) - firste = print_token (&eout, firste, symbols[i]->tag); - bitset_set (no_reduce_set, i); - } - } - } + for (int i = 0; i < ntokens; i++) + if (bitset_test (reds->lookahead_tokens[j], i)) + { + if (bitset_test (no_reduce_set, i)) + firstd = print_token (&dout, firstd, symbols[i]->tag); + else + { + if (! defaulted) + firste = print_token (&eout, firste, symbols[i]->tag); + bitset_set (no_reduce_set, i); + } + } /* Do the actual output. */ conclude_red (&dout, source, ruleno, false, firstd, fout); diff --git a/contrib/tools/bison/src/ielr.c b/contrib/tools/bison/src/ielr.c index 437635674b..5eb7d312dc 100644 --- a/contrib/tools/bison/src/ielr.c +++ b/contrib/tools/bison/src/ielr.c @@ -929,7 +929,7 @@ ielr_compute_state (bitsetv follow_kernel_items, bitsetv always_follows, * compatibility or, if <tt>annotation_lists = NULL</tt>, the canonical * LR(1) state compatibility test was used. * - If <tt>annotation_lists = NULL</tt>, reduction lookahead sets were - * computed in all states. TV_IELR_PHASE4 was pushed while they were + * computed in all states. tv_ielr_phase4 was pushed while they were * computed from item lookahead sets. */ static void @@ -1004,7 +1004,7 @@ ielr_split_states (bitsetv follow_kernel_items, bitsetv always_follows, lookahead sets. */ if (!annotation_lists) { - timevar_push (TV_IELR_PHASE4); + timevar_push (tv_ielr_phase4); initialize_LA (); for (state_list *node = first_state; node; node = node->next) if (!node->state->consistent) @@ -1037,7 +1037,7 @@ ielr_split_states (bitsetv follow_kernel_items, bitsetv always_follows, } } } - timevar_pop (TV_IELR_PHASE4); + timevar_pop (tv_ielr_phase4); } /* Free state list. */ @@ -1080,7 +1080,7 @@ ielr (void) } /* Phase 0: LALR(1). */ - timevar_push (TV_LALR); + timevar_push (tv_lalr); if (lr_type == LR_TYPE__CANONICAL_LR) set_goto_map (); else @@ -1088,10 +1088,10 @@ ielr (void) if (lr_type == LR_TYPE__LALR) { bitsetv_free (goto_follows); - timevar_pop (TV_LALR); + timevar_pop (tv_lalr); return; } - timevar_pop (TV_LALR); + timevar_pop (tv_lalr); { bitsetv follow_kernel_items; @@ -1104,14 +1104,14 @@ ielr (void) { /* Phase 1: Compute Auxiliary Tables. */ state ***predecessors; - timevar_push (TV_IELR_PHASE1); + timevar_push (tv_ielr_phase1); ielr_compute_auxiliary_tables ( &follow_kernel_items, &always_follows, lr_type == LR_TYPE__CANONICAL_LR ? NULL : &predecessors); - timevar_pop (TV_IELR_PHASE1); + timevar_pop (tv_ielr_phase1); /* Phase 2: Compute Annotations. */ - timevar_push (TV_IELR_PHASE2); + timevar_push (tv_ielr_phase2); if (lr_type != LR_TYPE__CANONICAL_LR) { obstack_init (&annotations_obstack); @@ -1125,11 +1125,11 @@ ielr (void) bitsetv_free (goto_follows); lalr_free (); } - timevar_pop (TV_IELR_PHASE2); + timevar_pop (tv_ielr_phase2); } /* Phase 3: Split States. */ - timevar_push (TV_IELR_PHASE3); + timevar_push (tv_ielr_phase3); { state_number nstates_lr0 = nstates; ielr_split_states (follow_kernel_items, always_follows, @@ -1144,11 +1144,11 @@ ielr (void) free (annotation_lists); bitsetv_free (follow_kernel_items); bitsetv_free (always_follows); - timevar_pop (TV_IELR_PHASE3); + timevar_pop (tv_ielr_phase3); } /* Phase 4: Compute Reduction Lookaheads. */ - timevar_push (TV_IELR_PHASE4); + timevar_push (tv_ielr_phase4); free (goto_map); free (from_state); free (to_state); @@ -1163,5 +1163,5 @@ ielr (void) lalr (); bitsetv_free (goto_follows); } - timevar_pop (TV_IELR_PHASE4); + timevar_pop (tv_ielr_phase4); } diff --git a/contrib/tools/bison/src/location.c b/contrib/tools/bison/src/location.c index 5962ef0c41..e75e67e331 100644 --- a/contrib/tools/bison/src/location.c +++ b/contrib/tools/bison/src/location.c @@ -137,7 +137,7 @@ location_print (location loc, FILE *out) } -/* Persistant data used by location_caret to avoid reopening and rereading the +/* Persistent data used by location_caret to avoid reopening and rereading the same file all over for each error. */ struct caret_info { diff --git a/contrib/tools/bison/src/location.h b/contrib/tools/bison/src/location.h index 25a9aa4917..106048dd07 100644 --- a/contrib/tools/bison/src/location.h +++ b/contrib/tools/bison/src/location.h @@ -107,7 +107,7 @@ void location_compute (location *loc, Warning: uses quotearg's slot 3. */ unsigned location_print (location loc, FILE *out); -/* Free any allocated ressources and close any open file handles that are +/* Free any allocated resources and close any open file handles that are left-over by the usage of location_caret. */ void cleanup_caret (void); diff --git a/contrib/tools/bison/src/main.c b/contrib/tools/bison/src/main.c index a5ff83a07f..957005ceaa 100644 --- a/contrib/tools/bison/src/main.c +++ b/contrib/tools/bison/src/main.c @@ -77,9 +77,9 @@ main (int argc, char *argv[]) getargs (argc, argv); - timevar_report = trace_flag & trace_time; - init_timevar (); - timevar_start (TV_TOTAL); + timevar_enabled = trace_flag & trace_time; + timevar_init (); + timevar_start (tv_total); if (trace_flag & trace_bitsets) bitset_stats_enable (); @@ -88,29 +88,29 @@ main (int argc, char *argv[]) and FATTRS. In file reader.c. The other parts are recorded in the grammar; see gram.h. */ - timevar_push (TV_READER); + timevar_push (tv_reader); reader (); - timevar_pop (TV_READER); + timevar_pop (tv_reader); if (complaint_status == status_complaint) goto finish; /* Find useless nonterminals and productions and reduce the grammar. */ - timevar_push (TV_REDUCE); + timevar_push (tv_reduce); reduce_grammar (); - timevar_pop (TV_REDUCE); + timevar_pop (tv_reduce); /* Record other info about the grammar. In files derives and nullable. */ - timevar_push (TV_SETS); + timevar_push (tv_sets); derives_compute (); nullable_compute (); - timevar_pop (TV_SETS); + timevar_pop (tv_sets); /* Compute LR(0) parser states. See state.h for more info. */ - timevar_push (TV_LR0); + timevar_push (tv_lr0); generate_states (); - timevar_pop (TV_LR0); + timevar_pop (tv_lr0); /* Add lookahead sets to parser states. Except when LALR(1) is requested, split states to eliminate LR(1)-relative @@ -121,7 +121,7 @@ main (int argc, char *argv[]) lookahead is not enough to disambiguate the parsing. In file conflicts. Also resolve s/r conflicts based on precedence declarations. */ - timevar_push (TV_CONFLICTS); + timevar_push (tv_conflicts); conflicts_solve (); if (!muscle_percent_define_flag_if ("lr.keep-unreachable-state")) { @@ -133,12 +133,12 @@ main (int argc, char *argv[]) free (old_to_new); } conflicts_print (); - timevar_pop (TV_CONFLICTS); + timevar_pop (tv_conflicts); /* Compute the parser tables. */ - timevar_push (TV_ACTIONS); + timevar_push (tv_actions); tables_generate (); - timevar_pop (TV_ACTIONS); + timevar_pop (tv_actions); grammar_rules_useless_report (_("rule useless in parser due to conflicts")); @@ -150,25 +150,25 @@ main (int argc, char *argv[]) /* Output the detailed report on the grammar. */ if (report_flag) { - timevar_push (TV_REPORT); + timevar_push (tv_report); print_results (); - timevar_pop (TV_REPORT); + timevar_pop (tv_report); } /* Output the graph. */ if (graph_flag) { - timevar_push (TV_GRAPH); + timevar_push (tv_graph); print_graph (); - timevar_pop (TV_GRAPH); + timevar_pop (tv_graph); } /* Output xml. */ if (xml_flag) { - timevar_push (TV_XML); + timevar_push (tv_xml); print_xml (); - timevar_pop (TV_XML); + timevar_pop (tv_xml); } /* Stop if there were errors, to avoid trashing previous output @@ -177,16 +177,16 @@ main (int argc, char *argv[]) goto finish; /* Lookahead tokens are no longer needed. */ - timevar_push (TV_FREE); + timevar_push (tv_free); lalr_free (); - timevar_pop (TV_FREE); + timevar_pop (tv_free); /* Output the tables and the parser to ftable. In file output. */ - timevar_push (TV_PARSER); + timevar_push (tv_parser); output (); - timevar_pop (TV_PARSER); + timevar_pop (tv_parser); - timevar_push (TV_FREE); + timevar_push (tv_free); nullable_free (); derives_free (); tables_free (); @@ -204,7 +204,7 @@ main (int argc, char *argv[]) code_scanner_free (); skel_scanner_free (); quotearg_free (); - timevar_pop (TV_FREE); + timevar_pop (tv_free); if (trace_flag & trace_bitsets) bitset_stats_dump (stderr); @@ -212,7 +212,7 @@ main (int argc, char *argv[]) finish: /* Stop timing and print the times. */ - timevar_stop (TV_TOTAL); + timevar_stop (tv_total); timevar_print (stderr); cleanup_caret (); diff --git a/contrib/tools/bison/src/muscle-tab.c b/contrib/tools/bison/src/muscle-tab.c index c14273f60a..d4c195cb9d 100644 --- a/contrib/tools/bison/src/muscle-tab.c +++ b/contrib/tools/bison/src/muscle-tab.c @@ -175,9 +175,6 @@ muscle_grow (const char *key, const char *val, const char *separator, const char *terminator) { muscle_entry *entry = muscle_lookup (key); - size_t vals = strlen (val); - size_t terms = strlen (terminator); - if (entry) { obstack_sgrow (&muscle_obstack, entry->value); @@ -189,12 +186,14 @@ muscle_grow (const char *key, const char *val, obstack_sgrow (&muscle_obstack, val); + size_t vals = strlen (val); + size_t terms = strlen (terminator); if (terms <= vals && STRNEQ (val + vals - terms, terminator)) obstack_sgrow (&muscle_obstack, terminator); { - char *new_val = obstack_finish0 (&muscle_obstack); + char const *new_val = obstack_finish0 (&muscle_obstack); entry->value = entry->storage = xstrdup (new_val); obstack_free (&muscle_obstack, new_val); } @@ -208,12 +207,11 @@ muscle_grow (const char *key, const char *val, static void muscle_syncline_grow (char const *key, location loc) { - char *extension = NULL; obstack_printf (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line); obstack_quote (&muscle_obstack, quotearg_style (c_quoting_style, loc.start.file)); obstack_sgrow (&muscle_obstack, ")["); - extension = obstack_finish0 (&muscle_obstack); + char const *extension = obstack_finish0 (&muscle_obstack); muscle_grow (key, extension, "", ""); obstack_free (&muscle_obstack, extension); } @@ -236,13 +234,12 @@ void muscle_pair_list_grow (const char *muscle, const char *a1, const char *a2) { - char *pair; obstack_sgrow (&muscle_obstack, "["); obstack_quote (&muscle_obstack, a1); obstack_sgrow (&muscle_obstack, ", "); obstack_quote (&muscle_obstack, a2); obstack_sgrow (&muscle_obstack, "]"); - pair = obstack_finish0 (&muscle_obstack); + char const *pair = obstack_finish0 (&muscle_obstack); muscle_grow (muscle, pair, ",\n", ""); obstack_free (&muscle_obstack, pair); } @@ -275,11 +272,10 @@ muscle_find (char const *key) static void muscle_boundary_grow (char const *key, boundary bound) { - char *extension; obstack_sgrow (&muscle_obstack, "[["); obstack_escape (&muscle_obstack, bound.file); obstack_printf (&muscle_obstack, ":%d.%d]]", bound.line, bound.column); - extension = obstack_finish0 (&muscle_obstack); + char const *extension = obstack_finish0 (&muscle_obstack); muscle_grow (key, extension, "", ""); obstack_free (&muscle_obstack, extension); } @@ -322,9 +318,6 @@ static char * string_decode (char const *key) { char const *value = muscle_find_const (key); - char *value_decoded; - char *result; - if (!value) return NULL; do { @@ -337,20 +330,20 @@ string_decode (char const *key) break; } } while (*value++); - value_decoded = obstack_finish (&muscle_obstack); - result = xstrdup (value_decoded); + char const *value_decoded = obstack_finish (&muscle_obstack); + char *res = xstrdup (value_decoded); obstack_free (&muscle_obstack, value_decoded); - return result; + return res; } /* Reverse of muscle_location_grow. */ static location location_decode (char const *value) { - location loc; aver (value); aver (*value == '['); ++value; aver (*value == '['); + location loc; while (*++value) switch (*value) { @@ -359,29 +352,26 @@ location_decode (char const *value) aver (false); break; case ']': - { - char *boundary_str; - ++value; aver (*value == ']'); - boundary_str = obstack_finish0 (&muscle_obstack); - switch (*++value) - { - case ',': - boundary_set_from_string (&loc.start, boundary_str); - obstack_free (&muscle_obstack, boundary_str); - ++value; aver (*value == ' '); - ++value; aver (*value == '['); - ++value; aver (*value == '['); - break; - case '\0': - boundary_set_from_string (&loc.end, boundary_str); - obstack_free (&muscle_obstack, boundary_str); - return loc; - break; - default: - aver (false); - break; - } - } + ++value; aver (*value == ']'); + char *boundary_str = obstack_finish0 (&muscle_obstack); + switch (*++value) + { + case ',': + boundary_set_from_string (&loc.start, boundary_str); + obstack_free (&muscle_obstack, boundary_str); + ++value; aver (*value == ' '); + ++value; aver (*value == '['); + ++value; aver (*value == '['); + break; + case '\0': + boundary_set_from_string (&loc.end, boundary_str); + obstack_free (&muscle_obstack, boundary_str); + return loc; + break; + default: + aver (false); + break; + } break; } aver (false); @@ -446,21 +436,21 @@ muscle_percent_variable_update (char const *variable, location variable_loc, } conversion_type; const conversion_type conversion[] = { - { "api.push_pull", "api.push-pull", }, - { "api.tokens.prefix", "api.token.prefix", }, - { "lex_symbol", "api.token.constructor", }, - { "location_type", "api.location.type", }, - { "lr.default-reductions", "lr.default-reduction", }, + { "api.push_pull", "api.push-pull", }, + { "api.tokens.prefix", "api.token.prefix", }, + { "lex_symbol", "api.token.constructor", }, + { "location_type", "api.location.type", }, + { "lr.default-reductions", "lr.default-reduction", }, { "lr.keep-unreachable-states", "lr.keep-unreachable-state", }, { "lr.keep_unreachable_states", "lr.keep-unreachable-state", }, - { "namespace", "api.namespace", }, - { "stype", "api.value.type", }, - { "variant=", "api.value.type=variant", }, - { "variant=true", "api.value.type=variant", }, + { "namespace", "api.namespace", }, + { "stype", "api.value.type", }, + { "variant=", "api.value.type=variant", }, + { "variant=true", "api.value.type=variant", }, { NULL, NULL, } }; - conversion_type const *c; - for (c = conversion; c->obsolete; ++c) + + for (conversion_type const *c = conversion; c->obsolete; ++c) { char const *eq = strchr (c->obsolete, '='); if (eq @@ -474,14 +464,12 @@ muscle_percent_variable_update (char const *variable, location variable_loc, free (old); free (upd); char *res = xstrdup (c->updated); - { - char *eq2 = strchr (res, '='); - if (eq2) - { - *eq2 = '\0'; - *value = eq2 + 1; - } - } + char *eq2 = strchr (res, '='); + if (eq2) + { + *eq2 = '\0'; + *value = eq2 + 1; + } return res; } } @@ -507,9 +495,9 @@ muscle_percent_define_insert (char const *var, location variable_loc, && muscle_find_const (name)) { muscle_percent_define_how how_old = atoi (muscle_find_const (how_name)); - unsigned i = 0; if (how_old == MUSCLE_PERCENT_DEFINE_F) goto end; + unsigned i = 0; complain_indent (&variable_loc, complaint, &i, _("%%define variable %s redefined"), quote (variable)); @@ -645,16 +633,16 @@ bool muscle_percent_define_flag_if (char const *variable) { uniqstr invalid_boolean_name = muscle_name (variable, "invalid_boolean"); - bool result = false; + bool res = false; if (muscle_percent_define_ifdef (variable)) { char *value = muscle_percent_define_get (variable); muscle_percent_define_check_kind (variable, muscle_keyword); if (value[0] == '\0' || STREQ (value, "true")) - result = true; + res = true; else if (STREQ (value, "false")) - result = false; + res = false; else if (!muscle_find_const (invalid_boolean_name)) { muscle_insert (invalid_boolean_name, ""); @@ -669,7 +657,7 @@ muscle_percent_define_flag_if (char const *variable) complain (NULL, fatal, _("%s: undefined %%define variable %s"), "muscle_percent_define_flag", quote (variable)); - return result; + return res; } void @@ -705,14 +693,12 @@ muscle_percent_define_check_values (char const * const *values) if (value) { for (++values; *values; ++values) - { - if (STREQ (value, *values)) - break; - } + if (STREQ (value, *values)) + break; if (!*values) { - unsigned i = 0; location loc = muscle_percent_define_get_loc (*variablep); + unsigned i = 0; complain_indent (&loc, complaint, &i, _("invalid value for %%define variable %s: %s"), quote (*variablep), quote_n (1, value)); @@ -722,10 +708,8 @@ muscle_percent_define_check_values (char const * const *values) _("accepted value: %s"), quote (*values)); } else - { - while (*values) - ++values; - } + while (*values) + ++values; free (value); } else diff --git a/contrib/tools/bison/src/muscle-tab.h b/contrib/tools/bison/src/muscle-tab.h index 4ec1ae1b27..b1c59506a1 100644 --- a/contrib/tools/bison/src/muscle-tab.h +++ b/contrib/tools/bison/src/muscle-tab.h @@ -158,7 +158,7 @@ char *muscle_percent_define_get (char const *variable); /* Mimic muscle_percent_define_get_loc in ../data/bison.m4 exactly. That is, if the %define variable VARIABLE is undefined, complain fatally since that's a Bison error. Otherwise, return its definition location in a form - approriate for the first argument of warn_at, complain_at, or fatal_at. + appropriate for the first argument of warn_at, complain_at, or 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. */ location muscle_percent_define_get_loc (char const *variable); diff --git a/contrib/tools/bison/src/output.c b/contrib/tools/bison/src/output.c index a4f7910bca..5009fe7f7b 100644 --- a/contrib/tools/bison/src/output.c +++ b/contrib/tools/bison/src/output.c @@ -21,10 +21,10 @@ #include <config.h> #include "system.h" -#include <concat-filename.h> #include <configmake.h> -#include <filename.h> +#include <filename.h> /* IS_PATH_WITH_DIR */ #include <get-errno.h> +#include <path-join.h> #include <quotearg.h> #include <spawn-pipe.h> #include <timevar.h> @@ -58,7 +58,7 @@ default_pkgdatadir() const char* arc_path = getenv("ARCADIA_ROOT_DISTBUILD"); if (arc_path == NULL) arc_path = ArcadiaRoot(); - return uniqstr_vsprintf("%s/" STR(BISON_DATA_DIR), arc_path); + return uniqstr_concat(3, arc_path, "/", STR(BISON_DATA_DIR)); } #undef PKGDATADIR #define PKGDATADIR (default_pkgdatadir()) @@ -552,11 +552,11 @@ output_skeleton (void) /* Compute the names of the package data dir and skeleton files. */ char const *m4 = (m4 = getenv ("M4")) ? m4 : M4; char const *datadir = pkgdatadir (); - char *m4sugar = xconcatenated_filename (datadir, "m4sugar/m4sugar.m4", NULL); - char *m4bison = xconcatenated_filename (datadir, "bison.m4", NULL); + char *m4sugar = xpath_join (datadir, "m4sugar/m4sugar.m4"); + char *m4bison = xpath_join (datadir, "bison.m4"); char *skel = (IS_PATH_WITH_DIR (skeleton) ? xstrdup (skeleton) - : xconcatenated_filename (datadir, skeleton, NULL)); + : xpath_join (datadir, skeleton)); /* Test whether m4sugar.m4 is readable, to check for proper installation. A faulty installation can cause deadlock, so a @@ -624,7 +624,7 @@ output_skeleton (void) } /* Read and process m4's output. */ - timevar_push (TV_M4); + timevar_push (tv_m4); { FILE *in = xfdopen (filter_fd[0], "r"); scan_skel (in); @@ -635,7 +635,7 @@ output_skeleton (void) xfclose (in); } wait_subprocess (pid, "m4", false, false, true, true, NULL); - timevar_pop (TV_M4); + timevar_pop (tv_m4); } static void @@ -646,6 +646,8 @@ prepare (void) char const *cp = getenv ("BISON_USE_PUSH_FOR_PULL"); bool use_push_for_pull_flag = cp && *cp && strtol (cp, 0, 10); + MUSCLE_INSERT_INT ("required_version", required_version); + /* Flags. */ MUSCLE_INSERT_BOOL ("defines_flag", defines_flag); MUSCLE_INSERT_BOOL ("glr_flag", glr_parser); diff --git a/contrib/tools/bison/src/parse-gram.c b/contrib/tools/bison/src/parse-gram.c index bf9ade4734..82ac533466 100644 --- a/contrib/tools/bison/src/parse-gram.c +++ b/contrib/tools/bison/src/parse-gram.c @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 3.0.5.75-d835. */ +/* A Bison parser, made by GNU Bison 3.1.91.31-00793. */ /* Bison implementation for Yacc-like parsers in C @@ -40,11 +40,14 @@ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ +/* Undocumented macros, especially those whose name start with YY_, + are private implementation details. Do not rely on them. */ + /* Identify Bison output. */ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "3.0.5.75-d835" +#define YYBISON_VERSION "3.1.91.31-00793" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -64,7 +67,7 @@ /* On column 0 to please syntax-check. */ #include <config.h> -#line 68 "src/parse-gram.c" /* yacc.c:316 */ +#line 71 "src/parse-gram.c" /* yacc.c:316 */ /* Substitute the type names. */ #define YYSTYPE GRAM_STYPE #define YYLTYPE GRAM_LTYPE @@ -76,15 +79,16 @@ #define yynerrs gram_nerrs -/* Copy the first part of user declarations. */ - -#line 82 "src/parse-gram.c" /* yacc.c:339 */ # 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 @@ -116,11 +120,11 @@ extern int gram_debug; #endif /* "%code requires" blocks. */ -#line 21 "src/parse-gram.y" /* yacc.c:355 */ +#line 21 "src/parse-gram.y" /* yacc.c:353 */ #include "symlist.h" #include "symtab.h" -#line 221 "src/parse-gram.y" /* yacc.c:355 */ +#line 222 "src/parse-gram.y" /* yacc.c:353 */ typedef enum { @@ -129,10 +133,10 @@ extern int gram_debug; param_parse = 1 << 1, param_both = param_lex | param_parse } param_type; -#line 644 "src/parse-gram.y" /* yacc.c:355 */ +#line 645 "src/parse-gram.y" /* yacc.c:353 */ #include "muscle-tab.h" -#line 136 "src/parse-gram.c" /* yacc.c:355 */ +#line 140 "src/parse-gram.c" /* yacc.c:353 */ /* Token type. */ #ifndef GRAM_TOKENTYPE @@ -203,27 +207,27 @@ extern int gram_debug; union GRAM_STYPE { -#line 182 "src/parse-gram.y" /* yacc.c:355 */ +#line 183 "src/parse-gram.y" /* yacc.c:353 */ unsigned char character; -#line 186 "src/parse-gram.y" /* yacc.c:355 */ +#line 187 "src/parse-gram.y" /* yacc.c:353 */ char *code; -#line 191 "src/parse-gram.y" /* yacc.c:355 */ +#line 192 "src/parse-gram.y" /* yacc.c:353 */ uniqstr uniqstr; -#line 199 "src/parse-gram.y" /* yacc.c:355 */ +#line 200 "src/parse-gram.y" /* yacc.c:353 */ int integer; -#line 203 "src/parse-gram.y" /* yacc.c:355 */ +#line 204 "src/parse-gram.y" /* yacc.c:353 */ symbol *symbol; -#line 208 "src/parse-gram.y" /* yacc.c:355 */ +#line 209 "src/parse-gram.y" /* yacc.c:353 */ assoc assoc; -#line 211 "src/parse-gram.y" /* yacc.c:355 */ +#line 212 "src/parse-gram.y" /* yacc.c:353 */ symbol_list *list; -#line 214 "src/parse-gram.y" /* yacc.c:355 */ +#line 215 "src/parse-gram.y" /* yacc.c:353 */ named_ref *named_ref; -#line 241 "src/parse-gram.y" /* yacc.c:355 */ +#line 242 "src/parse-gram.y" /* yacc.c:353 */ param_type param; -#line 408 "src/parse-gram.y" /* yacc.c:355 */ +#line 409 "src/parse-gram.y" /* yacc.c:353 */ code_props_type code_type; -#line 646 "src/parse-gram.y" /* yacc.c:355 */ +#line 647 "src/parse-gram.y" /* yacc.c:353 */ struct { @@ -231,7 +235,7 @@ code_props_type code_type; muscle_kind kind; } value; -#line 235 "src/parse-gram.c" /* yacc.c:355 */ +#line 239 "src/parse-gram.c" /* yacc.c:353 */ }; typedef union GRAM_STYPE GRAM_STYPE; @@ -259,13 +263,12 @@ int gram_parse (void); #endif /* !YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED */ -/* Copy the second part of user declarations. */ -#line 265 "src/parse-gram.c" /* yacc.c:358 */ /* Unqualified %code blocks. */ -#line 33 "src/parse-gram.y" /* yacc.c:359 */ +#line 33 "src/parse-gram.y" /* yacc.c:356 */ #include "system.h" + #include <errno.h> #include "c-ctype.h" #include "complain.h" @@ -326,7 +329,7 @@ int gram_parse (void); #define YYTYPE_INT8 int_fast8_t #define YYTYPE_UINT16 uint_fast16_t #define YYTYPE_UINT8 uint_fast8_t -#line 231 "src/parse-gram.y" /* yacc.c:359 */ +#line 232 "src/parse-gram.y" /* yacc.c:356 */ /** Add a lex-param and/or a parse-param. * @@ -337,7 +340,7 @@ int gram_parse (void); static void add_param (param_type type, char *decl, location loc); static param_type current_param = param_none; -#line 341 "src/parse-gram.c" /* yacc.c:359 */ +#line 344 "src/parse-gram.c" /* yacc.c:356 */ #ifdef short # undef short @@ -412,15 +415,6 @@ typedef short yytype_int16; # 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__)) -# endif -#endif - /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ # define YYUSE(E) ((void) (E)) @@ -428,7 +422,7 @@ typedef short yytype_int16; # define YYUSE(E) /* empty */ #endif -#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ _Pragma ("GCC diagnostic push") \ @@ -619,18 +613,18 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 264, 264, 273, 274, 278, 279, 285, 289, 294, - 295, 300, 306, 307, 308, 309, 314, 319, 320, 321, - 322, 323, 324, 324, 325, 326, 350, 351, 352, 353, - 357, 358, 367, 368, 369, 373, 384, 388, 392, 400, - 411, 412, 422, 423, 429, 441, 441, 446, 446, 451, - 461, 475, 476, 477, 478, 482, 483, 488, 490, 495, - 500, 510, 512, 517, 518, 522, 523, 527, 528, 529, - 534, 539, 544, 550, 556, 567, 568, 577, 578, 584, - 585, 586, 593, 593, 601, 602, 603, 608, 611, 613, - 615, 617, 619, 621, 623, 628, 629, 639, 640, 665, - 666, 667, 668, 680, 682, 691, 696, 697, 702, 710, - 711 + 0, 265, 265, 274, 275, 279, 280, 286, 290, 295, + 296, 301, 307, 308, 309, 310, 315, 320, 321, 322, + 323, 324, 325, 325, 326, 327, 351, 352, 353, 354, + 358, 359, 368, 369, 370, 374, 385, 389, 393, 401, + 412, 413, 423, 424, 430, 442, 442, 447, 447, 452, + 462, 476, 477, 478, 479, 483, 484, 489, 491, 496, + 501, 511, 513, 518, 519, 523, 524, 528, 529, 530, + 535, 540, 545, 551, 557, 568, 569, 578, 579, 585, + 586, 587, 594, 594, 602, 603, 604, 609, 612, 614, + 616, 618, 620, 622, 624, 629, 630, 640, 641, 666, + 667, 668, 669, 681, 683, 692, 697, 698, 703, 711, + 712 }; #endif @@ -937,10 +931,10 @@ do { \ /* Print *YYLOCP on YYO. Private, do not rely on its existence. */ YY_ATTRIBUTE_UNUSED -static unsigned +static int yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) { - unsigned res = 0; + int res = 0; int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; if (0 <= yylocp->first_line) { @@ -983,98 +977,98 @@ do { \ } while (0) -/*----------------------------------------. -| Print this symbol's value on YYOUTPUT. | -`----------------------------------------*/ +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) +yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) { - FILE *yyo = yyoutput; - YYUSE (yyo); + FILE *yyoutput = yyo; + YYUSE (yyoutput); YYUSE (yylocationp); if (!yyvaluep) return; # ifdef YYPRINT if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); + YYPRINT (yyo, yytoknum[yytype], *yyvaluep); # endif switch (yytype) { case 3: /* "string" */ -#line 188 "src/parse-gram.y" /* yacc.c:684 */ +#line 189 "src/parse-gram.y" /* yacc.c:681 */ { fputs (quotearg_style (c_quoting_style, ((*yyvaluep).code)), yyo); } -#line 1008 "src/parse-gram.c" /* yacc.c:684 */ +#line 1002 "src/parse-gram.c" /* yacc.c:681 */ break; case 23: /* "%<flag>" */ -#line 196 "src/parse-gram.y" /* yacc.c:684 */ +#line 197 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "%%%s", ((*yyvaluep).uniqstr)); } -#line 1014 "src/parse-gram.c" /* yacc.c:684 */ +#line 1008 "src/parse-gram.c" /* yacc.c:681 */ break; case 39: /* "{...}" */ -#line 189 "src/parse-gram.y" /* yacc.c:684 */ +#line 190 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); } -#line 1020 "src/parse-gram.c" /* yacc.c:684 */ +#line 1014 "src/parse-gram.c" /* yacc.c:681 */ break; case 40: /* "%?{...}" */ -#line 189 "src/parse-gram.y" /* yacc.c:684 */ +#line 190 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); } -#line 1026 "src/parse-gram.c" /* yacc.c:684 */ +#line 1020 "src/parse-gram.c" /* yacc.c:681 */ break; case 41: /* "[identifier]" */ -#line 194 "src/parse-gram.y" /* yacc.c:684 */ +#line 195 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "[%s]", ((*yyvaluep).uniqstr)); } -#line 1032 "src/parse-gram.c" /* yacc.c:684 */ +#line 1026 "src/parse-gram.c" /* yacc.c:681 */ break; case 42: /* "char" */ -#line 184 "src/parse-gram.y" /* yacc.c:684 */ +#line 185 "src/parse-gram.y" /* yacc.c:681 */ { fputs (char_name (((*yyvaluep).character)), yyo); } -#line 1038 "src/parse-gram.c" /* yacc.c:684 */ +#line 1032 "src/parse-gram.c" /* yacc.c:681 */ break; case 43: /* "epilogue" */ -#line 189 "src/parse-gram.y" /* yacc.c:684 */ +#line 190 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); } -#line 1044 "src/parse-gram.c" /* yacc.c:684 */ +#line 1038 "src/parse-gram.c" /* yacc.c:681 */ break; case 45: /* "identifier" */ -#line 193 "src/parse-gram.y" /* yacc.c:684 */ +#line 194 "src/parse-gram.y" /* yacc.c:681 */ { fputs (((*yyvaluep).uniqstr), yyo); } -#line 1050 "src/parse-gram.c" /* yacc.c:684 */ +#line 1044 "src/parse-gram.c" /* yacc.c:681 */ break; case 46: /* "identifier:" */ -#line 195 "src/parse-gram.y" /* yacc.c:684 */ +#line 196 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "%s:", ((*yyvaluep).uniqstr)); } -#line 1056 "src/parse-gram.c" /* yacc.c:684 */ +#line 1050 "src/parse-gram.c" /* yacc.c:681 */ break; case 49: /* "%{...%}" */ -#line 189 "src/parse-gram.y" /* yacc.c:684 */ +#line 190 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).code)); } -#line 1062 "src/parse-gram.c" /* yacc.c:684 */ +#line 1056 "src/parse-gram.c" /* yacc.c:681 */ break; case 51: /* "<tag>" */ -#line 197 "src/parse-gram.y" /* yacc.c:684 */ +#line 198 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "<%s>", ((*yyvaluep).uniqstr)); } -#line 1068 "src/parse-gram.c" /* yacc.c:684 */ +#line 1062 "src/parse-gram.c" /* yacc.c:681 */ break; case 54: /* "integer" */ -#line 201 "src/parse-gram.y" /* yacc.c:684 */ +#line 202 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "%d", ((*yyvaluep).integer)); } -#line 1074 "src/parse-gram.c" /* yacc.c:684 */ +#line 1068 "src/parse-gram.c" /* yacc.c:681 */ break; case 55: /* "%param" */ -#line 244 "src/parse-gram.y" /* yacc.c:684 */ +#line 245 "src/parse-gram.y" /* yacc.c:681 */ { switch (((*yyvaluep).param)) { @@ -1087,35 +1081,35 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue case param_none: aver (false); break; } } -#line 1091 "src/parse-gram.c" /* yacc.c:684 */ +#line 1085 "src/parse-gram.c" /* yacc.c:681 */ break; case 65: /* code_props_type */ -#line 409 "src/parse-gram.y" /* yacc.c:684 */ +#line 410 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "%s", code_props_type_string (((*yyvaluep).code_type))); } -#line 1097 "src/parse-gram.c" /* yacc.c:684 */ +#line 1091 "src/parse-gram.c" /* yacc.c:681 */ break; case 74: /* symbol.prec */ -#line 205 "src/parse-gram.y" /* yacc.c:684 */ +#line 206 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); } -#line 1103 "src/parse-gram.c" /* yacc.c:684 */ +#line 1097 "src/parse-gram.c" /* yacc.c:681 */ break; case 78: /* tag */ -#line 197 "src/parse-gram.y" /* yacc.c:684 */ +#line 198 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "<%s>", ((*yyvaluep).uniqstr)); } -#line 1109 "src/parse-gram.c" /* yacc.c:684 */ +#line 1103 "src/parse-gram.c" /* yacc.c:681 */ break; case 88: /* variable */ -#line 193 "src/parse-gram.y" /* yacc.c:684 */ +#line 194 "src/parse-gram.y" /* yacc.c:681 */ { fputs (((*yyvaluep).uniqstr), yyo); } -#line 1115 "src/parse-gram.c" /* yacc.c:684 */ +#line 1109 "src/parse-gram.c" /* yacc.c:681 */ break; case 89: /* value */ -#line 655 "src/parse-gram.y" /* yacc.c:684 */ +#line 656 "src/parse-gram.y" /* yacc.c:681 */ { switch (((*yyvaluep).value).kind) { @@ -1124,31 +1118,31 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue case muscle_string: fprintf (yyo, "\"%s\"", ((*yyvaluep).value).chars); break; } } -#line 1128 "src/parse-gram.c" /* yacc.c:684 */ +#line 1122 "src/parse-gram.c" /* yacc.c:681 */ break; case 90: /* id */ -#line 205 "src/parse-gram.y" /* yacc.c:684 */ +#line 206 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); } -#line 1134 "src/parse-gram.c" /* yacc.c:684 */ +#line 1128 "src/parse-gram.c" /* yacc.c:681 */ break; case 91: /* id_colon */ -#line 206 "src/parse-gram.y" /* yacc.c:684 */ +#line 207 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "%s:", ((*yyvaluep).symbol)->tag); } -#line 1140 "src/parse-gram.c" /* yacc.c:684 */ +#line 1134 "src/parse-gram.c" /* yacc.c:681 */ break; case 92: /* symbol */ -#line 205 "src/parse-gram.y" /* yacc.c:684 */ +#line 206 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); } -#line 1146 "src/parse-gram.c" /* yacc.c:684 */ +#line 1140 "src/parse-gram.c" /* yacc.c:681 */ break; case 93: /* string_as_id */ -#line 205 "src/parse-gram.y" /* yacc.c:684 */ +#line 206 "src/parse-gram.y" /* yacc.c:681 */ { fprintf (yyo, "%s", ((*yyvaluep).symbol)->tag); } -#line 1152 "src/parse-gram.c" /* yacc.c:684 */ +#line 1146 "src/parse-gram.c" /* yacc.c:681 */ break; @@ -1158,20 +1152,20 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue } -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) +yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp) { - YYFPRINTF (yyoutput, "%s %s (", + YYFPRINTF (yyo, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); - YY_LOCATION_PRINT (yyoutput, *yylocationp); - YYFPRINTF (yyoutput, ": "); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp); - YYFPRINTF (yyoutput, ")"); + YY_LOCATION_PRINT (yyo, *yylocationp); + YYFPRINTF (yyo, ": "); + yy_symbol_value_print (yyo, yytype, yyvaluep, yylocationp); + YYFPRINTF (yyo, ")"); } /*------------------------------------------------------------------. @@ -1276,7 +1270,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) { @@ -1439,7 +1433,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; @@ -1455,15 +1449,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) { @@ -1483,7 +1476,7 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, } *++yyesp = yystate; } - YYDPRINTF ((stderr, " G%d", yystate)); + YYDPRINTF ((stderr, " G%d", (int) yystate)); } } } @@ -1571,7 +1564,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 @@ -1843,7 +1836,7 @@ YYLTYPE yylloc = yyloc_default; yychar = YYEMPTY; /* Cause a token to be read. */ /* User initialization code. */ -#line 108 "src/parse-gram.y" /* yacc.c:1433 */ +#line 109 "src/parse-gram.y" /* yacc.c:1429 */ { /* Bison's grammar can initial empty locations, hence a default location is needed. */ @@ -1851,7 +1844,7 @@ YYLTYPE yylloc = yyloc_default; boundary_set (&yylloc.end, current_file, 1, 1); } -#line 1855 "src/parse-gram.c" /* yacc.c:1433 */ +#line 1848 "src/parse-gram.c" /* yacc.c:1429 */ yylsp[0] = yylloc; goto yysetstate; @@ -1864,12 +1857,12 @@ YYLTYPE yylloc = yyloc_default; 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 { @@ -1889,10 +1882,9 @@ YYLTYPE yylloc = yyloc_default; &yyvs1, yysize * sizeof (*yyvsp), &yyls1, yysize * sizeof (*yylsp), &yystacksize); - - yyls = yyls1; yyss = yyss1; yyvs = yyvs1; + yyls = yyls1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE @@ -2045,144 +2037,144 @@ yyreduce: int yychar_backup = yychar; switch (yyn) { - case 6: -#line 280 "src/parse-gram.y" /* yacc.c:1651 */ + case 6: +#line 281 "src/parse-gram.y" /* yacc.c:1645 */ { muscle_code_grow (union_seen ? "post_prologue" : "pre_prologue", translate_code ((yyvsp[0].code), (yylsp[0]), true), (yylsp[0])); code_scanner_last_string_free (); } -#line 2056 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2048 "src/parse-gram.c" /* yacc.c:1645 */ break; case 7: -#line 286 "src/parse-gram.y" /* yacc.c:1651 */ +#line 287 "src/parse-gram.y" /* yacc.c:1645 */ { muscle_percent_define_ensure ((yyvsp[0].uniqstr), (yylsp[0]), true); } -#line 2064 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2056 "src/parse-gram.c" /* yacc.c:1645 */ break; case 8: -#line 290 "src/parse-gram.y" /* yacc.c:1651 */ +#line 291 "src/parse-gram.y" /* yacc.c:1645 */ { muscle_percent_define_insert ((yyvsp[-1].uniqstr), (yylsp[-1]), (yyvsp[0].value).kind, (yyvsp[0].value).chars, MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE); } -#line 2073 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2065 "src/parse-gram.c" /* yacc.c:1645 */ break; case 9: -#line 294 "src/parse-gram.y" /* yacc.c:1651 */ +#line 295 "src/parse-gram.y" /* yacc.c:1645 */ { defines_flag = true; } -#line 2079 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2071 "src/parse-gram.c" /* yacc.c:1645 */ break; case 10: -#line 296 "src/parse-gram.y" /* yacc.c:1651 */ +#line 297 "src/parse-gram.y" /* yacc.c:1645 */ { defines_flag = true; spec_defines_file = xstrdup ((yyvsp[0].code)); } -#line 2088 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2080 "src/parse-gram.c" /* yacc.c:1645 */ break; case 11: -#line 301 "src/parse-gram.y" /* yacc.c:1651 */ +#line 302 "src/parse-gram.y" /* yacc.c:1645 */ { muscle_percent_define_insert ("parse.error", (yylsp[0]), muscle_keyword, "verbose", MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE); } -#line 2098 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2090 "src/parse-gram.c" /* yacc.c:1645 */ break; case 12: -#line 306 "src/parse-gram.y" /* yacc.c:1651 */ +#line 307 "src/parse-gram.y" /* yacc.c:1645 */ { expected_sr_conflicts = (yyvsp[0].integer); } -#line 2104 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2096 "src/parse-gram.c" /* yacc.c:1645 */ break; case 13: -#line 307 "src/parse-gram.y" /* yacc.c:1651 */ +#line 308 "src/parse-gram.y" /* yacc.c:1645 */ { expected_rr_conflicts = (yyvsp[0].integer); } -#line 2110 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2102 "src/parse-gram.c" /* yacc.c:1645 */ break; case 14: -#line 308 "src/parse-gram.y" /* yacc.c:1651 */ +#line 309 "src/parse-gram.y" /* yacc.c:1645 */ { spec_file_prefix = (yyvsp[0].code); } -#line 2116 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2108 "src/parse-gram.c" /* yacc.c:1645 */ break; case 15: -#line 310 "src/parse-gram.y" /* yacc.c:1651 */ +#line 311 "src/parse-gram.y" /* yacc.c:1645 */ { nondeterministic_parser = true; glr_parser = true; } -#line 2125 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2117 "src/parse-gram.c" /* yacc.c:1645 */ break; case 16: -#line 315 "src/parse-gram.y" /* yacc.c:1651 */ +#line 316 "src/parse-gram.y" /* yacc.c:1645 */ { muscle_code_grow ("initial_action", translate_code ((yyvsp[0].code), (yylsp[0]), false), (yylsp[0])); code_scanner_last_string_free (); } -#line 2134 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2126 "src/parse-gram.c" /* yacc.c:1645 */ break; case 17: -#line 319 "src/parse-gram.y" /* yacc.c:1651 */ +#line 320 "src/parse-gram.y" /* yacc.c:1645 */ { language_argmatch ((yyvsp[0].code), grammar_prio, (yylsp[-1])); } -#line 2140 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2132 "src/parse-gram.c" /* yacc.c:1645 */ break; case 18: -#line 320 "src/parse-gram.y" /* yacc.c:1651 */ +#line 321 "src/parse-gram.y" /* yacc.c:1645 */ { spec_name_prefix = (yyvsp[0].code); } -#line 2146 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2138 "src/parse-gram.c" /* yacc.c:1645 */ break; case 19: -#line 321 "src/parse-gram.y" /* yacc.c:1651 */ +#line 322 "src/parse-gram.y" /* yacc.c:1645 */ { no_lines_flag = true; } -#line 2152 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2144 "src/parse-gram.c" /* yacc.c:1645 */ break; case 20: -#line 322 "src/parse-gram.y" /* yacc.c:1651 */ +#line 323 "src/parse-gram.y" /* yacc.c:1645 */ { nondeterministic_parser = true; } -#line 2158 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2150 "src/parse-gram.c" /* yacc.c:1645 */ break; case 21: -#line 323 "src/parse-gram.y" /* yacc.c:1651 */ +#line 324 "src/parse-gram.y" /* yacc.c:1645 */ { spec_outfile = (yyvsp[0].code); } -#line 2164 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2156 "src/parse-gram.c" /* yacc.c:1645 */ break; case 22: -#line 324 "src/parse-gram.y" /* yacc.c:1651 */ +#line 325 "src/parse-gram.y" /* yacc.c:1645 */ { current_param = (yyvsp[0].param); } -#line 2170 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2162 "src/parse-gram.c" /* yacc.c:1645 */ break; case 23: -#line 324 "src/parse-gram.y" /* yacc.c:1651 */ +#line 325 "src/parse-gram.y" /* yacc.c:1645 */ { current_param = param_none; } -#line 2176 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2168 "src/parse-gram.c" /* yacc.c:1645 */ break; case 24: -#line 325 "src/parse-gram.y" /* yacc.c:1651 */ +#line 326 "src/parse-gram.y" /* yacc.c:1645 */ { version_check (&(yylsp[0]), (yyvsp[0].code)); } -#line 2182 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2174 "src/parse-gram.c" /* yacc.c:1645 */ break; case 25: -#line 327 "src/parse-gram.y" /* yacc.c:1651 */ +#line 328 "src/parse-gram.y" /* yacc.c:1645 */ { char const *skeleton_user = (yyvsp[0].code); if (strchr (skeleton_user, '/')) @@ -2206,49 +2198,49 @@ yyreduce: } skeleton_arg (skeleton_user, grammar_prio, (yylsp[-1])); } -#line 2210 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2202 "src/parse-gram.c" /* yacc.c:1645 */ break; case 26: -#line 350 "src/parse-gram.y" /* yacc.c:1651 */ +#line 351 "src/parse-gram.y" /* yacc.c:1645 */ { token_table_flag = true; } -#line 2216 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2208 "src/parse-gram.c" /* yacc.c:1645 */ break; case 27: -#line 351 "src/parse-gram.y" /* yacc.c:1651 */ +#line 352 "src/parse-gram.y" /* yacc.c:1645 */ { report_flag |= report_states; } -#line 2222 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2214 "src/parse-gram.c" /* yacc.c:1645 */ break; case 28: -#line 352 "src/parse-gram.y" /* yacc.c:1651 */ +#line 353 "src/parse-gram.y" /* yacc.c:1645 */ { yacc_flag = true; } -#line 2228 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2220 "src/parse-gram.c" /* yacc.c:1645 */ break; case 30: -#line 357 "src/parse-gram.y" /* yacc.c:1651 */ +#line 358 "src/parse-gram.y" /* yacc.c:1645 */ { add_param (current_param, (yyvsp[0].code), (yylsp[0])); } -#line 2234 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2226 "src/parse-gram.c" /* yacc.c:1645 */ break; case 31: -#line 358 "src/parse-gram.y" /* yacc.c:1651 */ +#line 359 "src/parse-gram.y" /* yacc.c:1645 */ { add_param (current_param, (yyvsp[0].code), (yylsp[0])); } -#line 2240 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2232 "src/parse-gram.c" /* yacc.c:1645 */ break; case 34: -#line 370 "src/parse-gram.y" /* yacc.c:1651 */ +#line 371 "src/parse-gram.y" /* yacc.c:1645 */ { grammar_start_symbol_set ((yyvsp[0].symbol), (yylsp[0])); } -#line 2248 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2240 "src/parse-gram.c" /* yacc.c:1645 */ break; case 35: -#line 374 "src/parse-gram.y" /* yacc.c:1651 */ +#line 375 "src/parse-gram.y" /* yacc.c:1645 */ { code_props code; code_props_symbol_action_init (&code, (yyvsp[-1].code), (yylsp[-1])); @@ -2259,27 +2251,27 @@ yyreduce: symbol_list_free ((yyvsp[0].list)); } } -#line 2263 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2255 "src/parse-gram.c" /* yacc.c:1645 */ break; case 36: -#line 385 "src/parse-gram.y" /* yacc.c:1651 */ +#line 386 "src/parse-gram.y" /* yacc.c:1645 */ { default_prec = true; } -#line 2271 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2263 "src/parse-gram.c" /* yacc.c:1645 */ break; case 37: -#line 389 "src/parse-gram.y" /* yacc.c:1651 */ +#line 390 "src/parse-gram.y" /* yacc.c:1645 */ { default_prec = false; } -#line 2279 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2271 "src/parse-gram.c" /* yacc.c:1645 */ break; case 38: -#line 393 "src/parse-gram.y" /* yacc.c:1651 */ +#line 394 "src/parse-gram.y" /* yacc.c:1645 */ { /* Do not invoke muscle_percent_code_grow here since it invokes muscle_user_name_list_grow. */ @@ -2287,97 +2279,97 @@ yyreduce: translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0])); code_scanner_last_string_free (); } -#line 2291 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2283 "src/parse-gram.c" /* yacc.c:1645 */ break; case 39: -#line 401 "src/parse-gram.y" /* yacc.c:1651 */ +#line 402 "src/parse-gram.y" /* yacc.c:1645 */ { muscle_percent_code_grow ((yyvsp[-1].uniqstr), (yylsp[-1]), translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0])); code_scanner_last_string_free (); } -#line 2300 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2292 "src/parse-gram.c" /* yacc.c:1645 */ break; case 40: -#line 411 "src/parse-gram.y" /* yacc.c:1651 */ +#line 412 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.code_type) = destructor; } -#line 2306 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2298 "src/parse-gram.c" /* yacc.c:1645 */ break; case 41: -#line 412 "src/parse-gram.y" /* yacc.c:1651 */ +#line 413 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.code_type) = printer; } -#line 2312 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2304 "src/parse-gram.c" /* yacc.c:1645 */ break; case 42: -#line 422 "src/parse-gram.y" /* yacc.c:1651 */ +#line 423 "src/parse-gram.y" /* yacc.c:1645 */ {} -#line 2318 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2310 "src/parse-gram.c" /* yacc.c:1645 */ break; case 43: -#line 423 "src/parse-gram.y" /* yacc.c:1651 */ +#line 424 "src/parse-gram.y" /* yacc.c:1645 */ { muscle_percent_define_insert ("api.value.union.name", (yylsp[0]), muscle_keyword, (yyvsp[0].uniqstr), MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE); } -#line 2326 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2318 "src/parse-gram.c" /* yacc.c:1645 */ break; case 44: -#line 430 "src/parse-gram.y" /* yacc.c:1651 */ +#line 431 "src/parse-gram.y" /* yacc.c:1645 */ { union_seen = true; muscle_code_grow ("union_members", translate_code_braceless ((yyvsp[0].code), (yylsp[0])), (yylsp[0])); code_scanner_last_string_free (); } -#line 2336 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2328 "src/parse-gram.c" /* yacc.c:1645 */ break; case 45: -#line 441 "src/parse-gram.y" /* yacc.c:1651 */ +#line 442 "src/parse-gram.y" /* yacc.c:1645 */ { current_class = nterm_sym; } -#line 2342 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2334 "src/parse-gram.c" /* yacc.c:1645 */ break; case 46: -#line 442 "src/parse-gram.y" /* yacc.c:1651 */ +#line 443 "src/parse-gram.y" /* yacc.c:1645 */ { current_class = unknown_sym; current_type = NULL; } -#line 2351 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2343 "src/parse-gram.c" /* yacc.c:1645 */ break; case 47: -#line 446 "src/parse-gram.y" /* yacc.c:1651 */ +#line 447 "src/parse-gram.y" /* yacc.c:1645 */ { current_class = token_sym; } -#line 2357 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2349 "src/parse-gram.c" /* yacc.c:1645 */ break; case 48: -#line 447 "src/parse-gram.y" /* yacc.c:1651 */ +#line 448 "src/parse-gram.y" /* yacc.c:1645 */ { current_class = unknown_sym; current_type = NULL; } -#line 2366 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2358 "src/parse-gram.c" /* yacc.c:1645 */ break; case 49: -#line 452 "src/parse-gram.y" /* yacc.c:1651 */ +#line 453 "src/parse-gram.y" /* yacc.c:1645 */ { tag_seen = true; for (symbol_list *list = (yyvsp[0].list); list; list = list->next) symbol_type_set (list->content.sym, (yyvsp[-1].uniqstr), (yylsp[-1])); symbol_list_free ((yyvsp[0].list)); } -#line 2377 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2369 "src/parse-gram.c" /* yacc.c:1645 */ break; case 50: -#line 462 "src/parse-gram.y" /* yacc.c:1651 */ +#line 463 "src/parse-gram.y" /* yacc.c:1645 */ { ++current_prec; for (symbol_list *list = (yyvsp[0].list); list; list = list->next) @@ -2388,341 +2380,341 @@ yyreduce: symbol_list_free ((yyvsp[0].list)); current_type = NULL; } -#line 2392 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2384 "src/parse-gram.c" /* yacc.c:1645 */ break; case 51: -#line 475 "src/parse-gram.y" /* yacc.c:1651 */ +#line 476 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.assoc) = left_assoc; } -#line 2398 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2390 "src/parse-gram.c" /* yacc.c:1645 */ break; case 52: -#line 476 "src/parse-gram.y" /* yacc.c:1651 */ +#line 477 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.assoc) = right_assoc; } -#line 2404 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2396 "src/parse-gram.c" /* yacc.c:1645 */ break; case 53: -#line 477 "src/parse-gram.y" /* yacc.c:1651 */ +#line 478 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.assoc) = non_assoc; } -#line 2410 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2402 "src/parse-gram.c" /* yacc.c:1645 */ break; case 54: -#line 478 "src/parse-gram.y" /* yacc.c:1651 */ +#line 479 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.assoc) = precedence_assoc; } -#line 2416 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2408 "src/parse-gram.c" /* yacc.c:1645 */ break; case 55: -#line 482 "src/parse-gram.y" /* yacc.c:1651 */ +#line 483 "src/parse-gram.y" /* yacc.c:1645 */ { current_type = NULL; } -#line 2422 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2414 "src/parse-gram.c" /* yacc.c:1645 */ break; case 56: -#line 483 "src/parse-gram.y" /* yacc.c:1651 */ +#line 484 "src/parse-gram.y" /* yacc.c:1645 */ { current_type = (yyvsp[0].uniqstr); tag_seen = true; } -#line 2428 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2420 "src/parse-gram.c" /* yacc.c:1645 */ break; case 57: -#line 489 "src/parse-gram.y" /* yacc.c:1651 */ +#line 490 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.list) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); } -#line 2434 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2426 "src/parse-gram.c" /* yacc.c:1645 */ break; case 58: -#line 491 "src/parse-gram.y" /* yacc.c:1651 */ +#line 492 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.list) = symbol_list_append ((yyvsp[-1].list), symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0]))); } -#line 2440 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2432 "src/parse-gram.c" /* yacc.c:1645 */ break; case 59: -#line 496 "src/parse-gram.y" /* yacc.c:1651 */ +#line 497 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.symbol) = (yyvsp[0].symbol); symbol_class_set ((yyvsp[0].symbol), token_sym, (yylsp[0]), false); } -#line 2449 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2441 "src/parse-gram.c" /* yacc.c:1645 */ break; case 60: -#line 501 "src/parse-gram.y" /* yacc.c:1651 */ +#line 502 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.symbol) = (yyvsp[-1].symbol); symbol_user_token_number_set ((yyvsp[-1].symbol), (yyvsp[0].integer), (yylsp[0])); symbol_class_set ((yyvsp[-1].symbol), token_sym, (yylsp[-1]), false); } -#line 2459 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2451 "src/parse-gram.c" /* yacc.c:1645 */ break; case 61: -#line 511 "src/parse-gram.y" /* yacc.c:1651 */ +#line 512 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.list) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); } -#line 2465 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2457 "src/parse-gram.c" /* yacc.c:1645 */ break; case 62: -#line 513 "src/parse-gram.y" /* yacc.c:1651 */ +#line 514 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.list) = symbol_list_append ((yyvsp[-1].list), symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0]))); } -#line 2471 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2463 "src/parse-gram.c" /* yacc.c:1645 */ break; case 63: -#line 517 "src/parse-gram.y" /* yacc.c:1651 */ +#line 518 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.list) = (yyvsp[0].list); } -#line 2477 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2469 "src/parse-gram.c" /* yacc.c:1645 */ break; case 64: -#line 518 "src/parse-gram.y" /* yacc.c:1651 */ +#line 519 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.list) = symbol_list_append ((yyvsp[-1].list), (yyvsp[0].list)); } -#line 2483 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2475 "src/parse-gram.c" /* yacc.c:1645 */ break; case 65: -#line 522 "src/parse-gram.y" /* yacc.c:1651 */ +#line 523 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.list) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); } -#line 2489 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2481 "src/parse-gram.c" /* yacc.c:1645 */ break; case 66: -#line 523 "src/parse-gram.y" /* yacc.c:1651 */ +#line 524 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.list) = symbol_list_type_new ((yyvsp[0].uniqstr), (yylsp[0])); } -#line 2495 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2487 "src/parse-gram.c" /* yacc.c:1645 */ break; case 68: -#line 528 "src/parse-gram.y" /* yacc.c:1651 */ +#line 529 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.uniqstr) = uniqstr_new ("*"); } -#line 2501 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2493 "src/parse-gram.c" /* yacc.c:1645 */ break; case 69: -#line 529 "src/parse-gram.y" /* yacc.c:1651 */ +#line 530 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.uniqstr) = uniqstr_new (""); } -#line 2507 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2499 "src/parse-gram.c" /* yacc.c:1645 */ break; case 70: -#line 535 "src/parse-gram.y" /* yacc.c:1651 */ +#line 536 "src/parse-gram.y" /* yacc.c:1645 */ { current_type = (yyvsp[0].uniqstr); tag_seen = true; } -#line 2516 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2508 "src/parse-gram.c" /* yacc.c:1645 */ break; case 71: -#line 540 "src/parse-gram.y" /* yacc.c:1651 */ +#line 541 "src/parse-gram.y" /* yacc.c:1645 */ { symbol_class_set ((yyvsp[0].symbol), current_class, (yylsp[0]), true); symbol_type_set ((yyvsp[0].symbol), current_type, (yylsp[0])); } -#line 2525 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2517 "src/parse-gram.c" /* yacc.c:1645 */ break; case 72: -#line 545 "src/parse-gram.y" /* yacc.c:1651 */ +#line 546 "src/parse-gram.y" /* yacc.c:1645 */ { symbol_class_set ((yyvsp[-1].symbol), current_class, (yylsp[-1]), true); symbol_type_set ((yyvsp[-1].symbol), current_type, (yylsp[-1])); symbol_user_token_number_set ((yyvsp[-1].symbol), (yyvsp[0].integer), (yylsp[0])); } -#line 2535 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2527 "src/parse-gram.c" /* yacc.c:1645 */ break; case 73: -#line 551 "src/parse-gram.y" /* yacc.c:1651 */ +#line 552 "src/parse-gram.y" /* yacc.c:1645 */ { symbol_class_set ((yyvsp[-1].symbol), current_class, (yylsp[-1]), true); symbol_type_set ((yyvsp[-1].symbol), current_type, (yylsp[-1])); symbol_make_alias ((yyvsp[-1].symbol), (yyvsp[0].symbol), (yyloc)); } -#line 2545 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2537 "src/parse-gram.c" /* yacc.c:1645 */ break; case 74: -#line 557 "src/parse-gram.y" /* yacc.c:1651 */ +#line 558 "src/parse-gram.y" /* yacc.c:1645 */ { symbol_class_set ((yyvsp[-2].symbol), current_class, (yylsp[-2]), true); symbol_type_set ((yyvsp[-2].symbol), current_type, (yylsp[-2])); symbol_user_token_number_set ((yyvsp[-2].symbol), (yyvsp[-1].integer), (yylsp[-1])); symbol_make_alias ((yyvsp[-2].symbol), (yyvsp[0].symbol), (yyloc)); } -#line 2556 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2548 "src/parse-gram.c" /* yacc.c:1645 */ break; case 81: -#line 587 "src/parse-gram.y" /* yacc.c:1651 */ +#line 588 "src/parse-gram.y" /* yacc.c:1645 */ { yyerrok; } -#line 2564 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2556 "src/parse-gram.c" /* yacc.c:1645 */ break; case 82: -#line 593 "src/parse-gram.y" /* yacc.c:1651 */ +#line 594 "src/parse-gram.y" /* yacc.c:1645 */ { current_lhs ((yyvsp[-1].symbol), (yylsp[-1]), (yyvsp[0].named_ref)); } -#line 2570 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2562 "src/parse-gram.c" /* yacc.c:1645 */ break; case 83: -#line 594 "src/parse-gram.y" /* yacc.c:1651 */ +#line 595 "src/parse-gram.y" /* yacc.c:1645 */ { /* Free the current lhs. */ current_lhs (0, (yylsp[-3]), 0); } -#line 2579 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2571 "src/parse-gram.c" /* yacc.c:1645 */ break; case 84: -#line 601 "src/parse-gram.y" /* yacc.c:1651 */ +#line 602 "src/parse-gram.y" /* yacc.c:1645 */ { grammar_current_rule_end ((yylsp[0])); } -#line 2585 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2577 "src/parse-gram.c" /* yacc.c:1645 */ break; case 85: -#line 602 "src/parse-gram.y" /* yacc.c:1651 */ +#line 603 "src/parse-gram.y" /* yacc.c:1645 */ { grammar_current_rule_end ((yylsp[0])); } -#line 2591 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2583 "src/parse-gram.c" /* yacc.c:1645 */ break; case 87: -#line 609 "src/parse-gram.y" /* yacc.c:1651 */ +#line 610 "src/parse-gram.y" /* yacc.c:1645 */ { grammar_current_rule_begin (current_lhs_symbol, current_lhs_location, current_lhs_named_ref); } -#line 2598 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2590 "src/parse-gram.c" /* yacc.c:1645 */ break; case 88: -#line 612 "src/parse-gram.y" /* yacc.c:1651 */ +#line 613 "src/parse-gram.y" /* yacc.c:1645 */ { grammar_current_rule_symbol_append ((yyvsp[-1].symbol), (yylsp[-1]), (yyvsp[0].named_ref)); } -#line 2604 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2596 "src/parse-gram.c" /* yacc.c:1645 */ break; case 89: -#line 614 "src/parse-gram.y" /* yacc.c:1651 */ +#line 615 "src/parse-gram.y" /* yacc.c:1645 */ { grammar_current_rule_action_append ((yyvsp[-1].code), (yylsp[-1]), (yyvsp[0].named_ref), current_type); } -#line 2610 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2602 "src/parse-gram.c" /* yacc.c:1645 */ break; case 90: -#line 616 "src/parse-gram.y" /* yacc.c:1651 */ +#line 617 "src/parse-gram.y" /* yacc.c:1645 */ { grammar_current_rule_predicate_append ((yyvsp[0].code), (yylsp[0])); } -#line 2616 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2608 "src/parse-gram.c" /* yacc.c:1645 */ break; case 91: -#line 618 "src/parse-gram.y" /* yacc.c:1651 */ +#line 619 "src/parse-gram.y" /* yacc.c:1645 */ { grammar_current_rule_empty_set ((yylsp[0])); } -#line 2622 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2614 "src/parse-gram.c" /* yacc.c:1645 */ break; case 92: -#line 620 "src/parse-gram.y" /* yacc.c:1651 */ +#line 621 "src/parse-gram.y" /* yacc.c:1645 */ { grammar_current_rule_prec_set ((yyvsp[0].symbol), (yylsp[0])); } -#line 2628 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2620 "src/parse-gram.c" /* yacc.c:1645 */ break; case 93: -#line 622 "src/parse-gram.y" /* yacc.c:1651 */ +#line 623 "src/parse-gram.y" /* yacc.c:1645 */ { grammar_current_rule_dprec_set ((yyvsp[0].integer), (yylsp[0])); } -#line 2634 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2626 "src/parse-gram.c" /* yacc.c:1645 */ break; case 94: -#line 624 "src/parse-gram.y" /* yacc.c:1651 */ +#line 625 "src/parse-gram.y" /* yacc.c:1645 */ { grammar_current_rule_merge_set ((yyvsp[0].uniqstr), (yylsp[0])); } -#line 2640 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2632 "src/parse-gram.c" /* yacc.c:1645 */ break; case 95: -#line 628 "src/parse-gram.y" /* yacc.c:1651 */ +#line 629 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.named_ref) = 0; } -#line 2646 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2638 "src/parse-gram.c" /* yacc.c:1645 */ break; case 96: -#line 629 "src/parse-gram.y" /* yacc.c:1651 */ +#line 630 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.named_ref) = named_ref_new ((yyvsp[0].uniqstr), (yylsp[0])); } -#line 2652 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2644 "src/parse-gram.c" /* yacc.c:1645 */ break; case 98: -#line 640 "src/parse-gram.y" /* yacc.c:1651 */ +#line 641 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.uniqstr) = uniqstr_new ((yyvsp[0].code)); } -#line 2658 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2650 "src/parse-gram.c" /* yacc.c:1645 */ break; case 99: -#line 665 "src/parse-gram.y" /* yacc.c:1651 */ +#line 666 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.value).kind = muscle_keyword; (yyval.value).chars = ""; } -#line 2664 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2656 "src/parse-gram.c" /* yacc.c:1645 */ break; case 100: -#line 666 "src/parse-gram.y" /* yacc.c:1651 */ +#line 667 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.value).kind = muscle_keyword; (yyval.value).chars = (yyvsp[0].uniqstr); } -#line 2670 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2662 "src/parse-gram.c" /* yacc.c:1645 */ break; case 101: -#line 667 "src/parse-gram.y" /* yacc.c:1651 */ +#line 668 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.value).kind = muscle_string; (yyval.value).chars = (yyvsp[0].code); } -#line 2676 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2668 "src/parse-gram.c" /* yacc.c:1645 */ break; case 102: -#line 668 "src/parse-gram.y" /* yacc.c:1651 */ +#line 669 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.value).kind = muscle_code; (yyval.value).chars = strip_braces ((yyvsp[0].code)); } -#line 2682 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2674 "src/parse-gram.c" /* yacc.c:1645 */ break; case 103: -#line 681 "src/parse-gram.y" /* yacc.c:1651 */ +#line 682 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[0].uniqstr), (yylsp[0])); } -#line 2688 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2680 "src/parse-gram.c" /* yacc.c:1645 */ break; case 104: -#line 683 "src/parse-gram.y" /* yacc.c:1651 */ +#line 684 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.symbol) = symbol_get (char_name ((yyvsp[0].character)), (yylsp[0])); symbol_class_set ((yyval.symbol), token_sym, (yylsp[0]), false); symbol_user_token_number_set ((yyval.symbol), (yyvsp[0].character), (yylsp[0])); } -#line 2698 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2690 "src/parse-gram.c" /* yacc.c:1645 */ break; case 105: -#line 691 "src/parse-gram.y" /* yacc.c:1651 */ +#line 692 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.symbol) = symbol_from_uniqstr ((yyvsp[0].uniqstr), (yylsp[0])); } -#line 2704 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2696 "src/parse-gram.c" /* yacc.c:1645 */ break; case 108: -#line 703 "src/parse-gram.y" /* yacc.c:1651 */ +#line 704 "src/parse-gram.y" /* yacc.c:1645 */ { (yyval.symbol) = symbol_get (quotearg_style (c_quoting_style, (yyvsp[0].code)), (yylsp[0])); symbol_class_set ((yyval.symbol), token_sym, (yylsp[0]), false); } -#line 2713 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2705 "src/parse-gram.c" /* yacc.c:1645 */ break; case 110: -#line 712 "src/parse-gram.y" /* yacc.c:1651 */ +#line 713 "src/parse-gram.y" /* yacc.c:1645 */ { muscle_code_grow ("epilogue", translate_code ((yyvsp[0].code), (yylsp[0]), true), (yylsp[0])); code_scanner_last_string_free (); } -#line 2722 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2714 "src/parse-gram.c" /* yacc.c:1645 */ break; -#line 2726 "src/parse-gram.c" /* yacc.c:1651 */ +#line 2718 "src/parse-gram.c" /* yacc.c:1645 */ default: break; } if (yychar_backup != yychar) @@ -2751,14 +2743,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; @@ -2968,7 +2959,7 @@ yyreturn: #endif return yyresult; } -#line 718 "src/parse-gram.y" /* yacc.c:1910 */ +#line 719 "src/parse-gram.y" /* yacc.c:1903 */ /* Return the location of the left-hand side of a rule whose @@ -3076,10 +3067,37 @@ add_param (param_type type, char *decl, location loc) static void version_check (location const *loc, char const *version) { - if (strverscmp (version, PACKAGE_VERSION) > 0) + /* Changes of behavior are only on minor version changes, so "3.0.5" + is the same as "3.0". */ + errno = 0; + char* cp = NULL; + unsigned long major = strtoul (version, &cp, 10); + if (errno || *cp != '.') + { + complain (loc, complaint, _("invalid version requirement: %s"), + version); + return; + } + ++cp; + unsigned long minor = strtoul (cp, NULL, 10); + if (errno) + { + complain (loc, complaint, _("invalid version requirement: %s"), + version); + return; + } + required_version = major * 100 + minor; + /* Pretend to be at least 3.2, even if we are only 3.1-211, as it + allows us to check features published in 3.2 while developping + 3.2. */ + const char* api_version = "3.2"; + const char* package_version = + strverscmp (api_version, PACKAGE_VERSION) > 0 + ? api_version : PACKAGE_VERSION; + if (strverscmp (version, package_version) > 0) { - complain (loc, complaint, "require bison %s, but have %s", - version, PACKAGE_VERSION); + complain (loc, complaint, _("require bison %s, but have %s"), + version, package_version); exit (EX_MISMATCH); } } diff --git a/contrib/tools/bison/src/parse-gram.h b/contrib/tools/bison/src/parse-gram.h index 8766525cf8..fe656f1d25 100644 --- a/contrib/tools/bison/src/parse-gram.h +++ b/contrib/tools/bison/src/parse-gram.h @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 3.0.5.75-d835. */ +/* A Bison parser, made by GNU Bison 3.1.91.31-00793. */ /* Bison interface for Yacc-like parsers in C @@ -30,6 +30,9 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ +/* Undocumented macros, especially those whose name start with YY_, + are private implementation details. Do not rely on them. */ + #ifndef YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED # define YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED /* Debug traces. */ @@ -48,11 +51,11 @@ extern int gram_debug; #endif /* "%code requires" blocks. */ -#line 21 "src/parse-gram.y" /* yacc.c:1913 */ +#line 21 "src/parse-gram.y" /* yacc.c:1906 */ #include "symlist.h" #include "symtab.h" -#line 221 "src/parse-gram.y" /* yacc.c:1913 */ +#line 222 "src/parse-gram.y" /* yacc.c:1906 */ typedef enum { @@ -61,10 +64,10 @@ extern int gram_debug; param_parse = 1 << 1, param_both = param_lex | param_parse } param_type; -#line 644 "src/parse-gram.y" /* yacc.c:1913 */ +#line 645 "src/parse-gram.y" /* yacc.c:1906 */ #include "muscle-tab.h" -#line 68 "src/parse-gram.h" /* yacc.c:1913 */ +#line 71 "src/parse-gram.h" /* yacc.c:1906 */ /* Token type. */ #ifndef GRAM_TOKENTYPE @@ -135,27 +138,27 @@ extern int gram_debug; union GRAM_STYPE { -#line 182 "src/parse-gram.y" /* yacc.c:1913 */ +#line 183 "src/parse-gram.y" /* yacc.c:1906 */ unsigned char character; -#line 186 "src/parse-gram.y" /* yacc.c:1913 */ +#line 187 "src/parse-gram.y" /* yacc.c:1906 */ char *code; -#line 191 "src/parse-gram.y" /* yacc.c:1913 */ +#line 192 "src/parse-gram.y" /* yacc.c:1906 */ uniqstr uniqstr; -#line 199 "src/parse-gram.y" /* yacc.c:1913 */ +#line 200 "src/parse-gram.y" /* yacc.c:1906 */ int integer; -#line 203 "src/parse-gram.y" /* yacc.c:1913 */ +#line 204 "src/parse-gram.y" /* yacc.c:1906 */ symbol *symbol; -#line 208 "src/parse-gram.y" /* yacc.c:1913 */ +#line 209 "src/parse-gram.y" /* yacc.c:1906 */ assoc assoc; -#line 211 "src/parse-gram.y" /* yacc.c:1913 */ +#line 212 "src/parse-gram.y" /* yacc.c:1906 */ symbol_list *list; -#line 214 "src/parse-gram.y" /* yacc.c:1913 */ +#line 215 "src/parse-gram.y" /* yacc.c:1906 */ named_ref *named_ref; -#line 241 "src/parse-gram.y" /* yacc.c:1913 */ +#line 242 "src/parse-gram.y" /* yacc.c:1906 */ param_type param; -#line 408 "src/parse-gram.y" /* yacc.c:1913 */ +#line 409 "src/parse-gram.y" /* yacc.c:1906 */ code_props_type code_type; -#line 646 "src/parse-gram.y" /* yacc.c:1913 */ +#line 647 "src/parse-gram.y" /* yacc.c:1906 */ struct { @@ -163,7 +166,7 @@ code_props_type code_type; muscle_kind kind; } value; -#line 167 "src/parse-gram.h" /* yacc.c:1913 */ +#line 170 "src/parse-gram.h" /* yacc.c:1906 */ }; typedef union GRAM_STYPE GRAM_STYPE; diff --git a/contrib/tools/bison/src/print.c b/contrib/tools/bison/src/print.c index 36ad9d34a8..dd751d5765 100644 --- a/contrib/tools/bison/src/print.c +++ b/contrib/tools/bison/src/print.c @@ -61,7 +61,6 @@ max_length (size_t *width, const char *str) static void print_core (FILE *out, state *s) { - size_t i; item_number *sitems = s->items; size_t snritems = s->nitems; sym_content *previous_lhs = NULL; @@ -79,18 +78,15 @@ print_core (FILE *out, state *s) fputc ('\n', out); - for (i = 0; i < snritems; i++) + for (size_t i = 0; i < snritems; i++) { - item_number *sp; - item_number *sp1; - rule_number r; - - sp1 = sp = ritem + sitems[i]; + item_number *sp1 = ritem + sitems[i]; + item_number *sp = sp1; while (*sp >= 0) sp++; - r = item_number_as_rule_number (*sp); + rule_number r = item_number_as_rule_number (*sp); rule_lhs_print (&rules[r], previous_lhs, out); previous_lhs = rules[r].lhs; @@ -124,10 +120,9 @@ print_transitions (state *s, FILE *out, bool display_transitions_p) { transitions *trans = s->transitions; size_t width = 0; - int i; /* Compute the width of the lookahead token column. */ - for (i = 0; i < trans->num; i++) + for (int i = 0; i < trans->num; i++) if (!TRANSITION_IS_DISABLED (trans, i) && TRANSITION_IS_SHIFT (trans, i) == display_transitions_p) { @@ -143,17 +138,16 @@ print_transitions (state *s, FILE *out, bool display_transitions_p) width += 2; /* Report lookahead tokens and shifts. */ - for (i = 0; i < trans->num; i++) + for (int i = 0; i < trans->num; i++) if (!TRANSITION_IS_DISABLED (trans, i) && TRANSITION_IS_SHIFT (trans, i) == display_transitions_p) { symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)]; const char *tag = sym->tag; state *s1 = trans->states[i]; - int j; fprintf (out, " %s", tag); - for (j = width - strlen (tag); j > 0; --j) + for (int j = width - strlen (tag); j > 0; --j) fputc (' ', out); if (display_transitions_p) fprintf (out, _("shift, and go to state %d\n"), s1->number); @@ -172,10 +166,9 @@ print_errs (FILE *out, state *s) { errs *errp = s->errs; size_t width = 0; - int i; /* Compute the width of the lookahead token column. */ - for (i = 0; i < errp->num; ++i) + for (int i = 0; i < errp->num; ++i) if (errp->symbols[i]) max_length (&width, errp->symbols[i]->tag); @@ -187,13 +180,12 @@ print_errs (FILE *out, state *s) width += 2; /* Report lookahead tokens and errors. */ - for (i = 0; i < errp->num; ++i) + for (int i = 0; i < errp->num; ++i) if (errp->symbols[i]) { const char *tag = errp->symbols[i]->tag; - int j; fprintf (out, " %s", tag); - for (j = width - strlen (tag); j > 0; --j) + for (int j = width - strlen (tag); j > 0; --j) fputc (' ', out); fputs (_("error (nonassociative)\n"), out); } @@ -211,9 +203,8 @@ print_reduction (FILE *out, size_t width, const char *lookahead_token, rule *r, bool enabled) { - int j; fprintf (out, " %s", lookahead_token); - for (j = width - strlen (lookahead_token); j > 0; --j) + for (int j = width - strlen (lookahead_token); j > 0; --j) fputc (' ', out); if (!enabled) fputc ('[', out); @@ -235,36 +226,37 @@ print_reduction (FILE *out, size_t width, static void print_reductions (FILE *out, state *s) { - transitions *trans = s->transitions; reductions *reds = s->reductions; - rule *default_reduction = NULL; - size_t width = 0; - int i, j; - bool default_reduction_only = true; - if (reds->num == 0) return; + rule *default_reduction = NULL; if (yydefact[s->number] != 0) default_reduction = &rules[yydefact[s->number] - 1]; + transitions *trans = s->transitions; + bitset_zero (no_reduce_set); - FOR_EACH_SHIFT (trans, i) - bitset_set (no_reduce_set, TRANSITION_SYMBOL (trans, i)); - for (i = 0; i < s->errs->num; ++i) + { + int i; + FOR_EACH_SHIFT (trans, i) + bitset_set (no_reduce_set, TRANSITION_SYMBOL (trans, i)); + } + for (int i = 0; i < s->errs->num; ++i) if (s->errs->symbols[i]) bitset_set (no_reduce_set, s->errs->symbols[i]->content->number); /* Compute the width of the lookahead token column. */ + size_t width = 0; if (default_reduction) width = strlen (_("$default")); if (reds->lookahead_tokens) - for (i = 0; i < ntokens; i++) + for (int i = 0; i < ntokens; i++) { bool count = bitset_test (no_reduce_set, i); - for (j = 0; j < reds->num; ++j) + for (int j = 0; j < reds->num; ++j) if (bitset_test (reds->lookahead_tokens[j], i)) { if (! count) @@ -274,9 +266,7 @@ print_reductions (FILE *out, state *s) count = true; } else - { - max_length (&width, symbols[i]->tag); - } + max_length (&width, symbols[i]->tag); } } @@ -287,16 +277,18 @@ print_reductions (FILE *out, state *s) fputc ('\n', out); width += 2; + bool default_reduction_only = true; + /* Report lookahead tokens (or $default) and reductions. */ if (reds->lookahead_tokens) - for (i = 0; i < ntokens; i++) + for (int i = 0; i < ntokens; i++) { bool defaulted = false; bool count = bitset_test (no_reduce_set, i); if (count) default_reduction_only = false; - for (j = 0; j < reds->num; ++j) + for (int j = 0; j < reds->num; ++j) if (bitset_test (reds->lookahead_tokens[j], i)) { if (! count) @@ -396,18 +388,14 @@ print_state (FILE *out, state *s) static void print_terminal_symbols (FILE *out) { - symbol_number i; - /* TERMINAL (type #) : rule #s terminal is on RHS */ fprintf (out, "%s\n\n", _("Terminals, with rules where they appear")); - for (i = 0; i < max_user_token_number + 1; i++) + for (symbol_number i = 0; i < max_user_token_number + 1; i++) if (token_translations[i] != undeftoken->content->number) { const char *tag = symbols[token_translations[i]]->tag; int column = strlen (tag); char buffer[90]; - rule_number r; - item_number *rhsp; buffer[0] = 0; fputs (tag, out); @@ -420,8 +408,8 @@ print_terminal_symbols (FILE *out) } sprintf (buffer, " (%d)", i); - for (r = 0; r < nrules; r++) - for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) + for (rule_number r = 0; r < nrules; r++) + for (item_number *rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) if (item_number_as_symbol_number (*rhsp) == token_translations[i]) { END_TEST (65); @@ -437,24 +425,18 @@ print_terminal_symbols (FILE *out) static void print_nonterminal_symbols (FILE *out) { - symbol_number i; - fprintf (out, "%s\n\n", _("Nonterminals, with rules where they appear")); - for (i = ntokens; i < nsyms; i++) + for (symbol_number i = ntokens; i < nsyms; i++) { const char *tag = symbols[i]->tag; int column = strlen (tag); int left_count = 0, right_count = 0; - rule_number r; - char buffer[90]; - buffer[0] = 0; - for (r = 0; r < nrules; r++) + for (rule_number r = 0; r < nrules; r++) { - item_number *rhsp; if (rules[r].lhs->number == i) left_count++; - for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) + for (item_number *rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) if (item_number_as_symbol_number (*rhsp) == i) { right_count++; @@ -466,6 +448,8 @@ print_nonterminal_symbols (FILE *out) if (symbols[i]->content->type_name) column += fprintf (out, " <%s>", symbols[i]->content->type_name); + char buffer[90]; + buffer[0] = 0; sprintf (buffer, " (%d)", i); END_TEST (0); @@ -474,7 +458,7 @@ print_nonterminal_symbols (FILE *out) END_TEST (65); sprintf (buffer + strlen (buffer), _(" on left:")); - for (r = 0; r < nrules; r++) + for (rule_number r = 0; r < nrules; r++) { if (rules[r].lhs->number == i) { @@ -490,7 +474,7 @@ print_nonterminal_symbols (FILE *out) sprintf (buffer + strlen (buffer), ","); END_TEST (65); sprintf (buffer + strlen (buffer), _(" on right:")); - for (r = 0; r < nrules; r++) + for (rule_number r = 0; r < nrules; r++) { item_number *rhsp; for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) @@ -528,12 +512,9 @@ print_results (void) if (report_flag & report_itemsets) new_closure (nritems); /* Storage for print_reductions. */ - no_reduce_set = bitset_create (ntokens, BITSET_FIXED); - { - state_number i; - for (i = 0; i < nstates; i++) - print_state (out, states[i]); - } + no_reduce_set = bitset_create (ntokens, BITSET_FIXED); + for (state_number i = 0; i < nstates; i++) + print_state (out, states[i]); bitset_free (no_reduce_set); if (report_flag & report_itemsets) free_closure (); diff --git a/contrib/tools/bison/src/print_graph.c b/contrib/tools/bison/src/print_graph.c index 15d6dd572e..aea418cc32 100644 --- a/contrib/tools/bison/src/print_graph.c +++ b/contrib/tools/bison/src/print_graph.c @@ -48,7 +48,6 @@ print_core (struct obstack *oout, state *s) { item_number const *sitems = s->items; sym_content *previous_lhs = NULL; - size_t i; size_t snritems = s->nitems; /* Output all the items of a state, not just its kernel. */ @@ -61,16 +60,15 @@ print_core (struct obstack *oout, state *s) obstack_printf (oout, _("State %d"), s->number); obstack_sgrow (oout, "\\n\\l"); - for (i = 0; i < snritems; i++) + for (size_t i = 0; i < snritems; ++i) { item_number const *sp1 = ritem + sitems[i]; item_number const *sp = sp1; - rule *r; while (0 <= *sp) sp++; - r = &rules[item_number_as_rule_number (*sp)]; + rule *r = &rules[item_number_as_rule_number (*sp)]; obstack_printf (oout, "%3d ", r->number); if (previous_lhs && UNIQSTR_EQ (previous_lhs->symbol->tag, @@ -130,16 +128,15 @@ static void print_actions (state const *s, FILE *fgraph) { transitions const *trans = s->transitions; - int i; if (!trans->num && !s->reductions) return; - for (i = 0; i < trans->num; i++) + for (int i = 0; i < trans->num; i++) if (!TRANSITION_IS_DISABLED (trans, i)) { - state *s1 = trans->states[i]; - symbol_number sym = s1->accessing_symbol; + const state *s1 = trans->states[i]; + const symbol_number sym = s1->accessing_symbol; /* Shifts are solid, gotos are dashed, and error is dotted. */ char const *style = @@ -183,13 +180,12 @@ print_state (state *s, FILE *fgraph) void print_graph (void) { - state_number i; FILE *fgraph = xfopen (spec_graph_file, "w"); start_graph (fgraph); /* Output nodes and edges. */ new_closure (nritems); - for (i = 0; i < nstates; i++) + for (int i = 0; i < nstates; i++) print_state (states[i], fgraph); free_closure (); diff --git a/contrib/tools/bison/src/reader.c b/contrib/tools/bison/src/reader.c index 664dea7101..d073d4ed57 100644 --- a/contrib/tools/bison/src/reader.c +++ b/contrib/tools/bison/src/reader.c @@ -253,8 +253,8 @@ grammar_current_rule_begin (symbol *lhs, location loc, /*----------------------------------------------------------------------. | A symbol should be used if either: | | 1. It has a destructor. | -| 2. The symbol is a mid-rule symbol (i.e., the generated LHS | -| replacing a mid-rule action) that was assigned to or used, as in | +| 2. The symbol is a midrule symbol (i.e., the generated LHS | +| replacing a midrule action) that was assigned to or used, as in | | "exp: { $$ = 1; } { $$ = $1; }". | `----------------------------------------------------------------------*/ @@ -275,13 +275,14 @@ symbol_should_be_used (symbol_list const *s, bool *midrule_warning) return false; } -/*----------------------------------------------------------------. -| Check that the rule R is properly defined. For instance, there | -| should be no type clash on the default action. | -`----------------------------------------------------------------*/ +/*-----------------------------------------------------------------. +| Check that the rule R is properly defined. For instance, there | +| should be no type clash on the default action. Possibly install | +| the default action. | +`-----------------------------------------------------------------*/ static void -grammar_rule_check (const symbol_list *r) +grammar_rule_check_and_complete (symbol_list *r) { /* Type check. @@ -303,6 +304,23 @@ grammar_rule_check (const symbol_list *r) complain (&r->location, Wother, _("type clash on default action: <%s> != <%s>"), lhs_type, rhs_type); + else + { + /* Install the default action only for C++. */ + const bool is_cxx = + STREQ (language->language, "c++") + || (skeleton && (STREQ (skeleton, "glr.cc") + || STREQ (skeleton, "lalr1.cc"))); + if (is_cxx) + { + code_props_rule_action_init (&r->action_props, "{ $$ = $1; }", + r->location, r, + /* name */ NULL, + /* type */ NULL, + /* is_predicate */ false); + code_props_translate_code (&r->action_props); + } + } } /* Warn if there is no default for $$ but we need one. */ else @@ -373,9 +391,9 @@ grammar_current_rule_end (location loc) /*-------------------------------------------------------------------. -| The previous action turns out to be a mid-rule action. Attach it | +| The previous action turns out to be a midrule action. Attach it | | to the current rule, i.e., create a dummy symbol, attach it this | -| mid-rule action, and append this dummy nonterminal to the current | +| midrule action, and append this dummy nonterminal to the current | | rule. | `-------------------------------------------------------------------*/ @@ -439,14 +457,14 @@ grammar_current_rule_prec_set (symbol *precsym, location loc) { /* POSIX says that any identifier is a nonterminal if it does not appear on the LHS of a grammar rule and is not defined by %token - or by one of the directives that assigns precedence to a token. We - ignore this here because the only kind of identifier that POSIX - allows to follow a %prec is a token and because assuming it's a - token now can produce more logical error messages. Nevertheless, - grammar_rule_check does obey what we believe is the real intent of - POSIX here: that an error be reported for any identifier that - appears after %prec but that is not defined separately as a - token. */ + or by one of the directives that assigns precedence to a token. + We ignore this here because the only kind of identifier that + POSIX allows to follow a %prec is a token and because assuming + it's a token now can produce more logical error messages. + Nevertheless, grammar_rule_check_and_complete does obey what we + believe is the real intent of POSIX here: that an error be + reported for any identifier that appears after %prec but that is + not defined separately as a token. */ symbol_class_set (precsym, token_sym, loc, false); if (current_rule->ruleprec) duplicate_directive ("%prec", @@ -512,7 +530,7 @@ grammar_current_rule_merge_set (uniqstr name, location loc) } /* Attach SYM to the current rule. If needed, move the previous - action as a mid-rule action. */ + action as a midrule action. */ void grammar_current_rule_symbol_append (symbol *sym, location loc, @@ -576,39 +594,40 @@ packgram (void) for (symbol_list *p = grammar; p; p = p->next) { - symbol *ruleprec = p->ruleprec; - record_merge_function_type (p->merger, p->content.sym->content->type_name, - p->merger_declaration_location); - rules[ruleno].user_number = ruleno; - rules[ruleno].number = ruleno; - rules[ruleno].lhs = p->content.sym->content; - rules[ruleno].rhs = ritem + itemno; - rules[ruleno].prec = NULL; - rules[ruleno].dprec = p->dprec; - rules[ruleno].merger = p->merger; - rules[ruleno].precsym = NULL; - rules[ruleno].location = p->location; - rules[ruleno].useful = true; - rules[ruleno].action = p->action_props.code; - rules[ruleno].action_location = p->action_props.location; - rules[ruleno].is_predicate = p->action_props.is_predicate; - + symbol_list *lhs = p; + record_merge_function_type (lhs->merger, lhs->content.sym->content->type_name, + lhs->merger_declaration_location); /* If the midrule's $$ is set or its $n is used, remove the '$' from the symbol name so that it's a user-defined symbol so that the default %destructor and %printer apply. */ - if (p->midrule_parent_rule - && (p->action_props.is_value_used - || (symbol_list_n_get (p->midrule_parent_rule, - p->midrule_parent_rhs_index) + if (lhs->midrule_parent_rule + && (lhs->action_props.is_value_used + || (symbol_list_n_get (lhs->midrule_parent_rule, + lhs->midrule_parent_rhs_index) ->action_props.is_value_used))) - p->content.sym->tag += 1; + lhs->content.sym->tag += 1; /* Don't check the generated rule 0. It has no action, so some rhs symbols may appear unused, but the parsing algorithm ensures that %destructor's are invoked appropriately. */ if (p != grammar) - grammar_rule_check (p); + grammar_rule_check_and_complete (p); + rules[ruleno].user_number = ruleno; + rules[ruleno].number = ruleno; + rules[ruleno].lhs = lhs->content.sym->content; + rules[ruleno].rhs = ritem + itemno; + rules[ruleno].prec = NULL; + rules[ruleno].dprec = lhs->dprec; + rules[ruleno].merger = lhs->merger; + rules[ruleno].precsym = NULL; + rules[ruleno].location = lhs->location; + rules[ruleno].useful = true; + rules[ruleno].action = lhs->action_props.code; + rules[ruleno].action_location = lhs->action_props.location; + rules[ruleno].is_predicate = lhs->action_props.is_predicate; + + /* Traverse the rhs. */ { size_t rule_length = 0; for (p = p->next; p->content.sym; p = p->next) @@ -633,11 +652,12 @@ packgram (void) /* If this rule has a %prec, the specified symbol's precedence replaces the default. */ - if (ruleprec) + if (lhs->ruleprec) { - rules[ruleno].precsym = ruleprec->content; - rules[ruleno].prec = ruleprec->content; + rules[ruleno].precsym = lhs->ruleprec->content; + rules[ruleno].prec = lhs->ruleprec->content; } + /* An item ends by the rule number (negated). */ ritem[itemno++] = rule_number_as_item_number (ruleno); aver (itemno < ITEM_NUMBER_MAX); @@ -797,12 +817,13 @@ check_and_convert_grammar (void) symbols_pack above) so that token types are set correctly before the rule action type checking. - Before invoking grammar_rule_check (in packgram below) on any rule, make - sure all actions have already been scanned in order to set 'used' flags. - Otherwise, checking that a midrule's $$ should be set will not always work - properly because the check must forward-reference the midrule's parent - rule. For the same reason, all the 'used' flags must be set before - checking whether to remove '$' from any midrule symbol name (also in + Before invoking grammar_rule_check_and_complete (in packgram + below) on any rule, make sure all actions have already been + scanned in order to set 'used' flags. Otherwise, checking that a + midrule's $$ should be set will not always work properly because + the check must forward-reference the midrule's parent rule. For + the same reason, all the 'used' flags must be set before checking + whether to remove '$' from any midrule symbol name (also in packgram). */ for (symbol_list *sym = grammar; sym; sym = sym->next) code_props_translate_code (&sym->action_props); diff --git a/contrib/tools/bison/src/reduce.c b/contrib/tools/bison/src/reduce.c index c5013a9e05..ee5118eae5 100644 --- a/contrib/tools/bison/src/reduce.c +++ b/contrib/tools/bison/src/reduce.c @@ -52,9 +52,7 @@ static bitset V; 'useless', but no warning should be issued). */ static bitset V1; -static unsigned nuseful_productions; unsigned nuseless_productions; -static unsigned nuseful_nonterminals; unsigned nuseless_nonterminals; #define bitset_swap(Lhs, Rhs) \ @@ -73,12 +71,10 @@ unsigned nuseless_nonterminals; static bool useful_production (rule_number r, bitset N0) { - item_number *rhsp; - /* A production is useful if all of the nonterminals in its appear in the set of useful nonterminals. */ - for (rhsp = rules[r].rhs; 0 <= *rhsp; ++rhsp) + for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; ++rhsp) if (ISVAR (*rhsp) && !bitset_test (N0, *rhsp - ntokens)) return false; return true; @@ -115,9 +111,8 @@ useless_nonterminals (void) while (1) { - rule_number r; bitset_copy (Np, N); - for (r = 0; r < nrules; ++r) + for (rule_number r = 0; r < nrules; ++r) if (!bitset_test (P, r) && useful_production (r, N)) { @@ -169,15 +164,13 @@ inaccessable_symbols (void) while (1) { - rule_number r; bitset_copy (Vp, V); - for (r = 0; r < nrules; ++r) + for (rule_number r = 0; r < nrules; ++r) if (!bitset_test (Pp, r) && bitset_test (P, r) && bitset_test (V, rules[r].lhs->number)) { - item_number *rhsp; - for (rhsp = rules[r].rhs; 0 <= *rhsp; ++rhsp) + for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; ++rhsp) if (ISTOKEN (*rhsp) || bitset_test (N, *rhsp - ntokens)) bitset_set (Vp, *rhsp); bitset_set (Pp, r); @@ -200,24 +193,18 @@ inaccessable_symbols (void) bitset_free (P); P = Pp; - nuseful_productions = bitset_count (P); + unsigned nuseful_productions = bitset_count (P); nuseless_productions = nrules - nuseful_productions; - nuseful_nonterminals = 0; - { - symbol_number i; - for (i = ntokens; i < nsyms; ++i) - nuseful_nonterminals += bitset_test (V, i); - } + unsigned nuseful_nonterminals = 0; + for (symbol_number i = ntokens; i < nsyms; ++i) + nuseful_nonterminals += bitset_test (V, i); nuseless_nonterminals = nvars - nuseful_nonterminals; /* A token that was used in %prec should not be warned about. */ - { - rule_number r; - for (r = 0; r < nrules; ++r) - if (rules[r].precsym != 0) - bitset_set (V1, rules[r].precsym->number); - } + for (rule_number r = 0; r < nrules; ++r) + if (rules[r].precsym != 0) + bitset_set (V1, rules[r].precsym->number); } @@ -231,8 +218,7 @@ reduce_grammar_tables (void) { /* Report and flag useless productions. */ { - rule_number r; - for (r = 0; r < nrules; ++r) + for (rule_number r = 0; r < nrules; ++r) rules[r].useful = bitset_test (P, r); grammar_rules_useless_report (_("rule useless in grammar")); } @@ -243,14 +229,13 @@ reduce_grammar_tables (void) int useful = 0; int useless = nrules - nuseless_productions; rule *rules_sorted = xnmalloc (nrules, sizeof *rules_sorted); - rule_number r; - for (r = 0; r < nrules; ++r) + for (rule_number r = 0; r < nrules; ++r) rules_sorted[rules[r].useful ? useful++ : useless++] = rules[r]; free (rules); rules = rules_sorted; /* Renumber the rules markers in RITEMS. */ - for (r = 0; r < nrules; ++r) + for (rule_number r = 0; r < nrules; ++r) { item_number *rhsp = rules[r].rhs; for (/* Nothing. */; 0 <= *rhsp; ++rhsp) @@ -262,14 +247,10 @@ reduce_grammar_tables (void) } /* Adjust NRITEMS. */ - { - rule_number r; - int length; - for (r = nrules; r < nrules + nuseless_productions; ++r) - { - length = rule_rhs_length (&rules[r]); - nritems -= length + 1; - } + for (rule_number r = nrules; r < nrules + nuseless_productions; ++r) + { + int length = rule_rhs_length (&rules[r]); + nritems -= length + 1; } } @@ -287,11 +268,10 @@ nonterminals_reduce (void) symbol_number *nontermmap = xnmalloc (nvars, sizeof *nontermmap); { symbol_number n = ntokens; - symbol_number i; - for (i = ntokens; i < nsyms; ++i) + for (symbol_number i = ntokens; i < nsyms; ++i) if (bitset_test (V, i)) nontermmap[i - ntokens] = n++; - for (i = ntokens; i < nsyms; ++i) + for (symbol_number i = ntokens; i < nsyms; ++i) if (!bitset_test (V, i)) { nontermmap[i - ntokens] = n++; @@ -306,26 +286,21 @@ nonterminals_reduce (void) /* Shuffle elements of tables indexed by symbol number. */ { symbol **symbols_sorted = xnmalloc (nvars, sizeof *symbols_sorted); - symbol_number i; - for (i = ntokens; i < nsyms; ++i) + for (symbol_number i = ntokens; i < nsyms; ++i) symbols[i]->content->number = nontermmap[i - ntokens]; - for (i = ntokens; i < nsyms; ++i) + for (symbol_number i = ntokens; i < nsyms; ++i) symbols_sorted[nontermmap[i - ntokens] - ntokens] = symbols[i]; - for (i = ntokens; i < nsyms; ++i) + for (symbol_number i = ntokens; i < nsyms; ++i) symbols[i] = symbols_sorted[i - ntokens]; free (symbols_sorted); } { - rule_number r; - for (r = 0; r < nrules; ++r) - { - item_number *rhsp; - for (rhsp = rules[r].rhs; 0 <= *rhsp; ++rhsp) - if (ISVAR (*rhsp)) - *rhsp = symbol_number_as_item_number (nontermmap[*rhsp - - ntokens]); - } + for (rule_number r = 0; r < nrules; ++r) + for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; ++rhsp) + if (ISVAR (*rhsp)) + *rhsp = symbol_number_as_item_number (nontermmap[*rhsp + - ntokens]); accept->content->number = nontermmap[accept->content->number - ntokens]; } @@ -345,17 +320,15 @@ reduce_output (FILE *out) { if (nuseless_nonterminals) { - int i; fprintf (out, "%s\n\n", _("Nonterminals useless in grammar")); - for (i = 0; i < nuseless_nonterminals; ++i) + for (int i = 0; i < nuseless_nonterminals; ++i) fprintf (out, " %s\n", symbols[nsyms + i]->tag); fputs ("\n\n", out); } { bool b = false; - int i; - for (i = 0; i < ntokens; ++i) + for (int i = 0; i < ntokens; ++i) if (reduce_token_unused_in_grammar (i)) { if (!b) diff --git a/contrib/tools/bison/src/scan-code.c b/contrib/tools/bison/src/scan-code.c index 14e7366d89..d8b9ad64f2 100644 --- a/contrib/tools/bison/src/scan-code.c +++ b/contrib/tools/bison/src/scan-code.c @@ -2595,10 +2595,7 @@ is_dot_or_dash (char ch) static inline bool contains_dot_or_dash (const char* p) { - for (; *p; ++p) - if (is_dot_or_dash (*p)) - return true; - return false; + return strpbrk(p, ".-"); } /* Defines a variant of a symbolic name resolution. */ @@ -2657,26 +2654,21 @@ variant_table_free (void) variant_table_size = variant_count = 0; } -static char * -find_prefix_end (const char *prefix, char *begin, char *end) +static char const * +find_prefix_end (char const *prefix, char const *cp, char const *end) { - char *ptr = begin; - - for (; *prefix && ptr != end; ++prefix, ++ptr) - if (*prefix != *ptr) - return 0; + for (; *prefix && cp != end; ++prefix, ++cp) + if (*prefix != *cp) + return NULL; - if (*prefix) - return 0; - - return ptr; + return *prefix ? NULL : cp; } static variant * variant_add (uniqstr id, location id_loc, unsigned symbol_index, - char *cp, char *cp_end, bool explicit_bracketing) + char const *cp, char const *cp_end, bool explicit_bracketing) { - char *prefix_end = find_prefix_end (id, cp, cp_end); + char const *prefix_end = find_prefix_end (id, cp, cp_end); if (prefix_end && (prefix_end == cp_end || (!explicit_bracketing && is_dot_or_dash (*prefix_end)))) @@ -2759,7 +2751,7 @@ show_sub_message (warnings warning, if (var->err & VARIANT_NOT_VISIBLE_FROM_MIDRULE) obstack_printf (&msg_buf, - _(", cannot be accessed from mid-rule action at $%d"), + _(", cannot be accessed from midrule action at $%d"), midrule_rhs_index); complain_indent (&id_loc, warning, &indent, "%s", @@ -2813,35 +2805,14 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, } } - char *cp_end; - bool explicit_bracketing; + bool const explicit_bracketing = *cp == '['; - if ('[' == *cp) - { - /* Ignore the brackets. */ - char *p; - for (p = ++cp; *p != ']'; ++p) - continue; - cp_end = p; - - explicit_bracketing = true; - } + if (explicit_bracketing) + ++cp; else - { - /* Take all characters of the name. */ - char* p; - for (p = cp; *p; ++p) - if (is_dot_or_dash (*p)) - { - ref_tail_fields = p; - break; - } - for (p = cp; *p; ++p) - continue; - cp_end = p; + ref_tail_fields = strpbrk (cp, ".-"); - explicit_bracketing = false; - } + char const *cp_end = strchr (cp, explicit_bracketing ? ']' : '\0'); /* Add all relevant variants. */ { @@ -2874,7 +2845,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, variant *var = &variant_table[i]; unsigned symbol_index = var->symbol_index; - /* Check visibility from mid-rule actions. */ + /* Check visibility from midrule actions. */ if (midrule_rhs_index != 0 && (symbol_index == 0 || midrule_rhs_index < symbol_index)) var->err |= VARIANT_NOT_VISIBLE_FROM_MIDRULE; @@ -3085,8 +3056,15 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc) obstack_quote (&obstack_for_string, type_name); obstack_sgrow (&obstack_for_string, ")["); if (0 < n) - symbol_list_n_get (effective_rule, n)->action_props.is_value_used = - true; + { + symbol_list *sym = symbol_list_n_get (effective_rule, n); + if (muscle_percent_define_ifdef ("api.value.automove") + && sym->action_props.is_value_used) + complain (&dollar_loc, Wother, + _("multiple occurrences of $%d with api.value.automove"), + n); + sym->action_props.is_value_used = true; + } break; } } @@ -3214,17 +3192,17 @@ code_props_translate_code (code_props *self) { switch (self->kind) { - case CODE_PROPS_NONE: - break; - case CODE_PROPS_PLAIN: - self->code = translate_action (self, INITIAL); - break; - case CODE_PROPS_SYMBOL_ACTION: - self->code = translate_action (self, SC_SYMBOL_ACTION); - break; - case CODE_PROPS_RULE_ACTION: - self->code = translate_action (self, SC_RULE_ACTION); - break; + case CODE_PROPS_NONE: + break; + case CODE_PROPS_PLAIN: + self->code = translate_action (self, INITIAL); + break; + case CODE_PROPS_SYMBOL_ACTION: + self->code = translate_action (self, SC_SYMBOL_ACTION); + break; + case CODE_PROPS_RULE_ACTION: + self->code = translate_action (self, SC_RULE_ACTION); + break; } } diff --git a/contrib/tools/bison/src/scan-code.h b/contrib/tools/bison/src/scan-code.h index fb8b4a272e..c3df29c0ce 100644 --- a/contrib/tools/bison/src/scan-code.h +++ b/contrib/tools/bison/src/scan-code.h @@ -85,7 +85,7 @@ typedef struct code_props { /** Named reference. */ named_ref *named_ref; - /** Type, for mid-rule actions. */ + /** Type, for midrule actions. */ uniqstr type; } code_props; diff --git a/contrib/tools/bison/src/scan-gram.c b/contrib/tools/bison/src/scan-gram.c index ff9094eeba..8fbead0af7 100644 --- a/contrib/tools/bison/src/scan-gram.c +++ b/contrib/tools/bison/src/scan-gram.c @@ -2769,7 +2769,7 @@ YY_RULE_SETUP #line 709 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; nesting--; YY_BREAK -/* Tokenize '<<%' correctly (as '<<' '%') rather than incorrrectly +/* Tokenize '<<%' correctly (as '<<' '%') rather than incorrectly (as '<' '<%'). */ case 124: /* rule 124 can match eol */ diff --git a/contrib/tools/bison/src/scan-skel.c b/contrib/tools/bison/src/scan-skel.c index e6caf1b977..ec42cd8e0d 100644 --- a/contrib/tools/bison/src/scan-skel.c +++ b/contrib/tools/bison/src/scan-skel.c @@ -1,6 +1,5 @@ -#line 1 "src/scan-skel.c" -#line 3 "src/scan-skel.c" +#line 2 "lex.skel_.c" #define YY_INT_ALIGNED short int @@ -821,9 +820,9 @@ int yy_flex_debug = 1; static const flex_int16_t yy_rule_linenum[25] = { 0, - 73, 74, 75, 76, 77, 78, 80, 81, 83, 84, - 85, 88, 89, 90, 103, 105, 106, 107, 108, 109, - 111, 130, 135, 136 + 74, 75, 76, 77, 78, 79, 81, 82, 84, 85, + 86, 89, 90, 91, 104, 106, 107, 108, 109, 110, + 112, 131, 136, 137 } ; /* The intent behind this definition is that it'll catch @@ -863,8 +862,9 @@ char *yytext; #define FLEX_PREFIX(Id) skel_ ## Id #include <src/flex-scanner.h> -#include <dirname.h> #include <error.h> +#include <dirname.h> +#include <path-join.h> #include <quotearg.h> #include <src/complain.h> @@ -883,9 +883,9 @@ static void at_output (int argc, char *argv[], char **name, int *lineno); static void fail_for_at_directive_too_many_args (char const *at_directive_name); static void fail_for_at_directive_too_few_args (char const *at_directive_name); static void fail_for_invalid_at (char const *at); -#line 886 "src/scan-skel.c" +#line 886 "lex.skel_.c" -#line 888 "src/scan-skel.c" +#line 888 "lex.skel_.c" #define INITIAL 0 #define SC_AT_DIRECTIVE_ARGS 1 @@ -1165,11 +1165,11 @@ YY_DECL { /* %% [7.0] user's declarations go here */ -#line 57 "src/scan-skel.l" +#line 58 "src/scan-skel.l" -#line 61 "src/scan-skel.l" +#line 62 "src/scan-skel.l" int out_lineno PACIFY_CC (= 0); char *out_name = NULL; @@ -1182,7 +1182,7 @@ YY_DECL at_directive at_ptr = NULL; -#line 1185 "src/scan-skel.c" +#line 1185 "lex.skel_.c" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -1260,79 +1260,79 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 73 "src/scan-skel.l" +#line 74 "src/scan-skel.l" continue; YY_BREAK case 2: YY_RULE_SETUP -#line 74 "src/scan-skel.l" +#line 75 "src/scan-skel.l" fputc ('@', yyout); YY_BREAK case 3: YY_RULE_SETUP -#line 75 "src/scan-skel.l" +#line 76 "src/scan-skel.l" fputc ('[', yyout); YY_BREAK case 4: YY_RULE_SETUP -#line 76 "src/scan-skel.l" +#line 77 "src/scan-skel.l" fputc (']', yyout); YY_BREAK case 5: YY_RULE_SETUP -#line 77 "src/scan-skel.l" +#line 78 "src/scan-skel.l" continue; /* Used by b4_cat in ../data/bison.m4. */ YY_BREAK case 6: /* rule 6 can match eol */ YY_RULE_SETUP -#line 78 "src/scan-skel.l" +#line 79 "src/scan-skel.l" continue; YY_BREAK case 7: YY_RULE_SETUP -#line 80 "src/scan-skel.l" +#line 81 "src/scan-skel.l" fprintf (yyout, "%d", out_lineno + 1); YY_BREAK case 8: YY_RULE_SETUP -#line 81 "src/scan-skel.l" +#line 82 "src/scan-skel.l" fputs (quotearg_style (c_quoting_style, out_name), yyout); YY_BREAK case 9: YY_RULE_SETUP -#line 83 "src/scan-skel.l" +#line 84 "src/scan-skel.l" at_init (&argc, argv, &at_ptr, &at_basename); YY_BREAK case 10: YY_RULE_SETUP -#line 84 "src/scan-skel.l" +#line 85 "src/scan-skel.l" at_init (&argc, argv, &at_ptr, &at_complain); YY_BREAK case 11: YY_RULE_SETUP -#line 85 "src/scan-skel.l" +#line 86 "src/scan-skel.l" at_init (&argc, argv, &at_ptr, &at_output); YY_BREAK /* This pattern must not match more than the previous @ patterns. */ case 12: YY_RULE_SETUP -#line 88 "src/scan-skel.l" +#line 89 "src/scan-skel.l" fail_for_invalid_at (yytext); YY_BREAK case 13: /* rule 13 can match eol */ YY_RULE_SETUP -#line 89 "src/scan-skel.l" +#line 90 "src/scan-skel.l" out_lineno++; ECHO; YY_BREAK case 14: YY_RULE_SETUP -#line 90 "src/scan-skel.l" +#line 91 "src/scan-skel.l" ECHO; YY_BREAK case YY_STATE_EOF(INITIAL): -#line 92 "src/scan-skel.l" +#line 93 "src/scan-skel.l" { if (out_name) { @@ -1347,38 +1347,38 @@ case YY_STATE_EOF(INITIAL): case 15: /* rule 15 can match eol */ YY_RULE_SETUP -#line 103 "src/scan-skel.l" +#line 104 "src/scan-skel.l" STRING_GROW; YY_BREAK case 16: YY_RULE_SETUP -#line 105 "src/scan-skel.l" +#line 106 "src/scan-skel.l" obstack_1grow (&obstack_for_string, '@'); YY_BREAK case 17: YY_RULE_SETUP -#line 106 "src/scan-skel.l" +#line 107 "src/scan-skel.l" obstack_1grow (&obstack_for_string, '['); YY_BREAK case 18: YY_RULE_SETUP -#line 107 "src/scan-skel.l" +#line 108 "src/scan-skel.l" obstack_1grow (&obstack_for_string, ']'); YY_BREAK case 19: YY_RULE_SETUP -#line 108 "src/scan-skel.l" +#line 109 "src/scan-skel.l" continue; /* For starting an argument that begins with whitespace. */ YY_BREAK case 20: /* rule 20 can match eol */ YY_RULE_SETUP -#line 109 "src/scan-skel.l" +#line 110 "src/scan-skel.l" continue; YY_BREAK case 21: YY_RULE_SETUP -#line 111 "src/scan-skel.l" +#line 112 "src/scan-skel.l" { if (argc >= ARGC_MAX) fail_for_at_directive_too_many_args (argv[0]); @@ -1400,7 +1400,7 @@ YY_RULE_SETUP YY_BREAK case 22: YY_RULE_SETUP -#line 130 "src/scan-skel.l" +#line 131 "src/scan-skel.l" fail_for_invalid_at (yytext); YY_BREAK @@ -1409,12 +1409,12 @@ fail_for_invalid_at (yytext); case 23: /* rule 23 can match eol */ YY_RULE_SETUP -#line 135 "src/scan-skel.l" +#line 136 "src/scan-skel.l" continue; YY_BREAK case 24: YY_RULE_SETUP -#line 136 "src/scan-skel.l" +#line 137 "src/scan-skel.l" yyless (0); BEGIN SC_AT_DIRECTIVE_ARGS; YY_BREAK @@ -1422,16 +1422,16 @@ yyless (0); BEGIN SC_AT_DIRECTIVE_ARGS; case YY_STATE_EOF(SC_AT_DIRECTIVE_ARGS): case YY_STATE_EOF(SC_AT_DIRECTIVE_SKIP_WS): -#line 141 "src/scan-skel.l" +#line 142 "src/scan-skel.l" complain (NULL, fatal, _("unclosed %s directive in skeleton"), argv[0]); YY_BREAK case 25: YY_RULE_SETUP -#line 144 "src/scan-skel.l" +#line 145 "src/scan-skel.l" YY_FATAL_ERROR( "flex scanner jammed" ); YY_BREAK -#line 1434 "src/scan-skel.c" +#line 1434 "lex.skel_.c" case YY_END_OF_BUFFER: { @@ -2536,7 +2536,7 @@ void yyfree (void * ptr ) /* %ok-for-header */ -#line 144 "src/scan-skel.l" +#line 145 "src/scan-skel.l" static void @@ -2634,14 +2634,14 @@ at_complain (int argc, char *argv[], char **out_namep, int *out_linenop) static void at_output (int argc, char *argv[], char **out_namep, int *out_linenop) { - if (2 < argc) + if (3 < argc) fail_for_at_directive_too_many_args (argv[0]); if (*out_namep) { free (*out_namep); xfclose (yyout); } - *out_namep = xstrdup (argv[1]); + *out_namep = xpath_join (argv[1], 2 < argc ? argv[2] : NULL); output_file_name_check (out_namep, true); /* If there were errors, do not generate the output. */ yyout = xfopen (complaint_status ? "/dev/null" : *out_namep, "wb"); diff --git a/contrib/tools/bison/src/state.h b/contrib/tools/bison/src/state.h index f8ef6d2a0d..9fb968f761 100644 --- a/contrib/tools/bison/src/state.h +++ b/contrib/tools/bison/src/state.h @@ -148,7 +148,7 @@ typedef struct /* Iterate over each transition over a token (shifts). */ -# define FOR_EACH_SHIFT(Transitions, Iter) \ +# define FOR_EACH_SHIFT(Transitions, Iter) \ for (Iter = 0; \ Iter < Transitions->num \ && (TRANSITION_IS_DISABLED (Transitions, Iter) \ diff --git a/contrib/tools/bison/src/symtab.h b/contrib/tools/bison/src/symtab.h index 63b5fba2b6..71ade8a7cf 100644 --- a/contrib/tools/bison/src/symtab.h +++ b/contrib/tools/bison/src/symtab.h @@ -68,7 +68,7 @@ typedef enum undeclared, /** Used by %destructor/%printer but not defined (warning). */ used, - /** Used in the gramar (rules) but not defined (error). */ + /** Used in the grammar (rules) but not defined (error). */ needed, /** Defined with %type or %token (good). */ declared, @@ -307,7 +307,7 @@ typedef struct { /** The key, name of the semantic type. */ uniqstr tag; - /** The location of its first occurence. */ + /** The location of its first occurrence. */ location location; /** Its status : "undeclared", "used" or "declared". diff --git a/contrib/tools/bison/src/system.h b/contrib/tools/bison/src/system.h index caca04421e..fa7a060d38 100644 --- a/contrib/tools/bison/src/system.h +++ b/contrib/tools/bison/src/system.h @@ -19,7 +19,7 @@ #ifndef BISON_SYSTEM_H # define BISON_SYSTEM_H -/* flex 2.5.31 gratutiously defines macros like INT8_MIN. But this +/* flex 2.5.31 gratuitously defines macros like INT8_MIN. But this runs afoul of pre-C99 compilers that have <inttypes.h> or <stdint.h>, which are included below if available. It also runs afoul of pre-C99 compilers that define these macros in <limits.h>. */ diff --git a/contrib/tools/bison/src/tables.c b/contrib/tools/bison/src/tables.c index 7da2788a66..3c35b6f10b 100644 --- a/contrib/tools/bison/src/tables.c +++ b/contrib/tools/bison/src/tables.c @@ -182,20 +182,18 @@ table_grow (int desired) static void conflict_row (state *s) { - int i, j; - reductions *reds = s->reductions; - if (!nondeterministic_parser) return; - for (j = 0; j < ntokens; j += 1) + const reductions *reds = s->reductions; + for (state_number j = 0; j < ntokens; j += 1) if (conflrow[j]) { conflrow[j] = conflict_list_cnt; /* Find all reductions for token J, and record all that do not match ACTROW[J]. */ - for (i = 0; i < reds->num; i += 1) + for (int i = 0; i < reds->num; i += 1) if (bitset_test (reds->lookahead_tokens[i], j) && (actrow[j] != rule_number_as_item_number (reds->rules[i]->number))) @@ -238,7 +236,6 @@ conflict_row (state *s) static rule * action_row (state *s) { - int i; rule *default_reduction = NULL; reductions *reds = s->reductions; transitions *trans = s->transitions; @@ -247,57 +244,60 @@ action_row (state *s) bool nodefault = false; bool conflicted = false; - for (i = 0; i < ntokens; i++) + for (state_number i = 0; i < ntokens; i++) actrow[i] = conflrow[i] = 0; if (reds->lookahead_tokens) - { - int j; - bitset_iterator biter; - /* loop over all the rules available here which require - lookahead (in reverse order to give precedence to the first - rule) */ - for (i = reds->num - 1; i >= 0; --i) - /* and find each token which the rule finds acceptable - to come next */ + /* loop over all the rules available here which require + lookahead (in reverse order to give precedence to the first + rule) */ + for (int i = reds->num - 1; i >= 0; --i) + /* and find each token which the rule finds acceptable + to come next */ + { + bitset_iterator biter; + int j; BITSET_FOR_EACH (biter, reds->lookahead_tokens[i], j, 0) - { - /* and record this rule as the rule to use if that - token follows. */ - if (actrow[j] != 0) - { - conflicted = true; - conflrow[j] = 1; - } - actrow[j] = rule_number_as_item_number (reds->rules[i]->number); - } - } + { + /* and record this rule as the rule to use if that + token follows. */ + if (actrow[j] != 0) + { + conflicted = true; + conflrow[j] = 1; + } + actrow[j] = rule_number_as_item_number (reds->rules[i]->number); + } + } /* Now see which tokens are allowed for shifts in this state. For them, record the shift as the thing to do. So shift is preferred to reduce. */ - FOR_EACH_SHIFT (trans, i) - { - symbol_number sym = TRANSITION_SYMBOL (trans, i); - state *shift_state = trans->states[i]; + { + int i; + FOR_EACH_SHIFT (trans, i) + { + symbol_number sym = TRANSITION_SYMBOL (trans, i); + state *shift_state = trans->states[i]; - if (actrow[sym] != 0) - { - conflicted = true; - conflrow[sym] = 1; - } - actrow[sym] = state_number_as_int (shift_state->number); + if (actrow[sym] != 0) + { + conflicted = true; + conflrow[sym] = 1; + } + actrow[sym] = state_number_as_int (shift_state->number); - /* Do not use any default reduction if there is a shift for - error */ - if (sym == errtoken->content->number) - nodefault = true; - } + /* Do not use any default reduction if there is a shift for + error */ + if (sym == errtoken->content->number) + nodefault = true; + } + } /* See which tokens are an explicit error in this state (due to %nonassoc). For them, record ACTION_NUMBER_MINIMUM as the action. */ - for (i = 0; i < errp->num; i++) + for (int i = 0; i < errp->num; i++) { symbol *sym = errp->symbols[i]; actrow[sym->content->number] = ACTION_NUMBER_MINIMUM; @@ -324,13 +324,11 @@ action_row (state *s) else { int max = 0; - for (i = 0; i < reds->num; i++) + for (int i = 0; i < reds->num; i++) { int count = 0; rule *r = reds->rules[i]; - symbol_number j; - - for (j = 0; j < ntokens; j++) + for (symbol_number j = 0; j < ntokens; j++) if (actrow[j] == rule_number_as_item_number (r->number)) count++; @@ -349,8 +347,7 @@ action_row (state *s) if (max > 0) { - int j; - for (j = 0; j < ntokens; j++) + for (symbol_number j = 0; j < ntokens; j++) if (actrow[j] == rule_number_as_item_number (default_reduction->number) && ! (nondeterministic_parser && conflrow[j])) @@ -363,7 +360,7 @@ action_row (state *s) So replace any action which says "error" with "use default". */ if (!default_reduction) - for (i = 0; i < ntokens; i++) + for (symbol_number i = 0; i < ntokens; i++) if (actrow[i] == ACTION_NUMBER_MINIMUM) actrow[i] = 0; @@ -381,11 +378,9 @@ action_row (state *s) static void save_row (state_number s) { - symbol_number i; - /* Number of non default actions in S. */ size_t count = 0; - for (i = 0; i < ntokens; i++) + for (symbol_number i = 0; i < ntokens; i++) if (actrow[i] != 0) count++; @@ -398,7 +393,7 @@ save_row (state_number s) nondeterministic_parser ? xnmalloc (count, sizeof *sp3) : NULL; /* Store non defaulted actions. */ - for (i = 0; i < ntokens; i++) + for (symbol_number i = 0; i < ntokens; i++) if (actrow[i] != 0) { *sp1++ = i; @@ -437,34 +432,27 @@ token_actions (void) /* Find the rules which are reduced. */ if (!nondeterministic_parser) + for (rule_number r = 0; r < nrules; ++r) + rules[r].useful = false; + + for (state_number i = 0; i < nstates; ++i) { - rule_number r; - for (r = 0; r < nrules; ++r) - rules[r].useful = false; + rule *default_reduction = action_row (states[i]); + yydefact[i] = default_reduction ? default_reduction->number + 1 : 0; + save_row (i); + + /* Now that the parser was computed, we can find which rules are + really reduced, and which are not because of SR or RR + conflicts. */ + if (!nondeterministic_parser) + { + for (symbol_number j = 0; j < ntokens; ++j) + if (actrow[j] < 0 && actrow[j] != ACTION_NUMBER_MINIMUM) + rules[item_number_as_rule_number (actrow[j])].useful = true; + if (yydefact[i]) + rules[yydefact[i] - 1].useful = true; + } } - - { - state_number i; - for (i = 0; i < nstates; ++i) - { - rule *default_reduction = action_row (states[i]); - yydefact[i] = default_reduction ? default_reduction->number + 1 : 0; - save_row (i); - - /* Now that the parser was computed, we can find which rules are - really reduced, and which are not because of SR or RR - conflicts. */ - if (!nondeterministic_parser) - { - symbol_number j; - for (j = 0; j < ntokens; ++j) - if (actrow[j] < 0 && actrow[j] != ACTION_NUMBER_MINIMUM) - rules[item_number_as_rule_number (actrow[j])].useful = true; - if (yydefact[i]) - rules[yydefact[i] - 1].useful = true; - } - } - } free (actrow); free (conflrow); } @@ -482,13 +470,12 @@ token_actions (void) static void save_column (symbol_number sym, state_number default_state) { - goto_number i; - goto_number begin = goto_map[sym - ntokens]; - goto_number end = goto_map[sym - ntokens + 1]; + const goto_number begin = goto_map[sym - ntokens]; + const goto_number end = goto_map[sym - ntokens + 1]; /* Number of non default GOTO. */ size_t count = 0; - for (i = begin; i < end; i++) + for (goto_number i = begin; i < end; i++) if (to_state[i] != default_state) count++; @@ -500,7 +487,7 @@ save_column (symbol_number sym, state_number default_state) base_number *sp2 = tos[symno] = xnmalloc (count, sizeof *sp2); /* Store the state numbers of the non defaulted gotos. */ - for (i = begin; i < end; i++) + for (goto_number i = begin; i < end; i++) if (to_state[i] != default_state) { *sp1++ = from_state[i]; @@ -521,23 +508,20 @@ save_column (symbol_number sym, state_number default_state) static state_number default_goto (symbol_number sym, size_t state_count[]) { - goto_number begin = goto_map[sym - ntokens]; - goto_number end = goto_map[sym - ntokens + 1]; + const goto_number begin = goto_map[sym - ntokens]; + const goto_number end = goto_map[sym - ntokens + 1]; state_number res = -1; if (begin != end) { - size_t max = 0; - goto_number i; - state_number s; - - for (s = 0; s < nstates; s++) + for (state_number s = 0; s < nstates; s++) state_count[s] = 0; - for (i = begin; i < end; i++) + for (goto_number i = begin; i < end; i++) state_count[to_state[i]]++; - for (s = 0; s < nstates; s++) + size_t max = 0; + for (state_number s = 0; s < nstates; s++) if (max < state_count[s]) { max = state_count[s]; @@ -560,13 +544,12 @@ default_goto (symbol_number sym, size_t state_count[]) static void goto_actions (void) { - symbol_number i; size_t *state_count = xnmalloc (nstates, sizeof *state_count); yydefgoto = xnmalloc (nvars, sizeof *yydefgoto); /* For a given nterm I, STATE_COUNT[S] is the number of times there is a GOTO to S on I. */ - for (i = ntokens; i < nsyms; ++i) + for (symbol_number i = ntokens; i < nsyms; ++i) { state_number default_state = default_goto (i, state_count); save_column (i, default_state); @@ -584,16 +567,13 @@ goto_actions (void) static void sort_actions (void) { - int i; - nentries = 0; - for (i = 0; i < nvectors; i++) + for (int i = 0; i < nvectors; i++) if (0 < tally[i]) { - int k; - size_t t = tally[i]; - int w = width[i]; + const size_t t = tally[i]; + const int w = width[i]; int j = nentries - 1; while (0 <= j && width[order[j]] < w) @@ -602,7 +582,7 @@ sort_actions (void) while (0 <= j && width[order[j]] == w && tally[order[j]] < t) j--; - for (k = nentries - 1; k > j; k--) + for (int k = nentries - 1; k > j; k--) order[k + 1] = order[k]; order[j + 1] = i; @@ -630,12 +610,9 @@ matching_state (vector_number vector) /* If VECTOR has GLR conflicts, return -1 */ if (conflict_tos[i] != NULL) - { - int j; - for (j = 0; j < t; j += 1) - if (conflict_tos[i][j] != 0) - return -1; - } + for (int j = 0; j < t; j += 1) + if (conflict_tos[i][j] != 0) + return -1; for (prev = vector - 1; 0 <= prev; prev--) { @@ -647,8 +624,7 @@ matching_state (vector_number vector) else { bool match = true; - int k; - for (k = 0; match && k < t; k++) + for (int k = 0; match && k < t; k++) if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k] || (conflict_tos[j] != NULL && conflict_tos[j][k] != 0)) @@ -665,7 +641,6 @@ matching_state (vector_number vector) static base_number pack_vector (vector_number vector) { - base_number res; vector_number i = order[vector]; size_t t = tally[i]; base_number *from = froms[i]; @@ -674,13 +649,12 @@ pack_vector (vector_number vector) aver (t != 0); - for (res = lowzero - from[0]; ; res++) + for (base_number res = lowzero - from[0]; ; res++) { bool ok = true; aver (res < table_size); { - int k; - for (k = 0; ok && k < t; k++) + for (int k = 0; ok && k < t; k++) { int loc = res + state_number_as_int (from[k]); if (table_size <= loc) @@ -691,7 +665,7 @@ pack_vector (vector_number vector) } if (ok) - for (k = 0; k < vector; k++) + for (int k = 0; k < vector; k++) if (pos[k] == res) ok = false; } @@ -699,8 +673,7 @@ pack_vector (vector_number vector) if (ok) { int loc PACIFY_CC (= -1); - int k; - for (k = 0; k < t; k++) + for (int k = 0; k < t; k++) { loc = res + state_number_as_int (from[k]); table[loc] = to[k]; @@ -734,15 +707,14 @@ static base_number table_ninf_remap (base_number tab[], int size, base_number ninf) { base_number res = 0; - int i; - for (i = 0; i < size; i++) + for (int i = 0; i < size; i++) if (tab[i] < res && tab[i] != ninf) res = tab[i]; --res; - for (i = 0; i < size; i++) + for (int i = 0; i < size; i++) if (tab[i] == ninf) tab[i] = res; @@ -752,8 +724,6 @@ table_ninf_remap (base_number tab[], int size, base_number ninf) static void pack_table (void) { - int i; - base = xnmalloc (nvectors, sizeof *base); pos = xnmalloc (nentries, sizeof *pos); table = xcalloc (table_size, sizeof *table); @@ -763,13 +733,13 @@ pack_table (void) lowzero = 0; high = 0; - for (i = 0; i < nvectors; i++) + for (int i = 0; i < nvectors; i++) base[i] = BASE_MINIMUM; - for (i = 0; i < table_size; i++) + for (int i = 0; i < table_size; i++) check[i] = -1; - for (i = 0; i < nentries; i++) + for (int i = 0; i < nentries; i++) { state_number s = matching_state (i); base_number place; @@ -802,13 +772,11 @@ pack_table (void) void tables_generate (void) { - int i; - /* This is a poor way to make sure the sizes are properly correlated. In particular the signedness is not taken into account. But it's not useless. */ - verify (sizeof nstates <= sizeof nvectors - && sizeof nvars <= sizeof nvectors); + verify (sizeof nstates <= sizeof nvectors); + verify (sizeof nvars <= sizeof nvectors); nvectors = state_number_as_int (nstates) + nvars; @@ -833,7 +801,7 @@ tables_generate (void) free (tally); free (width); - for (i = 0; i < nvectors; i++) + for (int i = 0; i < nvectors; i++) { free (froms[i]); free (tos[i]); diff --git a/contrib/tools/bison/src/uniqstr.c b/contrib/tools/bison/src/uniqstr.c index bfe1d17218..b4f6e9463d 100644 --- a/contrib/tools/bison/src/uniqstr.c +++ b/contrib/tools/bison/src/uniqstr.c @@ -56,19 +56,36 @@ uniqstr_new (char const *str) } uniqstr -uniqstr_vsprintf (char const *format, ...) +uniqstr_concat (int nargs, ...) { va_list args; - size_t length; - va_start (args, format); - length = vsnprintf (NULL, 0, format, args); + + va_start (args, nargs); + size_t reslen = 0; + for (int i = 0; i < nargs; i++) + reslen += strlen (va_arg (args, char const *)); va_end (args); - char res[length + 1]; - va_start (args, format); - vsprintf (res, format, args); + char *str = xmalloc (reslen + 1); + char *p = str; + + va_start (args, nargs); + for (int i = 0; i < nargs; i++) + { + char const *arg = va_arg (args, char const *); + size_t arglen = strlen (arg); + memcpy (p, arg, arglen); + p += arglen; + } va_end (args); - return uniqstr_new (res); + + *p = '\0'; + uniqstr res = hash_insert (uniqstrs_table, str); + if (!res) + xalloc_die (); + if (res != str) + free (str); + return res; } /*------------------------------. diff --git a/contrib/tools/bison/src/uniqstr.h b/contrib/tools/bison/src/uniqstr.h index fe04cb7948..5247242158 100644 --- a/contrib/tools/bison/src/uniqstr.h +++ b/contrib/tools/bison/src/uniqstr.h @@ -32,12 +32,6 @@ typedef char const *uniqstr; /* Return the uniqstr for STR. */ uniqstr uniqstr_new (char const *str); -/* Return a uniqstr built by vsprintf. In order to simply concatenate - strings, use UNIQSTR_CONCAT, which is a convenient wrapper around - this function. */ -uniqstr uniqstr_vsprintf (char const *format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2); - /* Two uniqstr values have the same value iff they are the same. */ # define UNIQSTR_EQ(Ustr1, Ustr2) (!!((Ustr1) == (Ustr2))) @@ -52,38 +46,12 @@ void uniqstr_assert (char const *str); | Concatenation. | `----------------*/ -/* Concatenate at most 20 strings and return a uniqstr. The goal of - this macro is to make the caller's code a little more succinct - without a trivial uniqstr_vsprintf format string to maintain - (for example, "%s%s%s") while still benefitting from gcc's type - checking. Unfortunately, because of the missing format string in the - macro invocation, the argument number reported by gcc for a bad - argument type is 1 too large. */ +/* Concatenate strings and return a uniqstr. The goal of + this macro is to make the caller's code a little more succinct. */ # define UNIQSTR_CONCAT(...) \ - uniqstr_vsprintf (UNIQSTR_GEN_FORMAT (__VA_ARGS__, \ - "%s", "%s", "%s", "%s", "%s", \ - "%s", "%s", "%s", "%s", "%s", \ - "%s", "%s", "%s", "%s", "%s", \ - "%s", "%s", "%s", "%s", "%s"), \ - __VA_ARGS__) - -# define UNIQSTR_GEN_FORMAT(F1, F2, F3, F4, F5, \ - F6, F7, F8, F9, F10, \ - F11, F12, F13, F14, F15, \ - F16, F17, F18, F19, F20, \ - ...) \ - UNIQSTR_GEN_FORMAT_ (__VA_ARGS__, \ - "", "", "", "", "", \ - "", "", "", "", "", \ - "", "", "", "", "", \ - "", "", "", "", "") - -# define UNIQSTR_GEN_FORMAT_(F1, F2, F3, F4, F5, \ - F6, F7, F8, F9, F10, \ - F11, F12, F13, F14, F15, \ - F16, F17, F18, F19, F20, ...) \ - F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 \ - F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 + uniqstr_concat (ARRAY_CARDINALITY (((char const *[]) {__VA_ARGS__})), \ + __VA_ARGS__) +uniqstr uniqstr_concat (int nargs, ...); /*--------------------. | Table of uniqstrs. | diff --git a/contrib/tools/bison/ya.make b/contrib/tools/bison/ya.make index b4d1e4c12b..8e78546b4c 100644 --- a/contrib/tools/bison/ya.make +++ b/contrib/tools/bison/ya.make @@ -10,9 +10,9 @@ LICENSE( LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -VERSION(3.1) +VERSION(3.2.4) -ORIGINAL_SOURCE(mirror://gnu/bison/bison-3.1.tar.gz) +ORIGINAL_SOURCE(mirror://gnu/bison/bison-3.2.4.tar.gz) PEERDIR( contrib/tools/bison/lib |