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
764764 int get_reg(int rc);
765765 int get_reg_ex(int rc,int rc2);
766766
767+struct macro_level {
768+ struct macro_level *prev;
769+ int *p;
770+};
771+
767772 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);
769774 void gen_op(int op);
770775 void force_charshort_cast(int t);
771776 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
39803985 } else {
39813986 /* NOTE: the stream cannot be read when macro
39823987 substituing an argument */
3983− macro_subst(&str, nested_list, st, 0);
3988+ macro_subst(&str, nested_list, st, NULL);
39843989 }
39853990 } else {
39863991 tok_str_add(&str, t);
@@ -4005,7 +4010,7 @@ static char const ab_month_name[12][4] = · 18 unmodified lines
40054010 macros we got inside to avoid recursing. Return non zero if no
40064011 substitution needs to be done */
40074012 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)
40094014 {
40104015 Sym *args, *sa, *sa1;
40114016 int mstr_allocated, parlevel, *mstr, t, t1;
@@ -4054,16 +4059,23 @@ static int macro_subst_tok(TokenString *tok_str, · 42 unmodified lines
40544059 if (s->type.t == MACRO_FUNC) {
40554060 /* NOTE: we do not use next_nomacro to avoid eating the
40564061 next token. XXX: find better solution */
4062+ redo:
40574063 if (macro_ptr) {
40584064 t = *macro_ptr;
40594065 if (t == 0 && can_read_stream) {
40604066 /* end of macro stream: we must look at the token
40614067 after in the file */
4068+ struct macro_level *ml = *can_read_stream;
40624069 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;
40644077 }
40654078 } else {
4066− parse_stream:
40674079 /* XXX: incorrect with comments */
40684080 ch = file->buf_ptr[0];
40694081 while (is_space(ch) || ch == '\n')
@@ -4133,7 +4145,7 @@ static int macro_subst_tok(TokenString *tok_str, · 63 unmodified lines
41334145 mstr_allocated = 1;
41344146 }
41354147 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);
41374149 /* pop nested defined symbol */
41384150 sa1 = *nested_list;
41394151 *nested_list = sa1->prev;
@@ -4281,13 +4293,14 @@ static inline int *macro_twosharps(const int *macro_str) · 141 unmodified lines
42814293 (tok_str,tok_len). 'nested_list' is the list of all macros we got
42824294 inside to avoid recursing. */
42834295 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)
42854297 {
42864298 Sym *s;
4287− int *saved_macro_ptr, *macro_str1;
4299+ int *macro_str1;
42884300 const int *ptr;
42894301 int t, ret;
42904302 CValue cval;
4303+ struct macro_level ml;
42914304
42924305 /* first scan for '##' operator handling */
42934306 ptr = macro_str;
@@ -4307,12 +4320,16 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 13 unmodified lines
43074320 /* if nested substitution, do nothing */
43084321 if (sym_find2(*nested_list, t))
43094322 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;
43114326 macro_ptr = (int *)ptr;
43124327 tok = t;
43134328 ret = macro_subst_tok(tok_str, nested_list, s, can_read_stream);
43144329 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;
43164333 if (ret != 0)
43174334 goto no_subst;
43184335 } else {
@@ -4329,6 +4346,7 @@ static void next(void) · 10 unmodified lines
43294346 {
43304347 Sym *nested_list, *s;
43314348 TokenString str;
4349+ struct macro_level *ml;
43324350
43334351 redo:
43344352 next_nomacro();
@@ -4342,7 +4360,8 @@ static void next(void) · 7 unmodified lines
43424360 /* we have a macro: we try to substitute */
43434361 tok_str_new(&str);
43444362 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) {
43464365 /* substitution done, NOTE: maybe empty */
43474366 tok_str_add(&str, 0);
43484367 macro_ptr = str.str;
@@ -9747,7 +9766,8 @@ TCCState *tcc_new(void) · 5398 unmodified lines
97479766 #ifdef CHAR_IS_UNSIGNED
97489767 s->char_is_unsigned = 1;
97499768 #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 */
97519771 s->leading_underscore = 1;
97529772 #endif
97539773 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