scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 7b66933103d3d4930735aec4dd0d739d0efe78e4
parent c8abdfe1b720a9d786ea3fd840d48b744ef07e06
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 11 Jul 2014 11:50:03 +0200

Allow variables with same name of typedef of external contexts

It is legal a code like:

	typedef int pepe;

	main()
	{
		int pepe;
	}

So, we have to detect when we already have a type in the declaration
and don't generate an error when we get a TYPENAME in this case. It
is also necessary add a new rule in directdcl in order to allow
create a new symbol from the string of a TYPENAME.

Diffstat:
Mcc1/decl.c | 13++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -68,12 +68,13 @@ directdcl(struct dcldata *dp, int8_t flags) dp = declarator0(dp, flags); expect(')'); } else if (flags) { - if (yytoken != IDEN) { - if (flags & ID_EXPECTED) - unexpected(); - sym = install("", NS_IDEN); - } else { + if (yytoken == IDEN || + yytoken == TYPE && yylval.token == TYPENAME) { sym = newiden(); + } else if (flags & ID_EXPECTED) { + unexpected(); + } else { + sym = install("", NS_IDEN); } dp->op = IDEN; dp->u.sym = sym; @@ -186,6 +187,8 @@ specifier(int8_t *sclass) case STRUCT: case UNION: dcl = structdcl; p = &type; break; case TYPENAME: + if (type) + goto check_types; tp = yylval.sym->type; case VOID: case BOOL: case CHAR: case INT: case FLOAT: case DOUBLE: