History

1 macro_push and macro_pop work I made a mistake, no matter the definition does not define can be macro_push. And the modified tcctest.c test 2, pack: in the compiler under the mode of s1->ppfp, I have no clear ideas1->ppfp Some advice thank you Roy to me.This patch, I hope I can pass the Roy test

jiang committed 12 years ago

Commit 196c9991 parent 276553c3 files · +40 −32Browse files

Unified · Split

3 files
  1. tcc.h +0 −1
  2. tccpp.c +12 −15
  3. tests/tcctest.c +28 −16
tcc.h+0−1
@@ -1132,7 +1132,6 @@ ST_DATA TokenSym **table_ident; · 1131 unmodified lines
11321132 returned at eof */
11331133 #define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */
11341134 #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
1135−#define PARSE_FLAG_PACK 0x0020 /* #pragma pack */
11361135
11371136 ST_FUNC TokenSym *tok_alloc(const char *str, int len);
11381137 ST_FUNC char *get_tok_str(int v, CValue *cv);
tccpp.c+12−15
@@ -1627,7 +1627,7 @@ skip: · 1626 unmodified lines
16271627 break;
16281628 case TOK_PRAGMA:
16291629 next();
1630− if (tok == TOK_pack && parse_flags & PARSE_FLAG_PACK) {
1630+ if (tok == TOK_pack && s1->output_type != TCC_OUTPUT_PREPROCESS) {
16311631 /*
16321632 This may be:
16331633 #pragma pack(1) // set
@@ -1736,32 +1736,29 @@ pack_error: · 102 unmodified lines
17361736 def = &ts->sym_define;
17371737 if(t == TOK_PUSH_MACRO){
17381738 void *tmp = def->data[def->off];
1739− if(tmp){
1740− def->off++;
1741− if(def->off >= def->size){
1742− int size = def->size;
1743− size *= 2;
1744− if (size > MACRO_STACK_SIZE)
1745− tcc_error("stack full");
1746− def->data = tcc_realloc(def->data, size*sizeof(Sym*));
1747− def->size = size;
1748− }
1749− def->data[def->off] = tmp;
1739+ def->off++;
1740+ if(def->off >= def->size){
1741+ int size = def->size;
1742+ size *= 2;
1743+ if (size > MACRO_STACK_SIZE)
1744+ tcc_error("stack full");
1745+ def->data = tcc_realloc(def->data, size*sizeof(Sym*));
1746+ def->size = size;
17501747 }
1748+ def->data[def->off] = tmp;
17511749 }else{
17521750 if(def->off){
17531751 --def->off;
1754− }else{
1755− tcc_warning("stack empty");
17561752 }
17571753 }
17581754 }
1759− }else{
1755+ }else if(s1->output_type == TCC_OUTPUT_PREPROCESS){
17601756 fputs("#pragma ", s1->ppfp);
17611757 while (tok != TOK_LINEFEED){
17621758 fputs(get_tok_str(tok, &tokc), s1->ppfp);
17631759 next();
17641760 }
1761+ fputs("\n", s1->ppfp);
17651762 goto the_end;
17661763 }
17671764 break;
tests/tcctest.c+28−16
@@ -379,34 +379,46 @@ comment · 378 unmodified lines
379379 /* And again when the name and parenthes are separated by a
380380 comment. */
381381 TEST2 /* the comment */ ();
382+
382383 /* macro_push and macro_pop test */
383− #define MACRO_TEST "macro_test1\n"
384− #pragma push_macro("MACRO_TEST")
385− printf(MACRO_TEST);
386384 #undef MACRO_TEST
385+ #ifdef MACRO_TEST
386+ printf("define MACRO_TEST\n");
387+ #else
388+ printf("undef MACRO_TEST\n");
389+ #endif
387390
388− #define MACRO_TEST "macro_test2\n"
389391 #pragma push_macro("MACRO_TEST")
390− printf(MACRO_TEST);
391− #undef MACRO_TEST
392−
393− #define MACRO_TEST "macro_test3\n"
392+ #define MACRO_TEST
394393 #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);
400394 #undef MACRO_TEST
395+ #pragma push_macro("MACRO_TEST")
401396
402397 #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
404403
405404 #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
407410
408411 #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+
410422 /* gcc does not support
411423 #define MACRO_TEST_MACRO "MACRO_TEST"
412424 #pragma push_macro(MACRO_TEST_MACRO)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t