]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | ** Splint - annotation-assisted static program checker | |
3 | ** Copyright (C) 1994-2002 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 splint: info@splint.org | |
21 | ** To report a bug: splint-bug@splint.org | |
22 | ** For more information: http://www.splint.org | |
23 | */ | |
24 | ||
25 | # include "splintMacros.nf" | |
26 | # include "basic.h" | |
27 | ||
28 | void stateInfo_free (/*@only@*/ stateInfo a) | |
29 | { | |
30 | if (a != NULL) | |
31 | { | |
32 | fileloc_free (a->loc); | |
33 | sfree (a); | |
34 | } | |
35 | } | |
36 | ||
37 | /*@only@*/ stateInfo stateInfo_update (/*@only@*/ stateInfo old, stateInfo newinfo) | |
38 | /* | |
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 | |
41 | ** efficient.) | |
42 | */ | |
43 | { | |
44 | if (old == NULL) | |
45 | { | |
46 | return stateInfo_copy (newinfo); | |
47 | } | |
48 | else if (newinfo == NULL) | |
49 | { | |
50 | stateInfo_free (old); | |
51 | return NULL; | |
52 | } | |
53 | else | |
54 | { | |
55 | stateInfo snew = stateInfo_makeRefLoc (newinfo->ref, newinfo->loc); | |
56 | snew->previous = old; | |
57 | return snew; | |
58 | } | |
59 | } | |
60 | ||
61 | /*@only@*/ stateInfo stateInfo_updateLoc (/*@only@*/ stateInfo old, fileloc loc) | |
62 | { | |
63 | if (old == NULL) | |
64 | { | |
65 | old = stateInfo_makeLoc (loc); | |
66 | } | |
67 | else | |
68 | { | |
69 | old->loc = fileloc_update (old->loc, loc); | |
70 | old->ref = sRef_undefined; | |
71 | } | |
72 | ||
73 | return old; | |
74 | } | |
75 | ||
76 | /*@only@*/ stateInfo | |
77 | stateInfo_updateRefLoc (/*@only@*/ stateInfo old, /*@exposed@*/ sRef ref, fileloc loc) | |
78 | { | |
79 | if (old == NULL) | |
80 | { | |
81 | old = stateInfo_makeRefLoc (ref, loc); | |
82 | } | |
83 | else | |
84 | { | |
85 | old->loc = fileloc_update (old->loc, loc); | |
86 | old->ref = ref; | |
87 | } | |
88 | ||
89 | return old; | |
90 | } | |
91 | ||
92 | /*@only@*/ stateInfo stateInfo_copy (stateInfo a) | |
93 | { | |
94 | if (a == NULL) | |
95 | { | |
96 | return NULL; | |
97 | } | |
98 | else | |
99 | { | |
100 | stateInfo ret = (stateInfo) dmalloc (sizeof (*ret)); | |
101 | ||
102 | ret->loc = fileloc_copy (a->loc); /*< should report bug without copy! >*/ | |
103 | ret->ref = a->ref; | |
104 | ret->previous = stateInfo_copy (a->previous); | |
105 | ||
106 | return ret; | |
107 | } | |
108 | } | |
109 | ||
110 | /*@only@*/ /*@notnull@*/ stateInfo | |
111 | stateInfo_currentLoc (void) | |
112 | { | |
113 | return stateInfo_makeLoc (g_currentloc); | |
114 | } | |
115 | ||
116 | /*@only@*/ /*@notnull@*/ stateInfo | |
117 | stateInfo_makeLoc (fileloc loc) | |
118 | { | |
119 | stateInfo ret = (stateInfo) dmalloc (sizeof (*ret)); | |
120 | ||
121 | ret->loc = fileloc_copy (loc); /* don't need to copy! */ | |
122 | ret->ref = sRef_undefined; | |
123 | ret->previous = stateInfo_undefined; | |
124 | ||
125 | return ret; | |
126 | } | |
127 | ||
128 | /*@only@*/ stateInfo | |
129 | stateInfo_makeRefLoc (/*@exposed@*/ sRef ref, fileloc loc) | |
130 | /*@post:isnull result->previous@*/ | |
131 | { | |
132 | stateInfo ret = (stateInfo) dmalloc (sizeof (*ret)); | |
133 | ||
134 | ret->loc = fileloc_copy (loc); | |
135 | ret->ref = ref; | |
136 | ret->previous = stateInfo_undefined; | |
137 | ||
138 | return ret; | |
139 | } | |
140 | ||
141 | /*@only@*/ cstring | |
142 | stateInfo_unparse (stateInfo s) | |
143 | { | |
144 | if (stateInfo_isDefined (s) && fileloc_isDefined (s->loc)) | |
145 | { | |
146 | if (stateInfo_isDefined (s->previous)) { | |
147 | return message ("%q; %q", fileloc_unparse (s->loc), stateInfo_unparse (s->previous)); | |
148 | } else { | |
149 | return fileloc_unparse (s->loc); | |
150 | } | |
151 | } | |
152 | else | |
153 | { | |
154 | return cstring_makeLiteral ("<no info>"); | |
155 | } | |
156 | } | |
157 | ||
158 | fileloc stateInfo_getLoc (stateInfo info) | |
159 | { | |
160 | if (stateInfo_isDefined (info)) | |
161 | { | |
162 | return info->loc; | |
163 | } | |
164 | ||
165 | return fileloc_undefined; | |
166 | } | |
167 | ||
168 | void stateInfo_display (stateInfo s, cstring sname) | |
169 | { | |
170 | while (stateInfo_isDefined (s)) | |
171 | { | |
172 | cstring msg = message ("Storage %s ", sname); | |
173 | ||
174 | if (sRef_isValid (s->ref)) { | |
175 | msg = message ("%q through alias %q ", msg, sRef_unparse (s->ref)); | |
176 | } | |
177 | ||
178 | msg = message ("%qreleased", msg); /* For now, just used for release...need to make this work. */ | |
179 | llgenindentmsg (msg, s->loc); | |
180 | s = s->previous; | |
181 | } | |
182 | ||
183 | cstring_free (sname); | |
184 | } | |
185 | ||
186 |