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