]>
Commit | Line | Data |
---|---|---|
361091cc | 1 | /* |
92c4a786 | 2 | ** constraintExpr.c |
361091cc | 3 | */ |
4 | ||
f5ac53de | 5 | //#define DEBUGPRINT 1 |
6 | ||
361091cc | 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" | |
93307a76 | 16 | |
17 | //# include "exprData.i" | |
361091cc | 18 | |
92c4a786 | 19 | /*@-czechfcns@*/ |
20 | ||
21 | //#include "constraintExpr.h" | |
361091cc | 22 | |
f5ac53de | 23 | |
24 | ||
25 | ||
92c4a786 | 26 | bool constraintTerm_isIntLiteral (constraintTerm term) |
361091cc | 27 | { |
92c4a786 | 28 | llassert(term); |
29 | ||
30 | if (term->kind == INTLITERAL) | |
31 | return TRUE; | |
32 | ||
33 | return FALSE; | |
361091cc | 34 | } |
35 | ||
36 | constraintTerm constraintTerm_simplify (constraintTerm term) | |
37 | { | |
92c4a786 | 38 | if (term->kind == EXPRNODE) |
bf92e32c | 39 | { |
92c4a786 | 40 | if ( exprNode_knownIntValue (term->value.expr ) ) |
bf92e32c | 41 | { |
92c4a786 | 42 | int temp; |
43 | temp = exprNode_getLongValue (term->value.expr); | |
44 | term->value.intlit = temp; | |
45 | term->kind = INTLITERAL; | |
bf92e32c | 46 | } |
bf92e32c | 47 | } |
361091cc | 48 | return term; |
49 | } | |
50 | ||
92c4a786 | 51 | fileloc constraintTerm_getFileloc (constraintTerm t) |
361091cc | 52 | { |
92c4a786 | 53 | return (fileloc_copy (t->loc) ); |
361091cc | 54 | } |
55 | ||
92c4a786 | 56 | constraintTerm constraintTerm_makeExprNode (/*@only@*/ exprNode e) |
361091cc | 57 | { |
58 | constraintTerm ret = new_constraintTermExpr(); | |
59 | ret->loc = exprNode_getfileloc(e); | |
60 | ret->value.expr = e; | |
61 | ret->kind = EXPRNODE; | |
92c4a786 | 62 | ret = constraintTerm_simplify(ret); |
361091cc | 63 | return ret; |
64 | } | |
65 | ||
93307a76 | 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 | ||
92c4a786 | 76 | constraintTerm constraintTerm_copy (constraintTerm term) |
361091cc | 77 | { |
78 | constraintTerm ret; | |
92c4a786 | 79 | ret = new_constraintTermExpr(); |
80 | ret->loc = fileloc_copy (term->loc); | |
81 | ret->value= term->value; | |
82 | ret->kind = term->kind; | |
361091cc | 83 | return ret; |
84 | } | |
85 | ||
92c4a786 | 86 | constraintTerm constraintTerm_setFileloc (constraintTerm term, fileloc loc) |
361091cc | 87 | { |
92c4a786 | 88 | llassert(term); |
89 | term->loc = fileloc_copy(loc); | |
90 | return term; | |
361091cc | 91 | } |
92 | ||
93307a76 | 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 | ||
f5ac53de | 146 | cstring constraintTerm_print (constraintTerm term) /*@*/ |
361091cc | 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: | |
361091cc | 161 | s = message (" %d ", term->value.intlit); |
162 | break; | |
92c4a786 | 163 | |
361091cc | 164 | case SREF: |
93307a76 | 165 | s = message ("%s ", sRef_unparseDebug (term->value.sref) ); |
166 | ||
361091cc | 167 | break; |
168 | } | |
361091cc | 169 | |
92c4a786 | 170 | return s; |
361091cc | 171 | } |
172 | ||
173 | ||
92c4a786 | 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) | |
bf92e32c | 184 | { |
92c4a786 | 185 | if (term->kind == INTLITERAL) |
186 | return TRUE; | |
187 | else | |
188 | return FALSE; | |
189 | } | |
bf92e32c | 190 | |
92c4a786 | 191 | int constraintTerm_getValue (constraintTerm term) |
192 | { | |
193 | llassert (term->kind == INTLITERAL); | |
194 | return term->value.intlit; | |
bf92e32c | 195 | } |
196 | ||
92c4a786 | 197 | |
198 | ||
bf92e32c | 199 | /* same and similar are similar but not the same*/ |
361091cc | 200 | |
201 | bool constraintTerm_same (constraintTerm term1, constraintTerm term2) | |
202 | { | |
203 | llassert (term1 !=NULL && term2 !=NULL); | |
204 | ||
361091cc | 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 | { | |
bf92e32c | 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 | ||
93307a76 | 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 | ||
bf92e32c | 272 | bool constraintTerm_similar (constraintTerm term1, constraintTerm term2) |
273 | { | |
93307a76 | 274 | sRef s1, s2; |
275 | ||
bf92e32c | 276 | llassert (term1 !=NULL && term2 !=NULL); |
277 | ||
93307a76 | 278 | s1 = constraintTerm_getsRef (term1); |
279 | s2 = constraintTerm_getsRef (term2); | |
280 | ||
281 | if ( ! (s1 && s2) ) | |
bf92e32c | 282 | { |
283 | return FALSE; | |
284 | } | |
93307a76 | 285 | |
754746a0 | 286 | DPRINTF ( (message |
bf92e32c | 287 | ("Comparing srefs for %s and %s ", constraintTerm_print(term1), constraintTerm_print(term2) |
288 | ) | |
289 | ) | |
290 | ); | |
291 | ||
93307a76 | 292 | if (sRef_sameName (s1, s2) ) |
bf92e32c | 293 | { |
294 | DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2) ) )); | |
361091cc | 295 | return TRUE; |
296 | } | |
297 | else | |
298 | { | |
754746a0 | 299 | DPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2) ) )); |
361091cc | 300 | return FALSE; |
301 | } | |
302 | ||
303 | } | |
304 | ||
92c4a786 | 305 | |
306 |