]> git.sur5r.net Git - cc65/blobdiff - src/cc65/error.c
Fixed the cc65 code that handled an addition of a pointer to a 32-bit offset.
[cc65] / src / cc65 / error.c
index bce570e34780c3033ac6f193f82178fd51067347..5218d195ca93a1160a339b897be5e69231390ba1 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-2010, 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 */
                                             /* Warn about: */
-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 */
+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;
@@ -80,6 +81,7 @@ 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"        },
@@ -104,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);
@@ -134,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);
@@ -177,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");
     }
 }
 
@@ -232,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;
 
     }
 }
@@ -281,8 +283,8 @@ void PPWarning (const char* Format, ...)
 
 IntStack* FindWarning (const char* Name)
 /* Search for a warning in the WarnMap table and return a pointer to the
- * intstack that holds its state. Return NULL if there is no such warning.
- */
+** intstack that holds its state. Return NULL if there is no such warning.
+*/
 {
     unsigned I;
 
@@ -297,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                                    */
 /*****************************************************************************/
@@ -308,6 +321,3 @@ void ErrorReport (void)
 {
     Print (stdout, 1, "%u errors, %u warnings\n", ErrorCount, WarningCount);
 }
-
-
-