+/* 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;
+ }
+}
+
+/* Likewise, for locations. */
+
+static
+void locations_sort (location *first, location *second)
+{
+ if (0 < location_cmp (*first, *second))
+ {
+ location tmp = *first;
+ *first = *second;
+ *second = tmp;
+ }
+}
+