]> andersk Git - splint.git/blame - src/warnClause.c
*** empty log message ***
[splint.git] / src / warnClause.c
CommitLineData
28bf4b0b 1/*
2** LCLint - annotation-assisted static program checker
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
22** For more information: http://lclint.cs.virginia.edu
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,
33 /*@only@*/ exprNode msg)
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
44extern warnClause warnClause_create (lltok tok, flagSpec flag, exprNode msg)
45{
46 warnClause res;
47 DPRINTF (("Create warn message: %s/ %s ",
48 flagSpec_unparse (flag), exprNode_unparse(msg)));
49
50 res = warnClause_createAux (lltok_stealLoc (tok),
51 flag, msg);
52 lltok_release (tok);
53 return res;
54}
55
efd360a3 56warnClause warnClause_copy (warnClause w)
57{
58 if (warnClause_isDefined (w))
59 {
60 return warnClause_createAux (fileloc_copy (w->loc),
61 flagSpec_copy (w->flag),
ccf0a4a8 62 w->msg); /*@i32 should exprNode_copy (w->msg)); */
efd360a3 63 }
64 else
65 {
66 return warnClause_undefined;
67 }
68}
69
28bf4b0b 70extern flagSpec warnClause_getFlag (warnClause w)
71{
72 return w->flag;
73}
74
75extern cstring warnClause_unparse (warnClause w)
76{
77 if (warnClause_isDefined (w))
78 {
79 return message ("<%q> %s",
80 flagSpec_unparse (w->flag), exprNode_unparse (w->msg));
81 }
82 else
83 {
84 return cstring_undefined;
85 }
86}
87
88extern bool warnClause_hasMessage (warnClause w)
89{
90 return warnClause_isDefined (w) && exprNode_isDefined (w->msg)
91 && cstring_isDefined (multiVal_forceString (exprNode_getValue (w->msg)));
92}
93
94extern /*@observer@*/ cstring warnClause_getMessage (warnClause w)
95{
96 if (warnClause_isDefined (w) && exprNode_isDefined (w->msg)) {
97 llassert (exprNode_knownStringValue (w->msg));
98 return multiVal_forceString (exprNode_getValue (w->msg));
99 } else {
100 return cstring_undefined;
101 }
102}
103
104
105extern void warnClause_free (warnClause w)
106{
107 if (warnClause_isDefined (w))
108 {
109 flagSpec_free (w->flag);
efd360a3 110 /*@i43 should be copied! exprNode_free (w->msg); */
28bf4b0b 111 fileloc_free (w->loc);
112 sfree (w);
113 }
114}
115
116/*@only@*/ cstring
117warnClause_dump (warnClause wc)
118{
119 cstring st = cstring_undefined;
120
121 llassert (!cstring_containsChar (warnClause_getMessage (wc), '#'));
2c88d156 122
123 if (warnClause_hasMessage (wc))
124 {
125 llassert (cstring_firstChar (warnClause_getMessage (wc)) != '.');
126 st = message ("%q#%s#", flagSpec_dump (wc->flag), warnClause_getMessage (wc));
127 }
128 else
129 {
130 st = message ("%q#.#", flagSpec_dump (wc->flag));
131 }
132
28bf4b0b 133 return st;
134}
135
136warnClause
137warnClause_undump (char **s)
138{
139 flagSpec flag;
140 cstring msg;
141 exprNode emsg;
142
2c88d156 143 DPRINTF (("Undump: %s", *s));
28bf4b0b 144 flag = flagSpec_undump (s);
2c88d156 145 DPRINTF (("Here: %s", *s));
28bf4b0b 146 reader_checkChar (s, '#');
2c88d156 147 DPRINTF (("Here: %s", *s));
148
149 if (reader_optCheckChar (s, '.'))
150 {
151 msg = cstring_undefined;
152 }
153 else
154 {
155 msg = reader_readUntil (s, '#');
156 }
157
158 DPRINTF (("Here: %s", *s));
28bf4b0b 159 reader_checkChar (s, '#');
2c88d156 160
28bf4b0b 161 emsg = exprNode_rawStringLiteral (msg, fileloc_copy (g_currentloc));
162
163 return warnClause_createAux (fileloc_copy (g_currentloc), flag, emsg);
164}
This page took 0.070721 seconds and 5 git commands to generate.