Define the "identifier" of a symbol.

Symbols may have several string representations, for instance if they
have an alias.  What I call its "id" is a string that can be used as
an identifier.  May not exist.

Currently the symbols which have the "tag_is_id" flag set are those that
don't have an alias.  Look harder for the id.

	* src/output.c (is_identifier): Move to...
	* src/symtab.c (is_identifier): here.
	* src/symtab.h, src/symtab.c (symbol_id_get): New.
	* src/output.c (symbol_definitions_output): Use it to define "id"
	and "has_id".
	Remove the definition of "tag_is_id".
	* data/lalr1.cc: Use the "id" and "has_id" whereever "tag" and
	"tag_is_id" were used to produce code.
	We still use "tag" for documentation.
This commit is contained in:
Akim Demaille
2008-08-26 20:10:03 +02:00
parent 086fd1137d
commit aea10ef46f
5 changed files with 90 additions and 33 deletions

View File

@@ -128,6 +128,41 @@ symbol_print (symbol *s, FILE *f)
#undef SYMBOL_ATTR_PRINT
#undef SYMBOL_CODE_PRINT
/*----------------------------------.
| Whether S is a valid identifier. |
`----------------------------------*/
static bool
is_identifier (uniqstr s)
{
static char const alphanum[26 + 26 + 1 + 10] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"_"
"0123456789";
if (!s || ! memchr (alphanum, *s, sizeof alphanum - 10))
return false;
for (++s; *s; ++s)
if (! memchr (alphanum, *s, sizeof alphanum))
return false;
return true;
}
/*-----------------------------------------------.
| Get the identifier associated to this symbol. |
`-----------------------------------------------*/
uniqstr
symbol_id_get (symbol const *sym)
{
aver (sym->user_token_number != USER_NUMBER_ALIAS);
if (sym->alias)
sym = sym->alias;
return is_identifier (sym->tag) ? sym->tag : 0;
}
/*------------------------------------------------------------------.
| Complain that S's WHAT is redeclared at SECOND, and was first set |
| at FIRST. |