2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
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.
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.
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.
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
28 # include "splintMacros.nf"
31 static /*@only@*/ /*@notnull@*/ /*@special@*/ functionClause /*@i32 need special? @*/
32 functionClause_alloc (functionClauseKind kind) /*@defines result->kind@*/
34 functionClause res = (functionClause) dmalloc (sizeof (*res));
40 extern functionClause functionClause_createGlobals (globalsClause node) /*@*/
42 functionClause res = functionClause_alloc (FCK_GLOBALS);
43 res->val.globals = node;
47 extern functionClause functionClause_createModifies (modifiesClause node) /*@*/
49 functionClause res = functionClause_alloc (FCK_MODIFIES);
50 res->val.modifies = node;
54 extern functionClause functionClause_createState (stateClause node) /*@*/
56 if (stateClause_hasEmptyReferences (node) &&
57 (!stateClause_isMetaState (node) ) )
59 DPRINTF((message("functionClause_createState:: Returning functionClause_undefined" ) ));
60 return functionClause_undefined;
64 functionClause res = functionClause_alloc (FCK_STATE);
65 res->val.state = node;
70 extern functionClause functionClause_createEnsures (functionConstraint node) /*@*/
72 functionClause res = functionClause_alloc (FCK_ENSURES);
73 res->val.constraint = node;
77 extern functionClause functionClause_createRequires (functionConstraint node) /*@*/
79 functionClause res = functionClause_alloc (FCK_REQUIRES);
80 res->val.constraint = node;
84 extern functionClause functionClause_createWarn (warnClause node) /*@*/
86 functionClause res = functionClause_alloc (FCK_WARN);
91 /*@only@*/ cstring functionClause_unparse (functionClause p)
93 if (functionClause_isUndefined (p))
95 return cstring_undefined;
101 return globalsClause_unparse (p->val.globals);
103 return modifiesClause_unparse (p->val.modifies);
105 return warnClause_unparse (p->val.warn);
107 return stateClause_unparse (p->val.state);
109 return message ("ensures %q", functionConstraint_unparse (p->val.constraint));
111 return message ("requires %q", functionConstraint_unparse (p->val.constraint));
113 return cstring_makeLiteral ("<dead clause>");
116 BADBRANCHRET (cstring_undefined);
119 extern bool functionClause_matchKind (functionClause p, functionClauseKind kind) /*@*/
121 if (functionClause_isDefined (p))
123 return (p->kind == kind);
131 extern stateClause functionClause_getState (functionClause node)
133 llassert (functionClause_isDefined (node));
134 llassert (node->kind == FCK_STATE);
136 return node->val.state;
139 extern stateClause functionClause_takeState (functionClause fc)
142 llassert (functionClause_isDefined (fc));
143 llassert (fc->kind == FCK_STATE);
146 fc->val.state = NULL;
151 extern functionConstraint functionClause_getEnsures (functionClause node)
153 llassert (functionClause_isDefined (node));
154 llassert (node->kind == FCK_ENSURES);
156 return node->val.constraint;
159 extern functionConstraint functionClause_takeEnsures (functionClause fc)
161 functionConstraint res;
162 llassert (functionClause_isDefined (fc));
163 llassert (fc->kind == FCK_ENSURES);
165 res = fc->val.constraint;
166 fc->val.constraint = NULL;
171 extern functionConstraint functionClause_getRequires (functionClause node)
173 llassert (functionClause_isDefined (node));
174 llassert (node->kind == FCK_REQUIRES);
176 return node->val.constraint;
179 extern functionConstraint functionClause_takeRequires (functionClause fc)
181 functionConstraint res;
182 llassert (functionClause_isDefined (fc));
183 llassert (fc->kind == FCK_REQUIRES);
185 res = fc->val.constraint;
186 fc->val.constraint = NULL;
191 extern warnClause functionClause_getWarn (functionClause node)
193 llassert (functionClause_isDefined (node));
194 llassert (node->kind == FCK_WARN);
196 return node->val.warn;
199 extern warnClause functionClause_takeWarn (functionClause fc)
202 llassert (functionClause_isDefined (fc));
203 llassert (fc->kind == FCK_WARN);
206 fc->val.warn = warnClause_undefined;
211 extern modifiesClause functionClause_getModifies (functionClause node)
213 llassert (functionClause_isDefined (node));
214 llassert (node->kind == FCK_MODIFIES);
216 return node->val.modifies;
219 extern globalsClause functionClause_getGlobals (functionClause node)
221 llassert (functionClause_isDefined (node));
222 llassert (node->kind == FCK_GLOBALS);
224 return node->val.globals;
227 extern void functionClause_free (/*@only@*/ functionClause node)
231 DPRINTF (("free: %s", functionClause_unparse (node)));
236 globalsClause_free (node->val.globals);
239 modifiesClause_free (node->val.modifies);
242 warnClause_free (node->val.warn);
245 stateClause_free (node->val.state);
248 functionConstraint_free (node->val.constraint);
251 functionConstraint_free (node->val.constraint);
254 /* Nothing to release */