History

fixed macro argument substitution

bellard committed 23 years ago

Commit 6cdf6f81 parent 59087251 file · +12 −10Browse files

Unified · Split

tcc.c+12−10
@@ -681,8 +681,8 @@ void vswap(void); · 680 unmodified lines
681681 void vdup(void);
682682 int get_reg(int rc);
683683
684−static void macro_subst(TokenString *tok_str,
685− Sym **nested_list, const int *macro_str);
684+static void macro_subst(TokenString *tok_str, Sym **nested_list,
685+ const int *macro_str, int can_read_stream);
686686 int save_reg_forced(int r);
687687 void gen_op(int op);
688688 void force_charshort_cast(int t);
@@ -3711,7 +3711,9 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args) · 3022 unmodified lines
37113711 }
37123712 }
37133713 } else {
3714− macro_subst(&str, nested_list, st);
3714+ /* NOTE: the stream cannot be read when macro
3715+ substituing an argument */
3716+ macro_subst(&str, nested_list, st, 0);
37153717 }
37163718 } else {
37173719 tok_str_add(&str, t);
@@ -3736,7 +3738,7 @@ static char const ab_month_name[12][4] = · 18 unmodified lines
37363738 macros we got inside to avoid recursing. Return non zero if no
37373739 substitution needs to be done */
37383740 static int macro_subst_tok(TokenString *tok_str,
3739− Sym **nested_list, Sym *s)
3741+ Sym **nested_list, Sym *s, int can_read_stream)
37403742 {
37413743 Sym *args, *sa, *sa1;
37423744 int mstr_allocated, parlevel, *mstr, t;
@@ -3785,7 +3787,7 @@ static int macro_subst_tok(TokenString *tok_str, · 42 unmodified lines
37853787 next token. XXX: find better solution */
37863788 if (macro_ptr) {
37873789 t = *macro_ptr;
3788− if (t == 0) {
3790+ if (t == 0 && can_read_stream) {
37893791 /* end of macro stream: we must look at the token
37903792 after in the file */
37913793 macro_ptr = NULL;
@@ -3862,7 +3864,7 @@ static int macro_subst_tok(TokenString *tok_str, · 70 unmodified lines
38623864 mstr_allocated = 1;
38633865 }
38643866 sym_push2(nested_list, s->v, 0, 0);
3865− macro_subst(tok_str, nested_list, mstr);
3867+ macro_subst(tok_str, nested_list, mstr, 1);
38663868 /* pop nested defined symbol */
38673869 sa1 = *nested_list;
38683870 *nested_list = sa1->prev;
@@ -4009,8 +4011,8 @@ static inline int *macro_twosharps(const int *macro_str) · 140 unmodified lines
40094011 /* do macro substitution of macro_str and add result to
40104012 (tok_str,tok_len). 'nested_list' is the list of all macros we got
40114013 inside to avoid recursing. */
4012−static void macro_subst(TokenString *tok_str,
4013− Sym **nested_list, const int *macro_str)
4014+static void macro_subst(TokenString *tok_str, Sym **nested_list,
4015+ const int *macro_str, int can_read_stream)
40144016 {
40154017 Sym *s;
40164018 int *saved_macro_ptr, *macro_str1;
@@ -4039,7 +4041,7 @@ static void macro_subst(TokenString *tok_str, · 22 unmodified lines
40394041 saved_macro_ptr = macro_ptr;
40404042 macro_ptr = (int *)ptr;
40414043 tok = t;
4042− ret = macro_subst_tok(tok_str, nested_list, s);
4044+ ret = macro_subst_tok(tok_str, nested_list, s, can_read_stream);
40434045 ptr = (int *)macro_ptr;
40444046 macro_ptr = saved_macro_ptr;
40454047 if (ret != 0)
@@ -4071,7 +4073,7 @@ static void next(void) · 25 unmodified lines
40714073 /* we have a macro: we try to substitute */
40724074 tok_str_new(&str);
40734075 nested_list = NULL;
4074− if (macro_subst_tok(&str, &nested_list, s) == 0) {
4076+ if (macro_subst_tok(&str, &nested_list, s, 1) == 0) {
40754077 /* substitution done, NOTE: maybe empty */
40764078 tok_str_add(&str, 0);
40774079 macro_ptr = str.str;