aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/c.c3
-rw-r--r--src/c_lex.c20
-rw-r--r--test/07-pp.c4
3 files changed, 21 insertions, 6 deletions
diff --git a/src/c.c b/src/c.c
index 0ae12d9..2d51bd2 100644
--- a/src/c.c
+++ b/src/c.c
@@ -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;
}