ref: aac839f3897be831eb35c3b31403a0b099079ae3
parent: 9d9febe1d36995046c0ec246fcec54fdbe1d16f8
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Mon Nov 22 12:29:01 EST 2021
Remove `dbgPrint` and `TRACE_LEXER` support I have not found `TRACE_LEXER` to be useful in debugging actual lexer issues.
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,7 +26,6 @@
option(SANITIZERS "Build with sanitizers enabled" OFF) # Ignored on MSVC
option(MORE_WARNINGS "Turn on more warnings" OFF) # Ignored on MSVC
option(TRACE_PARSER "Trace parser execution" OFF)
-option(TRACE_LEXER "Trace lexer execution" OFF)
if(MSVC)
# MSVC's standard library triggers warning C5105,
@@ -92,8 +91,4 @@
if(TRACE_PARSER)
target_compile_definitions(rgbasm PRIVATE -DYYDEBUG)
-endif()
-
-if(TRACE_LEXER)
- target_compile_definitions(rgbasm PRIVATE -DLEXER_DEBUG)
endif()
--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -23,12 +23,6 @@
#define MAXINCPATHS 128
-#ifdef LEXER_DEBUG
- #define dbgPrint(...) fprintf(stderr, "[fstack] " __VA_ARGS__)
-#else
- #define dbgPrint(...)
-#endif
-
struct Context {
struct Context *parent;
struct FileStackNode *fileInfo;
@@ -259,7 +253,6 @@
} else if (!contextStack->parent) {
return true;
}
- dbgPrint("Popping context\n");
struct Context *context = contextStack;
@@ -269,10 +262,8 @@
lexer_DeleteState(context->lexerState);
/* Restore args if a macro (not REPT) saved them */
- if (context->fileInfo->type == NODE_MACRO) {
- dbgPrint("Restoring macro args %p\n", (void *)contextStack->macroArgs);
+ if (context->fileInfo->type == NODE_MACRO)
macro_UseNewArgs(contextStack->macroArgs);
- }
/* Free the file stack node */
if (!context->fileInfo->referenced)
free(context->fileInfo);
@@ -315,8 +306,6 @@
void fstk_RunInclude(char const *path)
{
- dbgPrint("Including path \"%s\"\n", path);
-
char *fullPath = NULL;
size_t size = 0;
@@ -332,7 +321,6 @@
}
return;
}
- dbgPrint("Full path: \"%s\"\n", fullPath);
struct FileStackNamedNode *fileInfo = malloc(sizeof(*fileInfo) + size);
@@ -356,8 +344,6 @@
void fstk_RunMacro(char const *macroName, struct MacroArgs *args)
{
- dbgPrint("Running macro \"%s\"\n", macroName);
-
struct Symbol *macro = sym_FindExactSymbol(macroName);
if (!macro) {
@@ -461,8 +447,6 @@
void fstk_RunRept(uint32_t count, int32_t reptLineNo, char *body, size_t size)
{
- dbgPrint("Running REPT(%" PRIu32 ")\n", count);
-
if (count == 0)
return;
if (!newReptContext(reptLineNo, body, size))
@@ -475,9 +459,6 @@
void fstk_RunFor(char const *symName, int32_t start, int32_t stop, int32_t step,
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);
if (sym->type != SYM_VAR)
@@ -517,8 +498,6 @@
bool fstk_Break(void)
{
- dbgPrint("Breaking out of REPT/FOR\n");
-
if (contextStack->fileInfo->type != NODE_REPT) {
error("BREAK can only be used inside a REPT/FOR block\n");
return false;
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -38,12 +38,6 @@
/* Include this last so it gets all type & constant definitions */
#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` */
#if defined(_MSC_VER) || defined(__MINGW32__)
# define WIN32_LEAN_AND_MEAN // include less from windows.h
@@ -452,8 +446,6 @@
struct LexerState *lexer_OpenFile(char const *path)
{
- dbgPrint("Opening file \"%s\"\n", path);
-
bool isStdin = !strcmp(path, "-");
struct LexerState *state = malloc(sizeof(*state));
struct stat fileInfo;
@@ -530,8 +522,6 @@
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));
if (!state) {
@@ -553,7 +543,6 @@
void lexer_RestartRept(uint32_t lineNo)
{
- dbgPrint("Restarting REPT/FOR\n");
lexerState->offset = 0;
initState(lexerState);
lexerState->lineNo = lineNo;
@@ -725,7 +714,6 @@
static uint32_t readBracketedMacroArgNum(void)
{
- dbgPrint("Reading bracketed macro arg\n");
bool disableMacroArgs = lexerState->disableMacroArgs;
bool disableInterpolation = lexerState->disableInterpolation;
@@ -1038,7 +1026,6 @@
/* Discards a block comment */
static void discardBlockComment(void)
{
- dbgPrint("Discarding block comment\n");
lexerState->disableMacroArgs = true;
lexerState->disableInterpolation = true;
for (;;) {
@@ -1081,7 +1068,6 @@
static void discardComment(void)
{
- dbgPrint("Discarding comment\n");
lexerState->disableMacroArgs = true;
lexerState->disableInterpolation = true;
for (;; shiftChar()) {
@@ -1098,7 +1084,6 @@
static void readLineContinuation(void)
{
- dbgPrint("Beginning line continuation\n");
for (;;) {
int c = peek();
@@ -1161,7 +1146,6 @@
{
uint32_t value = 0, divisor = 1;
- dbgPrint("Reading fractional part\n");
for (;; shiftChar()) {
int c = peek();
@@ -1199,7 +1183,6 @@
{
uint32_t value = 0;
- dbgPrint("Reading binary number with digits [%c,%c]\n", binDigits[0], binDigits[1]);
for (;; shiftChar()) {
int c = peek();
int bit;
@@ -1226,7 +1209,6 @@
uint32_t value = 0;
bool empty = true;
- dbgPrint("Reading hex number\n");
for (;; shiftChar()) {
int c = peek();
@@ -1261,8 +1243,6 @@
uint32_t bitPlaneLower = 0, bitPlaneUpper = 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()) {
int c = peek();
uint32_t pixel;
@@ -1313,7 +1293,6 @@
static int readIdentifier(char firstChar)
{
- dbgPrint("Reading identifier or keyword\n");
/* Lex while checking for a keyword */
yylval.symName[0] = firstChar;
uint16_t nodeID = keywordDict[0].children[dictIndex(firstChar)];
@@ -1343,7 +1322,6 @@
i = sizeof(yylval.symName) - 1;
}
yylval.symName[i] = '\0'; /* Terminate the string */
- dbgPrint("Ident/keyword = \"%s\"\n", yylval.symName);
if (keywordDict[nodeID].keyword)
return keywordDict[nodeID].keyword->token;
@@ -1478,7 +1456,6 @@
static void readString(void)
{
- dbgPrint("Reading string\n");
lexerState->disableMacroArgs = true;
lexerState->disableInterpolation = true;
@@ -1623,7 +1600,6 @@
}
yylval.string[i] = '\0';
- dbgPrint("Read string \"%s\"\n", yylval.string);
lexerState->disableMacroArgs = false;
lexerState->disableInterpolation = false;
}
@@ -1630,7 +1606,6 @@
static size_t appendStringLiteral(size_t i)
{
- dbgPrint("Reading string\n");
lexerState->disableMacroArgs = true;
lexerState->disableInterpolation = true;
@@ -1773,7 +1748,6 @@
}
yylval.string[i] = '\0';
- dbgPrint("Read string \"%s\"\n", yylval.string);
lexerState->disableMacroArgs = false;
lexerState->disableInterpolation = false;
@@ -1786,9 +1760,6 @@
static int yylex_NORMAL(void)
{
- dbgPrint("Lexing in normal mode, line=%" PRIu32 ", col=%" PRIu32 "\n",
- lexer_GetLineNo(), lexer_GetColNo());
-
for (;;) {
int c = nextChar();
char secondChar;
@@ -2069,9 +2040,6 @@
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` */
size_t parenDepth = 0;
size_t i = 0;
@@ -2188,8 +2156,6 @@
i--;
yylval.string[i] = '\0';
- dbgPrint("Read raw string \"%s\"\n", yylval.string);
-
// 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
// then T_COMMA) without advancing the read. To avoid this, commas in raw
@@ -2229,7 +2195,6 @@
*/
static int skipIfBlock(bool toEndc)
{
- dbgPrint("Skipping IF block (toEndc = %s)\n", toEndc ? "true" : "false");
lexer_SetMode(LEXER_NORMAL);
uint32_t startingDepth = lexer_GetIFDepth();
int token;
@@ -2324,7 +2289,6 @@
static int yylex_SKIP_TO_ENDR(void)
{
- dbgPrint("Skipping remainder of REPT/FOR block\n");
lexer_SetMode(LEXER_NORMAL);
int depth = 1;
bool atLineStart = lexerState->atLineStart;
@@ -2407,17 +2371,11 @@
lexerStateEOL = NULL;
}
/* `lexer_SetState` updates `lexerState`, so check for EOF after it */
- if (lexerState->lastToken == T_EOB) {
- if (yywrap()) {
- dbgPrint("Reached end of input.\n");
- return T_EOF;
- }
- }
- if (lexerState->atLineStart) {
- /* Newlines read within an expansion should not increase the line count */
- if (!lexerState->expansions)
- nextLine();
- }
+ if (lexerState->lastToken == T_EOB && yywrap())
+ return T_EOF;
+ /* Newlines read within an expansion should not increase the line count */
+ if (lexerState->atLineStart && !lexerState->expansions)
+ nextLine();
static int (* const lexerModeFuncs[])(void) = {
[LEXER_NORMAL] = yylex_NORMAL,
@@ -2428,12 +2386,9 @@
};
int token = lexerModeFuncs[lexerState->mode]();
- if (token == T_EOF) {
- dbgPrint("Reached EOB!\n");
- /* Captures end at their buffer's boundary no matter what */
- if (!lexerState->capturing)
- token = T_EOB;
- }
+ /* Captures end at their buffer's boundary no matter what */
+ if (token == T_EOF && !lexerState->capturing)
+ token = T_EOB;
lexerState->lastToken = token;
lexerState->atLineStart = token == T_NEWLINE || token == T_EOB;