]> git.saurik.com Git - bison.git/blobdiff - src/symtab.c
Named symbol references.
[bison.git] / src / symtab.c
index c956e72d6d0ae1f41f5788d0a7474eeed6b40deb..727ac2c7390f2cd3cde58502053ddf53fe5d8326 100644 (file)
@@ -193,6 +193,7 @@ semantic_type_redeclaration (semantic_type *s, const char *what, location first,
 }
 
 
+
 /*-----------------------------------------------------------------.
 | Set the TYPE_NAME associated with SYM.  Does nothing if passed 0 |
 | as TYPE_NAME.                                                    |
@@ -582,7 +583,26 @@ symbol_pack_processor (void *this, void *null ATTRIBUTE_UNUSED)
 }
 
 
+static void
+user_token_number_redeclaration (int num, symbol *first, symbol *second)
+{
+  /* User token numbers are not assigned during the parsing, but in a
+     second step, via a (nondeterministic) traversal of the symbol
+     hash table.
 
+     Make errors deterministic: keep the first declaration first.  */
+  if (location_cmp (first->location, second->location) > 0)
+    {
+      symbol* tmp = first;
+      first = second;
+      second = tmp;
+    }
+  complain_at (second->location,
+               _("user token number %d redeclaration for %s"),
+               num, second->tag);
+  complain_at (first->location, _("previous declaration for %s"),
+               first->tag);
+}
 
 /*--------------------------------------------------.
 | Put THIS in TOKEN_TRANSLATIONS if it is a token.  |
@@ -597,10 +617,10 @@ symbol_translation (symbol *this)
     {
       /* A token which translation has already been set? */
       if (token_translations[this->user_token_number] != undeftoken->number)
-       complain_at (this->location,
-                    _("tokens %s and %s both assigned number %d"),
-                    symbols[token_translations[this->user_token_number]]->tag,
-                    this->tag, this->user_token_number);
+       user_token_number_redeclaration
+          (this->user_token_number,
+           symbols[token_translations[this->user_token_number]],
+           this);
 
       token_translations[this->user_token_number] = this->number;
     }
@@ -715,7 +735,8 @@ symbol_from_uniqstr (const uniqstr key, location loc)
     {
       /* First insertion in the hash. */
       entry = symbol_new (key, loc);
-      hash_insert (symbol_table, entry);
+      if (!hash_insert (symbol_table, entry))
+        xalloc_die ();
     }
   return entry;
 }
@@ -739,7 +760,8 @@ semantic_type_from_uniqstr (const uniqstr key)
     {
       /* First insertion in the hash. */
       entry = semantic_type_new (key);
-      hash_insert (semantic_type_table, entry);
+      if (!hash_insert (semantic_type_table, entry))
+        xalloc_die ();
     }
   return entry;
 }