commit 23e5d28bcfafb191be14957906a01453dd911353
parent badf250751e7443df7f671a7cf29a9151d04ca91
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 14 Jun 2016 12:31:06 +0200
[cc1] Add support for -U in cc1
POSIX indicates that -U remove any definition of a macro,
and it means that we have to parse -U options after having
initialized the preprocessor and having parsed -D options.
Diffstat:
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/cc1/cc1.h b/cc1/cc1.h
@@ -4,6 +4,8 @@
#define GLOBALCTX 0
+#define NR_USWITCHES 20
+
/*
* Definition of enumerations
*/
@@ -417,6 +419,7 @@ extern int expand(char *begin, Symbol *sym);
extern void incdir(char *dir);
extern void outcpp(void);
extern Symbol *defmacro(char *s);
+extern void undefmacro(char *s);
/*
* Definition of global variables
diff --git a/cc1/cpp.c b/cc1/cpp.c
@@ -39,6 +39,12 @@ defmacro(char *s)
}
void
+undefmacro(char *s)
+{
+ killsym(lookup(NS_CPP, s));
+}
+
+void
icpp(void)
{
static char sdate[17], stime[14];
diff --git a/cc1/main.c b/cc1/main.c
@@ -38,8 +38,10 @@ int
main(int argc, char *argv[])
{
char *base;
+ static char *uvec[NR_USWITCHES], **umacro = uvec;
atexit(clean);
+ icpp();
ARGBEGIN {
case 'w':
@@ -51,6 +53,11 @@ main(int argc, char *argv[])
case 'D':
defmacro(EARGF(usage()));
break;
+ case 'U':
+ if (umacro == &uvec[NR_USWITCHES])
+ die("too many -U switches");
+ *umacro++ = EARGF(usage());
+ break;
case 'd':
DBGON();
break;
@@ -64,6 +71,9 @@ main(int argc, char *argv[])
usage();
} ARGEND
+ for (umacro = uvec; *umacro; umacro++)
+ undefmacro(*umacro);
+
if (argc > 1)
usage();
@@ -78,9 +88,7 @@ main(int argc, char *argv[])
if (output && !freopen(output, "w", stdout))
die("error opening output: %s", strerror(errno));
- icpp();
ilex(*argv);
-
if (onlycpp) {
outcpp();
} else {