]>
Commit | Line | Data |
---|---|---|
28bf4b0b | 1 | /* |
2 | ** LCLint - annotation-assisted static program checker | |
3 | ** Copyright (C) 1994-2001 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. | |
19 | ** | |
20 | ** For information on lclint: lclint-request@cs.virginia.edu | |
21 | ** To report a bug: lclint-bug@cs.virginia.edu | |
22 | ** For more information: http://lclint.cs.virginia.edu | |
23 | */ | |
24 | /* | |
25 | ** mtDeclarationPiece.c | |
26 | */ | |
27 | ||
28 | # include "lclintMacros.nf" | |
29 | # include "basic.h" | |
30 | # include "mtgrammar.h" | |
31 | ||
32 | static mtDeclarationPiece | |
33 | mtDeclarationPiece_create (mtPieceKind kind, /*@null@*/ /*@only@*/ void *node) | |
34 | { | |
35 | mtDeclarationPiece res = (mtDeclarationPiece) dmalloc (sizeof (*res)); | |
36 | ||
37 | res->kind = kind; | |
38 | res->node = node; | |
39 | ||
40 | /*@i32@*/ return res; | |
41 | } | |
42 | ||
43 | extern mtDeclarationPiece mtDeclarationPiece_createContext (mtContextNode node) /*@*/ | |
44 | { | |
45 | return mtDeclarationPiece_create (MTP_CONTEXT, (void *) node); | |
46 | } | |
47 | ||
48 | extern mtDeclarationPiece mtDeclarationPiece_createValues (mtValuesNode node) /*@*/ | |
49 | { | |
50 | return mtDeclarationPiece_create (MTP_VALUES, (void *) node); | |
51 | } | |
52 | ||
53 | extern mtDeclarationPiece mtDeclarationPiece_createDefaults (mtDefaultsNode node) /*@*/ | |
54 | { | |
55 | return mtDeclarationPiece_create (MTP_DEFAULTS, (void *) node); | |
56 | } | |
57 | ||
58 | extern mtDeclarationPiece mtDeclarationPiece_createValueDefault (mttok node) /*@*/ | |
59 | { | |
60 | llassert (mttok_isIdentifier (node)); | |
61 | return mtDeclarationPiece_create (MTP_DEFAULTVALUE, (void *) node); | |
62 | } | |
63 | ||
64 | extern mtDeclarationPiece mtDeclarationPiece_createAnnotations (mtAnnotationsNode node) /*@*/ | |
65 | { | |
66 | return mtDeclarationPiece_create (MTP_ANNOTATIONS, (void *) node); | |
67 | } | |
68 | ||
69 | extern mtDeclarationPiece mtDeclarationPiece_createMerge (mtMergeNode node) /*@*/ | |
70 | { | |
71 | return mtDeclarationPiece_create (MTP_MERGE, (void *) node); | |
72 | } | |
73 | ||
74 | extern mtDeclarationPiece mtDeclarationPiece_createTransfers (mtTransferClauseList node) /*@*/ | |
75 | { | |
76 | return mtDeclarationPiece_create (MTP_TRANSFERS, (void *) node); | |
77 | } | |
78 | ||
79 | extern mtDeclarationPiece mtDeclarationPiece_createPreconditions (mtTransferClauseList node) /*@*/ | |
80 | { | |
81 | return mtDeclarationPiece_create (MTP_PRECONDITIONS, (void *) node); | |
82 | } | |
83 | ||
84 | mtDeclarationPiece mtDeclarationPiece_createPostconditions (mtTransferClauseList node) /*@*/ | |
85 | { | |
86 | return mtDeclarationPiece_create (MTP_POSTCONDITIONS, (void *) node); | |
87 | } | |
88 | ||
89 | mtDeclarationPiece mtDeclarationPiece_createLosers (mtLoseReferenceList node) /*@*/ | |
90 | { | |
91 | return mtDeclarationPiece_create (MTP_LOSERS, (void *) node); | |
92 | } | |
93 | ||
94 | /*@only@*/ cstring mtDeclarationPiece_unparse (mtDeclarationPiece p) | |
95 | { | |
96 | if (mtDeclarationPiece_isUndefined (p)) | |
97 | { | |
98 | return cstring_undefined; | |
99 | } | |
100 | ||
101 | switch (p->kind) | |
102 | { | |
103 | case MTP_CONTEXT: | |
104 | /*@access mtContextNode@*/ | |
105 | return mtContextNode_unparse ((mtContextNode) p->node); | |
106 | /*@noaccess mtContextNode@*/ | |
107 | case MTP_VALUES: | |
108 | /*@access mtValuesNode@*/ | |
109 | return mtValuesNode_unparse ((mtValuesNode) p->node); | |
110 | /*@noaccess mtValuesNode@*/ | |
111 | case MTP_DEFAULTS: | |
112 | /*@access mtDefaultsNode@*/ | |
113 | return mtDefaultsNode_unparse ((mtDefaultsNode) p->node); | |
114 | /*@noaccess mtDefaultsNode@*/ | |
115 | case MTP_DEFAULTVALUE: | |
116 | /*@access mttok@*/ | |
117 | return message ("default %q", mttok_getText ((mttok) p->node)); | |
118 | /*@noaccess mttok@*/ | |
119 | case MTP_ANNOTATIONS: | |
120 | /*@access mtAnnotationsNode@*/ | |
121 | return mtAnnotationsNode_unparse ((mtAnnotationsNode) p->node); | |
122 | /*@noaccess mtAnnotationsNode@*/ | |
123 | case MTP_MERGE: | |
124 | /*@access mtMergeNode@*/ | |
125 | return mtMergeNode_unparse ((mtMergeNode) p->node); | |
126 | /*@noaccess mtMergeNode@*/ | |
127 | case MTP_TRANSFERS: | |
128 | case MTP_PRECONDITIONS: | |
129 | case MTP_POSTCONDITIONS: | |
130 | /*@access mtTransferClauseList@*/ | |
131 | return mtTransferClauseList_unparse ((mtTransferClauseList) p->node); | |
132 | /*@noaccess mtTransferClauseList@*/ | |
133 | case MTP_LOSERS: | |
134 | /*@access mtLoseReferenceList@*/ | |
135 | return mtLoseReferenceList_unparse ((mtLoseReferenceList) p->node); | |
136 | /*@noaccess mtLoseReferenceList@*/ | |
137 | case MTP_DEAD: | |
138 | return cstring_makeLiteral ("Dead Piece"); | |
139 | } | |
140 | ||
141 | BADBRANCH; | |
142 | } | |
143 | ||
144 | extern bool mtDeclarationPiece_matchKind (mtDeclarationPiece p, mtPieceKind kind) /*@*/ | |
145 | { | |
146 | if (mtDeclarationPiece_isDefined (p)) | |
147 | { | |
148 | return (p->kind == kind); | |
149 | } | |
150 | else | |
151 | { | |
152 | return FALSE; | |
153 | } | |
154 | } | |
155 | ||
156 | extern mtContextNode mtDeclarationPiece_getContext (mtDeclarationPiece node) | |
157 | { | |
158 | llassert (mtDeclarationPiece_isDefined (node)); | |
159 | llassert (node->kind == MTP_CONTEXT); | |
160 | ||
161 | /*@-abstract@*/ | |
162 | return (mtContextNode) node->node; | |
163 | /*@=abstract@*/ | |
164 | } | |
165 | ||
166 | extern mtContextNode mtDeclarationPiece_stealContext (mtDeclarationPiece node) | |
167 | { | |
168 | mtContextNode res; | |
169 | ||
170 | llassert (mtDeclarationPiece_isDefined (node)); | |
171 | llassert (node->kind == MTP_CONTEXT); | |
172 | ||
173 | /*@-abstract@*/ | |
174 | res = (mtContextNode) node->node; | |
175 | /*@=abstract@*/ | |
176 | node->kind = MTP_DEAD; | |
177 | node->node = NULL; | |
178 | return res; | |
179 | } | |
180 | ||
181 | extern mtDefaultsNode mtDeclarationPiece_getDefaults (mtDeclarationPiece node) | |
182 | { | |
183 | llassert (mtDeclarationPiece_isDefined (node)); | |
184 | llassert (node->kind == MTP_DEFAULTS); | |
185 | ||
186 | /*@-abstract@*/ | |
187 | return (mtDefaultsNode) node->node; | |
188 | /*@=abstract@*/ | |
189 | } | |
190 | ||
191 | extern cstring mtDeclarationPiece_getDefaultValue (mtDeclarationPiece node) | |
192 | { | |
193 | llassert (mtDeclarationPiece_isDefined (node)); | |
194 | llassert (node->kind == MTP_DEFAULTVALUE); | |
195 | ||
196 | /*@-abstract@*/ | |
197 | return mttok_observeText ((mttok) node->node); | |
198 | /*@=abstract@*/ | |
199 | } | |
200 | ||
201 | extern mtAnnotationsNode mtDeclarationPiece_getAnnotations (mtDeclarationPiece node) | |
202 | { | |
203 | llassert (mtDeclarationPiece_isDefined (node)); | |
204 | llassert (node->kind == MTP_ANNOTATIONS); | |
205 | ||
206 | /*@-abstract@*/ | |
207 | return (mtAnnotationsNode) node->node; | |
208 | /*@=abstract@*/ | |
209 | } | |
210 | ||
211 | extern mtMergeNode mtDeclarationPiece_getMerge (mtDeclarationPiece node) | |
212 | { | |
213 | llassert (mtDeclarationPiece_isDefined (node)); | |
214 | llassert (node->kind == MTP_MERGE); | |
215 | ||
216 | /*@-abstract@*/ | |
217 | return (mtMergeNode) node->node; | |
218 | /*@=abstract@*/ | |
219 | } | |
220 | ||
221 | extern mtTransferClauseList mtDeclarationPiece_getTransfers (mtDeclarationPiece node) | |
222 | { | |
223 | llassert (mtDeclarationPiece_isDefined (node)); | |
224 | llassert (node->kind == MTP_TRANSFERS); | |
225 | ||
226 | /*@-abstract@*/ | |
227 | return (mtTransferClauseList) node->node; | |
228 | /*@=abstract@*/ | |
229 | } | |
230 | ||
231 | extern mtTransferClauseList mtDeclarationPiece_getPreconditions (mtDeclarationPiece node) | |
232 | { | |
233 | llassert (mtDeclarationPiece_isDefined (node)); | |
234 | llassert (node->kind == MTP_PRECONDITIONS); | |
235 | ||
236 | /*@-abstract@*/ | |
237 | return (mtTransferClauseList) node->node; | |
238 | /*@=abstract@*/ | |
239 | } | |
240 | ||
241 | extern mtTransferClauseList mtDeclarationPiece_getPostconditions (mtDeclarationPiece node) | |
242 | { | |
243 | llassert (mtDeclarationPiece_isDefined (node)); | |
244 | llassert (node->kind == MTP_POSTCONDITIONS); | |
245 | ||
246 | /*@-abstract@*/ | |
247 | return (mtTransferClauseList) node->node; | |
248 | /*@=abstract@*/ | |
249 | } | |
250 | ||
251 | extern mtLoseReferenceList mtDeclarationPiece_getLosers (mtDeclarationPiece node) | |
252 | { | |
253 | llassert (mtDeclarationPiece_isDefined (node)); | |
254 | llassert (node->kind == MTP_LOSERS); | |
255 | ||
256 | /*@-abstract@*/ | |
257 | return (mtLoseReferenceList) node->node; | |
258 | /*@=abstract@*/ | |
259 | } | |
260 | ||
261 | extern mtValuesNode mtDeclarationPiece_getValues (mtDeclarationPiece node) | |
262 | { | |
263 | llassert (mtDeclarationPiece_isDefined (node)); | |
264 | llassert (node->kind == MTP_VALUES); | |
265 | ||
266 | /*@-abstract@*/ | |
267 | return (mtValuesNode) node->node; | |
268 | /*@=abstract@*/ | |
269 | } | |
270 | ||
271 | extern void mtDeclarationPiece_free (/*@only@*/ mtDeclarationPiece node) | |
272 | { | |
273 | if (node != NULL) | |
274 | { | |
275 | switch (node->kind) | |
276 | { | |
277 | case MTP_DEAD: | |
278 | llassert (node->node == NULL); | |
279 | break; | |
280 | ||
281 | case MTP_CONTEXT: | |
282 | /*@access mtContextNode@*/ | |
283 | mtContextNode_free ((mtContextNode) node->node); | |
284 | break; | |
285 | /*@noaccess mtContextNode@*/ | |
286 | case MTP_VALUES: | |
287 | /*@access mtValuesNode@*/ | |
288 | mtValuesNode_free ((mtValuesNode) node->node); | |
289 | break; | |
290 | /*@noaccess mtValuesNode@*/ | |
291 | case MTP_DEFAULTS: | |
292 | /*@access mtDefaultsNode@*/ | |
293 | mtDefaultsNode_free ((mtDefaultsNode) node->node); | |
294 | break; | |
295 | /*@noaccess mtDefaultsNode@*/ | |
296 | case MTP_DEFAULTVALUE: | |
297 | /*@access mttok@*/ | |
298 | mttok_free ((mttok) node->node); | |
299 | break; | |
300 | /*@noaccess mttok@*/ | |
301 | case MTP_ANNOTATIONS: | |
302 | /*@access mtAnnotationsNode@*/ | |
303 | mtAnnotationsNode_free ((mtAnnotationsNode) node->node); | |
304 | break; | |
305 | /*@noaccess mtAnnotationsNode@*/ | |
306 | case MTP_MERGE: | |
307 | /*@access mtMergeNode@*/ | |
308 | mtMergeNode_free ((mtMergeNode) node->node); | |
309 | break; | |
310 | /*@noaccess mtMergeNode@*/ | |
311 | case MTP_TRANSFERS: | |
312 | case MTP_PRECONDITIONS: | |
313 | case MTP_POSTCONDITIONS: | |
314 | /*@access mtTransferClauseList@*/ | |
315 | mtTransferClauseList_free ((mtTransferClauseList) node->node); | |
316 | break; | |
317 | /*@noaccess mtTransferClauseList@*/ | |
318 | case MTP_LOSERS: | |
319 | /*@access mtLoseReferenceList@*/ | |
320 | mtLoseReferenceList_free ((mtLoseReferenceList) node->node); | |
321 | break; | |
322 | /*@noaccess mtLoseReferenceList@*/ | |
323 | } | |
324 | ||
325 | sfree (node); | |
326 | } | |
327 | } |