2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 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
28 # include "lclintMacros.nf"
32 stateValue stateValue_create (int value, stateInfo info) {
33 stateValue sv = (stateValue) dmalloc (sizeof (*sv));
41 stateValue stateValue_copy (stateValue s) {
43 llassert (stateValue_isDefined (s));
44 res = stateValue_create (s->value, stateInfo_copy (s->info));
48 bool stateValue_sameValue (stateValue s1, stateValue s2)
50 if (stateValue_isDefined (s1) && stateValue_isDefined (s2))
52 return s1->value == s2->value;
56 return !stateValue_isDefined (s1) && !stateValue_isDefined (s2);
61 cstring stateValue_unparse (stateValue s) {
62 if (stateValue_isDefined (s))
64 return (message ("%d:%q", s->value, stateInfo_unparse (s->info)));
68 return (cstring_makeLiteral ("<stateValue_undefined>"));
72 void stateValue_updateValue (stateValue s, int value, stateInfo info)
74 llassert (stateValue_isDefined (s));
77 if (stateInfo_isDefined (info)) {
78 stateInfo_free (s->info);
82 DPRINTF (("update state value: %s", stateValue_unparse (s)));
85 void stateValue_updateValueLoc (stateValue s, int value, fileloc loc)
87 llassert (stateValue_isDefined (s));
89 DPRINTF (("Update state: %s -> %d at %s", stateValue_unparse (s), value,
90 fileloc_unparse (loc)));
94 if (fileloc_isDefined (loc)) {
95 s->info = stateInfo_updateLoc (s->info, loc);
99 void stateValue_update (stateValue res, stateValue val)
101 llassert (stateValue_isDefined (res));
102 res->value = val->value;
103 res->info = stateInfo_update (res->info, val->info);
104 DPRINTF (("update state: %s", stateValue_unparse (res)));
107 void stateValue_show (stateValue s, metaStateInfo msinfo)
109 if (stateValue_isDefined (s))
111 stateInfo info = stateValue_getInfo (s);
113 if (stateInfo_isDefined (info))
115 if (fileloc_isDefined (info->loc))
117 llgenindentmsg (message
119 metaStateInfo_unparseValue (msinfo,
120 stateValue_getValue (s))),
127 /*@observer@*/ cstring stateValue_unparseValue (stateValue s, metaStateInfo msinfo)
129 return metaStateInfo_unparseValue (msinfo,
130 stateValue_getValue (s));
133 int stateValue_getValue (stateValue s)
135 llassert (stateValue_isDefined (s));
139 stateInfo stateValue_getInfo (stateValue s)
141 llassert (stateValue_isDefined (s));
145 bool stateValue_hasLoc (stateValue s)
147 return (fileloc_isDefined (stateValue_getLoc (s)));