diff options
| author | Ramsay Jones <ramsay@ramsayjones.plus.com> | 2018-11-19 20:51:33 +0000 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-11-24 18:29:01 +0100 |
| commit | 5607ba28a4e67dd549cd2b7420f4bbe251d85a88 (patch) | |
| tree | b0680e82919e982f88c30c72e0569531d1a71d16 /pre-process.c | |
| parent | ea3b2526d48aba9e5f3d30e1ce6e81cb12e9cacc (diff) | |
| download | sparse-dev-5607ba28a4e67dd549cd2b7420f4bbe251d85a88.tar.gz | |
pre-process: print variable argument macros correctly
The dump_macros() function fails to correctly output the definition of
macros that have a variable argument list. For example, the following
macros:
#define unlocks(...) annotate(unlock_func(__VA_ARGS__))
#define apply(x,...) x(__VA_ARGS__)
are output like so:
#define unlocks(__VA_ARGS__) annotate(unlock_func(__VA_ARGS__))
#define apply(x,__VA_ARGS__) x(__VA_ARGS__)
Add the code necessary to print the ellipsis in the argument list to the
dump_macros() function and add the above macros to the 'dump-macros.c'
test file.
Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'pre-process.c')
| -rw-r--r-- | pre-process.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/pre-process.c b/pre-process.c index a258da68..f0a9cf24 100644 --- a/pre-process.c +++ b/pre-process.c @@ -2167,6 +2167,12 @@ struct token * preprocess(struct token *token) return token; } +static int is_VA_ARGS_token(struct token *token) +{ + return (token_type(token) == TOKEN_IDENT) && + (token->ident == &__VA_ARGS___ident); +} + static void dump_macro(struct symbol *sym) { int nargs = sym->arglist ? sym->arglist->count.normal : 0; @@ -2182,7 +2188,10 @@ static void dump_macro(struct symbol *sym) for (; !eof_token(token); token = token->next) { if (token_type(token) == TOKEN_ARG_COUNT) continue; - printf("%s%s", sep, show_token(token)); + if (is_VA_ARGS_token(token)) + printf("%s...", sep); + else + printf("%s%s", sep, show_token(token)); args[narg++] = token; sep = ","; } |
