2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 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 lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
25 ** filelocStack.c (from slist_template.c)
28 # include "lclintMacros.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]);
129 s->nelements = i + 1;
134 filelocStack_push (s, el);
139 filelocStack_unparse (filelocStack s)
142 cstring st = cstring_makeLiteral ("[");
144 if (filelocStack_isDefined (s))
146 for (i = s->nelements - 1; i >= 0; i--)
148 if (i == s->nelements - 1)
150 st = message ("%q %q", st, fileloc_unparse (s->elements[i]));
154 st = message ("%q, %q", st, fileloc_unparse (s->elements[i]));
159 st = message ("%q ]", st);
163 int filelocStack_includeDepth (filelocStack s)
168 if (filelocStack_isDefined (s))
170 /* the zeroth element doesn't count! */
171 for (i = s->nelements - 1; i > 0; i--)
173 if (!fileloc_isSpecialFile (s->elements[i]))
184 filelocStack_printIncludes (filelocStack s)
186 if (filelocStack_isDefined (s))
189 bool prep = context_isPreprocessing ();
193 /* need to do this for messages */
194 context_clearPreprocessing ();
197 /* don't show last two files pushed */
198 for (i = s->nelements - 3; i >= 0; i--)
200 if (i == 0 || !fileloc_isSpecialFile (s->elements[i]))
202 llgenindentmsg (cstring_makeLiteral ("Include site"),
209 context_setPreprocessing ();
215 filelocStack_free (/*@only@*/ filelocStack s)
217 if (filelocStack_isDefined (s))
220 for (i = 0; i < s->nelements; i++)
222 fileloc_free (s->elements[i]);