shithub: scc

Download patch

ref: b5a07a8e256269a057c0143c8f61f131d038eb44
parent: 2adcda7668e73c5fd1471f0766fd6fd3ba8d638b
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Sep 28 19:13:39 EDT 2015

Remove delmacro()

Delmacro() is not needed at all, because its work is already done by
killsym, which is more generic.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -346,7 +346,7 @@
 extern Symbol *newsym(int ns);
 extern void pushctx(void), popctx(void);
 extern void ikeywords(void);
-extern void delmacro(Symbol *sym);
+extern void killsym(Symbol *sym);
 extern Symbol *newlabel(void);
 
 /* stmt.c */
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -241,7 +241,7 @@
 	input->p = input->begin = begin;
 
 	if (!(sym->flags & ISDECLARED))
-		delmacro(sym);
+		killsym(sym);
 
 	return 1;
 }
@@ -342,7 +342,7 @@
 		free(sym->u.s);
 	} else {
 		sym = install(NS_CPP, sym);
-		sym->flags |= ISDECLARED;
+		sym->flags |= ISDECLARED|ISSTRING;
 	}
 
 	namespace = NS_IDEN;       /* Avoid polution in NS_CPP */
@@ -357,7 +357,7 @@
 	return;
 
 delete:
-	delmacro(sym);
+	killsym(sym);
 }
 
 void
@@ -531,7 +531,7 @@
 		next();
 		status = (sym->flags & ISDECLARED) != 0;
 		if (!status)
-			delmacro(sym);
+			killsym(sym);
 	} else {
 		/* TODO: catch recovery here */
 		if ((expr = iconstexpr()) == NULL) {
@@ -614,7 +614,7 @@
 		error("no macro name given in #undef directive");
 		return;
 	}
-	delmacro(yylval.sym);
+	killsym(yylval.sym);
 	next();
 }
 
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -76,7 +76,7 @@
 		error("too much nested blocks");
 }
 
-static void
+void
 killsym(Symbol *sym)
 {
 	short f;
@@ -87,14 +87,14 @@
 		free(sym->u.s);
 	if (sym->ns == NS_TAG)
 		sym->type->defined = 0;
-	if ((name = sym->name) != NULL) {
-		unlinkhash(sym);
+	unlinkhash(sym);
+	if ((name = sym->name) != NULL && sym->ns != NS_CPP) {
 		if ((f & (ISUSED|ISGLOBAL|ISDECLARED)) == ISDECLARED)
 			warn("'%s' defined but not used", name);
 		if ((f & ISDEFINED) == 0 && sym->ns == NS_LABEL)
 			errorp("label '%s' is not defined", name);
-		free(name);
 	}
+	free(name);
 	free(sym);
 }
 
@@ -168,7 +168,6 @@
 {
 	Symbol *p, *prev;
 
-	sym->flags |= ISDECLARED;
 	switch (sym->ns) {
 	case NS_CPP:
 		return sym;
@@ -198,7 +197,6 @@
 	Symbol **h, *p, *prev;
 
 	h = &htab[hash(sym->name)];
-
 	for (prev = p = *h; p; prev = p, p = p->hash) {
 		if (p->ctx <= sym->ctx)
 			break;
@@ -214,6 +212,7 @@
 
 	if (sym->ns != NS_CPP)
 		sym->id = newid();
+	sym->flags |= ISDECLARED;
 	return linksym(sym);
 }
 
@@ -220,10 +219,7 @@
 Symbol *
 newsym(int ns)
 {
-	Symbol *sym;
-
-	sym = linksym(allocsym(ns, NULL));
-	return sym;
+	return linksym(allocsym(ns, NULL));
 }
 
 Symbol *
@@ -251,15 +247,6 @@
 			return sym;
 	}
 	return allocsym(ns, name);
-}
-
-void
-delmacro(Symbol *sym)
-{
-	unlinkhash(sym);
-	free(sym->name);
-	free(sym->u.s);
-	free(sym);
 }
 
 Symbol *