X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/42ec0ae176c4c75b9b29d7e01b4e543c54cdfa5e..b7226022b07fac385defbf2297892d8c3dc3cd18:/src/symtab.c diff --git a/src/symtab.c b/src/symtab.c index a2631852..56cfe511 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -1,8 +1,7 @@ /* Symbol table manager for Bison. - Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007, - 2008, 2009 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 2000-2002, 2004-2012 Free Software + Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -23,7 +22,6 @@ #include "system.h" #include -#include #include "complain.h" #include "gram.h" @@ -69,7 +67,7 @@ symbol_new (uniqstr tag, location loc) /* If the tag is not a string (starts with a double quote), check that it is valid for Yacc. */ - if (tag[0] != '\"' && tag[0] != '\'' && strchr (tag, '-')) + if (tag[0] != '\"' && tag[0] != '\'' && mbschr (tag, '-')) yacc_at (loc, _("POSIX Yacc forbids dashes in symbol names: %s"), tag); @@ -152,16 +150,20 @@ static void symbol_redeclaration (symbol *s, const char *what, location first, location second) { - complain_at (second, _("%s redeclaration for %s"), what, s->tag); - complain_at (first, _("previous declaration")); + unsigned i = 0; + complain_at_indent (second, &i, _("%s redeclaration for %s"), what, s->tag); + i += SUB_INDENT; + complain_at_indent (first, &i, _("previous declaration")); } static void semantic_type_redeclaration (semantic_type *s, const char *what, location first, location second) { - complain_at (second, _("%s redeclaration for <%s>"), what, s->tag); - complain_at (first, _("previous declaration")); + unsigned i = 0; + complain_at_indent (second, &i, _("%s redeclaration for <%s>"), what, s->tag); + i += SUB_INDENT; + complain_at_indent (first, &i, _("previous declaration")); } @@ -184,24 +186,6 @@ symbol_type_set (symbol *sym, uniqstr type_name, location loc) } } -/*-----------------------------------. -| Get the CLASS associated with SYM. | -`-----------------------------------*/ - -const char * -symbol_class_get_string (symbol *sym) -{ - if (sym->class) - { - if (sym->class == token_sym) - return "terminal"; - else if (sym->class == nterm_sym) - return "nonterminal"; - } - return "unknown"; -} - - /*-----------------------------------------. | Set the DESTRUCTOR associated with SYM. | `-----------------------------------------*/ @@ -387,10 +371,11 @@ symbol_user_token_number_set (symbol *sym, int user_token_number, location loc) if (user_token_number == 0) { endtoken = sym; - endtoken->number = 0; /* It is always mapped to 0, so it was already counted in NTOKENS. */ - --ntokens; + if (endtoken->number != NUMBER_UNDEFINED) + --ntokens; + endtoken->number = 0; } } @@ -427,11 +412,11 @@ void symbol_make_alias (symbol *sym, symbol *str, location loc) { if (str->alias) - warn_at (loc, _("symbol `%s' used more than once as a literal string"), - str->tag); + warn_at (loc, _("symbol %s used more than once as a literal string"), + str->tag); else if (sym->alias) - warn_at (loc, _("symbol `%s' given more than one literal string"), - sym->tag); + warn_at (loc, _("symbol %s given more than one literal string"), + sym->tag); else { str->class = token_sym; @@ -534,6 +519,7 @@ symbol_pack_processor (void *this, void *null ATTRIBUTE_UNUSED) 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. @@ -545,11 +531,13 @@ user_token_number_redeclaration (int num, symbol *first, symbol *second) 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); + complain_at_indent (second->location, &i, + _("user token number %d redeclaration for %s"), + num, second->tag); + i += SUB_INDENT; + complain_at_indent (first->location, &i, + _("previous declaration for %s"), + first->tag); } /*--------------------------------------------------. @@ -942,10 +930,12 @@ default_tagged_destructor_set (code_props const *destructor) { if (default_tagged_destructor.code) { - complain_at (destructor->location, - _("redeclaration for default tagged %%destructor")); - complain_at (default_tagged_destructor.location, - _("previous declaration")); + unsigned i = 0; + complain_at_indent (destructor->location, &i, + _("redeclaration for default tagged %%destructor")); + i += SUB_INDENT; + complain_at_indent (default_tagged_destructor.location, &i, + _("previous declaration")); } default_tagged_destructor = *destructor; } @@ -955,10 +945,12 @@ default_tagless_destructor_set (code_props const *destructor) { if (default_tagless_destructor.code) { - complain_at (destructor->location, - _("redeclaration for default tagless %%destructor")); - complain_at (default_tagless_destructor.location, - _("previous declaration")); + unsigned i = 0; + complain_at_indent (destructor->location, &i, + _("redeclaration for default tagless %%destructor")); + i += SUB_INDENT; + complain_at_indent (default_tagless_destructor.location, &i, + _("previous declaration")); } default_tagless_destructor = *destructor; } @@ -968,10 +960,12 @@ default_tagged_printer_set (code_props const *printer) { if (default_tagged_printer.code) { - complain_at (printer->location, - _("redeclaration for default tagged %%printer")); - complain_at (default_tagged_printer.location, - _("previous declaration")); + unsigned i = 0; + complain_at_indent (printer->location, &i, + _("redeclaration for default tagged %%printer")); + i += SUB_INDENT; + complain_at_indent (default_tagged_printer.location, &i, + _("previous declaration")); } default_tagged_printer = *printer; } @@ -981,10 +975,12 @@ default_tagless_printer_set (code_props const *printer) { if (default_tagless_printer.code) { - complain_at (printer->location, - _("redeclaration for default tagless %%printer")); - complain_at (default_tagless_printer.location, - _("previous declaration")); + unsigned i = 0; + complain_at_indent (printer->location, &i, + _("redeclaration for default tagless %%printer")); + i += SUB_INDENT; + complain_at_indent (default_tagless_printer.location, &i, + _("previous declaration")); } default_tagless_printer = *printer; }