shithub: rgbds

Download patch

ref: 55fbecee497b7971b9b773fe7136ff953b10e186
parent: ccc666c1e4b38fa2d1608b81d49b0dac253cefca
author: ISSOtm <eldredhabert0@gmail.com>
date: Thu Sep 12 05:57:01 EDT 2019

Add info about string expansions in error reports
This is especially useful when an EQUS expands to another one, to help
track them.
This is done separately from the file stack as the EQUS stack is separate
(which is itself because EQUS are managed *way* differently).

--- a/include/asm/fstack.h
+++ b/include/asm/fstack.h
@@ -43,6 +43,7 @@
 void fstk_RunMacroArg(int32_t s);
 void fstk_Init(char *s);
 void fstk_Dump(void);
+void fstk_DumpStringExpansions(void);
 void fstk_AddIncludePath(char *s);
 uint32_t fstk_RunMacro(char *s);
 void fstk_RunRept(uint32_t count, int32_t nReptLineNo);
--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -263,6 +263,20 @@
 }
 
 /*
+ * Dump the string expansion stack to stderr
+ */
+void fstk_DumpStringExpansions(void)
+{
+	const struct sStringExpansionPos *pExpansion = pCurrentStringExpansion;
+
+	while (pExpansion) {
+		fprintf(stderr, "while expanding symbol \"%s\"\n",
+			pExpansion->tzName);
+		pExpansion = pExpansion->pParent;
+	}
+}
+
+/*
  * Extra includepath stuff
  */
 void fstk_AddIncludePath(char *s)
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -239,12 +239,13 @@
  */
 void verror(const char *fmt, va_list args)
 {
-	fprintf(stderr, "ERROR: ");
+	fputs("ERROR: ", stderr);
 	fstk_Dump();
-	fprintf(stderr, ":\n    ");
+	fputs(":\n    ", stderr);
 	vfprintf(stderr, fmt, args);
-	fprintf(stderr, "\n");
-	nErrors += 1;
+	fputc('\n', stderr);
+	fstk_DumpStringExpansions();
+	nErrors++;
 }
 
 void yyerror(const char *fmt, ...)
@@ -276,11 +277,12 @@
 
 	va_start(args, fmt);
 
-	fprintf(stderr, "warning: ");
+	fputs("warning: ", stderr);
 	fstk_Dump();
-	fprintf(stderr, ":\n    ");
+	fputs(":\n    ", stderr);
 	vfprintf(stderr, fmt, args);
-	fprintf(stderr, "\n");
+	fputc('\n', stderr);
+	fstk_DumpStringExpansions();
 
 	va_end(args);
 }
--- a/test/asm/equs-recursion.out
+++ b/test/asm/equs-recursion.out
@@ -1,2 +1,66 @@
 ERROR: equs-recursion.asm(2):
     Recursion limit (64) exceeded
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"
+while expanding symbol "recurse"