History

preprocessor function macro parsing fix (grischka) - disabled -fleading-underscore for win32

bellard committed 21 years ago

Commit 4d7eadb1 parent c262e9e1 file · +32 −12Browse files

Unified · Split

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

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