Generate warnings for useless declarations like "char data;"
[fw/sdcc] / support / Util / SDCCerr.c
index 2efbdc8c2071dafc056ab2617b8603595eb2fce2..3fdc279f59d774575e3130d3810ef941686f2090 100644 (file)
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 
 #include "SDCCerr.h"
 
-
 #define USE_STDOUT_FOR_ERRORS          0
 
 #if USE_STDOUT_FOR_ERRORS
@@ -32,6 +32,7 @@
 static struct {
     ERROR_LOG_LEVEL logLevel;
     FILE *out;
+    int style; /* 1=MSVC */
 } _SDCCERRG;
 
 extern char *filename ;
@@ -384,6 +385,10 @@ struct
     "duplicate %s member '%s'" },
 { E_STACK_VIOLATION, ERROR_LEVEL_ERROR,
     "'%s' internal stack %s" },
+{ W_INT_OVL, ERROR_LEVEL_WARNING,
+    "integer overflow in expression" },
+{ W_USELESS_DECL, ERROR_LEVEL_WARNING,
+    "useless declaration (possible use of keyword as variable name)" },
 };
 
 /*
@@ -432,8 +437,11 @@ void vwerror (int errNum, va_list marker)
             fatalError++ ;
   
         if ( filename && lineno ) {
-            fprintf(_SDCCERRG.out, "%s:%d: ",filename,lineno);
-        } else if (lineno) {
+                       if(_SDCCERRG.style)
+                               fprintf(_SDCCERRG.out, "%s(%d) : ",filename,lineno);
+                       else
+                               fprintf(_SDCCERRG.out, "%s:%d: ",filename,lineno);
+         } else if (lineno) {
             fprintf(_SDCCERRG.out, "at %d: ", lineno);
         } else {
             fprintf(_SDCCERRG.out, "-:0: ");
@@ -459,7 +467,7 @@ void vwerror (int errNum, va_list marker)
         fprintf(_SDCCERRG.out, "\n");
     }
     else {
-        // Below the logging level, drop.
+        /* Below the logging level, drop. */
     }
 }
 /*
@@ -469,11 +477,38 @@ werror - Output a standard eror message with variable number of arguements
 -------------------------------------------------------------------------------
 */
 
-void werror (int errNum, ... )
+void werror (int errNum, ...)
 {
-    va_list    marker;
+    va_list marker;
     va_start(marker,errNum);
     vwerror(errNum, marker);
-    va_end( marker );
+    va_end(marker);
 }
 
+
+/*
+-------------------------------------------------------------------------------
+fatal - Output a standard eror message with variable number of arguements and
+        call exit()
+-------------------------------------------------------------------------------
+*/
+void fatal (int exitCode, int errNum, ...)
+{
+    va_list marker;
+    va_start(marker,errNum);
+    vwerror(errNum, marker);
+    va_end(marker);
+
+    exit(exitCode);
+}
+
+/*
+-------------------------------------------------------------------------------
+style - Change the output error style to MSVC
+-------------------------------------------------------------------------------
+*/
+
+void    MSVC_style (int style)
+{
+    _SDCCERRG.style = style;
+}