Store IF depth relative to each fstack context

This disallows starting/ending an IF inside an
INCLUDEd file or a macro expansion
This commit is contained in:
Rangi
2021-01-08 16:28:51 -05:00
committed by Eldred Habert
parent 62bea23c49
commit cab9cb06a3
12 changed files with 64 additions and 21 deletions

View File

@@ -1966,7 +1966,7 @@ static int skipIfBlock(bool toEndc)
{
dbgPrint("Skipping IF block (toEndc = %s)\n", toEndc ? "true" : "false");
lexer_SetMode(LEXER_NORMAL);
int startingDepth = nIFDepth;
int startingDepth = fstk_GetIFDepth();
int token;
bool atLineStart = lexerState->atLineStart;
@@ -1990,7 +1990,7 @@ static int skipIfBlock(bool toEndc)
token = readIdentifier(c);
switch (token) {
case T_POP_IF:
nIFDepth++;
fstk_IncIFDepth();
break;
case T_POP_ELIF:
@@ -1999,10 +1999,10 @@ static int skipIfBlock(bool toEndc)
break;
/* fallthrough */
case T_POP_ENDC:
if (nIFDepth == startingDepth)
if (fstk_GetIFDepth() == startingDepth)
goto finish;
if (token == T_POP_ENDC)
nIFDepth--;
fstk_DecIFDepth();
}
}
atLineStart = false;
@@ -2087,11 +2087,11 @@ static int yylex_SKIP_TO_ENDR(void)
break;
case T_POP_IF:
nIFDepth++;
fstk_IncIFDepth();
break;
case T_POP_ENDC:
nIFDepth--;
fstk_DecIFDepth();
}
}
atLineStart = false;