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