Skip to content

Commit

Permalink
Merge pull request cc65#2272 from acqn/Diagnostics
Browse files Browse the repository at this point in the history
[cc65] Improved diagnostics
  • Loading branch information
mrdudz authored Nov 28, 2023
2 parents 2af16ee + b99ebc1 commit 5537b61
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/cc65/asmstmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static SymEntry* AsmGetSym (unsigned Arg, unsigned Type)

/* Did we find a symbol with this name? */
if (Sym == 0) {
Error ("Undefined symbol '%s' for argument %u", CurTok.Ident, Arg);
Error ("Undeclared symbol '%s' for argument %u", CurTok.Ident, Arg);
AsmErrorSkip ();
return 0;
}
Expand Down
32 changes: 29 additions & 3 deletions src/cc65/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ static void Parse (void)
while (CurTok.Tok != TOK_CEOF) {

DeclSpec Spec;
int NeedClean = 0;
unsigned PrevErrorCount = ErrorCount;

/* Check for empty statements */
if (CurTok.Tok == TOK_SEMI) {
Expand Down Expand Up @@ -144,7 +146,11 @@ static void Parse (void)
Declarator Decl;

/* Read the next declaration */
ParseDecl (&Spec, &Decl, DM_NEED_IDENT);
NeedClean = ParseDecl (&Spec, &Decl, DM_NEED_IDENT);
if (Decl.Ident[0] == '\0') {
Sym = 0;
goto NextDecl;
}

/* Check if we must reserve storage for the variable. We do this,
**
Expand Down Expand Up @@ -310,6 +316,7 @@ static void Parse (void)

}

NextDecl:
/* Check for end of declaration list */
if (CurTok.Tok == TOK_COMMA) {
NextToken ();
Expand All @@ -325,6 +332,7 @@ static void Parse (void)
/* Function */
if (CurTok.Tok == TOK_SEMI) {
/* Prototype only */
NeedClean = 0;
NextToken ();
} else if (CurTok.Tok == TOK_LCURLY) {
/* ISO C: The type category in a function definition cannot be
Expand All @@ -337,6 +345,7 @@ static void Parse (void)
}

/* Parse the function body anyways */
NeedClean = 0;
NewFunc (Sym, FuncDef);

/* Make sure we aren't omitting any work */
Expand All @@ -345,10 +354,27 @@ static void Parse (void)

} else {

/* Must be followed by a semicolon */
ConsumeSemi ();
if (Sym) {
/* Must be followed by a semicolon */
if (CurTok.Tok != TOK_SEMI) {
NeedClean = -1;
}
ConsumeSemi ();
}

}

/* Try some smart error recovery */
if (PrevErrorCount != ErrorCount && NeedClean < 0) {
/* Some fix point tokens that are used for error recovery */
static const token_t TokenList[] = { TOK_SEMI, TOK_RCURLY };

SmartErrorSkip ();
SkipTokens (TokenList, sizeof (TokenList) / sizeof (TokenList[0]));
if (CurTok.Tok == TOK_SEMI || CurTok.Tok == TOK_RCURLY) {
NextToken ();
}
}
}

/* Done with deferred operations */
Expand Down
Loading

0 comments on commit 5537b61

Please sign in to comment.