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++)
64 s->elements[i] = oldelements[i];
71 filelocStack_push (/*@returned@*/ filelocStack s, /*@keep@*/ fileloc el)
74 llassert (filelocStack_isDefined (s));
78 filelocStack_grow (s);
83 s->elements[s->nelements] = el;
87 fileloc filelocStack_nextTop (filelocStack s)
89 llassert (filelocStack_isDefined (s) && s->nelements > 1);
91 return (s->elements[s->nelements - 2]);
94 void filelocStack_clear (filelocStack s)
96 if (filelocStack_isDefined (s))
100 for (i = 0; i < s->nelements; i++)
103 fileloc_free (s->elements[i]);
106 s->free += s->nelements;
112 ** Returns TRUE of el is a new file.
115 bool filelocStack_popPushFile (filelocStack s, fileloc el)
119 llassert (filelocStack_isDefined (s));
121 for (i = s->nelements - 1; i >= 0; i--)
124 if (fileloc_sameBaseFile (s->elements[i], el))
128 for (j = i; j < s->nelements; j++)
131 fileloc_free (s->elements[j]);
135 s->nelements = i + 1;
140 filelocStack_push (s, el);
145 filelocStack_unparse (filelocStack s)
148 cstring st = cstring_makeLiteral ("[");
150 if (filelocStack_isDefined (s))
152 for (i = s->nelements - 1; i >= 0; i--)
154 if (i == s->nelements - 1)
157 st = message ("%q %q", st, fileloc_unparse (s->elements[i]));
162 st = message ("%q, %q", st, fileloc_unparse (s->elements[i]));
167 st = message ("%q ]", st);
171 int filelocStack_includeDepth (filelocStack s)
176 if (filelocStack_isDefined (s))
178 /* the zeroth element doesn't count! */
179 for (i = s->nelements - 1; i > 0; i--)
182 if (!fileloc_isSpecialFile (s->elements[i]))
193 filelocStack_printIncludes (filelocStack s)
195 if (filelocStack_isDefined (s))
198 bool prep = context_isPreprocessing ();
202 /* need to do this for messages */
203 context_clearPreprocessing ();
206 /* don't show last two files pushed */
207 for (i = s->nelements - 3; i >= 0; i--)
210 if (i == 0 || !fileloc_isSpecialFile (s->elements[i]))
213 llgenindentmsg (cstring_makeLiteral ("Include site"),
220 context_setPreprocessing ();
226 filelocStack_free (/*@only@*/ filelocStack s)
228 if (filelocStack_isDefined (s))
231 for (i = 0; i < s->nelements; i++)
234 fileloc_free (s->elements[i]);