History

pp: simplify pasting, enable L ## number

grischka committed 17 years ago

Commit fcdb6631 parent 045cff21 file · +26 −88Browse files

Unified · Split

tccpp.c+26−88
@@ -2598,13 +2598,13 @@ static int macro_subst_tok(TokenString *tok_str, · 2597 unmodified lines
25982598 return the resulting string (which must be freed). */
25992599 static inline int *macro_twosharps(const int *macro_str)
26002600 {
2601− TokenSym *ts;
2602− const int *ptr, *saved_macro_ptr;
2601+ const int *ptr;
26032602 int t;
2604− const char *p1, *p2;
26052603 CValue cval;
26062604 TokenString macro_str1;
26072605 CString cstr;
2606+ char *p;
2607+ int n;
26082608
26092609 /* we search the first '##' */
26102610 for(ptr = macro_str;;) {
@@ -2617,104 +2617,42 @@ static inline int *macro_twosharps(const int *macro_str) · 6 unmodified lines
26172617 }
26182618
26192619 /* we saw '##', so we need more processing to handle it */
2620− cstr_new(&cstr);
26212620 tok_str_new(&macro_str1);
2622− saved_macro_ptr = macro_ptr;
2623− /* XXX: get rid of the use of macro_ptr here */
2624− macro_ptr = (int *)macro_str;
2625− for(;;) {
2626− next_nomacro_spc();
2621+ for(ptr = macro_str;;) {
2622+ TOK_GET(tok, ptr, tokc);
26272623 if (tok == 0)
26282624 break;
26292625 if (tok == TOK_TWOSHARPS)
26302626 continue;
2631− while (*macro_ptr == TOK_TWOSHARPS) {
2632− t = *++macro_ptr;
2627+ while (*ptr == TOK_TWOSHARPS) {
2628+ t = *++ptr;
26332629 if (t && t != TOK_TWOSHARPS) {
2634− TOK_GET(t, macro_ptr, cval);
2635− /* We concatenate the two tokens if we have an
2636− identifier or a preprocessing number */
2637− cstr_reset(&cstr);
2638− p1 = get_tok_str(tok, &tokc);
2639− cstr_cat(&cstr, p1);
2640− p2 = get_tok_str(t, &cval);
2641− cstr_cat(&cstr, p2);
2630+ TOK_GET(t, ptr, cval);
2631+
2632+ /* We concatenate the two tokens */
2633+ cstr_new(&cstr);
2634+ cstr_cat(&cstr, get_tok_str(tok, &tokc));
2635+ n = cstr.size;
2636+ cstr_cat(&cstr, get_tok_str(t, &cval));
26422637 cstr_ccat(&cstr, '\0');
26432638
2644− if ((tok >= TOK_IDENT || tok == TOK_PPNUM) &&
2645− (t >= TOK_IDENT || t == TOK_PPNUM)) {
2646− if (tok == TOK_PPNUM) {
2647− /* if number, then create a number token */
2648− /* NOTE: no need to allocate because
2649− tok_str_add2() does it */
2650− cstr_reset(&tokcstr);
2651− tokcstr = cstr;
2652− cstr_new(&cstr);
2653− tokc.cstr = &tokcstr;
2654− } else {
2655− /* if identifier, we must do a test to
2656− validate we have a correct identifier */
2657− if (t == TOK_PPNUM) {
2658− const char *p;
2659− int c;
2660−
2661− p = p2;
2662− for(;;) {
2663− c = *p;
2664− if (c == '\0')
2665− break;
2666− p++;
2667− if (!isnum(c) && !isid(c))
2668− goto error_pasting;
2669− }
2670− }
2671− ts = tok_alloc(cstr.data, strlen(cstr.data));
2672− tok = ts->tok; /* modify current token */
2673− }
2674− } else {
2675− const char *str = cstr.data;
2676− const unsigned char *q;
2677−
2678− /* we look for a valid token */
2679− /* XXX: do more extensive checks */
2680− if (!strcmp(str, ">>=")) {
2681− tok = TOK_A_SAR;
2682− } else if (!strcmp(str, "<<=")) {
2683− tok = TOK_A_SHL;
2684− } else if (strlen(str) == 2) {
2685− /* search in two bytes table */
2686− q = tok_two_chars;
2687− for(;;) {
2688− if (!*q)
2689− goto error_pasting;
2690− if (q[0] == str[0] && q[1] == str[1])
2691− break;
2692− q += 3;
2693− }
2694− tok = q[2];
2695− } else {
2696− error_pasting:
2697− /* NOTE: because get_tok_str use a static buffer,
2698− we must save it */
2699− cstr_reset(&cstr);
2700− p1 = get_tok_str(tok, &tokc);
2701− cstr_cat(&cstr, p1);
2702− cstr_ccat(&cstr, '\0');
2703− p2 = get_tok_str(t, &cval);
2704− warning("pasting \"%s\" and \"%s\" does not give a valid preprocessing token", cstr.data, p2);
2705− /* cannot merge tokens: just add them separately */
2706− tok_str_add2(&macro_str1, tok, &tokc);
2707− /* XXX: free associated memory ? */
2708− tok = t;
2709− tokc = cval;
2710− }
2639+ p = file->buf_ptr;
2640+ file->buf_ptr = cstr.data;
2641+ for (;;) {
2642+ next_nomacro1();
2643+ if (0 == *file->buf_ptr)
2644+ break;
2645+ tok_str_add2(&macro_str1, tok, &tokc);
2646+
2647+ warning("pasting \"%.*s\" and \"%s\" does not give a valid preprocessing token",
2648+ n, cstr.data, (char*)cstr.data + n);
27112649 }
2650+ file->buf_ptr = p;
2651+ cstr_reset(&cstr);
27122652 }
27132653 }
27142654 tok_str_add2(&macro_str1, tok, &tokc);
27152655 }
2716− macro_ptr = (int *)saved_macro_ptr;
2717− cstr_free(&cstr);
27182656 tok_str_add(&macro_str1, 0);
27192657 return macro_str1.str;
27202658 }

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