scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit c3bb2c04976c4e4ff610aec7b593c192e55a84b2
parent 0a859705bf32bb1462671e03b2b8e932f3d287e4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  5 Apr 2022 17:40:34 +0200

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.

Diffstat:
Msrc/cmd/cc/cc1/cpp.c | 31+++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/cmd/cc/cc1/cpp.c b/src/cmd/cc/cc1/cpp.c @@ -45,32 +45,35 @@ undefmacro(char *s) 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); 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; }