]> Shamusworld >> Repos - rmac/commitdiff
Fix for bug #174 - when a macro contains an error, actually print the filename it...
authorggn <ggn.dbug@gmail.com>
Wed, 2 Sep 2020 19:49:42 +0000 (22:49 +0300)
committerShamus Hammons <jlhamm@acm.org>
Wed, 9 Jun 2021 01:41:50 +0000 (20:41 -0500)
error.c
symbol.c
symbol.h
token.c
token.h

diff --git a/error.c b/error.c
index d0edaf400240ef95a6270aa566af8a9a690d7d27..ce22b395f3d87976f60ca0b8beaabe0a359044d7 100644 (file)
--- a/error.c
+++ b/error.c
@@ -102,7 +102,36 @@ int error(const char * text, ...)
                        sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
                        break;
                case SRC_IMACRO:
-                       sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf);
+               {
+                       // This is basically SetFilenameForErrorReporting() but we don't call it here
+                       // as it will clobber curfname. That function is used during fixups only so
+                       // it really doesn't matter at that point...
+                       char * filename;
+#include <token.h>
+                       FILEREC * fr;
+                       uint16_t fnum = cur_inobj->inobj.imacro->im_macro->cfileno;
+                       // Check for absolute top filename (this should never happen)
+                       if (fnum == -1)
+                               interror(8);
+                       else
+                       {
+                               fr = filerec;
+
+                               // Advance to the correct record...
+                               while (fr != NULL && fnum != 0)
+                               {
+                                       fr = fr->frec_next;
+                                       fnum--;
+                               }
+                       }
+                       // Check for file # record not found (this should never happen either)
+                       if (fr == NULL)
+                               interror(8);
+
+                       filename = fr->frec_name;
+
+                       sprintf(buf1, "%s %d: Error: %s\n", filename, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf);
+               }
                        break;
                case SRC_IREPT:
                        sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.irept->lineno, buf);
index 2635e7a3c369c71d636f905dd019f4bb897f3762..c2da09abece5cd67a0eaf73cc26f72a20764b7f4 100644 (file)
--- a/symbol.c
+++ b/symbol.c
@@ -103,6 +103,9 @@ SYM * NewSymbol(uint8_t * name, int type, int envno)
        symbol->sorder = NULL;
        symbol->uid    = currentUID++;
 
+       // Record filename the symbol is defined (for now only used by macro error reporting)
+       symbol->cfileno = cfileno;
+
        // Install symbol in the symbol table
        int hash = HashSymbol(name, envno);
        symbol->snext = symbolTable[hash];
index e68076c787bc50fed2deee85b02b8d15adb73591..ddf2d22c07285dac525804a0f612778bb9ff89d7 100644 (file)
--- a/symbol.h
+++ b/symbol.h
@@ -35,6 +35,7 @@ SYM
        uint8_t * sname;                // * -> Symbol's print-name
        LLIST * lineList;               // * -> Macro's linked list of lines
        LLIST * last;                   // * -> end of macro linked list
+       uint16_t cfileno;               // File the macro is defined in
        uint32_t uid;                   // Symbol's unique ID
 };
 
diff --git a/token.c b/token.c
index f3cf619a5f41472ac36d9b5db140c4e8afc4f300..807f08fc34b4f2789b90bc557e5758dc11711018 100644 (file)
--- a/token.c
+++ b/token.c
@@ -40,13 +40,6 @@ TOKEN tokeol[1] = {EOL};     // Bailout end-of-line token
 char * string[TOKBUFSIZE*2];// Token buffer string pointer storage
 int optimizeOff;                       // Optimization override flag
 
-// File record, used to maintain a list of every include file ever visited
-#define FILEREC struct _filerec
-FILEREC
-{
-   FILEREC * frec_next;
-   char * frec_name;
-};
 
 FILEREC * filerec;
 FILEREC * last_fr;
diff --git a/token.h b/token.h
index 1dc3a8a817ff6a3ea8b22e38878b929604c7719f..310a9c258be013e885ac83cdeb971ec3c0a458d2 100644 (file)
--- a/token.h
+++ b/token.h
@@ -157,6 +157,14 @@ IREPT {
        uint32_t lineno;                // Repeat line number (Convert this to global instead of putting it here?)
 };
 
+// File record, used to maintain a list of every include file ever visited
+#define FILEREC struct _filerec
+FILEREC
+{
+   FILEREC * frec_next;
+   char * frec_name;
+};
+
 // Exported variables
 extern int lnsave;
 extern uint32_t curlineno;
@@ -170,6 +178,7 @@ extern INOBJ * cur_inobj;
 extern int mjump_align;
 extern char * string[];
 extern int optimizeOff;
+extern FILEREC * filerec;
 
 // Exported functions
 int include(int, char *);