Commit Graph

5585 Commits

Author SHA1 Message Date
Akim Demaille
b610f43f25 examples: check the variant example
* examples/mfcalc/local.mk, examples/rpcalc/local.mk: Define the
programs in a more natural order, source, preproc, then linker.

* examples/test: Be ready to work on programs that are not in
a subdir.
* examples/variant.test: New.
* examples/local.mk: Use it.
* examples/variant.yy: Don't use 0 for nullptr.
Use a more natural output for a list of string.
2018-08-19 17:47:59 +02:00
Akim Demaille
f348522005 C++: fix portability issue with MSVC 2017
Visual Studio issues a C4146 warning on '-static_cast<unsigned>(rhs)'.
The code is weird, probably to cope with INT_MIN.  Let's go back to
using std::max (whose header is still included in position.hh...) like
originally, but with the needed casts.

Reported by 長田偉伸, and with help from Rici Lake.

See also
http://lists.gnu.org/archive/html/bug-bison/2013-02/msg00000.html
and commit 75ae829984.

* data/location.cc (position::add_): Take min as an int.
Use std::max.
While here, get rid of a couple of useless inlines.
2018-08-18 18:07:43 +02:00
Akim Demaille
e866c476fd build: fix concurrent build failure
Reported by Dengke Du and Robert Yang.
https://lists.gnu.org/archive/html/bison-patches/2017-07/msg00000.html

* src/local.mk (src/yacc): Make sure the directory exists.
2018-08-18 15:37:14 +02:00
Akim Demaille
72252aaa97 lalr1.cc: remove debug comment
* data/lalr1.cc: Remove a comment about indentation.
I'm not sure it would be nice to indent even more, it's already quite
of the right.
2018-08-18 14:46:17 +02:00
Akim Demaille
a1513c265b doc: fix the name of the GFDL section
Reported by dine <2500418497@qq.com>.
http://lists.gnu.org/archive/html/bug-bison/2016-10/msg00000.html

I mirrored what the Coreutils do.

* doc/bison.texi (Copying This Manual): Rename as...
(GNU Free Documentation License): this, since that the name we
used in the preamble.
2018-08-18 14:33:06 +02:00
Akim Demaille
425044a936 doc: clarify the destructor selection example
Reported by Gary L Peskin.
http://lists.gnu.org/archive/html/help-bison/2016-02/msg00000.html

