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
28 # include "splintMacros.nf"
31 /*@notnull@*/ metaStateInfo
32 metaStateInfo_create (cstring name
,
33 cstringList valueNames
,
34 mtContextNode context
,
35 stateCombinationTable sctable
,
36 stateCombinationTable mergetable
,
39 metaStateInfo res
= (metaStateInfo
) dmalloc (sizeof (*res
));
43 res
->valueNames
= valueNames
;
44 res
->context
= context
;
46 res
->sctable
= sctable
;
47 res
->mergetable
= mergetable
;
50 for (i
= 0; i
< MTC_NUMCONTEXTS
; i
++)
52 res
->defaultValue
[i
] = stateValue_error
;
55 llassert (stateCombinationTable_size (res
->sctable
)
56 == cstringList_size (res
->valueNames
));
61 void metaStateInfo_free (/*@only@*/ metaStateInfo msinfo
)
63 if (metaStateInfo_isDefined (msinfo
))
65 cstring_free (msinfo
->name
);
66 cstringList_free (msinfo
->valueNames
);
67 stateCombinationTable_free (msinfo
->sctable
);
68 stateCombinationTable_free (msinfo
->mergetable
);
69 fileloc_free (msinfo
->loc
);
70 mtContextNode_free (msinfo
->context
); /* evans 2002-01-03 */
75 cstring
metaStateInfo_unparse (metaStateInfo info
)
77 llassert (metaStateInfo_isDefined (info
));
78 return message ("%s: %q\n%q", info
->name
,
79 cstringList_unparse (info
->valueNames
),
80 stateCombinationTable_unparse (info
->sctable
));
83 cstring
metaStateInfo_unparseValue (metaStateInfo info
, int value
)
85 llassert (metaStateInfo_isDefined (info
));
87 DPRINTF (("unparse value: %s / %d",
88 metaStateInfo_unparse (info
), value
));
92 llassert (value
== stateValue_error
);
93 return cstring_makeLiteralTemp ("error");
96 llassert (value
< cstringList_size (info
->valueNames
));
97 return cstringList_get (info
->valueNames
, value
);
100 /*@observer@*/ mtContextNode
metaStateInfo_getContext (metaStateInfo info
)
102 llassert (metaStateInfo_isDefined (info
));
103 return info
->context
;
106 /*@observer@*/ cstring
metaStateInfo_getName (metaStateInfo info
)
108 llassert (metaStateInfo_isDefined (info
));
112 /*@observer@*/ fileloc
metaStateInfo_getLoc (metaStateInfo info
)
114 llassert (metaStateInfo_isDefined (info
));
118 extern /*@exposed@*/ stateCombinationTable
119 metaStateInfo_getTransferTable (metaStateInfo info
) /*@*/
121 llassert (metaStateInfo_isDefined (info
));
122 return info
->sctable
;
125 extern /*@exposed@*/ stateCombinationTable
126 metaStateInfo_getMergeTable (metaStateInfo info
) /*@*/
128 llassert (metaStateInfo_isDefined (info
));
129 return info
->mergetable
;
132 /*@+enumindex@*/ /* allow context kinds to reference array */
133 extern int metaStateInfo_getDefaultValueContext (metaStateInfo info
, mtContextKind context
)
135 llassert (metaStateInfo_isDefined (info
));
136 return info
->defaultValue
[context
];
139 extern int metaStateInfo_getDefaultValue (metaStateInfo info
, sRef s
)
141 llassert (metaStateInfo_isDefined (info
));
144 && (info
->defaultValue
[MTC_PARAM
] != stateValue_error
))
146 return info
->defaultValue
[MTC_PARAM
];
148 else if (sRef_isResult (s
)
149 && (info
->defaultValue
[MTC_RESULT
] != stateValue_error
))
151 return info
->defaultValue
[MTC_RESULT
];
153 else if (sRef_isConst (s
)
154 && (info
->defaultValue
[MTC_LITERAL
] != stateValue_error
))
156 return info
->defaultValue
[MTC_LITERAL
];
160 llassert (mtContextNode_matchesRef (metaStateInfo_getContext (info
), s
));
161 return info
->defaultValue
[MTC_REFERENCE
];
165 extern int metaStateInfo_getDefaultGlobalValue (metaStateInfo info
)
167 llassert (metaStateInfo_isDefined (info
));
168 return info
->defaultValue
[MTC_REFERENCE
];
171 void metaStateInfo_setDefaultValueContext (metaStateInfo info
, mtContextKind context
, int val
)
173 llassert (metaStateInfo_isDefined (info
));
174 /*@-type@*/ llassert (context
>= 0 && context
< MTC_NUMCONTEXTS
); /*@=type@*/
175 llassert (metaStateInfo_getDefaultValueContext (info
, context
) == stateValue_error
);
176 info
->defaultValue
[context
] = val
;
180 void metaStateInfo_setDefaultRefValue (metaStateInfo info
, int val
)
182 metaStateInfo_setDefaultValueContext (info
, MTC_REFERENCE
, val
);
186 void metaStateInfo_setDefaultResultValue (metaStateInfo info
, int val
)
188 metaStateInfo_setDefaultValueContext (info
, MTC_RESULT
, val
);
191 void metaStateInfo_setDefaultParamValue (metaStateInfo info
, int val
)
193 metaStateInfo_setDefaultValueContext (info
, MTC_PARAM
, val
);
195 # endif /* DEADCODE */
197 int metaStateInfo_getDefaultRefValue (metaStateInfo info
)
199 return metaStateInfo_getDefaultValueContext (info
, MTC_REFERENCE
);
203 int metaStateInfo_getDefaultResultValue (metaStateInfo info
)
205 return metaStateInfo_getDefaultValueContext (info
, MTC_RESULT
);
208 int metaStateInfo_getDefaultParamValue (metaStateInfo info
)
210 return metaStateInfo_getDefaultValueContext (info
, MTC_PARAM
);
212 # endif /* DEADCODE */