mirror of
https://github.com/cc65/cc65.git
synced 2025-01-03 16:33:19 +00:00
Fix issue #1663.
This commit is contained in:
parent
b688cfa0c0
commit
4b68d19993
@ -133,24 +133,26 @@ static void SetIfCond (IfDesc* ID, int C)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void ElseClause (IfDesc* ID, const char* Directive)
|
static int ElseClause (IfDesc* ID, const char* Directive)
|
||||||
/* Enter an .ELSE clause */
|
/* Enter an .ELSE clause. Return true if this was ok, zero on errors. */
|
||||||
{
|
{
|
||||||
/* Check if we have an open .IF - otherwise .ELSE is not allowed */
|
/* Check if we have an open .IF - otherwise .ELSE is not allowed */
|
||||||
if (ID == 0) {
|
if (ID == 0) {
|
||||||
Error ("Unexpected %s", Directive);
|
Error ("Unexpected %s", Directive);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for a duplicate else, then remember that we had one */
|
/* Check for a duplicate else, then remember that we had one */
|
||||||
if (ID->Flags & ifElse) {
|
if (ID->Flags & ifElse) {
|
||||||
/* We already had a .ELSE ! */
|
/* We already had a .ELSE ! */
|
||||||
Error ("Duplicate .ELSE");
|
Error ("Duplicate .ELSE");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
ID->Flags |= ifElse;
|
ID->Flags |= ifElse;
|
||||||
|
|
||||||
/* Condition is inverted now */
|
/* Condition is inverted now */
|
||||||
ID->Flags ^= ifCond;
|
ID->Flags ^= ifCond;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -226,46 +228,52 @@ void DoConditionals (void)
|
|||||||
D = GetCurrentIf ();
|
D = GetCurrentIf ();
|
||||||
|
|
||||||
/* Allow an .ELSE */
|
/* Allow an .ELSE */
|
||||||
ElseClause (D, ".ELSE");
|
if (ElseClause (D, ".ELSE")) {
|
||||||
|
/* Remember the data for the .ELSE */
|
||||||
|
if (D) {
|
||||||
|
ReleaseFullLineInfo (&D->LineInfos);
|
||||||
|
GetFullLineInfo (&D->LineInfos);
|
||||||
|
D->Name = ".ELSE";
|
||||||
|
}
|
||||||
|
|
||||||
/* Remember the data for the .ELSE */
|
/* Calculate the new overall condition */
|
||||||
if (D) {
|
CalcOverallIfCond ();
|
||||||
ReleaseFullLineInfo (&D->LineInfos);
|
|
||||||
GetFullLineInfo (&D->LineInfos);
|
/* Skip .ELSE */
|
||||||
D->Name = ".ELSE";
|
NextTok ();
|
||||||
|
ExpectSep ();
|
||||||
|
} else {
|
||||||
|
/* Problem with .ELSE, ignore remainder of line */
|
||||||
|
SkipUntilSep ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate the new overall condition */
|
|
||||||
CalcOverallIfCond ();
|
|
||||||
|
|
||||||
/* Skip .ELSE */
|
|
||||||
NextTok ();
|
|
||||||
ExpectSep ();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_ELSEIF:
|
case TOK_ELSEIF:
|
||||||
D = GetCurrentIf ();
|
D = GetCurrentIf ();
|
||||||
/* Handle as if there was an .ELSE first */
|
/* Handle as if there was an .ELSE first */
|
||||||
ElseClause (D, ".ELSEIF");
|
if (ElseClause (D, ".ELSEIF")) {
|
||||||
|
/* Calculate the new overall if condition */
|
||||||
|
CalcOverallIfCond ();
|
||||||
|
|
||||||
/* Calculate the new overall if condition */
|
/* Allocate and prepare a new descriptor */
|
||||||
CalcOverallIfCond ();
|
D = AllocIf (".ELSEIF", 0);
|
||||||
|
NextTok ();
|
||||||
|
|
||||||
/* Allocate and prepare a new descriptor */
|
/* Ignore the new condition if we are inside a false .ELSE
|
||||||
D = AllocIf (".ELSEIF", 0);
|
** branch. This way we won't get any errors about undefined
|
||||||
NextTok ();
|
** symbols or similar...
|
||||||
|
*/
|
||||||
|
if (IfCond) {
|
||||||
|
SetIfCond (D, ConstExpression ());
|
||||||
|
ExpectSep ();
|
||||||
|
}
|
||||||
|
|
||||||
/* Ignore the new condition if we are inside a false .ELSE
|
/* Get the new overall condition */
|
||||||
** branch. This way we won't get any errors about undefined
|
CalcOverallIfCond ();
|
||||||
** symbols or similar...
|
} else {
|
||||||
*/
|
/* Problem with .ELSEIF, ignore remainder of line */
|
||||||
if (IfCond) {
|
SkipUntilSep ();
|
||||||
SetIfCond (D, ConstExpression ());
|
|
||||||
ExpectSep ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the new overall condition */
|
|
||||||
CalcOverallIfCond ();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_ENDIF:
|
case TOK_ENDIF:
|
||||||
|
Loading…
Reference in New Issue
Block a user