Some consistency changes to library & headers flags.
[splint-patched.git] / src / mtDeclarationPiece.c
blobd617c9d1327248820fa8608e184d387ea1753c2b
1 /*
2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
25 ** mtDeclarationPiece.c
28 # include "splintMacros.nf"
29 # include "basic.h"
31 static mtDeclarationPiece
32 mtDeclarationPiece_create (mtPieceKind kind, /*@null@*/ /*@only@*/ void *node)
34 mtDeclarationPiece res = (mtDeclarationPiece) dmalloc (sizeof (*res));
36 res->kind = kind;
37 res->node = node;
39 return res;
42 extern mtDeclarationPiece mtDeclarationPiece_createContext (mtContextNode node) /*@*/
44 return mtDeclarationPiece_create (MTP_CONTEXT, (void *) node);
47 extern mtDeclarationPiece mtDeclarationPiece_createValues (mtValuesNode node) /*@*/
49 return mtDeclarationPiece_create (MTP_VALUES, (void *) node);
52 extern mtDeclarationPiece mtDeclarationPiece_createDefaults (mtDefaultsNode node) /*@*/
54 return mtDeclarationPiece_create (MTP_DEFAULTS, (void *) node);
57 extern mtDeclarationPiece mtDeclarationPiece_createValueDefault (mttok node) /*@*/
59 llassert (mttok_isIdentifier (node));
60 return mtDeclarationPiece_create (MTP_DEFAULTVALUE, (void *) node);
63 extern mtDeclarationPiece mtDeclarationPiece_createAnnotations (mtAnnotationsNode node) /*@*/
65 return mtDeclarationPiece_create (MTP_ANNOTATIONS, (void *) node);
68 extern mtDeclarationPiece mtDeclarationPiece_createMerge (mtMergeNode node) /*@*/
70 return mtDeclarationPiece_create (MTP_MERGE, (void *) node);
73 extern mtDeclarationPiece mtDeclarationPiece_createTransfers (mtTransferClauseList node) /*@*/
75 return mtDeclarationPiece_create (MTP_TRANSFERS, (void *) node);
78 extern mtDeclarationPiece mtDeclarationPiece_createPreconditions (mtTransferClauseList node) /*@*/
80 return mtDeclarationPiece_create (MTP_PRECONDITIONS, (void *) node);
83 mtDeclarationPiece mtDeclarationPiece_createPostconditions (mtTransferClauseList node) /*@*/
85 return mtDeclarationPiece_create (MTP_POSTCONDITIONS, (void *) node);
88 mtDeclarationPiece mtDeclarationPiece_createLosers (mtLoseReferenceList node) /*@*/
90 return mtDeclarationPiece_create (MTP_LOSERS, (void *) node);
93 /*@only@*/ cstring mtDeclarationPiece_unparse (mtDeclarationPiece p)
95 if (mtDeclarationPiece_isUndefined (p))
97 return cstring_undefined;
100 switch (p->kind)
102 case MTP_CONTEXT:
103 /*@access mtContextNode@*/
104 return mtContextNode_unparse ((mtContextNode) p->node);
105 /*@noaccess mtContextNode@*/
106 case MTP_VALUES:
107 /*@access mtValuesNode@*/
108 return mtValuesNode_unparse ((mtValuesNode) p->node);
109 /*@noaccess mtValuesNode@*/
110 case MTP_DEFAULTS:
111 /*@access mtDefaultsNode@*/
112 return mtDefaultsNode_unparse ((mtDefaultsNode) p->node);
113 /*@noaccess mtDefaultsNode@*/
114 case MTP_DEFAULTVALUE:
115 /*@access mttok@*/
116 return message ("default %q", mttok_getText ((mttok) p->node));
117 /*@noaccess mttok@*/
118 case MTP_ANNOTATIONS:
119 /*@access mtAnnotationsNode@*/
120 return mtAnnotationsNode_unparse ((mtAnnotationsNode) p->node);
121 /*@noaccess mtAnnotationsNode@*/
122 case MTP_MERGE:
123 /*@access mtMergeNode@*/
124 return mtMergeNode_unparse ((mtMergeNode) p->node);
125 /*@noaccess mtMergeNode@*/
126 case MTP_TRANSFERS:
127 case MTP_PRECONDITIONS:
128 case MTP_POSTCONDITIONS:
129 /*@access mtTransferClauseList@*/
130 return mtTransferClauseList_unparse ((mtTransferClauseList) p->node);
131 /*@noaccess mtTransferClauseList@*/
132 case MTP_LOSERS:
133 /*@access mtLoseReferenceList@*/
134 return mtLoseReferenceList_unparse ((mtLoseReferenceList) p->node);
135 /*@noaccess mtLoseReferenceList@*/
136 case MTP_DEAD:
137 return cstring_makeLiteral ("Dead Piece");
140 BADBRANCHRET (cstring_undefined);
143 extern bool mtDeclarationPiece_matchKind (mtDeclarationPiece p, mtPieceKind kind) /*@*/
145 if (mtDeclarationPiece_isDefined (p))
147 return (p->kind == kind);
149 else
151 return FALSE;
155 # ifdef DEADCODE
156 extern mtContextNode mtDeclarationPiece_getContext (mtDeclarationPiece node)
158 llassert (mtDeclarationPiece_isDefined (node));
159 llassert (node->kind == MTP_CONTEXT);
161 /*@-abstract@*/
162 return (mtContextNode) node->node;
163 /*@=abstract@*/
165 # endif /* DEADCODE */
167 extern mtContextNode mtDeclarationPiece_stealContext (mtDeclarationPiece node)
169 mtContextNode res;
171 llassert (mtDeclarationPiece_isDefined (node));
172 llassert (node->kind == MTP_CONTEXT);
174 /*@-abstract@*/
175 res = (mtContextNode) node->node;
176 /*@=abstract@*/
177 node->kind = MTP_DEAD;
178 node->node = NULL;
179 return res;
182 extern mtDefaultsNode mtDeclarationPiece_getDefaults (mtDeclarationPiece node)
184 llassert (mtDeclarationPiece_isDefined (node));
185 llassert (node->kind == MTP_DEFAULTS);
187 /*@-abstract@*/
188 return (mtDefaultsNode) node->node;
189 /*@=abstract@*/
192 extern cstring mtDeclarationPiece_getDefaultValue (mtDeclarationPiece node)
194 llassert (mtDeclarationPiece_isDefined (node));
195 llassert (node->kind == MTP_DEFAULTVALUE);
197 /*@-abstract@*/
198 return mttok_observeText ((mttok) node->node);
199 /*@=abstract@*/
202 extern mtAnnotationsNode mtDeclarationPiece_getAnnotations (mtDeclarationPiece node)
204 llassert (mtDeclarationPiece_isDefined (node));
205 llassert (node->kind == MTP_ANNOTATIONS);
207 /*@-abstract@*/
208 return (mtAnnotationsNode) node->node;
209 /*@=abstract@*/
212 extern mtMergeNode mtDeclarationPiece_getMerge (mtDeclarationPiece node)
214 llassert (mtDeclarationPiece_isDefined (node));
215 llassert (node->kind == MTP_MERGE);
217 /*@-abstract@*/
218 return (mtMergeNode) node->node;
219 /*@=abstract@*/
222 extern mtTransferClauseList mtDeclarationPiece_getTransfers (mtDeclarationPiece node)
224 llassert (mtDeclarationPiece_isDefined (node));
225 llassert (node->kind == MTP_TRANSFERS);
227 /*@-abstract@*/
228 return (mtTransferClauseList) node->node;
229 /*@=abstract@*/
232 extern mtTransferClauseList mtDeclarationPiece_getPreconditions (mtDeclarationPiece node)
234 llassert (mtDeclarationPiece_isDefined (node));
235 llassert (node->kind == MTP_PRECONDITIONS);
237 /*@-abstract@*/
238 return (mtTransferClauseList) node->node;
239 /*@=abstract@*/
242 # ifdef DEADCODE
243 extern mtTransferClauseList mtDeclarationPiece_getPostconditions (mtDeclarationPiece node)
245 llassert (mtDeclarationPiece_isDefined (node));
246 llassert (node->kind == MTP_POSTCONDITIONS);
248 /*@-abstract@*/
249 return (mtTransferClauseList) node->node;
250 /*@=abstract@*/
252 # endif /* DEADCODE */
254 extern mtLoseReferenceList mtDeclarationPiece_getLosers (mtDeclarationPiece node)
256 llassert (mtDeclarationPiece_isDefined (node));
257 llassert (node->kind == MTP_LOSERS);
259 /*@-abstract@*/
260 return (mtLoseReferenceList) node->node;
261 /*@=abstract@*/
264 extern mtValuesNode mtDeclarationPiece_getValues (mtDeclarationPiece node)
266 llassert (mtDeclarationPiece_isDefined (node));
267 llassert (node->kind == MTP_VALUES);
269 /*@-abstract@*/
270 return (mtValuesNode) node->node;
271 /*@=abstract@*/
274 extern void mtDeclarationPiece_free (/*@only@*/ mtDeclarationPiece node)
276 if (node != NULL)
278 switch (node->kind)
280 case MTP_DEAD:
281 llassert (node->node == NULL);
282 break;
284 case MTP_CONTEXT:
285 /*@access mtContextNode@*/
286 mtContextNode_free ((mtContextNode) node->node);
287 break;
288 /*@noaccess mtContextNode@*/
289 case MTP_VALUES:
290 /*@access mtValuesNode@*/
291 mtValuesNode_free ((mtValuesNode) node->node);
292 break;
293 /*@noaccess mtValuesNode@*/
294 case MTP_DEFAULTS:
295 /*@access mtDefaultsNode@*/
296 mtDefaultsNode_free ((mtDefaultsNode) node->node);
297 break;
298 /*@noaccess mtDefaultsNode@*/
299 case MTP_DEFAULTVALUE:
300 /*@access mttok@*/
301 mttok_free ((mttok) node->node);
302 break;
303 /*@noaccess mttok@*/
304 case MTP_ANNOTATIONS:
305 /*@access mtAnnotationsNode@*/
306 mtAnnotationsNode_free ((mtAnnotationsNode) node->node);
307 break;
308 /*@noaccess mtAnnotationsNode@*/
309 case MTP_MERGE:
310 /*@access mtMergeNode@*/
311 mtMergeNode_free ((mtMergeNode) node->node);
312 break;
313 /*@noaccess mtMergeNode@*/
314 case MTP_TRANSFERS:
315 case MTP_PRECONDITIONS:
316 case MTP_POSTCONDITIONS:
317 /*@access mtTransferClauseList@*/
318 mtTransferClauseList_free ((mtTransferClauseList) node->node);
319 break;
320 /*@noaccess mtTransferClauseList@*/
321 case MTP_LOSERS:
322 /*@access mtLoseReferenceList@*/
323 mtLoseReferenceList_free ((mtLoseReferenceList) node->node);
324 break;
325 /*@noaccess mtLoseReferenceList@*/
328 sfree (node);