]> andersk Git - splint.git/blob - src/constraintTerm.c
If checking mostly works. Boolean expression are handled.
[splint.git] / src / constraintTerm.c
1 /*
2 ** constraintExpr.c
3 */
4
5 # include <ctype.h> /* for isdigit */
6 # include "lclintMacros.nf"
7 # include "basic.h"
8 # include "cgrammar.h"
9 # include "cgrammar_tokens.h"
10
11 # include "exprChecks.h"
12 # include "aliasChecks.h"
13 # include "exprNodeSList.h"
14
15 //# include "exprData.i"
16
17 /*@-czechfcns@*/
18
19 //#include "constraintExpr.h"
20
21 bool constraintTerm_isIntLiteral (constraintTerm term)
22 {
23   llassert(term);
24   
25   if (term->kind == INTLITERAL)
26     return TRUE;
27
28   return FALSE;
29 }
30
31 constraintTerm constraintTerm_simplify (constraintTerm term)
32 {
33   if (term->kind == EXPRNODE)
34     {
35       if ( exprNode_knownIntValue (term->value.expr ) )
36         {
37           int temp;
38           temp  = exprNode_getLongValue (term->value.expr);
39           term->value.intlit = temp;
40           term->kind = INTLITERAL;
41         }
42     }
43   return term;
44 }
45
46 fileloc constraintTerm_getFileloc (constraintTerm t)
47 {
48   return (fileloc_copy (t->loc) );
49 }
50
51 constraintTerm constraintTerm_makeExprNode (/*@only@*/ exprNode e)
52 {
53   constraintTerm ret = new_constraintTermExpr();
54   ret->loc =  exprNode_getfileloc(e);
55   ret->value.expr = e;
56   ret->kind = EXPRNODE;
57   ret = constraintTerm_simplify(ret);
58   return ret;
59 }
60
61 constraintTerm constraintTerm_makesRef  (/*@only@*/ sRef s)
62 {
63   constraintTerm ret = new_constraintTermExpr();
64   ret->loc =  fileloc_undefined;
65   ret->value.sref = s;
66   ret->kind = SREF;
67   ret = constraintTerm_simplify(ret);
68   return ret;
69 }
70
71 constraintTerm constraintTerm_copy (constraintTerm term)
72 {
73   constraintTerm ret;
74   ret = new_constraintTermExpr();
75   ret->loc = fileloc_copy (term->loc);
76   ret->value= term->value;
77   ret->kind = term->kind;
78   return ret;
79 }
80
81 constraintTerm constraintTerm_setFileloc (constraintTerm term, fileloc loc)
82 {
83   llassert(term);
84   term->loc = fileloc_copy(loc);
85   return term;
86 }
87
88
89 cstring constraintTerm_getName (constraintTerm term)
90 {
91   cstring s;
92   s = cstring_undefined;
93   
94   llassert (term != NULL);
95
96   switch (term->kind)
97     {
98     case EXPRNODE:
99       /*@i334*/  //wtf
100       s = message ("%s", exprNode_unparse (term->value.expr) );
101       break;
102     case INTLITERAL:
103       s = message (" %d ", term->value.intlit);
104       break;
105       
106     case SREF:
107       s = message ("%s", sRef_unparse (term->value.sref) );
108
109       break;
110     }
111   
112   return s;
113 }
114
115
116 constraintTerm constraintTerm_doSRefFixBaseParam (constraintTerm term, exprNodeList arglist)
117 {
118   llassert (term != NULL);
119
120   switch (term->kind)
121     {
122     case EXPRNODE:
123       /*@i334*/  //wtf
124       //   s = message ("%s @ %s ", exprNode_unparse (term->value.expr),
125       //           fileloc_unparse (term->loc) );
126       break;
127     case INTLITERAL:
128       //  s = message (" %d ", term->value.intlit);
129        break;
130       
131     case SREF:
132       term->value.sref = sRef_fixBaseParam (term->value.sref, arglist);
133       //      s = message ("%s ", sRef_unparse (term->value.sref) );
134
135       break;
136     }
137   return term;
138   
139 }
140
141 cstring constraintTerm_print (constraintTerm term)
142 {
143   cstring s;
144   s = cstring_undefined;
145   
146   llassert (term != NULL);
147
148   switch (term->kind)
149     {
150     case EXPRNODE:
151       /*@i334*/  //wtf
152       s = message ("%s @ %s ", exprNode_unparse (term->value.expr),
153                    fileloc_unparse (term->loc) );
154       break;
155     case INTLITERAL:
156       s = message (" %d ", term->value.intlit);
157       break;
158       
159     case SREF:
160       s = message ("%s ", sRef_unparseDebug (term->value.sref) );
161
162       break;
163     }
164   
165   return s;
166 }
167
168
169 constraintTerm constraintTerm_makeIntLiteral (int i)
170 {
171   constraintTerm ret = new_constraintTermExpr();
172   ret->value.intlit = i;
173   ret->kind = INTLITERAL;
174   ret->loc =  fileloc_undefined;
175   return ret;
176 }
177
178 bool constraintTerm_canGetValue (constraintTerm term)
179 {
180   if (term->kind == INTLITERAL)
181     return TRUE;
182   else
183     return FALSE;
184 }
185
186 int constraintTerm_getValue (constraintTerm term) 
187 {
188   llassert (term->kind == INTLITERAL);
189   return term->value.intlit;
190 }
191
192
193
194 /* same and similar are similar but not the same*/
195
196 bool constraintTerm_same (constraintTerm term1, constraintTerm term2)
197 {
198   llassert (term1 !=NULL && term2 !=NULL);
199
200   if ( (term1->kind != term2->kind) || (term1->kind != EXPRNODE) )
201     {
202       return FALSE;
203     }
204       
205  DPRINTF ( (message
206             ("Comparing srefs for %s and  %s ", constraintTerm_print(term1), constraintTerm_print(term2)
207              )
208             )
209            );
210  
211  if (sRef_same (term1->value.expr->sref, term2->value.expr->sref) )
212    {
213      DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2)  )  ));
214      return TRUE;
215    }
216  else
217    {
218      DPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2)  )  ));
219      return FALSE;
220    }     
221     
222 }
223
224 sRef constraintTerm_getsRef (constraintTerm t)
225 {
226   llassert (t);
227   if (t->kind == EXPRNODE)
228     {
229       return t->value.expr->sref;
230     }
231
232   if (t->kind == SREF)
233     {
234       return t->value.sref;
235     }
236
237   return sRef_undefined;
238 }
239
240 bool constraintTerm_probSame (constraintTerm term1, constraintTerm term2)
241 {
242   cstring s1, s2;
243
244   llassert (term1 !=NULL && term2 !=NULL);
245      
246  DPRINTF ( (message
247             ("Comparing srefs for %s and  %s ", constraintTerm_print(term1), constraintTerm_print(term2)
248              )
249             )
250            );
251   
252   s1 = constraintTerm_getName (term1);
253   s2 = constraintTerm_getName (term2);
254
255   if (cstring_equal (s1, s2) )
256     {
257       DPRINTF ((message (" %s and %s are same", s1, s2 ) ) );
258      return TRUE;
259    }
260   else
261      {
262      DPRINTF ((message (" %s and %s are not same", s1, s2 ) ) );
263      return FALSE;
264    }   
265 }
266
267 bool constraintTerm_similar (constraintTerm term1, constraintTerm term2)
268 {
269   sRef s1, s2;
270   
271   llassert (term1 !=NULL && term2 !=NULL);
272
273   s1 = constraintTerm_getsRef (term1);
274   s2 = constraintTerm_getsRef (term2);
275
276   if ( ! (s1 && s2) )
277     {
278       return FALSE;
279     }
280   
281  DPRINTF ( (message
282             ("Comparing srefs for %s and  %s ", constraintTerm_print(term1), constraintTerm_print(term2)
283              )
284             )
285            );
286  
287  if (sRef_sameName (s1, s2) )
288    {
289      DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2)  )  ));
290      return TRUE;
291    }
292  else
293    {
294      DPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2)  )  ));
295      return FALSE;
296    }     
297     
298 }
299
300
301
This page took 0.162297 seconds and 5 git commands to generate.