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: info@splint.org
21 ** To report a bug: splint-bug@splint.org
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>"));
83 /*drl added 04-22-2002
84 for code generate code
88 idDecl_unparseCNoType (idDecl d)
91 if (ctype_isFunction ( qtype_getType (d->typ ) ) )
94 return idDecl_unparseC(d);
96 if (idDecl_isDefined (d))
98 return (message ("%s", d->id));
103 return (cstring_makeLiteral ("<undefined id>"));
108 idDecl_unparseC (idDecl d)
110 if (idDecl_isDefined (d))
112 if (qtype_isFixedArray(d->typ) )
114 cstring ret, arType, size;
116 arType = qtype_unparseArrayType(d->typ);
117 size = qtype_unparseArraySize(d->typ);
118 ret = message ("%q %s %q", arType, d->id, size);
121 else if (qtype_isArray(d->typ) )
125 arType = qtype_unparseArrayType(d->typ);
126 ret = message ("%q %s[]", arType, d->id);
130 else if (ctype_isFunction ( qtype_getType (d->typ ) ) )
132 cstring st, tmp, cQuals, ret;
134 st = cstring_copy (d->id);
135 tmp = ctype_unparseFunction ( qtype_getType (d->typ ), st);
136 if ( qualList_isDefined(idDecl_getQuals (d) ) )
138 cQuals = qualList_unparse(idDecl_getQuals(d) );
142 cQuals = cstring_undefined;
145 ret = message("%q %q", cQuals, tmp);
154 tId = ctype_typeId(qtype_getType(d->typ) );
156 ue = usymtab_getTypeEntry (tId);
158 loc = uentry_whereDeclared(ue) ;
160 DPRINTF(( message("id = %s ue: %s at %s", d->id, uentry_unparse(ue), fileloc_unparse(loc) ) ));
161 return (message ("%q %s", qtypetryToPrintStruct (d->typ), d->id));
166 return (cstring_makeLiteral ("<undefined id>"));
171 /*drl added 04-24-2002*/
173 idDecl_unparseCLoc (idDecl d, fileloc dLoc)
175 if (idDecl_isDefined (d))
177 if (qtype_isFixedArray(d->typ) )
179 cstring ret, arType, size;
181 arType = qtype_unparseArrayType(d->typ);
182 size = qtype_unparseArraySize(d->typ);
183 ret = message ("%q %s %q", arType, d->id, size);
186 else if (qtype_isArray(d->typ) )
190 arType = qtype_unparseArrayType(d->typ);
191 ret = message ("%q %s[]", arType, d->id);
194 else if (ctype_isFunctionPointer ( qtype_getType (d->typ ) ) )
196 cstring st, tmp, cQuals, ret;
198 st = cstring_copy (d->id);
200 if ( qualList_isDefined(idDecl_getQuals (d) ) )
202 cQuals = qualList_unparse(idDecl_getQuals(d) );
206 cQuals = cstring_undefined;
209 tmp = ctype_unparseFunctionPointer ( qtype_getType (d->typ ), cQuals, st);
211 ret = message("%q", tmp);
212 cstring_free(cQuals);
215 else if (ctype_isFunction ( qtype_getType (d->typ ) ) )
217 cstring st, tmp, cQuals, ret;
219 st = cstring_copy (d->id);
220 tmp = ctype_unparseFunction ( qtype_getType (d->typ ), st);
221 if ( qualList_isDefined(idDecl_getQuals (d) ) )
223 cQuals = qualList_unparse(idDecl_getQuals(d) );
227 cQuals = cstring_undefined;
230 ret = message("%q %q", cQuals, tmp);
239 if (ctype_isUser(qtype_getType(d->typ) ) )
241 tId = ctype_typeId(qtype_getType(d->typ) );
243 ue = usymtab_getTypeEntry (tId);
245 loc = uentry_whereDeclared(ue) ;
247 DPRINTF(( message("id = %s ue: %s at %s", d->id, uentry_unparse(ue), fileloc_unparse(loc) ) ));
249 if (fileloc_sameFileAndLine (loc, dLoc) )
250 return (message ("%q %s", qtypetryToPrintStruct (d->typ), d->id));
253 return (message ("%s %s", qtype_unparse (d->typ), d->id));
255 } /*end if (ctype_isFunction ...*/
259 return (cstring_makeLiteral ("<undefined id>"));
264 /*@observer@*/ cstring
265 idDecl_observeId (idDecl d)
267 if (idDecl_isDefined (d))
273 return cstring_undefined;
278 idDecl_getTyp (idDecl d)
280 llassert (idDecl_isDefined (d));
286 idDecl_getCtype (idDecl d)
288 if (idDecl_isDefined (d))
290 return (qtype_getType (d->typ));
294 return ctype_unknown;
299 idDecl_getQuals (idDecl d)
301 if (idDecl_isDefined (d))
303 return (qtype_getQuals (d->typ));
307 return qualList_undefined;
312 idDecl_getClauses (idDecl d)
314 if (idDecl_isDefined (d))
320 return functionClauseList_undefined;
325 idDecl_addQual (idDecl d, qual q)
327 llassert (idDecl_isDefined (d));
329 (void) qtype_addQual (d->typ, q);
333 idDecl_setTyp (idDecl d, qtype c)
335 llassert (idDecl_isDefined (d));
342 idDecl_replaceCtype (/*@returned@*/ idDecl d, ctype c)
344 llassert (idDecl_isDefined (d));
346 DPRINTF (("Replace type: %s / %s", idDecl_unparse (d), ctype_unparse (c)));
347 qtype_setType (d->typ, c);
352 idDecl_fixBase (/*@returned@*/ idDecl t, qtype b)
354 llassert (idDecl_isDefined (t));
356 t->typ = qtype_newQbase (t->typ, b);
361 idDecl_fixParamBase (/*@returned@*/ idDecl t, qtype b)
366 llassert (idDecl_isDefined (t));
368 q = qtype_newQbase (t->typ, b);
369 c = qtype_getType (q);
372 ** For some reason, C adds an implicit pointer to function
373 ** parameters. It is "optional" syntax.
376 if (ctype_isFunction (c) && !ctype_isPointer (c))
378 qtype_setType (q, ctype_makePointer (c));
382 /* Splint thinks t->typ is kept. */
383 /*@-compmempass@*/ return t; /*@=compmempass@*/
387 idDecl_expectFunction (/*@returned@*/ idDecl d)
389 llassert (idDecl_isDefined (d));
391 qtype_setType (d->typ, ctype_expectFunction (qtype_getType (d->typ)));
396 ** evans 2002-02-09: This is a bit of a kludge, but we
397 ** need it to fix declarations like int (*p)[];
401 idDecl_notExpectingFunction (/*@returned@*/ idDecl d)
403 if (idDecl_isDefined (d))
405 ctype ct = qtype_getType (d->typ);
407 if (ctype_isExpFcn (ct))
409 qtype_setType (d->typ, ctype_dontExpectFunction (ct));
415 idDecl_addClauses (idDecl d, functionClauseList clauses)
417 llassert (idDecl_isDefined (d));
418 llassert (functionClauseList_isUndefined (d->clauses));
419 d->clauses = clauses;