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
32193219 static int paste_tokens(int t1, CValue *v1, int t2, CValue *v2)
32203220 {
32213221 CString cstr;
3222− int n;
3222+ int n, ret = 1;
32233223
32243224 cstr_new(&cstr);
32253225 if (t1 != TOK_PLCHLDR)
@@ -3237,15 +3237,15 @@ static int paste_tokens(int t1, CValue *v1, int t2, CValue *v2) · 11 unmodified lines
32373237 break;
32383238 if (is_space(tok))
32393239 continue;
3240− tcc_warning("pasting <%.*s> and <%s> does not give a valid preprocessing token",
3241− n, cstr.data, (char*)cstr.data + n);
3240+ tcc_warning("pasting \"%.*s\" and \"%s\" does not give a valid"
3241+ " preprocessing token", n, cstr.data, (char*)cstr.data + n);
3242+ ret = 0;
32423243 break;
32433244 }
32443245 tcc_close();
3245−
32463246 //printf("paste <%s>\n", (char*)cstr.data);
32473247 cstr_free(&cstr);
3248− return 0;
3248+ return ret;
32493249 }
32503250
32513251 /* handle the '##' operator. Return NULL if no '##' seen. Otherwise
@@ -3284,13 +3284,15 @@ static inline int *macro_twosharps(const int *ptr0) · 32 unmodified lines
32843284 /* given 'a##b', remove nosubsts preceding 'b' */
32853285 while ((t1 = *++ptr) == TOK_NOSUBST)
32863286 ;
3287− if (t1 && t1 != TOK_TWOSHARPS
3288− && t1 != ':') /* 'a##:' don't build a new token */
3289− {
3287+ if (t1 && t1 != TOK_TWOSHARPS) {
32903288 TOK_GET(&t1, &ptr, &cv1);
32913289 if (t != TOK_PLCHLDR || t1 != TOK_PLCHLDR) {
3292− paste_tokens(t, &cval, t1, &cv1);
3293− t = tok, cval = tokc;
3290+ if (paste_tokens(t, &cval, t1, &cv1)) {
3291+ t = tok, cval = tokc;
3292+ } else {
3293+ tok_str_add2(&macro_str1, t, &cval);
3294+ t = t1, cval = cv1;
3295+ }
32943296 }
32953297 }
32963298 }

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