]>
Commit | Line | Data |
---|---|---|
28bf4b0b | 1 | /* |
11db3170 | 2 | ** Splint - annotation-assisted static program checker |
28bf4b0b | 3 | ** Copyright (C) 1994-2001 University of Virginia, |
4 | ** Massachusetts Institute of Technology | |
5 | ** | |
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. | |
10 | ** | |
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. | |
15 | ** | |
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. | |
19 | ** | |
20 | ** For information on lclint: lclint-request@cs.virginia.edu | |
21 | ** To report a bug: lclint-bug@cs.virginia.edu | |
11db3170 | 22 | ** For more information: http://www.splint.org |
28bf4b0b | 23 | */ |
24 | /* | |
25 | ** stateValue.c | |
26 | */ | |
27 | ||
28 | # include "lclintMacros.nf" | |
29 | # include "llbasic.h" | |
30 | ||
31 | extern | |
2c88d156 | 32 | /*@notnull@*/ stateValue stateValue_create (int value, stateInfo info) { |
28bf4b0b | 33 | stateValue sv = (stateValue) dmalloc (sizeof (*sv)); |
34 | ||
35 | sv->value = value; | |
36 | sv->info = info; | |
2c88d156 | 37 | sv->implicit = FALSE; |
38 | return sv; | |
39 | } | |
40 | ||
41 | extern | |
42 | /*@notnull@*/ stateValue stateValue_createImplicit (int value, stateInfo info) { | |
43 | stateValue sv = (stateValue) dmalloc (sizeof (*sv)); | |
28bf4b0b | 44 | |
2c88d156 | 45 | sv->value = value; |
46 | sv->info = info; | |
47 | sv->implicit = TRUE; | |
28bf4b0b | 48 | return sv; |
49 | } | |
50 | ||
51 | stateValue stateValue_copy (stateValue s) { | |
52 | stateValue res; | |
53 | llassert (stateValue_isDefined (s)); | |
54 | res = stateValue_create (s->value, stateInfo_copy (s->info)); | |
2c88d156 | 55 | res->implicit = s->implicit; |
28bf4b0b | 56 | return res; |
57 | } | |
58 | ||
59 | bool stateValue_sameValue (stateValue s1, stateValue s2) | |
60 | { | |
61 | if (stateValue_isDefined (s1) && stateValue_isDefined (s2)) | |
62 | { | |
63 | return s1->value == s2->value; | |
64 | } | |
65 | else | |
66 | { | |
67 | return !stateValue_isDefined (s1) && !stateValue_isDefined (s2); | |
68 | } | |
69 | } | |
70 | ||
71 | extern | |
72 | cstring stateValue_unparse (stateValue s) { | |
73 | if (stateValue_isDefined (s)) | |
74 | { | |
75 | return (message ("%d:%q", s->value, stateInfo_unparse (s->info))); | |
76 | } | |
77 | else | |
78 | { | |
79 | return (cstring_makeLiteral ("<stateValue_undefined>")); | |
80 | } | |
81 | } | |
82 | ||
83 | void stateValue_updateValue (stateValue s, int value, stateInfo info) | |
84 | { | |
85 | llassert (stateValue_isDefined (s)); | |
86 | s->value = value; | |
87 | ||
88 | if (stateInfo_isDefined (info)) { | |
89 | stateInfo_free (s->info); | |
90 | s->info = info; | |
91 | } | |
92 | ||
93 | DPRINTF (("update state value: %s", stateValue_unparse (s))); | |
94 | } | |
95 | ||
96 | void stateValue_updateValueLoc (stateValue s, int value, fileloc loc) | |
97 | { | |
98 | llassert (stateValue_isDefined (s)); | |
99 | ||
100 | DPRINTF (("Update state: %s -> %d at %s", stateValue_unparse (s), value, | |
101 | fileloc_unparse (loc))); | |
102 | ||
103 | s->value = value; | |
104 | ||
105 | if (fileloc_isDefined (loc)) { | |
106 | s->info = stateInfo_updateLoc (s->info, loc); | |
107 | } | |
108 | } | |
109 | ||
110 | void stateValue_update (stateValue res, stateValue val) | |
111 | { | |
112 | llassert (stateValue_isDefined (res)); | |
113 | res->value = val->value; | |
114 | res->info = stateInfo_update (res->info, val->info); | |
115 | DPRINTF (("update state: %s", stateValue_unparse (res))); | |
116 | } | |
117 | ||
118 | void stateValue_show (stateValue s, metaStateInfo msinfo) | |
119 | { | |
120 | if (stateValue_isDefined (s)) | |
121 | { | |
122 | stateInfo info = stateValue_getInfo (s); | |
123 | ||
124 | if (stateInfo_isDefined (info)) | |
125 | { | |
126 | if (fileloc_isDefined (info->loc)) | |
127 | { | |
128 | llgenindentmsg (message | |
2c88d156 | 129 | ("State becomes %q", |
130 | stateValue_unparseValue (s, msinfo)), | |
28bf4b0b | 131 | info->loc); |
132 | } | |
133 | } | |
134 | } | |
135 | } | |
136 | ||
2c88d156 | 137 | /*@only@*/ cstring stateValue_unparseValue (stateValue s, metaStateInfo msinfo) |
28bf4b0b | 138 | { |
2c88d156 | 139 | if (stateValue_isImplicit (s)) |
140 | { | |
141 | return message ("implicitly %s", | |
142 | metaStateInfo_unparseValue (msinfo, | |
143 | stateValue_getValue (s))); | |
144 | } | |
145 | else | |
146 | { | |
147 | return cstring_copy (metaStateInfo_unparseValue (msinfo, | |
148 | stateValue_getValue (s))); | |
149 | } | |
28bf4b0b | 150 | } |
151 | ||
152 | int stateValue_getValue (stateValue s) | |
153 | { | |
ccf0a4a8 | 154 | if (!stateValue_isDefined (s)) |
155 | { | |
156 | llassert (stateValue_isDefined (s)); | |
157 | return stateValue_error; | |
158 | } | |
159 | ||
28bf4b0b | 160 | return s->value; |
161 | } | |
162 | ||
2c88d156 | 163 | bool stateValue_isImplicit (stateValue s) |
164 | { | |
165 | llassert (stateValue_isDefined (s)); | |
166 | return s->implicit; | |
167 | } | |
168 | ||
28bf4b0b | 169 | stateInfo stateValue_getInfo (stateValue s) |
170 | { | |
171 | llassert (stateValue_isDefined (s)); | |
172 | return s->info; | |
173 | } | |
174 | ||
175 | bool stateValue_hasLoc (stateValue s) | |
176 | { | |
177 | return (fileloc_isDefined (stateValue_getLoc (s))); | |
178 | } |