]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | ** Splint - annotation-assisted static program checker | |
3 | ** Copyright (C) 1994-2003 University of Virginia, | |
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 | ** | |
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 | |
23 | */ | |
24 | /* | |
25 | ** idDecl.c | |
26 | */ | |
27 | ||
28 | # include "splintMacros.nf" | |
29 | # include "basic.h" | |
30 | ||
31 | /*@only@*/ idDecl | |
32 | idDecl_createClauses (/*@only@*/ cstring s, /*@only@*/ qtype t, /*@only@*/ functionClauseList clauses) | |
33 | { | |
34 | idDecl d = (idDecl) dmalloc (sizeof (*d)); | |
35 | ||
36 | d->id = s; | |
37 | d->typ = t; | |
38 | d->clauses = clauses; | |
39 | ||
40 | return (d); | |
41 | } | |
42 | ||
43 | /*@only@*/ idDecl | |
44 | idDecl_create (/*@only@*/ cstring s, /*@only@*/ qtype t) | |
45 | { | |
46 | return idDecl_createClauses (s, t, functionClauseList_undefined); | |
47 | } | |
48 | ||
49 | void | |
50 | idDecl_free (idDecl t) | |
51 | { | |
52 | if (idDecl_isDefined (t)) | |
53 | { | |
54 | /* don't: functionClauseList_free (t->clauses); */ /* evans 2002-01-03: splint catches this now! */ | |
55 | qtype_free (t->typ); | |
56 | cstring_free (t->id); | |
57 | ||
58 | /*@-compdestroy@*/ sfree (t); /*@=compdestroy@*/ | |
59 | } | |
60 | } | |
61 | ||
62 | cstring | |
63 | idDecl_unparse (idDecl d) | |
64 | { | |
65 | if (idDecl_isDefined (d)) | |
66 | { | |
67 | if (functionClauseList_isDefined (d->clauses)) | |
68 | { | |
69 | return (message ("%s : %q / %q", d->id, qtype_unparse (d->typ), | |
70 | functionClauseList_unparse (d->clauses))); | |
71 | } | |
72 | else | |
73 | { | |
74 | return (message ("%s : %q", d->id, qtype_unparse (d->typ))); | |
75 | } | |
76 | } | |
77 | else | |
78 | { | |
79 | return (cstring_makeLiteral ("<undefined id>")); | |
80 | } | |
81 | } | |
82 | ||
83 | cstring | |
84 | idDecl_unparseC (idDecl d) | |
85 | { | |
86 | if (idDecl_isDefined (d)) | |
87 | { | |
88 | return (message ("%q %s", qtype_unparse (d->typ), d->id)); | |
89 | } | |
90 | else | |
91 | { | |
92 | return (cstring_makeLiteral ("<undefined id>")); | |
93 | } | |
94 | } | |
95 | ||
96 | /*@observer@*/ cstring | |
97 | idDecl_observeId (idDecl d) | |
98 | { | |
99 | if (idDecl_isDefined (d)) | |
100 | { | |
101 | return (d->id); | |
102 | } | |
103 | else | |
104 | { | |
105 | return cstring_undefined; | |
106 | } | |
107 | } | |
108 | ||
109 | qtype | |
110 | idDecl_getTyp (idDecl d) | |
111 | { | |
112 | llassert (idDecl_isDefined (d)); | |
113 | ||
114 | return d->typ; | |
115 | } | |
116 | ||
117 | ctype | |
118 | idDecl_getCtype (idDecl d) | |
119 | { | |
120 | if (idDecl_isDefined (d)) | |
121 | { | |
122 | return (qtype_getType (d->typ)); | |
123 | } | |
124 | else | |
125 | { | |
126 | return ctype_unknown; | |
127 | } | |
128 | } | |
129 | ||
130 | qualList | |
131 | idDecl_getQuals (idDecl d) | |
132 | { | |
133 | if (idDecl_isDefined (d)) | |
134 | { | |
135 | return (qtype_getQuals (d->typ)); | |
136 | } | |
137 | else | |
138 | { | |
139 | return qualList_undefined; | |
140 | } | |
141 | } | |
142 | ||
143 | functionClauseList | |
144 | idDecl_getClauses (idDecl d) | |
145 | { | |
146 | if (idDecl_isDefined (d)) | |
147 | { | |
148 | return (d->clauses); | |
149 | } | |
150 | else | |
151 | { | |
152 | return functionClauseList_undefined; | |
153 | } | |
154 | } | |
155 | ||
156 | void | |
157 | idDecl_addQual (idDecl d, qual q) | |
158 | { | |
159 | llassert (idDecl_isDefined (d)); | |
160 | ||
161 | (void) qtype_addQual (d->typ, q); | |
162 | } | |
163 | ||
164 | void | |
165 | idDecl_setTyp (idDecl d, qtype c) | |
166 | { | |
167 | llassert (idDecl_isDefined (d)); | |
168 | ||
169 | qtype_free (d->typ); | |
170 | d->typ = c; | |
171 | } | |
172 | ||
173 | idDecl | |
174 | idDecl_replaceCtype (/*@returned@*/ idDecl d, ctype c) | |
175 | { | |
176 | llassert (idDecl_isDefined (d)); | |
177 | ||
178 | DPRINTF (("Replace type: %s / %s", idDecl_unparse (d), ctype_unparse (c))); | |
179 | qtype_setType (d->typ, c); | |
180 | return d; | |
181 | } | |
182 | ||
183 | idDecl | |
184 | idDecl_fixBase (/*@returned@*/ idDecl t, qtype b) | |
185 | { | |
186 | llassert (idDecl_isDefined (t)); | |
187 | ||
188 | t->typ = qtype_newQbase (t->typ, b); | |
189 | return t; | |
190 | } | |
191 | ||
192 | idDecl | |
193 | idDecl_fixParamBase (/*@returned@*/ idDecl t, qtype b) | |
194 | { | |
195 | qtype q; | |
196 | ctype c; | |
197 | ||
198 | llassert (idDecl_isDefined (t)); | |
199 | ||
200 | q = qtype_newQbase (t->typ, b); | |
201 | c = qtype_getType (q); | |
202 | ||
203 | /* | |
204 | ** For some reason, C adds an implicit pointer to function | |
205 | ** parameters. It is "optional" syntax. | |
206 | */ | |
207 | ||
208 | if (ctype_isFunction (c) && !ctype_isPointer (c)) | |
209 | { | |
210 | qtype_setType (q, ctype_makePointer (c)); | |
211 | } | |
212 | ||
213 | t->typ = q; | |
214 | /* Splint thinks t->typ is kept. */ | |
215 | /*@-compmempass@*/ return t; /*@=compmempass@*/ | |
216 | } | |
217 | ||
218 | idDecl | |
219 | idDecl_expectFunction (/*@returned@*/ idDecl d) | |
220 | { | |
221 | llassert (idDecl_isDefined (d)); | |
222 | ||
223 | qtype_setType (d->typ, ctype_expectFunction (qtype_getType (d->typ))); | |
224 | return d; | |
225 | } | |
226 | ||
227 | /* | |
228 | ** evans 2002-02-09: This is a bit of a kludge, but we | |
229 | ** need it to fix declarations like int (*p)[]; | |
230 | */ | |
231 | ||
232 | void | |
233 | idDecl_notExpectingFunction (/*@returned@*/ idDecl d) | |
234 | { | |
235 | if (idDecl_isDefined (d)) | |
236 | { | |
237 | ctype ct = qtype_getType (d->typ); | |
238 | ||
239 | if (ctype_isExpFcn (ct)) | |
240 | { | |
241 | qtype_setType (d->typ, ctype_dontExpectFunction (ct)); | |
242 | } | |
243 | } | |
244 | } | |
245 | ||
246 | void | |
247 | idDecl_addClauses (idDecl d, functionClauseList clauses) | |
248 | { | |
249 | llassert (idDecl_isDefined (d)); | |
250 | ||
251 | /* | |
252 | DRL comment out llassert: | |
253 | ||
254 | This breaks on sometypes of functionPointers. | |
255 | I.e. | |
256 | void (*signal (int sig ) @requires g >= 0 @ ) (int) @requires g >= 0 @ ; | |
257 | ||
258 | llassert (functionClauseList_isUndefined (d->clauses)); | |
259 | ||
260 | */ | |
261 | ||
262 | if (functionClauseList_isUndefined (d->clauses) ) | |
263 | { | |
264 | d->clauses = clauses; | |
265 | } | |
266 | else | |
267 | { | |
268 | functionClauseList_free(d->clauses); | |
269 | d->clauses = clauses; | |
270 | } | |
271 | } |