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 static warnClause
warnClause_createAux (/*@only@*/ fileloc loc
,
32 /*@only@*/ flagSpec flag
,
33 /*@only@*/ cstring msg
)
35 warnClause res
= (warnClause
) dmalloc (sizeof (*res
));
41 DPRINTF (("Creating warn clause with flag spec: [%p] %s", flag
,
42 flagSpec_unparse (flag
)));
46 extern warnClause
warnClause_create (lltok tok
, flagSpec flag
, cstring msg
)
52 ** res = warnClause_createAux (lltok_stealLoc (tok), flag, msg);
53 ** but this leads to unexplained (yet) crashes.
54 ** Reported by Walter Briscoe
57 res
= warnClause_createAux (fileloc_copy (lltok_getLoc (tok
)), flag
, msg
);
62 warnClause
warnClause_copy (warnClause w
)
64 if (warnClause_isDefined (w
))
66 return warnClause_createAux (fileloc_copy (w
->loc
),
67 flagSpec_copy (w
->flag
),
68 cstring_copy (w
->msg
));
72 return warnClause_undefined
;
76 extern flagSpec
warnClause_getFlag (warnClause w
)
78 llassert (warnClause_isDefined (w
));
82 extern cstring
warnClause_unparse (warnClause w
)
84 if (warnClause_isDefined (w
))
86 return message ("<%q> %s", flagSpec_unparse (w
->flag
), w
->msg
);
90 return cstring_undefined
;
94 extern bool warnClause_hasMessage (warnClause w
)
96 return warnClause_isDefined (w
) && cstring_isDefined (w
->msg
);
99 extern /*@observer@*/ cstring
warnClause_getMessage (warnClause w
)
101 if (warnClause_isDefined (w
)) {
104 return cstring_undefined
;
109 extern void warnClause_free (warnClause w
)
111 if (warnClause_isDefined (w
))
113 flagSpec_free (w
->flag
);
114 fileloc_free (w
->loc
);
115 cstring_free (w
->msg
);
121 warnClause_dump (warnClause wc
)
123 cstring st
= cstring_undefined
;
124 llassert (warnClause_isDefined (wc
));
125 llassert (!cstring_containsChar (warnClause_getMessage (wc
), '#'));
127 if (warnClause_hasMessage (wc
))
129 llassert (cstring_firstChar (warnClause_getMessage (wc
)) != '.');
130 st
= message ("%q#%s#", flagSpec_dump (wc
->flag
), warnClause_getMessage (wc
));
134 st
= message ("%q#.#", flagSpec_dump (wc
->flag
));
141 warnClause_undump (char **s
)
146 DPRINTF (("Undump: %s", *s
));
147 flag
= flagSpec_undump (s
);
148 DPRINTF (("Here: %s", *s
));
149 reader_checkChar (s
, '#');
150 DPRINTF (("Here: %s", *s
));
152 if (reader_optCheckChar (s
, '.'))
154 msg
= cstring_undefined
;
158 msg
= reader_readUntil (s
, '#');
161 DPRINTF (("Here: %s", *s
));
162 reader_checkChar (s
, '#');
164 return warnClause_createAux (fileloc_copy (g_currentloc
), flag
, msg
);