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