]>
Commit | Line | Data |
---|---|---|
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 | ** idDecl.c | |
26 | */ | |
27 | ||
1b8ae690 | 28 | # include "splintMacros.nf" |
616915dd | 29 | # include "basic.h" |
30 | ||
31 | /*@only@*/ idDecl | |
28bf4b0b | 32 | idDecl_createClauses (/*@only@*/ cstring s, /*@only@*/ qtype t, /*@only@*/ functionClauseList clauses) |
616915dd | 33 | { |
34 | idDecl d = (idDecl) dmalloc (sizeof (*d)); | |
35 | ||
36 | d->id = s; | |
37 | d->typ = t; | |
28bf4b0b | 38 | d->clauses = clauses; |
616915dd | 39 | |
40 | return (d); | |
41 | } | |
42 | ||
28bf4b0b | 43 | /*@only@*/ idDecl |
44 | idDecl_create (/*@only@*/ cstring s, /*@only@*/ qtype t) | |
45 | { | |
46 | return idDecl_createClauses (s, t, functionClauseList_undefined); | |
47 | } | |
48 | ||
616915dd | 49 | void |
50 | idDecl_free (idDecl t) | |
51 | { | |
52 | if (idDecl_isDefined (t)) | |
53 | { | |
bb7c2085 | 54 | /*@i523 functionClauseList_free (t->clauses); */ /* evans 2002-01-03: splint catches this now! */ |
616915dd | 55 | qtype_free (t->typ); |
bb7c2085 | 56 | cstring_free (t->id); |
57 | ||
58 | /*@-compdestroy@*/ sfree (t); /*@=compdestroy@*/ | |
616915dd | 59 | } |
60 | } | |
61 | ||
62 | cstring | |
63 | idDecl_unparse (idDecl d) | |
64 | { | |
65 | if (idDecl_isDefined (d)) | |
66 | { | |
28bf4b0b | 67 | if (functionClauseList_isDefined (d->clauses)) |
68 | { | |
69 | return (message ("%s : %q / %q", d->id, qtype_unparse (d->typ), | |
70 | functionClauseList_unparse (d->clauses))); | |
71 | } | |
72 | else | |
73 | { | |
74 | return (message ("%s : %q", d->id, qtype_unparse (d->typ))); | |
75 | } | |
76 | } | |
77 | else | |
78 | { | |
79 | return (cstring_makeLiteral ("<undefined id>")); | |
80 | } | |
81 | } | |
82 | ||
83 | cstring | |
84 | idDecl_unparseC (idDecl d) | |
85 | { | |
86 | if (idDecl_isDefined (d)) | |
87 | { | |
88 | return (message ("%q %s", qtype_unparse (d->typ), d->id)); | |
616915dd | 89 | } |
90 | else | |
91 | { | |
92 | return (cstring_makeLiteral ("<undefined id>")); | |
93 | } | |
94 | } | |
95 | ||
96 | /*@observer@*/ cstring | |
97 | idDecl_observeId (idDecl d) | |
98 | { | |
99 | if (idDecl_isDefined (d)) | |
100 | { | |
101 | return (d->id); | |
102 | } | |
103 | else | |
104 | { | |
105 | return cstring_undefined; | |
106 | } | |
107 | } | |
108 | ||
109 | qtype | |
110 | idDecl_getTyp (idDecl d) | |
111 | { | |
112 | llassert (idDecl_isDefined (d)); | |
113 | ||
114 | return d->typ; | |
115 | } | |
116 | ||
117 | ctype | |
118 | idDecl_getCtype (idDecl d) | |
119 | { | |
120 | if (idDecl_isDefined (d)) | |
121 | { | |
122 | return (qtype_getType (d->typ)); | |
123 | } | |
124 | else | |
125 | { | |
126 | return ctype_unknown; | |
127 | } | |
128 | } | |
129 | ||
130 | qualList | |
131 | idDecl_getQuals (idDecl d) | |
132 | { | |
133 | if (idDecl_isDefined (d)) | |
134 | { | |
135 | return (qtype_getQuals (d->typ)); | |
136 | } | |
137 | else | |
138 | { | |
139 | return qualList_undefined; | |
140 | } | |
141 | } | |
142 | ||
28bf4b0b | 143 | functionClauseList |
144 | idDecl_getClauses (idDecl d) | |
145 | { | |
146 | if (idDecl_isDefined (d)) | |
147 | { | |
148 | return (d->clauses); | |
149 | } | |
150 | else | |
151 | { | |
152 | return functionClauseList_undefined; | |
153 | } | |
154 | } | |
155 | ||
616915dd | 156 | void |
157 | idDecl_addQual (idDecl d, qual q) | |
158 | { | |
159 | llassert (idDecl_isDefined (d)); | |
160 | ||
161 | (void) qtype_addQual (d->typ, q); | |
162 | } | |
163 | ||
164 | void | |
165 | idDecl_setTyp (idDecl d, qtype c) | |
166 | { | |
167 | llassert (idDecl_isDefined (d)); | |
168 | ||
169 | qtype_free (d->typ); | |
170 | d->typ = c; | |
171 | } | |
172 | ||
173 | idDecl | |
174 | idDecl_replaceCtype (/*@returned@*/ idDecl d, ctype c) | |
175 | { | |
176 | llassert (idDecl_isDefined (d)); | |
177 | ||
178 | qtype_setType (d->typ, c); | |
179 | return d; | |
180 | } | |
181 | ||
182 | idDecl | |
183 | idDecl_fixBase (/*@returned@*/ idDecl t, qtype b) | |
184 | { | |
185 | llassert (idDecl_isDefined (t)); | |
186 | ||
187 | t->typ = qtype_newQbase (t->typ, b); | |
188 | return t; | |
189 | } | |
190 | ||
191 | idDecl | |
192 | idDecl_fixParamBase (/*@returned@*/ idDecl t, qtype b) | |
193 | { | |
194 | qtype q; | |
195 | ctype c; | |
196 | ||
197 | llassert (idDecl_isDefined (t)); | |
198 | ||
199 | q = qtype_newQbase (t->typ, b); | |
200 | c = qtype_getType (q); | |
201 | ||
202 | /* | |
203 | ** For some reason, C adds an implicit pointer to function | |
204 | ** parameters. It is "optional" syntax. | |
205 | */ | |
206 | ||
207 | if (ctype_isFunction (c) && !ctype_isPointer (c)) | |
208 | { | |
209 | qtype_setType (q, ctype_makePointer (c)); | |
210 | } | |
211 | ||
212 | t->typ = q; | |
11db3170 | 213 | /* Splint thinks t->typ is kept. */ |
616915dd | 214 | /*@-compmempass@*/ return t; /*@=compmempass@*/ |
215 | } | |
216 | ||
217 | idDecl | |
218 | idDecl_expectFunction (/*@returned@*/ idDecl d) | |
219 | { | |
220 | llassert (idDecl_isDefined (d)); | |
221 | ||
222 | qtype_setType (d->typ, ctype_expectFunction (qtype_getType (d->typ))); | |
223 | return d; | |
224 | } | |
28bf4b0b | 225 | |
226 | void | |
227 | idDecl_addClauses (idDecl d, functionClauseList clauses) | |
228 | { | |
229 | llassert (idDecl_isDefined (d)); | |
230 | llassert (functionClauseList_isUndefined (d->clauses)); | |
231 | d->clauses = clauses; | |
232 | } |