* doc/bison.texi (Destructor Decl): here.
2018-08-18 14:15:21 +02:00
Akim Demaille
5010af94d0 portability: don't use _Pragma with ICC
ICC defines __GNUC__ [1], but does not support GCC's _Pragma for
diagnostics.  As a matter of fact, I believe it does not support
_Pragma at all (only #pragma) [2].

Reported by Maxim Prohorenko.
https://savannah.gnu.org/support/index.php?108339

[1] https://software.intel.com/en-us/cpp-compiler-18.0-developer-guide-and-reference-gcc-compatibility-and-interoperability
[2] https://software.intel.com/en-us/cpp-compiler-18.0-developer-guide-and-reference-pragmas

* data/c.m4 (YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN): Exclude ICC from
the club.
2018-08-18 14:15:13 +02:00
Akim Demaille
005ea24cbb doc: typed mid-rule actions
* doc/bison.texi (Mid-Rule Actions): Restructure to insert...
(Typed Mid-Rule Actions): this new section.
Move the manual translation of mid-rule actions into regular actions
to...
(Mid-Rule Action Translation): here.
2018-08-18 10:42:35 +02:00
Akim Demaille
adf0425d11 escape properly the file names in #line for printer/destructor
Reported by Jannick.
http://lists.gnu.org/archive/html/bug-bison/2017-05/msg00001.html

"Amusingly" enough, we have the same problem with %defines when the
parser file name has backslashes or quotes: we generate #includes with
an incorrect C string.

* src/output.c (prepare_symbol_definitions): Escape properly the file
names before passing them to M4.
* data/bison.m4, data/lalr1.cc: Don't simply put the file name between
two quotes (that should have been strong enough a smell...), expect
the string to be properly quoted.
* tests/synclines.at: New tests to check this.
2018-08-18 10:04:50 +02:00
Akim Demaille
cb4e7ecefa tests: fix title and improve quoting
* tests/synclines.at: here.
Also, prefer '%code' to ;%{...%}' for yylex/yyerror prototypes.
2018-08-18 10:00:21 +02:00
Akim Demaille
2e9ad04cdb style: reduce scopes
* src/output.c: here.
2018-08-18 09:53:29 +02:00
Akim Demaille
28cde9c128 style: reduce scopes
* src/scan-code.l: here.
2018-08-18 09:53:29 +02:00
Akim Demaille
d288047e9b regen 2018-08-18 07:42:07 +02:00
Akim Demaille
d135a16792 style: reduce scopes
* src/parse-gram.y: Declare iterator within the for-loop.
2018-08-18 07:42:07 +02:00
Akim Demaille
75417c1c1c tests: style changes
* tests/c++.at, tests/local.at: Formatting and title changes.
2018-08-18 07:28:04 +02:00
Akim Demaille
8bc4348cc7 reader: simplify the search of the start symbol
Suggested by Paul Eggert.

* src/reader.c (find_start_symbol): Don't check 'res', we know it is
not null.  That suffices to avoid the GCC warnings.
* bootstrap.conf: We don't need 'assume', which doesn't exist anyway.
2018-08-17 06:22:47 +02:00
Akim Demaille
1113522acb c++: fix GCC8 warnings about uninitialized values
In 0931d14728 I removed too many
initializations from some ctors: some were not about base ctors, but
about member variables.  In fact, more of them were missing to please
GCC 8.

While at it, generate more natural code for C++ without variant:
instead of

    template <typename Base>
    parser::basic_symbol<Base>::basic_symbol (const basic_symbol& other)
      : Base (other)
      , value ()
    {
      value = other.value
    }

generate

    template <typename Base>
    parser::basic_symbol<Base>::basic_symbol (const basic_symbol& other)
      : Base (other)
      , value (other.value)
    {}

* data/c++.m4 (basic_symbol::basic_symbol): Always initialize 'value',
it might be a POD without a ctor.
* data/lalr1.cc (stack_symbol_type::stack_symbol_type): Likewise.
* data/variant.hh (variant::variant): Default initialize the buffer too.
2018-08-15 20:24:16 +02:00
Akim Demaille
45b9d97b54 tests: style: use %empty
* tests/conflicts.at: here.
2018-08-15 19:40:19 +02:00
Akim Demaille
b01b80836d tests: fix warnings in push mode
Fix warning with GCC 8, -DNDEBUG.

    422. push.at:83: testing Multiple impure instances ...
    input.y: In function 'main':
    input.c:1022:12: error: potential null pointer dereference [-Werror=null-dereference]
       if (!yyps->yynew && yyps->yyss != yyps->yyssa)
            ~~~~^~~~~~~

* data/yacc.c (pstate_delete): Do nothing if called on null pointer.
2018-08-15 19:40:15 +02:00
Akim Demaille
bd07c76b0a c++: avoid GCC 8 warnings
GCC 8 issues warnings whose root cause was a bit hard to find.

    calc.cc: In member function 'virtual int yy::parser::parse()':
    calc.cc:810:18: warning: '*((void*)&<anonymous> +8)' may be used uninitialized in this function [-Wmaybe-uninitialized]
         , location (l)
                      ^
    calc.cc: In member function 'void yy::parser::yypush_(const char*, yy::parser::stack_symbol_type&)':
    calc.cc:810:18: warning: '*((void*)&<anonymous> +8)' may be used uninitialized in this function [-Wmaybe-uninitialized]
         , location (l)
                      ^
    calc.cc: In member function 'void yy::parser::yypush_(const char*, yy::parser::state_type, yy::parser::symbol_type&)':
    calc.cc:810:18: warning: '*((void*)&<anonymous> +8)' may be used uninitialized in this function [-Wmaybe-uninitialized]
         , location (l)
                      ^

The problem is with locations that don't have a constructor, such as
Span (in calc.cc) which is POD.  It is POD on purpose: so that we can
use that structure to test glr.cc which cannot use non POD in its
(C) stacks.

* data/c++.m4 (basic_symbol): Also ensure that 'location' is
initialized.
2018-08-15 19:23:00 +02:00
Akim Demaille
45ca5043ce tests: avoid compiler warnings
* tests/calc.at (AT_CALC_MAIN): Declare yyparse and operator<< in an
unnamed namespace to avoid "not declared" warnings (clang
-Weverything).
Remove useless prototypes.
2018-08-15 19:21:17 +02:00
Akim Demaille
ef98967ada build: work around GCC warnings on Flex code
With GCC 7.3.0 and Flex 2.6.4, we get warnings on all the generated
scanners:

    examples/calc++/calc++-scanner.cc: In function 'void yyrestart(FILE*)':
    examples/calc++/calc++-scanner.cc:1611:20: error: potential null pointer dereference [-Werror=null-dereference]
     /* %endif */
      ~~~~~~~~~~~       ^
    examples/calc++/calc++-scanner.cc:1607:19: error: potential null pointer dereference [-Werror=null-dereference]
     /* %if-c-only */
      ~~~~~~~~~~~~~~~  ^
    examples/calc++/calc++-scanner.cc:1611:20: error: potential null pointer dereference [-Werror=null-dereference]
     /* %endif */
      ~~~~~~~~~~~       ^
    examples/calc++/calc++-scanner.cc:1607:19: error: potential null pointer dereference [-Werror=null-dereference]
     /* %if-c-only */
      ~~~~~~~~~~~~~~~  ^
    cc1plus: all warnings being treated as errors

Obviously the lines are incorrect, and the warnings are emitted twice.
Still, let's get rid of these warnings.

* doc/bison.texi, src/flex-scanner.h: Disable these warnings in code
generated by Flex.
2018-08-15 14:42:09 +02:00
Akim Demaille
7783ba2d4f fix incorrect C code
Commit 3df32101e7 introduced invalid C
code.  Caught by GCC 7.3.0.

* bootstrap.conf (gnulib_modules): We need assume.
* src/reader.c (find_start_symbol): Fix the signature (too much C++,
sorry...).
Prefer 'assume' to 'assert', so that we don't have these warnings even
when NDEBUG is defined.
2018-08-15 14:39:46 +02:00
Akim Demaille
bbd17b68fb examples: fix Englishoes
* examples/README: Fix my mistakes.
2018-08-14 13:40:54 +02:00
Akim Demaille
30c179fee8 examples: ship and install variant.yy
This file was meant to be shown as an example.  Install it.

* README, data/README: Put Emacs metadata in the final section.
* examples/README: New.
* examples/variant.yy: Use %empty.
* examples/local.mk: Install both these files.
2018-08-14 13:36:47 +02:00
Akim Demaille
7ab25ad020 C++: remove useless copy-constructor
We currently generate copy constructors such as the following
one (taken from examples/variant.yy):

    parser::stack_symbol_type::stack_symbol_type (const stack_symbol_type& that)
      : super_type (that.state, that.location)
    {
      switch (that.type_get ())
      {
        case 3: // TEXT
        case 8: // item
          value.copy< ::std::string > (that.value);
          break;

        case 7: // list
          value.copy< ::std::vector<std::string> > (that.value);
          break;

        case 4: // NUMBER
          value.copy< int > (that.value);
          break;

        default:
          break;
      }
    }

they are actually useless: we never need it.

* data/lalr1.cc: Don't generate the stack_symbol_type copy ctor.
2018-08-14 06:17:21 +02:00
Akim Demaille
e555fb5e55 C++: symbol constructors: add a missing reference
Fix a typo so that instead of

    basic_symbol::basic_symbol (typename Base::kind_type t, const int v)

we now generate

    basic_symbol::basic_symbol (typename Base::kind_type t, const int& v)

* data/variant.hh (b4_basic_symbol_constructor_declare)
(b4_basic_symbol_constructor_define): Add missing reference.
2018-08-14 06:17:21 +02:00
Akim Demaille
0931d14728 C++: remove useless calls to the base default constructor
* data/c++.m4, data/stack.hh, data/variant.hh: here.
2018-08-14 06:17:21 +02:00
Akim Demaille
e76245fcd9 C++: prefer size_type to unsigned for indexes
* data/stack.hh (size_type): New, based on the container type.
2018-08-14 06:17:21 +02:00
Akim Demaille
c2de9dafd1 regen 2018-08-14 06:15:42 +02:00
Akim Demaille
f7de571ff1 style: m4: remove useless reference to 'int' in integral types
* m4/cxx.m4: Prefer 'unsigned' to 'unsigned int'.
2018-08-14 06:15:42 +02:00
Akim Demaille
c226d4ed48 style: doc: remove useless reference to 'int' in integral types
* doc/bison.texi: Prefer 'unsigned' to 'unsigned int'.  Likewise for
long and short.
2018-08-14 06:15:41 +02:00
Akim Demaille
9df53e7288 style: lib: remove useless reference to 'int' in integral types
* lib/abitset.c, lib/bbitset.h, lib/bitset.c, lib/bitset.h,
* lib/bitset_stats.c, lib/bitsetv-print.c, lib/bitsetv.c,
* lib/bitsetv.h, lib/ebitset.c, lib/lbitset.c, lib/timevar.c,
* lib/vbitset.c:
Prefer 'unsigned' to 'unsigned int'.  Likewise for long and short.
2018-08-14 06:15:41 +02:00
Akim Demaille
9a5c688ae4 style: src: remove useless reference to 'int' in integral types
* src/AnnotationList.c, src/AnnotationList.h, src/InadequacyList.h,
* src/closure.c, src/closure.h, src/gram.c, src/gram.h, src/ielr.c,
* src/location.c, src/output.c, src/reader.c, src/relation.c,
* src/scan-code.l, src/scan-gram.l, src/tables.c, src/tables.h:
Prefer 'unsigned' to 'unsigned int'.  Likewise for long and short.
2018-08-14 06:15:41 +02:00
Akim Demaille
e3b7c01820 style: tests: remove useless reference to 'int' in integral types
* tests/actions.at, tests/cxx-type.at: Prefer 'unsigned' to 'unsigned
int'.  Likewise for long and short.
2018-08-14 06:15:41 +02:00
Akim Demaille
5cc5703239 style: data: remove useless reference to 'int' in integral types
* data/c.m4, data/glr.c, data/yacc.c: Prefer 'unsigned' to 'unsigned
int'.  Likewise for long and short.
2018-08-14 06:15:41 +02:00
Akim Demaille
c8dc9a8f51 gnulib: update
* bootstrap.conf: gnulib_mk is defined again by bootstrap.
2018-08-12 11:23:38 +02:00
Akim Demaille
f9a6b34147 doc: avoid type aliases
* doc/bison.texi (C++ Location Values): Use 'unsigned' instead of
'uint'.
2018-08-12 09:40:32 +02:00
Akim Demaille
48828e779f doc: remove the "experimental" warning for some features
Several features were flagged 'experimental' and waiting for user
feedback to 'stabilize', but i. AFAIK, no user ever reported anything
about them, ii. they'be been here long enough to prove they don't do
harm.

* doc/bison.texi: No longer experimental: default %printer and
%destructor (typed: <*> and untyped: <>), %define api.value.type union
and variant, Java parsers, XML output, LR family (lr, ielr, lalr),
semantic predicates (%?).
2018-08-12 09:15:01 +02:00
Akim Demaille
4ad0ed3425 tests: check variants and typed mid-rule actions
See
http://lists.gnu.org/archive/html/bison-patches/2018-08/msg00013.html

* tests/c++.at (Variants and Typed Mid-rule Actions): New.
2018-08-12 09:04:04 +02:00
Akim Demaille
ad42f96053 tests: fix minor issues
* tests/actions.at: Fix some log messages.
Prefer #error to fprintf: it fixes the invalid use of yyoutput in
%destructor, and it is an even stronger check: that the code is not
even emitted.  The portability of #error is not really a problem here,
since the point is anyway to have the compilation fail.
2018-08-12 08:44:32 +02:00
Akim Demaille
4410084223 c++: variant: add more assertions
* data/variant.hh (variant::as): Check yytypeid_ before
checking *yytypeid_.
2018-08-11 18:27:10 +02:00
Akim Demaille
ccc759e81a doc: -fcaret is enabled by default
* doc/bison.texi (Mid-Rule Action Translation): So no need to pass it.
2018-08-11 18:27:09 +02:00
Akim Demaille
e19e088e66 style: reduce scopes
* src/closure.c, src/conflicts.c: here.
2018-08-11 18:27:09 +02:00
Akim Demaille
9c80fa286e NEWS: update 2018-08-11 18:09:29 +02:00
Akim Demaille
da8f4a2f5f rule actions cannot be typed
Make sure that we cannot apply a type to the (main) action of a rule.

* src/reader.c (grammar_rule_check): Issue the warning.
* tests/input.at (Cannot type action): Check the warning.
2018-08-11 18:09:29 +02:00
Akim Demaille
f18f71cfb0 warn about typed mid-rule actions in Yacc mode
* src/reader.c (grammar_current_rule_action_append): Warn.
* tests/input.at (AT_CHECK_UNUSED_VALUES): Check.
2018-08-11 18:09:29 +02:00
Akim Demaille
11548b8e68 tests: check typed mid-rule actions
* tests/input.at (_AT_UNUSED_VALUES_DECLARATIONS): Check
typed mid-rule actions.
* tests/report.at (Reports): Check that types of typed mid-rule
actions are reported.
* tests/actions.at (Typed mid-rule actions): Check that
the values of typed mid-rule actions are correct.
2018-08-11 18:09:29 +02:00
Akim Demaille
b79b889de5 regen 2018-08-11 18:09:29 +02:00
Akim Demaille
7b24c424b5 add support for typed mid-rule actions
Prompted on Piotr Marcińczyk's message:
http://lists.gnu.org/archive/html/bug-bison/2017-06/msg00000.html.
See also http://lists.gnu.org/archive/html/bug-bison/2018-06/msg00001.html.

Because their type is unknown to Bison, the values of midrule actions are
not treated like the others: they don't have %printer and %destructor
support.  In addition, in C++, (Bison) variants cannot work properly.

Typed midrule actions address these issues.  Instead of:

    exp: { $<ival>$ = 1; } { $<ival>$ = 2; }   { $$ = $<ival>1 + $<ival>2; }

write:

    exp: <ival>{ $$ = 1; } <ival>{ $$ = 2; }   { $$ = $1 + $2; }

* src/scan-code.h, src/scan-code.l (code_props): Add a `type` field to
record the declared type of an action.
(code_props_rule_action_init): Add a type argument.
* src/parse-gram.y: Accept an optional type tag for actions.
* src/reader.h, src/reader.c (grammar_current_rule_action_append): Add
a type argument.
(grammar_midrule_action): When a mid-rule is typed, pass its type to
the defined dummy non terminal symbol.
2018-08-11 18:09:29 +02:00