shithub: scc

Download patch

ref: b206061137fe1f86fd9669679e055bc826816f99
parent: c30fd72ab5feaa2e1326dbed4feb7ffc581d937e
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon May 25 12:50:05 EDT 2015

Implement #undef

Undef only undefined an already defined macro.

--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -460,8 +460,18 @@
 		error("#else without #if");
 	cleanup(s);
 	cppoff += (ifstatus[numif-1] ^= 1) ? -1 : 1;
+}
 
-	return;
+static void
+undef(char *s)
+{
+	Symbol *sym;
+
+	if (!iden(&s))
+		error("#undef must have an identifier as parameter");
+	sym = lookup(NS_CPP);
+	sym->flags &= ~ISDEFINED;
+	cleanup(s);
 }
 
 bool
@@ -477,6 +487,7 @@
 		"ifndef", ifndef,
 		"endif", endif,
 		"else", elseclause,
+		"undef", undef,
 		"line", line,
 		"pragma", pragma,
 		"error", usererr,