diff options
| author | 2026-04-14 12:05:57 +0200 | |
|---|---|---|
| committer | 2026-04-14 12:14:51 +0200 | |
| commit | 98222b7c0506b0a9833230177b939f8c25046b31 (patch) | |
| tree | f2330b72c7288437a864c30601512e41da051a12 | |
| parent | cd44dafedb6e69c7cca218fd33c1530a48b3e3d1 (diff) | |
cpp: concat 123 ## .
| -rw-r--r-- | src/c.c | 3 | ||||
| -rw-r--r-- | src/c_lex.c | 20 | ||||
| -rw-r--r-- | test/07-pp.c | 4 |
3 files changed, 21 insertions, 6 deletions
@@ -163,7 +163,8 @@ isexprtok(CComp *cm) #define tk(x) [x] = 1 tk('+'), tk('-'), tk('*'), tk('&'), tk('~'), tk('!'), tk(TKINC), tk(TKDEC), tk(TKWsizeof), tk(TKW_Alignof), tk(TKWalignof), tk(TKWtrue), tk(TKWfalse), - tk('('), tk(TKNUMLIT), tk(TKCHRLIT), tk(TKSTRLIT), tk(TKW_Generic) + tk('('), tk(TKNUMLIT), tk(TKCHRLIT), tk(TKSTRLIT), tk(TKW_Generic), + tk(TKW__builtin_va_arg), #undef tk }; return tk.t < countof(tks) && tks[tk.t]; diff --git a/src/c_lex.c b/src/c_lex.c index c5e16aa..6370a1c 100644 --- a/src/c_lex.c +++ b/src/c_lex.c @@ -819,6 +819,12 @@ tokpaste(Lexer *lx, Token *dst, const Token *l, const Token *r) } else if (l->t == TKNUMLIT && (isppident(*r) || r->t == TKNUMLIT)) { /* 0x ## abc ; 213 ## 456 */ t = TKNUMLIT; + } else if (l->t == '.' && r->t == TKNUMLIT) { + /* . ## 123 */ + t = TKNUMLIT; + } else if (l->t == TKNUMLIT && r->t == '.') { + /* 123 ## . */ + t = TKNUMLIT; } else if (l->t && !r->t) { if (dst) *dst = *l; return 1; @@ -855,10 +861,18 @@ tokpaste(Lexer *lx, Token *dst, const Token *l, const Token *r) if (dst->span.ex.file == r->span.ex.file && dst->span.ex.off < r->span.ex.off) joinspan(&dst->span.ex, r->span.ex); dst->t = t; - dst->len = l->len + r->len; + + int n1, n2; + const char *s1, *s2; + if (l->t == '.') n1 = 1, s1 = "."; + else n1 = l->len, s1 = l->s; + if (r->t == '.') n2 = 1, s2 = "."; + else n2 = r->len, s2 = r->s; + + dst->len = n1 + n2; char *s = (isppident(*dst) && dst->len + 1 < sizeof buf) ? buf : alloc(lx->tmparena, dst->len + 1, 1); - memcpy(s, l->s, l->len); - memcpy(s + l->len, r->s, r->len); + memcpy(s, s1, n1); + memcpy(s + n1, s2, n2); s[dst->len] = 0; dst->space = l->space; if (isppident(*dst)) { diff --git a/test/07-pp.c b/test/07-pp.c index 4301dbd..7370413 100644 --- a/test/07-pp.c +++ b/test/07-pp.c @@ -14,7 +14,7 @@ token spacing: sum = 1 + 2 +3;$ [ baz] ;$ +. *$ -x=7 +x=7 7 */ #include "07-pp.h" @@ -138,7 +138,7 @@ qx2(*) ) "$\n" 3 #endif ); - printf("x=%d\n",x); + printf("x=%d %g\n",x, CAT(7,.)); CAT(ret,urn) 0; } |