1
0
mirror of https://github.com/cc65/cc65.git synced 2024-09-27 04:54:54 +00:00

Remove MacSkipDef, capture all MacDef errors

This commit is contained in:
mvax 2023-04-28 17:16:16 -04:00
parent e5f4ca6b89
commit 6bcce49d5d

View File

@ -364,27 +364,6 @@ static void FreeMacExp (MacExp* E)
static void MacSkipDef (unsigned Style)
/* Skip a macro definition */
{
if (Style == MAC_STYLE_CLASSIC) {
/* Skip tokens until we reach the final .endmacro */
while (CurTok.Tok != TOK_ENDMACRO && CurTok.Tok != TOK_EOF) {
NextTok ();
}
if (CurTok.Tok != TOK_EOF) {
SkipUntilSep ();
} else {
Error ("'.ENDMACRO' expected");
}
} else {
/* Skip until end of line */
SkipUntilSep ();
}
}
void MacDef (unsigned Style) void MacDef (unsigned Style)
/* Parse a macro definition */ /* Parse a macro definition */
{ {
@ -393,6 +372,7 @@ void MacDef (unsigned Style)
FilePos Pos; FilePos Pos;
int HaveParams; int HaveParams;
int LastTokWasSep; int LastTokWasSep;
unsigned MacroErrorCount;
/* For classic macros, remember if we are at the beginning of the line. /* For classic macros, remember if we are at the beginning of the line.
** If the macro name and parameters pass our checks then we will be on a ** If the macro name and parameters pass our checks then we will be on a
@ -405,27 +385,23 @@ void MacDef (unsigned Style)
*/ */
Pos = CurTok.Pos; Pos = CurTok.Pos;
/* Remember current error count */
MacroErrorCount = ErrorCount;
/* We expect a macro name here */ /* We expect a macro name here */
if (CurTok.Tok != TOK_IDENT) { if (CurTok.Tok != TOK_IDENT) {
Error ("Identifier expected"); Error ("Identifier expected");
MacSkipDef (Style);
return;
} else if (!UbiquitousIdents && FindInstruction (&CurTok.SVal) >= 0) { } else if (!UbiquitousIdents && FindInstruction (&CurTok.SVal) >= 0) {
/* The identifier is a name of a 6502 instruction, which is not /* The identifier is a name of a 6502 instruction, which is not
** allowed if not explicitly enabled. ** allowed if not explicitly enabled.
*/ */
Error ("Cannot use an instruction as macro name"); Error ("Cannot use an instruction as macro name");
MacSkipDef (Style);
return;
} }
/* Did we already define that macro? */ /* Did we already define that macro? */
if (HT_Find (&MacroTab, &CurTok.SVal) != 0) { if (HT_Find (&MacroTab, &CurTok.SVal) != 0) {
/* Macro is already defined */ /* Macro is already defined */
Error ("A macro named '%m%p' is already defined", &CurTok.SVal); Error ("A macro named '%m%p' is already defined", &CurTok.SVal);
/* Skip tokens until we reach the final .endmacro */
MacSkipDef (Style);
return;
} }
/* Define the macro */ /* Define the macro */
@ -508,13 +484,14 @@ void MacDef (unsigned Style)
** it will be added to the macro definition instead of closing it. ** it will be added to the macro definition instead of closing it.
*/ */
if (CurTok.Tok == TOK_ENDMACRO && LastTokWasSep) { if (CurTok.Tok == TOK_ENDMACRO && LastTokWasSep) {
/* Done */ /* Done: Skip the .endmacro token */
NextTok ();
break; break;
} }
/* May not have end of file in a macro definition */ /* May not have end of file in a macro definition */
if (CurTok.Tok == TOK_EOF) { if (CurTok.Tok == TOK_EOF) {
PError (&Pos, "'.ENDMACRO' expected for macro '%m%p'", &M->Name); PError (&Pos, "'.ENDMACRO' expected for macro '%m%p'", &M->Name);
goto Done; break;
} }
} else { } else {
/* Accept a newline or end of file for new style macros */ /* Accept a newline or end of file for new style macros */
@ -597,15 +574,11 @@ void MacDef (unsigned Style)
NextTok (); NextTok ();
} }
/* Skip the .endmacro for a classic macro */ /* Set the Incomplete flag now that parsing is done. Any errors
if (Style == MAC_STYLE_CLASSIC) { ** generated in this routine will result in an incomplete macro
NextTok (); */
} M->Incomplete = (MacroErrorCount != ErrorCount);
/* Reset the Incomplete flag now that parsing is done */
M->Incomplete = 0;
Done:
/* Switch out of raw token mode */ /* Switch out of raw token mode */
LeaveRawTokenMode (); LeaveRawTokenMode ();
} }