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 ** filelocStack.c (from slist_template.c)
28 # include "splintMacros.nf"
30 # include "filelocStack.h"
32 static /*@notnull@*/ /*@only@*/ filelocStack
33 filelocStack_newEmpty (void)
35 filelocStack s = (filelocStack) dmalloc (sizeof (*s));
38 s->free = filelocStackBASESIZE;
39 s->elements = (fileloc *) dmalloc (sizeof (*s->elements) * filelocStackBASESIZE);
47 return (filelocStack_newEmpty ());
51 filelocStack_grow (/*@notnull@*/ filelocStack s)
53 o_fileloc *oldelements = s->elements;
56 s->free += filelocStackBASESIZE;
57 s->elements = (fileloc *) dmalloc (sizeof (*s->elements)
58 * (s->nelements + s->free));
60 for (i = 0; i < s->nelements; i++)
62 s->elements[i] = oldelements[i];
69 filelocStack_push (/*@returned@*/ filelocStack s, /*@keep@*/ fileloc el)
72 llassert (filelocStack_isDefined (s));
76 filelocStack_grow (s);
80 s->elements[s->nelements] = el;
84 fileloc filelocStack_nextTop (filelocStack s)
86 llassert (filelocStack_isDefined (s) && s->nelements > 1);
88 return (s->elements[s->nelements - 2]);
91 void filelocStack_clear (filelocStack s)
93 if (filelocStack_isDefined (s))
97 for (i = 0; i < s->nelements; i++)
99 fileloc_free (s->elements[i]);
102 s->free += s->nelements;
108 ** Returns TRUE of el is a new file.
111 bool filelocStack_popPushFile (filelocStack s, fileloc el)
115 llassert (filelocStack_isDefined (s));
117 for (i = s->nelements - 1; i >= 0; i--)
119 if (fileloc_sameBaseFile (s->elements[i], el))
123 for (j = i; j < s->nelements; j++)
125 fileloc_free (s->elements[j]);
128 s->nelements = i + 1;
133 filelocStack_push (s, el);
138 filelocStack_unparse (filelocStack s)
141 cstring st = cstring_makeLiteral ("[");
143 if (filelocStack_isDefined (s))
145 for (i = s->nelements - 1; i >= 0; i--)
147 if (i == s->nelements - 1)
149 st = message ("%q %q", st, fileloc_unparse (s->elements[i]));
153 st = message ("%q, %q", st, fileloc_unparse (s->elements[i]));
158 st = message ("%q ]", st);
162 int filelocStack_includeDepth (filelocStack s)
167 if (filelocStack_isDefined (s))
169 /* the zeroth element doesn't count! */
170 for (i = s->nelements - 1; i > 0; i--)
172 if (!fileloc_isSpecialFile (s->elements[i]))
183 filelocStack_printIncludes (filelocStack s)
185 if (filelocStack_isDefined (s))
188 bool prep = context_isPreprocessing ();
192 /* need to do this for messages */
193 context_clearPreprocessing ();
196 /* don't show last two files pushed */
197 for (i = s->nelements - 3; i >= 0; i--)
199 if (i == 0 || !fileloc_isSpecialFile (s->elements[i]))
201 llgenindentmsg (cstring_makeLiteral ("Include site"),
208 context_setPreprocessing ();
214 filelocStack_free (/*@only@*/ filelocStack s)
216 if (filelocStack_isDefined (s))
219 for (i = 0; i < s->nelements; i++)
221 fileloc_free (s->elements[i]);