]> andersk Git - splint.git/blame - src/functionClause.c
Manual flags.
[splint.git] / src / functionClause.c
CommitLineData
28bf4b0b 1/*
11db3170 2** Splint - annotation-assisted static program checker
77d37419 3** Copyright (C) 1994-2002 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**
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** functionClause.c
26*/
27
28# include "lclintMacros.nf"
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) /*@*/
55{
56 functionClause res = functionClause_alloc (FCK_STATE);
57 res->val.state = node;
58 return res;
59}
60
3814599d 61extern functionClause functionClause_createEnsures (functionConstraint node) /*@*/
d9a28762 62{
63 functionClause res = functionClause_alloc (FCK_ENSURES);
3814599d 64 res->val.constraint = node;
d9a28762 65 return res;
66}
67
3814599d 68extern functionClause functionClause_createRequires (functionConstraint node) /*@*/
d9a28762 69{
70 functionClause res = functionClause_alloc (FCK_REQUIRES);
3814599d 71 res->val.constraint = node;
08eb3d0e 72 return res;
73}
74
28bf4b0b 75extern functionClause functionClause_createWarn (warnClause node) /*@*/
76{
77 functionClause res = functionClause_alloc (FCK_WARN);
78 res->val.warn = node;
79 return res;
80}
81
82/*@only@*/ cstring functionClause_unparse (functionClause p)
83{
84 if (functionClause_isUndefined (p))
85 {
86 return cstring_undefined;
87 }
88
89 switch (p->kind)
90 {
91 case FCK_GLOBALS:
92 return globalsClause_unparse (p->val.globals);
93 case FCK_MODIFIES:
94 return modifiesClause_unparse (p->val.modifies);
95 case FCK_WARN:
96 return warnClause_unparse (p->val.warn);
97 case FCK_STATE:
98 return stateClause_unparse (p->val.state);
d9a28762 99 case FCK_ENSURES:
3814599d 100 return message ("ensures %q", functionConstraint_unparse (p->val.constraint));
d9a28762 101 case FCK_REQUIRES:
3814599d 102 return message ("requires %q", functionConstraint_unparse (p->val.constraint));
28bf4b0b 103 case FCK_DEAD:
104 BADBRANCH;
105 }
106
8250fa4a 107 BADBRANCHRET (cstring_undefined);
28bf4b0b 108}
109
110extern bool functionClause_matchKind (functionClause p, functionClauseKind kind) /*@*/
111{
112 if (functionClause_isDefined (p))
113 {
114 return (p->kind == kind);
115 }
116 else
117 {
118 return FALSE;
119 }
120}
121
122extern stateClause functionClause_getState (functionClause node)
123{
124 llassert (functionClause_isDefined (node));
125 llassert (node->kind == FCK_STATE);
126
127 return node->val.state;
128}
129
130extern stateClause functionClause_takeState (functionClause fc)
131{
132 stateClause res;
133 llassert (functionClause_isDefined (fc));
134 llassert (fc->kind == FCK_STATE);
135
136 res = fc->val.state;
137 fc->val.state = NULL;
138 fc->kind = FCK_DEAD;
139 return res;
140}
141
3814599d 142extern functionConstraint functionClause_getEnsures (functionClause node)
d9a28762 143{
144 llassert (functionClause_isDefined (node));
145 llassert (node->kind == FCK_ENSURES);
146
3814599d 147 return node->val.constraint;
d9a28762 148}
149
3814599d 150extern functionConstraint functionClause_takeEnsures (functionClause fc)
d9a28762 151{
3814599d 152 functionConstraint res;
d9a28762 153 llassert (functionClause_isDefined (fc));
154 llassert (fc->kind == FCK_ENSURES);
155
3814599d 156 res = fc->val.constraint;
157 fc->val.constraint = NULL;
d9a28762 158 fc->kind = FCK_DEAD;
159 return res;
160}
161
3814599d 162extern functionConstraint functionClause_getRequires (functionClause node)
d9a28762 163{
164 llassert (functionClause_isDefined (node));
165 llassert (node->kind == FCK_REQUIRES);
166
3814599d 167 return node->val.constraint;
d9a28762 168}
169
3814599d 170extern functionConstraint functionClause_takeRequires (functionClause fc)
d9a28762 171{
3814599d 172 functionConstraint res;
d9a28762 173 llassert (functionClause_isDefined (fc));
174 llassert (fc->kind == FCK_REQUIRES);
175
3814599d 176 res = fc->val.constraint;
177 fc->val.constraint = NULL;
08eb3d0e 178 fc->kind = FCK_DEAD;
179 return res;
180}
181
28bf4b0b 182extern warnClause functionClause_getWarn (functionClause node)
183{
184 llassert (functionClause_isDefined (node));
185 llassert (node->kind == FCK_WARN);
186
187 return node->val.warn;
188}
189
190extern warnClause functionClause_takeWarn (functionClause fc)
191{
192 warnClause res;
193 llassert (functionClause_isDefined (fc));
194 llassert (fc->kind == FCK_WARN);
195
196 res = fc->val.warn;
197 fc->val.warn = warnClause_undefined;
198 fc->kind = FCK_DEAD;
199 return res;
200}
201
202extern modifiesClause functionClause_getModifies (functionClause node)
203{
204 llassert (functionClause_isDefined (node));
205 llassert (node->kind == FCK_MODIFIES);
206
207 return node->val.modifies;
208}
209
210extern globalsClause functionClause_getGlobals (functionClause node)
211{
212 llassert (functionClause_isDefined (node));
213 llassert (node->kind == FCK_GLOBALS);
214
215 return node->val.globals;
216}
217
218extern void functionClause_free (/*@only@*/ functionClause node)
219{
220 if (node != NULL)
221 {
222 switch (node->kind)
223 {
224 case FCK_GLOBALS:
225 globalsClause_free (node->val.globals);
226 break;
227 case FCK_MODIFIES:
228 modifiesClause_free (node->val.modifies);
229 break;
230 case FCK_WARN:
231 warnClause_free (node->val.warn);
232 break;
233 case FCK_STATE:
234 stateClause_free (node->val.state);
235 break;
d9a28762 236 case FCK_ENSURES:
3814599d 237 functionConstraint_free (node->val.constraint);
d9a28762 238 break;
239 case FCK_REQUIRES:
3814599d 240 functionConstraint_free (node->val.constraint);
08eb3d0e 241 break;
28bf4b0b 242 case FCK_DEAD:
243 /* Nothing to release */
244 break;
245 }
246
247 sfree (node);
248 }
249}
This page took 1.619248 seconds and 5 git commands to generate.