[hackers] [scc] Do not link cpp and label symbols in the block list || Roberto E. Vargas Caballero

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

commit da310fbe77b3276fa9554b91c3e28dd53399fe22
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Aug 11 12:41:43 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Aug 11 15:23:44 2015 +0200

    Do not link cpp and label symbols in the block list
    
    Cpp symbols have file storage, and labels have
    function storage, so it is not very useful put
    them in the block list.
    disturb in popctx().

diff --git a/cc1/cc1.h b/cc1/cc1.h
index ee724f9..cab3c33 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -4,6 +4,8 @@
 #define PREFIX "/usr/"
 #endif
 
+#define GLOBALCTX 0
+
 /*
  * Definition of structures
  */
diff --git a/cc1/decl.c b/cc1/decl.c
index f072110..991a784 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -9,7 +9,6 @@
 #include "../inc/cc.h"
 #include "cc1.h"
 
-#define GLOBALCTX 0
 #define NOSCLASS 0
 
 struct dcldata {
diff --git a/cc1/symbol.c b/cc1/symbol.c
index 6328897..6fa736d 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
_AT_@ -14,7 +14,7 @@ unsigned curctx;
 static short localcnt;
 static short globalcnt;
 
-static Symbol *head;
+static Symbol *head, *labels;
 static Symbol *htab[NR_SYM_HASH];
 
 #ifndef NDEBUG
_AT_@ -102,36 +102,28 @@ void
 popctx(void)
 {
         Symbol *next, *sym;
- Symbol dummy = {.next = NULL}, *hp = &dummy;
+ short f;
 
- if (--curctx == 0)
+ if (--curctx == GLOBALCTX) {
                 localcnt = 0;
+ for (sym = labels; sym; sym = next) {
+ next = sym->next;
+ if ((f & (ISUSED|ISDECLARED)) == ISDECLARED)
+ warn("'%s' defined but not used", sym->name);
+ if ((sym->flags & ISDECLARED) == 0)
+ printerr("label '%s' is not defined", sym->name);
+ free(sym->name);
+ free(sym);
+ }
+ labels = NULL;
+ }
 
         for (sym = head; sym && sym->ctx > curctx; sym = next) {
                 next = sym->next;
- switch (sym->ns) {
- case NS_LABEL:
- if (curctx != 0)
- goto save_symbol;
- if (sym->flags & ISDECLARED)
- break;
- printerr("label '%s' is not defined", sym->name);
- break;
- case NS_CPP:
- save_symbol:
- /*
- * CPP symbols have file scope
- * Labels have function scope
- */
- hp->next = sym;
- hp = sym;
- continue;
- case NS_TAG:
+ if (sym->ns == NS_TAG)
                         sym->type->defined = 0;
- break;
- }
                 if (sym->name) {
- short f = sym->flags;
+ f = sym->flags;
                         unlinkhash(sym);
                         if ((f & (ISUSED|ISGLOBAL|ISDECLARED)) == ISDECLARED)
                                 warn("'%s' defined but not used", sym->name);
_AT_@ -140,8 +132,7 @@ popctx(void)
                 // TODO: Fix this memory leak free(sym->u.pars);
                 free(sym);
         }
- hp->next = sym;
- head = dummy.next;
+ head = sym;
 }
 
 Type *
_AT_@ -171,6 +162,10 @@ newsym(unsigned ns)
 
         if (ns == NS_CPP)
                 return sym;
+ if (ns == NS_LABEL) {
+ sym->next = labels;
+ return labels = sym;
+ }
 
         for (prev = p = head; p; prev = p, p = p->next) {
                 if (p->ctx <= sym->ctx)
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:15 CEST