Fixed a problem with conditional assembly. The assembler did not check if end

of lined was reached after a .IF/.ELSE/... This could lead to invalid input
accepted without an error message.


git-svn-id: svn://svn.cc65.org/cc65/trunk@2947 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2004-03-21 11:03:08 +00:00
parent 3f1ebfe116
commit 1447b104db
3 changed files with 40 additions and 13 deletions

View file

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2003 Ullrich von Bassewitz */ /* (C) 2000-2004 Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Römerstraße 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -223,6 +223,7 @@ void DoConditionals (void)
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
} }
NextTok (); NextTok ();
ExpectSep ();
break; break;
case TOK_ELSEIF: case TOK_ELSEIF:
@ -247,6 +248,7 @@ void DoConditionals (void)
*/ */
if (IfCond == 0) { if (IfCond == 0) {
SetIfCond (D, ConstExpression ()); SetIfCond (D, ConstExpression ());
ExpectSep ();
} }
/* Get the new overall condition */ /* Get the new overall condition */
@ -262,6 +264,7 @@ void DoConditionals (void)
* has been cleanup up, since we may be at end of file. * has been cleanup up, since we may be at end of file.
*/ */
NextTok (); NextTok ();
ExpectSep ();
/* Get the new overall condition */ /* Get the new overall condition */
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
@ -272,6 +275,7 @@ void DoConditionals (void)
NextTok (); NextTok ();
if (IfCond) { if (IfCond) {
SetIfCond (D, ConstExpression ()); SetIfCond (D, ConstExpression ());
ExpectSep ();
} }
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
break; break;
@ -297,6 +301,7 @@ void DoConditionals (void)
ExprNode* Expr = Expression(); ExprNode* Expr = Expression();
SetIfCond (D, IsConstExpr (Expr, 0)); SetIfCond (D, IsConstExpr (Expr, 0));
FreeExpr (Expr); FreeExpr (Expr);
ExpectSep ();
} }
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
break; break;
@ -332,6 +337,7 @@ void DoConditionals (void)
ExprNode* Expr = Expression(); ExprNode* Expr = Expression();
SetIfCond (D, !IsConstExpr (Expr, 0)); SetIfCond (D, !IsConstExpr (Expr, 0));
FreeExpr (Expr); FreeExpr (Expr);
ExpectSep ();
} }
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
break; break;
@ -342,6 +348,7 @@ void DoConditionals (void)
if (IfCond) { if (IfCond) {
SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING); SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING);
SetIfCond (D, Sym == 0 || !SymIsDef (Sym)); SetIfCond (D, Sym == 0 || !SymIsDef (Sym));
ExpectSep ();
} }
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
break; break;
@ -352,6 +359,7 @@ void DoConditionals (void)
if (IfCond) { if (IfCond) {
SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING); SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING);
SetIfCond (D, Sym == 0 || !SymIsRef (Sym)); SetIfCond (D, Sym == 0 || !SymIsRef (Sym));
ExpectSep ();
} }
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
break; break;
@ -363,6 +371,7 @@ void DoConditionals (void)
SetIfCond (D, GetCPU() == CPU_6502); SetIfCond (D, GetCPU() == CPU_6502);
} }
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
ExpectSep ();
break; break;
case TOK_IFP816: case TOK_IFP816:
@ -372,6 +381,7 @@ void DoConditionals (void)
SetIfCond (D, GetCPU() == CPU_65816); SetIfCond (D, GetCPU() == CPU_65816);
} }
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
ExpectSep ();
break; break;
case TOK_IFPC02: case TOK_IFPC02:
@ -381,6 +391,7 @@ void DoConditionals (void)
SetIfCond (D, GetCPU() == CPU_65C02); SetIfCond (D, GetCPU() == CPU_65C02);
} }
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
ExpectSep ();
break; break;
case TOK_IFPSC02: case TOK_IFPSC02:
@ -390,6 +401,7 @@ void DoConditionals (void)
SetIfCond (D, GetCPU() == CPU_65SC02); SetIfCond (D, GetCPU() == CPU_65SC02);
} }
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
ExpectSep ();
break; break;
case TOK_IFREF: case TOK_IFREF:
@ -398,6 +410,7 @@ void DoConditionals (void)
if (IfCond) { if (IfCond) {
SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING); SymEntry* Sym = ParseScopedSymName (SYM_FIND_EXISTING);
SetIfCond (D, Sym != 0 && SymIsRef (Sym)); SetIfCond (D, Sym != 0 && SymIsRef (Sym));
ExpectSep ();
} }
IfCond = GetCurrentIfCond (); IfCond = GetCurrentIfCond ();
break; break;

View file

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2003 Ullrich von Bassewitz */ /* (C) 2000-2004 Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Römerstraße 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -419,16 +419,13 @@ void Consume (enum Token Expected, const char* ErrMsg)
void ConsumeSep (void) void ConsumeSep (void)
/* Consume a separator token */ /* Consume a separator token */
{ {
/* Accept an EOF as separator */ /* We expect a separator token */
if (Tok != TOK_EOF) { ExpectSep ();
if (Tok != TOK_SEP) {
Error ("Unexpected trailing garbage characters"); /* If we have one, skip it */
SkipUntilSep ();
}
if (Tok == TOK_SEP) { if (Tok == TOK_SEP) {
NextTok (); NextTok ();
} }
}
} }
@ -467,6 +464,18 @@ void SkipUntilSep (void)
void ExpectSep (void)
/* Check if we've reached a line separator, and output an error if not. Do
* not skip the line separator.
*/
{
if (!TokIsSep (Tok)) {
ErrorSkip ("Unexpected trailing garbage characters");
}
}
void EnterRawTokenMode (void) void EnterRawTokenMode (void)
/* Enter raw token mode. In raw mode, token handling functions are not /* Enter raw token mode. In raw mode, token handling functions are not
* executed, but the function tokens are passed untouched to the upper * executed, but the function tokens are passed untouched to the upper

View file

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2003 Ullrich von Bassewitz */ /* (C) 2000-2004 Ullrich von Bassewitz */
/* Römerstraße 52 */ /* Römerstraße 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
@ -69,6 +69,11 @@ void ConsumeComma (void);
void SkipUntilSep (void); void SkipUntilSep (void);
/* Skip tokens until we reach a line separator or end of file */ /* Skip tokens until we reach a line separator or end of file */
void ExpectSep (void);
/* Check if we've reached a line separator, and output an error if not. Do
* not skip the line separator.
*/
void EnterRawTokenMode (void); void EnterRawTokenMode (void);
/* Enter raw token mode. In raw mode, token handling functions are not /* Enter raw token mode. In raw mode, token handling functions are not
* executed, but the function tokens are passed untouched to the upper * executed, but the function tokens are passed untouched to the upper