]> andersk Git - splint.git/blame - src/stateValue.c
*** empty log message ***
[splint.git] / src / stateValue.c
CommitLineData
28bf4b0b 1/*
2** LCLint - annotation-assisted static program checker
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
22** For more information: http://lclint.cs.virginia.edu
23*/
24/*
25** stateValue.c
26*/
27
28# include "lclintMacros.nf"
29# include "llbasic.h"
30
31extern
32stateValue stateValue_create (int value, stateInfo info) {
33 stateValue sv = (stateValue) dmalloc (sizeof (*sv));
34
35 sv->value = value;
36 sv->info = info;
37
38 return sv;
39}
40
41stateValue stateValue_copy (stateValue s) {
42 stateValue res;
43 llassert (stateValue_isDefined (s));
44 res = stateValue_create (s->value, stateInfo_copy (s->info));
45 return res;
46}
47
48bool stateValue_sameValue (stateValue s1, stateValue s2)
49{
50 if (stateValue_isDefined (s1) && stateValue_isDefined (s2))
51 {
52 return s1->value == s2->value;
53 }
54 else
55 {
56 return !stateValue_isDefined (s1) && !stateValue_isDefined (s2);
57 }
58}
59
60extern
61cstring stateValue_unparse (stateValue s) {
62 if (stateValue_isDefined (s))
63 {
64 return (message ("%d:%q", s->value, stateInfo_unparse (s->info)));
65 }
66 else
67 {
68 return (cstring_makeLiteral ("<stateValue_undefined>"));
69 }
70}
71
72void stateValue_updateValue (stateValue s, int value, stateInfo info)
73{
74 llassert (stateValue_isDefined (s));
75 s->value = value;
76
77 if (stateInfo_isDefined (info)) {
78 stateInfo_free (s->info);
79 s->info = info;
80 }
81
82 DPRINTF (("update state value: %s", stateValue_unparse (s)));
83}
84
85void stateValue_updateValueLoc (stateValue s, int value, fileloc loc)
86{
87 llassert (stateValue_isDefined (s));
88
89 DPRINTF (("Update state: %s -> %d at %s", stateValue_unparse (s), value,
90 fileloc_unparse (loc)));
91
92 s->value = value;
93
94 if (fileloc_isDefined (loc)) {
95 s->info = stateInfo_updateLoc (s->info, loc);
96 }
97}
98
99void stateValue_update (stateValue res, stateValue val)
100{
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)));
105}
106
107void stateValue_show (stateValue s, metaStateInfo msinfo)
108{
109 if (stateValue_isDefined (s))
110 {
111 stateInfo info = stateValue_getInfo (s);
112
113 if (stateInfo_isDefined (info))
114 {
115 if (fileloc_isDefined (info->loc))
116 {
117 llgenindentmsg (message
118 ("State becomes %s",
119 metaStateInfo_unparseValue (msinfo,
120 stateValue_getValue (s))),
121 info->loc);
122 }
123 }
124 }
125}
126
127/*@observer@*/ cstring stateValue_unparseValue (stateValue s, metaStateInfo msinfo)
128{
129 return metaStateInfo_unparseValue (msinfo,
130 stateValue_getValue (s));
131}
132
133int stateValue_getValue (stateValue s)
134{
135 llassert (stateValue_isDefined (s));
136 return s->value;
137}
138
139stateInfo stateValue_getInfo (stateValue s)
140{
141 llassert (stateValue_isDefined (s));
142 return s->info;
143}
144
145bool stateValue_hasLoc (stateValue s)
146{
147 return (fileloc_isDefined (stateValue_getLoc (s)));
148}
This page took 0.062619 seconds and 5 git commands to generate.