X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/77d3741943947b83a5d6a10a5e31650a1005dbde..35eea586ba9af7af69f0646f5f6a5958b8215dd8:/src/cpperror.c diff --git a/src/cpperror.c b/src/cpperror.c index 55312c0..73a26d9 100644 --- a/src/cpperror.c +++ b/src/cpperror.c @@ -17,8 +17,8 @@ ** 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 information on splint: info@splint.org +** To report a bug: splint-bug@splint.org ** For more information: http://www.splint.org */ /* @@ -74,7 +74,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /*@+ignorequals@*/ /*@+ignoresigns@*/ /*@+matchanyintegral@*/ -/*@-shiftsigned@*/ /*@-onlyunqglobaltrans@*/ /*@-macroconstdecl@*/ @@ -84,12 +83,13 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # define FATAL_EXIT_CODE EXIT_FAILURE -# include "lclintMacros.nf" +# include "splintMacros.nf" # include "llbasic.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); @@ -129,19 +129,19 @@ 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 (g_msgstream, " In file included"); + fprintf (g_warningstream, " In file included"); } else - fprintf (g_msgstream, ",\n "); + fprintf (g_warningstream, ",\n "); } - fprintf (g_msgstream, " from %s", + fprintf (g_warningstream, " from %s", cstring_toCharsSafe (temps = fileloc_unparseRaw (ip->nominal_fname, line))); cstring_free (temps); @@ -149,53 +149,19 @@ void cppReader_printContainingFiles (cppReader *pfile) if (!first) { - fprintf (g_msgstream, "\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 (""), - (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 (""), - (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 */ @@ -228,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) @@ -255,34 +221,21 @@ cppReader_getLoc (cppReader *pfile) cstring fname = ip->nominal_fname; fileId fid = fileTable_lookup (context_fileTable (), fname); - llassert (fileId_isValid (fid)); - - cppBuffer_lineAndColumn (ip, &line, &col); - - return fileloc_create (fid, line, col); - } - else - { - return fileloc_createBuiltin (); - } -} - -void -cppReader_printFileAndLine (cppReader *pfile) -{ - cppBuffer *ip = cppReader_fileBuffer (pfile); + if (!fileId_isValid (fid)) + { + /* evans 2002-02-09 + ** filename used in #line comment is new + */ - if (ip != NULL) - { - int line, col; + fid = fileTable_addFile (context_fileTable (), fname); + } - cppBuffer_lineAndColumn (ip, &line, &col); - cppReader_fileLineForMessage (ip->nominal_fname, - line, pfile->show_column ? col : -1); + cppBuffer_getLineAndColumn (ip, &line, &col); + return fileloc_create (fid, line, col); } else { - fprintf (stderr, "Command Line: "); + return fileloc_createBuiltin (); } } @@ -295,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. */ @@ -315,12 +267,8 @@ cppReader_warning (cppReader *pfile, /*@only@*/ cstring msg) { 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. */ @@ -345,44 +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)->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 @@ -401,9 +333,10 @@ cppReader_pedwarnWithLine (cppReader *pfile, int line, int column, void cppReader_perrorWithName (cppReader *pfile, cstring name) { - cppReader_message (pfile, 1, - message ("Preprocessing error for %s: %s", - name, lldecodeerror (errno))); + cppoptgenerror (FLG_PREPROC, + message ("%s: Preprocessing error: %s", + name, lldecodeerror (errno)), + pfile); }