fix self-referential token pasting
This commit is contained in:
16
tccpp.c
16
tccpp.c
@ -2788,7 +2788,7 @@ static inline int *macro_twosharps(const int *macro_str)
|
|||||||
CValue cval;
|
CValue cval;
|
||||||
TokenString macro_str1;
|
TokenString macro_str1;
|
||||||
CString cstr;
|
CString cstr;
|
||||||
int n;
|
int n, start_of_nosubsts;
|
||||||
|
|
||||||
/* we search the first '##' */
|
/* we search the first '##' */
|
||||||
for(ptr = macro_str;;) {
|
for(ptr = macro_str;;) {
|
||||||
@ -2801,6 +2801,7 @@ static inline int *macro_twosharps(const int *macro_str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* we saw '##', so we need more processing to handle it */
|
/* we saw '##', so we need more processing to handle it */
|
||||||
|
start_of_nosubsts = -1;
|
||||||
tok_str_new(¯o_str1);
|
tok_str_new(¯o_str1);
|
||||||
for(ptr = macro_str;;) {
|
for(ptr = macro_str;;) {
|
||||||
TOK_GET(&tok, &ptr, &tokc);
|
TOK_GET(&tok, &ptr, &tokc);
|
||||||
@ -2808,8 +2809,17 @@ static inline int *macro_twosharps(const int *macro_str)
|
|||||||
break;
|
break;
|
||||||
if (tok == TOK_TWOSHARPS)
|
if (tok == TOK_TWOSHARPS)
|
||||||
continue;
|
continue;
|
||||||
|
if (tok == TOK_NOSUBST && start_of_nosubsts < 0)
|
||||||
|
start_of_nosubsts = macro_str1.len;
|
||||||
while (*ptr == TOK_TWOSHARPS) {
|
while (*ptr == TOK_TWOSHARPS) {
|
||||||
do { t = *++ptr; } while (t == TOK_NOSUBST);
|
/* given 'a##b', remove nosubsts preceding 'a' */
|
||||||
|
if (start_of_nosubsts >= 0)
|
||||||
|
macro_str1.len = start_of_nosubsts;
|
||||||
|
/* given 'a##b', skip '##' */
|
||||||
|
t = *++ptr;
|
||||||
|
/* given 'a##b', remove nosubsts preceding 'b' */
|
||||||
|
while (t == TOK_NOSUBST)
|
||||||
|
t = *++ptr;
|
||||||
|
|
||||||
if (t && t != TOK_TWOSHARPS) {
|
if (t && t != TOK_TWOSHARPS) {
|
||||||
TOK_GET(&t, &ptr, &cval);
|
TOK_GET(&t, &ptr, &cval);
|
||||||
@ -2835,6 +2845,8 @@ static inline int *macro_twosharps(const int *macro_str)
|
|||||||
cstr_reset(&cstr);
|
cstr_reset(&cstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (tok != TOK_NOSUBST)
|
||||||
|
start_of_nosubsts = -1;
|
||||||
tok_str_add2(¯o_str1, tok, &tokc);
|
tok_str_add2(¯o_str1, tok, &tokc);
|
||||||
}
|
}
|
||||||
tok_str_add(¯o_str1, 0);
|
tok_str_add(¯o_str1, 0);
|
||||||
|
|||||||
@ -103,6 +103,10 @@ int isid(int c);
|
|||||||
#define HIGHLOW "hello"
|
#define HIGHLOW "hello"
|
||||||
#define LOW LOW ", world"
|
#define LOW LOW ", world"
|
||||||
|
|
||||||
|
static int onetwothree = 123;
|
||||||
|
#define onetwothree4 onetwothree
|
||||||
|
#define onetwothree xglue(onetwothree,4)
|
||||||
|
|
||||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
|
||||||
#ifdef C99_MACROS
|
#ifdef C99_MACROS
|
||||||
@ -155,6 +159,8 @@ void macro_test(void)
|
|||||||
printf("s4=%s\n", str(a1));
|
printf("s4=%s\n", str(a1));
|
||||||
printf("B3=%d\n", B3);
|
printf("B3=%d\n", B3);
|
||||||
|
|
||||||
|
printf("onetwothree=%d\n", onetwothree);
|
||||||
|
|
||||||
#ifdef A
|
#ifdef A
|
||||||
printf("A defined\n");
|
printf("A defined\n");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user