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