]> andersk Git - splint.git/blobdiff - src/cpperror.c
Fixed all /*@i...@*/ tags (except 1).
[splint.git] / src / cpperror.c
index 1fd702794d05aa47b1687147c452f59a5b16b5da..70ac876a251a10ff900d10ba7459bdfe1e808d38 100644 (file)
@@ -1,6 +1,6 @@
 /*
-** LCLint - annotation-assisted static program checker
-** Copyright (C) 1994-2000 University of Virginia,
+** Splint - annotation-assisted static program checker
+** Copyright (C) 1994-2003 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
@@ -17,9 +17,9 @@
 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 ** MA 02111-1307, USA.
 **
-** For information on lclint: lclint-request@cs.virginia.edu
-** To report a bug: lclint-bug@cs.virginia.edu
-** For more information: http://lclint.cs.virginia.edu
+** For information on splint: info@splint.org
+** To report a bug: splint-bug@splint.org
+** For more information: http://www.splint.org
 */
 /*
 ** cpperror.c
@@ -74,7 +74,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 /*@+ignorequals@*/
 /*@+ignoresigns@*/
 /*@+matchanyintegral@*/
-/*@-shiftsigned@*/
 /*@-onlyunqglobaltrans@*/
 /*@-macroconstdecl@*/
 
@@ -84,13 +83,13 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 # define FATAL_EXIT_CODE EXIT_FAILURE
 
-# include "lclintMacros.nf"
-# include "llbasic.h"
-# include "cpp.h"
+# include "splintMacros.nf"
+# include "basic.h"
 # include "cpplib.h"
 # include "cpperror.h"
 
-static void cppReader_printFileAndLine (cppReader *p_pfile);
+static cstring cppReader_unparseLoc (cppReader *p_pfile);
+
 static void cppReader_warningWithLine (cppReader *p_pfile, 
                                       int p_line, int p_column, 
                                       /*@only@*/ cstring p_msg);
@@ -98,7 +97,7 @@ static void cppReader_warningWithLine (cppReader *p_pfile,
 /* Print the file names and line numbers of the #include
    commands which led to the current file.  */
 
-static void cppReader_printContainingFiles (cppReader *pfile)
+void cppReader_printContainingFiles (cppReader *pfile)
 {
   cppBuffer *ip;
   int first = 1;
@@ -130,73 +129,39 @@ static void cppReader_printContainingFiles (cppReader *pfile)
       int line, col;
       cstring temps; 
       
-      cppBuffer_lineAndColumn (ip, &line, &col);
+      cppBuffer_getLineAndColumn (ip, &line, &col);
       if (ip->fname != NULL)
        {
          if (first)
            {
              first = 0;
-             fprintf (stderr, "In file included");
+             fprintf (g_warningstream, "   In file included");
            }
          else
-           fprintf (stderr, ",\n                ");
+           fprintf (g_warningstream, ",\n                ");
        }
 
-      fprintf (stderr, "  from %s", 
+      fprintf (g_warningstream, " from %s", 
               cstring_toCharsSafe (temps = fileloc_unparseRaw (ip->nominal_fname, line)));
-
+      
       cstring_free (temps);
     }
   
   if (!first)
     {
-      fprintf (stderr, ":\n");
+      fprintf (g_warningstream, "\n");
     }
 
   /* Record we have printed the status as of this time.  */
   pfile->input_stack_listing_current = 1;
 }
 
-static void
-cppReader_fileLineForMessage (cstring filename, long line, long column)
+static /*@only@*/ cstring
+cppReader_unparseLoc (cppReader *pfile)
 {
-  if (column > 0)
-    {
-      cstring temps;
-
-      if (filename != NULL)
-       {
-         fprintf (stderr, "%s: ",
-                  cstring_toCharsSafe (temps = fileloc_unparseRawCol (filename, (int) line, (int) column)));
-       }
-      else 
-       {
-         fprintf (stderr, "%s: ",
-                  cstring_toCharsSafe (temps = fileloc_unparseRawCol (cstring_makeLiteralTemp ("<no file>"),
-                                                                      (int) line, (int) column)));
-       }
-
-      cstring_free (temps);
-    }
-  else
-    {
-      cstring temps;
-
-      if (filename != NULL) 
-       {
-         fprintf (stderr, "%s: ", 
-                  cstring_toCharsSafe (temps = fileloc_unparseRaw (filename, (int) line)));
-         
-       }
-      else
-       {
-         fprintf (stderr, "%s: ",
-                  cstring_toCharsSafe (temps = fileloc_unparseRaw (cstring_makeLiteralTemp ("<no file>"),
-                                                                   (int) line)));
-       }
-
-      cstring_free (temps);
-    }
+  DPRINTF (("unparse loc: %s",
+           fileloc_unparse (cppReader_getLoc (pfile))));
+  return (fileloc_unparse (cppReader_getLoc (pfile)));
 }
 
 /* IS_ERROR is 2 for "fatal" error, 1 for error, 0 for warning */
@@ -229,7 +194,7 @@ cppReader_message (cppReader *pfile, int is_error, /*@only@*/ cstring msg)
    such as inconsistent options.  I.e. there is little point in continuing.
    (We do not exit, to support use of cpplib as a library.
    Instead, it is the caller's responsibility to check
-   cppFatalErrors.  */
+   cpplib_fatalErrors.  */
 
 void
 cppReader_fatalError (cppReader *pfile, /*@only@*/ cstring str)
@@ -245,22 +210,32 @@ cppReader_pfatalWithName (cppReader *pfile, cstring name)
   exit (FATAL_EXIT_CODE);
 }
 
-void
-cppReader_printFileAndLine (cppReader *pfile)
+/*@only@*/ fileloc
+cppReader_getLoc (cppReader *pfile)
 {
   cppBuffer *ip = cppReader_fileBuffer (pfile);
 
-  if (ip != NULL)
+  if (ip != NULL && ip->buf != NULL)
     {
       int line, col;
+      cstring fname = ip->nominal_fname;
+      fileId fid = fileTable_lookup (context_fileTable (), fname);
 
-      cppBuffer_lineAndColumn (ip, &line, &col);
-      cppReader_fileLineForMessage (ip->nominal_fname,
-                                   line, pfile->show_column ? col : -1);
+      if (!fileId_isValid (fid))
+       {
+         /* evans 2002-02-09
+         ** filename used in #line comment is new
+         */
+
+         fid = fileTable_addFile (context_fileTable (), fname);
+       }
+
+      cppBuffer_getLineAndColumn (ip, &line, &col);      
+      return fileloc_create (fid, line, col);
     }
   else
     {
-      fprintf (stderr, "Command Line: ");
+      return fileloc_createBuiltin ();
     }
 }
 
@@ -273,11 +248,10 @@ cppReader_errorLit (cppReader *pfile, /*@observer@*/ cstring msg)
 void
 cppReader_error (cppReader *pfile, /*@only@*/ cstring msg)
 {
-  prepareMessage ();
-  cppReader_printContainingFiles (pfile);
-  cppReader_printFileAndLine (pfile);
-  cppReader_message (pfile, 1, msg);
-  closeMessage ();
+  if (cppoptgenerror (FLG_PREPROC, msg, pfile))
+    {
+      pfile->errors++;
+    }
 }
 
 /* Print error message but don't count it.  */
@@ -291,17 +265,10 @@ cppReader_warningLit (cppReader *pfile, cstring msg)
 void
 cppReader_warning (cppReader *pfile, /*@only@*/ cstring msg)
 {
-  if (CPPOPTIONS (pfile)->inhibit_warnings)
-    return;
-
   if (CPPOPTIONS (pfile)->warnings_are_errors)
     pfile->errors++;
 
-  prepareMessage ();
-  cppReader_printContainingFiles (pfile);
-  cppReader_printFileAndLine (pfile);
-  cppReader_message (pfile, 0, msg);
-  closeMessage ();
+  cppoptgenerror (FLG_PREPROC, msg, pfile);
 }
 
 /* Print an error message and maybe count it.  */
@@ -326,47 +293,28 @@ cppReader_pedwarn (cppReader *pfile, /*@only@*/ cstring msg)
 }
 
 void
