]> andersk Git - splint.git/blame - src/warnClause.c
Renaming - LCLint => Splint
[splint.git] / src / warnClause.c
CommitLineData
28bf4b0b 1/*
11db3170 2** Splint - annotation-assisted static program checker
28bf4b0b 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
11db3170 22** For more information: http://www.splint.org
28bf4b0b 23*/
24/*
25** warnClause.c
26*/
27
28# include "lclintMacros.nf"
29# include "basic.h"
28bf4b0b 30
31static warnClause warnClause_createAux (/*@only@*/ fileloc loc,
32 /*@only@*/ flagSpec flag,
6970c11b 33 /*@only@*/ cstring msg)
28bf4b0b 34{
35 warnClause res = (warnClause) dmalloc (sizeof (*res));
36
37 res->loc = loc;
38 res->flag = flag;
39 res->msg = msg;
40
41 return res;
42}
43
6970c11b 44extern warnClause warnClause_create (lltok tok, flagSpec flag, cstring msg)
28bf4b0b 45{
46 warnClause res;
6970c11b 47 res = warnClause_createAux (lltok_stealLoc (tok), flag, msg);
28bf4b0b 48 lltok_release (tok);
49 return res;
50}
51
efd360a3 52warnClause warnClause_copy (warnClause w)
53{
54 if (warnClause_isDefined (w))
55 {
56 return warnClause_createAux (fileloc_copy (w->loc),
57 flagSpec_copy (w->flag),
6970c11b 58 cstring_copy (w->msg));
efd360a3 59 }
60 else
61 {
62 return warnClause_undefined;
63 }
64}
65
28bf4b0b 66extern flagSpec warnClause_getFlag (warnClause w)
67{
6970c11b 68 llassert (warnClause_isDefined (w));
28bf4b0b 69 return w->flag;
70}
71
72extern cstring warnClause_unparse (warnClause w)
73{
74 if (warnClause_isDefined (w))
75 {
6970c11b 76 return message ("<%q> %s", flagSpec_unparse (w->flag), w->msg);
28bf4b0b 77 }
78 else
79 {
80 return cstring_undefined;
81 }
82}
83
84extern bool warnClause_hasMessage (warnClause w)
85{
6970c11b 86 return warnClause_isDefined (w) && cstring_isDefined (w->msg);
28bf4b0b 87}
88
89extern /*@observer@*/ cstring warnClause_getMessage (warnClause w)
90{
6970c11b 91 if (warnClause_isDefined (w)) {
92 return w->msg;
28bf4b0b 93 } else {
94 return cstring_undefined;
95 }
96}
97
98
99extern void warnClause_free (warnClause w)
100{
101 if (warnClause_isDefined (w))
102 {
103 flagSpec_free (w->flag);
28bf4b0b 104 fileloc_free (w->loc);
6970c11b 105 cstring_free (w->msg);
28bf4b0b 106 sfree (w);
107 }
108}
109
110/*@only@*/ cstring
111warnClause_dump (warnClause wc)
112{
113 cstring st = cstring_undefined;
6970c11b 114 llassert (warnClause_isDefined (wc));
28bf4b0b 115 llassert (!cstring_containsChar (warnClause_getMessage (wc), '#'));
2c88d156 116
117 if (warnClause_hasMessage (wc))
118 {
119 llassert (cstring_firstChar (warnClause_getMessage (wc)) != '.');
120 st = message ("%q#%s#", flagSpec_dump (wc->flag), warnClause_getMessage (wc));
121 }
122 else
123 {
124 st = message ("%q#.#", flagSpec_dump (wc->flag));
125 }
126
28bf4b0b 127 return st;
128}
129
130warnClause
131warnClause_undump (char **s)
132{
133 flagSpec flag;
134 cstring msg;
28bf4b0b 135
2c88d156 136 DPRINTF (("Undump: %s", *s));
28bf4b0b 137 flag = flagSpec_undump (s);
2c88d156 138 DPRINTF (("Here: %s", *s));
28bf4b0b 139 reader_checkChar (s, '#');
2c88d156 140 DPRINTF (("Here: %s", *s));
141
142 if (reader_optCheckChar (s, '.'))
143 {
144 msg = cstring_undefined;
145 }
146 else
147 {
148 msg = reader_readUntil (s, '#');
149 }
150
151 DPRINTF (("Here: %s", *s));
28bf4b0b 152 reader_checkChar (s, '#');
2c88d156 153
6970c11b 154 return warnClause_createAux (fileloc_copy (g_currentloc), flag, msg);
28bf4b0b 155}
This page took 0.107707 seconds and 5 git commands to generate.