From 6b4f352810b3cbdcf7f16c88998ffbebbc9f24a0 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 15 May 2017 21:46:24 -0700 Subject: 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 directives, that is added. Nesting is supported. We group the symbols according to their controlling preprocessor symbol lists. --- genprotsym.txr | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'genprotsym.txr') 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) -- cgit v1.2.3