]> git.sur5r.net Git - cc65/blobdiff - src/cc65/error.c
Merge remote-tracking branch 'upstream/master' into a5200
[cc65] / src / cc65 / error.c
index 95549216bcf5a8d416a31c8b5b582701222d5680..56750367a61ad7fe4136f54a40f84c3782fd5c00 100644 (file)
@@ -1,12 +1,12 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                 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 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;
@@ -77,6 +81,9 @@ struct 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"          },
     { &WarnUnusedParam,         "unused-param"          },
@@ -99,11 +106,11 @@ void Fatal (const char* Format, ...)
     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);
@@ -129,15 +136,15 @@ void Internal (const char* Format, ...)
     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);
@@ -172,7 +179,7 @@ static void IntError (const char* Filename, unsigned LineNo, const char* Msg, va
     }
     ++ErrorCount;
     if (ErrorCount > 10) {
-               Fatal ("Too many errors");
+        Fatal ("Too many errors");
     }
 }
 
@@ -227,14 +234,14 @@ static void IntWarning (const char* Filename, unsigned LineNo, const char* Msg,
 
     } 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;
 
     }
 }
@@ -292,6 +299,17 @@ IntStack* FindWarning (const char* Name)
 
 
 
+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                                    */
 /*****************************************************************************/
@@ -303,6 +321,3 @@ void ErrorReport (void)
 {
     Print (stdout, 1, "%u errors, %u warnings\n", ErrorCount, WarningCount);
 }
-
-
-