Unified · Split
| @@ -2598,13 +2598,13 @@ static int macro_subst_tok(TokenString *tok_str, · 2597 unmodified lines | |||
| 2598 | return the resulting string (which must be freed). */ | 2598 | return the resulting string (which must be freed). */ |
| 2599 | static inline int *macro_twosharps(const int *macro_str) | 2599 | static inline int *macro_twosharps(const int *macro_str) |
| 2600 | { | 2600 | { |
| 2601 | TokenSym *ts; | 2601 | const int *ptr; |
| 2602 | const int *ptr, *saved_macro_ptr; | ||
| 2603 | int t; | 2602 | int t; |
| 2604 | const char *p1, *p2; | ||
| 2605 | CValue cval; | 2603 | CValue cval; |
| 2606 | TokenString macro_str1; | 2604 | TokenString macro_str1; |
| 2607 | CString cstr; | 2605 | CString cstr; |
| 2606 | char *p; | ||
| 2607 | int n; | ||
| 2608 | 2608 | ||
| 2609 | /* we search the first '##' */ | 2609 | /* we search the first '##' */ |
| 2610 | for(ptr = macro_str;;) { | 2610 | for(ptr = macro_str;;) { |
| @@ -2617,104 +2617,42 @@ static inline int *macro_twosharps(const int *macro_str) · 6 unmodified lines | |||
| 2617 | } | 2617 | } |
| 2618 | 2618 | ||
| 2619 | /* we saw '##', so we need more processing to handle it */ | 2619 | /* we saw '##', so we need more processing to handle it */ |
| 2620 | cstr_new(&cstr); | ||
| 2621 | tok_str_new(¯o_str1); | 2620 | tok_str_new(¯o_str1); |
| 2622 | saved_macro_ptr = macro_ptr; | 2621 | for(ptr = macro_str;;) { |
| 2623 | /* XXX: get rid of the use of macro_ptr here */ | 2622 | TOK_GET(tok, ptr, tokc); |
| 2624 | macro_ptr = (int *)macro_str; | ||
| 2625 | for(;;) { | ||
| 2626 | next_nomacro_spc(); | ||
| 2627 | if (tok == 0) | 2623 | if (tok == 0) |
| 2628 | break; | 2624 | break; |
| 2629 | if (tok == TOK_TWOSHARPS) | 2625 | if (tok == TOK_TWOSHARPS) |
| 2630 | continue; | 2626 | continue; |
| 2631 | while (*macro_ptr == TOK_TWOSHARPS) { | 2627 | while (*ptr == TOK_TWOSHARPS) { |
| 2632 | t = *++macro_ptr; | 2628 | t = *++ptr; |
| 2633 | if (t && t != TOK_TWOSHARPS) { | 2629 | if (t && t != TOK_TWOSHARPS) { |
| 2634 | TOK_GET(t, macro_ptr, cval); | 2630 | TOK_GET(t, ptr, cval); |
| 2635 | /* We concatenate the two tokens if we have an | 2631 | |
| 2636 | identifier or a preprocessing number */ | 2632 | /* We concatenate the two tokens */ |
| 2637 | cstr_reset(&cstr); | 2633 | cstr_new(&cstr); |
| 2638 | p1 = get_tok_str(tok, &tokc); | 2634 | cstr_cat(&cstr, get_tok_str(tok, &tokc)); |
| 2639 | cstr_cat(&cstr, p1); | 2635 | n = cstr.size; |
| 2640 | p2 = get_tok_str(t, &cval); | 2636 | cstr_cat(&cstr, get_tok_str(t, &cval)); |
| 2641 | cstr_cat(&cstr, p2); | ||
| 2642 | cstr_ccat(&cstr, '\0'); | 2637 | cstr_ccat(&cstr, '\0'); |
| 2643 | 2638 | ||
| 2644 | if ((tok >= TOK_IDENT || tok == TOK_PPNUM) && | 2639 | p = file->buf_ptr; |
| 2645 | (t >= TOK_IDENT || t == TOK_PPNUM)) { | 2640 | file->buf_ptr = cstr.data; |
| 2646 | if (tok == TOK_PPNUM) { | 2641 | for (;;) { |
| 2647 | /* if number, then create a number token */ | 2642 | next_nomacro1(); |
| 2648 | /* NOTE: no need to allocate because | 2643 | if (0 == *file->buf_ptr) |
| 2649 | tok_str_add2() does it */ | 2644 | break; |
| 2650 | cstr_reset(&tokcstr); | 2645 | tok_str_add2(¯o_str1, tok, &tokc); |
| 2651 | tokcstr = cstr; | 2646 | |
| 2652 | cstr_new(&cstr); | 2647 | warning("pasting \"%.*s\" and \"%s\" does not give a valid preprocessing token", |
| 2653 | tokc.cstr = &tokcstr; | 2648 | n, cstr.data, (char*)cstr.data + n); |
| 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(¯o_str1, tok, &tokc); | ||
| 2707 | /* XXX: free associated memory ? */ | ||
| 2708 | tok = t; | ||
| 2709 | tokc = cval; | ||
| 2710 | } | ||
| 2711 | } | 2649 | } |
| 2650 | file->buf_ptr = p; | ||
| 2651 | cstr_reset(&cstr); | ||
| 2712 | } | 2652 | } |
| 2713 | } | 2653 | } |
| 2714 | tok_str_add2(¯o_str1, tok, &tokc); | 2654 | tok_str_add2(¯o_str1, tok, &tokc); |
| 2715 | } | 2655 | } |
| 2716 | macro_ptr = (int *)saved_macro_ptr; | ||
| 2717 | cstr_free(&cstr); | ||
| 2718 | tok_str_add(¯o_str1, 0); | 2656 | tok_str_add(¯o_str1, 0); |
| 2719 | return macro_str1.str; | 2657 | return macro_str1.str; |
| 2720 | } | 2658 | } |