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.

Signed-off-by: Akim Demaille <akim@lrde.epita.fr>
This commit is contained in:
Victor Santet
2012-06-14 14:20:07 +02:00
committed by Akim Demaille
parent 9641b918ba
commit ea9a35c605
5 changed files with 96 additions and 10 deletions

View File

@@ -419,6 +419,15 @@ symbol_check_defined (symbol *sym)
sym->number = nvars++;
}
for (int i = 0; i < 2; ++i)
if (sym->props[i].kind == CODE_PROPS_NONE && sym->type_name)
{
semantic_type *sem_type = semantic_type_get (sym->type_name, NULL);
if (sem_type
&& sem_type->props[i].kind != CODE_PROPS_NONE)
sem_type->props[i].is_used = true;
}
/* Set the semantic type status associated to the current symbol to
'declared' so that we could check semantic types unnecessary uses. */
if (sym->type_name)
@@ -434,7 +443,16 @@ symbol_check_defined (symbol *sym)
static inline bool
semantic_type_check_defined (semantic_type *sem_type)
{
if (sem_type->status != declared)
if (sem_type->status == declared)
{
for (int i = 0; i < 2; ++i)
if (sem_type->props[i].kind != CODE_PROPS_NONE
&& ! sem_type->props[i].is_used)
warn_at (sem_type->location,
_("useless %s for type <%s>"),
code_props_type_string (i), sem_type->tag);
}
else
warn_at (sem_type->location,
_("type <%s> is used, but is not associated to any symbol"),
sem_type->tag);