shithub: scc

Download patch

ref: c69a4b90cc4b70415cc5ac62d9465b7ec8fdd543
parent: 1372160651f5eea2d275bf4509aeec427b6ce5e6
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Aug 11 12:35:18 EDT 2015

Force cpp symbols to be at the beginning of the hash

Cpp symbols have bigger 'priority' than any other symbol,
because they are expanded in a previous stage, so they
must not be hidden by any other symbol.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -306,6 +306,7 @@
 extern Symbol *newsym(unsigned ns);
 extern void pushctx(void), popctx(void);
 extern void ikeywords(void);
+extern Symbol *addmacro(void);
 
 /* stmt.c */
 extern void compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch);
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -29,7 +29,7 @@
 	Symbol *sym;
 
 	strcpy(yytext, s);
-	sym = lookup(NS_CPP);
+	sym = addmacro();
 	sym->flags |= ISDECLARED;
 	return sym;
 }
@@ -330,7 +330,7 @@
 		warn("'%s' redefined", yytext);
 		free(sym->u.s);
 	} else if (sym->ns != NS_CPP) {
-		sym = lookup(NS_CPP);
+		sym = addmacro();
 	}
 	sym->flags |= ISDECLARED;
 
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -1,5 +1,6 @@
 
 #include <inttypes.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -207,6 +208,20 @@
 	sym->flags &= ~ISDECLARED;
 
 	return sym;
+}
+
+Symbol *
+addmacro(void)
+{
+	unsigned ctx = curctx;
+	Symbol *sym;
+
+	/* Force cpp symbols to be at the beginning of the hash */
+	curctx = UCHAR_MAX;
+	sym = lookup(NS_CPP);
+	curctx = ctx;
+	return sym;
+}
 }
 
 Symbol *