ref: c6f7989176b9da3b977f397ac4f20bc2f86dec1b
parent: 8ebe958ddf4b81df3ecf9b26c4333b2dca1cc987
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Apr 26 05:32:42 EDT 2020
copy all the tokens from the tokenrows with a paste. if we do 'CAT(foo bar, baz quux)', the resulting token row should have 3 tokens: 'foo', 'barbaz', 'quux'. tested by jonasa, rebuilding /sys/src, perl, netsurf, and nuklear.
--- a/sys/src/cmd/cpp/macro.c
+++ b/sys/src/cmd/cpp/macro.c
@@ -350,7 +350,7 @@
void
substargs(Nlist *np, Tokenrow *rtr, Tokenrow **atr)
{
- Tokenrow ttr;
+ Tokenrow ttr, rp, rn;
Token *tp, *ap, *an, *pp, *pn;
int ntok, argno, hs;
@@ -369,19 +369,25 @@
insertrow(rtr, ntok, stringify(atr[argno]));
} else if (ispaste(rtr, &ap, &an, &ntok)) { /* first token, just do the next one */
pp = ap;
+ memset(&rp, 0, sizeof(rp));
pn = an;
+ memset(&rn, 0, sizeof(rp));
if (ap && (argno = lookuparg(np, ap)) >= 0){
pp = nil;
- if(atr[argno]->tp != atr[argno]->lp)
- pp = atr[argno]->lp - 1;
+ rp = *atr[argno];
+ if(rp.tp != rp.lp)
+ pp = --rp.lp;
}
if (an && (argno = lookuparg(np, an)) >= 0) {
pn = nil;
- if(atr[argno]->tp != atr[argno]->lp)
- pn = atr[argno]->lp - 1;
+ rn = *atr[argno];
+ if(rn.tp != rn.lp)
+ pn = rn.bp++;
}
glue(&ttr, pp, pn);
+ insertrow(rtr, 0, &rp);
insertrow(rtr, ntok, &ttr);
+ insertrow(rtr, 0, &rn);
free(ttr.bp);
} else if (rtr->tp->type==NAME) {
if((argno = lookuparg(np, rtr->tp)) >= 0) {
--- a/sys/src/cmd/cpp/test.c
+++ b/sys/src/cmd/cpp/test.c
@@ -21,6 +21,9 @@
#define FOO CAT(BAR, 3)
FOO
+/* Expected: a bc d */
+CAT(a b, c d)
+
/*
* CURRENTLY BROKEN:
* __VA_ARGS__ requires at least one item.
@@ -58,4 +61,4 @@
* It should treat no args as a single empty arg list.
p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
char c[2][6] = { str(hello), str() };
-*/
\ No newline at end of file
+*/