mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Add recursion limit for string expansions
Unlike macros, REPTs and INCLUDEs, this recursion depth is independent. This is intentional, because string expansions work very differently. While it's easy to know when a string expansion begins, checking where it ends is much more complicated, since the expansion's contents are simply injected back into the lex buffer. Therefore, the depth has to be checked after lexing took place. Because of this, the placement of the expansion end check is somewhat haphazard, but I think it's good. While I have no certainty, all tests ended with all expansions properly ended, and I couldn't find any pitfalls. Finally, `pCurrentStringExpansion` has been made global so error printing can use it to tell the user if an error occurred inside of an expansion.
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
|
||||
static struct sContext *pFileStack;
|
||||
static unsigned int nFileStackDepth;
|
||||
unsigned int nMaxFileStackDepth;
|
||||
unsigned int nMaxRecursionDepth;
|
||||
static struct sSymbol *pCurrentMacro;
|
||||
static YY_BUFFER_STATE CurrentFlexHandle;
|
||||
static FILE *pCurrentFile;
|
||||
@@ -62,8 +62,8 @@ static void pushcontext(void)
|
||||
{
|
||||
struct sContext **ppFileStack;
|
||||
|
||||
if (++nFileStackDepth > nMaxFileStackDepth)
|
||||
fatalerror("Recursion limit (%d) exceeded", nMaxFileStackDepth);
|
||||
if (++nFileStackDepth > nMaxRecursionDepth)
|
||||
fatalerror("Recursion limit (%d) exceeded", nMaxRecursionDepth);
|
||||
|
||||
ppFileStack = &pFileStack;
|
||||
while (*ppFileStack)
|
||||
|
||||
Reference in New Issue
Block a user