]> andersk Git - splint.git/blame - src/qtype.c
Cleaned up flags to generate manual help.
[splint.git] / src / qtype.c
CommitLineData
616915dd 1/*
11db3170 2** Splint - annotation-assisted static program checker
77d37419 3** Copyright (C) 1994-2002 University of Virginia,
616915dd 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.
19**
20** For information on lclint: lclint-request@cs.virginia.edu
21** To report a bug: lclint-bug@cs.virginia.edu
11db3170 22** For more information: http://www.splint.org
616915dd 23*/
24/*
25** qtype.c
26**
27** Qualified types: a type qualifier list, and a ctype.
28** qtypes are mutable
29*/
30
31# include "lclintMacros.nf"
32# include "basic.h"
33
34/*@notnull@*/ qtype qtype_create (ctype c)
35{
36 qtype q = (qtype) dmalloc (sizeof (*q));
37
38 q->type = c;
39 q->quals = qualList_new ();
40 return q;
41}
42
43void qtype_free (/*@only@*/ qtype q)
44{
45 if (qtype_isDefined (q))
46 {
47 qualList_free (q->quals);
48 sfree (q);
49 }
50}
51
52qtype qtype_unknown ()
53{
54 return (qtype_create (ctype_unknown));
55}
56
57qtype qtype_addQual (qtype qt, qual q)
58{
59 if (qtype_isDefined (qt))
60 {
61 qt->quals = qualList_add (qt->quals, q);
62 }
63
64 return qt;
65}
66
67# ifndef NOLCL
68qtype qtype_addQualList (/*@returned@*/ qtype qt, qualList ql)
69{
70 if (qtype_isDefined (qt))
71 {
72 qt->quals = qualList_appendList (qt->quals, ql);
73 }
74
75 return qt;
76}
77# endif
78
79static void checkAltQuals (qtype q)
80{
81 if (qtype_isDefined (q))
82 {
83 qualList badQuals = qualList_undefined;
84
85 qualList_elements (q->quals, qu)
86 {
87 if (!qual_isCQual (qu) && !qual_isImplied (qu))
88 {
89 badQuals = qualList_add (badQuals, qu);
90 }
91 } end_qualList_elements ;
92
93 if (!qualList_isEmpty (badQuals))
94 {
95 voptgenerror (FLG_SYNTAX,
96 message
97 ("Alternate type cannot use annotations %q: %q",
98 qualList_unparse (badQuals),
99 qtype_unparse (q)),
100 g_currentloc);
101 }
102 }
103}
104
105# ifndef NOLCL
106qtype qtype_mergeImplicitAlt (/*@returned@*/ qtype q1, /*@only@*/ qtype q2)
107{
108 if (qtype_isDefined (q1) && qtype_isDefined (q2))
109 {
110 q1->type = ctype_makeConj (q1->type, q2->type);
111
112 if (!qualList_isEmpty (q2->quals))
113 {
114 checkAltQuals (q2);
115 }
116 }
117
118 qtype_free (q2);
119 return q1;
120}
121# endif
122
123qtype qtype_mergeAlt (/*@returned@*/ qtype q1, /*@only@*/ qtype q2)
124{
125 if (qtype_isDefined (q1) && qtype_isDefined (q2))
126 {
127 if (context_getFlag (FLG_IMPCONJ))
128 {
129 q1->type = ctype_makeConj (q1->type, q2->type);
130 }
131 else
132 {
133 q1->type = ctype_makeExplicitConj (q1->type, q2->type);
134 }
135
136
137 if (!qualList_isEmpty (q2->quals))
138 {
139 checkAltQuals (q2);
140 }
141 }
142
143 qtype_free (q2);
144 return q1;
145}
146
147qtype qtype_combine (/*@returned@*/ qtype q1, ctype ct)
148{
149 if (qtype_isDefined (q1))
150 {
151 /* ct is modifier (or q1->type is unknown) */
152 q1->type = ctype_combine (q1->type, ct);
153 }
154
155 return q1;
156}
157
158qtype qtype_resolve (/*@returned@*/ qtype q)
159{
160 if (qtype_isDefined (q))
161 {
162 q->type = ctype_resolve (q->type);
163 }
164
165 return q;
166}
167
168cstring qtype_unparse (qtype q)
169{
170 if (qtype_isDefined (q))
171 {
172 return (message ("%q%s", qualList_unparse (q->quals),
173 ctype_unparse (q->type)));
174 }
175 else
176 {
177 return (cstring_makeLiteral ("<undefined>"));
178 }
179}
180
181qtype qtype_newBase (/*@returned@*/ qtype q, ctype ct)
182{
183 if (qtype_isDefined (q))
184 {
185 q->type = ctype_newBase (ct, q->type);
186 }
187
188 return q;
189}
190
191qtype qtype_newQbase (qtype q1, qtype q2)
192{
193 if (qtype_isDefined (q1) && qtype_isDefined (q2))
194 {
195 q1->type = ctype_newBase (q1->type, q2->type);
196 q1->quals = qualList_appendList (q1->quals, q2->quals);
197 }
198
199 return q1;
200}
201
202void qtype_adjustPointers (int n, qtype q)
203{
204 if (qtype_isDefined (q))
205 {
206 q->type = ctype_adjustPointers (n, q->type);
207 }
208}
209
210# ifndef NOLCL
211qtype qtype_copy (qtype q)
212{
213 if (qtype_isDefined (q))
214 {
215 qtype r = qtype_create (q->type);
216
217 qualList_free (r->quals);
218 r->quals = qualList_copy (q->quals);
219 return r;
220 }
221 else
222 {
223 return qtype_undefined;
224 }
225}
226# endif
This page took 0.075234 seconds and 5 git commands to generate.