]> andersk Git - splint.git/blame - src/qtype.c
Fixed problem with resetting null state after error for constants.
[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**
155af98d 20** For information on splint: info@splint.org
21** To report a bug: splint-bug@splint.org
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
1b8ae690 31# include "splintMacros.nf"
616915dd 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{
02b84d4b 125 DPRINTF (("Merge alt: %s + %s", qtype_unparse (q1), qtype_unparse (q2)));
126
616915dd 127 if (qtype_isDefined (q1) && qtype_isDefined (q2))
128 {
129 if (context_getFlag (FLG_IMPCONJ))
130 {
131 q1->type = ctype_makeConj (q1->type, q2->type);
132 }
133 else
134 {
135 q1->type = ctype_makeExplicitConj (q1->type, q2->type);
136 }
616915dd 137
138 if (!qualList_isEmpty (q2->quals))
139 {
140 checkAltQuals (q2);
141 }
142 }
143
144 qtype_free (q2);
145 return q1;
146}
147
148qtype qtype_combine (/*@returned@*/ qtype q1, ctype ct)
149{
150 if (qtype_isDefined (q1))
151 {
152 /* ct is modifier (or q1->type is unknown) */
153 q1->type = ctype_combine (q1->type, ct);
154 }
155
156 return q1;
157}
158
159qtype qtype_resolve (/*@returned@*/ qtype q)
160{
161 if (qtype_isDefined (q))
162 {
163 q->type = ctype_resolve (q->type);
164 }
165
166 return q;
167}
168
169cstring qtype_unparse (qtype q)
170{
171 if (qtype_isDefined (q))
172 {
173 return (message ("%q%s", qualList_unparse (q->quals),
174 ctype_unparse (q->type)));
175 }
176 else
177 {
178 return (cstring_makeLiteral ("<undefined>"));
179 }
180}
181
182qtype qtype_newBase (/*@returned@*/ qtype q, ctype ct)
183{
184 if (qtype_isDefined (q))
185 {
186 q->type = ctype_newBase (ct, q->type);
187 }
188
189 return q;
190}
191
192qtype qtype_newQbase (qtype q1, qtype q2)
193{
194 if (qtype_isDefined (q1) && qtype_isDefined (q2))
195 {
196 q1->type = ctype_newBase (q1->type, q2->type);
197 q1->quals = qualList_appendList (q1->quals, q2->quals);
198 }
199
200 return q1;
201}
202
203void qtype_adjustPointers (int n, qtype q)
204{
205 if (qtype_isDefined (q))
206 {
207 q->type = ctype_adjustPointers (n, q->type);
208 }
209}
210
211# ifndef NOLCL
212qtype qtype_copy (qtype q)
213{
214 if (qtype_isDefined (q))
215 {
216 qtype r = qtype_create (q->type);
217
218 qualList_free (r->quals);
219 r->quals = qualList_copy (q->quals);
220 return r;
221 }
222 else
223 {
224 return qtype_undefined;
225 }
226}
227# endif
This page took 0.104648 seconds and 5 git commands to generate.