Unified · Split
| @@ -764,8 +764,13 @@ void vdup(void); · 763 unmodified lines | ||
| 764 | 764 | int get_reg(int rc); |
| 765 | 765 | int get_reg_ex(int rc,int rc2); |
| 766 | 766 | |
| 767 | +struct macro_level { | |
| 768 | + struct macro_level *prev; | |
| 769 | + int *p; | |
| 770 | +}; | |
| 771 | + | |
| 767 | 772 | static void macro_subst(TokenString *tok_str, Sym **nested_list, |
| 768 | − const int *macro_str, int can_read_stream); | |
| 773 | + const int *macro_str, struct macro_level **can_read_stream); | |
| 769 | 774 | void gen_op(int op); |
| 770 | 775 | void force_charshort_cast(int t); |
| 771 | 776 | static void gen_cast(CType *type); |
| @@ -3980,7 +3985,7 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args) · 3208 unmodified lines | ||
| 3980 | 3985 | } else { |
| 3981 | 3986 | /* NOTE: the stream cannot be read when macro |
| 3982 | 3987 | substituing an argument */ |
| 3983 | − macro_subst(&str, nested_list, st, 0); | |
| 3988 | + macro_subst(&str, nested_list, st, NULL); | |
| 3984 | 3989 | } |
| 3985 | 3990 | } else { |
| 3986 | 3991 | tok_str_add(&str, t); |
| @@ -4005,7 +4010,7 @@ static char const ab_month_name[12][4] = · 18 unmodified lines | ||
| 4005 | 4010 | macros we got inside to avoid recursing. Return non zero if no |
| 4006 | 4011 | substitution needs to be done */ |
| 4007 | 4012 | static int macro_subst_tok(TokenString *tok_str, |
| 4008 | − Sym **nested_list, Sym *s, int can_read_stream) | |
| 4013 | + Sym **nested_list, Sym *s, struct macro_level **can_read_stream) | |
| 4009 | 4014 | { |
| 4010 | 4015 | Sym *args, *sa, *sa1; |
| 4011 | 4016 | int mstr_allocated, parlevel, *mstr, t, t1; |
| @@ -4054,16 +4059,23 @@ static int macro_subst_tok(TokenString *tok_str, · 42 unmodified lines | ||
| 4054 | 4059 | if (s->type.t == MACRO_FUNC) { |
| 4055 | 4060 | /* NOTE: we do not use next_nomacro to avoid eating the |
| 4056 | 4061 | next token. XXX: find better solution */ |
| 4062 | + redo: | |
| 4057 | 4063 | if (macro_ptr) { |
| 4058 | 4064 | t = *macro_ptr; |
| 4059 | 4065 | if (t == 0 && can_read_stream) { |
| 4060 | 4066 | /* end of macro stream: we must look at the token |
| 4061 | 4067 | after in the file */ |
| 4068 | + struct macro_level *ml = *can_read_stream; | |
| 4062 | 4069 | macro_ptr = NULL; |
| 4063 | − goto parse_stream; | |
| 4070 | + if (ml) | |
| 4071 | + { | |
| 4072 | + macro_ptr = ml->p; | |
| 4073 | + ml->p = NULL; | |
| 4074 | + *can_read_stream = ml -> prev; | |
| 4075 | + } | |
| 4076 | + goto redo; | |
| 4064 | 4077 | } |
| 4065 | 4078 | } else { |
| 4066 | − parse_stream: | |
| 4067 | 4079 | /* XXX: incorrect with comments */ |
| 4068 | 4080 | ch = file->buf_ptr[0]; |
| 4069 | 4081 | while (is_space(ch) || ch == '\n') |
| @@ -4133,7 +4145,7 @@ static int macro_subst_tok(TokenString *tok_str, · 63 unmodified lines | ||
| 4133 | 4145 | mstr_allocated = 1; |
| 4134 | 4146 | } |
| 4135 | 4147 | sym_push2(nested_list, s->v, 0, 0); |
| 4136 | − macro_subst(tok_str, nested_list, mstr, 1); | |
| 4148 | + macro_subst(tok_str, nested_list, mstr, can_read_stream); | |
| 4137 | 4149 | /* pop nested defined symbol */ |
| 4138 | 4150 | sa1 = *nested_list; |
| 4139 | 4151 | *nested_list = sa1->prev; |
| @@ -4281,13 +4293,14 @@ static inline int *macro_twosharps(const int *macro_str) · 141 unmodified lines | ||
| 4281 | 4293 | (tok_str,tok_len). 'nested_list' is the list of all macros we got |
| 4282 | 4294 | inside to avoid recursing. */ |
| 4283 | 4295 | static void macro_subst(TokenString *tok_str, Sym **nested_list, |
| 4284 | − const int *macro_str, int can_read_stream) | |
| 4296 | + const int *macro_str, struct macro_level ** can_read_stream) | |
| 4285 | 4297 | { |
| 4286 | 4298 | Sym *s; |
| 4287 | − int *saved_macro_ptr, *macro_str1; | |
| 4299 | + int *macro_str1; | |
| 4288 | 4300 | const int *ptr; |
| 4289 | 4301 | int t, ret; |
| 4290 | 4302 | CValue cval; |
| 4303 | + struct macro_level ml; | |
| 4291 | 4304 | |
| 4292 | 4305 | /* first scan for '##' operator handling */ |
| 4293 | 4306 | ptr = macro_str; |
| @@ -4307,12 +4320,16 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 13 unmodified lines | ||
| 4307 | 4320 | /* if nested substitution, do nothing */ |
| 4308 | 4321 | if (sym_find2(*nested_list, t)) |
| 4309 | 4322 | goto no_subst; |
| 4310 | − saved_macro_ptr = macro_ptr; | |
| 4323 | + ml.p = macro_ptr; | |
| 4324 | + if (can_read_stream) | |
| 4325 | + ml.prev = *can_read_stream, *can_read_stream = &ml; | |
| 4311 | 4326 | macro_ptr = (int *)ptr; |
| 4312 | 4327 | tok = t; |
| 4313 | 4328 | ret = macro_subst_tok(tok_str, nested_list, s, can_read_stream); |
| 4314 | 4329 | ptr = (int *)macro_ptr; |
| 4315 | − macro_ptr = saved_macro_ptr; | |
| 4330 | + macro_ptr = ml.p; | |
| 4331 | + if (can_read_stream && *can_read_stream == &ml) | |
| 4332 | + *can_read_stream = ml.prev; | |
| 4316 | 4333 | if (ret != 0) |
| 4317 | 4334 | goto no_subst; |
| 4318 | 4335 | } else { |
| @@ -4329,6 +4346,7 @@ static void next(void) · 10 unmodified lines | ||
| 4329 | 4346 | { |
| 4330 | 4347 | Sym *nested_list, *s; |
| 4331 | 4348 | TokenString str; |
| 4349 | + struct macro_level *ml; | |
| 4332 | 4350 | |
| 4333 | 4351 | redo: |
| 4334 | 4352 | next_nomacro(); |
| @@ -4342,7 +4360,8 @@ static void next(void) · 7 unmodified lines | ||
| 4342 | 4360 | /* we have a macro: we try to substitute */ |
| 4343 | 4361 | tok_str_new(&str); |
| 4344 | 4362 | nested_list = NULL; |
| 4345 | − if (macro_subst_tok(&str, &nested_list, s, 1) == 0) { | |
| 4363 | + ml = NULL; | |
| 4364 | + if (macro_subst_tok(&str, &nested_list, s, &ml) == 0) { | |
| 4346 | 4365 | /* substitution done, NOTE: maybe empty */ |
| 4347 | 4366 | tok_str_add(&str, 0); |
| 4348 | 4367 | macro_ptr = str.str; |
| @@ -9747,7 +9766,8 @@ TCCState *tcc_new(void) · 5398 unmodified lines | ||
| 9747 | 9766 | #ifdef CHAR_IS_UNSIGNED |
| 9748 | 9767 | s->char_is_unsigned = 1; |
| 9749 | 9768 | #endif |
| 9750 | −#ifdef TCC_TARGET_PE | |
| 9769 | +#if defined(TCC_TARGET_PE) && 0 | |
| 9770 | + /* XXX: currently the PE linker is not ready to support that */ | |
| 9751 | 9771 | s->leading_underscore = 1; |
| 9752 | 9772 | #endif |
| 9753 | 9773 | return s; |