1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-01 13:41:34 +00:00

Fixed extra "Macro argument count mismatch" message when a macro argument list is unterminated.

This commit is contained in:
acqn 2022-07-26 21:10:31 +08:00
parent 60c1290468
commit 2c9c8ee196

View File

@ -446,10 +446,14 @@ static int MacName (char* Ident)
static void ReadMacroArgs (MacroExp* E)
/* Identify the arguments to a macro call */
/* Identify the arguments to a macro call as-is */
{
int MissingParen = 0;
unsigned Parens; /* Number of open parenthesis */
StrBuf Arg = STATIC_STRBUF_INITIALIZER;
StrBuf Arg = AUTO_STRBUF_INITIALIZER;
/* Eat the left paren */
NextChar ();
/* Read the actual macro arguments */
Parens = 0;
@ -512,7 +516,7 @@ static void ReadMacroArgs (MacroExp* E)
} else if (CurC == '\0') {
/* End of input inside macro argument list */
PPError ("Unterminated argument list invoking macro '%s'", E->M->Name);
MissingParen = 1;
ClearLine ();
break;
} else {
@ -522,6 +526,21 @@ static void ReadMacroArgs (MacroExp* E)
}
}
/* Compare formal and actual argument count */
if (CollCount (&E->ActualArgs) != (unsigned) E->M->ArgCount) {
if (!MissingParen) {
/* Argument count mismatch */
PPError ("Macro argument count mismatch");
}
/* Be sure to make enough empty arguments available */
SB_Clear (&Arg);
while (CollCount (&E->ActualArgs) < (unsigned) E->M->ArgCount) {
ME_AppendActual (E, &Arg);
}
}
/* Deallocate string buf resources */
SB_Done (&Arg);
}
@ -666,29 +685,12 @@ static void MacroCall (StrBuf* Target, Macro* M)
{
MacroExp E;
/* Eat the left paren */
NextChar ();
/* Initialize our MacroExp structure */
InitMacroExp (&E, M);
/* Read the actual macro arguments */
/* Read the actual macro arguments (with the enclosing parentheses) */
ReadMacroArgs (&E);
/* Compare formal and actual argument count */
if (CollCount (&E.ActualArgs) != (unsigned) M->ArgCount) {
StrBuf Arg = STATIC_STRBUF_INITIALIZER;
/* Argument count mismatch */
PPError ("Macro argument count mismatch");
/* Be sure to make enough empty arguments available */
while (CollCount (&E.ActualArgs) < (unsigned) M->ArgCount) {
ME_AppendActual (&E, &Arg);
}
}
/* Replace macro arguments handling the # and ## operators */
MacroArgSubst (&E);