shithub: rgbds

Download patch

ref: e93d65d736a42f8317370b8e091cefafdc4a665b
parent: 0f4d543aebbfe37ecd2e19aefb00084798c5f89b
parent: 55fbecee497b7971b9b773fe7136ff953b10e186
author: Eldred Habert <eldredhabert0@gmail.com>
date: Thu Oct 3 06:20:49 EDT 2019

Merge pull request #425 from ISSOtm/eexpansion_error

Add info about string expansions in error reports

--- 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"