From f1650c42d950400b41be53af2da1ad9867642df4 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Mon, 7 Apr 2014 06:00:04 -0400 Subject: [PATCH] Match C's preprocessor semantics for token pasting with '##'. --- ftepp.c | 12 +++++++++++- tests/pmacros.qc | 2 +- tests/ppcat.qc | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ftepp.c b/ftepp.c index 44c1ebb..c574f03 100644 --- a/ftepp.c +++ b/ftepp.c @@ -763,6 +763,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param lex_file *inlex; bool old_inmacro; + bool strip = false; int nextok; @@ -827,6 +828,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param if (nextok == '#') { /* raw concatenation */ ++o; + strip = true; break; } if ( (nextok == TOKEN_IDENT || @@ -835,6 +837,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param macro_params_find(macro, macro->output[o+1]->value, &pi)) { ++o; + ftepp_stringify(ftepp, ¶ms[pi]); break; } @@ -845,7 +848,14 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param ftepp_out(ftepp, "\n", false); break; default: - ftepp_out(ftepp, out->value, false); + buffer = out->value; + if (vec_size(macro->output) > o + 1 && macro->output[o+1]->token == '#') + buffer++; + if (strip) { + while (util_isspace(*buffer)) buffer++; + strip = false; + } + ftepp_out(ftepp, buffer, false); break; } } diff --git a/tests/pmacros.qc b/tests/pmacros.qc index 1ec0780..9bac539 100644 --- a/tests/pmacros.qc +++ b/tests/pmacros.qc @@ -26,7 +26,7 @@ # define ALPHA(SEL) ALPHA_##SEL -# define ABC ALPHA(a)##ALPHA(b)##ALPHA(c) +# define ABC ALPHA(a)ALPHA(b)ALPHA(c) void() main = { if (ABC == "abc") diff --git a/tests/ppcat.qc b/tests/ppcat.qc index ca92060..dc28269 100644 --- a/tests/ppcat.qc +++ b/tests/ppcat.qc @@ -8,6 +8,6 @@ REDIR(CAT(hello, world), CAT(world, hello)) SCONS(hello, world) #define FOO(X) X##X -#define BAR(X) FOO(X)##FOO(X) +#define BAR(X) FOO(X)FOO(X) -REDIR(BAR(hello), BAR(world)) +REDIR(BAR(hello),BAR(world)) -- 2.39.2