2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 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 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
28 # include "lclintMacros.nf"
30 # include "mtincludes.h"
32 static /*@only@*/ /*@notnull@*/ /*@special@*/ functionClause /*@i32 need special? @*/
33 functionClause_alloc (functionClauseKind kind) /*@defines result->kind@*/
35 functionClause res = (functionClause) dmalloc (sizeof (*res));
41 extern functionClause functionClause_createGlobals (globalsClause node) /*@*/
43 functionClause res = functionClause_alloc (FCK_GLOBALS);
44 res->val.globals = node;
48 extern functionClause functionClause_createModifies (modifiesClause node) /*@*/
50 functionClause res = functionClause_alloc (FCK_MODIFIES);
51 res->val.modifies = node;
55 extern functionClause functionClause_createState (stateClause node) /*@*/
57 functionClause res = functionClause_alloc (FCK_STATE);
58 res->val.state = node;
62 extern functionClause functionClause_createEnsures (constraintList node) /*@*/
64 functionClause res = functionClause_alloc (FCK_ENSURES);
65 res->val.ensures = node;
69 extern functionClause functionClause_createRequires (constraintList node) /*@*/
71 functionClause res = functionClause_alloc (FCK_REQUIRES);
72 res->val.requires = node;
76 extern functionClause functionClause_createMetaEnsures (metaStateConstraint node) /*@*/
78 functionClause res = functionClause_alloc (FCK_MTENSURES);
79 res->val.mtconstraint = node;
83 extern functionClause functionClause_createMetaRequires (metaStateConstraint node) /*@*/
85 functionClause res = functionClause_alloc (FCK_MTREQUIRES);
86 res->val.mtconstraint = node;
90 extern functionClause functionClause_createWarn (warnClause node) /*@*/
92 functionClause res = functionClause_alloc (FCK_WARN);
97 /*@only@*/ cstring functionClause_unparse (functionClause p)
99 if (functionClause_isUndefined (p))
101 return cstring_undefined;
107 return globalsClause_unparse (p->val.globals);
109 return modifiesClause_unparse (p->val.modifies);
111 return warnClause_unparse (p->val.warn);
113 return stateClause_unparse (p->val.state);
115 return message ("ensures %q", constraintList_unparse (p->val.ensures));
117 return message ("requires %q", constraintList_unparse (p->val.requires));
119 return message ("ensures %q", metaStateConstraint_unparse (p->val.mtconstraint));
121 return message ("requires %q", metaStateConstraint_unparse (p->val.mtconstraint));
129 extern bool functionClause_matchKind (functionClause p, functionClauseKind kind) /*@*/
131 if (functionClause_isDefined (p))
133 return (p->kind == kind);
141 extern stateClause functionClause_getState (functionClause node)
143 llassert (functionClause_isDefined (node));
144 llassert (node->kind == FCK_STATE);
146 return node->val.state;
149 extern stateClause functionClause_takeState (functionClause fc)
152 llassert (functionClause_isDefined (fc));
153 llassert (fc->kind == FCK_STATE);
156 fc->val.state = NULL;
161 extern constraintList functionClause_getEnsures (functionClause node)
163 llassert (functionClause_isDefined (node));
164 llassert (node->kind == FCK_ENSURES);
166 return node->val.ensures;
169 extern constraintList functionClause_takeEnsures (functionClause fc)
172 llassert (functionClause_isDefined (fc));
173 llassert (fc->kind == FCK_ENSURES);
175 res = fc->val.ensures;
176 fc->val.ensures = NULL;
181 extern constraintList functionClause_getRequires (functionClause node)
183 llassert (functionClause_isDefined (node));
184 llassert (node->kind == FCK_REQUIRES);
186 return node->val.requires;
189 extern constraintList functionClause_takeRequires (functionClause fc)
192 llassert (functionClause_isDefined (fc));
193 llassert (fc->kind == FCK_REQUIRES);
195 res = fc->val.requires;
196 fc->val.requires = NULL;
201 extern metaStateConstraint functionClause_getMetaConstraint (functionClause node)
203 llassert (functionClause_isDefined (node));
204 llassert (node->kind == FCK_MTENSURES || node->kind == FCK_MTREQUIRES);
206 return node->val.mtconstraint;
209 extern metaStateConstraint functionClause_takeMetaConstraint (functionClause fc)
211 metaStateConstraint res;
212 llassert (functionClause_isDefined (fc));
213 llassert (fc->kind == FCK_MTENSURES || fc->kind == FCK_MTREQUIRES);
215 res = fc->val.mtconstraint;
216 fc->val.mtconstraint = NULL;
221 extern warnClause functionClause_getWarn (functionClause node)
223 llassert (functionClause_isDefined (node));
224 llassert (node->kind == FCK_WARN);
226 return node->val.warn;
229 extern warnClause functionClause_takeWarn (functionClause fc)
232 llassert (functionClause_isDefined (fc));
233 llassert (fc->kind == FCK_WARN);
236 fc->val.warn = warnClause_undefined;
241 extern modifiesClause functionClause_getModifies (functionClause node)
243 llassert (functionClause_isDefined (node));
244 llassert (node->kind == FCK_MODIFIES);
246 return node->val.modifies;
249 extern globalsClause functionClause_getGlobals (functionClause node)
251 llassert (functionClause_isDefined (node));
252 llassert (node->kind == FCK_GLOBALS);
254 return node->val.globals;
257 extern void functionClause_free (/*@only@*/ functionClause node)
264 globalsClause_free (node->val.globals);
267 modifiesClause_free (node->val.modifies);
270 warnClause_free (node->val.warn);
273 stateClause_free (node->val.state);
276 constraintList_free (node->val.ensures);
279 constraintList_free (node->val.requires);
283 metaStateConstraint_free (node->val.mtconstraint);
286 /* Nothing to release */