[hackers] [scc] Force cpp symbols to be at the beginning of the hash || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 11 Aug 2015 17:57:55 +0200 (CEST)

commit c69a4b90cc4b70415cc5ac62d9465b7ec8fdd543
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Aug 11 16:35:18 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Aug 11 17:27:01 2015 +0200

    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.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index cab3c33..3d91eaf 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -306,6 +306,7 @@ extern Symbol *install(unsigned ns, Symbol *sym);
 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);
diff --git a/cc1/cpp.c b/cc1/cpp.c
index 98765b0..64e0cd6 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -29,7 +29,7 @@ defmacro(char *s)
         Symbol *sym;
 
         strcpy(yytext, s);
- sym = lookup(NS_CPP);
+ sym = addmacro();
         sym->flags |= ISDECLARED;
         return sym;
 }
_AT_@ -330,7 +330,7 @@ define(void)
                 warn("'%s' redefined", yytext);
                 free(sym->u.s);
         } else if (sym->ns != NS_CPP) {
- sym = lookup(NS_CPP);
+ sym = addmacro();
         }
         sym->flags |= ISDECLARED;
 
diff --git a/cc1/symbol.c b/cc1/symbol.c
index 1f4aefa..001a471 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
_AT_@ -1,5 +1,6 @@
 
 #include <inttypes.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
_AT_@ -210,6 +211,20 @@ lookup(unsigned ns)
 }
 
 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 *
 nextsym(Symbol *sym, unsigned ns)
 {
         char *s, *t, c;
Received on Tue Aug 11 2015 - 17:57:55 CEST

This archive was generated by hypermail 2.3.0 : Tue Aug 11 2015 - 18:00:21 CEST