X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/c547693afdacf4b865027d3bb8c53f601eadb5ae..9fd33c2b6ef5d98ac14ac7d83bc453b148fda768:/src/symtab.c diff --git a/src/symtab.c b/src/symtab.c index b3f94560..ad8820f4 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -67,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] != '\'' && mbschr (tag, '-')) + if (tag[0] != '\"' && tag[0] != '\'' && strchr (tag, '-')) yacc_at (loc, _("POSIX Yacc forbids dashes in symbol names: %s"), tag); @@ -85,7 +85,7 @@ symbol_new (uniqstr tag, location loc) res->alias = NULL; res->class = unknown_sym; - res->declared = false; + res->status = undeclared; if (nsyms == SYMBOL_NUMBER_MAXIMUM) fatal (_("too many symbols in input grammar (limit is %d)"), @@ -358,10 +358,12 @@ symbol_precedence_set (symbol *sym, int prec, assoc a, location loc) void symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring) { + bool warned = false; if (sym->class != unknown_sym && sym->class != class) { complain_at (loc, _("symbol %s redefined"), sym->tag); - sym->declared = false; + // Don't report both "redefined" and "redeclared". + warned = true; } if (class == nterm_sym && sym->class != nterm_sym) @@ -373,9 +375,9 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring) if (declaring) { - if (sym->declared) + if (sym->status == declared && !warned) warn_at (loc, _("symbol %s redeclared"), sym->tag); - sym->declared = true; + sym->status = declared; } } @@ -421,10 +423,26 @@ symbol_check_defined (symbol *sym) { if (sym->class == unknown_sym) { - complain_at - (sym->location, - _("symbol %s is used, but is not defined as a token and has no rules"), - sym->tag); + switch (sym->status) + { + case used: + warn_at (sym->location, + _("symbol %s is used, but is not defined as a token" + " and has no rules"), + sym->tag); + break; + case undeclared: + case needed: + complain_at (sym->location, + _("symbol %s is used, but is not defined as a token" + " and has no rules"), + sym->tag); + break; + case declared: + /* If declared, then sym->class != unknown_sym. */ + assert (0); + } + sym->class = nterm_sym; sym->number = nvars++; }