| @@ -53,11 +53,6 @@ static struct TinyAlloc *toksym_alloc; · 52 unmodified lines |
| 53 | static struct TinyAlloc *tokstr_alloc; | 53 | static struct TinyAlloc *tokstr_alloc; |
| 54 | static struct TinyAlloc *cstr_alloc; | 54 | static struct TinyAlloc *cstr_alloc; |
| 55 | | 55 | |
| 56 | /* isidnum_table flags: */ | | |
| 57 | #define IS_SPC 1 | | |
| 58 | #define IS_ID 2 | | |
| 59 | #define IS_NUM 4 | | |
| 60 | | | |
| 61 | static TokenString *macro_stack; | 56 | static TokenString *macro_stack; |
| 62 | | 57 | |
| 63 | static const char tcc_keywords[] = | 58 | static const char tcc_keywords[] = |
| @@ -819,6 +814,11 @@ ST_FUNC uint8_t *parse_comment(uint8_t *p) · 755 unmodified lines |
| 819 | return p; | 814 | return p; |
| 820 | } | 815 | } |
| 821 | | 816 | |
| | 817 | ST_FUNC void set_idnum(int c, int val) |
| | 818 | { |
| | 819 | isidnum_table[c - CH_EOF] = val; |
| | 820 | } |
| | 821 | |
| 822 | #define cinp minp | 822 | #define cinp minp |
| 823 | | 823 | |
| 824 | static inline void skip_spaces(void) | 824 | static inline void skip_spaces(void) |
| @@ -1453,13 +1453,15 @@ ST_FUNC void parse_define(void) · 628 unmodified lines |
| 1453 | /* XXX: should check if same macro (ANSI) */ | 1453 | /* XXX: should check if same macro (ANSI) */ |
| 1454 | first = NULL; | 1454 | first = NULL; |
| 1455 | t = MACRO_OBJ; | 1455 | t = MACRO_OBJ; |
| | 1456 | /* We have to parse the whole define as if not in asm mode, in particular |
| | 1457 | no line comment with '#' must be ignored. Also for function |
| | 1458 | macros the argument list must be parsed without '.' being an ID |
| | 1459 | character. */ |
| | 1460 | parse_flags = ((parse_flags & ~PARSE_FLAG_ASM_FILE) | PARSE_FLAG_SPACES); |
| 1456 | /* '(' must be just after macro definition for MACRO_FUNC */ | 1461 | /* '(' must be just after macro definition for MACRO_FUNC */ |
| 1457 | parse_flags |= PARSE_FLAG_SPACES; | | |
| 1458 | next_nomacro_spc(); | 1462 | next_nomacro_spc(); |
| 1459 | if (tok == '(') { | 1463 | if (tok == '(') { |
| 1460 | /* must be able to parse TOK_DOTS (in asm mode '.' can be part of identifier) */ | 1464 | set_idnum('.', 0); |
| 1461 | parse_flags &= ~PARSE_FLAG_ASM_FILE; | | |
| 1462 | isidnum_table['.' - CH_EOF] = 0; | | |
| 1463 | next_nomacro(); | 1465 | next_nomacro(); |
| 1464 | ps = &first; | 1466 | ps = &first; |
| 1465 | if (tok != ')') for (;;) { | 1467 | if (tok != ')') for (;;) { |
| @@ -1487,14 +1489,17 @@ ST_FUNC void parse_define(void) · 21 unmodified lines |
| 1487 | } | 1489 | } |
| 1488 | next_nomacro_spc(); | 1490 | next_nomacro_spc(); |
| 1489 | t = MACRO_FUNC; | 1491 | t = MACRO_FUNC; |
| 1490 | parse_flags |= (saved_parse_flags & PARSE_FLAG_ASM_FILE); | | |
| 1491 | isidnum_table['.' - CH_EOF] = | | |
| 1492 | (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0; | | |
| 1493 | } | 1492 | } |
| 1494 | | 1493 | |
| 1495 | tokstr_buf.len = 0; | 1494 | tokstr_buf.len = 0; |
| 1496 | spc = 2; | 1495 | spc = 2; |
| 1497 | parse_flags |= PARSE_FLAG_ACCEPT_STRAYS | PARSE_FLAG_SPACES | PARSE_FLAG_LINEFEED; | 1496 | parse_flags |= PARSE_FLAG_ACCEPT_STRAYS | PARSE_FLAG_SPACES | PARSE_FLAG_LINEFEED; |
| | 1497 | /* The body of a macro definition should be parsed such that identifiers |
| | 1498 | are parsed like the file mode determines (i.e. with '.' being an |
| | 1499 | ID character in asm mode). But '#' should be retained instead of |
| | 1500 | regarded as line comment leader, so still don't set ASM_FILE |
| | 1501 | in parse_flags. */ |
| | 1502 | set_idnum('.', (saved_parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0); |
| 1498 | while (tok != TOK_LINEFEED && tok != TOK_EOF) { | 1503 | while (tok != TOK_LINEFEED && tok != TOK_EOF) { |
| 1499 | /* remove spaces around ## and after '#' */ | 1504 | /* remove spaces around ## and after '#' */ |
| 1500 | if (TOK_TWOSHARPS == tok) { | 1505 | if (TOK_TWOSHARPS == tok) { |
| @@ -2673,7 +2678,7 @@ maybe_newline: · 1172 unmodified lines |
| 2673 | if (isnum(c)) { | 2678 | if (isnum(c)) { |
| 2674 | t = '.'; | 2679 | t = '.'; |
| 2675 | goto parse_num; | 2680 | goto parse_num; |
| 2676 | } else if ((parse_flags & PARSE_FLAG_ASM_FILE) | 2681 | } else if ((isidnum_table['.' - CH_EOF] & IS_ID) |
| 2677 | && (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))) { | 2682 | && (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))) { |
| 2678 | *--p = c = '.'; | 2683 | *--p = c = '.'; |
| 2679 | goto parse_ident_fast; | 2684 | goto parse_ident_fast; |
| @@ -3470,10 +3475,8 @@ ST_FUNC void preprocess_start(TCCState *s1) · 790 unmodified lines |
| 3470 | s1->pack_stack[0] = 0; | 3475 | s1->pack_stack[0] = 0; |
| 3471 | s1->pack_stack_ptr = s1->pack_stack; | 3476 | s1->pack_stack_ptr = s1->pack_stack; |
| 3472 | | 3477 | |
| 3473 | isidnum_table['$' - CH_EOF] = | 3478 | set_idnum('$', s1->dollars_in_identifiers ? IS_ID : 0); |
| 3474 | s1->dollars_in_identifiers ? IS_ID : 0; | 3479 | set_idnum('.', (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0); |
| 3475 | isidnum_table['.' - CH_EOF] = | | |
| 3476 | (parse_flags & PARSE_FLAG_ASM_FILE) ? IS_ID : 0; | | |
| 3477 | buf = tcc_malloc(3 + strlen(file->filename)); | 3480 | buf = tcc_malloc(3 + strlen(file->filename)); |
| 3478 | sprintf(buf, "\"%s\"", file->filename); | 3481 | sprintf(buf, "\"%s\"", file->filename); |
| 3479 | tcc_undefine_symbol(s1, "__BASE_FILE__"); | 3482 | tcc_undefine_symbol(s1, "__BASE_FILE__"); |
| @@ -3505,14 +3508,14 @@ ST_FUNC void tccpp_new(TCCState *s) · 25 unmodified lines |
| 3505 | | 3508 | |
| 3506 | /* init isid table */ | 3509 | /* init isid table */ |
| 3507 | for(i = CH_EOF; i<128; i++) | 3510 | for(i = CH_EOF; i<128; i++) |
| 3508 | isidnum_table[i - CH_EOF] | 3511 | set_idnum(i, |
| 3509 | = is_space(i) ? IS_SPC | 3512 | is_space(i) ? IS_SPC |
| 3510 | : isid(i) ? IS_ID | 3513 | : isid(i) ? IS_ID |
| 3511 | : isnum(i) ? IS_NUM | 3514 | : isnum(i) ? IS_NUM |
| 3512 | : 0; | 3515 | : 0); |
| 3513 | | 3516 | |
| 3514 | for(i = 128; i<256; i++) | 3517 | for(i = 128; i<256; i++) |
| 3515 | isidnum_table[i - CH_EOF] = IS_ID; | 3518 | set_idnum(i, IS_ID); |
| 3516 | | 3519 | |
| 3517 | /* init allocators */ | 3520 | /* init allocators */ |
| 3518 | tal_new(&toksym_alloc, TOKSYM_TAL_LIMIT, TOKSYM_TAL_SIZE); | 3521 | tal_new(&toksym_alloc, TOKSYM_TAL_LIMIT, TOKSYM_TAL_SIZE); |