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