Unified · Split
| @@ -201,6 +201,7 @@ typedef struct BufferedFile { · 200 unmodified lines | ||
| 201 | 201 | unsigned char *buf_end; |
| 202 | 202 | int fd; |
| 203 | 203 | int line_num; /* current line number - here to simply code */ |
| 204 | + int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */ | |
| 204 | 205 | char filename[1024]; /* current filename - here to simplify code */ |
| 205 | 206 | unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char */ |
| 206 | 207 | } BufferedFile; |
| @@ -229,7 +230,9 @@ struct BufferedFile *file; · 22 unmodified lines | ||
| 229 | 230 | int ch, ch1, tok, tok1; |
| 230 | 231 | CValue tokc, tok1c; |
| 231 | 232 | CString tokcstr; /* current parsed string, if any */ |
| 232 | −int return_linefeed; /* if true, line feed is returned as a token */ | |
| 233 | +/* if true, line feed is returned as a token. line feed is also | |
| 234 | + returned at eof */ | |
| 235 | +int return_linefeed; | |
| 233 | 236 | |
| 234 | 237 | /* sections */ |
| 235 | 238 | Section **sections; |
| @@ -1040,7 +1043,7 @@ void skip(int c) · 804 unmodified lines | ||
| 1040 | 1043 | next(); |
| 1041 | 1044 | } |
| 1042 | 1045 | |
| 1043 | −void test_lvalue(void) | |
| 1046 | +static void test_lvalue(void) | |
| 1044 | 1047 | { |
| 1045 | 1048 | if (!(vtop->r & VT_LVAL)) |
| 1046 | 1049 | expect("lvalue"); |
| @@ -1051,8 +1054,6 @@ TokenSym *tok_alloc(const char *str, int len) · 4 unmodified lines | ||
| 1051 | 1054 | TokenSym *ts, **pts, **ptable; |
| 1052 | 1055 | int h, i; |
| 1053 | 1056 | |
| 1054 | − if (len <= 0) | |
| 1055 | − len = strlen(str); | |
| 1056 | 1057 | h = 1; |
| 1057 | 1058 | for(i=0;i<len;i++) |
| 1058 | 1059 | h = (h * 263 + ((unsigned char *)str)[i]) & (TOK_HASH_SIZE - 1); |
| @@ -1397,6 +1398,7 @@ BufferedFile *tcc_open(const char *filename) · 338 unmodified lines | ||
| 1397 | 1398 | bf->buffer[0] = CH_EOB; /* put eob symbol */ |
| 1398 | 1399 | pstrcpy(bf->filename, sizeof(bf->filename), filename); |
| 1399 | 1400 | bf->line_num = 1; |
| 1401 | + bf->ifdef_stack_ptr = ifdef_stack_ptr; | |
| 1400 | 1402 | // printf("opening '%s'\n", filename); |
| 1401 | 1403 | return bf; |
| 1402 | 1404 | } |
| @@ -1444,7 +1446,10 @@ void handle_eob(void) · 41 unmodified lines | ||
| 1444 | 1446 | ch1 = tcc_getc_slow(file); |
| 1445 | 1447 | if (ch1 != CH_EOF) |
| 1446 | 1448 | return; |
| 1447 | − | |
| 1449 | + if (return_linefeed) { | |
| 1450 | + ch1 = '\n'; | |
| 1451 | + return; | |
| 1452 | + } | |
| 1448 | 1453 | if (include_stack_ptr == include_stack) |
| 1449 | 1454 | return; |
| 1450 | 1455 | /* add end of include file debug info */ |
| @@ -1732,7 +1737,7 @@ int expr_preprocess(void) · 281 unmodified lines | ||
| 1732 | 1737 | TokenString str; |
| 1733 | 1738 | |
| 1734 | 1739 | tok_str_new(&str); |
| 1735 | − while (tok != TOK_LINEFEED && tok != TOK_EOF) { | |
| 1740 | + while (tok != TOK_LINEFEED) { | |
| 1736 | 1741 | next(); /* do macro subst */ |
| 1737 | 1742 | if (tok == TOK_DEFINED) { |
| 1738 | 1743 | next_nomacro(); |
| @@ -1817,12 +1822,11 @@ void parse_define(void) · 78 unmodified lines | ||
| 1817 | 1822 | t = MACRO_FUNC; |
| 1818 | 1823 | } |
| 1819 | 1824 | tok_str_new(&str); |
| 1820 | − while (1) { | |
| 1821 | − skip_spaces(); | |
| 1822 | − if (ch == '\n' || ch == CH_EOF) | |
| 1823 | − break; | |
| 1824 | − next_nomacro(); | |
| 1825 | + next_nomacro(); | |
| 1826 | + /* EOF testing necessary for '-D' handling */ | |
| 1827 | + while (tok != TOK_LINEFEED && tok != TOK_EOF) { | |
| 1825 | 1828 | tok_str_add2(&str, tok, &tokc); |
| 1829 | + next_nomacro(); | |
| 1826 | 1830 | } |
| 1827 | 1831 | tok_str_add(&str, 0); |
| 1828 | 1832 | #ifdef PP_DEBUG |
| @@ -1991,7 +1995,7 @@ void preprocess(void) · 162 unmodified lines | ||
| 1991 | 1995 | goto redo; |
| 1992 | 1996 | } |
| 1993 | 1997 | } else if (tok == TOK_ENDIF) { |
| 1994 | − if (ifdef_stack_ptr == ifdef_stack) | |
| 1998 | + if (ifdef_stack_ptr <= file->ifdef_stack_ptr) | |
| 1995 | 1999 | error("#endif without matching #if"); |
| 1996 | 2000 | ifdef_stack_ptr--; |
| 1997 | 2001 | } else if (tok == TOK_LINE) { |
| @@ -2013,7 +2017,7 @@ void preprocess(void) · 15 unmodified lines | ||
| 2013 | 2017 | error("#error"); |
| 2014 | 2018 | } |
| 2015 | 2019 | /* ignore other preprocess commands or #! for C scripts */ |
| 2016 | − while (tok != TOK_LINEFEED && tok != TOK_EOF) | |
| 2020 | + while (tok != TOK_LINEFEED) | |
| 2017 | 2021 | next_nomacro(); |
| 2018 | 2022 | the_end: |
| 2019 | 2023 | return_linefeed = 0; |
| @@ -2640,7 +2644,7 @@ int *macro_twosharps(int *macro_str) · 620 unmodified lines | ||
| 2640 | 2644 | pstrcpy(token_buf, sizeof(token_buf), p); |
| 2641 | 2645 | p = get_tok_str(t, &cval); |
| 2642 | 2646 | pstrcat(token_buf, sizeof(token_buf), p); |
| 2643 | − ts = tok_alloc(token_buf, 0); | |
| 2647 | + ts = tok_alloc(token_buf, strlen(token_buf)); | |
| 2644 | 2648 | tok = ts->tok; /* modify current token */ |
| 2645 | 2649 | } else { |
| 2646 | 2650 | /* cannot merge tokens: skip '##' */ |
| @@ -6652,7 +6656,10 @@ static int tcc_compile(TCCState *s) · 4005 unmodified lines | ||
| 6652 | 6656 | |
| 6653 | 6657 | funcname = ""; |
| 6654 | 6658 | include_stack_ptr = include_stack; |
| 6659 | + /* XXX: move that before to avoid having to initialize | |
| 6660 | + file->ifdef_stack_ptr ? */ | |
| 6655 | 6661 | ifdef_stack_ptr = ifdef_stack; |
| 6662 | + file->ifdef_stack_ptr = ifdef_stack_ptr; | |
| 6656 | 6663 | |
| 6657 | 6664 | /* XXX: not ANSI compliant: bound checking says error */ |
| 6658 | 6665 | vtop = vstack - 1; |
| @@ -6774,7 +6781,7 @@ void tcc_undefine_symbol(TCCState *s1, const char *sym) · 115 unmodified lines | ||
| 6774 | 6781 | { |
| 6775 | 6782 | TokenSym *ts; |
| 6776 | 6783 | Sym *s; |
| 6777 | − ts = tok_alloc(sym, 0); | |
| 6784 | + ts = tok_alloc(sym, strlen(sym)); | |
| 6778 | 6785 | s = sym_find1(&define_stack, tok); |
| 6779 | 6786 | /* undefine symbol by putting an invalid name */ |
| 6780 | 6787 | if (s) |