diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-07-03 00:25:20 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-07-06 03:39:44 +0200 |
commit | 20b4c3c4ca21106acc4065b7c22b6cd98b4de0e9 (patch) | |
tree | 45f747e5b4a09f3cdf1f0d507c8168b56f0ddb36 | |
parent | 61f53e257de47e29fe3d6eec6d233552e8116cb4 (diff) | |
download | sparse-20b4c3c4ca21106acc4065b7c22b6cd98b4de0e9.tar.gz |
predefine: add helper predefine_{strong,weak}()
A lot of predefined macros are just set to the value '1' and
of them have a name that is not statically known. OTOH, the
function predefine() is designed for a statically known name
but a variable value.
Add a set of helpers to cover the first case: predefine_strong()
and predefine_weak().
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | lib.h | 2 | ||||
-rw-r--r-- | pre-process.c | 26 |
2 files changed, 28 insertions, 0 deletions
@@ -123,6 +123,8 @@ enum phase { extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1); extern void predefine(const char *name, int weak, const char *fmt, ...) FORMAT_ATTR(3); +extern void predefine_strong(const char *name, ...) FORMAT_ATTR(1); +extern void predefine_weak(const char *name, ...) FORMAT_ATTR(1); extern void predefine_nostd(const char *name); extern void predefined_macros(void); diff --git a/pre-process.c b/pre-process.c index 38167802..403e3507 100644 --- a/pre-process.c +++ b/pre-process.c @@ -1439,6 +1439,32 @@ void predefine_nostd(const char *name) predefine(name, 1, "1"); } +static void predefine_fmt(const char *fmt, int weak, va_list ap) +{ + static char buf[256]; + + vsnprintf(buf, sizeof(buf), fmt, ap); + predefine(buf, weak, "1"); +} + +void predefine_strong(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + predefine_fmt(fmt, 0, ap); + va_end(ap); +} + +void predefine_weak(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + predefine_fmt(fmt, 1, ap); + va_end(ap); +} + static int do_handle_define(struct stream *stream, struct token **line, struct token *token, int attr) { struct token *arglist, *expansion; |