Some consistency changes to library & headers flags.
[splint-patched.git] / src / qual.c
blobd8de411a9fc97e903326e3714096697df1221919
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 ** qual.c
27 ** representation of type qualifiers
30 # include "splintMacros.nf"
31 # include "basic.h"
33 static qual qual_createPlainAux (int i) /*@*/
35 qual res = (qual) dmalloc (sizeof (*res));
36 res->kind = (quenum) i;
37 res->info = annotationInfo_undefined;
39 sfreeEventually (res); /* stored in qtable */
40 return res;
43 static qual qtable[QU_LAST];
44 static bool isinit = FALSE;
46 extern void qual_initMod (void)
48 int i = (int) QU_UNKNOWN;
49 llassert (!isinit);
51 while (i < (int) QU_LAST) {
52 qtable[i] = qual_createPlainAux (i);
53 i++;
56 isinit = TRUE;
59 static void qual_free (qual p_q) ;
61 extern void qual_destroyMod (void)
63 if (isinit)
65 int i = (int) QU_UNKNOWN;
66 isinit = FALSE;
68 while (i < (int) QU_LAST) {
69 qual_free (qtable[i]);
70 i++;
75 static void qual_free (qual q)
77 llassert (!isinit);
78 sfree (q);
81 extern qual qual_createPlain (quenum q)
83 llassert (isinit);
84 llassert (q != QU_USERANNOT && q < QU_LAST);
85 return qtable[(int) q];
88 extern qual qual_createMetaState (annotationInfo info)
90 qual res;
92 res = (qual) dmalloc (sizeof (*res));
93 res->kind = QU_USERANNOT;
94 res->info = info;
96 sfreeEventually (res); /* Memory leak */
97 return res;
100 # ifdef DEADCODE
101 static bool quenum_isValid (int q)
103 return ((quenum) q >= QU_UNKNOWN
104 && ((quenum) q < QU_LAST));
107 qual qual_fromInt (int q)
109 llassertprint (quenum_isValid (q), ("Invalid qual: %d", q));
110 return (qual_createPlain ((quenum) q));
112 # endif /* DEADCODE */
114 cstring qual_unparse (qual q)
116 if (q->kind == QU_USERANNOT)
118 return (annotationInfo_unparse (q->info));
120 else
122 switch (q->kind)
124 case QU_UNKNOWN: return cstring_makeLiteralTemp ("unknown");
125 case QU_ABSTRACT: return cstring_makeLiteralTemp ("abstract");
126 case QU_NUMABSTRACT:return cstring_makeLiteralTemp ("numabstract");
127 case QU_CONCRETE: return cstring_makeLiteralTemp ("concrete");
128 case QU_MUTABLE: return cstring_makeLiteralTemp ("mutable");
129 case QU_IMMUTABLE: return cstring_makeLiteralTemp ("immutable");
130 case QU_SHORT: return cstring_makeLiteralTemp ("short");
131 case QU_LONG: return cstring_makeLiteralTemp ("long");
132 case QU_SIGNED: return cstring_makeLiteralTemp ("signed");
133 case QU_UNSIGNED: return cstring_makeLiteralTemp ("unsigned");
134 case QU_CONST: return cstring_makeLiteralTemp ("const");
135 case QU_RESTRICT: return cstring_makeLiteralTemp ("restrict");
136 case QU_VOLATILE: return cstring_makeLiteralTemp ("volatile");
137 case QU_INLINE: return cstring_makeLiteralTemp ("inline");
138 case QU_EXTERN: return cstring_makeLiteralTemp ("extern");
139 case QU_STATIC: return cstring_makeLiteralTemp ("static");
140 case QU_AUTO: return cstring_makeLiteralTemp ("auto");
141 case QU_REGISTER: return cstring_makeLiteralTemp ("register");
142 case QU_OUT: return cstring_makeLiteralTemp ("out");
143 case QU_IN: return cstring_makeLiteralTemp ("in");
144 case QU_RELDEF: return cstring_makeLiteralTemp ("reldef");
145 case QU_ONLY: return cstring_makeLiteralTemp ("only");
146 case QU_IMPONLY: return cstring_makeLiteralTemp ("only");
147 case QU_PARTIAL: return cstring_makeLiteralTemp ("partial");
148 case QU_SPECIAL: return cstring_makeLiteralTemp ("special");
149 case QU_KEEP: return cstring_makeLiteralTemp ("keep");
150 case QU_KEPT: return cstring_makeLiteralTemp ("kept");
151 case QU_YIELD: return cstring_makeLiteralTemp ("yield");
152 case QU_TEMP: return cstring_makeLiteralTemp ("temp");
153 case QU_SHARED: return cstring_makeLiteralTemp ("shared");
154 case QU_UNIQUE: return cstring_makeLiteralTemp ("unique");
155 case QU_UNCHECKED: return cstring_makeLiteralTemp ("unchecked");
156 case QU_CHECKED: return cstring_makeLiteralTemp ("checked");
157 case QU_CHECKMOD: return cstring_makeLiteralTemp ("checkmod");
158 case QU_CHECKEDSTRICT: return cstring_makeLiteralTemp ("checkedstrict");
159 case QU_TRUENULL: return cstring_makeLiteralTemp ("truenull");
160 case QU_FALSENULL: return cstring_makeLiteralTemp ("falsenull");
161 case QU_NULL: return cstring_makeLiteralTemp ("null");
162 case QU_ISNULL: return cstring_makeLiteralTemp ("isnull");
163 case QU_RELNULL: return cstring_makeLiteralTemp ("relnull");
164 case QU_NOTNULL: return cstring_makeLiteralTemp ("notnull");
165 case QU_NULLTERMINATED: return cstring_makeLiteralTemp ("nullterminated");
166 case QU_RETURNED: return cstring_makeLiteralTemp ("returned");
167 case QU_EXPOSED: return cstring_makeLiteralTemp ("exposed");
168 case QU_EXITS: return cstring_makeLiteralTemp ("noreturn");
169 case QU_MAYEXIT: return cstring_makeLiteralTemp ("maynotreturn");
170 case QU_UNUSED: return cstring_makeLiteralTemp ("unused");
171 case QU_EXTERNAL: return cstring_makeLiteralTemp ("external");
172 case QU_SEF: return cstring_makeLiteralTemp ("sef");
173 case QU_OBSERVER: return cstring_makeLiteralTemp ("observer");
174 case QU_REFCOUNTED: return cstring_makeLiteralTemp ("refcounted");
175 case QU_REFS: return cstring_makeLiteralTemp ("refs");
176 case QU_NEWREF: return cstring_makeLiteralTemp ("newref");
177 case QU_KILLREF: return cstring_makeLiteralTemp ("killref");
178 case QU_TEMPREF: return cstring_makeLiteralTemp ("tempref");
179 case QU_OWNED: return cstring_makeLiteralTemp ("owned");
180 case QU_DEPENDENT: return cstring_makeLiteralTemp ("dependent");
181 case QU_NEVEREXIT: return cstring_makeLiteralTemp ("alwaysreturns");
182 case QU_TRUEEXIT: return cstring_makeLiteralTemp ("noreturnwhentrue");
183 case QU_FALSEEXIT: return cstring_makeLiteralTemp ("noreturnwhenfalse");
184 case QU_UNDEF: return cstring_makeLiteralTemp ("undef");
185 case QU_KILLED: return cstring_makeLiteralTemp ("killed");
186 case QU_PRINTFLIKE: return cstring_makeLiteralTemp ("printflike");
187 case QU_SCANFLIKE: return cstring_makeLiteralTemp ("scanflike");
188 case QU_MESSAGELIKE:return cstring_makeLiteralTemp ("messagelike");
189 case QU_SETBUFFERSIZE: return cstring_makeLiteralTemp("<qsetbuffersize>");
190 case QU_LAST: return cstring_makeLiteralTemp ("< last >");
191 case QU_USERANNOT: return cstring_makeLiteralTemp ("<user>");
195 BADEXIT;
198 qual qual_abstractFromCodeChar (char c)
200 switch (c) {
201 case '-': return qual_createUnknown ();
202 case 'a': return qual_createAbstract ();
203 case 'n': return qual_createNumAbstract ();
204 case 'c': return qual_createConcrete ();
205 BADDEFAULT;
209 char qual_abstractCode (qual q)
211 switch (q->kind) {
212 case QU_UNKNOWN: return '-';
213 case QU_ABSTRACT: return 'a';
214 case QU_NUMABSTRACT: return 'n';
215 case QU_CONCRETE: return 'c';
216 BADDEFAULT;
220 extern bool qual_match (qual q1, qual q2)
222 if (q1->kind == q2->kind) {
223 if (q1->kind == QU_USERANNOT) {
224 return (annotationInfo_equal (q1->info, q2->info));
225 } else {
226 return TRUE;
230 return FALSE;
233 extern annotationInfo qual_getAnnotationInfo (qual q)
235 llassert (qual_isMetaState (q));
236 return q->info;
239 extern cstring qual_dump (qual q)
241 llassert (isinit);
243 if (q->kind == QU_USERANNOT)
245 return message ("%d.%s",
246 (int) q->kind,
247 annotationInfo_dump (q->info));
249 else
251 return message ("%d", (int) q->kind);
256 extern qual qual_undump (char **s)
258 quenum q = (quenum) reader_getInt (s);
259 llassert (isinit);
261 if (q == QU_USERANNOT)
263 annotationInfo ai;
265 reader_checkChar (s, '.');
266 ai = annotationInfo_undump (s);
268 return qual_createMetaState (ai);
270 else
272 return qual_createPlain (q);