History

tccpp: token ## pasting: preserve parts if pasting fails

for example #define LBL(name) _ ## name ## : LBL(main) will give two tokens '_main' and ':' and the warning

grischka committed 10 years ago

Commit 8afb8cc1 parent c5b9ae41 file · +12 −10Browse files

Unified · Split

tccpp.c+12−10
@@ -3219,7 +3219,7 @@ static int macro_subst_tok( · 3218 unmodified lines
3219static int paste_tokens(int t1, CValue *v1, int t2, CValue *v2)3219static int paste_tokens(int t1, CValue *v1, int t2, CValue *v2)
3220{3220{
3221 CString cstr;3221 CString cstr;
3222 int n;3222 int n, ret = 1;
3223 3223
3224 cstr_new(&cstr);3224 cstr_new(&cstr);
3225 if (t1 != TOK_PLCHLDR)3225 if (t1 != TOK_PLCHLDR)
@@ -3237,15 +3237,15 @@ static int paste_tokens(int t1, CValue *v1, int t2, CValue *v2) · 11 unmodified lines
3237 break;3237 break;
3238 if (is_space(tok))3238 if (is_space(tok))
3239 continue;3239 continue;
3240 tcc_warning("pasting <%.*s> and <%s> does not give a valid preprocessing token",3240 tcc_warning("pasting \"%.*s\" and \"%s\" does not give a valid"
3241 n, cstr.data, (char*)cstr.data + n);3241 " preprocessing token", n, cstr.data, (char*)cstr.data + n);
3242 ret = 0;
3242 break;3243 break;
3243 }3244 }
3244 tcc_close();3245 tcc_close();
3245
3246 //printf("paste <%s>\n", (char*)cstr.data);3246 //printf("paste <%s>\n", (char*)cstr.data);
3247 cstr_free(&cstr);3247 cstr_free(&cstr);
3248 return 0;3248 return ret;
3249}3249}
3250 3250
3251/* handle the '##' operator. Return NULL if no '##' seen. Otherwise3251/* handle the '##' operator. Return NULL if no '##' seen. Otherwise
@@ -3284,13 +3284,15 @@ static inline int *macro_twosharps(const int *ptr0) · 32 unmodified lines
3284 /* given 'a##b', remove nosubsts preceding 'b' */3284 /* given 'a##b', remove nosubsts preceding 'b' */
3285 while ((t1 = *++ptr) == TOK_NOSUBST)3285 while ((t1 = *++ptr) == TOK_NOSUBST)
3286 ;3286 ;
3287 if (t1 && t1 != TOK_TWOSHARPS 3287 if (t1 && t1 != TOK_TWOSHARPS) {
3288 && t1 != ':') /* 'a##:' don't build a new token */
3289 {
3290 TOK_GET(&t1, &ptr, &cv1);3288 TOK_GET(&t1, &ptr, &cv1);
3291 if (t != TOK_PLCHLDR || t1 != TOK_PLCHLDR) {3289 if (t != TOK_PLCHLDR || t1 != TOK_PLCHLDR) {
3292 paste_tokens(t, &cval, t1, &cv1);3290 if (paste_tokens(t, &cval, t1, &cv1)) {
3293 t = tok, cval = tokc;3291 t = tok, cval = tokc;
3292 } else {
3293 tok_str_add2(&macro_str1, t, &cval);
3294 t = t1, cval = cv1;
3295 }
3294 }3296 }
3295 }3297 }
3296 }3298 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t