]> git.sur5r.net Git - cc65/blobdiff - src/ca65/error.c
Merge remote-tracking branch 'upstream/master' into a5200
[cc65] / src / ca65 / error.c
index 3de780d86bf643caed9951dfcd3f7af6f7a8148c..6731aa0e574e4abc01277c5ec65146d7ff5a3a3e 100644 (file)
@@ -1,12 +1,12 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                 error.c                                  */
+/*                                  error.c                                  */
 /*                                                                           */
-/*               Error handling for the ca65 macroassembler                 */
+/*                Error handling for the ca65 macroassembler                 */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2011, Ullrich von Bassewitz                                      */
+/* (C) 1998-2012, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
 
 
 /*****************************************************************************/
-/*                                  Data                                    */
+/*                                   Data                                    */
 /*****************************************************************************/
 
 
 
 /* Warning level */
-unsigned WarnLevel     = 1;
+unsigned WarnLevel      = 1;
 
 /* Statistics */
-unsigned ErrorCount    = 0;
-unsigned WarningCount  = 0;
+unsigned ErrorCount     = 0;
+unsigned WarningCount   = 0;
+
+/* Maximum number of additional notifications */
+#define MAX_NOTES       8
 
 
 
@@ -81,7 +84,7 @@ static void VPrintMsg (const FilePos* Pos, const char* Desc,
     SB_Terminate (&Msg);
 
     /* Format the message header */
-    SB_Printf (&S, "%s(%lu): %s: ",
+    SB_Printf (&S, "%s(%u): %s: ",
                SB_GetConstBuf (GetFileName (Pos->Name)),
                Pos->Line,
                Desc);
@@ -121,6 +124,7 @@ static void AddNotifications (const Collection* LineInfos)
 /* Output additional notifications for an error or warning */
 {
     unsigned I;
+    unsigned Output;
     unsigned Skipped;
 
     /* The basic line info is always in slot zero. It has been used to
@@ -128,28 +132,51 @@ static void AddNotifications (const Collection* LineInfos)
      * more information. Check them and print additional notifications if
      * they're present, but limit the number to a reasonable value.
      */
-    unsigned MaxCount = CollCount (LineInfos);
-    if (MaxCount > 6) {
-        MaxCount = 6;
-    }               
-    Skipped = CollCount (LineInfos) - MaxCount;
-    for (I = 1; I < MaxCount; ++I) {
+    for (I = 1, Output = 0, Skipped = 0; I < CollCount (LineInfos); ++I) {
         /* Get next line info */
         const LineInfo* LI = CollConstAt (LineInfos, I);
         /* Check the type and output an appropriate note */
-        unsigned Type = GetLineInfoType (LI);
-        if (Type == LI_TYPE_EXT) {
-            PrintMsg (GetSourcePos (LI), "Note",
-                      "Assembler code generated from this line");
-        } else if (Type == LI_TYPE_MACRO) {
-            PrintMsg (GetSourcePos (LI), "Note",
-                      "Macro was defined here");
+        const char* Msg;
+        switch (GetLineInfoType (LI)) {
+
+            case LI_TYPE_ASM:
+                Msg = "Expanded from here";
+                break;
+
+            case LI_TYPE_EXT:
+                Msg = "Assembler code generated from this line";
+                break;
+
+            case LI_TYPE_MACRO:
+                Msg = "Macro was defined here";
+                break;
+
+            case LI_TYPE_MACPARAM:
+                Msg = "Macro parameter came from here";
+                break;
+
+            default:
+                /* No output */
+                Msg = 0;
+                break;
+
+        }
+
+        /* Output until an upper limit of messages is reached */
+        if (Msg) {
+            if (Output < MAX_NOTES) {
+                PrintMsg (GetSourcePos (LI), "Note", "%s", Msg);
+                ++Output;
+            } else {
+                ++Skipped;
+            }
         }
     }
 
     /* Add a note if we have more stuff that we won't output */
     if (Skipped > 0) {
-        PrintMsg (GetSourcePos (CollConstAt (LineInfos, 0)), "Note",
+        const LineInfo* LI = CollConstAt (LineInfos, 0);
+        PrintMsg (GetSourcePos (LI), "Note",
                   "Dropping %u additional line infos", Skipped);
     }
 }
@@ -157,7 +184,7 @@ static void AddNotifications (const Collection* LineInfos)
 
 
 /*****************************************************************************/
-/*                                Warnings                                  */
+/*                                 Warnings                                  */
 /*****************************************************************************/
 
 
@@ -189,7 +216,7 @@ void Warning (unsigned Level, const char* Format, ...)
         Collection LineInfos = STATIC_COLLECTION_INITIALIZER;
 
         /* Get line infos for the current position */
-        GetFullLineInfo (&LineInfos, 0);
+        GetFullLineInfo (&LineInfos);
 
         /* Output the message */
         va_start (ap, Format);
@@ -197,6 +224,7 @@ void Warning (unsigned Level, const char* Format, ...)
         va_end (ap);
 
         /* Free the line info list */
+        ReleaseFullLineInfo (&LineInfos);
         DoneCollection (&LineInfos);
     }
 }
@@ -234,7 +262,7 @@ void LIWarning (const Collection* LineInfos, unsigned Level, const char* Format,
 
 
 /*****************************************************************************/
-/*                                 Errors                                   */
+/*                                  Errors                                   */
 /*****************************************************************************/
 
 
@@ -264,7 +292,7 @@ void Error (const char* Format, ...)
     Collection LineInfos = STATIC_COLLECTION_INITIALIZER;
 
     /* Get line infos for the current position */
-    GetFullLineInfo (&LineInfos, 0);
+    GetFullLineInfo (&LineInfos);
 
     /* Output the message */
     va_start (ap, Format);
@@ -272,11 +300,26 @@ void Error (const char* Format, ...)
     va_end (ap);
 
     /* Free the line info list */
+    ReleaseFullLineInfo (&LineInfos);
     DoneCollection (&LineInfos);
 }
 
 
 
+void PError (const FilePos* Pos, const char* Format, ...)
+/* Print an error message giving an explicit file and position. */
+{
+    va_list ap;
+    va_start (ap, Format);
+    VPrintMsg (Pos, "Error", Format, ap);
+    va_end (ap);
+
+    /* Count errors */
+    ++ErrorCount;
+}
+
+
+
 void LIError (const Collection* LineInfos, const char* Format, ...)
 /* Print an error message using the given line infos. */
 {
@@ -296,7 +339,7 @@ void ErrorSkip (const char* Format, ...)
     Collection LineInfos = STATIC_COLLECTION_INITIALIZER;
 
     /* Get line infos for the current position */
-    GetFullLineInfo (&LineInfos, 0);
+    GetFullLineInfo (&LineInfos);
 
     /* Output the message */
     va_start (ap, Format);
@@ -304,6 +347,7 @@ void ErrorSkip (const char* Format, ...)
     va_end (ap);
 
     /* Free the line info list */
+    ReleaseFullLineInfo (&LineInfos);
     DoneCollection (&LineInfos);
 
     /* Skip tokens until we reach the end of the line */
@@ -313,7 +357,7 @@ void ErrorSkip (const char* Format, ...)
 
 
 /*****************************************************************************/
-/*                                  Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -356,6 +400,3 @@ void Internal (const char* Format, ...)
 
     exit (EXIT_FAILURE);
 }
-
-
-