2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 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 splint: splint@cs.virginia.edu
21 ** To report a bug: splint-bug@cs.virginia.edu
22 ** For more information: http://www.splint.org
28 # include "splintMacros.nf"
32 idDecl_createClauses (/*@only@*/ cstring s, /*@only@*/ qtype t, /*@only@*/ functionClauseList clauses)
34 idDecl d = (idDecl) dmalloc (sizeof (*d));
44 idDecl_create (/*@only@*/ cstring s, /*@only@*/ qtype t)
46 return idDecl_createClauses (s, t, functionClauseList_undefined);
50 idDecl_free (idDecl t)
52 if (idDecl_isDefined (t))
54 /*@i523 functionClauseList_free (t->clauses); */ /* evans 2002-01-03: splint catches this now! */
58 /*@-compdestroy@*/ sfree (t); /*@=compdestroy@*/
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)));
74 return (message ("%s : %q", d->id, qtype_unparse (d->typ)));
79 return (cstring_makeLiteral ("<undefined id>"));
84 idDecl_unparseC (idDecl d)
86 if (idDecl_isDefined (d))
88 return (message ("%q %s", qtype_unparse (d->typ), d->id));
92 return (cstring_makeLiteral ("<undefined id>"));
96 /*@observer@*/ cstring
97 idDecl_observeId (idDecl d)
99 if (idDecl_isDefined (d))
105 return cstring_undefined;
110 idDecl_getTyp (idDecl d)
112 llassert (idDecl_isDefined (d));
118 idDecl_getCtype (idDecl d)
120 if (idDecl_isDefined (d))
122 return (qtype_getType (d->typ));
126 return ctype_unknown;
131 idDecl_getQuals (idDecl d)
133 if (idDecl_isDefined (d))
135 return (qtype_getQuals (d->typ));
139 return qualList_undefined;
144 idDecl_getClauses (idDecl d)
146 if (idDecl_isDefined (d))
152 return functionClauseList_undefined;
157 idDecl_addQual (idDecl d, qual q)
159 llassert (idDecl_isDefined (d));
161 (void) qtype_addQual (d->typ, q);
165 idDecl_setTyp (idDecl d, qtype c)
167 llassert (idDecl_isDefined (d));
174 idDecl_replaceCtype (/*@returned@*/ idDecl d, ctype c)
176 llassert (idDecl_isDefined (d));
178 qtype_setType (d->typ, c);
183 idDecl_fixBase (/*@returned@*/ idDecl t, qtype b)
185 llassert (idDecl_isDefined (t));
187 t->typ = qtype_newQbase (t->typ, b);
192 idDecl_fixParamBase (/*@returned@*/ idDecl t, qtype b)
197 llassert (idDecl_isDefined (t));
199 q = qtype_newQbase (t->typ, b);
200 c = qtype_getType (q);
203 ** For some reason, C adds an implicit pointer to function
204 ** parameters. It is "optional" syntax.
207 if (ctype_isFunction (c) && !ctype_isPointer (c))
209 qtype_setType (q, ctype_makePointer (c));
213 /* Splint thinks t->typ is kept. */
214 /*@-compmempass@*/ return t; /*@=compmempass@*/
218 idDecl_expectFunction (/*@returned@*/ idDecl d)
220 llassert (idDecl_isDefined (d));
222 qtype_setType (d->typ, ctype_expectFunction (qtype_getType (d->typ)));
227 idDecl_addClauses (idDecl d, functionClauseList clauses)
229 llassert (idDecl_isDefined (d));
230 llassert (functionClauseList_isUndefined (d->clauses));
231 d->clauses = clauses;