Unified · Split
| @@ -224,6 +224,7 @@ typedef struct TokenString { · 223 unmodified lines | ||
| 224 | 224 | struct BufferedFile *file; |
| 225 | 225 | int ch, ch1, tok, tok1; |
| 226 | 226 | CValue tokc, tok1c; |
| 227 | +int return_linefeed; /* if true, line feed is returned as a token */ | |
| 227 | 228 | |
| 228 | 229 | /* sections */ |
| 229 | 230 | Section **sections; |
| @@ -426,7 +427,8 @@ struct TCCState { · 196 unmodified lines | ||
| 426 | 427 | #define TOK_A_SHL 0x81 |
| 427 | 428 | #define TOK_A_SAR 0x82 |
| 428 | 429 | |
| 429 | −#define TOK_EOF (-1) /* end of file */ | |
| 430 | +#define TOK_EOF (-1) /* end of file */ | |
| 431 | +#define TOK_LINEFEED 10 /* line feed */ | |
| 430 | 432 | |
| 431 | 433 | /* all identificators and strings have token above that */ |
| 432 | 434 | #define TOK_IDENT 256 |
| @@ -1409,10 +1411,7 @@ int expr_preprocess(void) · 976 unmodified lines | ||
| 1409 | 1411 | TokenString str; |
| 1410 | 1412 | |
| 1411 | 1413 | tok_str_new(&str); |
| 1412 | − while (1) { | |
| 1413 | − skip_spaces(); | |
| 1414 | − if (ch == '\n') | |
| 1415 | − break; | |
| 1414 | + while (tok != TOK_LINEFEED && tok != TOK_EOF) { | |
| 1416 | 1415 | next(); /* do macro subst */ |
| 1417 | 1416 | if (tok == TOK_DEFINED) { |
| 1418 | 1417 | next_nomacro(); |
| @@ -1507,7 +1506,7 @@ void parse_define(void) · 88 unmodified lines | ||
| 1507 | 1506 | tok_str_add(&str, 0); |
| 1508 | 1507 | #ifdef PP_DEBUG |
| 1509 | 1508 | printf("define %s %d: ", get_tok_str(v, NULL), t); |
| 1510 | − tok_print(str); | |
| 1509 | + tok_print(str.str); | |
| 1511 | 1510 | #endif |
| 1512 | 1511 | s = sym_push1(&define_stack, v, t, (int)str.str); |
| 1513 | 1512 | s->next = first; |
| @@ -1521,6 +1520,7 @@ void preprocess(void) · 7 unmodified lines | ||
| 1521 | 1520 | BufferedFile *f; |
| 1522 | 1521 | Sym *s; |
| 1523 | 1522 | |
| 1523 | + return_linefeed = 1; /* linefeed will be returned as a token */ | |
| 1524 | 1524 | cinp(); |
| 1525 | 1525 | next_nomacro(); |
| 1526 | 1526 | redo: |
| @@ -1598,6 +1598,8 @@ void preprocess(void) · 71 unmodified lines | ||
| 1598 | 1598 | if (do_debug) { |
| 1599 | 1599 | put_stabs(file->filename, N_BINCL, 0, 0, 0); |
| 1600 | 1600 | } |
| 1601 | + ch = '\n'; | |
| 1602 | + goto the_end; | |
| 1601 | 1603 | } else if (tok == TOK_IFNDEF) { |
| 1602 | 1604 | c = 1; |
| 1603 | 1605 | goto do_ifdef; |
| @@ -1659,8 +1661,10 @@ void preprocess(void) · 55 unmodified lines | ||
| 1659 | 1661 | error("#error"); |
| 1660 | 1662 | } |
| 1661 | 1663 | /* ignore other preprocess commands or #! for C scripts */ |
| 1662 | − while (ch != '\n' && ch != -1) | |
| 1663 | − cinp(); | |
| 1664 | + while (tok != TOK_LINEFEED && tok != TOK_EOF) | |
| 1665 | + next_nomacro(); | |
| 1666 | + the_end: | |
| 1667 | + return_linefeed = 0; | |
| 1664 | 1668 | } |
| 1665 | 1669 | |
| 1666 | 1670 | /* read a number in base b */ |
| @@ -2043,6 +2047,11 @@ void next_nomacro1(void) · 376 unmodified lines | ||
| 2043 | 2047 | /* skip spaces */ |
| 2044 | 2048 | while(1) { |
| 2045 | 2049 | while (ch == '\n') { |
| 2050 | + /* during preprocessor parsing, '\n' is a token */ | |
| 2051 | + if (return_linefeed) { | |
| 2052 | + tok = TOK_LINEFEED; | |
| 2053 | + return; | |
| 2054 | + } | |
| 2046 | 2055 | cinp(); |
| 2047 | 2056 | while (ch == ' ' || ch == '\t') |
| 2048 | 2057 | cinp(); |
| @@ -2459,7 +2468,7 @@ void next(void) · 410 unmodified lines | ||
| 2459 | 2468 | } |
| 2460 | 2469 | } |
| 2461 | 2470 | #if defined(DEBUG) |
| 2462 | − printf("token = %s\n", get_tok_str(tok, tokc)); | |
| 2471 | + printf("token = %s\n", get_tok_str(tok, &tokc)); | |
| 2463 | 2472 | #endif |
| 2464 | 2473 | } |
| 2465 | 2474 | |