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 /*@constant int filelocStackBASESIZE;@*/
33 # define filelocStackBASESIZE MIDBASESIZE
35 static /*@notnull@*/ /*@only@*/ filelocStack
36 filelocStack_newEmpty (void)
38 filelocStack s
= (filelocStack
) dmalloc (sizeof (*s
));
41 s
->free
= filelocStackBASESIZE
;
42 s
->elements
= (fileloc
*) dmalloc (sizeof (*s
->elements
) * filelocStackBASESIZE
);
48 filelocStack_new (void)
50 return (filelocStack_newEmpty ());
54 filelocStack_grow (/*@notnull@*/ filelocStack s
)
56 o_fileloc
*oldelements
= s
->elements
;
59 s
->free
+= filelocStackBASESIZE
;
60 s
->elements
= (fileloc
*) dmalloc (sizeof (*s
->elements
)
61 * (s
->nelements
+ s
->free
));
63 for (i
= 0; i
< s
->nelements
; i
++)
65 s
->elements
[i
] = oldelements
[i
];
72 filelocStack_push (/*@returned@*/ filelocStack s
, /*@keep@*/ fileloc el
)
75 llassert (filelocStack_isDefined (s
));
79 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
++)
102 fileloc_free (s
->elements
[i
]);
105 s
->free
+= s
->nelements
;
111 ** Returns TRUE of el is a new file.
114 bool filelocStack_popPushFile (filelocStack s
, fileloc el
)
118 llassert (filelocStack_isDefined (s
));
120 for (i
= s
->nelements
- 1; i
>= 0; i
--)
122 if (fileloc_sameBaseFile (s
->elements
[i
], el
))
126 for (j
= i
; j
< s
->nelements
; j
++)
128 fileloc_free (s
->elements
[j
]);
131 s
->nelements
= i
+ 1;
136 filelocStack_push (s
, el
);
142 filelocStack_unparse (filelocStack s
)
145 cstring st
= cstring_makeLiteral ("[");
147 if (filelocStack_isDefined (s
))
149 for (i
= s
->nelements
- 1; i
>= 0; i
--)
151 if (i
== s
->nelements
- 1)
153 st
= message ("%q %q", st
, fileloc_unparse (s
->elements
[i
]));
157 st
= message ("%q, %q", st
, fileloc_unparse (s
->elements
[i
]));
162 st
= message ("%q ]", st
);
165 # endif /* DEADCODE */
167 int filelocStack_includeDepth (filelocStack s
)
172 if (filelocStack_isDefined (s
))
174 /* the zeroth element doesn't count! */
175 for (i
= s
->nelements
- 1; i
> 0; i
--)
177 if (!fileloc_isSpecialFile (s
->elements
[i
]))
188 filelocStack_printIncludes (filelocStack s
)
190 if (filelocStack_isDefined (s
))
193 bool prep
= context_isPreprocessing ();
197 /* need to do this for messages */
198 context_clearPreprocessing ();
201 /* don't show last two files pushed */
202 for (i
= s
->nelements
- 3; i
>= 0; i
--)
204 if (i
== 0 || !fileloc_isSpecialFile (s
->elements
[i
]))
206 llgenindentmsg (cstring_makeLiteral ("Include site"),
213 context_setPreprocessing ();
219 filelocStack_free (/*@only@*/ filelocStack s
)
221 if (filelocStack_isDefined (s
))
224 for (i
= 0; i
< s
->nelements
; i
++)
226 fileloc_free (s
->elements
[i
]);