Some consistency changes to library & headers flags.
[splint-patched.git] / src / idDecl.c
blob5aa3e5a75e1d607c016f435d846714cd2320ebd9
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.
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
25 ** idDecl.c
28 # include "splintMacros.nf"
29 # include "basic.h"
31 static /*@only@*/ idDecl
32 idDecl_createClauses (/*@only@*/ cstring s, /*@only@*/ qtype t, /*@only@*/ functionClauseList clauses)
34 idDecl d = (idDecl) dmalloc (sizeof (*d));
36 d->id = s;
37 d->typ = t;
38 d->clauses = clauses;
40 return (d);
43 /*@only@*/ idDecl
44 idDecl_create (/*@only@*/ cstring s, /*@only@*/ qtype t)
46 return idDecl_createClauses (s, t, functionClauseList_undefined);
49 void
50 idDecl_free (idDecl t)
52 if (idDecl_isDefined (t))
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);
58 /*@-compdestroy@*/ sfree (t); /*@=compdestroy@*/
62 cstring
63 idDecl_unparse (idDecl d)
65 if (idDecl_isDefined (d))
67 if (functionClauseList_isDefined (d->clauses))
69 return (message ("%s : %q / %q", d->id, qtype_unparse (d->typ),
70 functionClauseList_unparse (d->clauses)));
72 else
74 return (message ("%s : %q", d->id, qtype_unparse (d->typ)));
77 else
79 return (cstring_makeLiteral ("<undefined id>"));
83 cstring
84 idDecl_unparseC (idDecl d)
86 if (idDecl_isDefined (d))
88 return (message ("%q %s", qtype_unparse (d->typ), d->id));
90 else
92 return (cstring_makeLiteral ("<undefined id>"));
96 /*@observer@*/ cstring
97 idDecl_observeId (idDecl d)
99 if (idDecl_isDefined (d))
101 return (d->id);
103 else
105 return cstring_undefined;
109 qtype
110 idDecl_getTyp (idDecl d)
112 llassert (idDecl_isDefined (d));
114 return d->typ;
117 ctype
118 idDecl_getCtype (idDecl d)
120 if (idDecl_isDefined (d))
122 return (qtype_getType (d->typ));
124 else
126 return ctype_unknown;
130 qualList
131 idDecl_getQuals (idDecl d)
133 if (idDecl_isDefined (d))
135 return (qtype_getQuals (d->typ));
137 else
139 return qualList_undefined;
143 functionClauseList
144 idDecl_getClauses (idDecl d)
146 if (idDecl_isDefined (d))
148 return (d->clauses);
150 else
152 return functionClauseList_undefined;
156 void
157 idDecl_addQual (idDecl d, qual q)
159 llassert (idDecl_isDefined (d));
161 (void) qtype_addQual (d->typ, q);
164 void
165 idDecl_setTyp (idDecl d, qtype c)
167 llassert (idDecl_isDefined (d));
169 qtype_free (d->typ);
170 d->typ = c;
173 idDecl
174 idDecl_replaceCtype (/*@returned@*/ idDecl d, ctype c)
176 llassert (idDecl_isDefined (d));
178 DPRINTF (("Replace type: %s / %s", idDecl_unparse (d), ctype_unparse (c)));
179 qtype_setType (d->typ, c);
180 return d;
183 idDecl
184 idDecl_fixBase (/*@returned@*/ idDecl t, qtype b)
186 llassert (idDecl_isDefined (t));
188 t->typ = qtype_newQbase (t->typ, b);
189 return t;
192 idDecl
193 idDecl_fixParamBase (/*@returned@*/ idDecl t, qtype b)
195 qtype q;
196 ctype c;
198 llassert (idDecl_isDefined (t));
200 q = qtype_newQbase (t->typ, b);
201 c = qtype_getType (q);
204 ** For some reason, C adds an implicit pointer to function
205 ** parameters. It is "optional" syntax.
208 if (ctype_isFunction (c) && !ctype_isPointer (c))
210 qtype_setType (q, ctype_makePointer (c));
213 t->typ = q;
214 /* Splint thinks t->typ is kept. */
215 /*@-compmempass@*/ return t; /*@=compmempass@*/
218 idDecl
219 idDecl_expectFunction (/*@returned@*/ idDecl d)
221 llassert (idDecl_isDefined (d));
223 qtype_setType (d->typ, ctype_expectFunction (qtype_getType (d->typ)));
224 return d;
228 ** evans 2002-02-09: This is a bit of a kludge, but we
229 ** need it to fix declarations like int (*p)[];
232 void
233 idDecl_notExpectingFunction (/*@returned@*/ idDecl d)
235 if (idDecl_isDefined (d))
237 ctype ct = qtype_getType (d->typ);
239 if (ctype_isExpFcn (ct))
241 qtype_setType (d->typ, ctype_dontExpectFunction (ct));
246 void
247 idDecl_addClauses (idDecl d, functionClauseList clauses)
249 llassert (idDecl_isDefined (d));
252 DRL comment out llassert:
254 This breaks on sometypes of functionPointers.
255 I.e.
256 void (*signal (int sig ) @requires g >= 0 @ ) (int) @requires g >= 0 @ ;
258 llassert (functionClauseList_isUndefined (d->clauses));
262 if (functionClauseList_isUndefined (d->clauses) )
264 d->clauses = clauses;
266 else
268 functionClauseList_free(d->clauses);
269 d->clauses = clauses;