shithub: scc

Download patch

ref: a951173828d4c5fad5de2c54576cb01ad484dbae
parent: 9833ce7547fe04b441bdabf7ad86783c7be6efeb
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Apr 4 10:11:50 EDT 2022

cc1: Change name to sym in macro struct

Having the pointer to the symbol allows to print the name
but it also allows to access other fields of the symbol.

--- a/src/cmd/cc/cc1/cpp.c
+++ b/src/cmd/cc/cc1/cpp.c
@@ -10,7 +10,7 @@
 #include "cc1.h"
 
 struct macroctx {
-	char *name;
+	Symbol *sym;
 	char *argp;
 	char **arglist;
 	char **listp;
@@ -92,10 +92,10 @@
 	next();
 	if (yytoken == EOFTOK)
 		error("unterminated argument list invoking macro \"%s\"",
-		      mp->name);
+		      mp->sym->name);
 	if (yylen + 1 > mp->arglen)
 		error("argument overflow invoking macro \"%s\"",
-		      mp->name);
+		      mp->sym->name);
 	if (yytoken == IDEN)
 		yylval.sym->flags |= SUSED;
 	memcpy(mp->argp, yytext, yylen);
@@ -164,10 +164,10 @@
 	disexpand = 0;
 
 	if (n == NR_MACROARG)
-		error("too many parameters in macro \"%s\"", mp->name);
+		error("too many parameters in macro \"%s\"", mp->sym->name);
 	if (n != mp->npars) {
 		error("macro \"%s\" received %d arguments, but it takes %d",
-		      mp->name, n, mp->npars);
+		      mp->sym->name, n, mp->npars);
 	}
 
 	return 1;
@@ -264,7 +264,7 @@
 	return bp - mp->buffer;
 
 expansion_too_long:
-	error("macro expansion of \"%s\" too long", mp->name);
+	error("macro expansion of \"%s\" too long", mp->sym->name);
 }
 
 int
@@ -281,7 +281,7 @@
 	if (disexpand || sym->hide)
 		return 0;
 
-	macro.name = sym->name;
+	macro.sym = sym;
 	macro.argp = arguments;
 	macro.listp = arglist;
 	macro.arglist = arglist;
@@ -305,14 +305,11 @@
 	macro.npars = atoi(sym->u.s);
 	if (!parsepars(&macro))
 		return 0;
-	for (i = 0; i < macro.npars; ++i)
-		DBG("MACRO par%d:%s", i, arglist[i]);
-
 	elen = copymacro(&macro);
 
 substitute:
 	buffer[elen] = '\0';
-	DBG("MACRO '%s' expanded to :'%s'", macro.name, buffer);
+	DBG("MACRO '%s' expanded to :'%s'", macro.sym->name, buffer);
 	addinput(filenam, sym, xstrdup(buffer), FAIL);
 
 	return 1;