`-------------------------------------------------------------------*/
static symbol **symbols_sorted = NULL;
+static symbol **semantic_types_sorted = NULL;
/*------------------------.
| Distinguished symbols. |
`----------------------------------------*/
static semantic_type *
-semantic_type_new (uniqstr tag)
+semantic_type_new (uniqstr tag, const location *loc)
{
semantic_type *res = xmalloc (sizeof *res);
uniqstr_assert (tag);
res->tag = tag;
+ if (loc)
+ res->location = *loc;
for (int i = 0; i < CODE_PROPS_SIZE; ++i)
code_props_none_init (&res->props[i]);
if (sym->type_name)
{
code_props const *code =
- &semantic_type_get (sym->type_name)->props[kind];
+ &semantic_type_get (sym->type_name, NULL)->props[kind];
if (code->code)
return code;
}
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)
+ {
+ semantic_type *sem_type = semantic_type_get (sym->type_name, NULL);
+ if (sem_type)
+ sem_type->status = declared;
+ }
+
+ return true;
+}
+
+static inline bool
+semantic_type_check_defined (semantic_type *sem_type)
+{
+ 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);
+
return true;
}
return symbol_check_defined (sym);
}
+static bool
+semantic_type_check_defined_processor (void *sem_type,
+ void *null ATTRIBUTE_UNUSED)
+{
+ return semantic_type_check_defined (sem_type);
+}
+
void
symbol_make_alias (symbol *sym, symbol *str, location loc)
`-----------------------------------------------------------------------*/
semantic_type *
-semantic_type_from_uniqstr (const uniqstr key)
+semantic_type_from_uniqstr (const uniqstr key, const location *loc)
{
semantic_type probe;
semantic_type *entry;
if (!entry)
{
/* First insertion in the hash. */
- entry = semantic_type_new (key);
+ entry = semantic_type_new (key, loc);
if (!hash_insert (semantic_type_table, entry))
xalloc_die ();
}
`-----------------------------------------------------------------------*/
semantic_type *
-semantic_type_get (const char *key)
+semantic_type_get (const char *key, const location *loc)
{
- return semantic_type_from_uniqstr (uniqstr_new (key));
+ return semantic_type_from_uniqstr (uniqstr_new (key), loc);
}
{
symbols_do (symbol_check_defined_processor, NULL,
symbol_table, symbols_sorted);
+ symbols_do (semantic_type_check_defined_processor, NULL,
+ semantic_type_table, semantic_types_sorted);
}
/*------------------------------------------------------------------.
}
default_tagless_code_props[kind] = *code;
}
-