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
27 ** Qualified types: a type qualifier list, and a ctype.
31 # include "splintMacros.nf"
34 /*@notnull@*/ qtype qtype_create (ctype c)
36 qtype q = (qtype) dmalloc (sizeof (*q));
39 q->quals = qualList_new ();
43 void qtype_free (/*@only@*/ qtype q)
45 if (qtype_isDefined (q))
47 qualList_free (q->quals);
52 qtype qtype_unknown ()
54 return (qtype_create (ctype_unknown));
57 qtype qtype_addQual (qtype qt, qual q)
59 DPRINTF (("Add qual: %s / %s", qtype_unparse (qt), qual_unparse (q)));
61 if (qtype_isDefined (qt))
63 qt->quals = qualList_add (qt->quals, q);
66 DPRINTF (("==> %s", qtype_unparse (qt)));
71 qtype qtype_addQualList (/*@returned@*/ qtype qt, qualList ql)
73 if (qtype_isDefined (qt))
75 qt->quals = qualList_appendList (qt->quals, ql);
82 static void checkAltQuals (qtype q)
84 if (qtype_isDefined (q))
86 qualList badQuals = qualList_undefined;
88 qualList_elements (q->quals, qu)
90 if (!qual_isCQual (qu) && !qual_isImplied (qu))
92 badQuals = qualList_add (badQuals, qu);
94 } end_qualList_elements ;
96 if (!qualList_isEmpty (badQuals))
98 voptgenerror (FLG_SYNTAX,
100 ("Alternate type cannot use annotations %q: %q",
101 qualList_unparse (badQuals),
109 qtype qtype_mergeImplicitAlt (/*@returned@*/ qtype q1, /*@only@*/ qtype q2)
111 if (qtype_isDefined (q1) && qtype_isDefined (q2))
113 q1->type = ctype_makeConj (q1->type, q2->type);
115 if (!qualList_isEmpty (q2->quals))
126 qtype qtype_mergeAlt (/*@returned@*/ qtype q1, /*@only@*/ qtype q2)
128 DPRINTF (("Merge alt: %s + %s", qtype_unparse (q1), qtype_unparse (q2)));
130 if (qtype_isDefined (q1) && qtype_isDefined (q2))
132 if (context_getFlag (FLG_IMPCONJ))
134 q1->type = ctype_makeConj (q1->type, q2->type);
138 q1->type = ctype_makeExplicitConj (q1->type, q2->type);
141 if (!qualList_isEmpty (q2->quals))
151 qtype qtype_combine (/*@returned@*/ qtype q1, ctype ct)
153 DPRINTF (("Combine: %s %s", qtype_unparse (q1), ctype_unparse (ct)));
154 if (qtype_isDefined (q1))
156 /* ct is modifier (or q1->type is unknown) */
157 q1->type = ctype_combine (q1->type, ct);
160 DPRINTF (("Combine: %s %s", qtype_unparse (q1), ctype_unparse (ct)));
164 qtype qtype_resolve (/*@returned@*/ qtype q)
166 if (qtype_isDefined (q))
168 DPRINTF (("Resolving: %s", qtype_unparse (q)));
169 q->type = ctype_resolve (q->type);
170 DPRINTF (("Resolving: %s", qtype_unparse (q)));
176 cstring qtype_unparse (qtype q)
178 if (qtype_isDefined (q))
180 return (message ("%q%s", qualList_unparse (q->quals),
181 ctype_unparse (q->type)));
185 return (cstring_makeLiteral ("<undefined>"));
189 qtype qtype_newBase (/*@returned@*/ qtype q, ctype ct)
191 if (qtype_isDefined (q))
193 DPRINTF (("new base: %s -> %s", qtype_unparse (q), ctype_unparse (ct)));
194 q->type = ctype_newBase (ct, q->type);
195 DPRINTF (("new base: %s -> %s", qtype_unparse (q), ctype_unparse (ct)));
201 qtype qtype_newQbase (qtype q1, qtype q2)
203 if (qtype_isDefined (q1) && qtype_isDefined (q2))
205 q1->type = ctype_newBase (q1->type, q2->type);
206 q1->quals = qualList_appendList (q1->quals, q2->quals);
209 DPRINTF (("new base: %s -> %s", qtype_unparse (q1), qtype_unparse (q1)));
213 void qtype_adjustPointers (int n, qtype q)
215 if (qtype_isDefined (q))
217 q->type = ctype_adjustPointers (n, q->type);
222 qtype qtype_copy (qtype q)
224 if (qtype_isDefined (q))
226 qtype r = qtype_create (q->type);
228 qualList_free (r->quals);
229 r->quals = qualList_copy (q->quals);
234 return qtype_undefined;