mirror of
https://github.com/rui314/chibicc
synced 2025-02-21 16:13:57 +03:00
Skip nested #if in a skipped #if-clause
This commit is contained in:
parent
bf6ff928ad
commit
aa570f3086
@ -53,10 +53,16 @@ static Token *append(Token *tok1, Token *tok2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip until next `#endif`.
|
// Skip until next `#endif`.
|
||||||
|
// Nested `#if` and `#endif` are skipped.
|
||||||
static Token *skip_cond_incl(Token *tok) {
|
static Token *skip_cond_incl(Token *tok) {
|
||||||
while (tok->kind != TK_EOF) {
|
while (tok->kind != TK_EOF) {
|
||||||
|
if (is_hash(tok) && equal(tok->next, "if")) {
|
||||||
|
tok = skip_cond_incl(tok->next->next);
|
||||||
|
tok = tok->next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (is_hash(tok) && equal(tok->next, "endif"))
|
if (is_hash(tok) && equal(tok->next, "endif"))
|
||||||
return tok;
|
break;
|
||||||
tok = tok->next;
|
tok = tok->next;
|
||||||
}
|
}
|
||||||
return tok;
|
return tok;
|
||||||
|
@ -17,6 +17,8 @@ int main() {
|
|||||||
#if 0
|
#if 0
|
||||||
#include "/no/such/file"
|
#include "/no/such/file"
|
||||||
assert(0, 1, "1");
|
assert(0, 1, "1");
|
||||||
|
#if nested
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int m = 0;
|
int m = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user