nested #if blocks now behave correctly

This commit is contained in:
Jeremiah Orians 2022-01-20 07:38:01 -05:00
parent 2043782a45
commit 533aeb1dfa
No known key found for this signature in database
GPG Key ID: 6B3A3F198708F894
1 changed files with 34 additions and 1 deletions

View File

@ -808,6 +808,38 @@ struct token_list* expand_macro_functions(struct token_list* expansion, struct t
return hold;
}
void eat_until_endif()
{
/* This #if block is nested inside of an #if block that needs to be dropped, lose EVERYTHING */
do
{
if(match("#if", macro_token->s) || match("#ifdef", macro_token->s) || match("#ifndef", macro_token->s))
{
eat_current_token();
eat_until_endif();
}
eat_current_token();
require(NULL != macro_token, "Unterminated #if block\n");
} while(!match("#endif", macro_token->s));
}
void eat_block()
{
/* This conditional #if block is wrong, drop everything until the #elif/#else/#endif */
do
{
if(match("#if", macro_token->s) || match("#ifdef", macro_token->s) || match("#ifndef", macro_token->s))
{
eat_current_token();
eat_until_endif();
}
eat_current_token();
require(NULL != macro_token, "Unterminated #if block\n");
} while(!match("#elif", macro_token->s) && !match("#else", macro_token->s) && !match("#endif", macro_token->s));
}
struct token_list* maybe_expand(struct token_list* token)
{
if(NULL == token)
@ -919,7 +951,8 @@ void preprocess()
else if(!conditional_inclusion_top->include)
{
/* rewrite the token stream to exclude the current token */
eat_current_token();
eat_block();
start_of_line = TRUE;
}
else
{