00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 # include <stdlib.h>
00082 # include <errno.h>
00083 # include <stdio.h>
00084
00085 # define FATAL_EXIT_CODE EXIT_FAILURE
00086
00087 # include "lclintMacros.nf"
00088 # include "llbasic.h"
00089 # include "cpp.h"
00090 # include "cpplib.h"
00091 # include "cpperror.h"
00092
00093 static void cppReader_printFileAndLine (cppReader *p_pfile);
00094 static void cppReader_warningWithLine (cppReader *p_pfile,
00095 int p_line, int p_column,
00096 cstring p_msg);
00097
00098
00099
00100
00101 static void cppReader_printContainingFiles (cppReader *pfile)
00102 {
00103 cppBuffer *ip;
00104 int first = 1;
00105
00106 if (pfile == NULL) {
00107
00108 return;
00109 }
00110
00111
00112
00113 if (pfile->input_stack_listing_current)
00114 {
00115 return;
00116 }
00117
00118 ip = cppReader_fileBuffer (pfile);
00119
00120
00121 if (ip == NULL)
00122 {
00123 return;
00124 }
00125
00126
00127 while ((ip = cppBuffer_prevBuffer (ip)),
00128 ip != cppReader_nullBuffer (pfile))
00129 {
00130 int line, col;
00131 cstring temps;
00132
00133 cppBuffer_lineAndColumn (ip, &line, &col);
00134 if (ip->fname != NULL)
00135 {
00136 if (first)
00137 {
00138 first = 0;
00139 fprintf (stderr, "In file included");
00140 }
00141 else
00142 fprintf (stderr, ",\n ");
00143 }
00144
00145 fprintf (stderr, " from %s",
00146 cstring_toCharsSafe (temps = fileloc_unparseRaw (ip->nominal_fname, line)));
00147
00148 cstring_free (temps);
00149 }
00150
00151 if (!first)
00152 {
00153 fprintf (stderr, ":\n");
00154 }
00155
00156
00157 pfile->input_stack_listing_current = 1;
00158 }
00159
00160 static void
00161 cppReader_fileLineForMessage (cstring filename, long line, long column)
00162 {
00163 if (column > 0)
00164 {
00165 cstring temps;
00166
00167 if (filename != NULL)
00168 {
00169 fprintf (stderr, "%s: ",
00170 cstring_toCharsSafe (temps = fileloc_unparseRawCol (filename, (int) line, (int) column)));
00171 }
00172 else
00173 {
00174 fprintf (stderr, "%s: ",
00175 cstring_toCharsSafe (temps = fileloc_unparseRawCol (cstring_makeLiteralTemp ("<no file>"),
00176 (int) line, (int) column)));
00177 }
00178
00179 cstring_free (temps);
00180 }
00181 else
00182 {
00183 cstring temps;
00184
00185 if (filename != NULL)
00186 {
00187 fprintf (stderr, "%s: ",
00188 cstring_toCharsSafe (temps = fileloc_unparseRaw (filename, (int) line)));
00189
00190 }
00191 else
00192 {
00193 fprintf (stderr, "%s: ",
00194 cstring_toCharsSafe (temps = fileloc_unparseRaw (cstring_makeLiteralTemp ("<no file>"),
00195 (int) line)));
00196 }
00197
00198 cstring_free (temps);
00199 }
00200 }
00201
00202
00203
00204 static void
00205 cppReader_message (cppReader *pfile, int is_error, cstring msg)
00206 {
00207 if (!is_error)
00208 {
00209
00210 }
00211 else if (is_error == 2)
00212 {
00213 pfile->errors = cppReader_fatalErrorLimit;
00214 }
00215 else if (pfile->errors < cppReader_fatalErrorLimit)
00216 {
00217 pfile->errors++;
00218 }
00219 else
00220 {
00221 ;
00222 }
00223
00224 fprintf (stderr, "%s", cstring_toCharsSafe (msg));
00225 fprintf (stderr, "\n");
00226 }
00227
00228
00229
00230
00231
00232
00233
00234 void
00235 cppReader_fatalError (cppReader *pfile, cstring str)
00236 {
00237 fprintf (stderr, "preprocessor: ");
00238 cppReader_message (pfile, 2, str);
00239 }
00240
00241 void
00242 cppReader_pfatalWithName (cppReader *pfile, cstring name)
00243 {
00244 cppReader_perrorWithName (pfile, name);
00245 exit (FATAL_EXIT_CODE);
00246 }
00247
00248 void
00249 cppReader_printFileAndLine (cppReader *pfile)
00250 {
00251 cppBuffer *ip = cppReader_fileBuffer (pfile);
00252
00253 if (ip != NULL)
00254 {
00255 int line, col;
00256
00257 cppBuffer_lineAndColumn (ip, &line, &col);
00258 cppReader_fileLineForMessage (ip->nominal_fname,
00259 line, pfile->show_column ? col : -1);
00260 }
00261 else
00262 {
00263 fprintf (stderr, "Command Line: ");
00264 }
00265 }
00266
00267 void
00268 cppReader_errorLit (cppReader *pfile, cstring msg)
00269 {
00270 cppReader_error (pfile, cstring_copy (msg));
00271 }
00272
00273 void
00274 cppReader_error (cppReader *pfile, cstring msg)
00275 {
00276 prepareMessage ();
00277 cppReader_printContainingFiles (pfile);
00278 cppReader_printFileAndLine (pfile);
00279 cppReader_message (pfile, 1, msg);
00280 closeMessage ();
00281 }
00282
00283
00284
00285 void
00286 cppReader_warningLit (cppReader *pfile, cstring msg)
00287 {
00288 cppReader_warning (pfile, cstring_copy (msg));
00289 }
00290
00291 void
00292 cppReader_warning (cppReader *pfile, cstring msg)
00293 {
00294 if (CPPOPTIONS (pfile)->inhibit_warnings)
00295 return;
00296
00297 if (CPPOPTIONS (pfile)->warnings_are_errors)
00298 pfile->errors++;
00299
00300 prepareMessage ();
00301 cppReader_printContainingFiles (pfile);
00302 cppReader_printFileAndLine (pfile);
00303 cppReader_message (pfile, 0, msg);
00304 closeMessage ();
00305 }
00306
00307
00308
00309 extern void
00310 cppReader_pedwarnLit (cppReader *pfile, cstring msg)
00311 {
00312 cppReader_pedwarn (pfile, cstring_copy (msg));
00313 }
00314
00315 extern void
00316 cppReader_pedwarn (cppReader *pfile, cstring msg)
00317 {
00318 if (CPPOPTIONS (pfile)->pedantic_errors)
00319 {
00320 cppReader_error (pfile, msg);
00321 }
00322 else
00323 {
00324 cppReader_warning (pfile, msg);
00325 }
00326 }
00327
00328 void
00329 cppReader_errorWithLine (cppReader *pfile, long line, long column,
00330 cstring msg)
00331 {
00332 cppBuffer *ip = cppReader_fileBuffer (pfile);
00333
00334 prepareMessage ();
00335 cppReader_printContainingFiles (pfile);
00336
00337 if (ip != NULL)
00338 cppReader_fileLineForMessage (ip->nominal_fname, line, column);
00339
00340 cppReader_message (pfile, 1, msg);
00341 closeMessage ();
00342 }
00343
00344 void
00345 cppReader_warningWithLine (cppReader *pfile,
00346 int line, int column,
00347 cstring msg)
00348 {
00349 cppBuffer *ip;
00350
00351 if (CPPOPTIONS (pfile)->inhibit_warnings)
00352 return;
00353
00354 if (CPPOPTIONS (pfile)->warnings_are_errors)
00355 pfile->errors++;
00356
00357 prepareMessage ();
00358
00359 cppReader_printContainingFiles (pfile);
00360
00361 ip = cppReader_fileBuffer (pfile);
00362
00363 if (ip != NULL)
00364 {
00365 cppReader_fileLineForMessage (ip->nominal_fname, line, column);
00366 }
00367
00368 cppReader_message (pfile, 0, msg);
00369 closeMessage ();
00370 }
00371
00372 void
00373 cppReader_pedwarnWithLine (cppReader *pfile, int line, int column,
00374 cstring msg)
00375 {
00376 if (CPPOPTIONS (pfile)->pedantic_errors)
00377 {
00378 cppReader_errorWithLine (pfile, column, line, msg);
00379 }
00380 else
00381 {
00382 cppReader_warningWithLine (pfile, line, column, msg);
00383 }
00384 }
00385
00386 void cppReader_perrorWithName (cppReader *pfile, cstring name)
00387 {
00388 cppReader_message (pfile, 1,
00389 message ("preprocessing: %s: %s",
00390 name, lldecodeerror (errno)));
00391 }
00392
00393
00394
00395
00396
00397
00398
00399