diagnostics: fix the order of multiple declarations reports

On

  %token FOO "foo"
  %printer {} "foo"
  %printer {} FOO

we report

  /tmp/foo.yy:2.10-11: error: %printer redeclaration for FOO
   %printer {} "foo"
            ^^
  /tmp/foo.yy:3.10-11:     previous declaration
   %printer {} FOO
            ^^

* src/symtab.c (locations_sort): New.
Use it.
* tests/input.at (Invalid Aliases): Stress the order of diagnostics.
This commit is contained in:
Akim Demaille
2013-12-09 15:26:52 +01:00
parent 26eb4f0bdc
commit 461f1516f8
3 changed files with 136 additions and 32 deletions

View File

@@ -122,6 +122,19 @@ void symbols_sort (symbol **first, symbol **second)
}
}
/* Likewise, for locations. */
static
void locations_sort (location *first, location *second)
{
if (0 < location_cmp (*first, *second))
{
location tmp = *first;
*first = *second;
*second = tmp;
}
}
char const *
code_props_type_string (code_props_type kind)
{
@@ -232,6 +245,7 @@ symbol_redeclaration (symbol *s, const char *what, location first,
location second)
{
unsigned i = 0;
locations_sort (&first, &second);
complain_indent (&second, complaint, &i,
_("%s redeclaration for %s"), what, s->tag);
i += SUB_INDENT;
@@ -244,6 +258,7 @@ semantic_type_redeclaration (semantic_type *s, const char *what, location first,
location second)
{
unsigned i = 0;
locations_sort (&first, &second);
complain_indent (&second, complaint, &i,
_("%s redeclaration for <%s>"), what, s->tag);
i += SUB_INDENT;