diff options
author | Ori Bernstein <ori@eigenstate.org> | 2020-03-17 22:03:25 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2020-03-17 22:03:25 -0700 |
commit | 37b86df09ff381bcc4f60802d43e57bd9bfcac73 (patch) | |
tree | 76065637ec0ea0d646ec783c00a156f9702968c7 /sys/src/cmd/cpp/cpp.c | |
parent | 52dc943702a8f7815546e76286b153c3813e1db0 (diff) |
Improve the posix preprocessor.
This fixes token pasting, making it expand when
it should expand, and paste before expansion when
it should paste before expanding.
#define CAT(a, b) a ## b
#define BAR 3
#define FOO CAT(BAR, 3)
FOO
now produces 33, while
#define CAT(a, b) a ## b
#define EOF (-1)
#define NOP(x) x
NOP(CAT(foo, EOF))
CAT(,EOF)
CAT(,)
produces
fooEOF
(-1)
<empty>
respectively.
Diffstat (limited to 'sys/src/cmd/cpp/cpp.c')
-rw-r--r-- | sys/src/cmd/cpp/cpp.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/sys/src/cmd/cpp/cpp.c b/sys/src/cmd/cpp/cpp.c index c7b6146bb..2a49ea8bc 100644 --- a/sys/src/cmd/cpp/cpp.c +++ b/sys/src/cmd/cpp/cpp.c @@ -68,7 +68,7 @@ process(Tokenrow *trp) trp->tp += 1; control(trp); } else if (!skipping && anymacros) - expandrow(trp, NULL, Notinmacro); + expandrow(trp, NULL); if (skipping) setempty(trp); puttokens(trp); @@ -217,7 +217,7 @@ control(Tokenrow *trp) case KLINE: trp->tp = tp+1; - expandrow(trp, "<line>", Notinmacro); + expandrow(trp, "<line>"); tp = trp->bp+2; kline: if (tp+1>=trp->lp || tp->type!=NUMBER || tp+3<trp->lp |