]> andersk Git - splint.git/blob - src/warnClause.c
*** empty log message ***
[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
31 static 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
44 extern 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
56 extern flagSpec warnClause_getFlag (warnClause w)
57 {
58   return w->flag;
59 }
60
61 extern cstring warnClause_unparse (warnClause w)
62 {
63   if (warnClause_isDefined (w))
64     {
65       return message ("<%q> %s",
66                       flagSpec_unparse (w->flag), exprNode_unparse (w->msg));
67     }
68   else
69     {
70       return cstring_undefined;
71     }
72 }
73
74 extern bool warnClause_hasMessage (warnClause w)
75 {
76   return warnClause_isDefined (w) && exprNode_isDefined (w->msg)
77     && cstring_isDefined (multiVal_forceString (exprNode_getValue (w->msg)));
78 }
79
80 extern /*@observer@*/ cstring warnClause_getMessage (warnClause w)
81 {
82   if (warnClause_isDefined (w) && exprNode_isDefined (w->msg)) {
83     llassert (exprNode_knownStringValue (w->msg));
84     return multiVal_forceString (exprNode_getValue (w->msg));
85   } else {
86     return cstring_undefined;
87   }
88 }
89
90
91 extern void warnClause_free (warnClause w)
92 {
93   if (warnClause_isDefined (w))
94     {
95       flagSpec_free (w->flag);
96       exprNode_free (w->msg);
97       fileloc_free (w->loc);
98       sfree (w);
99     }
100 }
101
102 /*@only@*/ cstring
103 warnClause_dump (warnClause wc)
104 {
105   cstring st = cstring_undefined;
106
107   llassert (!cstring_containsChar (warnClause_getMessage (wc), '#'));
108
109   if (warnClause_hasMessage (wc))
110     {
111       llassert (cstring_firstChar (warnClause_getMessage (wc)) != '.');
112       st = message ("%q#%s#", flagSpec_dump (wc->flag), warnClause_getMessage (wc));
113     }
114   else
115     {
116       st = message ("%q#.#", flagSpec_dump (wc->flag));
117     }
118
119   return st;
120 }
121
122 warnClause
123 warnClause_undump (char **s)
124 {
125   flagSpec flag;
126   cstring msg;
127   exprNode emsg;
128
129   DPRINTF (("Undump: %s", *s));
130   flag = flagSpec_undump (s);
131   DPRINTF (("Here: %s", *s));
132   reader_checkChar (s, '#');
133   DPRINTF (("Here: %s", *s));
134
135   if (reader_optCheckChar (s, '.'))
136     {
137       msg = cstring_undefined;
138     }
139   else
140     {
141       msg = reader_readUntil (s, '#');
142     }
143   
144   DPRINTF (("Here: %s", *s));
145   reader_checkChar (s, '#');
146
147   emsg = exprNode_rawStringLiteral (msg, fileloc_copy (g_currentloc));
148   
149   return warnClause_createAux (fileloc_copy (g_currentloc), flag, emsg);
150 }
This page took 0.037784 seconds and 5 git commands to generate.