]> git.sur5r.net Git - cc65/blobdiff - src/cc65/error.c
Fixed warnings generated by clang (run by Per Olofsson).
[cc65] / src / cc65 / error.c
index cba0a479e97ecb2dca7979037abf8696655a93c7..694ccdd01deaed5bcadf088821e475019a56c121 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2009, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -68,16 +68,18 @@ unsigned WarningCount       = 0;
 
 
 
-static void IntWarning (const char* Filename, unsigned Line, const char* Msg, va_list ap)
+static void IntWarning (const char* Filename, unsigned LineNo, const char* Msg, va_list ap)
 /* Print warning message - internal function. */
 {
-    if (!NoWarn) {
-               fprintf (stderr, "%s(%u): Warning: ", Filename, Line);
+    if (!IS_Get (&WarnDisable)) {
+               fprintf (stderr, "%s(%u): Warning: ", Filename, LineNo);
        vfprintf (stderr, Msg, ap);
        fprintf (stderr, "\n");
 
-       Print (stderr, 1, "Line: %s\n", line);
-       ++WarningCount;
+        if (Line) {
+           Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
+        }
+       ++WarningCount;
     }
 }
 
@@ -94,6 +96,17 @@ void Warning (const char* Format, ...)
 
 
 
+void LIWarning (const LineInfo* LI, const char* Format, ...)
+/* Print a warning message with the line info given explicitly */
+{
+    va_list ap;
+    va_start (ap, Format);
+    IntWarning (GetInputName (LI), GetInputLine (LI), Format, ap);
+    va_end (ap);
+}
+
+
+
 void PPWarning (const char* Format, ...)
 /* Print warning message. For use within the preprocessor. */
 {
@@ -105,14 +118,16 @@ void PPWarning (const char* Format, ...)
 
 
 
-static void IntError (const char* Filename, unsigned Line, const char* Msg, va_list ap)
+static void IntError (const char* Filename, unsigned LineNo, const char* Msg, va_list ap)
 /* Print an error message - internal function*/
 {
-    fprintf (stderr, "%s(%u): Error: ", Filename, Line);
+    fprintf (stderr, "%s(%u): Error: ", Filename, LineNo);
     vfprintf (stderr, Msg, ap);
     fprintf (stderr, "\n");
 
-    Print (stderr, 1, "Line: %s\n", line);
+    if (Line) {
+        Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
+    }
     ++ErrorCount;
     if (ErrorCount > 10) {
                Fatal ("Too many errors");
@@ -132,6 +147,17 @@ void Error (const char* Format, ...)
 
 
 
+void LIError (const LineInfo* LI, const char* Format, ...)
+/* Print an error message with the line info given explicitly */
+{
+    va_list ap;
+    va_start (ap, Format);
+    IntError (GetInputName (LI), GetInputLine (LI), Format, ap);
+    va_end (ap);
+}
+
+
+
 void PPError (const char* Format, ...)
 /* Print an error message. For use within the preprocessor.  */
 {
@@ -151,11 +177,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);
@@ -165,7 +191,9 @@ void Fatal (const char* Format, ...)
     va_end (ap);
     fprintf (stderr, "\n");
 
-    Print (stderr, 1, "Line: %s\n", line);
+    if (Line) {
+        Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
+    }
     exit (EXIT_FAILURE);
 }
 
@@ -179,36 +207,36 @@ 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);
     va_end (ap);
-    fprintf (stderr, "\nLine: %s\n", line);
+    fprintf (stderr, "\n");
+
+    if (Line) {
+        fprintf (stderr, "\nInput: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
+    }
 
     /* Use abort to create a core dump */
     abort ();
-}              
+}
 
 
 
 void ErrorReport (void)
 /* Report errors (called at end of compile) */
 {
-    if (ErrorCount == 0 && Verbosity > 0) {
-       printf ("No errors.\n");
-    }
+    Print (stdout, 1, "%u errors, %u warnings\n", ErrorCount, WarningCount);
 }
 
 
 
-
-