summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-15 21:46:24 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-15 21:46:24 -0700
commit6b4f352810b3cbdcf7f16c88998ffbebbc9f24a0 (patch)
treedd151c3e0b30644312f2145a112a43ebc1ff7e82
parent692c82523abcc55709dcbc785578826b70597189 (diff)
downloadtxr-6b4f352810b3cbdcf7f16c88998ffbebbc9f24a0.tar.gz
txr-6b4f352810b3cbdcf7f16c88998ffbebbc9f24a0.tar.bz2
txr-6b4f352810b3cbdcf7f16c88998ffbebbc9f24a0.zip
protsym: further refinement.
In sysif.c, we have conditionally defined symbol variables. This has to be reflected with #if directivec in protsym.c. * genprotsym.txr: Associate each symbol with a list of preprocessor symbols which controls it, via a hash. All symbols coming from a conditional file are tagged with a list which includes at least the controlling symbol. If symbols are wrapped with #if <sym> directives, that is added. Nesting is supported. We group the symbols according to their controlling preprocessor symbol lists.
-rw-r--r--genprotsym.txr26
1 files changed, 19 insertions, 7 deletions
diff --git a/genprotsym.txr b/genprotsym.txr
index b343ce04..0a54946e 100644
--- a/genprotsym.txr
+++ b/genprotsym.txr
@@ -1,5 +1,5 @@
-@(bind prepro-sym @(hash :equal-based))
-@(bind file-of @(hash :equal-based))
+@(bind pp-sym-of-file @(hash :equal-based))
+@(bind pp-syms-of-sym @(hash :equal-based))
@(next "Makefile")
@(repeat)
@ (cases)
@@ -9,14 +9,26 @@ OBJS-$(have_@sym) += @file.o
OBJS-$(@sym) += @file.o
@ (bind ppsym @(upcase-str `CONFIG_@sym`))
@ (end)
-@ (do (set [prepro-sym `@file.c`] ppsym))
+@ (do (set [pp-sym-of-file `@file.c`] ppsym))
@(end)
@(next :list (glob "*.c"))
+@(bind pp-stack nil)
@(collect)
@file
@ (next file)
+@ (do (whenlet ((pp [pp-sym-of-file file]))
+ (set pp-stack (list pp))))
@ (collect :vars ((sym nil)))
-val @(coll)@{sym /[A-Za-z0-9_]+_[sk]/}@/[,;]/@(do (set [file-of sym] file))@(end)
+@ (cases)
+val @(coll)@{sym /[A-Za-z0-9_]+_[sk]/}@/[,;]/@\
+ @(do (set [pp-syms-of-sym sym] pp-stack))@(end)
+@ (or)
+#if @ppsym
+@ (do (push ppsym pp-stack))
+@ (or)
+#endif
+@ (do (pop pp-stack))
+@ (end)
@ (end)
@ (flatten sym)
@(end)
@@ -27,7 +39,7 @@ val @(coll)@{sym /[A-Za-z0-9_]+_[sk]/}@/[,;]/@(do (set [file-of sym] file))@(end
@(end)
@(flatten sym)
-@(bind pp-groups @[group-by [chain file-of prepro-sym] sym])
+@(bind pp-groups @[group-by pp-syms-of-sym sym])
@(bind gsym @[mapcar (opip sort (tuples 5)) (hash-values pp-groups)])
@(bind gpp @(hash-keys pp-groups))
@(output "protsym.c")
@@ -40,7 +52,7 @@ val @(coll)@{sym /[A-Za-z0-9_]+_[sk]/}@/[,;]/@(do (set [file-of sym] file))@(end
#include "lib.h"
@ (repeat :vars (gpp))
-@ (if gpp `#if @gpp`)
+@ (if gpp `#if @{gpp " && "}`)
@ (repeat)
extern val @(rep)@gsym, @(last)@gsym;@(end)
@ (end)
@@ -49,7 +61,7 @@ extern val @(rep)@gsym, @(last)@gsym;@(end)
val *protected_sym[] = {
@ (repeat :vars (gpp))
-@ (if gpp `#if @gpp`)
+@ (if gpp `#if @{gpp " && "}`)
@ (repeat)
@(rep)&@gsym, @(last)&@gsym,@(end)
@ (end)