]> andersk Git - splint.git/blob - src/warnClause.c
Fixed bugs in the constant removal code for binary expressions.
[splint.git] / src / warnClause.c
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"
30 # include "mtgrammar.h"
31
32 static warnClause warnClause_createAux (/*@only@*/ fileloc loc, 
33                                         /*@only@*/ flagSpec flag, 
34                                         /*@only@*/ exprNode msg)
35 {
36   warnClause res = (warnClause) dmalloc (sizeof (*res));
37   
38   res->loc = loc;
39   res->flag = flag;
40   res->msg = msg;
41   
42   return res;
43 }
44
45 extern warnClause warnClause_create (lltok tok, flagSpec flag, exprNode msg) 
46 {
47   warnClause res;
48   DPRINTF (("Create warn message: %s/ %s ", 
49             flagSpec_unparse (flag), exprNode_unparse(msg)));
50   
51   res = warnClause_createAux (lltok_stealLoc (tok),
52                               flag, msg);
53   lltok_release (tok);
54   return res;
55 }
56
57 extern flagSpec warnClause_getFlag (warnClause w)
58 {
59   return w->flag;
60 }
61
62 extern cstring warnClause_unparse (warnClause w)
63 {
64   if (warnClause_isDefined (w))
65     {
66       return message ("<%q> %s",
67                       flagSpec_unparse (w->flag), exprNode_unparse (w->msg));
68     }
69   else
70     {
71       return cstring_undefined;
72     }
73 }
74
75 extern bool warnClause_hasMessage (warnClause w)
76 {
77   return warnClause_isDefined (w) && exprNode_isDefined (w->msg)
78     && cstring_isDefined (multiVal_forceString (exprNode_getValue (w->msg)));
79 }
80
81 extern /*@observer@*/ cstring warnClause_getMessage (warnClause w)
82 {
83   if (warnClause_isDefined (w) && exprNode_isDefined (w->msg)) {
84     llassert (exprNode_knownStringValue (w->msg));
85     return multiVal_forceString (exprNode_getValue (w->msg));
86   } else {
87     return cstring_undefined;
88   }
89 }
90
91
92 extern void warnClause_free (warnClause w)
93 {
94   if (warnClause_isDefined (w))
95     {
96       flagSpec_free (w->flag);
97       exprNode_free (w->msg);
98       fileloc_free (w->loc);
99       sfree (w);
100     }
101 }
102
103 /*@only@*/ cstring
104 warnClause_dump (warnClause wc)
105 {
106   cstring st = cstring_undefined;
107
108   llassert (!cstring_containsChar (warnClause_getMessage (wc), '#'));
109
110   if (warnClause_hasMessage (wc))
111     {
112       llassert (cstring_firstChar (warnClause_getMessage (wc)) != '.');
113       st = message ("%q#%s#", flagSpec_dump (wc->flag), warnClause_getMessage (wc));
114     }
115   else
116     {
117       st = message ("%q#.#", flagSpec_dump (wc->flag));
118     }
119
120   return st;
121 }
122
123 warnClause
124 warnClause_undump (char **s)
125 {
126   flagSpec flag;
127   cstring msg;
128   exprNode emsg;
129
130   DPRINTF (("Undump: %s", *s));
131   flag = flagSpec_undump (s);
132   DPRINTF (("Here: %s", *s));
133   reader_checkChar (s, '#');
134   DPRINTF (("Here: %s", *s));
135
136   if (reader_optCheckChar (s, '.'))
137     {
138       msg = cstring_undefined;
139     }
140   else
141     {
142       msg = reader_readUntil (s, '#');
143     }
144   
145   DPRINTF (("Here: %s", *s));
146   reader_checkChar (s, '#');
147
148   emsg = exprNode_rawStringLiteral (msg, fileloc_copy (g_currentloc));
149   
150   return warnClause_createAux (fileloc_copy (g_currentloc), flag, emsg);
151 }
This page took 0.046362 seconds and 5 git commands to generate.