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"
31 /*@constant int filelocListBASESIZE;@*/
32 # define filelocListBASESIZE MIDBASESIZE
35 ** Invariant: If any member of the list is fileloc_undefined, then
36 ** the 0th member is fileloc_undefined.
40 filelocList_new (void)
42 return (filelocList_undefined
);
45 static /*@notnull@*/ /*@only@*/ filelocList
46 filelocList_newEmpty (void)
48 filelocList s
= (filelocList
) dmalloc (sizeof (*s
));
51 s
->free
= filelocListBASESIZE
;
52 s
->elements
= (fileloc
*) dmalloc (sizeof (*s
->elements
) * filelocListBASESIZE
);
58 filelocList_grow (/*@notnull@*/ filelocList s
)
61 o_fileloc
*oldelements
= s
->elements
;
63 s
->free
+= filelocListBASESIZE
;
64 s
->elements
= (fileloc
*) dmalloc (sizeof (*s
->elements
)
65 * (s
->nelements
+ s
->free
));
67 for (i
= 0; i
< s
->nelements
; i
++)
69 s
->elements
[i
] = oldelements
[i
];
76 filelocList_append (/*@returned@*/ filelocList s
, /*@only@*/ filelocList t
)
78 llassert (NOALIAS (s
, t
));
80 if (filelocList_isUndefined (t
) || filelocList_isEmpty (t
)) return s
;
82 if (filelocList_isUndefined (s
))
84 s
= filelocList_newEmpty ();
87 filelocList_elements (t
, fl
)
89 /* Okay to use exposed storage here, t is begin eaten. */
91 /*@-exposetrans@*/ /*@-dependenttrans@*/
92 s
= filelocList_add (s
, fl
);
93 /*@=exposetrans@*/ /*@=dependenttrans@*/
94 } end_filelocList_elements
;
103 filelocList_addUndefined (/*@returned@*/ filelocList s
)
105 if (filelocList_isUndefined (s
)
107 || fileloc_isDefined (s
->elements
[0]))
109 return (filelocList_add (s
, fileloc_undefined
));
117 static bool filelocList_hasUndefinedLoc (filelocList s
)
119 return (filelocList_isDefined (s
)
121 && fileloc_isUndefined (s
->elements
[0]));
125 filelocList_addDifferentFile (/*@returned@*/ filelocList s
,
129 if (filelocList_hasUndefinedLoc (s
) || filelocList_size (s
) >= 2)
135 if (fileloc_sameModule (where
, loc
))
137 if (filelocList_isEmpty (s
))
139 return filelocList_add (s
, fileloc_copy (loc
));
148 return filelocList_addUndefined (s
);
154 filelocList_add (/*@returned@*/ filelocList s
, /*@only@*/ fileloc el
)
156 if (filelocList_isUndefined (s
))
158 s
= filelocList_newEmpty ();
163 filelocList_grow (s
);
167 s
->elements
[s
->nelements
] = el
;
169 if (fileloc_isUndefined (el
))
171 s
->elements
[s
->nelements
] = s
->elements
[0];
172 s
->elements
[0] = fileloc_undefined
;
181 filelocList_unparse (filelocList s
)
184 cstring st
= cstring_makeLiteral ("[");
186 if (filelocList_isDefined (s
))
188 for (i
= 0; i
< filelocList_size (s
); i
++)
192 st
= message ("%q %q", st
, fileloc_unparse (s
->elements
[i
]));
195 st
= message ("%q, %q", st
, fileloc_unparse (s
->elements
[i
]));
199 st
= message ("%q ]", st
);
202 # endif /* DEADCODE */
204 int filelocList_realSize (filelocList s
)
208 filelocList_elements (s
, el
)
210 if (fileloc_isDefined (el
))
214 } end_filelocList_elements
;
219 cstring
filelocList_unparseUses (filelocList s
)
223 int maxlen
= context_getLineLen () - 3;
224 cstring st
= cstring_undefined
;
225 fileId lastFile
= fileId_invalid
;
226 bool parenFormat
= context_getFlag (FLG_PARENFILEFORMAT
);
228 if (filelocList_isDefined (s
))
230 bool firstone
= TRUE
;
232 for (i
= 0; i
< filelocList_size (s
); i
++)
234 if (fileloc_isDefined (s
->elements
[i
]))
238 st
= fileloc_unparse (s
->elements
[i
]);
239 lastFile
= fileloc_fileId (s
->elements
[i
]);
240 linelen
= 3 + cstring_length (st
);
245 if (fileId_equal (fileloc_fileId (s
->elements
[i
]), lastFile
))
247 if (linelen
+ 7 > size_fromInt (maxlen
))
249 st
= message ("%q\n ", st
);
254 st
= message ("%q, ", st
);
259 st
= message ("%q(%d,%d)",
260 st
, fileloc_lineno (s
->elements
[i
]),
261 fileloc_column (s
->elements
[i
]));
265 st
= message ("%q%d:%d",
266 st
, fileloc_lineno (s
->elements
[i
]),
267 fileloc_column (s
->elements
[i
]));
270 linelen
+= 3 + int_log (fileloc_lineno (s
->elements
[i
]))
271 + int_log (fileloc_column (s
->elements
[i
]));
275 cstring fl
= fileloc_unparse (s
->elements
[i
]);
276 st
= message ("%q\n %s", st
, fl
);
277 lastFile
= fileloc_fileId (s
->elements
[i
]);
278 linelen
= 3 + cstring_length (fl
);
290 filelocList_free (/*@only@*/ filelocList s
)
292 if (filelocList_isDefined (s
))
295 for (i
= 0; i
< s
->nelements
; i
++)
297 fileloc_free (s
->elements
[i
]);