commit 1dacb7932abe8799f3d0106d24c2615781dfe3a0
parent 3dca060d1ad6e41aa5ec4c4bc26bfff2fff54a1d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 11 Jul 2014 09:50:31 +0200
Allow tags with same name that a previous typedef
Tags have a separate namespace, so it is correct this combination,
but the problem is the lexer returns a different token for an
identifier after a typedef for it. For example:
main()
{
typedef int pepe;
struct pepe {
int i;
char c;
} h;
}
The easier solution is a hack, where we modify the grammar to
accept an IDEN or a TYPE when creating tags.
Diffstat:
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/cc1/decl.c b/cc1/decl.c
@@ -322,12 +322,20 @@ newtag(uint8_t tag)
register Symbol *sym;
register Type *tp;
- if (yytoken == IDEN) {
+ switch (yytoken) {
+ case TYPE:
+ if (yylval.token != TYPENAME)
+ goto no_tag;
+ /* pass through */
+ case IDEN:
if ((sym = lookup(yytext, NS_TAG)) == NULL)
sym = install(yytext, NS_TAG);
next();
- } else {
+ break;
+ default:
+ no_tag:
sym = install("", NS_TAG);
+ break;
}
if (!(tp = sym->type))
tp = sym->type = mktype(NULL, tag, 0);