Commit Graph

5397 Commits

Author SHA1 Message Date
Akim Demaille
74ce3cfbf6 regen 2013-02-01 14:26:29 +01:00
Akim Demaille
b805eca764 location: pass the location first
* src/location.h, src/location.c (location_print): For consistency
with other data structures and other location_* routines, pass the
location argument first.
* src/complain.c: Adjust.
(location_caret): Likewise.
* src/parse-gram.y: Adjust.
2013-02-01 14:24:48 +01:00
Akim Demaille
e6c25014bb symlist: use the right stream
* src/symlist.c (symbol_list_syms_print): Use "f", not stderr.
2013-02-01 14:23:49 +01:00
Akim Demaille
97ad789d10 tests: put two related tests together
* tests/conflicts.at (Useless associativity warning): Move next
to "Useless precedence warning".
2013-01-30 21:41:41 +01:00
Akim Demaille
d2f9ae18be news: name contributors
* NEWS: here.
2013-01-30 21:40:47 +01:00
Valentin Tolmer
cc2235ace2 warnings: introduce -Wprecedence
The new warning category "precedence" flags useless precedence and
associativity.  -Wprecedence can now be used, it is disabled by default.
The warnings about precedence and associativity are grouped into one, and
the testsuite was corrected accordingly.

* src/complain.h (warnings): Introduce "precedence".
* src/complain.c (warnings_print_categories): Adjust.
* src/getargs.c (warnings_args, warning_types): Likewise.
* src/symtab.h, src/symtab.c (print_associativity_warnings): Remove.
* src/symtab.h (register_assoc): Correct arguments.
* src/symtab.c (print_precedence_warnings): Print both warnings together.
* doc/bison.texi (Bison options): Document the warnings and provide an
example.
* tests/conflicts.at, tests/existing.at, tests/local.at,
* tests/regression.at: Adapt the testsuite for the new category
(-Wprecedence instead of -Wother where appropriate).
2013-01-30 21:39:08 +01:00
Akim Demaille
df1ca1b0de build: avoid clang's colored diagnostics in the test suite
The syncline tests, which try to recognize compiler diagnostics,
are confused by escapes for colors.

