2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
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.
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.
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.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
25 ** filelocList.c (from slist_template.c)
28 # include "splintMacros.nf"
30 # include "filelocList.h"
33 ** Invariant: If any member of the list is fileloc_undefined, then
34 ** the 0th member is fileloc_undefined.
40 return (filelocList_undefined);
43 static /*@notnull@*/ /*@only@*/ filelocList
44 filelocList_newEmpty (void)
46 filelocList s = (filelocList) dmalloc (sizeof (*s));
49 s->free = filelocListBASESIZE;
50 s->elements = (fileloc *) dmalloc (sizeof (*s->elements) * filelocListBASESIZE);
56 filelocList_grow (/*@notnull@*/ filelocList s)
59 o_fileloc *oldelements = s->elements;
61 s->free += filelocListBASESIZE;
62 s->elements = (fileloc *) dmalloc (sizeof (*s->elements)
63 * (s->nelements + s->free));
65 for (i = 0; i < s->nelements; i++)
67 s->elements[i] = oldelements[i];
74 filelocList_append (/*@returned@*/ filelocList s, /*@only@*/ filelocList t)
76 llassert (NOALIAS (s, t));
78 if (filelocList_isUndefined (t) || filelocList_isEmpty (t)) return s;
80 if (filelocList_isUndefined (s))
82 s = filelocList_newEmpty ();
85 filelocList_elements (t, fl)
87 /* Okay to use exposed storage here, t is begin eaten. */
89 /*@-exposetrans@*/ /*@-dependenttrans@*/
90 s = filelocList_add (s, fl);
91 /*@=exposetrans@*/ /*@=dependenttrans@*/
92 } end_filelocList_elements;
101 filelocList_addUndefined (/*@returned@*/ filelocList s)
103 if (filelocList_isUndefined (s)
105 || fileloc_isDefined (s->elements[0]))
107 return (filelocList_add (s, fileloc_undefined));
115 static bool filelocList_hasUndefinedLoc (filelocList s)
117 return (filelocList_isDefined (s)
119 && fileloc_isUndefined (s->elements[0]));
123 filelocList_addDifferentFile (/*@returned@*/ filelocList s,
127 if (filelocList_hasUndefinedLoc (s) || filelocList_size (s) >= 2)
133 if (fileloc_sameModule (where, loc))
135 if (filelocList_isEmpty (s))
137 return filelocList_add (s, fileloc_copy (loc));
146 return filelocList_addUndefined (s);
152 filelocList_add (/*@returned@*/ filelocList s, /*@only@*/ fileloc el)
154 if (filelocList_isUndefined (s))
156 s = filelocList_newEmpty ();
161 filelocList_grow (s);
165 s->elements[s->nelements] = el;
167 if (fileloc_isUndefined (el))
169 s->elements[s->nelements] = s->elements[0];
170 s->elements[0] = fileloc_undefined;
178 filelocList_unparse (filelocList s)
181 cstring st = cstring_makeLiteral ("[");
183 if (filelocList_isDefined (s))
185 for (i = 0; i < filelocList_size (s); i++)
189 st = message ("%q %q", st, fileloc_unparse (s->elements[i]));
192 st = message ("%q, %q", st, fileloc_unparse (s->elements[i]));
196 st = message ("%q ]", st);
200 int filelocList_realSize (filelocList s)
204 filelocList_elements (s, el)
206 if (fileloc_isDefined (el))
210 } end_filelocList_elements;
215 cstring filelocList_unparseUses (filelocList s)
219 int maxlen = context_getLineLen () - 3;
220 cstring st = cstring_undefined;
221 fileId lastFile = fileId_invalid;
222 bool parenFormat = context_getFlag (FLG_PARENFILEFORMAT);
224 if (filelocList_isDefined (s))
226 bool firstone = TRUE;
228 for (i = 0; i < filelocList_size (s); i++)
230 if (fileloc_isDefined (s->elements[i]))
234 st = fileloc_unparse (s->elements[i]);
235 lastFile = fileloc_fileId (s->elements[i]);
236 linelen = 3 + cstring_length (st);
241 if (fileId_equal (fileloc_fileId (s->elements[i]), lastFile))
243 if (linelen + 7 > size_fromInt (maxlen))
245 st = message ("%q\n ", st);
250 st = message ("%q, ", st);
255 st = message ("%q(%d,%d)",
256 st, fileloc_lineno (s->elements[i]),
257 fileloc_column (s->elements[i]));
261 st = message ("%q%d:%d",
262 st, fileloc_lineno (s->elements[i]),
263 fileloc_column (s->elements[i]));
266 linelen += 3 + int_log (fileloc_lineno (s->elements[i]))
267 + int_log (fileloc_column (s->elements[i]));
271 cstring fl = fileloc_unparse (s->elements[i]);
272 st = message ("%q\n %s", st, fl);
273 lastFile = fileloc_fileId (s->elements[i]);
274 linelen = 3 + cstring_length (fl);
286 filelocList_free (/*@only@*/ filelocList s)
288 if (filelocList_isDefined (s))
291 for (i = 0; i < s->nelements; i++)
293 fileloc_free (s->elements[i]);