shithub: scc

Download patch

ref: c3bb2c04976c4e4ff610aec7b593c192e55a84b2
parent: 0a859705bf32bb1462671e03b2b8e932f3d287e4
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Apr 5 13:40:34 EDT 2022

cc1: Simplify icpp()

It is possible to use a single array to define all the predefined
macros instead of splitting between values or not valued macros.

--- a/src/cmd/cc/cc1/cpp.c
+++ b/src/cmd/cc/cc1/cpp.c
@@ -45,14 +45,22 @@
 void
 icpp(void)
 {
-	static char sdate[14], stime[11];
 	struct tm *tm;
 	time_t t;
-	static char **bp, *list[] = {
-		"__STDC__",
-		"__STDC_HOSTED__",
-		"__SCC__",
-		NULL
+	static char sdate[14], stime[11];
+	static struct {
+		char *name;
+		char *value;
+	} *bp, list[] = {
+		{"__STDC__", "1"},
+		{"__STDC_HOSTED__", "1"},
+		{"__SCC__", "1"},
+		{"__DATE__", sdate},
+		{"__TIME__", stime},
+		{"__STDC_VERSION__", STDC_VERSION},
+		{"__LINE__", NULL},
+		{"__FILE__", NULL},
+		{NULL, NULL}
 	};
 
 	t = time(NULL);
@@ -59,17 +67,12 @@
 	tm = localtime(&t);
 	strftime(sdate, sizeof(sdate), "\"%b %d %Y\"", tm);
 	strftime(stime, sizeof(stime), "\"%H:%M:%S\"", tm);
-	defdefine("__DATE__", sdate, "built-in");
-	defdefine("__TIME__", stime, "built-in");
-	defdefine("__STDC_VERSION__", STDC_VERSION, "built-in");
-	defdefine("__LINE__", NULL, "built-in");
-	defdefine("__FILE__", NULL, "built-in");
 
+	for (bp = list; bp->name; ++bp)
+		defdefine(bp->name, bp->value, "built-in");
+
 	symline = lookup(NS_CPP, "__LINE__", ALLOC);
 	symfile = lookup(NS_CPP, "__FILE__", ALLOC);
-
-	for (bp = list; *bp; ++bp)
-		defdefine(*bp, "1", "built-in");
 
 	ncmdlines = 0;
 }