shithub: rgbds

Download patch

ref: 861192c332560d8f9b668f42b1bdb9dfbb5f11a3
parent: 4b40d63dfdaa8c6788a9e546e10456cb9f36e37e
parent: d07ba6971b0be52cdf08214327191bee3653cbe8
author: Antonio Niño Díaz <antonio_nd@outlook.com>
date: Sat Jan 19 11:13:40 EST 2019

Merge pull request #318 from mid-kid/patch-316

Update a symbol's filename and line when defined

--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -103,6 +103,19 @@
 }
 
 /*
+ * Update a symbol's definition filename and line
+ */
+void updateSymbolFilename(struct sSymbol *nsym)
+{
+	if (snprintf(nsym->tzFileName, _MAX_PATH + 1, "%s",
+		     tzCurrentFileName) > _MAX_PATH) {
+		fatalerror("%s: File name is too long: '%s'", __func__,
+			   tzCurrentFileName);
+	}
+	nsym->nFileLine = fstk_GetLine();
+}
+
+/*
  * Create a new symbol by name
  */
 struct sSymbol *createsymbol(char *s)
@@ -133,14 +146,7 @@
 	(*ppsym)->pMacro = NULL;
 	(*ppsym)->pSection = NULL;
 	(*ppsym)->Callback = NULL;
-
-	if (snprintf((*ppsym)->tzFileName, _MAX_PATH + 1, "%s",
-		     tzCurrentFileName) > _MAX_PATH) {
-		fatalerror("%s: File name is too long: '%s'", __func__,
-			   tzCurrentFileName);
-	}
-
-	(*ppsym)->nFileLine = fstk_GetLine();
+	updateSymbolFilename(*ppsym);
 	return *ppsym;
 }
 
@@ -560,6 +566,7 @@
 			nsym->nValue = value;
 			nsym->nType |= SYMF_EQU | SYMF_DEFINED | SYMF_CONST;
 			nsym->pScope = NULL;
+			updateSymbolFilename(nsym);
 		}
 	}
 }
@@ -633,6 +640,7 @@
 		nsym->nValue = value;
 		nsym->nType |= SYMF_SET | SYMF_DEFINED | SYMF_CONST;
 		nsym->pScope = NULL;
+		updateSymbolFilename(nsym);
 	}
 }
 
@@ -710,6 +718,8 @@
 
 			nsym->pScope = scope;
 			nsym->pSection = pCurrentSection;
+
+			updateSymbolFilename(nsym);
 		}
 	}
 	pScope = findsymbol(tzSym, scope);
@@ -840,6 +850,7 @@
 			nsym->pScope = NULL;
 			nsym->ulMacroSize = ulNewMacroSize;
 			nsym->pMacro = tzNewMacro;
+			updateSymbolFilename(nsym);
 		}
 	}
 }
--- /dev/null
+++ b/test/asm/label-redefinition.asm
@@ -1,0 +1,7 @@
+SECTION "sec", ROM0
+    dw Sym
+m: MACRO
+Sym::
+ENDM
+    m
+Sym::
--- /dev/null
+++ b/test/asm/label-redefinition.out
@@ -1,0 +1,3 @@
+ERROR: label-redefinition.asm(7):
+    'Sym' already defined in m(6)
+error: Assembly aborted in pass 1 (1 errors)!