]>
Commit | Line | Data |
---|---|---|
28bf4b0b | 1 | /* |
11db3170 | 2 | ** Splint - annotation-assisted static program checker |
c59f5181 | 3 | ** Copyright (C) 1994-2003 University of Virginia, |
28bf4b0b | 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 | ** | |
155af98d | 20 | ** For information on splint: info@splint.org |
21 | ** To report a bug: splint-bug@splint.org | |
11db3170 | 22 | ** For more information: http://www.splint.org |
28bf4b0b | 23 | */ |
24 | /* | |
25 | ** functionClause.c | |
26 | */ | |
27 | ||
1b8ae690 | 28 | # include "splintMacros.nf" |
28bf4b0b | 29 | # include "basic.h" |
30 | ||
b73d1009 | 31 | static /*@only@*/ /*@notnull@*/ /*@special@*/ functionClause |
28bf4b0b | 32 | functionClause_alloc (functionClauseKind kind) /*@defines result->kind@*/ |
33 | { | |
34 | functionClause res = (functionClause) dmalloc (sizeof (*res)); | |
35 | ||
36 | res->kind = kind; | |
37 | return res; | |
38 | } | |
39 | ||
40 | extern functionClause functionClause_createGlobals (globalsClause node) /*@*/ | |
41 | { | |
42 | functionClause res = functionClause_alloc (FCK_GLOBALS); | |
43 | res->val.globals = node; | |
44 | return res; | |
45 | } | |
46 | ||
47 | extern functionClause functionClause_createModifies (modifiesClause node) /*@*/ | |
48 | { | |
49 | functionClause res = functionClause_alloc (FCK_MODIFIES); | |
50 | res->val.modifies = node; | |
51 | return res; | |
52 | } | |
53 | ||
54 | extern functionClause functionClause_createState (stateClause node) /*@*/ | |
a07995d9 | 55 | { |
56 | if (stateClause_hasEmptyReferences (node) && | |
57 | (!stateClause_isMetaState (node) ) ) | |
58 | { | |
59 | DPRINTF((message("functionClause_createState:: Returning functionClause_undefined" ) )); | |
f6099dac | 60 | stateClause_free (node); |
a07995d9 | 61 | return functionClause_undefined; |
62 | } | |
63 | else | |
64 | { | |
65 | functionClause res = functionClause_alloc (FCK_STATE); | |
66 | res->val.state = node; | |
67 | return res; | |
68 | } | |
28bf4b0b | 69 | } |
70 | ||
3814599d | 71 | extern functionClause functionClause_createEnsures (functionConstraint node) /*@*/ |
d9a28762 | 72 | { |
73 | functionClause res = functionClause_alloc (FCK_ENSURES); | |
3814599d | 74 | res->val.constraint = node; |
d9a28762 | 75 | return res; |
76 | } | |
77 | ||
3814599d | 78 | extern functionClause functionClause_createRequires (functionConstraint node) /*@*/ |
d9a28762 | 79 | { |
80 | functionClause res = functionClause_alloc (FCK_REQUIRES); | |
3814599d | 81 | res->val.constraint = node; |
08eb3d0e | 82 | return res; |
83 | } | |
84 | ||
28bf4b0b | 85 | extern functionClause functionClause_createWarn (warnClause node) /*@*/ |
86 | { | |
87 | functionClause res = functionClause_alloc (FCK_WARN); | |
88 | res->val.warn = node; | |
89 | return res; | |
90 | } | |
91 | ||
92 | /*@only@*/ cstring functionClause_unparse (functionClause p) | |
93 | { | |
94 | if (functionClause_isUndefined (p)) | |
95 | { | |
96 | return cstring_undefined; | |
97 | } | |
98 | ||
99 | switch (p->kind) | |
100 | { | |
101 | case FCK_GLOBALS: | |
102 | return globalsClause_unparse (p->val.globals); | |
103 | case FCK_MODIFIES: | |
104 | return modifiesClause_unparse (p->val.modifies); | |
105 | case FCK_WARN: | |
106 | return warnClause_unparse (p->val.warn); | |
107 | case FCK_STATE: | |
108 | return stateClause_unparse (p->val.state); | |
d9a28762 | 109 | case FCK_ENSURES: |
3814599d | 110 | return message ("ensures %q", functionConstraint_unparse (p->val.constraint)); |
d9a28762 | 111 | case FCK_REQUIRES: |
3814599d | 112 | return message ("requires %q", functionConstraint_unparse (p->val.constraint)); |
28bf4b0b | 113 | case FCK_DEAD: |
bb7c2085 | 114 | return cstring_makeLiteral ("<dead clause>"); |
28bf4b0b | 115 | } |
116 | ||
8250fa4a | 117 | BADBRANCHRET (cstring_undefined); |
28bf4b0b | 118 | } |
119 | ||
120 | extern bool functionClause_matchKind (functionClause p, functionClauseKind kind) /*@*/ | |
121 | { | |
122 | if (functionClause_isDefined (p)) | |
123 | { | |
124 | return (p->kind == kind); | |
125 | } | |
126 | else | |
127 | { | |
128 | return FALSE; | |
129 | } | |
130 | } | |
131 | ||
132 | extern stateClause functionClause_getState (functionClause node) | |
133 | { | |
134 | llassert (functionClause_isDefined (node)); | |
135 | llassert (node->kind == FCK_STATE); | |
136 | ||
137 | return node->val.state; | |
138 | } | |
139 | ||
140 | extern stateClause functionClause_takeState (functionClause fc) | |
141 | { | |
142 | stateClause res; | |
143 | llassert (functionClause_isDefined (fc)); | |
144 | llassert (fc->kind == FCK_STATE); | |
145 | ||
146 | res = fc->val.state; | |
147 | fc->val.state = NULL; | |
148 | fc->kind = FCK_DEAD; | |
149 | return res; | |
150 | } | |
151 | ||
3814599d | 152 | extern functionConstraint functionClause_getEnsures (functionClause node) |
d9a28762 | 153 | { |
154 | llassert (functionClause_isDefined (node)); | |
155 | llassert (node->kind == FCK_ENSURES); | |
156 | ||
3814599d | 157 | return node->val.constraint; |
d9a28762 | 158 | } |
159 | ||
3814599d | 160 | extern functionConstraint functionClause_takeEnsures (functionClause fc) |
d9a28762 | 161 | { |
3814599d | 162 | functionConstraint res; |
d9a28762 | 163 | llassert (functionClause_isDefined (fc)); |
164 | llassert (fc->kind == FCK_ENSURES); | |
165 | ||
3814599d | 166 | res = fc->val.constraint; |
167 | fc->val.constraint = NULL; | |
d9a28762 | 168 | fc->kind = FCK_DEAD; |
169 | return res; | |
170 | } | |
171 | ||
3814599d | 172 | extern functionConstraint functionClause_getRequires (functionClause node) |
d9a28762 | 173 | { |
174 | llassert (functionClause_isDefined (node)); | |
175 | llassert (node->kind == FCK_REQUIRES); | |
176 | ||
3814599d | 177 | return node->val.constraint; |
d9a28762 | 178 | } |
179 | ||
3814599d | 180 | extern functionConstraint functionClause_takeRequires (functionClause fc) |
d9a28762 | 181 | { |
3814599d | 182 | functionConstraint res; |
d9a28762 | 183 | llassert (functionClause_isDefined (fc)); |
184 | llassert (fc->kind == FCK_REQUIRES); | |
185 | ||
3814599d | 186 | res = fc->val.constraint; |
187 | fc->val.constraint = NULL; | |
08eb3d0e | 188 | fc->kind = FCK_DEAD; |
189 | return res; | |
190 | } | |
191 | ||
28bf4b0b | 192 | extern warnClause functionClause_getWarn (functionClause node) |
193 | { | |
194 | llassert (functionClause_isDefined (node)); | |
195 | llassert (node->kind == FCK_WARN); | |
196 | ||
197 | return node->val.warn; | |
198 | } | |
199 | ||
200 | extern warnClause functionClause_takeWarn (functionClause fc) | |
201 | { | |
202 | warnClause res; | |
203 | llassert (functionClause_isDefined (fc)); | |
204 | llassert (fc->kind == FCK_WARN); | |
205 | ||
206 | res = fc->val.warn; | |
207 | fc->val.warn = warnClause_undefined; | |
208 | fc->kind = FCK_DEAD; | |
209 | return res; | |
210 | } | |
211 | ||
212 | extern modifiesClause functionClause_getModifies (functionClause node) | |
213 | { | |
214 | llassert (functionClause_isDefined (node)); | |
215 | llassert (node->kind == FCK_MODIFIES); | |
216 | ||
217 | return node->val.modifies; | |
218 | } | |
219 | ||
220 | extern globalsClause functionClause_getGlobals (functionClause node) | |
221 | { | |
222 | llassert (functionClause_isDefined (node)); | |
223 | llassert (node->kind == FCK_GLOBALS); | |
224 | ||
225 | return node->val.globals; | |
226 | } | |
227 | ||
228 | extern void functionClause_free (/*@only@*/ functionClause node) | |
229 | { | |
230 | if (node != NULL) | |
231 | { | |
bb7c2085 | 232 | DPRINTF (("free: %s", functionClause_unparse (node))); |
233 | ||
28bf4b0b | 234 | switch (node->kind) |
235 | { | |
236 | case FCK_GLOBALS: | |
237 | globalsClause_free (node->val.globals); | |
238 | break; | |
239 | case FCK_MODIFIES: | |
240 | modifiesClause_free (node->val.modifies); | |
241 | break; | |
242 | case FCK_WARN: | |
243 | warnClause_free (node->val.warn); | |
244 | break; | |
245 | case FCK_STATE: | |
246 | stateClause_free (node->val.state); | |
247 | break; | |
d9a28762 | 248 | case FCK_ENSURES: |
3814599d | 249 | functionConstraint_free (node->val.constraint); |
d9a28762 | 250 | break; |
251 | case FCK_REQUIRES: | |
3814599d | 252 | functionConstraint_free (node->val.constraint); |
08eb3d0e | 253 | break; |
28bf4b0b | 254 | case FCK_DEAD: |
255 | /* Nothing to release */ | |
256 | break; | |
257 | } | |
258 | ||
259 | sfree (node); | |
260 | } | |
261 | } |