# HG changeset patch # User kono # Date 1397125624 -32400 # Node ID 60451f9e0c6e563efe75e550fc2f2b3fcb6fb171 # Parent af6f9373ce640b97a0f3dcc398368db3a13fc7d7 stringfy and concat bad interaction fix. diff -r af6f9373ce64 -r 60451f9e0c6e mc-macro.c --- a/mc-macro.c Thu Apr 10 12:04:39 2014 +0900 +++ b/mc-macro.c Thu Apr 10 19:27:04 2014 +0900 @@ -107,10 +107,10 @@ // remove \s**##\s* // it is difficult to remove former space on the fly, // so multi path loop is required - + int before=0; while (mconcat) { // ## re-eval macro - if (lsrc) printf("## before %s",macropp); + if (lsrc) { printf("## before %s\n",macropp); before=1; } mconcat = 0; macrop = 0; for(s=t=macropp;*s;) { @@ -144,6 +144,7 @@ } cheap = reset_cheap(&scheap); // genrated macro will be overwrited by cheap, but it's OK, again + if (before && lsrc) printf("## after %s\n",macropp); mconcat = 0; set_lfree(slfree); #if 0 @@ -778,7 +779,7 @@ int args = glist3s(STRING,0,cheap->ptr); body = (char **)&scaddr(args); for(;;) { - *cheap->ptr = c = *chptr++; + *cheap->ptr = c = *chptr++; cheap = increment_cheap(cheap,body); if (c=='\\') { if (*chptr=='\n') { @@ -991,7 +992,7 @@ prev_concat = 1; // name concatenation. flag only. remove and re-evaluate // in the top level. (and skip space) - } else if (!mconcat && c=='#' && alpha(*body)) { + } else if (!prev_concat && c=='#' && alpha(*body)) { // turn into string next macro literal string_flag = 1; string_mark(expand); @@ -1046,11 +1047,9 @@ default: if (prev_concat) { prev_concat = 0; - // macro = nptrm->u.nm; macro = nptrm->nm; } else if (next_concat(c,body)) { prev_concat = 1; - // macro = nptrm->u.nm; macro = nptrm->nm; } if (macro==0 || !macro[0]) diff -r af6f9373ce64 -r 60451f9e0c6e test/macro.c --- a/test/macro.c Thu Apr 10 12:04:39 2014 +0900 +++ b/test/macro.c Thu Apr 10 19:27:04 2014 +0900 @@ -66,7 +66,7 @@ #define aho000(a) (a*a) /* hoge comment */ - +#define stringify(x) (#x) int main() { @@ -107,6 +107,7 @@ printf("#0104:%d\n",names(3,hoge)); printf("#0105:%d\n",hoge000(3)); printf("#0106:%d\n",names1(4,aho)); + printf("#0107:%s\n",stringify(aho)); f(); return 0; }