]>
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" |
495af944 | 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 | ||
495af944 | 212 | /*drl added 04/16/2002 */ |
213 | bool fileloc_canGetName (fileloc f) | |
214 | { | |
215 | if (fileloc_isValid(f) && (fileId_isValid (f->fid)) ) | |
216 | { | |
217 | return TRUE; | |
218 | } | |
219 | ||
220 | return FALSE; | |
221 | } | |
222 | ||
223 | /*drl added 04/16/2002 */ | |
224 | cstring fileloc_getName (fileloc f) | |
225 | { | |
226 | cstring rootName; | |
227 | ||
228 | if (! (fileloc_isValid(f) && (fileId_isValid (f->fid)) ) ) | |
229 | { | |
230 | llcontbug(cstring_makeLiteral("fileloc_getName call with invalid fileloc and fileloc->id")); | |
231 | return cstring_newEmpty(); | |
232 | } | |
233 | ||
234 | // rootName = fileTable_getRootName (context_fileTable(), f->fid); | |
235 | ||
236 | rootName = fileTable_fileName ( f->fid); | |
237 | ||
238 | return cstring_copy(rootName); | |
239 | } | |
240 | ||
241 | ||
242 | ||
616915dd | 243 | cstring fileloc_getBase (fileloc f) |
244 | { | |
245 | llassert (fileloc_isDefined (f)); | |
246 | ||
4dd72714 | 247 | return (fileTable_fileNameBase (f->fid)); |
616915dd | 248 | } |
249 | ||
250 | bool | |
251 | fileloc_equal (fileloc f1, fileloc f2) | |
252 | { | |
253 | return ((f1 == f2) | |
254 | || (fileloc_isDefined (f1) && fileloc_isDefined (f2) | |
255 | && ((f1->column == f2->column) && | |
256 | (f1->lineno == f2->lineno) && fileloc_sameFile (f1, f2)))); | |
257 | } | |
258 | ||
259 | int | |
260 | fileloc_compare (fileloc f1, fileloc f2) | |
261 | { | |
262 | if (fileloc_isUndefined (f1)) | |
263 | { | |
264 | if (fileloc_isUndefined (f2)) return 0; | |
265 | return -1; | |
266 | } | |
267 | ||
268 | if (fileloc_isUndefined (f2)) | |
269 | return 1; | |
270 | ||
271 | /*@access fileId@*/ | |
272 | INTCOMPARERETURN (f1->fid, f2->fid); | |
273 | /*@noaccess fileId@*/ | |
274 | ||
f4ec8018 | 275 | |
276 | /* drl 8-11-01 fix what I think is a bug | |
b7e84605 | 277 | lineno should more important than column number*/ |
278 | ||
279 | INTCOMPARERETURN (f1->lineno, f2->lineno); | |
f4ec8018 | 280 | INTCOMPARERETURN (f1->column, f2->column); |
281 | ||
616915dd | 282 | return 0; |
283 | } | |
284 | ||
285 | bool | |
286 | fileloc_withinLines (fileloc f1, fileloc f2, int n) | |
287 | { | |
288 | ||
289 | return (fileloc_isDefined (f1) && | |
290 | fileloc_isDefined (f2) && | |
291 | ((f2->lineno <= f1->lineno + n) | |
292 | && (f2->lineno >= f1->lineno) | |
293 | && fileloc_sameFile (f1, f2))); | |
294 | } | |
295 | ||
296 | bool | |
297 | fileloc_lessthan (fileloc f1, fileloc f2) | |
298 | { | |
299 | /*@access fileId*/ | |
300 | return ((fileloc_isDefined (f1) && fileloc_isDefined (f2)) | |
301 | && ((f1->fid < f2->fid) | |
302 | || ((f1->fid == f2->fid) | |
303 | && ((f1->lineno < f2->lineno) | |
304 | || ((f1->lineno == f2->lineno) | |
305 | && (f1->column < f2->column)))))); | |
306 | /*@noaccess fileId*/ | |
307 | } | |
308 | ||
309 | /* | |
310 | ** returns true if f1 and f2 are different files, | |
311 | ** or f1 is before f2 in same file | |
312 | */ | |
313 | ||
314 | bool | |
315 | fileloc_notAfter (fileloc f1, fileloc f2) | |
316 | { | |
317 | /*@access fileId*/ | |
318 | return ((fileloc_isDefined (f1) && fileloc_isDefined (f2)) | |
319 | && ((f1->fid != f2->fid) | |
320 | || ((f1->lineno < f2->lineno) | |
321 | || ((f1->lineno == f2->lineno) | |
322 | && (f1->column <= f2->column))))); | |
323 | /*@noaccess fileId@*/ | |
324 | } | |
325 | ||
326 | # ifndef NOLCL | |
327 | bool | |
328 | fileloc_isStandardLibrary (fileloc f) | |
329 | { | |
330 | cstring s = fileloc_getBase (f); | |
331 | ||
332 | return (cstring_equalLit (s, LLSTDLIBS_NAME) | |
333 | || cstring_equalLit (s, LLSTRICTLIBS_NAME) | |
334 | || cstring_equalLit (s, LLUNIXLIBS_NAME) | |
335 | || cstring_equalLit (s, LLUNIXSTRICTLIBS_NAME) | |
336 | || cstring_equalLit (s, LLPOSIXSTRICTLIBS_NAME) | |
337 | || cstring_equalLit (s, LLPOSIXLIBS_NAME)); | |
338 | } | |
339 | # endif | |
340 | ||
28bf4b0b | 341 | bool |
342 | fileloc_sameFileAndLine (fileloc f1, fileloc f2) | |
343 | { | |
344 | return (fileloc_sameFile (f1, f2) | |
345 | && (fileloc_isDefined (f1) && fileloc_isDefined (f2) | |
346 | && f1->lineno == f2->lineno)); | |
347 | } | |
348 | ||
616915dd | 349 | bool |
350 | fileloc_sameFile (fileloc f1, fileloc f2) | |
351 | { | |
352 | if ((fileloc_isUndefined (f1) || (fileloc_isUndefined (f2)) | |
353 | || (fileloc_isLib (f1)) || (fileloc_isLib (f2)))) | |
354 | { | |
355 | return FALSE; | |
356 | } | |
357 | else | |
358 | { | |
359 | return (fileId_equal (f1->fid, f2->fid)); | |
360 | } | |
361 | } | |
362 | ||
363 | bool | |
364 | fileloc_sameModule (fileloc f1, fileloc f2) | |
365 | { | |
366 | if (fileloc_isUndefined (f1)) | |
367 | { | |
368 | return (fileloc_isUndefined (f2)); | |
369 | } | |
370 | else if (fileloc_isUndefined (f2)) | |
371 | { | |
372 | return (FALSE); | |
373 | } | |
374 | else | |
375 | { | |
376 | if (fileloc_isBuiltin (f1) || fileloc_isBuiltin (f2) | |
377 | || fileloc_isExternal (f1) || fileloc_isExternal (f2)) | |
378 | { | |
379 | return fileloc_sameFile (f1, f2); | |
380 | } | |
381 | else | |
382 | { | |
383 | cstring s1 = fileloc_getBase (f1); | |
384 | cstring s2 = fileloc_getBase (f2); | |
385 | ||
495af944 | 386 | return (cstring_equal (s1, s2)); |
616915dd | 387 | } |
388 | } | |
389 | } | |
390 | ||
391 | bool | |
392 | fileloc_sameBaseFile (fileloc f1, fileloc f2) | |
393 | { | |
394 | if (fileloc_isUndefined (f1)) | |
395 | { | |
396 | return (fileloc_isUndefined (f2)); | |
397 | } | |
398 | else if (fileloc_isUndefined (f2)) | |
399 | { | |
400 | return (FALSE); | |
401 | } | |
402 | else | |
403 | { | |
404 | return (fileId_baseEqual (f1->fid, f2->fid)); | |
405 | } | |
406 | } | |
407 | ||
408 | bool fileloc_isSystemFile (fileloc f1) | |
409 | { | |
410 | if (fileloc_isDefined (f1) | |
411 | && !fileloc_isBuiltin (f1) | |
412 | && !fileloc_isExternal (f1)) | |
413 | { | |
414 | return (fileTable_isSystemFile (context_fileTable (), f1->fid)); | |
415 | } | |
416 | ||
417 | return FALSE; | |
418 | } | |
419 | ||
28bf4b0b | 420 | bool fileloc_isXHFile (fileloc f1) |
421 | { | |
422 | if (fileloc_isDefined (f1) | |
423 | && !fileloc_isBuiltin (f1) | |
424 | && !fileloc_isExternal (f1)) | |
425 | { | |
ccf0a4a8 | 426 | DPRINTF (("Fileloc is XH: [%p] %s", f1, fileloc_unparse (f1))); |
28bf4b0b | 427 | return (fileTable_isXHFile (context_fileTable (), f1->fid)); |
428 | } | |
429 | ||
430 | return FALSE; | |
431 | } | |
432 | ||
616915dd | 433 | bool |
434 | fileloc_almostSameFile (fileloc f1, fileloc f2) | |
435 | { | |
436 | if ((fileloc_isUndefined (f1) || (fileloc_isUndefined (f2)) | |
437 | || (fileloc_isLib (f1)) || (fileloc_isLib (f2)))) | |
438 | { | |
439 | return FALSE; | |
440 | } | |
441 | else | |
442 | { | |
443 | if (fileId_baseEqual (f1->fid, f2->fid)) | |
444 | { | |
445 | return TRUE; | |
446 | } | |
447 | else if (fileTable_isSystemFile (context_fileTable (), f1->fid) | |
448 | || fileTable_isSystemFile (context_fileTable (), f2->fid)) | |
449 | { | |
450 | return TRUE; | |
451 | } | |
452 | else if (fileTable_isSpecialFile (context_fileTable (), f1->fid) | |
453 | || fileTable_isSpecialFile (context_fileTable (), f2->fid)) | |
454 | { | |
455 | return (cstring_equal (fileloc_getBase (f1), | |
456 | fileloc_getBase (f2))); | |
457 | } | |
458 | else | |
459 | { | |
460 | return FALSE; | |
461 | } | |
462 | } | |
463 | } | |
464 | ||
465 | # ifndef NOLCL | |
466 | /*@only@*/ fileloc | |
467 | fileloc_fromTok (ltoken t) | |
468 | { | |
469 | cstring fname = ltoken_fileName (t); | |
470 | fileId fid = fileTable_lookup (context_fileTable (), fname); | |
471 | fileloc fl; | |
472 | ||
473 | if (!fileId_isValid (fid)) | |
474 | { | |
475 | fid = fileTable_addLCLFile (context_fileTable (), fname); | |
476 | } | |
477 | ||
478 | fl = fileloc_create (fid, (int) ltoken_getLine (t), (int) ltoken_getCol (t)); | |
479 | ||
480 | return (fl); | |
481 | } | |
482 | # endif | |
483 | ||
484 | /*@only@*/ fileloc | |
485 | fileloc_createLib (cstring ln) | |
486 | { | |
487 | flkind fk = FL_LIB; | |
488 | fileId fid = fileTable_lookup (context_fileTable (), ln); | |
489 | ||
490 | if (!fileId_isValid (fid)) | |
491 | { | |
492 | fid = fileTable_addLibraryFile (context_fileTable (), ln); | |
493 | } | |
494 | ||
68de3f33 | 495 | if (cstring_equalPrefix (ln, cstring_makeLiteralTemp (SYSTEM_LIBDIR))) |
616915dd | 496 | { |
497 | fk = FL_STDLIB; | |
498 | } | |
499 | ||
500 | return (fileloc_createPrim (fk, fid, 0, 0)); | |
501 | } | |
502 | ||
503 | fileloc fileloc_createRc (cstring name) | |
504 | { | |
505 | fileId fid = fileTable_addFile (context_fileTable (), name); | |
506 | ||
507 | return (fileloc_createPrim (FL_RC, fid, 0, 0)); | |
508 | } | |
509 | ||
510 | fileloc fileloc_createExternal (void) | |
511 | { | |
512 | /*@i@*/ return (fileloc_getExternal ()); | |
513 | } | |
514 | ||
515 | fileloc fileloc_getExternal (void) | |
516 | { | |
517 | static /*@owned@*/ fileloc res = fileloc_undefined; | |
518 | ||
519 | if (res == fileloc_undefined) | |
520 | { | |
521 | res = fileloc_createPrim (FL_EXTERNAL, fileId_invalid, 0, 0); | |
522 | } | |
523 | ||
524 | return res; | |
525 | } | |
526 | ||
527 | fileloc fileloc_observeBuiltin () | |
528 | { | |
529 | /*@-onlytrans@*/ return (fileloc_getBuiltin ()); /*@=onlytrans@*/ | |
530 | } | |
531 | ||
532 | fileloc fileloc_getBuiltin () | |
533 | { | |
534 | static /*@owned@*/ fileloc res = fileloc_undefined; | |
535 | ||
536 | if (res == fileloc_undefined) | |
537 | { | |
538 | res = fileloc_createPrim (FL_BUILTIN, fileId_invalid, 0, 0); | |
539 | } | |
540 | ||
541 | return res; | |
542 | } | |
543 | ||
544 | fileloc | |
545 | fileloc_makePreproc (fileloc loc) | |
546 | { | |
547 | if (fileloc_isDefined (loc)) | |
548 | { | |
549 | return (fileloc_createPrim (FL_PREPROC, loc->fid, | |
550 | loc->lineno, loc->column)); | |
551 | } | |
552 | ||
553 | return (fileloc_createPrim (FL_PREPROC, fileId_invalid, 0, 0)); | |
554 | } | |
555 | ||
556 | fileloc | |
557 | fileloc_makePreprocPrevious (fileloc loc) | |
558 | { | |
559 | if (fileloc_isDefined (loc)) | |
560 | { | |
561 | if (loc->lineno > 1) | |
562 | { | |
563 | return (fileloc_createPrim (FL_PREPROC, loc->fid, | |
564 | loc->lineno - 1, 0)); | |
565 | } | |
566 | else | |
567 | { | |
568 | return (fileloc_createPrim (FL_PREPROC, loc->fid, | |
569 | loc->lineno, 0)); | |
570 | } | |
571 | } | |
572 | ||
573 | return (fileloc_createPrim (FL_PREPROC, fileId_invalid, 0, 0)); | |
574 | } | |
575 | ||
576 | /*@only@*/ fileloc | |
577 | fileloc_createBuiltin () | |
578 | { | |
579 | return (fileloc_createPrim (FL_BUILTIN, fileId_invalid, 0, 0)); | |
580 | } | |
581 | ||
582 | # ifndef NOLCL | |
583 | /*@only@*/ fileloc | |
584 | fileloc_createImport (cstring fname, int lineno) | |
585 | { | |
586 | fileId fid = fileTable_lookup (context_fileTable (), fname); | |
587 | ||
588 | if (!fileId_isValid (fid)) | |
589 | { | |
590 | fid = fileTable_addImportFile (context_fileTable (), fname); | |
591 | } | |
592 | ||
593 | return (fileloc_createPrim (FL_IMPORT, fid, lineno, 0)); | |
594 | } | |
595 | # endif | |
596 | ||
597 | static /*@only@*/ fileloc | |
598 | fileloc_createPrim (flkind kind, fileId fid, int line, int col) | |
599 | { | |
600 | fileloc f = (fileloc) dmalloc (sizeof (*f)); | |
601 | ||
602 | f->kind = kind; | |
603 | f->fid = fid; | |
604 | f->lineno = line; | |
605 | f->column = col; | |
28bf4b0b | 606 | |
ccf0a4a8 | 607 | DPRINTF (("Fileloc create: [%p] %s", f, fileloc_unparse (f))); |
616915dd | 608 | return (f); |
609 | } | |
610 | ||
611 | # ifndef NOLCL | |
612 | /*@only@*/ fileloc | |
613 | fileloc_createSpec (fileId fid, int line, int col) | |
614 | { | |
615 | return (fileloc_createPrim (FL_SPEC, fid, line, col)); | |
616 | } | |
617 | # endif | |
618 | ||
619 | fileloc fileloc_create (fileId fid, int line, int col) | |
620 | { | |
621 | return (fileloc_createPrim (fileId_kind (fid), fid, line, col)); | |
622 | } | |
623 | ||
624 | /*@observer@*/ cstring | |
625 | fileloc_filename (fileloc f) | |
626 | { | |
4dd72714 | 627 | return (fileloc_isDefined (f) ? fileTable_rootFileName (f->fid) : cstring_makeLiteralTemp ("<unknown>")); |
53a89507 | 628 | } |
629 | ||
630 | /*@only@*/ cstring fileloc_outputFilename (fileloc f) | |
631 | { | |
632 | if (fileloc_isDefined (f)) | |
633 | { | |
495af944 | 634 | return osd_outputPath (fileTable_rootFileName (f->fid)); |
53a89507 | 635 | } |
636 | else | |
637 | { | |
638 | return cstring_makeLiteral ("<unknown>"); | |
639 | } | |
616915dd | 640 | } |
641 | ||
642 | cstring | |
643 | fileloc_unparseFilename (fileloc f) | |
644 | { | |
645 | if (fileloc_isDefined (f)) | |
646 | { | |
647 | switch (f->kind) | |
648 | { | |
649 | case FL_LIB: | |
53a89507 | 650 | return (message ("load file %q", fileloc_outputFilename (f))); |
616915dd | 651 | case FL_BUILTIN: |
652 | return (cstring_makeLiteral ("# builtin #")); | |
653 | case FL_IMPORT: | |
53a89507 | 654 | return (message ("import file %q", fileloc_outputFilename (f))); |
616915dd | 655 | case FL_EXTERNAL: |
656 | return (cstring_makeLiteral ("<external>")); | |
657 | default: | |
53a89507 | 658 | return (fileloc_outputFilename (f)); |
616915dd | 659 | } |
660 | } | |
661 | return cstring_undefined; | |
662 | } | |
663 | ||
664 | int | |
665 | fileloc_lineno (fileloc f) | |
666 | { | |
667 | return (fileloc_isDefined (f) ? f->lineno : -1); | |
668 | } | |
669 | ||
670 | int | |
671 | fileloc_column (fileloc f) | |
672 | { | |
673 | return (fileloc_isDefined (f) ? f->column : -1); | |
674 | } | |
675 | ||
676 | /*@only@*/ cstring | |
677 | fileloc_unparse (fileloc f) | |
678 | { | |
679 | bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); | |
01a8227e | 680 | bool htmlFormat = context_getFlag (FLG_HTMLFILEFORMAT); |
681 | cstring res = cstring_undefined; | |
616915dd | 682 | |
683 | if (fileloc_isDefined (f)) | |
684 | { | |
28bf4b0b | 685 | switch (f->kind) |
616915dd | 686 | { |
616915dd | 687 | case FL_BUILTIN: |
495af944 | 688 | return (cstring_makeLiteral ("Command Line")); |
616915dd | 689 | case FL_IMPORT: |
690 | if (parenFormat) | |
691 | { | |
01a8227e | 692 | res = message ("import file %q(%d)", fileloc_outputFilename (f), f->lineno); |
616915dd | 693 | } |
694 | else | |
695 | { | |
01a8227e | 696 | res = message ("import file %q:%d", fileloc_outputFilename (f), f->lineno); |
616915dd | 697 | } |
01a8227e | 698 | break; |
616915dd | 699 | case FL_PREPROC: |
01a8227e | 700 | { |
701 | if (parenFormat) | |
702 | { | |
703 | res = message ("%q(%d)", fileloc_outputFilename (f), f->lineno); | |
704 | } | |
705 | else | |
706 | { | |
707 | res = message ("%q:%d", fileloc_outputFilename (f), f->lineno); | |
708 | } | |
709 | ||
710 | break; | |
711 | } | |
616915dd | 712 | case FL_EXTERNAL: |
01a8227e | 713 | res = cstring_makeLiteral ("<external>"); |
714 | break; | |
616915dd | 715 | default: |
28bf4b0b | 716 | { |
717 | cstring fname; | |
53a89507 | 718 | |
28bf4b0b | 719 | if (f->kind == FL_LIB) |
720 | { | |
53a89507 | 721 | fname = message ("load file %q", fileloc_outputFilename (f)); |
28bf4b0b | 722 | } |
723 | else | |
724 | { | |
53a89507 | 725 | fname = fileloc_outputFilename (f); |
28bf4b0b | 726 | } |
727 | ||
728 | if (context_getFlag (FLG_SHOWCOL)) | |
729 | { | |
730 | if (fileloc_linenoDefined (f)) | |
731 | { | |
732 | if (fileloc_columnDefined (f)) | |
733 | { | |
734 | if (parenFormat) | |
735 | { | |
01a8227e | 736 | res = message ("%q(%d,%d)", fname, f->lineno, f->column); |
28bf4b0b | 737 | } |
738 | else | |
739 | { | |
01a8227e | 740 | res = message ("%q:%d:%d", fname, f->lineno, f->column); |
28bf4b0b | 741 | } |
742 | } | |
743 | else | |
744 | { | |
745 | if (parenFormat) | |
746 | { | |
01a8227e | 747 | res = message ("%q(%d)", fname, f->lineno); |
28bf4b0b | 748 | } |
749 | else | |
750 | { | |
01a8227e | 751 | res = message ("%q:%d", fname, f->lineno); |
28bf4b0b | 752 | } |
753 | } | |
754 | } | |
01a8227e | 755 | else |
756 | { | |
757 | res = fname; | |
758 | } | |
28bf4b0b | 759 | } |
760 | else if (fileloc_linenoDefined (f)) | |
761 | { | |
762 | if (parenFormat) | |
763 | { | |
01a8227e | 764 | res = message ("%q(%d)", fname, f->lineno); |
28bf4b0b | 765 | } |
766 | else | |
767 | { | |
01a8227e | 768 | res = message ("%q:%d", fname, f->lineno); |
28bf4b0b | 769 | } |
770 | } | |
771 | else | |
772 | { | |
01a8227e | 773 | res = fname; |
28bf4b0b | 774 | } |
775 | } | |
616915dd | 776 | } |
28bf4b0b | 777 | |
01a8227e | 778 | if (htmlFormat && fileloc_linenoDefined (f)) |
779 | { | |
780 | res = message ("<a href=\"#line%d\">%s</a>", f->lineno, res); | |
781 | } | |
782 | } | |
783 | else | |
784 | { | |
785 | res = cstring_makeLiteral ("< Location unknown >"); | |
786 | } | |
f9264521 | 787 | |
01a8227e | 788 | return res; |
616915dd | 789 | } |
790 | ||
791 | /*@only@*/ cstring | |
792 | fileloc_unparseRaw (cstring fname, int lineno) | |
793 | { | |
dadc0519 | 794 | if (!cstring_isEmpty (fname)) |
616915dd | 795 | { |
dadc0519 | 796 | bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); |
797 | ||
798 | if (parenFormat) | |
799 | { | |
800 | return (message ("%q(%d)", osd_outputPath (fname), lineno)); | |
801 | } | |
802 | else | |
803 | { | |
804 | return (message ("%q:%d", osd_outputPath (fname), lineno)); | |
805 | } | |
616915dd | 806 | } |
807 | else | |
808 | { | |
dadc0519 | 809 | return cstring_makeLiteral ("Command Line"); |
616915dd | 810 | } |
811 | } | |
812 | ||
813 | /*@only@*/ cstring | |
814 | fileloc_unparseRawCol (cstring fname, int lineno, int col) | |
815 | { | |
dadc0519 | 816 | if (!cstring_isEmpty (fname)) |
616915dd | 817 | { |
dadc0519 | 818 | if (context_getFlag (FLG_SHOWCOL)) |
616915dd | 819 | { |
dadc0519 | 820 | bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT); |
821 | ||
822 | if (parenFormat) | |
823 | { | |
824 | return (message ("%q(%d,%d)", osd_outputPath (fname), lineno, col)); | |
825 | } | |
826 | else | |
827 | { | |
828 | return (message ("%q:%d:%d", osd_outputPath (fname), lineno, col)); | |
829 | } | |
616915dd | 830 | } |
831 | else | |
832 | { | |
dadc0519 | 833 | return fileloc_unparseRaw (fname, lineno); |
616915dd | 834 | } |
835 | } | |
836 | else | |
837 | { | |
dadc0519 | 838 | return cstring_makeLiteral ("Command Line"); |
616915dd | 839 | } |
840 | } | |
841 | ||
842 | bool fileloc_isSpecialFile (fileloc f) | |
843 | { | |
844 | if (fileloc_isDefined (f) | |
845 | && fileId_isValid (f->fid)) | |
846 | { | |
847 | return (fileTable_isSpecialFile (context_fileTable (), f->fid)); | |
848 | } | |
849 | else | |
850 | { | |
851 | return FALSE; | |
852 | } | |
853 | } | |
854 | ||
855 | bool fileloc_isHeader (fileloc f) | |
856 | { | |
857 | /* returns true if is not a .c file */ | |
858 | ||
859 | return (fileloc_isDefined (f) && fileId_isValid (f->fid) | |
860 | && fileId_isHeader (f->fid)); | |
861 | } | |
862 | ||
863 | bool fileloc_isSpec (fileloc f) | |
864 | { | |
865 | return (fileloc_isDefined (f) && | |
866 | (f->kind == FL_LIB || f->kind == FL_STDLIB || f->kind == FL_SPEC)); | |
867 | } | |
868 | ||
869 | bool fileloc_isRealSpec (fileloc f) | |
870 | { | |
871 | return (fileloc_isDefined (f) && (f->kind == FL_SPEC)); | |
872 | } | |
873 | ||
616915dd | 874 | bool fileloc_isLib (fileloc f) |
875 | { | |
876 | return (fileloc_isDefined (f) | |
877 | && (f->kind == FL_LIB || f->kind == FL_STDHDR || f->kind == FL_STDLIB)); | |
878 | } | |
879 | ||
880 | bool fileloc_isStandardLib (fileloc f) | |
881 | { | |
882 | return (fileloc_isDefined (f) && f->kind == FL_STDLIB); | |
883 | } | |
884 | ||
885 | /*@only@*/ cstring fileloc_unparseDirect (fileloc fl) | |
886 | { | |
887 | if (fileloc_isDefined (fl)) | |
888 | { | |
889 | return (message ("%d:%d:%d", | |
890 | /*@access fileId@*/ (int) fl->fid, /*@noaccess fileId@*/ | |
891 | fl->lineno, fl->column)); | |
892 | } | |
893 | else | |
894 | { | |
895 | return (cstring_makeLiteral ("<undef>")); | |
896 | } | |
897 | } | |
898 | ||
899 | bool fileloc_isUser (fileloc f) | |
900 | { | |
901 | return (fileloc_isDefined (f) | |
902 | && f->kind == FL_NORMAL); | |
903 | } | |
904 | ||
905 | ||
906 | ||
907 | ||
495af944 | 908 | bool fileloc_isDotH (fileloc f) |
909 | { | |
910 | cstring rootName; | |
911 | ||
912 | if (! (fileloc_isValid(f) && (fileId_isValid (f->fid)) ) ) | |
913 | { | |
914 | return FALSE; | |
915 | } | |
916 | ||
917 | rootName = fileTable_getRootName (context_fileTable() , f->fid); | |
918 | ||
919 | if (cstring_isDotH(rootName) ) | |
920 | { | |
921 | return TRUE; | |
922 | } | |
923 | else | |
924 | { | |
925 | return FALSE; | |
926 | } | |
927 | ||
928 | } |