mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Remove dbgPrint and TRACE_LEXER support
I have not found `TRACE_LEXER` to be useful in debugging actual lexer issues.
This commit is contained in:
@@ -26,7 +26,6 @@ endif()
|
|||||||
option(SANITIZERS "Build with sanitizers enabled" OFF) # Ignored on MSVC
|
option(SANITIZERS "Build with sanitizers enabled" OFF) # Ignored on MSVC
|
||||||
option(MORE_WARNINGS "Turn on more warnings" OFF) # Ignored on MSVC
|
option(MORE_WARNINGS "Turn on more warnings" OFF) # Ignored on MSVC
|
||||||
option(TRACE_PARSER "Trace parser execution" OFF)
|
option(TRACE_PARSER "Trace parser execution" OFF)
|
||||||
option(TRACE_LEXER "Trace lexer execution" OFF)
|
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
# MSVC's standard library triggers warning C5105,
|
# MSVC's standard library triggers warning C5105,
|
||||||
@@ -93,7 +92,3 @@ endif()
|
|||||||
if(TRACE_PARSER)
|
if(TRACE_PARSER)
|
||||||
target_compile_definitions(rgbasm PRIVATE -DYYDEBUG)
|
target_compile_definitions(rgbasm PRIVATE -DYYDEBUG)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(TRACE_LEXER)
|
|
||||||
target_compile_definitions(rgbasm PRIVATE -DLEXER_DEBUG)
|
|
||||||
endif()
|
|
||||||
|
|||||||
@@ -23,12 +23,6 @@
|
|||||||
|
|
||||||
#define MAXINCPATHS 128
|
#define MAXINCPATHS 128
|
||||||
|
|
||||||
#ifdef LEXER_DEBUG
|
|
||||||
#define dbgPrint(...) fprintf(stderr, "[fstack] " __VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define dbgPrint(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct Context {
|
struct Context {
|
||||||
struct Context *parent;
|
struct Context *parent;
|
||||||
struct FileStackNode *fileInfo;
|
struct FileStackNode *fileInfo;
|
||||||
@@ -259,7 +253,6 @@ bool yywrap(void)
|
|||||||
} else if (!contextStack->parent) {
|
} else if (!contextStack->parent) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
dbgPrint("Popping context\n");
|
|
||||||
|
|
||||||
struct Context *context = contextStack;
|
struct Context *context = contextStack;
|
||||||
|
|
||||||
@@ -269,10 +262,8 @@ bool yywrap(void)
|
|||||||
|
|
||||||
lexer_DeleteState(context->lexerState);
|
lexer_DeleteState(context->lexerState);
|
||||||
/* Restore args if a macro (not REPT) saved them */
|
/* Restore args if a macro (not REPT) saved them */
|
||||||
if (context->fileInfo->type == NODE_MACRO) {
|
if (context->fileInfo->type == NODE_MACRO)
|
||||||
dbgPrint("Restoring macro args %p\n", (void *)contextStack->macroArgs);
|
|
||||||
macro_UseNewArgs(contextStack->macroArgs);
|
macro_UseNewArgs(contextStack->macroArgs);
|
||||||
}
|
|
||||||
/* Free the file stack node */
|
/* Free the file stack node */
|
||||||
if (!context->fileInfo->referenced)
|
if (!context->fileInfo->referenced)
|
||||||
free(context->fileInfo);
|
free(context->fileInfo);
|
||||||
@@ -315,8 +306,6 @@ static void newContext(struct FileStackNode *fileInfo)
|
|||||||
|
|
||||||
void fstk_RunInclude(char const *path)
|
void fstk_RunInclude(char const *path)
|
||||||
{
|
{
|
||||||
dbgPrint("Including path \"%s\"\n", path);
|
|
||||||
|
|
||||||
char *fullPath = NULL;
|
char *fullPath = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
@@ -332,7 +321,6 @@ void fstk_RunInclude(char const *path)
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dbgPrint("Full path: \"%s\"\n", fullPath);
|
|
||||||
|
|
||||||
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + size);
|
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + size);
|
||||||
|
|
||||||
@@ -356,8 +344,6 @@ void fstk_RunInclude(char const *path)
|
|||||||
|
|
||||||
void fstk_RunMacro(char const *macroName, struct MacroArgs *args)
|
void fstk_RunMacro(char const *macroName, struct MacroArgs *args)
|
||||||
{
|
{
|
||||||
dbgPrint("Running macro \"%s\"\n", macroName);
|
|
||||||
|
|
||||||
struct Symbol *macro = sym_FindExactSymbol(macroName);
|
struct Symbol *macro = sym_FindExactSymbol(macroName);
|
||||||
|
|
||||||
if (!macro) {
|
if (!macro) {
|
||||||
@@ -461,8 +447,6 @@ static bool newReptContext(int32_t reptLineNo, char *body, size_t size)
|
|||||||
|
|
||||||
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size)
|
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size)
|
||||||
{
|
{
|
||||||
dbgPrint("Running REPT(%" PRIu32 ")\n", count);
|
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return;
|
return;
|
||||||
if (!newReptContext(reptLineNo, body, size))
|
if (!newReptContext(reptLineNo, body, size))
|
||||||
@@ -475,9 +459,6 @@ void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size)
|
|||||||
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
|
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
|
||||||
int32_t reptLineNo, char *body, size_t size)
|
int32_t reptLineNo, char *body, size_t size)
|
||||||
{
|
{
|
||||||
dbgPrint("Running FOR(\"%s\", %" PRId32 ", %" PRId32 ", %" PRId32 ")\n",
|
|
||||||
symName, start, stop, step);
|
|
||||||
|
|
||||||
struct Symbol *sym = sym_AddVar(symName, start);
|
struct Symbol *sym = sym_AddVar(symName, start);
|
||||||
|
|
||||||
if (sym->type != SYM_VAR)
|
if (sym->type != SYM_VAR)
|
||||||
@@ -517,8 +498,6 @@ void fstk_StopRept(void)
|
|||||||
|
|
||||||
bool fstk_Break(void)
|
bool fstk_Break(void)
|
||||||
{
|
{
|
||||||
dbgPrint("Breaking out of REPT/FOR\n");
|
|
||||||
|
|
||||||
if (contextStack->fileInfo->type != NODE_REPT) {
|
if (contextStack->fileInfo->type != NODE_REPT) {
|
||||||
error("BREAK can only be used inside a REPT/FOR block\n");
|
error("BREAK can only be used inside a REPT/FOR block\n");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -38,12 +38,6 @@
|
|||||||
/* Include this last so it gets all type & constant definitions */
|
/* Include this last so it gets all type & constant definitions */
|
||||||
#include "parser.h" /* For token definitions, generated from parser.y */
|
#include "parser.h" /* For token definitions, generated from parser.y */
|
||||||
|
|
||||||
#ifdef LEXER_DEBUG
|
|
||||||
#define dbgPrint(...) fprintf(stderr, "[lexer] " __VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define dbgPrint(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Neither MSVC nor MinGW provide `mmap` */
|
/* Neither MSVC nor MinGW provide `mmap` */
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
# define WIN32_LEAN_AND_MEAN // include less from windows.h
|
# define WIN32_LEAN_AND_MEAN // include less from windows.h
|
||||||
@@ -452,8 +446,6 @@ void lexer_ReachELSEBlock(void)
|
|||||||
|
|
||||||
struct LexerState *lexer_OpenFile(char const *path)
|
struct LexerState *lexer_OpenFile(char const *path)
|
||||||
{
|
{
|
||||||
dbgPrint("Opening file \"%s\"\n", path);
|
|
||||||
|
|
||||||
bool isStdin = !strcmp(path, "-");
|
bool isStdin = !strcmp(path, "-");
|
||||||
struct LexerState *state = malloc(sizeof(*state));
|
struct LexerState *state = malloc(sizeof(*state));
|
||||||
struct stat fileInfo;
|
struct stat fileInfo;
|
||||||
@@ -530,8 +522,6 @@ struct LexerState *lexer_OpenFile(char const *path)
|
|||||||
|
|
||||||
struct LexerState *lexer_OpenFileView(char const *path, char *buf, size_t size, uint32_t lineNo)
|
struct LexerState *lexer_OpenFileView(char const *path, char *buf, size_t size, uint32_t lineNo)
|
||||||
{
|
{
|
||||||
dbgPrint("Opening view on buffer \"%.*s\"[...]\n", size < 16 ? (int)size : 16, buf);
|
|
||||||
|
|
||||||
struct LexerState *state = malloc(sizeof(*state));
|
struct LexerState *state = malloc(sizeof(*state));
|
||||||
|
|
||||||
if (!state) {
|
if (!state) {
|
||||||
@@ -553,7 +543,6 @@ struct LexerState *lexer_OpenFileView(char const *path, char *buf, size_t size,
|
|||||||
|
|
||||||
void lexer_RestartRept(uint32_t lineNo)
|
void lexer_RestartRept(uint32_t lineNo)
|
||||||
{
|
{
|
||||||
dbgPrint("Restarting REPT/FOR\n");
|
|
||||||
lexerState->offset = 0;
|
lexerState->offset = 0;
|
||||||
initState(lexerState);
|
initState(lexerState);
|
||||||
lexerState->lineNo = lineNo;
|
lexerState->lineNo = lineNo;
|
||||||
@@ -725,7 +714,6 @@ static bool continuesIdentifier(int c);
|
|||||||
|
|
||||||
static uint32_t readBracketedMacroArgNum(void)
|
static uint32_t readBracketedMacroArgNum(void)
|
||||||
{
|
{
|
||||||
dbgPrint("Reading bracketed macro arg\n");
|
|
||||||
bool disableMacroArgs = lexerState->disableMacroArgs;
|
bool disableMacroArgs = lexerState->disableMacroArgs;
|
||||||
bool disableInterpolation = lexerState->disableInterpolation;
|
bool disableInterpolation = lexerState->disableInterpolation;
|
||||||
|
|
||||||
@@ -1038,7 +1026,6 @@ void lexer_DumpStringExpansions(void)
|
|||||||
/* Discards a block comment */
|
/* Discards a block comment */
|
||||||
static void discardBlockComment(void)
|
static void discardBlockComment(void)
|
||||||
{
|
{
|
||||||
dbgPrint("Discarding block comment\n");
|
|
||||||
lexerState->disableMacroArgs = true;
|
lexerState->disableMacroArgs = true;
|
||||||
lexerState->disableInterpolation = true;
|
lexerState->disableInterpolation = true;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -1081,7 +1068,6 @@ finish:
|
|||||||
|
|
||||||
static void discardComment(void)
|
static void discardComment(void)
|
||||||
{
|
{
|
||||||
dbgPrint("Discarding comment\n");
|
|
||||||
lexerState->disableMacroArgs = true;
|
lexerState->disableMacroArgs = true;
|
||||||
lexerState->disableInterpolation = true;
|
lexerState->disableInterpolation = true;
|
||||||
for (;; shiftChar()) {
|
for (;; shiftChar()) {
|
||||||
@@ -1098,7 +1084,6 @@ static void discardComment(void)
|
|||||||
|
|
||||||
static void readLineContinuation(void)
|
static void readLineContinuation(void)
|
||||||
{
|
{
|
||||||
dbgPrint("Beginning line continuation\n");
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c = peek();
|
int c = peek();
|
||||||
|
|
||||||
@@ -1161,7 +1146,6 @@ static uint32_t readFractionalPart(int32_t integer)
|
|||||||
{
|
{
|
||||||
uint32_t value = 0, divisor = 1;
|
uint32_t value = 0, divisor = 1;
|
||||||
|
|
||||||
dbgPrint("Reading fractional part\n");
|
|
||||||
for (;; shiftChar()) {
|
for (;; shiftChar()) {
|
||||||
int c = peek();
|
int c = peek();
|
||||||
|
|
||||||
@@ -1199,7 +1183,6 @@ static uint32_t readBinaryNumber(void)
|
|||||||
{
|
{
|
||||||
uint32_t value = 0;
|
uint32_t value = 0;
|
||||||
|
|
||||||
dbgPrint("Reading binary number with digits [%c,%c]\n", binDigits[0], binDigits[1]);
|
|
||||||
for (;; shiftChar()) {
|
for (;; shiftChar()) {
|
||||||
int c = peek();
|
int c = peek();
|
||||||
int bit;
|
int bit;
|
||||||
@@ -1226,7 +1209,6 @@ static uint32_t readHexNumber(void)
|
|||||||
uint32_t value = 0;
|
uint32_t value = 0;
|
||||||
bool empty = true;
|
bool empty = true;
|
||||||
|
|
||||||
dbgPrint("Reading hex number\n");
|
|
||||||
for (;; shiftChar()) {
|
for (;; shiftChar()) {
|
||||||
int c = peek();
|
int c = peek();
|
||||||
|
|
||||||
@@ -1261,8 +1243,6 @@ static uint32_t readGfxConstant(void)
|
|||||||
uint32_t bitPlaneLower = 0, bitPlaneUpper = 0;
|
uint32_t bitPlaneLower = 0, bitPlaneUpper = 0;
|
||||||
uint8_t width = 0;
|
uint8_t width = 0;
|
||||||
|
|
||||||
dbgPrint("Reading gfx constant with digits [%c,%c,%c,%c]\n",
|
|
||||||
gfxDigits[0], gfxDigits[1], gfxDigits[2], gfxDigits[3]);
|
|
||||||
for (;; shiftChar()) {
|
for (;; shiftChar()) {
|
||||||
int c = peek();
|
int c = peek();
|
||||||
uint32_t pixel;
|
uint32_t pixel;
|
||||||
@@ -1313,7 +1293,6 @@ static bool continuesIdentifier(int c)
|
|||||||
|
|
||||||
static int readIdentifier(char firstChar)
|
static int readIdentifier(char firstChar)
|
||||||
{
|
{
|
||||||
dbgPrint("Reading identifier or keyword\n");
|
|
||||||
/* Lex while checking for a keyword */
|
/* Lex while checking for a keyword */
|
||||||
yylval.symName[0] = firstChar;
|
yylval.symName[0] = firstChar;
|
||||||
uint16_t nodeID = keywordDict[0].children[dictIndex(firstChar)];
|
uint16_t nodeID = keywordDict[0].children[dictIndex(firstChar)];
|
||||||
@@ -1343,7 +1322,6 @@ static int readIdentifier(char firstChar)
|
|||||||
i = sizeof(yylval.symName) - 1;
|
i = sizeof(yylval.symName) - 1;
|
||||||
}
|
}
|
||||||
yylval.symName[i] = '\0'; /* Terminate the string */
|
yylval.symName[i] = '\0'; /* Terminate the string */
|
||||||
dbgPrint("Ident/keyword = \"%s\"\n", yylval.symName);
|
|
||||||
|
|
||||||
if (keywordDict[nodeID].keyword)
|
if (keywordDict[nodeID].keyword)
|
||||||
return keywordDict[nodeID].keyword->token;
|
return keywordDict[nodeID].keyword->token;
|
||||||
@@ -1478,7 +1456,6 @@ static size_t appendEscapedSubstring(char const *str, size_t i)
|
|||||||
|
|
||||||
static void readString(void)
|
static void readString(void)
|
||||||
{
|
{
|
||||||
dbgPrint("Reading string\n");
|
|
||||||
lexerState->disableMacroArgs = true;
|
lexerState->disableMacroArgs = true;
|
||||||
lexerState->disableInterpolation = true;
|
lexerState->disableInterpolation = true;
|
||||||
|
|
||||||
@@ -1623,14 +1600,12 @@ finish:
|
|||||||
}
|
}
|
||||||
yylval.string[i] = '\0';
|
yylval.string[i] = '\0';
|
||||||
|
|
||||||
dbgPrint("Read string \"%s\"\n", yylval.string);
|
|
||||||
lexerState->disableMacroArgs = false;
|
lexerState->disableMacroArgs = false;
|
||||||
lexerState->disableInterpolation = false;
|
lexerState->disableInterpolation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t appendStringLiteral(size_t i)
|
static size_t appendStringLiteral(size_t i)
|
||||||
{
|
{
|
||||||
dbgPrint("Reading string\n");
|
|
||||||
lexerState->disableMacroArgs = true;
|
lexerState->disableMacroArgs = true;
|
||||||
lexerState->disableInterpolation = true;
|
lexerState->disableInterpolation = true;
|
||||||
|
|
||||||
@@ -1773,7 +1748,6 @@ finish:
|
|||||||
}
|
}
|
||||||
yylval.string[i] = '\0';
|
yylval.string[i] = '\0';
|
||||||
|
|
||||||
dbgPrint("Read string \"%s\"\n", yylval.string);
|
|
||||||
lexerState->disableMacroArgs = false;
|
lexerState->disableMacroArgs = false;
|
||||||
lexerState->disableInterpolation = false;
|
lexerState->disableInterpolation = false;
|
||||||
|
|
||||||
@@ -1786,9 +1760,6 @@ static int yylex_SKIP_TO_ENDC(void); // forward declaration for yylex_NORMAL
|
|||||||
|
|
||||||
static int yylex_NORMAL(void)
|
static int yylex_NORMAL(void)
|
||||||
{
|
{
|
||||||
dbgPrint("Lexing in normal mode, line=%" PRIu32 ", col=%" PRIu32 "\n",
|
|
||||||
lexer_GetLineNo(), lexer_GetColNo());
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c = nextChar();
|
int c = nextChar();
|
||||||
char secondChar;
|
char secondChar;
|
||||||
@@ -2069,9 +2040,6 @@ static int yylex_NORMAL(void)
|
|||||||
|
|
||||||
static int yylex_RAW(void)
|
static int yylex_RAW(void)
|
||||||
{
|
{
|
||||||
dbgPrint("Lexing in raw mode, line=%" PRIu32 ", col=%" PRIu32 "\n",
|
|
||||||
lexer_GetLineNo(), lexer_GetColNo());
|
|
||||||
|
|
||||||
/* This is essentially a modified `appendStringLiteral` */
|
/* This is essentially a modified `appendStringLiteral` */
|
||||||
size_t parenDepth = 0;
|
size_t parenDepth = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
@@ -2188,8 +2156,6 @@ finish:
|
|||||||
i--;
|
i--;
|
||||||
yylval.string[i] = '\0';
|
yylval.string[i] = '\0';
|
||||||
|
|
||||||
dbgPrint("Read raw string \"%s\"\n", yylval.string);
|
|
||||||
|
|
||||||
// Returning T_COMMAs to the parser would mean that two consecutive commas
|
// Returning T_COMMAs to the parser would mean that two consecutive commas
|
||||||
// (i.e. an empty argument) need to return two different tokens (T_STRING
|
// (i.e. an empty argument) need to return two different tokens (T_STRING
|
||||||
// then T_COMMA) without advancing the read. To avoid this, commas in raw
|
// then T_COMMA) without advancing the read. To avoid this, commas in raw
|
||||||
@@ -2229,7 +2195,6 @@ finish:
|
|||||||
*/
|
*/
|
||||||
static int skipIfBlock(bool toEndc)
|
static int skipIfBlock(bool toEndc)
|
||||||
{
|
{
|
||||||
dbgPrint("Skipping IF block (toEndc = %s)\n", toEndc ? "true" : "false");
|
|
||||||
lexer_SetMode(LEXER_NORMAL);
|
lexer_SetMode(LEXER_NORMAL);
|
||||||
uint32_t startingDepth = lexer_GetIFDepth();
|
uint32_t startingDepth = lexer_GetIFDepth();
|
||||||
int token;
|
int token;
|
||||||
@@ -2324,7 +2289,6 @@ static int yylex_SKIP_TO_ENDC(void)
|
|||||||
|
|
||||||
static int yylex_SKIP_TO_ENDR(void)
|
static int yylex_SKIP_TO_ENDR(void)
|
||||||
{
|
{
|
||||||
dbgPrint("Skipping remainder of REPT/FOR block\n");
|
|
||||||
lexer_SetMode(LEXER_NORMAL);
|
lexer_SetMode(LEXER_NORMAL);
|
||||||
int depth = 1;
|
int depth = 1;
|
||||||
bool atLineStart = lexerState->atLineStart;
|
bool atLineStart = lexerState->atLineStart;
|
||||||
@@ -2407,17 +2371,11 @@ int yylex(void)
|
|||||||
lexerStateEOL = NULL;
|
lexerStateEOL = NULL;
|
||||||
}
|
}
|
||||||
/* `lexer_SetState` updates `lexerState`, so check for EOF after it */
|
/* `lexer_SetState` updates `lexerState`, so check for EOF after it */
|
||||||
if (lexerState->lastToken == T_EOB) {
|
if (lexerState->lastToken == T_EOB && yywrap())
|
||||||
if (yywrap()) {
|
return T_EOF;
|
||||||
dbgPrint("Reached end of input.\n");
|
/* Newlines read within an expansion should not increase the line count */
|
||||||
return T_EOF;
|
if (lexerState->atLineStart && !lexerState->expansions)
|
||||||
}
|
nextLine();
|
||||||
}
|
|
||||||
if (lexerState->atLineStart) {
|
|
||||||
/* Newlines read within an expansion should not increase the line count */
|
|
||||||
if (!lexerState->expansions)
|
|
||||||
nextLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
static int (* const lexerModeFuncs[])(void) = {
|
static int (* const lexerModeFuncs[])(void) = {
|
||||||
[LEXER_NORMAL] = yylex_NORMAL,
|
[LEXER_NORMAL] = yylex_NORMAL,
|
||||||
@@ -2428,12 +2386,9 @@ int yylex(void)
|
|||||||
};
|
};
|
||||||
int token = lexerModeFuncs[lexerState->mode]();
|
int token = lexerModeFuncs[lexerState->mode]();
|
||||||
|
|
||||||
if (token == T_EOF) {
|
/* Captures end at their buffer's boundary no matter what */
|
||||||
dbgPrint("Reached EOB!\n");
|
if (token == T_EOF && !lexerState->capturing)
|
||||||
/* Captures end at their buffer's boundary no matter what */
|
token = T_EOB;
|
||||||
if (!lexerState->capturing)
|
|
||||||
token = T_EOB;
|
|
||||||
}
|
|
||||||
lexerState->lastToken = token;
|
lexerState->lastToken = token;
|
||||||
lexerState->atLineStart = token == T_NEWLINE || token == T_EOB;
|
lexerState->atLineStart = token == T_NEWLINE || token == T_EOB;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user