/*****************************************************************************/
/* */
-/* error.c */
+/* error.c */
/* */
-/* Error handling for the cc65 C compiler */
+/* Error handling for the cc65 C compiler */
/* */
/* */
/* */
-/* (C) 1998-2009, Ullrich von Bassewitz */
+/* (C) 1998-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
/* Count of errors/warnings */
-unsigned ErrorCount = 0;
-unsigned WarningCount = 0;
+unsigned ErrorCount = 0;
+unsigned WarningCount = 0;
/* Warning and error options */
IntStack WarnEnable = INTSTACK(1); /* Enable warnings */
IntStack WarningsAreErrors = INTSTACK(0); /* Treat warnings as errors */
-IntStack WarnStructParam = INTSTACK(1); /* Warn about structs passed by val */
-IntStack WarnUnusedLabel = INTSTACK(1); /* Warn about unused labels */
-IntStack WarnUnusedParam = INTSTACK(1); /* Warn about unused parameters */
-IntStack WarnUnusedVar = INTSTACK(1); /* Warn about unused variables */
-IntStack WarnUnknownPragma = INTSTACK(1); /* Warn about unknown #pragmas */
+ /* Warn about: */
+IntStack WarnConstComparison= INTSTACK(1); /* - constant comparison results */
+IntStack WarnNoEffect = INTSTACK(1); /* - statements without an effect */
+IntStack WarnStructParam = INTSTACK(1); /* - structs passed by val */
+IntStack WarnUnusedLabel = INTSTACK(1); /* - unused labels */
+IntStack WarnUnusedParam = INTSTACK(1); /* - unused parameters */
+IntStack WarnUnusedVar = INTSTACK(1); /* - unused variables */
+IntStack WarnUnknownPragma = INTSTACK(1); /* - unknown #pragmas */
/* Map the name of a warning to the intstack that holds its state */
typedef struct WarnMapEntry WarnMapEntry;
static WarnMapEntry WarnMap[] = {
/* Keep sorted, even if this isn't used for now */
{ &WarningsAreErrors, "error" },
+ { &WarnConstComparison, "const-comparison" },
+ { &WarnNoEffect, "no-effect" },
{ &WarnStructParam, "struct-param" },
{ &WarnUnknownPragma, "unknown-pragma" },
{ &WarnUnusedLabel, "unused-label" },
const char* FileName;
unsigned LineNum;
if (CurTok.LI) {
- FileName = GetInputName (CurTok.LI);
- LineNum = GetInputLine (CurTok.LI);
+ FileName = GetInputName (CurTok.LI);
+ LineNum = GetInputLine (CurTok.LI);
} else {
- FileName = GetCurrentFile ();
- LineNum = GetCurrentLine ();
+ FileName = GetCurrentFile ();
+ LineNum = GetCurrentLine ();
}
fprintf (stderr, "%s(%u): Fatal: ", FileName, LineNum);
const char* FileName;
unsigned LineNum;
if (CurTok.LI) {
- FileName = GetInputName (CurTok.LI);
- LineNum = GetInputLine (CurTok.LI);
+ FileName = GetInputName (CurTok.LI);
+ LineNum = GetInputLine (CurTok.LI);
} else {
- FileName = GetCurrentFile ();
- LineNum = GetCurrentLine ();
+ FileName = GetCurrentFile ();
+ LineNum = GetCurrentLine ();
}
fprintf (stderr, "%s(%u): Internal compiler error:\n",
- FileName, LineNum);
+ FileName, LineNum);
va_start (ap, Format);
vfprintf (stderr, Format, ap);
}
++ErrorCount;
if (ErrorCount > 10) {
- Fatal ("Too many errors");
+ Fatal ("Too many errors");
}
}
} else if (IS_Get (&WarnEnable)) {
- fprintf (stderr, "%s(%u): Warning: ", Filename, LineNo);
- vfprintf (stderr, Msg, ap);
- fprintf (stderr, "\n");
+ fprintf (stderr, "%s(%u): Warning: ", Filename, LineNo);
+ vfprintf (stderr, Msg, ap);
+ fprintf (stderr, "\n");
if (Line) {
- Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
+ Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
}
- ++WarningCount;
+ ++WarningCount;
}
}
+void ListWarnings (FILE* F)
+/* Print a list of warning types/names to the given file */
+{
+ unsigned I;
+ for (I = 0; I < sizeof(WarnMap) / sizeof (WarnMap[0]); ++I) {
+ fprintf (F, "%s\n", WarnMap[I].Name);
+ }
+}
+
+
+
/*****************************************************************************/
/* Code */
/*****************************************************************************/
{
Print (stdout, 1, "%u errors, %u warnings\n", ErrorCount, WarningCount);
}
-
-
-