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
25 ** functionConstraint.c
28 # include "lclintMacros.nf"
31 static /*@only@*/ /*@notnull@*/ /*@special@*/ functionConstraint /*@i32 need special? @*/
32 functionConstraint_alloc (functionConstraintKind kind) /*@defines result->kind@*/
34 functionConstraint res = (functionConstraint) dmalloc (sizeof (*res));
40 extern functionConstraint functionConstraint_createBufferConstraint (constraintList buf)
42 functionConstraint res = functionConstraint_alloc (FCT_BUFFER);
43 res->constraint.buffer = buf;
47 extern functionConstraint functionConstraint_createMetaStateConstraint (metaStateConstraint msc)
49 functionConstraint res = functionConstraint_alloc (FCT_METASTATE);
50 res->constraint.metastate = msc;
54 extern functionConstraint functionConstraint_conjoin (functionConstraint f1, functionConstraint f2)
56 functionConstraint res = functionConstraint_alloc (FCT_CONJUNCT);
57 res->constraint.conjunct.op1 = f1;
58 res->constraint.conjunct.op2 = f2;
59 DPRINTF (("Conjoining ==> %s",
60 functionConstraint_unparse (res)));
64 /*@only@*/ cstring functionConstraint_unparse (functionConstraint p)
66 if (functionConstraint_isDefined (p))
71 return constraintList_unparse (p->constraint.buffer);
73 return metaStateConstraint_unparse (p->constraint.metastate);
75 return message ("%q /\\ %q",
76 functionConstraint_unparse (p->constraint.conjunct.op1),
77 functionConstraint_unparse (p->constraint.conjunct.op2));
84 return cstring_makeLiteral ("< empty constraint >");
88 extern constraintList functionConstraint_getBufferConstraint (functionConstraint node)
90 llassert (functionConstraint_isDefined (node));
92 if (node->kind == FCT_CONJUNCT)
94 if (functionConstraint_hasBufferConstraint (node->constraint.conjunct.op1))
96 return functionConstraint_getBufferConstraint (node->constraint.conjunct.op1);
100 llassert (functionConstraint_hasBufferConstraint (node->constraint.conjunct.op2));
101 return functionConstraint_getBufferConstraint (node->constraint.conjunct.op2);
105 llassert (node->kind == FCT_BUFFER);
106 return node->constraint.buffer;
109 extern metaStateConstraint functionConstraint_getMetaStateConstraint (functionConstraint node)
111 llassert (functionConstraint_isDefined (node));
113 if (node->kind == FCT_CONJUNCT)
115 if (functionConstraint_hasMetaStateConstraint (node->constraint.conjunct.op1))
117 return functionConstraint_getMetaStateConstraint (node->constraint.conjunct.op1);
121 llassert (functionConstraint_hasMetaStateConstraint (node->constraint.conjunct.op2));
122 return functionConstraint_getMetaStateConstraint (node->constraint.conjunct.op2);
126 llassert (node->kind == FCT_METASTATE);
127 return node->constraint.metastate;
130 extern bool functionConstraint_hasBufferConstraint (functionConstraint node)
132 if (functionConstraint_isDefined (node))
134 return node->kind == FCT_BUFFER
135 || (node->kind == FCT_CONJUNCT
136 && (functionConstraint_hasBufferConstraint (node->constraint.conjunct.op1)
137 || functionConstraint_hasBufferConstraint (node->constraint.conjunct.op2)));
145 extern bool functionConstraint_hasMetaStateConstraint (functionConstraint node)
147 if (functionConstraint_isDefined (node))
149 return node->kind == FCT_METASTATE
150 || (node->kind == FCT_CONJUNCT
151 && (functionConstraint_hasMetaStateConstraint (node->constraint.conjunct.op1)
152 || functionConstraint_hasMetaStateConstraint (node->constraint.conjunct.op2)));
160 extern functionConstraint functionConstraint_copy (functionConstraint node)
162 if (functionConstraint_isDefined (node))
167 return functionConstraint_createBufferConstraint (constraintList_copy (node->constraint.buffer));
169 return functionConstraint_createMetaStateConstraint (metaStateConstraint_copy (node->constraint.metastate));
171 return functionConstraint_conjoin (functionConstraint_copy (node->constraint.conjunct.op1),
172 functionConstraint_copy (node->constraint.conjunct.op2));
179 return functionConstraint_undefined;
183 extern void functionConstraint_free (/*@only@*/ functionConstraint node)
185 if (functionConstraint_isDefined (node))
190 constraintList_free (node->constraint.buffer);
193 metaStateConstraint_free (node->constraint.metastate);
196 functionConstraint_free (node->constraint.conjunct.op1);
197 functionConstraint_free (node->constraint.conjunct.op2);