]>
Commit | Line | Data |
---|---|---|
616915dd | 1 | /* |
11db3170 | 2 | ** Splint - annotation-assisted static program checker |
77d37419 | 3 | ** Copyright (C) 1994-2002 University of Virginia, |
616915dd | 4 | ** Massachusetts Institute of Technology |
5 | ** | |
6 | ** This program is free software; you can redistribute it and/or modify it | |
7 | ** under the terms of the GNU General Public License as published by the | |
8 | ** Free Software Foundation; either version 2 of the License, or (at your | |
9 | ** option) any later version. | |
10 | ** | |
11 | ** This program is distributed in the hope that it will be useful, but | |
12 | ** WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | ** General Public License for more details. | |
15 | ** | |
16 | ** The GNU General Public License is available from http://www.gnu.org/ or | |
17 | ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
18 | ** MA 02111-1307, USA. | |
19 | ** | |
155af98d | 20 | ** For information on splint: info@splint.org |
21 | ** To report a bug: splint-bug@splint.org | |
11db3170 | 22 | ** For more information: http://www.splint.org |
616915dd | 23 | */ |
24 | /* | |
25 | ** fileloc.c | |
26 | */ | |
27 | /* | |
28 | * Modified by Herbert 04/19/97: | |
29 | * - added new include file portab.h. | |
30 | * - added new private function fileloc_filenameForCpp() to handle | |
31 | * filenames belonging to "#line" statements for OS/2 and MSDOS. It | |
32 | * gets called by fileloc_lineMarker() and fileloc_previousLineMarker() | |
33 | * instead of fileloc_unparseFilename(). | |
34 | */ | |
35 | ||
1b8ae690 | 36 | # include "splintMacros.nf" |
616915dd | 37 | # include "llbasic.h" |
38 | # include "fileIdList.h" | |
53a89507 | 39 | # include "osd.h" |
616915dd | 40 | # include "portab.h" |
41 | ||
42 | static /*@only@*/ fileloc fileloc_createPrim (flkind p_kind, fileId p_fid, int p_line, int p_col); | |
43 | ||
44 | static flkind fileId_kind (fileId s) | |
45 | { | |
4dd72714 | 46 | cstring fname = fileTable_rootFileName (s); |
616915dd | 47 | |
28bf4b0b | 48 | if (fileLib_isLCLFile (fname)) |
616915dd | 49 | { |
50 | return (FL_SPEC); | |
51 | } | |
68de3f33 | 52 | else if (cstring_equalPrefix (fname, cstring_makeLiteralTemp (SYSTEM_LIBDIR))) |
616915dd | 53 | { |
54 | return (FL_STDHDR); | |
55 | } | |
56 | else | |
57 | { | |
58 | return (FL_NORMAL); | |
59 | } | |
60 | } | |
61 | ||
62 | fileloc | |
63 | fileloc_decColumn (fileloc f, int x) | |
64 | { | |
65 | fileloc ret = fileloc_copy (f); | |
68de3f33 | 66 | |
abd7f895 | 67 | llassert (x >= 0); |
68 | ||
616915dd | 69 | if (x > 0 && fileloc_isDefined (ret)) |
70 | { | |
71 | llassertprint (ret->column > x, ("decColumn: %d", x)); | |
72 | ret->column -= x; | |
73 | } | |
74 | ||
75 | return ret; | |
76 | } | |
77 | ||
78 | fileloc | |
79 | fileloc_noColumn (fileloc f) | |
80 | { | |
81 | if (fileloc_isDefined (f)) | |
82 | { | |
83 | fileloc ret = fileloc_copy (f); | |
84 | ||
85 | if (fileloc_isDefined (ret)) | |
86 | { | |
87 | ret->column = 0; | |
88 | } | |
89 | ||
90 | return ret; | |
91 | } | |
92 | else | |
93 | { | |
94 | return fileloc_undefined; | |
95 | } | |
96 | } | |
97 | ||
98 | void | |
99 | fileloc_subColumn (fileloc f, int x) | |
100 | { | |
101 | if (x > 0 && fileloc_isDefined (f)) | |
102 | { | |
103 | llassert (f->column > x); | |
104 | f->column -= x; | |
105 | } | |
106 | } | |
107 | ||
108 | fileloc fileloc_copy (fileloc f) | |
109 | { | |
110 | if (fileloc_isDefined (f)) | |
111 | { | |
112 | if (fileloc_isBuiltin (f) || fileloc_isExternal (f)) | |
113 | { | |
114 | /* | |
115 | ** Legitimate (spurious) errors reported since no copy | |
116 | ** is made. | |
117 | */ | |
118 | ||
119 | /*@i3@*/ return f; /* No copy is necessary. */ | |
120 | } | |
121 | else | |
122 | { | |
123 | return (fileloc_createPrim (f->kind, f->fid, f->lineno, f->column)); | |
124 | } | |
125 | } | |
126 | else | |
127 | { | |
128 | return fileloc_undefined; | |
129 | } | |
130 | } | |
131 | ||
132 | fileloc fileloc_update (/*@only@*/ fileloc old, fileloc fnew) | |
133 | { | |
134 | if (fileloc_isUndefined (fnew)) | |
135 | { | |
136 | fileloc_free (old); | |
137 | return fileloc_undefined; | |
138 | } | |
139 | else if (fileloc_isUndefined (old) || fileloc_isBuiltin (old) || fileloc_isExternal (old)) | |
140 | { | |
141 | return (fileloc_copy (fnew)); | |
142 | } | |
143 | else | |
144 | { | |
145 | old->kind = fnew->kind; | |
146 | old->fid = fnew->fid; | |
147 | old->lineno = fnew->lineno; | |
148 | old->column = fnew->column; | |
149 | ||
150 | return old; | |
151 | } | |
152 | } | |
153 | ||
154 | fileloc fileloc_updateFileId (/*@only@*/ fileloc old, fileId s) | |
155 | { | |
156 | if (fileloc_isUndefined (old) || fileloc_isBuiltin (old) || fileloc_isExternal (old)) | |
157 | { | |
158 | return (fileloc_create (s, 1, 1)); | |
159 | } | |
160 | else | |
161 | { | |
162 | old->kind = fileId_kind (s); | |
163 | old->fid = s; | |
164 | old->lineno = 1; | |
165 | old->column = 1; | |
166 | ||
167 | return old; | |
168 | } | |
169 | } | |
170 | ||
171 | void | |
172 | fileloc_free (/*@only@*/ fileloc f) | |
173 | { | |
174 | if (fileloc_isDefined (f)) | |
175 | { | |
176 | if (f != g_currentloc) | |
177 | { | |
178 | if (fileloc_isBuiltin (f) || fileloc_isExternal (f)) | |
179 | { | |
180 | ; /* don't free */ | |
181 | } | |
182 | else | |
183 | { | |
ccf0a4a8 | 184 | sfree (f); |
616915dd | 185 | /*@-branchstate@*/ |
186 | } | |
187 | } | |
188 | else | |
189 | { | |
ccf0a4a8 | 190 | ; /* Don't free g_currentloc ever! */ |
191 | } | |
616915dd | 192 | /*@=branchstate@*/ |
193 | } | |
194 | } | |
195 | ||
196 | void | |
197 | fileloc_reallyFree (/*@only@*/ fileloc f) | |
198 | { | |
199 | if (fileloc_isDefined (f)) | |
200 | { | |
201 | if (fileloc_isBuiltin (f) || fileloc_isExternal (f)) | |
202 | { | |
203 | ; /* don't free */ | |
204 | } | |
205 | else | |
206 | { | |
207 | sfree (f); | |
208 | /*@-branchstate@*/ } /*@=branchstate@*/ | |
209 | } | |
210 | } | |
211 | ||
212 | cstring fileloc_getBase (fileloc f) | |
213 | { | |
214 | llassert (fileloc_isDefined (f)); | |
215 | ||
4dd72714 | 216 | return (fileTable_fileNameBase (f->fid)); |
616915dd | 217 | } |
218 | ||
219 | bool | |
220 | fileloc_equal (fileloc f1, fileloc f2) | |
221 | { | |
222 | return ((f1 == f2) | |
223 | || (fileloc_isDefined (f1) && fileloc_isDefined (f2) | |
224 | && ((f1->column == f2->column) && | |
225 | (f1->lineno == f2->lineno) && fileloc_sameFile (f1, f2)))); | |
226 | } | |
227 | ||
228 | int | |
229 | fileloc_compare (fileloc f1, fileloc f2) | |
230 | { | |
231 | if (fileloc_isUndefined (f1)) | |
232 | { | |
233 | if (fileloc_isUndefined (f2)) return 0; | |
234 | return -1; | |
235 | } | |
236 | ||
237 | if (fileloc_isUndefined (f2)) | |
238 | return 1; | |
239 | ||
240 | /*@access fileId@*/ | |
241 | INTCOMPARERETURN (f1->fid, f2->fid); | |
242 | /*@noaccess fileId@*/ | |
243 | ||
f4ec8018 | 244 | |
245 | /* drl 8-11-01 fix what I think is a bug | |
b7e84605 | 246 | lineno should more important than column number*/ |
247 | ||
248 | INTCOMPARERETURN (f1->lineno, f2->lineno); | |
f4ec8018 | 249 | INTCOMPARERETURN (f1->column, f2->column); |
250 | ||
616915dd | 251 | return 0; |
252 | } | |
253 | ||
254 | bool | |
255 | fileloc_withinLines (fileloc f1, fileloc f2, int n) | |
256 | { | |
257 | ||
258 | return (fileloc_isDefined (f1) && | |
259 | fileloc_isDefined (f2) && | |
260 | ((f2->lineno <= f1->lineno + n) | |
261 | && (f2->lineno >= f1->lineno) | |
262 | && fileloc_sameFile (f1, f2))); | |
263 | } | |
264 | ||
265 | bool | |
266 | fileloc_lessthan (fileloc f1, fileloc f2) | |
267 | { | |
268 | /*@access fileId*/ | |
269 | return ((fileloc_isDefined (f1) && fileloc_isDefined (f2)) | |
270 | && ((f1->fid < f2->fid) | |
271 | || ((f1->fid == f2->fid) | |
272 | && ((f1->lineno < f2->lineno) | |
273 | || ((f1->lineno == f2->lineno) | |
274 | && (f1->column < f2->column)))))); | |
275 | /*@noaccess fileId*/ | |
276 | } | |
277 | ||
278 | /* | |
279 | ** returns true if f1 and f2 are different files, | |
280 | ** or f1 is before f2 in same file | |
281 | */ | |
282 | ||
283 | bool | |
284 | fileloc_notAfter (fileloc f1, fileloc f2) | |
285 | { | |
286 | /*@access fileId*/ | |
287 | return ((fileloc_isDefined (f1) && fileloc_isDefined (f2)) | |
288 | && ((f1->fid != f2->fid) | |
289 | || ((f1->lineno < f2->lineno) | |
290 | || ((f1->lineno == f2->lineno) | |
291 | && (f1->column <= f2->column))))); | |
292 | /*@noaccess fileId@*/ | |
293 | } | |
294 | ||
295 | # ifndef NOLCL | |
296 | bool | |
297 | fileloc_isStandardLibrary (fileloc f) | |
298 | { | |
299 | cstring s = fileloc_getBase (f); | |
300 | ||
301 | return (cstring_equalLit (s, LLSTDLIBS_NAME) | |
302 | || cstring_equalLit (s, LLSTRICTLIBS_NAME) | |
303 | || cstring_equalLit (s, LLUNIXLIBS_NAME) | |
304 | || cstring_equalLit (s, LLUNIXSTRICTLIBS_NAME) | |
305 | || cstring_equalLit (s, LLPOSIXSTRICTLIBS_NAME) | |
306 | || cstring_equalLit (s, LLPOSIXLIBS_NAME)); | |
307 | } | |
308 | # endif | |
309 | ||
28bf4b0b | 310 | bool |
311 | fileloc_sameFileAndLine (fileloc f1, fileloc f2) | |
312 | { | |
313 | return (fileloc_sameFile (f1, f2) | |
314 | && (fileloc_isDefined (f1) && fileloc_isDefined (f2) | |
315 | && f1->lineno == f2->lineno)); | |
316 | } | |
317 | ||
616915dd | 318 | bool |
319 | fileloc_sameFile (fileloc f1, fileloc f2) | |
320 | { | |
321 | if ((fileloc_isUndefined (f1) || (fileloc_isUndefined (f2)) | |
322 | || (fileloc_isLib (f1)) || (fileloc_isLib (f2)))) | |
323 | { | |
324 | return FALSE; | |
325 | } | |
326 | else | |
327 | { | |
328 | return (fileId_equal (f1->fid, f2->fid)); | |
329 | } | |
330 | } | |
331 | ||
332 | bool | |
333 | fileloc_sameModule (fileloc f1, fileloc f2) | |
334 | { | |
335 | if (fileloc_isUndefined (f1)) | |
336 | { | |
337 | return (fileloc_isUndefined (f2)); | |
338 | } | |
339 | else if (fileloc_isUndefined (f2)) | |
340 | { | |
341 | return (FALSE); | |
342 | } | |
343 | else | |
344 | { | |
345 | if (fileloc_isBuiltin (f1) || fileloc_isBuiltin (f2) | |
346 | || fileloc_isExternal (f1) || fileloc_isExternal (f2)) | |
347 | { | |
348 | return fileloc_sameFile (f1, f2); | |
349 | } | |
350 | else | |
351 | { | |
352 | cstring s1 = fileloc_getBase (f1); | |
353 | cstring s2 = fileloc_getBase (f2); | |
354 | ||
355 | return (cstring_equal (s1, s2)); | |
356 | } | |
357 | } | |
358 | } | |
359 | ||
360 | bool | |
361 | fileloc_sameBaseFile (fileloc f1, fileloc f2) | |
362 | { | |
363 | if (fileloc_isUndefined (f1)) | |
364 | { | |
365 | return (fileloc_isUndefined (f2)); | |
366 | } | |
367 | else if (fileloc_isUndefined (f2)) | |
368 | { | |
369 | return (FALSE); | |
370 | } | |
371 | else | |
372 | { | |
373 | return (fileId_baseEqual (f1->fid, f2->fid)); | |
374 | } | |
375 | } | |
376 | ||
377 | bool fileloc_isSystemFile (fileloc f1) | |
378 | { | |
379 | if (fileloc_isDefined (f1) | |
380 | && !fileloc_isBuiltin (f1) | |
381 | && !fileloc_isExternal (f1)) | |
382 | { | |
383 | return (fileTable_isSystemFile (context_fileTable (), f1->fid)); | |
384 | } | |
385 | ||
386 | return FALSE; | |
387 | } | |
388 | ||
28bf4b0b | 389 | bool fileloc_isXHFile (fileloc f1) |
390 | { | |
391 | if (fileloc_isDefined (f1) | |
392 | && !fileloc_isBuiltin (f1) | |
393 | && !fileloc_isExternal (f1)) | |
394 | { | |
ccf0a4a8 | 395 | DPRINTF (("Fileloc is XH: [%p] %s", f1, fileloc_unparse (f1))); |
28bf4b0b | 396 | return (fileTable_isXHFile (context_fileTable (), f1->fid)); |
397 | } | |
398 | ||
399 | return FALSE; | |
400 | } | |
401 | ||
616915dd | 402 | bool |
403 | fileloc_almostSameFile (fileloc f1, fileloc f2) | |
404 | { | |
405 | if ((fileloc_isUndefined (f1) || (fileloc_isUndefined (f2)) | |
406 | || (fileloc_isLib (f1)) || (fileloc_isLib (f2)))) | |
407 | { | |
408 | return FALSE; | |
409 | } | |
410 | else | |
411 | { | |
412 | if (fileId_baseEqual (f1->fid, f2->fid)) | |
413 | { | |
414 | return TRUE; | |
415 | } | |
416 | else if (fileTable_isSystemFile (context_fileTable (), f1->fid) | |
417 | || fileTable_isSystemFile (context_fileTable (), f2->fid)) | |
418 | { | |
419 | return TRUE; | |
420 | } | |
421 | else if (fileTable_isSpecialFile (context_fileTable (), f1->fid) | |
422 | || fileTable_isSpecialFile (context_fileTable (), f2->fid)) | |
423 | { | |
424 | return (cstring_equal (fileloc_getBase (f1), | |
425 | fileloc_getBase (f2))); | |
426 | } | |
427 | else | |
428 | { | |
429 | return FALSE; | |
430 | } | |
431 | } | |
432 | } | |
433 | ||
434 | # ifndef NOLCL | |
435 | /*@only@*/ fileloc | |
436 | fileloc_fromTok (ltoken t) | |
437 | { | |
438 | cstring fname = ltoken_fileName (t); | |
439 | fileId fid = fileTable_lookup (context_fileTable (), fname); | |
440 | fileloc fl; | |
441 | ||
442 | if (!fileId_isValid (fid)) | |
443 | { | |
444 | fid = fileTable_addLCLFile (context_fileTable (), fname); | |
445 | } | |
446 | ||
447 | fl = fileloc_create (fid, (int) ltoken_getLine (t), (int) ltoken_getCol (t)); | |
448 | ||
449 | return (fl); | |
450 | } | |
451 | # endif | |
452 | ||
453 | /*@only@*/ fileloc | |
454 | fileloc_createLib (cstring ln) | |
455 | { | |
456 | flkind fk = FL_LIB; | |
457 | fileId fid = fileTable_lookup (context_fileTable (), ln); | |
458 | ||
459 | if (!fileId_isValid (fid)) | |
460 | { | |
461 | fid = fileTable_addLibraryFile (context_fileTable (), ln); | |
462 | } | |
463 | ||
68de3f33 | 464 | if (cstring_equalPrefix (ln, cstring_makeLiteralTemp (SYSTEM_LIBDIR))) |
616915dd | 465 | { |
466 | fk = FL_STDLIB; | |
467 | } | |
468 | ||
469 | return (fileloc_createPrim (fk, fid, 0, 0)); | |
470 | } | |
471 | ||
472 | fileloc fileloc_createRc (cstring name) | |
473 | { | |
474 | fileId fid = fileTable_addFile (context_fileTable (), name); | |
475 | ||
476 | return (fileloc_createPrim (FL_RC, fid, 0, 0)); | |
477 | } | |
478 | ||
479 | fileloc fileloc_createExternal (void) | |
480 | { | |
481 | /*@i@*/ return (fileloc_getExternal ()); | |
482 | } | |
483 | ||
484 | fileloc fileloc_getExternal (void) | |
485 | { | |
486 | static /*@owned@*/ fileloc res = fileloc_undefined; | |
487 | ||
488 | if (res == fileloc_undefined) | |
489 | { | |
490 | res = fileloc_createPrim (FL_EXTERNAL, fileId_invalid, 0, 0); | |
491 | } | |
492 | ||
493 | return res; | |
494 | } | |
495 | ||
496 | fileloc fileloc_observeBuiltin () | |
497 | { | |
498 | /*@-onlytrans@*/ return (fileloc_getBuiltin ()); /*@=onlytrans@*/ | |
499 | } | |
500 | ||
501 | fileloc fileloc_getBuiltin () | |
502 | { | |
503 | static /*@owned@*/ fileloc res = fileloc_undefined; | |
504 | ||
505 | if (res == fileloc_undefined) | |
506 | { | |
507 | res = fileloc_createPrim (FL_BUILTIN, fileId_invalid, 0, 0); | |
508 | } | |
509 | ||
510 | return res; | |
511 | } | |
512 | ||
513 | fileloc | |
514 | fileloc_makePreproc (fileloc loc) | |
515 | { | |
516 | if (fileloc_isDefined (loc)) | |
517 | { | |
518 | return (fileloc_createPrim (FL_PREPROC, loc->fid, | |
519 | loc->lineno, loc->column)); | |
520 | } | |
521 | ||
522 | return (fileloc_createPrim (FL_PREPROC, fileId_invalid, 0, 0)); | |
523 | } | |
524 | ||
525 | fileloc | |
526 | fileloc_makePreprocPrevious (fileloc loc) | |
527 | { | |
528 | if (fileloc_isDefined (loc)) | |
529 | { | |
530 | if (loc->lineno > 1) | |
531 | { | |
532 | return (fileloc_createPrim (FL_PREPROC, loc->fid, | |
533 | loc->lineno - 1, 0)); | |
534 | } | |
535 | else | |
536 | { | |
537 | return (fileloc_createPrim (FL_PREPROC, loc->fid, | |
538 | loc->lineno, 0)); | |
539 | } | |
540 | } | |
541 | ||
542 | return (fileloc_createPrim (FL_PREPROC, fileId_invalid, 0, 0)); | |
543 | } | |
544 | ||
545 | /*@only@*/ fileloc | |
546 | fileloc_createBuiltin () | |
547 | { | |
548 | return (fileloc_createPrim (FL_BUILTIN, fileId_invalid, 0, 0)); | |
549 | } | |
550 | ||
551 | # ifndef NOLCL | |
552 | /*@only@*/ fileloc | |
553 | fileloc_createImport (cstring fname, int lineno) | |
554 | { | |
555 | fileId fid = fileTable_lookup (context_fileTable (), fname); | |
556 | ||
557 | if (!fileId_isValid (fid)) | |
558 | { | |
559 | fid = fileTable_addImportFile (context_fileTable (), fname); | |
560 | } | |
561 | ||
562 | return (fileloc_createPrim (FL_IMPORT, fid, lineno, 0)); | |
563 | } | |
564 | # endif | |
565 | ||
566 | static /*@only@*/ fileloc | |
567 | fileloc_createPrim (flkind kind, fileId fid, int line, int col) | |
568 | { | |
569 | fileloc f = (fileloc) dmalloc (sizeof (*f)); | |
570 | ||
571 | f->kind = kind; | |
572 | f->fid = fid; | |
573 | f->lineno = line; | |
574 | f->column = col; | |
28bf4b0b | 575 | |
ccf0a4a8 | 576 | DPRINTF (("Fileloc create: [%p] %s", f, fileloc_unparse (f))); |
616915dd | 577 | return (f); |
578 | } | |
579 | ||
580 | # ifndef NOLCL | |
581 | /*@only@*/ fileloc | |
582 | fileloc_createSpec (fileId fid, int line, int col) | |
583 | { | |
584 | return (fileloc_createPrim (FL_SPEC, fid, line, col)); | |
585 | } | |
586 | # endif | |
587 | ||
588 | fileloc fileloc_create (fileId fid, int line, int col) | |
589 | { | |
590 | return (fileloc_createPrim (fileId_kind (fid), fid, line, col)); | |
591 | } | |
592 | ||
593 | /*@observer@*/ cstring | |
594 | fileloc_filename (fileloc f) | |
595 | { | |
4dd72714 | 596 | return (fileloc_isDefined (f) ? fileTable_rootFileName (f->fid) : cstring_makeLiteralTemp ("<unknown>")); |
53a89507 | 597 | } |
598 | ||
599 | /*@only@*/ cstring fileloc_outputFilename (fileloc f) | |
600 | { | |
601 | if (fileloc_isDefined (f)) | |
602 | { | |
4dd72714 | 603 | return osd_outputPath (fileTable_rootFileName (f->fid)); |
53a89507 | 604 | } |
605 | else | |
606 | { | |
607 | return cstring_makeLiteral ("<unknown>"); | |
608 | } | |
616915dd | 609 | } |
610 | ||
611 | cstring | |
612 | fileloc_unparseFilename (fileloc f) | |
613 | { | |
614 | if (fileloc_isDefined (f)) | |
615 | { | |
616 | switch (f->kind) | |
617 | { | |
618 | case FL_LIB: | |
53a89507 | 619 | return (message ("load file %q", fileloc_outputFilename (f))); |
616915dd | 620 | case FL_BUILTIN: |
621 | return (cstring_makeLiteral ("# builtin #")); | |
622 | case FL_IMPORT: | |
53a89507 | 623 | return (message ("import file %q", fileloc_outputFilename (f))); |
616915dd | 624 | case FL_EXTERNAL: |
625 | return (cstring_makeLiteral ("<external>")); | |
626 | default: | |
53a89507 | 627 | return (fileloc_outputFilename (f)); |
616915dd | 628 | } |
629 | } | |
630 | return cstring_undefined; | |
631 | } | |
632 | ||
633 | int | |
634 | fileloc_lineno (fileloc f) | |
635 | { | |
636 | return (fileloc_isDefined (f) ? f->lineno : -1); | |
637 | } | |
638 | ||
639 | int | |
640 | fileloc_column (fileloc f) | |
641 | { | |
642 | return (fileloc_isDefined (f) ? f->column : -1); | |
643 | } | |
644 | ||
645 | /*@only@*/ cstring | |
646 | fileloc_unparse (fileloc f) | |
647 | { | |
648 | bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); | |
649 | ||
650 | if (fileloc_isDefined (f)) | |
651 | { | |
28bf4b0b | 652 | switch (f->kind) |
616915dd | 653 | { |
616915dd | 654 | case FL_BUILTIN: |
655 | return (cstring_makeLiteral ("Command Line")); | |
656 | case FL_IMPORT: | |
657 | if (parenFormat) | |
658 | { | |
53a89507 | 659 | return (message ("import file %q(%d)", fileloc_outputFilename (f), f->lineno)); |
616915dd | 660 | } |
661 | else | |
662 | { | |
53a89507 | 663 | return (message ("import file %q:%d", fileloc_outputFilename (f), f->lineno)); |
616915dd | 664 | } |
665 | case FL_PREPROC: | |
666 | if (parenFormat) | |
667 | { | |
53a89507 | 668 | return (message ("%q(%d)", fileloc_outputFilename (f), f->lineno)); |
616915dd | 669 | } |
670 | else | |
671 | { | |
53a89507 | 672 | return (message ("%q:%d", fileloc_outputFilename (f), f->lineno)); |
616915dd | 673 | } |
674 | case FL_EXTERNAL: | |
675 | return (cstring_makeLiteral ("<external>")); | |
676 | default: | |
28bf4b0b | 677 | { |
678 | cstring fname; | |
53a89507 | 679 | |
28bf4b0b | 680 | if (f->kind == FL_LIB) |
681 | { | |
53a89507 | 682 | fname = message ("load file %q", fileloc_outputFilename (f)); |
28bf4b0b | 683 | } |
684 | else | |
685 | { | |
53a89507 | 686 | fname = fileloc_outputFilename (f); |
28bf4b0b | 687 | } |
688 | ||
689 | if (context_getFlag (FLG_SHOWCOL)) | |
690 | { | |
691 | if (fileloc_linenoDefined (f)) | |
692 | { | |
693 | if (fileloc_columnDefined (f)) | |
694 | { | |
695 | if (parenFormat) | |
696 | { | |
53a89507 | 697 | return (message ("%q(%d,%d)", fname, f->lineno, f->column)); |
28bf4b0b | 698 | } |
699 | else | |
700 | { | |
53a89507 | 701 | return (message ("%q:%d:%d", fname, f->lineno, f->column)); |
28bf4b0b | 702 | } |
703 | } | |
704 | else | |
705 | { | |
706 | if (parenFormat) | |
707 | { | |
53a89507 | 708 | return (message ("%q(%d)", fname, f->lineno)); |
28bf4b0b | 709 | } |
710 | else | |
711 | { | |
53a89507 | 712 | return (message ("%q:%d", fname, f->lineno)); |
28bf4b0b | 713 | } |
714 | } | |
715 | } | |
53a89507 | 716 | |
717 | return fname; | |
28bf4b0b | 718 | } |
719 | else if (fileloc_linenoDefined (f)) | |
720 | { | |
721 | if (parenFormat) | |
722 | { | |
53a89507 | 723 | return (message ("%q(%d)", fname, f->lineno)); |
28bf4b0b | 724 | } |
725 | else | |
726 | { | |
53a89507 | 727 | return (message ("%q:%d", fname, f->lineno)); |
28bf4b0b | 728 | } |
729 | } | |
730 | else | |
731 | { | |
53a89507 | 732 | return fname; |
28bf4b0b | 733 | } |
734 | } | |
616915dd | 735 | } |
736 | } | |
28bf4b0b | 737 | |
616915dd | 738 | return (cstring_makeLiteral ("< Location unknown >")); |
739 | } | |
740 | ||
741 | /*@only@*/ cstring | |
742 | fileloc_unparseRaw (cstring fname, int lineno) | |
743 | { | |
744 | bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); | |
745 | ||
746 | if (parenFormat) | |
747 | { | |
53a89507 | 748 | return (message ("%q(%d)", osd_outputPath (fname), lineno)); |
616915dd | 749 | } |
750 | else | |
751 | { | |
53a89507 | 752 | return (message ("%q:%d", osd_outputPath (fname), lineno)); |
616915dd | 753 | } |
754 | } | |
755 | ||
756 | /*@only@*/ cstring | |
757 | fileloc_unparseRawCol (cstring fname, int lineno, int col) | |
758 | { | |
759 | if (context_getFlag (FLG_SHOWCOL)) | |
760 | { | |
761 | bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); | |
762 | ||
763 | if (parenFormat) | |
764 | { | |
53a89507 | 765 | return (message ("%q(%d,%d)", osd_outputPath (fname), lineno, col)); |
616915dd | 766 | } |
767 | else | |
768 | { | |
53a89507 | 769 | return (message ("%q:%d:%d", osd_outputPath (fname), lineno, col)); |
616915dd | 770 | } |
771 | } | |
772 | else | |
773 | { | |
774 | return fileloc_unparseRaw (fname, lineno); | |
775 | } | |
776 | } | |
777 | ||
778 | bool fileloc_isSpecialFile (fileloc f) | |
779 | { | |
780 | if (fileloc_isDefined (f) | |
781 | && fileId_isValid (f->fid)) | |
782 | { | |
783 | return (fileTable_isSpecialFile (context_fileTable (), f->fid)); | |
784 | } | |
785 | else | |
786 | { | |
787 | return FALSE; | |
788 | } | |
789 | } | |
790 | ||
791 | bool fileloc_isHeader (fileloc f) | |
792 | { | |
793 | /* returns true if is not a .c file */ | |
794 | ||
795 | return (fileloc_isDefined (f) && fileId_isValid (f->fid) | |
796 | && fileId_isHeader (f->fid)); | |
797 | } | |
798 | ||
799 | bool fileloc_isSpec (fileloc f) | |
800 | { | |
801 | return (fileloc_isDefined (f) && | |
802 | (f->kind == FL_LIB || f->kind == FL_STDLIB || f->kind == FL_SPEC)); | |
803 | } | |
804 | ||
805 | bool fileloc_isRealSpec (fileloc f) | |
806 | { | |
807 | return (fileloc_isDefined (f) && (f->kind == FL_SPEC)); | |
808 | } | |
809 | ||
616915dd | 810 | bool fileloc_isLib (fileloc f) |
811 | { | |
812 | return (fileloc_isDefined (f) | |
813 | && (f->kind == FL_LIB || f->kind == FL_STDHDR || f->kind == FL_STDLIB)); | |
814 | } | |
815 | ||
816 | bool fileloc_isStandardLib (fileloc f) | |
817 | { | |
818 | return (fileloc_isDefined (f) && f->kind == FL_STDLIB); | |
819 | } | |
820 | ||
821 | /*@only@*/ cstring fileloc_unparseDirect (fileloc fl) | |
822 | { | |
823 | if (fileloc_isDefined (fl)) | |
824 | { | |
825 | return (message ("%d:%d:%d", | |
826 | /*@access fileId@*/ (int) fl->fid, /*@noaccess fileId@*/ | |
827 | fl->lineno, fl->column)); | |
828 | } | |
829 | else | |
830 | { | |
831 | return (cstring_makeLiteral ("<undef>")); | |
832 | } | |
833 | } | |
834 | ||
835 | bool fileloc_isUser (fileloc f) | |
836 | { | |
837 | return (fileloc_isDefined (f) | |
838 | && f->kind == FL_NORMAL); | |
839 | } | |
840 | ||
841 | ||
842 | ||
843 |