Unified · Split
| @@ -1132,7 +1132,6 @@ ST_DATA TokenSym **table_ident; · 1131 unmodified lines | |||
| 1132 | returned at eof */ | 1132 | returned at eof */ |
| 1133 | #define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */ | 1133 | #define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */ |
| 1134 | #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */ | 1134 | #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */ |
| 1135 | #define PARSE_FLAG_PACK 0x0020 /* #pragma pack */ | ||
| 1136 | 1135 | ||
| 1137 | ST_FUNC TokenSym *tok_alloc(const char *str, int len); | 1136 | ST_FUNC TokenSym *tok_alloc(const char *str, int len); |
| 1138 | ST_FUNC char *get_tok_str(int v, CValue *cv); | 1137 | ST_FUNC char *get_tok_str(int v, CValue *cv); |
| @@ -1627,7 +1627,7 @@ skip: · 1626 unmodified lines | |||
| 1627 | break; | 1627 | break; |
| 1628 | case TOK_PRAGMA: | 1628 | case TOK_PRAGMA: |
| 1629 | next(); | 1629 | next(); |
| 1630 | if (tok == TOK_pack && parse_flags & PARSE_FLAG_PACK) { | 1630 | if (tok == TOK_pack && s1->output_type != TCC_OUTPUT_PREPROCESS) { |
| 1631 | /* | 1631 | /* |
| 1632 | This may be: | 1632 | This may be: |
| 1633 | #pragma pack(1) // set | 1633 | #pragma pack(1) // set |
| @@ -1736,32 +1736,29 @@ pack_error: · 102 unmodified lines | |||
| 1736 | def = &ts->sym_define; | 1736 | def = &ts->sym_define; |
| 1737 | if(t == TOK_PUSH_MACRO){ | 1737 | if(t == TOK_PUSH_MACRO){ |
| 1738 | void *tmp = def->data[def->off]; | 1738 | void *tmp = def->data[def->off]; |
| 1739 | if(tmp){ | 1739 | def->off++; |
| 1740 | def->off++; | 1740 | if(def->off >= def->size){ |
| 1741 | if(def->off >= def->size){ | 1741 | int size = def->size; |
| 1742 | int size = def->size; | 1742 | size *= 2; |
| 1743 | size *= 2; | 1743 | if (size > MACRO_STACK_SIZE) |
| 1744 | if (size > MACRO_STACK_SIZE) | 1744 | tcc_error("stack full"); |
| 1745 | tcc_error("stack full"); | 1745 | def->data = tcc_realloc(def->data, size*sizeof(Sym*)); |
| 1746 | def->data = tcc_realloc(def->data, size*sizeof(Sym*)); | 1746 | def->size = size; |
| 1747 | def->size = size; | ||
| 1748 | } | ||
| 1749 | def->data[def->off] = tmp; | ||
| 1750 | } | 1747 | } |
| 1748 | def->data[def->off] = tmp; | ||
| 1751 | }else{ | 1749 | }else{ |
| 1752 | if(def->off){ | 1750 | if(def->off){ |
| 1753 | --def->off; | 1751 | --def->off; |
| 1754 | }else{ | ||
| 1755 | tcc_warning("stack empty"); | ||
| 1756 | } | 1752 | } |
| 1757 | } | 1753 | } |
| 1758 | } | 1754 | } |
| 1759 | }else{ | 1755 | }else if(s1->output_type == TCC_OUTPUT_PREPROCESS){ |
| 1760 | fputs("#pragma ", s1->ppfp); | 1756 | fputs("#pragma ", s1->ppfp); |
| 1761 | while (tok != TOK_LINEFEED){ | 1757 | while (tok != TOK_LINEFEED){ |
| 1762 | fputs(get_tok_str(tok, &tokc), s1->ppfp); | 1758 | fputs(get_tok_str(tok, &tokc), s1->ppfp); |
| 1763 | next(); | 1759 | next(); |
| 1764 | } | 1760 | } |
| 1761 | fputs("\n", s1->ppfp); | ||
| 1765 | goto the_end; | 1762 | goto the_end; |
| 1766 | } | 1763 | } |
| 1767 | break; | 1764 | break; |
| @@ -379,34 +379,46 @@ comment · 378 unmodified lines | |||
| 379 | /* And again when the name and parenthes are separated by a | 379 | /* And again when the name and parenthes are separated by a |
| 380 | comment. */ | 380 | comment. */ |
| 381 | TEST2 /* the comment */ (); | 381 | TEST2 /* the comment */ (); |
| 382 | |||
| 382 | /* macro_push and macro_pop test */ | 383 | /* macro_push and macro_pop test */ |
| 383 | #define MACRO_TEST "macro_test1\n" | ||
| 384 | #pragma push_macro("MACRO_TEST") | ||
| 385 | printf(MACRO_TEST); | ||
| 386 | #undef MACRO_TEST | 384 | #undef MACRO_TEST |
| 385 | #ifdef MACRO_TEST | ||
| 386 | printf("define MACRO_TEST\n"); | ||
| 387 | #else | ||
| 388 | printf("undef MACRO_TEST\n"); | ||
| 389 | #endif | ||
| 387 | 390 | ||
| 388 | #define MACRO_TEST "macro_test2\n" | ||
| 389 | #pragma push_macro("MACRO_TEST") | 391 | #pragma push_macro("MACRO_TEST") |
| 390 | printf(MACRO_TEST); | 392 | #define MACRO_TEST |
| 391 | #undef MACRO_TEST | ||
| 392 | |||
| 393 | #define MACRO_TEST "macro_test3\n" | ||
| 394 | #pragma push_macro("MACRO_TEST") | 393 | #pragma push_macro("MACRO_TEST") |
| 395 | printf(MACRO_TEST); | ||
| 396 | #undef MACRO_TEST | ||
| 397 | |||
| 398 | #define MACRO_TEST "macro_test4\n" | ||
| 399 | printf(MACRO_TEST); | ||
| 400 | #undef MACRO_TEST | 394 | #undef MACRO_TEST |
| 395 | #pragma push_macro("MACRO_TEST") | ||
| 401 | 396 | ||
| 402 | #pragma pop_macro("MACRO_TEST") | 397 | #pragma pop_macro("MACRO_TEST") |
| 403 | printf(MACRO_TEST); | 398 | #ifdef MACRO_TEST |
| 399 | printf("define MACRO_TEST\n"); | ||
| 400 | #else | ||
| 401 | printf("undef MACRO_TEST\n"); | ||
| 402 | #endif | ||
| 404 | 403 | ||
| 405 | #pragma pop_macro("MACRO_TEST") | 404 | #pragma pop_macro("MACRO_TEST") |
| 406 | printf(MACRO_TEST); | 405 | #ifdef MACRO_TEST |
| 406 | printf("define MACRO_TEST\n"); | ||
| 407 | #else | ||
| 408 | printf("undef MACRO_TEST\n"); | ||
| 409 | #endif | ||
| 407 | 410 | ||
| 408 | #pragma pop_macro("MACRO_TEST") | 411 | #pragma pop_macro("MACRO_TEST") |
| 409 | printf(MACRO_TEST); | 412 | #ifdef MACRO_TEST |
| 413 | printf("define MACRO_TEST\n"); | ||
| 414 | #else | ||
| 415 | printf("undef MACRO_TEST\n"); | ||
| 416 | #endif | ||
| 417 | |||
| 418 | /* pack test */ | ||
| 419 | #pragma pack(push,8) | ||
| 420 | #pragma pack(pop) | ||
| 421 | |||
| 410 | /* gcc does not support | 422 | /* gcc does not support |
| 411 | #define MACRO_TEST_MACRO "MACRO_TEST" | 423 | #define MACRO_TEST_MACRO "MACRO_TEST" |
| 412 | #pragma push_macro(MACRO_TEST_MACRO) | 424 | #pragma push_macro(MACRO_TEST_MACRO) |