Fix incorrect error reporting of INCLUDEd files

This commit is contained in:
ISSOtm
2020-08-17 12:00:28 +02:00
parent 35396e6410
commit 4d1333e124

View File

@@ -33,6 +33,7 @@ struct Context {
struct LexerState *lexerState; struct LexerState *lexerState;
uint32_t uniqueID; uint32_t uniqueID;
char const *fileName; char const *fileName;
char *fileNameBuf;
uint32_t lineNo; /* Line number at which the context was EXITED */ uint32_t lineNo; /* Line number at which the context was EXITED */
struct Symbol const *macro; struct Symbol const *macro;
uint32_t nbReptIters; /* If zero, this isn't a REPT block */ uint32_t nbReptIters; /* If zero, this isn't a REPT block */
@@ -153,6 +154,10 @@ bool yywrap(void)
} }
dbgPrint("Popping context\n"); dbgPrint("Popping context\n");
/* Free an `INCLUDE`'s path */
if (contextStack->fileNameBuf)
free(contextStack->fileNameBuf);
contextStack = contextStack->parent; contextStack = contextStack->parent;
contextDepth--; contextDepth--;
@@ -206,7 +211,8 @@ void fstk_RunInclude(char const *path)
/* We're back at top-level, so most things are reset */ /* We're back at top-level, so most things are reset */
contextStack->uniqueID = 0; contextStack->uniqueID = 0;
macro_SetUniqueID(0); macro_SetUniqueID(0);
contextStack->fileName = lexer_GetFileName(); contextStack->fileName = fullPath;
contextStack->fileNameBuf = fullPath;
contextStack->macro = NULL; contextStack->macro = NULL;
contextStack->nbReptIters = 0; contextStack->nbReptIters = 0;
} }
@@ -236,6 +242,7 @@ void fstk_RunMacro(char *macroName, struct MacroArgs *args)
lexer_SetStateAtEOL(contextStack->lexerState); lexer_SetStateAtEOL(contextStack->lexerState);
contextStack->uniqueID = macro_UseNewUniqueID(); contextStack->uniqueID = macro_UseNewUniqueID();
contextStack->fileName = macro->fileName; contextStack->fileName = macro->fileName;
contextStack->fileNameBuf = NULL;
contextStack->macro = macro; contextStack->macro = macro;
contextStack->nbReptIters = 0; contextStack->nbReptIters = 0;
} }
@@ -253,6 +260,7 @@ void fstk_RunRept(uint32_t count, int32_t nReptLineNo, char *body, size_t size)
lexer_SetStateAtEOL(contextStack->lexerState); lexer_SetStateAtEOL(contextStack->lexerState);
contextStack->uniqueID = macro_UseNewUniqueID(); contextStack->uniqueID = macro_UseNewUniqueID();
contextStack->fileName = contextStack->parent->fileName; contextStack->fileName = contextStack->parent->fileName;
contextStack->fileNameBuf = NULL;
contextStack->macro = contextStack->parent->macro; /* Inherit */ contextStack->macro = contextStack->parent->macro; /* Inherit */
contextStack->nbReptIters = count; contextStack->nbReptIters = count;
/* Copy all of parent's iters, and add ours */ /* Copy all of parent's iters, and add ours */
@@ -354,6 +362,7 @@ void fstk_Init(char *mainPath, uint32_t maxRecursionDepth)
topLevelContext->uniqueID = 0; topLevelContext->uniqueID = 0;
macro_SetUniqueID(0); macro_SetUniqueID(0);
topLevelContext->fileName = lexer_GetFileName(); topLevelContext->fileName = lexer_GetFileName();
topLevelContext->fileNameBuf = NULL;
topLevelContext->macro = NULL; topLevelContext->macro = NULL;
topLevelContext->nbReptIters = 0; topLevelContext->nbReptIters = 0;
topLevelContext->reptDepth = 0; topLevelContext->reptDepth = 0;