]>
Commit | Line | Data |
---|---|---|
3814599d | 1 | /* |
11db3170 | 2 | ** Splint - annotation-assisted static program checker |
77d37419 | 3 | ** Copyright (C) 1994-2002 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 | |
31 | static /*@only@*/ /*@notnull@*/ /*@special@*/ functionConstraint /*@i32 need special? @*/ | |
32 | functionConstraint_alloc (functionConstraintKind kind) /*@defines result->kind@*/ | |
33 | { | |
34 | functionConstraint res = (functionConstraint) dmalloc (sizeof (*res)); | |
35 | ||
36 | res->kind = kind; | |
37 | return res; | |
38 | } | |
39 | ||
40 | extern functionConstraint functionConstraint_createBufferConstraint (constraintList buf) | |
41 | { | |
42 | functionConstraint res = functionConstraint_alloc (FCT_BUFFER); | |
43 | res->constraint.buffer = buf; | |
44 | return res; | |
45 | } | |
46 | ||
47 | extern functionConstraint functionConstraint_createMetaStateConstraint (metaStateConstraint msc) | |
48 | { | |
49 | functionConstraint res = functionConstraint_alloc (FCT_METASTATE); | |
50 | res->constraint.metastate = msc; | |
51 | return res; | |
52 | } | |
53 | ||
ba45e1e4 | 54 | extern 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 | 88 | extern constraintList functionConstraint_getBufferConstraints (functionConstraint node) |
3814599d | 89 | { |
ccf0a4a8 | 90 | if (functionConstraint_isDefined (node)) |
ba45e1e4 | 91 | { |
ccf0a4a8 | 92 | if (node->kind == FCT_CONJUNCT) |
ba45e1e4 | 93 | { |
312c9815 | 94 | /*@i223*/ /*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 | 116 | extern 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 | ||
144 | extern 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 | ||
159 | extern 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 | ||
174 | extern 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 | ||
199 | extern 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 | |
222 | ||
223 | ||
224 | ||
225 | ||
226 | ||
227 | ||
228 | ||
229 |