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 functionClause res = functionClause_alloc (FCK_STATE);
57 res->val.state = node;
61 extern functionClause functionClause_createEnsures (functionConstraint node) /*@*/
63 functionClause res = functionClause_alloc (FCK_ENSURES);
64 res->val.constraint = node;
68 extern functionClause functionClause_createRequires (functionConstraint node) /*@*/
70 functionClause res = functionClause_alloc (FCK_REQUIRES);
71 res->val.constraint = node;
75 extern functionClause functionClause_createWarn (warnClause node) /*@*/
77 functionClause res = functionClause_alloc (FCK_WARN);
82 /*@only@*/ cstring functionClause_unparse (functionClause p)
84 if (functionClause_isUndefined (p))
86 return cstring_undefined;
92 return globalsClause_unparse (p->val.globals);
94 return modifiesClause_unparse (p->val.modifies);
96 return warnClause_unparse (p->val.warn);
98 return stateClause_unparse (p->val.state);
100 return message ("ensures %q", functionConstraint_unparse (p->val.constraint));
102 return message ("requires %q", functionConstraint_unparse (p->val.constraint));
104 return cstring_makeLiteral ("<dead clause>");
107 BADBRANCHRET (cstring_undefined);
110 extern bool functionClause_matchKind (functionClause p, functionClauseKind kind) /*@*/
112 if (functionClause_isDefined (p))
114 return (p->kind == kind);
122 extern stateClause functionClause_getState (functionClause node)
124 llassert (functionClause_isDefined (node));
125 llassert (node->kind == FCK_STATE);
127 return node->val.state;
130 extern stateClause functionClause_takeState (functionClause fc)
133 llassert (functionClause_isDefined (fc));
134 llassert (fc->kind == FCK_STATE);
137 fc->val.state = NULL;
142 extern functionConstraint functionClause_getEnsures (functionClause node)
144 llassert (functionClause_isDefined (node));
145 llassert (node->kind == FCK_ENSURES);
147 return node->val.constraint;
150 extern functionConstraint functionClause_takeEnsures (functionClause fc)
152 functionConstraint res;
153 llassert (functionClause_isDefined (fc));
154 llassert (fc->kind == FCK_ENSURES);
156 res = fc->val.constraint;
157 fc->val.constraint = NULL;
162 extern functionConstraint functionClause_getRequires (functionClause node)
164 llassert (functionClause_isDefined (node));
165 llassert (node->kind == FCK_REQUIRES);
167 return node->val.constraint;
170 extern functionConstraint functionClause_takeRequires (functionClause fc)
172 functionConstraint res;
173 llassert (functionClause_isDefined (fc));
174 llassert (fc->kind == FCK_REQUIRES);
176 res = fc->val.constraint;
177 fc->val.constraint = NULL;
182 extern warnClause functionClause_getWarn (functionClause node)
184 llassert (functionClause_isDefined (node));
185 llassert (node->kind == FCK_WARN);
187 return node->val.warn;
190 extern warnClause functionClause_takeWarn (functionClause fc)
193 llassert (functionClause_isDefined (fc));
194 llassert (fc->kind == FCK_WARN);
197 fc->val.warn = warnClause_undefined;
202 extern modifiesClause functionClause_getModifies (functionClause node)
204 llassert (functionClause_isDefined (node));
205 llassert (node->kind == FCK_MODIFIES);
207 return node->val.modifies;
210 extern globalsClause functionClause_getGlobals (functionClause node)
212 llassert (functionClause_isDefined (node));
213 llassert (node->kind == FCK_GLOBALS);
215 return node->val.globals;
218 extern void functionClause_free (/*@only@*/ functionClause node)
222 DPRINTF (("free: %s", functionClause_unparse (node)));
227 globalsClause_free (node->val.globals);
230 modifiesClause_free (node->val.modifies);
233 warnClause_free (node->val.warn);
236 stateClause_free (node->val.state);
239 functionConstraint_free (node->val.constraint);
242 functionConstraint_free (node->val.constraint);
245 /* Nothing to release */