]> andersk Git - splint.git/blame - src/functionConstraint.c
Fixed all /*@i...@*/ tags (except 1).
[splint.git] / src / functionConstraint.c
CommitLineData
3814599d 1/*
11db3170 2** Splint - annotation-assisted static program checker
c59f5181 3** Copyright (C) 1994-2003 University of Virginia,
3814599d 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**
155af98d 20** For information on splint: info@splint.org
21** To report a bug: splint-bug@splint.org
11db3170 22** For more information: http://www.splint.org
3814599d 23*/
24/*
25** functionConstraint.c
26*/
27
1b8ae690 28# include "splintMacros.nf"
3814599d 29# include "basic.h"
3814599d 30
b73d1009 31static /*@only@*/ /*@notnull@*/ /*@special@*/ functionConstraint
3814599d 32functionConstraint_alloc (functionConstraintKind kind) /*@defines result->kind@*/
33{
34 functionConstraint res = (functionConstraint) dmalloc (sizeof (*res));
35
36 res->kind = kind;
37 return res;
38}
39
40extern functionConstraint functionConstraint_createBufferConstraint (constraintList buf)
41{
42 functionConstraint res = functionConstraint_alloc (FCT_BUFFER);
43 res->constraint.buffer = buf;
44 return res;
45}
46
47extern functionConstraint functionConstraint_createMetaStateConstraint (metaStateConstraint msc)
48{
49 functionConstraint res = functionConstraint_alloc (FCT_METASTATE);
50 res->constraint.metastate = msc;
51 return res;
52}
53
ba45e1e4 54extern functionConstraint functionConstraint_conjoin (functionConstraint f1, functionConstraint f2)
55{
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)));
61 return res;
62}
63
3814599d 64/*@only@*/ cstring functionConstraint_unparse (functionConstraint p)
65{
66 if (functionConstraint_isDefined (p))
67 {
68 switch (p->kind)
69 {
70 case FCT_BUFFER:
71 return constraintList_unparse (p->constraint.buffer);
72 case FCT_METASTATE:
73 return metaStateConstraint_unparse (p->constraint.metastate);
ba45e1e4 74 case FCT_CONJUNCT:
75 return message ("%q /\\ %q",
76 functionConstraint_unparse (p->constraint.conjunct.op1),
77 functionConstraint_unparse (p->constraint.conjunct.op2));
3814599d 78 BADDEFAULT;
79 }
80 BADBRANCH;
81 }
82 else
83 {
84 return cstring_makeLiteral ("< empty constraint >");
85 }
86}
87
ccf0a4a8 88extern constraintList functionConstraint_getBufferConstraints (functionConstraint node)
3814599d 89{
ccf0a4a8 90 if (functionConstraint_isDefined (node))
ba45e1e4 91 {
ccf0a4a8 92 if (node->kind == FCT_CONJUNCT)
ba45e1e4 93 {
b73d1009 94 /* make sure this is safe*/
ccf0a4a8 95 return constraintList_addListFree (functionConstraint_getBufferConstraints (node->constraint.conjunct.op1),
96 functionConstraint_getBufferConstraints (node->constraint.conjunct.op2));
ba45e1e4 97 }
98 else
99 {
ccf0a4a8 100 if (node->kind == FCT_BUFFER)
101 {
102 return constraintList_copy (node->constraint.buffer);
103 }
104 else
105 {
106 return constraintList_undefined;
107 }
ba45e1e4 108 }
109 }
ccf0a4a8 110 else
111 {
112 return constraintList_undefined;
113 }
3814599d 114}
115
ccf0a4a8 116extern metaStateConstraintList functionConstraint_getMetaStateConstraints (functionConstraint node)
3814599d 117{
ccf0a4a8 118 if (functionConstraint_isDefined (node))
ba45e1e4 119 {
ccf0a4a8 120 if (node->kind == FCT_CONJUNCT)
ba45e1e4 121 {
ccf0a4a8 122 return metaStateConstraintList_append
123 (functionConstraint_getMetaStateConstraints (node->constraint.conjunct.op1),
124 functionConstraint_getMetaStateConstraints (node->constraint.conjunct.op2));
ba45e1e4 125 }
126 else
127 {
ccf0a4a8 128 if (node->kind == FCT_METASTATE)
129 {
130 return metaStateConstraintList_single (node->constraint.metastate);
131 }
132 else
133 {
134 return metaStateConstraintList_undefined;
135 }
ba45e1e4 136 }
137 }
ccf0a4a8 138 else
139 {
140 return metaStateConstraintList_undefined;
141 }
3814599d 142}
143
144extern bool functionConstraint_hasBufferConstraint (functionConstraint node)
145{
ba45e1e4 146 if (functionConstraint_isDefined (node))
147 {
148 return node->kind == FCT_BUFFER
149 || (node->kind == FCT_CONJUNCT
150 && (functionConstraint_hasBufferConstraint (node->constraint.conjunct.op1)
151 || functionConstraint_hasBufferConstraint (node->constraint.conjunct.op2)));
152 }
153 else
154 {
155 return FALSE;
156 }
157}
158
159extern bool functionConstraint_hasMetaStateConstraint (functionConstraint node)
160{
161 if (functionConstraint_isDefined (node))
162 {
163 return node->kind == FCT_METASTATE
164 || (node->kind == FCT_CONJUNCT
165 && (functionConstraint_hasMetaStateConstraint (node->constraint.conjunct.op1)
166 || functionConstraint_hasMetaStateConstraint (node->constraint.conjunct.op2)));
167 }
168 else
169 {
170 return FALSE;
171 }
3814599d 172}
173
174extern functionConstraint functionConstraint_copy (functionConstraint node)
175{
176 if (functionConstraint_isDefined (node))
177 {
178 switch (node->kind)
179 {
180 case FCT_BUFFER:
181 return functionConstraint_createBufferConstraint (constraintList_copy (node->constraint.buffer));
182 case FCT_METASTATE:
183 return functionConstraint_createMetaStateConstraint (metaStateConstraint_copy (node->constraint.metastate));
ba45e1e4 184 case FCT_CONJUNCT:
185 return functionConstraint_conjoin (functionConstraint_copy (node->constraint.conjunct.op1),
186 functionConstraint_copy (node->constraint.conjunct.op2));
3814599d 187 }
188
189 BADBRANCH;
190 }
191 else
192 {
193 return functionConstraint_undefined;
194 }
8250fa4a 195
196 BADBRANCHRET (functionConstraint_undefined);
3814599d 197}
198
199extern void functionConstraint_free (/*@only@*/ functionConstraint node)
200{
201 if (functionConstraint_isDefined (node))
202 {
203 switch (node->kind)
204 {
205 case FCT_BUFFER:
206 constraintList_free (node->constraint.buffer);
207 break;
208 case FCT_METASTATE:
209 metaStateConstraint_free (node->constraint.metastate);
210 break;
ba45e1e4 211 case FCT_CONJUNCT:
212 functionConstraint_free (node->constraint.conjunct.op1);
213 functionConstraint_free (node->constraint.conjunct.op2);
3120b462 214 break;
215 BADDEFAULT;
3814599d 216 }
217
218 sfree (node);
219 }
220}
ba45e1e4 221
4287634e 222/*drl modified */
223void functionConstraint_addBufferConstraints (functionConstraint node, constraintList clist)
c3be2604 224{
4287634e 225 constraintList temp;
ba45e1e4 226
4287634e 227 temp = constraintList_copy (clist);
228
229 if (functionConstraint_isDefined (node))
230 {
231 if (node->kind == FCT_CONJUNCT)
232 {
233 functionConstraint_addBufferConstraints (node->constraint.conjunct.op1, constraintList_copy(temp) );
234 functionConstraint_addBufferConstraints (node->constraint.conjunct.op2,temp);
235 }
236 else
237 {
238 if (node->kind == FCT_BUFFER)
239 {
18b723f4 240 node->constraint.buffer = constraintList_addListFree(node->constraint.buffer, temp);
4287634e 241 }
242 else
243 {
244 constraintList_free (temp);
245 return;
246 }
247 }
248 }
249 else
250 {
251 constraintList_free (temp);
252 return;
253 }
254}
This page took 0.100015 seconds and 5 git commands to generate.