forked from Mirrors/tinycc
pp: simplify pasting, enable L ## number
parent
045cff28fe
commit
fcdb663dde
112
tccpp.c
112
tccpp.c
|
@ -2598,13 +2598,13 @@ static int macro_subst_tok(TokenString *tok_str,
|
||||||
return the resulting string (which must be freed). */
|
return the resulting string (which must be freed). */
|
||||||
static inline int *macro_twosharps(const int *macro_str)
|
static inline int *macro_twosharps(const int *macro_str)
|
||||||
{
|
{
|
||||||
TokenSym *ts;
|
const int *ptr;
|
||||||
const int *ptr, *saved_macro_ptr;
|
|
||||||
int t;
|
int t;
|
||||||
const char *p1, *p2;
|
|
||||||
CValue cval;
|
CValue cval;
|
||||||
TokenString macro_str1;
|
TokenString macro_str1;
|
||||||
CString cstr;
|
CString cstr;
|
||||||
|
char *p;
|
||||||
|
int n;
|
||||||
|
|
||||||
/* we search the first '##' */
|
/* we search the first '##' */
|
||||||
for(ptr = macro_str;;) {
|
for(ptr = macro_str;;) {
|
||||||
|
@ -2617,104 +2617,42 @@ 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 */
|
||||||
cstr_new(&cstr);
|
|
||||||
tok_str_new(¯o_str1);
|
tok_str_new(¯o_str1);
|
||||||
saved_macro_ptr = macro_ptr;
|
for(ptr = macro_str;;) {
|
||||||
/* XXX: get rid of the use of macro_ptr here */
|
TOK_GET(tok, ptr, tokc);
|
||||||
macro_ptr = (int *)macro_str;
|
|
||||||
for(;;) {
|
|
||||||
next_nomacro_spc();
|
|
||||||
if (tok == 0)
|
if (tok == 0)
|
||||||
break;
|
break;
|
||||||
if (tok == TOK_TWOSHARPS)
|
if (tok == TOK_TWOSHARPS)
|
||||||
continue;
|
continue;
|
||||||
while (*macro_ptr == TOK_TWOSHARPS) {
|
while (*ptr == TOK_TWOSHARPS) {
|
||||||
t = *++macro_ptr;
|
t = *++ptr;
|
||||||
if (t && t != TOK_TWOSHARPS) {
|
if (t && t != TOK_TWOSHARPS) {
|
||||||
TOK_GET(t, macro_ptr, cval);
|
TOK_GET(t, ptr, cval);
|
||||||
/* We concatenate the two tokens if we have an
|
|
||||||
identifier or a preprocessing number */
|
/* We concatenate the two tokens */
|
||||||
cstr_reset(&cstr);
|
cstr_new(&cstr);
|
||||||
p1 = get_tok_str(tok, &tokc);
|
cstr_cat(&cstr, get_tok_str(tok, &tokc));
|
||||||
cstr_cat(&cstr, p1);
|
n = cstr.size;
|
||||||
p2 = get_tok_str(t, &cval);
|
cstr_cat(&cstr, get_tok_str(t, &cval));
|
||||||
cstr_cat(&cstr, p2);
|
|
||||||
cstr_ccat(&cstr, '\0');
|
cstr_ccat(&cstr, '\0');
|
||||||
|
|
||||||
if ((tok >= TOK_IDENT || tok == TOK_PPNUM) &&
|
p = file->buf_ptr;
|
||||||
(t >= TOK_IDENT || t == TOK_PPNUM)) {
|
file->buf_ptr = cstr.data;
|
||||||
if (tok == TOK_PPNUM) {
|
for (;;) {
|
||||||
/* if number, then create a number token */
|
next_nomacro1();
|
||||||
/* NOTE: no need to allocate because
|
if (0 == *file->buf_ptr)
|
||||||
tok_str_add2() does it */
|
break;
|
||||||
cstr_reset(&tokcstr);
|
tok_str_add2(¯o_str1, tok, &tokc);
|
||||||
tokcstr = cstr;
|
|
||||||
cstr_new(&cstr);
|
|
||||||
tokc.cstr = &tokcstr;
|
|
||||||
} else {
|
|
||||||
/* if identifier, we must do a test to
|
|
||||||
validate we have a correct identifier */
|
|
||||||
if (t == TOK_PPNUM) {
|
|
||||||
const char *p;
|
|
||||||
int c;
|
|
||||||
|
|
||||||
p = p2;
|
warning("pasting \"%.*s\" and \"%s\" does not give a valid preprocessing token",
|
||||||
for(;;) {
|
n, cstr.data, (char*)cstr.data + n);
|
||||||
c = *p;
|
|
||||||
if (c == '\0')
|
|
||||||
break;
|
|
||||||
p++;
|
|
||||||
if (!isnum(c) && !isid(c))
|
|
||||||
goto error_pasting;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ts = tok_alloc(cstr.data, strlen(cstr.data));
|
|
||||||
tok = ts->tok; /* modify current token */
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const char *str = cstr.data;
|
|
||||||
const unsigned char *q;
|
|
||||||
|
|
||||||
/* we look for a valid token */
|
|
||||||
/* XXX: do more extensive checks */
|
|
||||||
if (!strcmp(str, ">>=")) {
|
|
||||||
tok = TOK_A_SAR;
|
|
||||||
} else if (!strcmp(str, "<<=")) {
|
|
||||||
tok = TOK_A_SHL;
|
|
||||||
} else if (strlen(str) == 2) {
|
|
||||||
/* search in two bytes table */
|
|
||||||
q = tok_two_chars;
|
|
||||||
for(;;) {
|
|
||||||
if (!*q)
|
|
||||||
goto error_pasting;
|
|
||||||
if (q[0] == str[0] && q[1] == str[1])
|
|
||||||
break;
|
|
||||||
q += 3;
|
|
||||||
}
|
|
||||||
tok = q[2];
|
|
||||||
} else {
|
|
||||||
error_pasting:
|
|
||||||
/* NOTE: because get_tok_str use a static buffer,
|
|
||||||
we must save it */
|
|
||||||
cstr_reset(&cstr);
|
|
||||||
p1 = get_tok_str(tok, &tokc);
|
|
||||||
cstr_cat(&cstr, p1);
|
|
||||||
cstr_ccat(&cstr, '\0');
|
|
||||||
p2 = get_tok_str(t, &cval);
|
|
||||||
warning("pasting \"%s\" and \"%s\" does not give a valid preprocessing token", cstr.data, p2);
|
|
||||||
/* cannot merge tokens: just add them separately */
|
|
||||||
tok_str_add2(¯o_str1, tok, &tokc);
|
|
||||||
/* XXX: free associated memory ? */
|
|
||||||
tok = t;
|
|
||||||
tokc = cval;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
file->buf_ptr = p;
|
||||||
|
cstr_reset(&cstr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tok_str_add2(¯o_str1, tok, &tokc);
|
tok_str_add2(¯o_str1, tok, &tokc);
|
||||||
}
|
}
|
||||||
macro_ptr = (int *)saved_macro_ptr;
|
|
||||||
cstr_free(&cstr);
|
|
||||||
tok_str_add(¯o_str1, 0);
|
tok_str_add(¯o_str1, 0);
|
||||||
return macro_str1.str;
|
return macro_str1.str;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue