Unified · Split
| @@ -213,7 +213,8 @@ typedef struct BufferedFile { · 212 unmodified lines | ||
| 213 | 213 | unsigned char *buf_end; |
| 214 | 214 | int fd; |
| 215 | 215 | int line_num; /* current line number - here to simply code */ |
| 216 | − int ifndef_macro; /*'#ifndef macro \n #define macro' search */ | |
| 216 | + int ifndef_macro; /* #ifndef macro / #endif search */ | |
| 217 | + int ifndef_macro_saved; /* saved ifndef_macro */ | |
| 217 | 218 | int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */ |
| 218 | 219 | char inc_type; /* type of include */ |
| 219 | 220 | char inc_filename[512]; /* filename specified by the user */ |
| @@ -249,73 +250,76 @@ typedef struct CachedInclude { · 29 unmodified lines | ||
| 249 | 250 | } CachedInclude; |
| 250 | 251 | |
| 251 | 252 | /* parser */ |
| 252 | −struct BufferedFile *file; | |
| 253 | −int ch, tok, tok1; | |
| 254 | −CValue tokc, tok1c; | |
| 255 | −CString tokcstr; /* current parsed string, if any */ | |
| 253 | +static struct BufferedFile *file; | |
| 254 | +static int ch, tok, tok1; | |
| 255 | +static CValue tokc, tok1c; | |
| 256 | +static CString tokcstr; /* current parsed string, if any */ | |
| 257 | +/* additionnal informations about token */ | |
| 258 | +static int tok_flags; | |
| 259 | +#define TOK_FLAG_BOL 0x0001 /* beginning of line before */ | |
| 260 | +#define TOK_FLAG_BOF 0x0002 /* beginning of file before */ | |
| 261 | +#define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */ | |
| 262 | + | |
| 256 | 263 | /* if true, line feed is returned as a token. line feed is also |
| 257 | 264 | returned at eof */ |
| 258 | −int return_linefeed; | |
| 259 | −/* set to TRUE if eof was reached */ | |
| 260 | −int eof_seen; | |
| 261 | −Section *text_section, *data_section, *bss_section; /* predefined sections */ | |
| 262 | −Section *cur_text_section; /* current section where function code is | |
| 265 | +static int return_linefeed; | |
| 266 | +static Section *text_section, *data_section, *bss_section; /* predefined sections */ | |
| 267 | +static Section *cur_text_section; /* current section where function code is | |
| 263 | 268 | generated */ |
| 264 | 269 | /* bound check related sections */ |
| 265 | −Section *bounds_section; /* contains global data bound description */ | |
| 266 | −Section *lbounds_section; /* contains local data bound description */ | |
| 270 | +static Section *bounds_section; /* contains global data bound description */ | |
| 271 | +static Section *lbounds_section; /* contains local data bound description */ | |
| 267 | 272 | /* symbol sections */ |
| 268 | −Section *symtab_section, *strtab_section; | |
| 273 | +static Section *symtab_section, *strtab_section; | |
| 269 | 274 | |
| 270 | 275 | /* debug sections */ |
| 271 | −Section *stab_section, *stabstr_section; | |
| 276 | +static Section *stab_section, *stabstr_section; | |
| 272 | 277 | |
| 273 | 278 | /* loc : local variable index |
| 274 | 279 | ind : output code index |
| 275 | 280 | rsym: return symbol |
| 276 | 281 | anon_sym: anonymous symbol index |
| 277 | 282 | */ |
| 278 | −int rsym, anon_sym, | |
| 279 | − prog, ind, loc; | |
| 283 | +static int rsym, anon_sym, ind, loc; | |
| 280 | 284 | /* expression generation modifiers */ |
| 281 | −int const_wanted; /* true if constant wanted */ | |
| 282 | −int nocode_wanted; /* true if no code generation wanted for an expression */ | |
| 283 | −int global_expr; /* true if compound literals must be allocated | |
| 284 | − globally (used during initializers parsing */ | |
| 285 | −CType func_vt; /* current function return type (used by return | |
| 286 | − instruction) */ | |
| 287 | −int func_vc; | |
| 288 | −int last_line_num, last_ind, func_ind; /* debug last line number and pc */ | |
| 289 | −int tok_ident; | |
| 290 | −TokenSym **table_ident; | |
| 291 | −TokenSym *hash_ident[TOK_HASH_SIZE]; | |
| 292 | −char token_buf[STRING_MAX_SIZE + 1]; | |
| 293 | −char *funcname; | |
| 294 | −Sym *global_stack, *local_stack; | |
| 295 | −Sym *define_stack; | |
| 296 | −Sym *label_stack; | |
| 297 | − | |
| 298 | −SValue vstack[VSTACK_SIZE], *vtop; | |
| 299 | −int *macro_ptr, *macro_ptr_allocated; | |
| 285 | +static int const_wanted; /* true if constant wanted */ | |
| 286 | +static int nocode_wanted; /* true if no code generation wanted for an expression */ | |
| 287 | +static int global_expr; /* true if compound literals must be allocated | |
| 288 | + globally (used during initializers parsing */ | |
| 289 | +static CType func_vt; /* current function return type (used by return | |
| 290 | + instruction) */ | |
| 291 | +static int func_vc; | |
| 292 | +static int last_line_num, last_ind, func_ind; /* debug last line number and pc */ | |
| 293 | +static int tok_ident; | |
| 294 | +static TokenSym **table_ident; | |
| 295 | +static TokenSym *hash_ident[TOK_HASH_SIZE]; | |
| 296 | +static char token_buf[STRING_MAX_SIZE + 1]; | |
| 297 | +static char *funcname; | |
| 298 | +static Sym *global_stack, *local_stack; | |
| 299 | +static Sym *define_stack; | |
| 300 | +static Sym *label_stack; | |
| 301 | + | |
| 302 | +static SValue vstack[VSTACK_SIZE], *vtop; | |
| 303 | +static int *macro_ptr, *macro_ptr_allocated; | |
| 300 | 304 | /* some predefined types */ |
| 301 | −CType char_pointer_type, func_old_type, int_type; | |
| 305 | +static CType char_pointer_type, func_old_type, int_type; | |
| 302 | 306 | |
| 303 | 307 | /* compile with debug symbol (and use them if error during execution) */ |
| 304 | −int do_debug = 0; | |
| 308 | +static int do_debug = 0; | |
| 305 | 309 | |
| 306 | 310 | /* compile with built-in memory and bounds checker */ |
| 307 | −int do_bounds_check = 0; | |
| 311 | +static int do_bounds_check = 0; | |
| 308 | 312 | |
| 309 | 313 | /* display benchmark infos */ |
| 310 | −int do_bench = 0; | |
| 311 | −int total_lines; | |
| 312 | −int total_bytes; | |
| 314 | +static int do_bench = 0; | |
| 315 | +static int total_lines; | |
| 316 | +static int total_bytes; | |
| 313 | 317 | |
| 314 | 318 | /* use GNU C extensions */ |
| 315 | −int gnu_ext = 1; | |
| 319 | +static int gnu_ext = 1; | |
| 316 | 320 | |
| 317 | 321 | /* use Tiny C extensions */ |
| 318 | −int tcc_ext = 1; | |
| 322 | +static int tcc_ext = 1; | |
| 319 | 323 | |
| 320 | 324 | /* max number of callers shown if error */ |
| 321 | 325 | static int num_callers = 6; |
| @@ -1225,6 +1229,21 @@ static void cstr_free(CString *cstr) · 903 unmodified lines | ||
| 1225 | 1229 | |
| 1226 | 1230 | #define cstr_reset(cstr) cstr_free(cstr) |
| 1227 | 1231 | |
| 1232 | +static CString *cstr_dup(CString *cstr1) | |
| 1233 | +{ | |
| 1234 | + CString *cstr; | |
| 1235 | + int size; | |
| 1236 | + | |
| 1237 | + cstr = tcc_malloc(sizeof(CString)); | |
| 1238 | + size = cstr1->size; | |
| 1239 | + cstr->size = size; | |
| 1240 | + cstr->size_allocated = size; | |
| 1241 | + cstr->data_allocated = tcc_malloc(size); | |
| 1242 | + cstr->data = cstr->data_allocated; | |
| 1243 | + memcpy(cstr->data_allocated, cstr1->data_allocated, size); | |
| 1244 | + return cstr; | |
| 1245 | +} | |
| 1246 | + | |
| 1228 | 1247 | /* XXX: unicode ? */ |
| 1229 | 1248 | static void add_char(CString *cstr, int c) |
| 1230 | 1249 | { |
| @@ -1525,32 +1544,10 @@ int tcc_getc_slow(BufferedFile *bf) · 294 unmodified lines | ||
| 1525 | 1544 | /* no need to put that inline */ |
| 1526 | 1545 | void handle_eob(void) |
| 1527 | 1546 | { |
| 1528 | − TCCState *s1 = tcc_state; | |
| 1529 | − | |
| 1530 | 1547 | /* no need to do anything if not at EOB */ |
| 1531 | 1548 | if (file->buf_ptr <= file->buf_end) |
| 1532 | 1549 | return; |
| 1533 | − | |
| 1534 | − for(;;) { | |
| 1535 | − ch = tcc_getc_slow(file); | |
| 1536 | − if (ch != CH_EOF) | |
| 1537 | − return; | |
| 1538 | − eof_seen = 1; | |
| 1539 | − if (return_linefeed) { | |
| 1540 | − ch = '\n'; | |
| 1541 | − return; | |
| 1542 | − } | |
| 1543 | − if (s1->include_stack_ptr == s1->include_stack) | |
| 1544 | − return; | |
| 1545 | − /* add end of include file debug info */ | |
| 1546 | − if (do_debug) { | |
| 1547 | − put_stabd(N_EINCL, 0, 0); | |
| 1548 | − } | |
| 1549 | − /* pop include stack */ | |
| 1550 | − tcc_close(file); | |
| 1551 | − s1->include_stack_ptr--; | |
| 1552 | − file = *s1->include_stack_ptr; | |
| 1553 | − } | |
| 1550 | + ch = tcc_getc_slow(file); | |
| 1554 | 1551 | } |
| 1555 | 1552 | |
| 1556 | 1553 | /* read next char from current input file and handle end of input buffer */ |
| @@ -1668,7 +1665,8 @@ void preprocess_skip(void) · 111 unmodified lines | ||
| 1668 | 1665 | |
| 1669 | 1666 | start_of_line = 1; |
| 1670 | 1667 | a = 0; |
| 1671 | − while (1) { | |
| 1668 | + for(;;) { | |
| 1669 | + redo_no_start: | |
| 1672 | 1670 | switch(ch) { |
| 1673 | 1671 | case ' ': |
| 1674 | 1672 | case '\t': |
| @@ -1676,19 +1674,18 @@ void preprocess_skip(void) · 1 unmodified line | ||
| 1676 | 1674 | case '\v': |
| 1677 | 1675 | case '\r': |
| 1678 | 1676 | inp(); |
| 1679 | − break; | |
| 1677 | + goto redo_no_start; | |
| 1680 | 1678 | case '\n': |
| 1681 | 1679 | start_of_line = 1; |
| 1682 | 1680 | file->line_num++; |
| 1683 | 1681 | inp(); |
| 1684 | − break; | |
| 1682 | + goto redo_no_start; | |
| 1685 | 1683 | case '\\': |
| 1686 | 1684 | handle_stray(); |
| 1687 | − break; | |
| 1685 | + goto redo_no_start; | |
| 1688 | 1686 | /* skip strings */ |
| 1689 | 1687 | case '\"': |
| 1690 | 1688 | case '\'': |
| 1691 | − start_of_line = 0; | |
| 1692 | 1689 | sep = ch; |
| 1693 | 1690 | inp(); |
| 1694 | 1691 | while (ch != sep) { |
| @@ -1714,8 +1711,6 @@ void preprocess_skip(void) · 19 unmodified lines | ||
| 1714 | 1711 | parse_comment(); |
| 1715 | 1712 | } else if (ch == '/') { |
| 1716 | 1713 | parse_line_comment(); |
| 1717 | − } else { | |
| 1718 | − start_of_line = 0; | |
| 1719 | 1714 | } |
| 1720 | 1715 | break; |
| 1721 | 1716 | |
| @@ -1731,16 +1726,15 @@ void preprocess_skip(void) · 9 unmodified lines | ||
| 1731 | 1726 | else if (tok == TOK_ENDIF) |
| 1732 | 1727 | a--; |
| 1733 | 1728 | } |
| 1734 | − start_of_line = 0; | |
| 1735 | 1729 | break; |
| 1736 | 1730 | case CH_EOF: |
| 1737 | 1731 | expect("#endif"); |
| 1738 | 1732 | break; |
| 1739 | 1733 | default: |
| 1740 | 1734 | inp(); |
| 1741 | − start_of_line = 0; | |
| 1742 | 1735 | break; |
| 1743 | 1736 | } |
| 1737 | + start_of_line = 0; | |
| 1744 | 1738 | } |
| 1745 | 1739 | the_end: ; |
| 1746 | 1740 | } |
| @@ -1846,22 +1840,13 @@ static void tok_str_add(TokenString *s, int t) · 99 unmodified lines | ||
| 1846 | 1840 | |
| 1847 | 1841 | static void tok_str_add2(TokenString *s, int t, CValue *cv) |
| 1848 | 1842 | { |
| 1849 | − int n, i, size; | |
| 1850 | − CString *cstr, *cstr1; | |
| 1843 | + int n, i; | |
| 1851 | 1844 | CValue cv1; |
| 1852 | 1845 | |
| 1853 | 1846 | tok_str_add(s, t); |
| 1854 | 1847 | if (t == TOK_STR || t == TOK_LSTR || t == TOK_PPNUM) { |
| 1855 | 1848 | /* special case: need to duplicate string */ |
| 1856 | − cstr1 = cv->cstr; | |
| 1857 | − cstr = tcc_malloc(sizeof(CString)); | |
| 1858 | − size = cstr1->size; | |
| 1859 | − cstr->size = size; | |
| 1860 | − cstr->size_allocated = size; | |
| 1861 | − cstr->data_allocated = tcc_malloc(size); | |
| 1862 | − cstr->data = cstr->data_allocated; | |
| 1863 | − memcpy(cstr->data_allocated, cstr1->data_allocated, size); | |
| 1864 | − cv1.cstr = cstr; | |
| 1849 | + cv1.cstr = cstr_dup(cv->cstr); | |
| 1865 | 1850 | tok_str_add(s, cv1.tab[0]); |
| 1866 | 1851 | } else { |
| 1867 | 1852 | n = tok_ext_size(t); |
| @@ -2107,17 +2092,11 @@ static inline void add_cached_include(TCCState *s1, int type, · 239 unmodified lines | ||
| 2107 | 2092 | dynarray_add((void ***)&s1->cached_includes, &s1->nb_cached_includes, e); |
| 2108 | 2093 | } |
| 2109 | 2094 | |
| 2110 | − | |
| 2111 | −enum IncludeState { | |
| 2112 | − INCLUDE_STATE_NONE = 0, | |
| 2113 | − INCLUDE_STATE_SEEK_IFNDEF, | |
| 2114 | −}; | |
| 2115 | − | |
| 2116 | −void preprocess(void) | |
| 2095 | +/* is_bof is true if first non space token at beginning of file */ | |
| 2096 | +static void preprocess(int is_bof) | |
| 2117 | 2097 | { |
| 2118 | 2098 | TCCState *s1 = tcc_state; |
| 2119 | 2099 | int size, i, c, n, line_num; |
| 2120 | − enum IncludeState state; | |
| 2121 | 2100 | char buf[1024], *q, *p; |
| 2122 | 2101 | char buf1[1024]; |
| 2123 | 2102 | BufferedFile *f; |
| @@ -2126,9 +2105,6 @@ void preprocess(void) · 2 unmodified lines | ||
| 2126 | 2105 | |
| 2127 | 2106 | return_linefeed = 1; /* linefeed will be returned as a |
| 2128 | 2107 | token. EOF is also returned as line feed */ |
| 2129 | − state = INCLUDE_STATE_NONE; | |
| 2130 | − eof_seen = 0; | |
| 2131 | − redo1: | |
| 2132 | 2108 | next_nomacro(); |
| 2133 | 2109 | redo: |
| 2134 | 2110 | switch(tok) { |
| @@ -2253,16 +2229,8 @@ void preprocess(void) · 118 unmodified lines | ||
| 2253 | 2229 | if (do_debug) { |
| 2254 | 2230 | put_stabs(file->filename, N_BINCL, 0, 0, 0); |
| 2255 | 2231 | } |
| 2256 | − /* we check for the construct: #ifndef IDENT \n #define IDENT */ | |
| 2257 | − inp(); | |
| 2258 | − /* get first non space char */ | |
| 2259 | − while (is_space(ch) || ch == '\n') | |
| 2260 | − cinp(); | |
| 2261 | − if (ch != '#') | |
| 2262 | − goto the_end; | |
| 2263 | − state = INCLUDE_STATE_SEEK_IFNDEF; | |
| 2264 | − cinp(); | |
| 2265 | − goto redo1; | |
| 2232 | + tok_flags |= TOK_FLAG_BOF; | |
| 2233 | + goto the_end; | |
| 2266 | 2234 | } |
| 2267 | 2235 | break; |
| 2268 | 2236 | case TOK_IFNDEF: |
| @@ -2277,11 +2245,13 @@ void preprocess(void) · 8 unmodified lines | ||
| 2277 | 2245 | next_nomacro(); |
| 2278 | 2246 | if (tok < TOK_IDENT) |
| 2279 | 2247 | error("invalid argument for '#if%sdef'", c ? "n" : ""); |
| 2280 | − if (state == INCLUDE_STATE_SEEK_IFNDEF) { | |
| 2248 | + if (is_bof) { | |
| 2281 | 2249 | if (c) { |
| 2250 | +#ifdef INC_DEBUG | |
| 2251 | + printf("#ifndef %s\n", get_tok_str(tok, NULL)); | |
| 2252 | +#endif | |
| 2282 | 2253 | file->ifndef_macro = tok; |
| 2283 | 2254 | } |
| 2284 | − state = INCLUDE_STATE_NONE; | |
| 2285 | 2255 | } |
| 2286 | 2256 | c = (define_find(tok) != 0) ^ c; |
| 2287 | 2257 | do_if: |
| @@ -2311,31 +2281,27 @@ void preprocess(void) · 23 unmodified lines | ||
| 2311 | 2281 | if (!(c & 1)) { |
| 2312 | 2282 | skip: |
| 2313 | 2283 | preprocess_skip(); |
| 2314 | − state = INCLUDE_STATE_NONE; | |
| 2284 | + is_bof = 0; | |
| 2315 | 2285 | goto redo; |
| 2316 | 2286 | } |
| 2317 | 2287 | break; |
| 2318 | 2288 | case TOK_ENDIF: |
| 2319 | 2289 | if (s1->ifdef_stack_ptr <= file->ifdef_stack_ptr) |
| 2320 | 2290 | error("#endif without matching #if"); |
| 2291 | + s1->ifdef_stack_ptr--; | |
| 2292 | + /* '#ifndef macro' was at the start of file. Now we check if | |
| 2293 | + an '#endif' is exactly at the end of file */ | |
| 2321 | 2294 | if (file->ifndef_macro && |
| 2322 | − s1->ifdef_stack_ptr == (file->ifdef_stack_ptr + 1)) { | |
| 2323 | − /* '#ifndef macro \n #define macro' was at the start of | |
| 2324 | − file. Now we check if an '#endif' is exactly at the end | |
| 2325 | − of file */ | |
| 2295 | + s1->ifdef_stack_ptr == file->ifdef_stack_ptr) { | |
| 2296 | + file->ifndef_macro_saved = file->ifndef_macro; | |
| 2297 | + /* need to set to zero to avoid false matches if another | |
| 2298 | + #ifndef at middle of file */ | |
| 2299 | + file->ifndef_macro = 0; | |
| 2326 | 2300 | while (tok != TOK_LINEFEED) |
| 2327 | 2301 | next_nomacro(); |
| 2328 | − /* XXX: should also skip comments, but it is more complicated */ | |
| 2329 | − if (eof_seen) { | |
| 2330 | − add_cached_include(s1, file->inc_type, file->inc_filename, | |
| 2331 | − file->ifndef_macro); | |
| 2332 | − } else { | |
| 2333 | − /* if not end of file, we must desactivate the ifndef | |
| 2334 | − macro search */ | |
| 2335 | − file->ifndef_macro = 0; | |
| 2336 | − } | |
| 2302 | + tok_flags |= TOK_FLAG_ENDIF; | |
| 2303 | + goto the_end; | |
| 2337 | 2304 | } |
| 2338 | − s1->ifdef_stack_ptr--; | |
| 2339 | 2305 | break; |
| 2340 | 2306 | case TOK_LINE: |
| 2341 | 2307 | next(); |
| @@ -2378,7 +2344,7 @@ void preprocess(void) · 36 unmodified lines | ||
| 2378 | 2344 | break; |
| 2379 | 2345 | } |
| 2380 | 2346 | /* ignore other preprocess commands or #! for C scripts */ |
| 2381 | − while (tok != TOK_LINEFEED && tok != TOK_EOF) | |
| 2347 | + while (tok != TOK_LINEFEED) | |
| 2382 | 2348 | next_nomacro(); |
| 2383 | 2349 | the_end: |
| 2384 | 2350 | return_linefeed = 0; |
| @@ -2780,11 +2746,10 @@ void parse_number(const char *p) · 395 unmodified lines | ||
| 2780 | 2746 | /* return next token without macro substitution */ |
| 2781 | 2747 | static inline void next_nomacro1(void) |
| 2782 | 2748 | { |
| 2783 | − int b, t, start_of_line; | |
| 2749 | + int b, t; | |
| 2784 | 2750 | char *q; |
| 2785 | 2751 | TokenSym *ts; |
| 2786 | 2752 | |
| 2787 | − start_of_line = 0; | |
| 2788 | 2753 | redo_no_start: |
| 2789 | 2754 | switch(ch) { |
| 2790 | 2755 | case ' ': |
| @@ -2799,13 +2764,48 @@ static inline void next_nomacro1(void) · 8 unmodified lines | ||
| 2799 | 2764 | handle_stray(); |
| 2800 | 2765 | goto redo_no_start; |
| 2801 | 2766 | |
| 2767 | + case CH_EOF: | |
| 2768 | + { | |
| 2769 | + TCCState *s1 = tcc_state; | |
| 2770 | + | |
| 2771 | + if (return_linefeed) { | |
| 2772 | + tok = TOK_LINEFEED; | |
| 2773 | + } else if (s1->include_stack_ptr == s1->include_stack) { | |
| 2774 | + /* no include left : end of file */ | |
| 2775 | + tok = TOK_EOF; | |
| 2776 | + } else { | |
| 2777 | + /* pop include file */ | |
| 2778 | + | |
| 2779 | + /* test if previous '#endif' was after a #ifdef at | |
| 2780 | + start of file */ | |
| 2781 | + if (tok_flags & TOK_FLAG_ENDIF) { | |
| 2782 | +#ifdef INC_DEBUG | |
| 2783 | + printf("#endif %s\n", get_tok_str(file->ifndef_macro_saved, NULL)); | |
| 2784 | +#endif | |
| 2785 | + add_cached_include(s1, file->inc_type, file->inc_filename, | |
| 2786 | + file->ifndef_macro_saved); | |
| 2787 | + } | |
| 2788 | + | |
| 2789 | + /* add end of include file debug info */ | |
| 2790 | + if (do_debug) { | |
| 2791 | + put_stabd(N_EINCL, 0, 0); | |
| 2792 | + } | |
| 2793 | + /* pop include stack */ | |
| 2794 | + tcc_close(file); | |
| 2795 | + s1->include_stack_ptr--; | |
| 2796 | + file = *s1->include_stack_ptr; | |
| 2797 | + inp(); | |
| 2798 | + goto redo_no_start; | |
| 2799 | + } | |
| 2800 | + } | |
| 2801 | + break; | |
| 2802 | + | |
| 2802 | 2803 | case '\n': |
| 2803 | 2804 | file->line_num++; |
| 2804 | 2805 | if (return_linefeed) { |
| 2805 | − /* XXX: should eat token ? */ | |
| 2806 | 2806 | tok = TOK_LINEFEED; |
| 2807 | 2807 | } else { |
| 2808 | − start_of_line = 1; | |
| 2808 | + tok_flags |= TOK_FLAG_BOL; | |
| 2809 | 2809 | inp(); |
| 2810 | 2810 | goto redo_no_start; |
| 2811 | 2811 | } |
| @@ -2813,8 +2813,8 @@ static inline void next_nomacro1(void) · 1 unmodified line | ||
| 2813 | 2813 | |
| 2814 | 2814 | case '#': |
| 2815 | 2815 | minp(); |
| 2816 | − if (start_of_line) { | |
| 2817 | − preprocess(); | |
| 2816 | + if (tok_flags & TOK_FLAG_BOL) { | |
| 2817 | + preprocess(tok_flags & TOK_FLAG_BOF); | |
| 2818 | 2818 | goto redo_no_start; |
| 2819 | 2819 | } else { |
| 2820 | 2820 | if (ch == '#') { |
| @@ -3108,13 +3108,11 @@ static inline void next_nomacro1(void) · 287 unmodified lines | ||
| 3108 | 3108 | tok = ch; |
| 3109 | 3109 | cinp(); |
| 3110 | 3110 | break; |
| 3111 | − case CH_EOF: | |
| 3112 | − tok = TOK_EOF; | |
| 3113 | − break; | |
| 3114 | 3111 | default: |
| 3115 | 3112 | error("unrecognized character \\x%02x", ch); |
| 3116 | 3113 | break; |
| 3117 | 3114 | } |
| 3115 | + tok_flags = 0; | |
| 3118 | 3116 | #if defined(PARSE_DEBUG) |
| 3119 | 3117 | printf("token = %s\n", get_tok_str(tok, &tokc)); |
| 3120 | 3118 | #endif |
| @@ -3386,6 +3384,7 @@ static int macro_subst_tok(TokenString *tok_str, · 265 unmodified lines | ||
| 3386 | 3384 | if (macro_ptr) { |
| 3387 | 3385 | t = *macro_ptr; |
| 3388 | 3386 | } else { |
| 3387 | + /* XXX: incorrect with comments */ | |
| 3389 | 3388 | while (is_space(ch) || ch == '\n') |
| 3390 | 3389 | cinp(); |
| 3391 | 3390 | t = ch; |
| @@ -7642,7 +7641,8 @@ static int tcc_compile(TCCState *s1) · 4250 unmodified lines | ||
| 7642 | 7641 | s1->nb_errors = 0; |
| 7643 | 7642 | s1->error_set_jmp_enabled = 1; |
| 7644 | 7643 | |
| 7645 | − ch = '\n'; /* needed to parse correctly first preprocessor command */ | |
| 7644 | + ch = '\n'; /* XXX: suppress that*/ | |
| 7645 | + tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF; | |
| 7646 | 7646 | next(); |
| 7647 | 7647 | decl(VT_CONST); |
| 7648 | 7648 | if (tok != -1) |