summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim@lrde.epita.fr>2013-12-09 15:40:07 +0100
committerAkim Demaille <akim@lrde.epita.fr>2013-12-09 16:03:03 +0100
commit26eb4f0bdcd78ea56c05c49363b9fbe6072c425c (patch)
tree96252cf5d6b0229acbe8bd1e212cddce97f5f024
parent0bd5ee5f8919a74cd3f4b8da3f51da99193e1319 (diff)
downloadbison-26eb4f0bdcd78ea56c05c49363b9fbe6072c425c.tar.gz
symbol: provide an easy means to compare them in source order
* src/symtab.c (symbols_sort): New. (user_token_number_redeclaration): Taken from here.
-rw-r--r--src/symtab.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/symtab.c b/src/symtab.c
index 1c2372c1..1b446119 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -100,6 +100,28 @@ symbol_new (uniqstr tag, location loc)
return res;
}
+/* If needed, swap first and second so that first has the earliest
+ location (according to location_cmp).
+
+ Many symbol features (e.g., user token numbers) are not assigned
+ during the parsing, but in a second step, via a traversal of the
+ symbol table sorted on tag.
+
+ However, error messages make more sense if we keep the first
+ declaration first.
+*/
+
+static
+void symbols_sort (symbol **first, symbol **second)
+{
+ if (0 < location_cmp ((*first)->location, (*second)->location))
+ {
+ symbol* tmp = *first;
+ *first = *second;
+ *second = tmp;
+ }
+}
+
char const *
code_props_type_string (code_props_type kind)
{
@@ -587,17 +609,7 @@ static void
user_token_number_redeclaration (int num, symbol *first, symbol *second)
{
unsigned i = 0;
- /* User token numbers are not assigned during the parsing, but in a
- second step, via a traversal of the symbol table sorted on tag.
-
- However, error messages make more sense if we keep the first
- declaration first. */
- if (location_cmp (first->location, second->location) > 0)
- {
- symbol* tmp = first;
- first = second;
- second = tmp;
- }
+ symbols_sort (&first, &second);
complain_indent (&second->location, complaint, &i,
_("user token number %d redeclaration for %s"),
num, second->tag);