* origin/maint:
tests: headers.at: strengthen.
glr.cc: do not override C++ definitions by C macros.
YYLLOC_DEFAULT: factor, and don't export it in headers.
api.prefix: do not use #define to handle YYSTYPE_IS_TRIVIAL etc.
tests: portability fixes.
c++: fewer #includes in the headers.
glr.cc: formatting changes.
tests: more logs.
api.prefix: also rename YYDEBUG.
YYLLOC_DEFAULT: factor, and don't export it in headers.
* data/c++.m4, data/c.m4 (b4_yylloc_default_define): New.
* data/glr.c, data/glr.cc, data/lalr1.cc, data/yacc.c: Use it.
* data/glr.cc: Do not define YYLLOC_DEFAULT in the header file,
but in the implementation one.
since, of course YYSTYPE_IS_TRIVIAL is defined. Instead we could
define YYSTYPE_IS_TRIVIAL as PREFIX_STYPE_IS_TRIVIAL only when the
later is defined, but let's avoid stacking CPP on top of M4: rather, use
* data/glr.c, data/yacc.c: Use YYSTYPE_IS_TRIVIAL, YYSTYPE_IS_DECLARED,
YYLTYPE_IS_TRIVIAL and YYLTYPE_IS_DECLARED under their api.prefix-renamed
name.
The testsuite in master has shown weird errors for the "Mulitple
Parsers" tests: the caller of p5.parse() received some apparently
random value, while tracing p5.parse() showed that the function was
consistently returning 0.
It happens when mixing several parser headers, some generated without
%debug, others with. In particular the C++ parser was generated with
%debug, i.e., with:
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
and compiled separatedly. Yet, its header was included after the one
of another parser, this time without %debug, i.e., with
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
in its header. As a result, the parser was compiled with YYDEBUG set,
but its header was used without. Since the layout of the objects are
then completely different, boom.
Therefore, do not change the value of YYDEBUG. Rather, use it as a
default value for <API.PREFIX>DEBUG.
* data/c.m4 (b4_YYDEBUG_define): New.
(b4_declare_yydebug): Rename as...
(b4_yydebug_declare): this, for consistency.
* data/glr.c, data/glr.cc, data/lalr1.cc, data/yacc.c: Use it.
* NEWS: Document it.
Victor Santet [Fri, 29 Jun 2012 13:22:09 +0000 (15:22 +0200)]
warnings: be ready to print warnings categories
A function to print warnings categories, like -Wyacc, -Wother, etc.
* src/complain.h, src/complain.c (print_warning_categories): New function.
* src/output.c (ARRAY_CARDINALITY): Move it to file 'src/system.h'.
* src/complain.h (enum warnings): New value, 'silent', "complain"
must not display the warning type.
Akim Demaille [Thu, 28 Jun 2012 13:29:18 +0000 (15:29 +0200)]
Merge remote-tracking branch 'origin/maint'
* origin/maint:
tests: use the generalized default yylex.
tests: AT_YYERROR_DEFINE: prepare for list of ints.
skeletons: no longer define YYLSP_NEEDED.
c++: do not export YYTOKEN_TABLE and YYERROR_VERBOSE.
Akim Demaille [Tue, 26 Jun 2012 14:43:22 +0000 (16:43 +0200)]
Merge remote-tracking branch 'origin/maint'
* origin/maint:
tests: do not output m4 set up.
tests: use the generic yyerror function.
tests: use assert instead of plain abort.
tests: improve the generic yylex implementation.
tests: generalize the compilation macros.
tests: fix confusion between api.prefix and name-prefix.
maint: gitignores.
yacc: work around the ylwrap limitation.
Victor Santet [Thu, 14 Jun 2012 12:20:07 +0000 (14:20 +0200)]
warnings: raise warning for useless printers or destructors
* src/scan-code.h (code_props): Add field 'is_used'.
(CODE_PROPS_NONE_INIT): Adjust.
* src/scan-code.l (code_props_plain_init, code_props_symbol_action_init)
(code_props_rule_action_init): Instead of implementing several
times the initialization of the code_props structures,
use code_props_none_init.
* src/symtab.c (symbol_check_defined): If a symbol does not have a
destructor (resp. printer) but has a type which has a destructor (resp.
printer), then set field 'is_used' to true.
(semantic_type_check_defined): If a type has a destructor (resp. printer)
but all symbols of this type have already a destructor (resp. printer),
then raise a warning.
* tests/input.at (Useless printers or destructors): New.
Akim Demaille [Tue, 26 Jun 2012 12:05:56 +0000 (14:05 +0200)]
tests: do not output m4 set up.
* tests/local.at (AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS):
Use a diversion to avoid outputting comments etc.
Removes 17k lines from testsuite (10% of the number of lines).
Akim Demaille [Tue, 26 Jun 2012 09:54:13 +0000 (11:54 +0200)]
tests: use the generic yyerror function.
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Factor.
Use AT_YYERROR_DEFINE.
Therefore, instead of using stdout, use and check stderr.
* tests/glr-regression.at (Uninitialized location when reporting ambiguity):
Use AT_YYERROR_DEFINE.
Akim Demaille [Mon, 25 Jun 2012 14:37:18 +0000 (16:37 +0200)]
tests: generalize the compilation macros.
* tests/local.at (AT_COMPILE, AT_COMPILE_CXX): If OUTPUT ends with ".o",
then append the "natural" extension for the input file (.c or .cc).
If there is no source, pass -c.
* tests/headers.at, tests/input.at, tests/regression.at: Adjust.
Akim Demaille [Tue, 26 Jun 2012 07:35:31 +0000 (09:35 +0200)]
tests: fix confusion between api.prefix and name-prefix.
* tests/local.at (AT_NAME_PREFIX): Take api.prefix into account.
(AT_API_PREFIX): Rename as...
(AT_API_prefix): this.
Do not take %name-prefix into account.
Fix misuses.
Victor Santet [Mon, 18 Jun 2012 13:44:38 +0000 (15:44 +0200)]
warnings: useless semantic types
* src/symtab.h (symbol_list): Represent semantic types as structure
'semantic_type'.
* src/symlist.c (symbol_list_type_new): Allocate this structure.
(symbol_list_code_props_set): Set this semantic type's status to used if it
was not declared.
* src/symtab.c (semantic_types_sorted): New.
(semantic_type_new): Set the new semantic type's location appropriately.
(symbol_check_defined): If a symbol has a type, then set this type's status
to "declared".
(semantic_type_check_defined, semantic_type_check_defined_processor): Same
as symbol_check_defined and symbol_check_defined_processor, but for semantic
types.
(symbol_check_defined): Check semantic types usefulness.
* src/symtab.h (semantic_type): New fields 'location' and 'status'.
* src/symtab.h, src/symtab.c (semantic_type_new)
(semantic_type_from_uniqstr, semantic_type_get): Accept a location as a
supplementary argument.
* tests/input.at (Unassociated types used for printer of destructor): New.
* tests/c++.at (AT_CHECK_VARIANTS): Fix an error caught by this commit.
Akim Demaille [Mon, 25 Jun 2012 08:15:44 +0000 (10:15 +0200)]
yacc: work around the ylwrap limitation.
* data/yacc.c (b4_shared_declarations): Include the header guards.
Do not include the header in the *.c file, duplicate it.
* NEWS (Future Changes): Extend, and announce the forthcoming change
about the use of the parser header.
Akim Demaille [Mon, 25 Jun 2012 07:26:48 +0000 (09:26 +0200)]
Merge remote-tracking branch 'origin/maint'
* origin/maint:
tests: more uniformity.
tests: handle locations in a more generic way.
tests: handle locations in the generic yyerror functions.
tests: fix AT_CHECK_CALC.
tests: improve infrastructure
tests: factor.
skeletons: minor style changes
tests: AT_LANG.
c skeletons: factor the declaration of yylloc and yylval.
news: condemn YYPARSE_PARAM and YYLEX_PARAM.
maint: regen.
Akim Demaille [Fri, 22 Jun 2012 12:47:31 +0000 (14:47 +0200)]
code_props: factor more.
* src/symtab.h, src/symtab.c (code_props_type_string): No longer static.
* src/output.c (CODE_PROPS): Remove, we can now iterate on both the
destructor and the printer.
(SET_KEY2): New.
Victor Santet [Fri, 22 Jun 2012 12:11:05 +0000 (14:11 +0200)]
maint: factor the handling of %printer and %destructor
There is too much code duplication between %printer and %destructor.
We used to have two functions for each action: the first one for
destructors, the second one for printers. Factor using a
'code_props_type', and an array of code_props instead of two
members.
Akim Demaille [Fri, 22 Jun 2012 10:08:02 +0000 (12:08 +0200)]
tests: more uniformity.
* tests/local.at (AT_LEX_FORMALS, AT_LEX_ARGS, AT_LEX_PRE_FORMALS)
(AT_LEX_PRE_ARGS): Rename as...
(AT_YYLEX_FORMALS, AT_YYLEX_ARGS, AT_YYLEX_PRE_FORMALS)
(AT_YYLEX_PRE_ARGS): these, for consistency.
(AT_API_PREFIX): Take %name-prefix into account.
(AT_YYLEX_PROTOTYPE): New.
Use it.
* tests/actions.at, tests/calc.at, tests/cxx-type.at: Adjust to
use them.
Akim Demaille [Fri, 22 Jun 2012 09:34:37 +0000 (11:34 +0200)]
tests: handle locations in a more generic way.
* tests/local.at (AT_YYERROR_PROTOTYPE): New.
Use it.
* tests/cxx-type.at: Extensive revamp to use a more traditional
quotation scheme, and to use the generic yyerror implementation.
Prefer Autotest macros to CPP macros.
* tests/java.at: .
Akim Demaille [Fri, 22 Jun 2012 08:20:28 +0000 (10:20 +0200)]
tests: handle locations in the generic yyerror functions.
* tests/local.at (AT_YYERROR_DECLARE_EXTERN, AT_YYERROR_DECLARE)
(AT_YYERROR_DEFINE): Handle locations for C and C++.
* tests/calc.at: Use it for C++ (as C has extra arguments which
are not yet handled by AT_BISON_OPTION_PUSHDEFS).
* tests/actions.at: Adjust.
Akim Demaille [Thu, 21 Jun 2012 21:05:05 +0000 (23:05 +0200)]
tests: improve infrastructure
* tests/local.at (AT_LANG): Use c++ instead of cxx for C++.
Adjust dependencies.
(AT_YYERROR_DECLARE_EXTERN, AT_YYERROR_DECLARE): Issue nothing
for C++/Java.
(AT_YYERROR_DEFINE): Use m4_case.
(AT_JAVA_COMPILE): Use AT_SKIP_IF.
Akim Demaille [Sun, 17 Jun 2012 10:10:44 +0000 (12:10 +0200)]
c skeletons: factor the declaration of yylloc and yylval.
There is one difference: now, even without --defines, we generate
extern declarations for these variables. The factoring is worth it.
* data/c.m4 (b4_declare_yylstype): Declare them.
* data/glr.c, data/yacc.c: Adjust.
Akim Demaille [Wed, 20 Jun 2012 10:33:34 +0000 (12:33 +0200)]
fix warnings for useless %printer/%destructor
The previous commit, which turns into a warning what used to be an
error:
%printer {} foo;
%%
exp: '0';
has two shortcomings: the warning is way too long (foo is reported
to be useless later), and besides, it also turns into a warning much
more serious errors:
%printer {} foo;
%%
exp: foo;
Reduce the amount to warnings in the first case, restore the error in
the second.
* src/symtab.h (status): Add a new inital state: undeclared.
* src/symtab.c (symbol_new): Initialize to undeclared.
(symbol_class_set): Simplify the logic of the code that neutralize
the "redeclared" warning after the "redefined" one.
(symbol_check_defined): "undeclared" is also an error.
* src/reader.c (grammar_current_rule_symbol_append): Symbols appearing
in a rule are "needed".
* src/symlist.c (symbol_list_destructor_set, symbol_list_printer_set):
An unknown symbol appearing in a %printer/%destructor is "used".
* src/reduce.c (nonterminals_reduce): Do not report as "useless" symbols
that are not used (e.g., those that for instance appeared only in a
%printer).
* tests/input.at (Undeclared symbols used for a printer or destructor):
Improve the cover the cases described above.
Victor Santet [Tue, 19 Jun 2012 14:14:55 +0000 (16:14 +0200)]
warnings: used but undeclared symbols are warnings
We used to raise an error if a symbol appears only in a %printer or
%destructor. Make it a warning.
* src/symtab.h (status): New enum.
(symbol): Replace the binary "declared" with the three-state "status".
Adjust dependencies.
* src/symtab.c (symbol_check_defined): Needed symbols are an error,
whereas "used" are simply warnings.
* src/symlist.c (symbol_list_destructor_set, symbol_list_printer): Set
symbol status to 'used' when associated to destructors or printers.
* input.at (Undeclared symbols used for a printer or destructor): New.
Akim Demaille [Tue, 19 Jun 2012 15:35:53 +0000 (17:35 +0200)]
Merge remote-tracking branch 'origin/maint'
* origin/maint:
maint: formatting changes.
tests: support api.prefix.
tests: pacify font-lock-mode.
tests: remove test covered elsewhere.
tests: factor the declaration/definition of yyerror and yylex.
regen.
tests: portability issues.
tests: call the parser from another compilation unit.
glr.c, yacc.c: declare yydebug in the header.
skeletons: use header guards.
tests: improve AT_FULL_COMPILE.
tests: reorder.
tests: strengthen the test on generated headers inclusion
yacc.c: instead of duplicating y.tab.h inside y.tac.c, include it.
yacc.c: factor.
Akim Demaille [Mon, 11 Jun 2012 14:47:46 +0000 (16:47 +0200)]
tests: call the parser from another compilation unit.
In order to improve the testing of %defines, which exports the
interface of the generated parser, change the calc.at tests so that
when %defines is passed, main will be in another compilation unit. It
loads the generated header.
* tests/calc.at (AT_CALC_MAIN): New.
Includes the definition of the global variables.
Therefore, now declare them from the %requires section of the parser.
Adjust to yydebug and yyparse being renamed by %name-prefix.
Akim Demaille [Fri, 15 Jun 2012 13:19:16 +0000 (15:19 +0200)]
glr.c, yacc.c: declare yydebug in the header.
* data/c.m4 (b4_declare_yydebug): New.
* data/glr.c, data/yacc.c (b4_shared_declarations): Use it.
Remove the corresponding code from the parser body.
* NEWS: Doc this.
Akim Demaille [Tue, 12 Jun 2012 12:40:18 +0000 (14:40 +0200)]
yacc.c: factor.
yacc.c used to include two almost identical sections: one for the *.h
file, and another for the *.c file. The main difference is that in
the *.c file we used the yy* names (as %name-prefix is handled by
"#define yy* <prefix>*" before), while the *.hh used <prefix>* names.
Keep only the later. If this is troublesome, b4_shared_declarations
can easily take the desired prefix as argument.
* data/yacc.c (b4_shared_declarations): New.
Use it to factor duplicated declarations.