2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
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.
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.
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"
31 static mtDeclarationPiece
32 mtDeclarationPiece_create (mtPieceKind kind
, /*@null@*/ /*@only@*/ void *node
)
34 mtDeclarationPiece res
= (mtDeclarationPiece
) dmalloc (sizeof (*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
;
103 /*@access mtContextNode@*/
104 return mtContextNode_unparse ((mtContextNode
) p
->node
);
105 /*@noaccess mtContextNode@*/
107 /*@access mtValuesNode@*/
108 return mtValuesNode_unparse ((mtValuesNode
) p
->node
);
109 /*@noaccess mtValuesNode@*/
111 /*@access mtDefaultsNode@*/
112 return mtDefaultsNode_unparse ((mtDefaultsNode
) p
->node
);
113 /*@noaccess mtDefaultsNode@*/
114 case MTP_DEFAULTVALUE
:
116 return message ("default %q", mttok_getText ((mttok
) p
->node
));
118 case MTP_ANNOTATIONS
:
119 /*@access mtAnnotationsNode@*/
120 return mtAnnotationsNode_unparse ((mtAnnotationsNode
) p
->node
);
121 /*@noaccess mtAnnotationsNode@*/
123 /*@access mtMergeNode@*/
124 return mtMergeNode_unparse ((mtMergeNode
) p
->node
);
125 /*@noaccess mtMergeNode@*/
127 case MTP_PRECONDITIONS
:
128 case MTP_POSTCONDITIONS
:
129 /*@access mtTransferClauseList@*/
130 return mtTransferClauseList_unparse ((mtTransferClauseList
) p
->node
);
131 /*@noaccess mtTransferClauseList@*/
133 /*@access mtLoseReferenceList@*/
134 return mtLoseReferenceList_unparse ((mtLoseReferenceList
) p
->node
);
135 /*@noaccess mtLoseReferenceList@*/
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
);
156 extern mtContextNode
mtDeclarationPiece_getContext (mtDeclarationPiece node
)
158 llassert (mtDeclarationPiece_isDefined (node
));
159 llassert (node
->kind
== MTP_CONTEXT
);
162 return (mtContextNode
) node
->node
;
165 # endif /* DEADCODE */
167 extern mtContextNode
mtDeclarationPiece_stealContext (mtDeclarationPiece node
)
171 llassert (mtDeclarationPiece_isDefined (node
));
172 llassert (node
->kind
== MTP_CONTEXT
);
175 res
= (mtContextNode
) node
->node
;
177 node
->kind
= MTP_DEAD
;
182 extern mtDefaultsNode
mtDeclarationPiece_getDefaults (mtDeclarationPiece node
)
184 llassert (mtDeclarationPiece_isDefined (node
));
185 llassert (node
->kind
== MTP_DEFAULTS
);
188 return (mtDefaultsNode
) node
->node
;
192 extern cstring
mtDeclarationPiece_getDefaultValue (mtDeclarationPiece node
)
194 llassert (mtDeclarationPiece_isDefined (node
));
195 llassert (node
->kind
== MTP_DEFAULTVALUE
);
198 return mttok_observeText ((mttok
) node
->node
);
202 extern mtAnnotationsNode
mtDeclarationPiece_getAnnotations (mtDeclarationPiece node
)
204 llassert (mtDeclarationPiece_isDefined (node
));
205 llassert (node
->kind
== MTP_ANNOTATIONS
);
208 return (mtAnnotationsNode
) node
->node
;
212 extern mtMergeNode
mtDeclarationPiece_getMerge (mtDeclarationPiece node
)
214 llassert (mtDeclarationPiece_isDefined (node
));
215 llassert (node
->kind
== MTP_MERGE
);
218 return (mtMergeNode
) node
->node
;
222 extern mtTransferClauseList
mtDeclarationPiece_getTransfers (mtDeclarationPiece node
)
224 llassert (mtDeclarationPiece_isDefined (node
));
225 llassert (node
->kind
== MTP_TRANSFERS
);
228 return (mtTransferClauseList
) node
->node
;
232 extern mtTransferClauseList
mtDeclarationPiece_getPreconditions (mtDeclarationPiece node
)
234 llassert (mtDeclarationPiece_isDefined (node
));
235 llassert (node
->kind
== MTP_PRECONDITIONS
);
238 return (mtTransferClauseList
) node
->node
;
243 extern mtTransferClauseList
mtDeclarationPiece_getPostconditions (mtDeclarationPiece node
)
245 llassert (mtDeclarationPiece_isDefined (node
));
246 llassert (node
->kind
== MTP_POSTCONDITIONS
);
249 return (mtTransferClauseList
) node
->node
;
252 # endif /* DEADCODE */
254 extern mtLoseReferenceList
mtDeclarationPiece_getLosers (mtDeclarationPiece node
)
256 llassert (mtDeclarationPiece_isDefined (node
));
257 llassert (node
->kind
== MTP_LOSERS
);
260 return (mtLoseReferenceList
) node
->node
;
264 extern mtValuesNode
mtDeclarationPiece_getValues (mtDeclarationPiece node
)
266 llassert (mtDeclarationPiece_isDefined (node
));
267 llassert (node
->kind
== MTP_VALUES
);
270 return (mtValuesNode
) node
->node
;
274 extern void mtDeclarationPiece_free (/*@only@*/ mtDeclarationPiece node
)
281 llassert (node
->node
== NULL
);
285 /*@access mtContextNode@*/
286 mtContextNode_free ((mtContextNode
) node
->node
);
288 /*@noaccess mtContextNode@*/
290 /*@access mtValuesNode@*/
291 mtValuesNode_free ((mtValuesNode
) node
->node
);
293 /*@noaccess mtValuesNode@*/
295 /*@access mtDefaultsNode@*/
296 mtDefaultsNode_free ((mtDefaultsNode
) node
->node
);
298 /*@noaccess mtDefaultsNode@*/
299 case MTP_DEFAULTVALUE
:
301 mttok_free ((mttok
) node
->node
);
304 case MTP_ANNOTATIONS
:
305 /*@access mtAnnotationsNode@*/
306 mtAnnotationsNode_free ((mtAnnotationsNode
) node
->node
);
308 /*@noaccess mtAnnotationsNode@*/
310 /*@access mtMergeNode@*/
311 mtMergeNode_free ((mtMergeNode
) node
->node
);
313 /*@noaccess mtMergeNode@*/
315 case MTP_PRECONDITIONS
:
316 case MTP_POSTCONDITIONS
:
317 /*@access mtTransferClauseList@*/
318 mtTransferClauseList_free ((mtTransferClauseList
) node
->node
);
320 /*@noaccess mtTransferClauseList@*/
322 /*@access mtLoseReferenceList@*/
323 mtLoseReferenceList_free ((mtLoseReferenceList
) node
->node
);
325 /*@noaccess mtLoseReferenceList@*/