* configure.ac (warn_tests): New, to factor the warnings for both
C and C++ tests.
Add -fno-color-diagnostics to it.
* tests/local.at (AT_TEST_TABLES_AND_PARSE): Do not remove glue
together compiler flags.
2013-01-30 16:10:12 +01:00
Akim Demaille
1217688141 build: please Clang++ 3.2+ on Flex scanners
Clang++, with -Wall, rejects code generated by Flex (for C scanners):

  CXX      examples/calc++/examples_calc___calc__-calc++-scanner.o
  In file included from examples/calc++/calc++-scanner.cc:1:
  error: implicit conversion of NULL constant to 'bool' [-Werror,-Wnull-conversion]
  if ( ! ( (yy_buffer_stack) ? (yy_buffer_stack)[(yy_buffer_stack_top)] : __null) ) {
       ~                                                                  ^~~~~~
                                                                          false
* configure.ac (WARN_NO_NULL_CONVERSION_CXXFLAGS): Compute it.
* examples/calc++/local.mk (examples_calc___calc___CXXFLAGS): Use it.
2013-01-30 16:10:00 +01:00
Valentin Tolmer
e8f7155d98 grammar: record used associativity and print useless ones
Record which symbol associativity is used, and display useless ones.

* src/symtab.h, src/symtab.c (register_assoc, print_assoc_warnings): New
* src/symtab.c (init_assoc, is_assoc_used): New
* src/main.c: Use print_assoc_warnings
* src/conflicts.c: Use register_assoc
* tests/conflicts.at (Useless associativity warning): New.

Due to the new warning, many tests had to be updated.

* tests/conflicts.at tests/existing.at tests/regression.at:
Add the associativity warning in the expected results.
* tests/java.at: Fix the java calculator's grammar to remove a useless
associativity.
* doc/bison.texi (mfcalc example): Fix associativity to remove
warning.
2013-01-30 10:18:39 +01:00
Valentin Tolmer
284bc49c83 grammar: warn about unused precedence for symbols
Symbols with precedence but no associativity, and whose precedence is
never used, can be declared with %token instead.  The used precedence
relationships are recorded and a warning about useless ones is issued.

* src/conflicts.c (resolve_sr_conflict): Record precedence relation.
* src/symtab.c, src/symtab.h (prec_nodes, init_prec_nodes)
(symgraphlink_new, register_precedence_second_symbol)
(print_precedence_warnings): New.
Record relationships in a graph and warn about useless ones.
* src/main.c (main): Print precedence warnings.
* tests/conflicts.at: New.
2013-01-29 15:11:35 +01:00
Theophile Ranquet
fbecd2ab59 variants: remove the 'built' assertions
When using %define parse.assert, the variants come with additional variables
that are useful for development purposes. One is a Boolean indicating if the
variant is built (to make sure we don't read a non-built variant), and the
other is a string describing the stored type. There is no need to have both of
these, the string is enough.

* data/variant.hh (built): Remove.
2013-01-29 15:42:32 +01:00
Akim Demaille
c13928073c style: indentation fixes
* src/parse-gram.y: here.
2013-01-29 14:23:58 +01:00
Akim Demaille
2f0b97a271 maint: be sure to neutralize out-of-tree paths from our parser
* tests/bison.in: Adjust to support fixed versions of ylwrap.
2013-01-29 14:14:39 +01:00
Theophile Ranquet
ee9cf8c4a6 m4: generate a basic_symbol constructor for each symbol type
Recently, there was a slightly vicious bug hidden in the make_ functions:

  parser::symbol_type
  parser::make_TEXT (const ::std::string& v)
  {
    return symbol_type (token::TOK_TEXT, v);
  }

The constructor for symbol_type doesn't take an ::std::string& as
argument, but a constant variant.  However, because there is a variant
constructor which takes an ::std::string&, this caused the implicit
construction of a built variant.  Considering that the variant argument
for the symbol_type constructor was cv-qualified, this temporary variant
was never destroyed.

As a temporary solution, the symbol was built in two stages:

  symbol_type res (token::TOK_TEXT);
  res.value.build< ::std::string&> (v);
  return res;

However, the solution introduced in this patch contributes to letting
the symbols handle themselves, by supplying them with constructors that
take a non-variant value and build the symbol's own variant with that
value.

* data/variant.hh (b4_symbol_constructor_define_): Use the new
constructors rather than building in a temporary symbol.
(b4_basic_symbol_constructor_declare,
b4_basic_symbol_constructor_define): New macros generating the
constructors.
* data/c++.m4 (basic_symbol): Invoke the macros here.
2013-01-29 11:37:04 +01:00
Theophile Ranquet
858666c443 c++: minor stylistic changes
* data/c++m4: Remove useless comment lines.
* data/variant.hh (self_type): Use this typedef instead of variant<S>.
(b4_symbol_constructor_define_): Remove commented-out line, and stylistic
change (avoid blank line).
2013-01-29 11:32:38 +01:00
Akim Demaille
ddb9db151b c++: please G++ 4.8 with -O3: type puning issue
* tests/c++.at (Exception safety): Now that this test covers
variants, pass -fno-strict-aliasing to g++.
2013-01-29 09:04:08 +01:00
Akim Demaille
675d9fe489 c++: please G++ 4.8 with -O3: array bounds
* data/c++.m4, data/lalr1.cc (by_state, by_type): Do not use -1 to
denote the absence of value, as GCC then fears that this -1 might
be used to dereference arrays (such as yytname).
Use 0, which corresponds to $accept, which is valueless (the needed
property: the symbol destructor must not try to reclaim the memory
associated with the symbol).
2013-01-29 09:04:08 +01:00
Akim Demaille
26f95f5f35 c++: use more explicit types than int
* data/c++.m4 (b4_public_types_declare): Declare token_number_type soon.
Introduce symbol_number_type (wider than token_number_type).
Clarify the requirement that kind_type from by_state and by_type
denote the _input_ type (required by the constructor), not the stored type.
Use symbol_number_type and token_number_type where appropriate, instead
of int.
* data/lalr1.cc: Adjust to these changes.
Propagate "symbol_number_type".
Invoke "type_get ()" instead of read "type" directly.
2013-01-29 09:04:08 +01:00
Akim Demaille
7fc7df7a38 c++: value_type -> kind_type
* data/c++.m4, data/lalr1.cc (by_type, by_state): Rename 'value_type'
as 'kind_type', as it is clearer.
2013-01-29 09:04:08 +01:00
Akim Demaille
38cea49be1 c++: improve the signature of yysyntax_error_
* data/lalr1.cc: This function is const.
It takes a symbol_number_type.
2013-01-29 09:04:08 +01:00
Akim Demaille
23be254ef4 c++: style changes
* data/lalr1.cc: Formatting changes.
And name changes.
2013-01-29 09:01:18 +01:00
Akim Demaille
c32b9ec077 doxygen: upgrade Doxyfile, and complete it
* doc/Doxyfile.in: Let doxygen upgrade it.
(INCLUDE_PATH): Point to lib too.
(PROJECT_BRIEF): New.
(EXCLUDE): Update to reflect the current file hierarchy.
2013-01-28 18:37:04 +01:00
Akim Demaille
bb1c50d88b maint: fix syntax-check issues
* cfg.mk: Ignore strcmp in local.at.
* tests/conflicts.at: Use AT_PARSER_CHECK.
* tests/regression.at: Preserve the exit status of the generated parsers.

* tests/local.mk ($(TESTSUITE)): Map @tb@ to a tabulation.
* tests/c++.at, tests/input.at, tests/regression.at: Use @tb@.
* cfg.mk: (space-tab): There are no longer exceptions.
2013-01-28 17:46:13 +01:00
Akim Demaille
312c0cff71 tests: please C90 compilers
* tests/actions.at, tests/conflicts.at: Use /* ... */ comments.
Let "main" return a value.
2013-01-28 17:46:13 +01:00
Akim Demaille
15c14fdfb9 maint: update todo
* TODO: Remove fixed items.
2013-01-28 17:46:13 +01:00
Akim Demaille
8458a41144 news: minor improvements
* NEWS: Name some more contributors.
Restructure slightly.
2013-01-28 17:46:13 +01:00
Akim Demaille
5cf79ede61 tests: please clang and use ".cc", not ".c", for C++ input
When fed with foo.c, clang++ 3.2 answers:

  clang: error: treating 'c' input as 'c++' when in C++ mode,
                this behavior is deprecated

* tests/output.at (AT_CHECK_OUTPUT_FILE_NAME): Use *.cc and *.hh
for C++.
2013-01-28 17:46:13 +01:00
Akim Demaille
1b92213969 tests: formatting changes
* tests/local.at: Restore proper indentation.
2013-01-28 17:46:13 +01:00
Theophile Ranquet
b20e797a71 c++: better inline expansion
Many 'inline' keywords were in the declarations.  They rather belong in
definitions, so move them.

* data/c++.m4 (basic_symbol, by_type): Many inlines here.
* data/lalr1.cc (yytranslate_, yy_destroy_, by_state, yypush_, yypop_): Inline
these as well.
(move): Move the definition outside the struct, where it belongs.
2013-01-28 18:26:49 +01:00
Akim Demaille
dc8e535c37 tests: check that using variants is exception safe
* tests/local.at: (Slightly) improve the regexp by escaping '.'
when it denotes a point.
(AT_VARIANT_IF): New.
* tests/c++.at (Exception Safety): Run it for variants too.
2013-01-28 16:07:51 +01:00
Akim Demaille
66fb016e1d tests: remove useless %defines
Many tests were using %defines because C++ skeletons used to require
it.

* tests/actions.at, tests/c++.at, tests/input.at, tests/regression.at:
Remove useless %defines.
2013-01-28 15:37:49 +01:00
Akim Demaille
7d1aa2d636 c++: remove now-useless operators
Now that symbols behaves properly, we can eliminate special routines
that are no longer needed.

* data/c++.m4, data/glr.cc, data/lalr1.cc, data/variant.hh:
Remove useless assignment operators and copy constructors.
As a consequence, remove useless includes for "abort".
2013-01-28 15:00:23 +01:00
Akim Demaille
26a4d3c895 tests: enable support for --debug
* tests/c++.at (Variants): Here.
And remove useless clutter when api.token.constructor is enabled.
2013-01-28 15:00:23 +01:00
Akim Demaille
97ae878ec3 c++: revamp the support for variants
The current approach was too adhoc: the symbols were not sufficiently
self-contained, in particular wrt memory management.  The "new"
guideline is the one that should have been followed from the start:
let the symbols handle themslves, instead of leaving their users to
it.  It was justified by the will to avoid gratuitious moves and
copies, but the current approach does not seem to be slower, yet it
will probably be simpler to adjust to support move semantics from
C++11.

The documentation says that the %parse-param are available from the
%destructor.  In retrospect, that was a silly design decision, which
we can break for variants, as its a new feature.  It should be phased
out for non-variants too.

* data/variant.hh: A variant never knows if it stores something or
not, it is up to its users to store this information.
Yet, in parse.assert mode, make sure the empty/filled variants
are properly used.
(b4_symbol_constructor_define_): Don't call directly the symbol
constructor, to save a useless temporary.
* data/stack.hh (push): Steal the pushed value instead of duplicating
it.
This will simplify the callers of push, who handled this "move"
approach themselves.
* data/c++.m4 (basic_symbol): Let -1, as kind, denote the fact that
a symbol is empty.
This is needed for instance when shifting the lookahead: yyla
is given as argument to "push", and its value is then moved on
the stack.  But then yyla must be declared "empty" so that its
destructor won't be called.
(basic_symbol::move): New.
Move the responsibility of calling the destructor from yy_destroy
to ~basic_symbol in the case of variants.
* data/lalr1.cc (stack_symbol_type): Now a derived class from its
previous value, so that we can add a constructor from a symbol_type.
(by_state): State -1 means empty.
(yypush_): Factor, by calling one overload from the other one, and
using the new semantics of stack::push.
No longer reclaim by hand the memory from rhs symbols, since now
that we store objects with proper destructors, they will be reclaimed
automatically.
Conversely, be sure to delete yylhs.
* tests/c++.at (C++ Variant-based Symbols): New "unit" test for
symbols.
2013-01-28 15:00:22 +01:00
Akim Demaille
5f87211cb4 c++: formatting and comment changes
* data/c++.m4, data/lalr1.cc, data/stack.hh, data/variant.hh:
Fix indentation.
Fix some comments.
2013-01-28 14:22:51 +01:00
Valentin Tolmer
9e62f1a657 tests: add token declaration order test
* tests/conflicts.at: New test.
2013-01-27 10:43:59 +01:00
Akim Demaille
c6a731eebb regen 2013-01-27 10:41:16 +01:00
Valentin Tolmer
93561c21e8 grammar: preserve token declaration order
In a declaration %token A B, the token A is declared before B, but in %left
A B (or with %precedence or %nonassoc or %right), the token B was declared
before A (tokens were declared in reverse order).

* src/symlist.h, src/symlist.c (symbol_list_append): New.
* src/parse-gram.y: Use it instead of symbol_list_prepend.
* tests/input.at: Adjust expectations.
2013-01-27 10:37:12 +01:00
Akim Demaille
9b3bb25885 tests: improve test group titles
* tests/local.at (AT_SETUP_STRIP): AT_SETUP does not behave properly
with new-lines in its argument.
Remove them.
Fix the handling of %define with quotes.
2013-01-25 16:48:36 +01:00
Akim Demaille
f0f95a50ee c: no longer require stdio.h when locations are enabled
Recent changes (in 2.7) introduced a dependency on both FILE and
fprintf, which are "available" only in %debug mode.  This was to
define yy_location_print_, which is used only in %debug mode by the
parser, but massively used by the test suite to output the locations
in yyerror.

Break this dependency: the test suite should define its own routines
to display the locations.  Eventually Bison will provide the user with
a means to display locations, but not yet.

* data/c.m4 (b4_yy_location_print_define): Use YYFPRINTF instead of
fprintf directly.
* data/yacc.c (b4_yy_location_print_define): Invoke it only in %debug
mode, so that stdio.h is included (needed for FILE*), and YYFPRINTF
is defined.

* tests/local.at (AT_YYERROR_DECLARE, AT_YYERROR_DEFINE): Declare
and define location_print and LOCATION_PRINT.

* tests/actions.at, tests/existing.at, tests/glr-regression.at,
* tests/input.at, tests/named-refs.at, tests/regression.at: Adjust
to use them.
Fix the expected line numbers (as the prologue's length has changed).
2013-01-25 16:45:17 +01:00
Akim Demaille
d9fa1b7c4f c: minor simplification in the debug code
* data/c.m4 (yy_symbol_print): Minor factoring.
2013-01-25 16:35:52 +01:00
Akim Demaille
aedcb6c095 c++: display locations as C does
See commit 3804aa260b.

* data/location.cc (operator<<): Display location exactly as is
done in C skeletons.
* tests/local.at (AT_LOC_PUSHDEF, AT_LOC_POPDEF): Also define
AT_FIRST_LINE, AT_LAST_LINE, AT_FIRST_COLUMN, AT_LAST_COLUMN.
* tests/actions.at (Location Print): Also check C++ skeletons.
2013-01-25 16:35:52 +01:00
Akim Demaille
c7442984e3 tests: highlight empty right-hand sides
* tests/actions.at, tests/c++.at, tests/headers.at,
* tests/input.at: here.
2013-01-25 16:35:52 +01:00
Akim Demaille
597afd73d7 news: prepare for 2.8
* NEWS: Restructure.
Name contributors.
2013-01-25 16:35:35 +01:00
Akim Demaille
56b91ae0b1 tests: generalize default main for api.namespace
* tests/local.at (AT_NAME_PREFIX): Also match api.namespace.
(AT_MAIN_DEFINE): Take it into account.
* tests/c++.at, tests/headers.at: Use AT_NAME_PREFIX.
(AT_CHECK_NAMESPACE): Rename as...
(AT_TEST): this.
2013-01-21 16:27:46 +01:00
Akim Demaille
f42c012fcf tests: improve factoring of the main function
* tests/local.at (AT_MAIN_DEFINE): If %debug is used, check if
-d/--debug is passed to the generated parser, and enable the traces.
Return exactly the result of yyparse, so that we can check exit code
2 too.
* tests/actions.at, tests/glr-regression.at, tests/regression.at:
Use AT_MAIN_DEFINE, helping AT_BISON_OPTION_PUSHDEFS where needed,
preferably to option -t.
2013-01-21 16:27:46 +01:00
Akim Demaille
3ef9fa8f83 tests: factor the definition of main
With Théophile Ranquet.

* tests/local.at (AT_MAIN_DEFINE): New.
(AT_YYERROR_DEFINE): Improve formatting.
* tests/actions.at, tests/c++.at, tests/conflicts.at,
* tests/glr-regression.at, tests/input.at, tests/regression.at,
* tests/skeletons.at, tests/torture.at: Adjust.
* tests/c++.at: Add missing %skeleton for a PUSHDEFS, and a missing
PUSH/POPDEFS for another test.
2013-01-21 16:27:46 +01:00
Akim Demaille
70b7c35747 tests: minor refactoring
* tests/named-refs.at: Use AT_FULL_COMPILE where applicable.
2013-01-21 16:15:05 +01:00
Akim Demaille
184878b9ca diagnostics: avoid useless caret stuttering
* src/scan-code.l: When reporting a missing ending ';', don't display
the guilty action twice.
2013-01-21 16:15:05 +01:00
Theophile Ranquet
6908c2e1f7 examples: please clang
* doc/bison.texi (calc++-scanner.ll): Don't output useless yyinput function.
2013-01-21 15:54:04 +01:00