Implement function names with dots in signatures ##anal (#15993)

* Allow function names containing dots in tcc
This commit is contained in:
Óscar Carrasco 2020-02-26 13:23:47 +00:00 committed by GitHub
parent fd23790d3c
commit aa8c7de595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 22 deletions

View File

@ -814,6 +814,11 @@ static inline int isnum(int c)
return c >= '0' && c <= '9';
}
static inline int isdot(int c)
{
return c == '.';
}
static inline int isoct(int c)
{
return c >= '0' && c <= '7';

View File

@ -59,7 +59,7 @@ static int unget_saved_buffer[TOK_MAX_SIZE + 1];
static int unget_buffer_enabled;
static TokenSym *hash_ident[TOK_HASH_SIZE];
static char token_buf[STRING_MAX_SIZE + 1];
/* true if isid(c) || isnum(c) */
/* true if isid(c) || isnum(c) || isdot(c) */
static unsigned char isidnum_table[256 - CH_EOF];
static const char tcc_keywords[] =
@ -2353,7 +2353,7 @@ maybe_newline:
case 'Q': case 'R': case 'S': case 'T':
case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
case '_':
case '_': case '.':
parse_ident_fast:
p1 = p;
h = TOK_HASH_INIT;
@ -2361,10 +2361,21 @@ parse_ident_fast:
p++;
for (;;) {
c = *p;
if (!isidnum_table[c - CH_EOF]) {
if (!isidnum_table[*p - CH_EOF]) {
break;
}
h = TOK_HASH_FUNC (h, c);
// dot handling here too
if (isdot (c)) {
PEEKC (c, p);
if (isnum (c)) {
cstr_reset (&tokcstr);
cstr_ccat (&tokcstr, '.');
goto parse_num;
} else if (isdot (c)) {
goto parse_dots;
}
}
h = TOK_HASH_FUNC (h, *p);
p++;
}
if (c != '\\') {
@ -2437,7 +2448,7 @@ parse_num:
t = c;
cstr_ccat (&tokcstr, c);
PEEKC (c, p);
if (!(isnum (c) || isid (c) || c == '.' ||
if (!(isnum (c) || isid (c) || isdot (c) ||
((c == '+' || c == '-') &&
(t == 'e' || t == 'E' || t == 'p' || t == 'P')))) {
break;
@ -2448,24 +2459,14 @@ parse_num:
tokc.cstr = &tokcstr;
tok = TOK_PPNUM;
break;
case '.':
/* special dot handling because it can also start a number */
PEEKC (c, p);
if (isnum (c)) {
cstr_reset (&tokcstr);
cstr_ccat (&tokcstr, '.');
goto parse_num;
} else if (c == '.') {
PEEKC (c, p);
if (c != '.') {
expect ("'.'");
return;
}
PEEKC (c, p);
tok = TOK_DOTS;
} else {
tok = '.';
parse_dots:
if (!isdot (c)) {
expect ("'.'");
return;
}
PEEKC (c, p);
tok = TOK_DOTS;
break;
case '\'':
case '\"':
@ -3256,7 +3257,7 @@ ST_FUNC void preprocess_new(void)
/* init isid table */
for (i = CH_EOF; i < 256; i++) {
isidnum_table[i - CH_EOF] = isid (i) || isnum (i);
isidnum_table[i - CH_EOF] = isid (i) || isnum (i) || isdot (i);
}
/* add all tokens */

View File

@ -1482,6 +1482,23 @@ char type (int32_t a, char **b);
EOF
RUN
NAME=afs fcnname with dots
FILE=../bins/elf/hello_world
CMDS=<<EOF
af
afs
"afs foo.bar();"
afs
"afs char foo.bar(int a, ...);"
afs
EOF
EXPECT=<<EOF
entry0 (int64_t arg3);
foo.bar (int64_t arg3);
foo.bar (int64_t arg3);
EOF
RUN
NAME=td crash
FILE=-
CMDS=<<EOF