2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
28 # include "splintMacros.nf"
31 static /*@only@*/ idDecl
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 /* don't: 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 DPRINTF (("Replace type: %s / %s", idDecl_unparse (d
), ctype_unparse (c
)));
179 qtype_setType (d
->typ
, c
);
184 idDecl_fixBase (/*@returned@*/ idDecl t
, qtype b
)
186 llassert (idDecl_isDefined (t
));
188 t
->typ
= qtype_newQbase (t
->typ
, b
);
193 idDecl_fixParamBase (/*@returned@*/ idDecl t
, qtype b
)
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
));
214 /* Splint thinks t->typ is kept. */
215 /*@-compmempass@*/ return t
; /*@=compmempass@*/
219 idDecl_expectFunction (/*@returned@*/ idDecl d
)
221 llassert (idDecl_isDefined (d
));
223 qtype_setType (d
->typ
, ctype_expectFunction (qtype_getType (d
->typ
)));
228 ** evans 2002-02-09: This is a bit of a kludge, but we
229 ** need it to fix declarations like int (*p)[];
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
));
247 idDecl_addClauses (idDecl d
, functionClauseList clauses
)
249 llassert (idDecl_isDefined (d
));
252 DRL comment out llassert:
254 This breaks on sometypes of functionPointers.
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
;
268 functionClauseList_free(d
->clauses
);
269 d
->clauses
= clauses
;