/* Symbol table manager for Bison.
- Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004 Free Software
- Foundation, Inc.
+ Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006 Free
+ Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
You should have received a copy of the GNU General Public License
along with Bison; see the file COPYING. If not, write to
- the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+#include <config.h>
#include "system.h"
#include <hash.h>
res->alias = NULL;
res->class = unknown_sym;
+ res->declared = false;
+ if (nsyms == SYMBOL_NUMBER_MAXIMUM)
+ fatal (_("too many symbols in input grammar (limit is %d)"),
+ SYMBOL_NUMBER_MAXIMUM);
nsyms++;
return res;
}
+/*-----------------.
+| Print a symbol. |
+`-----------------*/
+
+#define SYMBOL_ATTR_PRINT(Attr) \
+ if (s->Attr) \
+ fprintf (f, " %s { %s }", #Attr, s->Attr)
+
+void
+symbol_print (symbol *s, FILE *f)
+{
+ if (s)
+ {
+ fprintf (f, "\"%s\"", s->tag);
+ SYMBOL_ATTR_PRINT (type_name);
+ SYMBOL_ATTR_PRINT (destructor);
+ SYMBOL_ATTR_PRINT (printer);
+ }
+ else
+ fprintf (f, "<NULL>");
+}
+
+#undef SYMBOL_ATTR_PRINT
+
/*------------------------------------------------------------------.
| Complain that S's WHAT is redeclared at SECOND, and was first set |
| at FIRST. |
`------------------------------------------------------------------*/
void
-symbol_destructor_set (symbol *sym, char *destructor, location loc)
+symbol_destructor_set (symbol *sym, const char *destructor, location loc)
{
if (destructor)
{
`---------------------------------------------------------------*/
void
-symbol_printer_set (symbol *sym, char *printer, location loc)
+symbol_printer_set (symbol *sym, const char *printer, location loc)
{
if (printer)
{
}
/* Only terminals have a precedence. */
- symbol_class_set (sym, token_sym, loc);
+ symbol_class_set (sym, token_sym, loc, false);
}
`------------------------------------*/
void
-symbol_class_set (symbol *sym, symbol_class class, location loc)
+symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
{
if (sym->class != unknown_sym && sym->class != class)
- complain_at (loc, _("symbol %s redefined"), sym->tag);
+ {
+ complain_at (loc, _("symbol %s redefined"), sym->tag);
+ sym->declared = false;
+ }
if (class == nterm_sym && sym->class != nterm_sym)
sym->number = nvars++;
sym->number = ntokens++;
sym->class = class;
+
+ if (declaring)
+ {
+ if (sym->declared)
+ warn_at (loc, _("symbol %s redeclared"), sym->tag);
+ sym->declared = true;
+ }
}
void
symbol_user_token_number_set (symbol *sym, int user_token_number, location loc)
{
- if (sym->class != token_sym)
- abort ();
+ assert (sym->class == token_sym);
if (sym->user_token_number != USER_NUMBER_UNDEFINED
&& sym->user_token_number != user_token_number)
/* sym and symval combined are only one symbol. */
nsyms--;
ntokens--;
- if (ntokens != sym->number && ntokens != symval->number)
- abort ();
+ assert (ntokens == sym->number || ntokens == symval->number);
sym->number = symval->number =
(symval->number < sym->number) ? symval->number : sym->number;
+ symbol_type_set (symval, sym->type_name, loc);
}
}
if (!(this->alias && this->user_token_number == USER_NUMBER_ALIAS))
return;
- if (orig->type_name || alias->type_name)
+ if (orig->type_name != alias->type_name)
{
if (orig->type_name)
symbol_type_set (alias, orig->type_name, orig->type_location);
this->number = this->alias->number = 0;
else
{
- if (this->alias->number == NUMBER_UNDEFINED)
- abort ();
+ assert (this->alias->number != NUMBER_UNDEFINED);
this->number = this->alias->number;
}
}
return true;
}
else /* this->class == token_sym */
- {
- if (this->number == NUMBER_UNDEFINED)
- abort ();
- }
+ assert (this->number != NUMBER_UNDEFINED);
symbols[this->number] = this;
return true;
symbol probe;
symbol *entry;
- /* Keep the symbol in a printable form. */
- key = uniqstr_new (quotearg_style (escape_quoting_style, key));
+ key = uniqstr_new (key);
probe.tag = key;
entry = hash_lookup (symbol_table, &probe);