-cppReader_errorWithLine (cppReader *pfile, long line, long column, 
-                    /*@only@*/ cstring msg)
+cppReader_errorWithLine (cppReader *pfile, int line, int column, 
+                        /*@only@*/ cstring msg)
 {
-  cppBuffer *ip = cppReader_fileBuffer (pfile);
-
-  prepareMessage ();
-  cppReader_printContainingFiles (pfile);
-
-  if (ip != NULL)
-    cppReader_fileLineForMessage (ip->nominal_fname, line, column);
-
-  cppReader_message (pfile, 1, msg);
-  closeMessage ();
+  fileloc loc = cppReader_getLoc (pfile);
+  fileloc_setLineno (loc, line);
+  fileloc_setColumn (loc, column);
+
+  cppoptgenerror (FLG_PREPROC, message ("%s: %s",
+                                       fileloc_unparse (loc),
+                                       msg),
+                 pfile);
 }
 
 void
 cppReader_warningWithLine (cppReader *pfile, 
-                      int line, int column, 
-                      /*@only@*/ cstring msg)
+                          int line, int column, 
+                          /*@only@*/ cstring msg)
 {
-  cppBuffer *ip;
-
-  if (CPPOPTIONS (pfile)->inhibit_warnings)
-    return;
-
   if (CPPOPTIONS (pfile)->warnings_are_errors)
     pfile->errors++;
 
-  prepareMessage ();
-
-  cppReader_printContainingFiles (pfile);
-
-  ip = cppReader_fileBuffer (pfile);
-
-  if (ip != NULL)
-    {
-      cppReader_fileLineForMessage (ip->nominal_fname, line, column);
-    }
-
-  cppReader_message (pfile, 0, msg);
-  closeMessage ();
+  cppReader_errorWithLine (pfile, line, column, msg);
 }
 
 void
@@ -385,9 +333,10 @@ cppReader_pedwarnWithLine (cppReader *pfile, int line, int column,
 
 void cppReader_perrorWithName (cppReader *pfile, cstring name)
 {
-  cppReader_message (pfile, 1, 
-                    message ("preprocessing: %s: %s",
-                             name, lldecodeerror (errno)));
+  cppoptgenerror (FLG_PREPROC, 
+                 message ("%s: Preprocessing error: %s",
+                          name, lldecodeerror (errno)),
+                 pfile);
 }
 
 
This page took 0.046669 seconds and 4 git commands to generate.