2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 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 # include "splintMacros.nf"
28 void stateInfo_free (/*@only@*/ stateInfo a)
32 fileloc_free (a->loc);
37 /*@only@*/ stateInfo stateInfo_update (/*@only@*/ stateInfo old, stateInfo newinfo)
39 ** returns an stateInfo with the same value as new. May reuse the
40 ** storage of old. (i.e., same effect as copy, but more
46 return stateInfo_copy (newinfo);
48 else if (newinfo == NULL)
55 stateInfo snew = stateInfo_makeRefLoc (newinfo->ref, newinfo->loc);
56 llassert (snew->previous == NULL);
62 /*@only@*/ stateInfo stateInfo_updateLoc (/*@only@*/ stateInfo old, fileloc loc)
66 old = stateInfo_makeLoc (loc);
70 old->loc = fileloc_update (old->loc, loc);
71 old->ref = sRef_undefined;
78 stateInfo_updateRefLoc (/*@only@*/ stateInfo old, /*@exposed@*/ sRef ref, fileloc loc)
82 old = stateInfo_makeRefLoc (ref, loc);
86 old->loc = fileloc_update (old->loc, loc);
93 /*@only@*/ stateInfo stateInfo_copy (stateInfo a)
101 stateInfo ret = (stateInfo) dmalloc (sizeof (*ret));
103 ret->loc = fileloc_copy (a->loc); /*< should report bug without copy! >*/
105 ret->previous = stateInfo_copy (a->previous);
111 /*@only@*/ /*@notnull@*/ stateInfo
112 stateInfo_currentLoc (void)
114 return stateInfo_makeLoc (g_currentloc);
117 /*@only@*/ /*@notnull@*/ stateInfo
118 stateInfo_makeLoc (fileloc loc)
120 stateInfo ret = (stateInfo) dmalloc (sizeof (*ret));
122 ret->loc = fileloc_copy (loc); /* don't need to copy! */
123 ret->ref = sRef_undefined;
124 ret->previous = stateInfo_undefined;
129 /*@only@*/ /*@notnull@*/ stateInfo
130 stateInfo_makeRefLoc (/*@exposed@*/ sRef ref, fileloc loc)
131 /*@post:isnull result->previous@*/
133 stateInfo ret = (stateInfo) dmalloc (sizeof (*ret));
135 ret->loc = fileloc_copy (loc);
137 ret->previous = stateInfo_undefined;
143 stateInfo_unparse (stateInfo s)
145 if (stateInfo_isDefined (s) && fileloc_isDefined (s->loc))
147 if (stateInfo_isDefined (s->previous)) {
148 return message ("%q; %q", fileloc_unparse (s->loc), stateInfo_unparse (s->previous));
150 return fileloc_unparse (s->loc);
155 return cstring_makeLiteral ("<no info>");
159 fileloc stateInfo_getLoc (stateInfo info)
161 if (stateInfo_isDefined (info))
166 return fileloc_undefined;
169 void stateInfo_display (stateInfo s, cstring sname)
171 while (stateInfo_isDefined (s))
173 cstring msg = message ("Storage %s ", sname);
175 if (sRef_isValid (s->ref)) {
176 msg = message ("%q through alias %q ", msg, sRef_unparse (s->ref));
179 msg = message ("%qreleased", msg); /* For now, just used for release...need to make this work. */
180 llgenindentmsg (msg, s->loc);
184 cstring_free (sname);