]> andersk Git - splint.git/blob - src/constraintTerm.c
163baf8d6611f3f0ebba918e8543c27b1fb7cc7d
[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 # include "exprData.i"
15
16 /*@-czechfcns@*/
17
18 //#include "constraintExpr.h"
19
20 bool constraintTerm_isIntLiteral (constraintTerm term)
21 {
22   llassert(term);
23   
24   if (term->kind == INTLITERAL)
25     return TRUE;
26
27   return FALSE;
28 }
29
30 constraintTerm constraintTerm_simplify (constraintTerm term)
31 {
32   if (term->kind == EXPRNODE)
33     {
34       if ( exprNode_knownIntValue (term->value.expr ) )
35         {
36           int temp;
37           temp  = exprNode_getLongValue (term->value.expr);
38           term->value.intlit = temp;
39           term->kind = INTLITERAL;
40         }
41     }
42   return term;
43 }
44
45 fileloc constraintTerm_getFileloc (constraintTerm t)
46 {
47   return (fileloc_copy (t->loc) );
48 }
49
50 constraintTerm constraintTerm_makeExprNode (/*@only@*/ exprNode e)
51 {
52   constraintTerm ret = new_constraintTermExpr();
53   ret->loc =  exprNode_getfileloc(e);
54   ret->value.expr = e;
55   ret->kind = EXPRNODE;
56   ret = constraintTerm_simplify(ret);
57   return ret;
58 }
59
60 constraintTerm constraintTerm_copy (constraintTerm term)
61 {
62   constraintTerm ret;
63   ret = new_constraintTermExpr();
64   ret->loc = fileloc_copy (term->loc);
65   ret->value= term->value;
66   ret->kind = term->kind;
67   return ret;
68 }
69
70 constraintTerm constraintTerm_setFileloc (constraintTerm term, fileloc loc)
71 {
72   llassert(term);
73   term->loc = fileloc_copy(loc);
74   return term;
75 }
76
77 cstring constraintTerm_print (constraintTerm term)
78 {
79   cstring s;
80   s = cstring_undefined;
81   
82   llassert (term != NULL);
83
84   switch (term->kind)
85     {
86     case EXPRNODE:
87       /*@i334*/  //wtf
88       s = message ("%s @ %s ", exprNode_unparse (term->value.expr),
89                    fileloc_unparse (term->loc) );
90       break;
91     case INTLITERAL:
92       s = message (" %d ", term->value.intlit);
93       break;
94       
95     case SREF:
96       s = cstring_makeLiteral("Not Implemented\n");
97       llassert(FALSE);
98       break;
99     }
100   
101   return s;
102 }
103
104
105 constraintTerm constraintTerm_makeIntLiteral (int i)
106 {
107   constraintTerm ret = new_constraintTermExpr();
108   ret->value.intlit = i;
109   ret->kind = INTLITERAL;
110   ret->loc =  fileloc_undefined;
111   return ret;
112 }
113
114 bool constraintTerm_canGetValue (constraintTerm term)
115 {
116   if (term->kind == INTLITERAL)
117     return TRUE;
118   else
119     return FALSE;
120 }
121
122 int constraintTerm_getValue (constraintTerm term) 
123 {
124   llassert (term->kind == INTLITERAL);
125   return term->value.intlit;
126 }
127
128
129
130 /* same and similar are similar but not the same*/
131
132 bool constraintTerm_same (constraintTerm term1, constraintTerm term2)
133 {
134   llassert (term1 !=NULL && term2 !=NULL);
135
136   if ( (term1->kind != term2->kind) || (term1->kind != EXPRNODE) )
137     {
138       return FALSE;
139     }
140       
141  DPRINTF ( (message
142             ("Comparing srefs for %s and  %s ", constraintTerm_print(term1), constraintTerm_print(term2)
143              )
144             )
145            );
146  
147  if (sRef_same (term1->value.expr->sref, term2->value.expr->sref) )
148    {
149      DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2)  )  ));
150      return TRUE;
151    }
152  else
153    {
154      DPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2)  )  ));
155      return FALSE;
156    }     
157     
158 }
159
160 bool constraintTerm_similar (constraintTerm term1, constraintTerm term2)
161 {
162   llassert (term1 !=NULL && term2 !=NULL);
163
164   if ( (term1->kind != term2->kind) || (term1->kind != EXPRNODE) )
165     {
166       return FALSE;
167     }
168       
169  TPRINTF ( (message
170             ("Comparing srefs for %s and  %s ", constraintTerm_print(term1), constraintTerm_print(term2)
171              )
172             )
173            );
174  
175  if (sRef_same (term1->value.expr->sref, term2->value.expr->sref) )
176    {
177      DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2)  )  ));
178      return TRUE;
179    }
180  else
181    {
182      TPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2)  )  ));
183      return FALSE;
184    }     
185     
186 }
187
188
189
This page took 0.12251 seconds and 3 git commands to generate.