]> andersk Git - splint.git/blame - src/mtContextNode.c
*** empty log message ***
[splint.git] / src / mtContextNode.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** mtContextNode.c
26*/
27
28# include "lclintMacros.nf"
29# include "basic.h"
30# include "mtgrammar.h"
31
32static bool mtContextNode_matchesType (mtContextNode, ctype) /*@*/ ;
33
34static /*@observer@*/ cstring mtContextKind_unparse (mtContextKind ck)
35{
36 switch (ck)
37 {
38 case MTC_ANY: return cstring_makeLiteralTemp ("any");
39 case MTC_PARAM: return cstring_makeLiteralTemp ("param");
b072092f 40 case MTC_RESULT: return cstring_makeLiteralTemp ("result");
28bf4b0b 41 case MTC_REFERENCE: return cstring_makeLiteralTemp ("reference");
42 case MTC_CLAUSE: return cstring_makeLiteralTemp ("clause");
43 }
44
45 BADBRANCH;
46}
47
48static mtContextNode mtContextNode_create (mtContextKind context, ctype ct)
49{
50 mtContextNode res = (mtContextNode) dmalloc (sizeof (*res));
51 res->context = context;
52 res->type = ct;
53 DPRINTF (("Create: %s", mtContextNode_unparse (res)));
54 return res;
55}
56
57extern mtContextNode mtContextNode_createAny ()
58{
59 return mtContextNode_create (MTC_ANY, ctype_unknown);
60}
61
62extern mtContextNode mtContextNode_createParameter (ctype ct)
63{
64 return mtContextNode_create (MTC_PARAM, ct);
65}
66
b072092f 67extern mtContextNode mtContextNode_createResult (ctype ct)
68{
69 return mtContextNode_create (MTC_RESULT, ct);
70}
71
28bf4b0b 72extern mtContextNode mtContextNode_createReference (ctype ct)
73{
74 return mtContextNode_create (MTC_REFERENCE, ct);
75}
76
77extern mtContextNode mtContextNode_createClause (ctype ct)
78{
79 return mtContextNode_create (MTC_CLAUSE, ct);
80}
81
82extern void mtContextNode_free (/*@only@*/ mtContextNode node)
83{
84 sfree (node);
85}
86
87bool mtContextNode_matchesEntry (mtContextNode context, uentry ue)
88{
89 ctype ct;
90
91 llassert (mtContextNode_isDefined (context));
92
93 DPRINTF (("Matches context: %s / %s",
94 mtContextNode_unparse (context), uentry_unparse (ue)));
95
96 switch (context->context)
97 {
98 case MTC_ANY: break; /* everything matches */
b072092f 99 case MTC_RESULT:
100 if (!uentry_isFunction (ue))
101 {
102 return FALSE;
103 }
104 break;
28bf4b0b 105 case MTC_PARAM:
106 if (!uentry_isParam (ue))
107 {
108 return FALSE;
109 }
110 break;
111 case MTC_REFERENCE:
112 break;
113 case MTC_CLAUSE:
114 BADBRANCH;
115 }
116
117 if (uentry_isFunction (ue))
118 {
119 ct = ctype_getReturnType (uentry_getType (ue));
120 }
121 else
122 {
123 ct = uentry_getType (ue);
124 }
125
126 return mtContextNode_matchesType (context, ct);
127}
128
129bool mtContextNode_matchesRef (mtContextNode context, sRef sr)
130{
131 ctype ct;
132
133 llassert (mtContextNode_isDefined (context));
134
135 DPRINTF (("Matches context: %s / %s",
136 mtContextNode_unparse (context), sRef_unparse (sr)));
137
138 switch (context->context)
139 {
140 case MTC_ANY: break; /* everything matches */
b072092f 141 case MTC_RESULT:
142 DPRINTF (("Result? %s / %s",
143 sRef_unparseFull (sr),
144 bool_unparse (sRef_isResult (sr))));
145 return sRef_isResult (sr);
28bf4b0b 146 case MTC_PARAM:
147 if (!sRef_isParam (sr))
148 {
149 return FALSE;
150 }
151 break;
152 case MTC_REFERENCE:
153 break;
154 case MTC_CLAUSE:
155 BADBRANCH;
156 }
157
158 ct = sRef_getType (sr);
159 return mtContextNode_matchesType (context, ct);
160}
161
162bool mtContextNode_matchesRefStrict (mtContextNode context, sRef s)
163{
164 if (mtContextNode_matchesRef (context, s))
165 {
166 if (ctype_isKnown (context->type)
167 && (ctype_isUnknown (sRef_getType (s))
168 || ctype_isVoidPointer (sRef_getType (s))))
169 {
170 return FALSE;
171 }
172 else
173 {
174 return TRUE;
175 }
176 }
177
178 return FALSE;
179}
180
181bool mtContextNode_matchesType (mtContextNode context, ctype ct)
182{
183 DPRINTF (("Context type..."));
184
185 if (!ctype_match (context->type, ct))
186 {
187 DPRINTF (("Type mismatch: %s / %s",
188 ctype_unparse (context->type),
189 ctype_unparse (ct)));
190 return FALSE;
191 }
192 else
193 {
194 DPRINTF (("Type okay: %s / %s",
195 ctype_unparse (context->type),
196 ctype_unparse (ct)));
197 }
198
199 return TRUE;
200}
201
202cstring mtContextNode_unparse (mtContextNode node)
203{
204 if (ctype_isKnown (node->type))
205 {
206 return message ("%s %s", mtContextKind_unparse (node->context),
207 ctype_unparse (node->type));
208 }
209 else
210 {
211 return message ("%s", mtContextKind_unparse (node->context));
212 }
213}
214
215bool mtContextNode_isClause (mtContextNode n)
216{
217 llassert (mtContextNode_isDefined (n));
218 return (n->context == MTC_CLAUSE);
219}
220
221bool mtContextNode_isParameter (mtContextNode n)
222{
223 llassert (mtContextNode_isDefined (n));
224 return (n->context == MTC_PARAM);
225}
226
b072092f 227bool mtContextNode_isReference (mtContextNode n)
28bf4b0b 228{
229 llassert (mtContextNode_isDefined (n));
230 return (n->context == MTC_REFERENCE);
231}
232
b072092f 233bool mtContextNode_isResult (mtContextNode n)
234{
235 llassert (mtContextNode_isDefined (n));
236 return (n->context == MTC_RESULT);
237}
238
28bf4b0b 239
240
241
This page took 0.138398 seconds and 5 git commands to generate.