diff options
| author | Joe Soroka <gits@joesoroka.com> | 2011-02-01 13:23:40 -0800 |
|---|---|---|
| committer | Joe Soroka <gits@joesoroka.com> | 2011-02-01 13:23:40 -0800 |
| commit | 75c6695932b55b914f16b20dc32ff3ef1203ed4b (patch) | |
| tree | ce7a5642124f1be01525eacb5cff8baddaf5629e /tccpp.c | |
| parent | cf08675702044c180553c866ba1fde0414f00590 (diff) | |
| download | tinycc-75c6695932b55b914f16b20dc32ff3ef1203ed4b.tar.gz tinycc-75c6695932b55b914f16b20dc32ff3ef1203ed4b.tar.bz2 | |
tccpp: fix bug in handling of recursive macros
Diffstat (limited to 'tccpp.c')
| -rw-r--r-- | tccpp.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -2797,7 +2797,8 @@ static inline int *macro_twosharps(const int *macro_str) if (tok == TOK_TWOSHARPS) continue; while (*ptr == TOK_TWOSHARPS) { - t = *++ptr; + do { t = *++ptr; } while (t == TOK_NOSUBST); + if (t && t != TOK_TWOSHARPS) { TOK_GET(&t, &ptr, &cval); @@ -2856,11 +2857,20 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, TOK_GET(&t, &ptr, &cval); if (t == 0) break; + if (t == TOK_NOSUBST) { + /* following token has already been subst'd. just copy it on */ + tok_str_add2(tok_str, TOK_NOSUBST, NULL); + TOK_GET(&t, &ptr, &cval); + goto no_subst; + } s = define_find(t); if (s != NULL) { /* if nested substitution, do nothing */ - if (sym_find2(*nested_list, t)) + if (sym_find2(*nested_list, t)) { + /* and mark it as TOK_NOSUBST, so it doesn't get subst'd again */ + tok_str_add2(tok_str, TOK_NOSUBST, NULL); goto no_subst; + } ml.p = macro_ptr; if (can_read_stream) ml.prev = *can_read_stream, *can_read_stream = &ml; @@ -2928,6 +2938,9 @@ ST_FUNC void next(void) macro_ptr = NULL; } goto redo; + } else if (tok == TOK_NOSUBST) { + /* discard preprocessor's nosubst markers */ + goto redo; } } |
