shithub: scc

Download patch

ref: 1dacb7932abe8799f3d0106d24c2615781dfe3a0
parent: 3dca060d1ad6e41aa5ec4c4bc26bfff2fff54a1d
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Jul 11 05:50:31 EDT 2014

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.

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -322,12 +322,20 @@
 	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);