1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 23:29:39 +00:00

Reduced error flood raised by misplaced variable declarations.

This commit is contained in:
acqn 2020-08-03 01:34:02 +08:00 committed by Oliver Schmidt
parent 0f1a5e0520
commit 68d63b089d
3 changed files with 33 additions and 3 deletions

View File

@ -263,7 +263,7 @@ static void OptionalSigned (void)
static void InitDeclSpec (DeclSpec* D)
void InitDeclSpec (DeclSpec* D)
/* Initialize the DeclSpec struct for use */
{
D->StorageClass = 0;

View File

@ -93,6 +93,9 @@ typedef enum {
void InitDeclSpec (DeclSpec* D);
/* Initialize the DeclSpec struct for use */
Type* ParseType (Type* Type);
/* Parse a complete type specification */

View File

@ -920,8 +920,35 @@ static void Primary (ExprDesc* E)
/* Illegal primary. Be sure to skip the token to avoid endless
** error loops.
*/
Error ("Expression expected");
NextToken ();
{
/* Let's see if this is a C99-style declaration */
DeclSpec Spec;
InitDeclSpec (&Spec);
ParseDeclSpec (&Spec, -1, T_QUAL_NONE);
if (Spec.Type->C != T_END) {
Error ("Mixed declarations and code are not supported in cc65");
while (CurTok.Tok != TOK_SEMI) {
Declaration Decl;
/* Parse one declaration */
ParseDecl (&Spec, &Decl, DM_ACCEPT_IDENT);
if (CurTok.Tok == TOK_ASSIGN) {
NextToken ();
ParseInit (Decl.Type);
}
if (CurTok.Tok == TOK_COMMA) {
NextToken ();
} else {
break;
}
}
} else {
Error ("Expression expected");
NextToken ();
}
}
ED_MakeConstAbsInt (E, 1);
break;
}