5 # include <ctype.h> /* for isdigit */
6 # include "lclintMacros.nf"
9 # include "cgrammar_tokens.h"
11 # include "exprChecks.h"
12 # include "aliasChecks.h"
13 # include "exprNodeSList.h"
14 # include "exprData.i"
16 int constraintTerm_getValue (constraintTerm term)
18 if (term->kind == EXPRNODE)
20 return (multiVal_forceInt (term->value.expr->val) );
22 if (term->kind == INTLITERAL )
24 return (term->value.intlit);
30 /*@out@*/ static constraintTerm new_constraintTermExpr (void)
33 ret = dmalloc (sizeof (* ret ) );
37 constraintTerm constraintTerm_simplify (constraintTerm term)
39 if (term->constrType == VALUE)
41 if (term->kind == EXPRNODE)
43 if ( exprNode_knownIntValue (term->value.expr ) )
46 temp = exprNode_getLongValue (term->value.expr);
47 term->value.intlit = temp;
48 term->kind = INTLITERAL;
55 if (term->kind == CONSTRAINTEXPR )
57 if ( (term->constrType == MAXREAD) || (term->constrType == MAXSET) )
59 // ms(var + intlit) = ms (var) - intlit
60 if (term->value.constrExpr->expr == NULL)
63 if (term->value.constrExpr->expr->term->kind == INTLITERAL)
65 if (term->constrType == MAXREAD)
66 term->value.constrExpr->term->constrType = MAXREAD;
67 else if (term->constrType == MAXSET)
68 term->value.constrExpr->term->constrType = MAXSET;
72 term->constrType = VALUE;
74 if (term->value.constrExpr->op == PLUS)
75 term->value.constrExpr->op = MINUS;
77 term->value.constrExpr->op = PLUS;
89 constraintTerm constraintTerm_copy (constraintTerm term)
92 ret = new_constraintTermExpr();
93 ret->constrType = term->constrType;
94 ret->loc = fileloc_copy (term->loc);
95 ret->value= term->value;
96 ret->kind = term->kind;
100 constraintTerm exprNode_makeConstraintTerm (/*@only@*/ exprNode e)
102 constraintTerm ret = new_constraintTermExpr();
103 ret->loc = exprNode_getfileloc(e);
105 ret->kind = EXPRNODE;
110 constraintTerm constraintTerm_makeMaxSetexpr (exprNode e)
113 ret = exprNode_makeConstraintTerm (e);
114 ret->constrType = MAXSET;
118 constraintTerm constraintTerm_makeMinSetexpr (exprNode e)
121 ret = exprNode_makeConstraintTerm (e);
122 ret->constrType = MINSET;
126 constraintTerm constraintTerm_makeMaxReadexpr (exprNode e)
129 ret = exprNode_makeConstraintTerm (e);
130 ret->constrType = MAXREAD;
134 constraintTerm constraintTerm_makeMinReadexpr (exprNode e)
137 ret = exprNode_makeConstraintTerm (e);
138 ret->constrType = MINREAD;
142 constraintTerm constraintTerm_makeValueexpr (exprNode e)
145 ret = exprNode_makeConstraintTerm (e);
146 ret->constrType = VALUE;
147 ret = constraintTerm_simplify (ret);
152 constraintTerm intLit_makeConstraintTerm (int i)
154 constraintTerm ret = new_constraintTermExpr();
155 ret->value.intlit = i;
156 ret->kind = INTLITERAL;
157 ret->loc = fileloc_undefined;
162 constraintTerm constraintTerm_makeIntLitValue (int i)
165 ret = intLit_makeConstraintTerm (i);
166 ret->constrType = VALUE;
171 /* constraintTerm constraintTerm_makeMinSetexpr (int i) */
173 /* constraintTerm ret; */
174 /* ret = intLit_makeConstraintTerm (i); */
175 /* ret->constrType = MINSET; */
178 /* constraintTerm constraintTerm_makeMaxReadexpr (int i) */
180 /* constraintTerm ret; */
181 /* ret = intLit_makeConstraintTerm (i); */
182 /* ret->constrType = MAXREAD; */
184 /* constraintTerm constraintTerm_makeMinReadexpr (int i) */
186 /* constraintTerm ret; */
187 /* ret = exprNode_makeConstraintTerm (i); */
188 /* ret->constrType = MINREAD; */
194 cstring constraintType_print (constraintType constrType)
196 cstring st = cstring_undefined;
201 st = cstring_makeLiteral("VALUE");
204 st = cstring_makeLiteral("CALLSAFE");
207 st = cstring_makeLiteral ("MAXSET");
210 st = cstring_makeLiteral ("MINSET");
213 st = cstring_makeLiteral ("MAXREAD");
216 st = cstring_makeLiteral ("MINREAD");
219 st = cstring_makeLiteral ("NULLTERMINATED");
222 st = cstring_makeLiteral (("Unhandled value for constraintType"));
226 st = cstring_makeLiteral (("Unhandled value for constraintType"));
231 cstring constraintTerm_print (constraintTerm term)
234 s = cstring_undefined;
236 llassert (term != NULL);
242 s = message ("%s @ %s ", exprNode_unparse (term->value.expr),
243 fileloc_unparse (term->loc) );
247 s = message (" %d ", term->value.intlit);
251 s = cstring_makeLiteral("Not Implemented\n");
255 s = message ("%s ", constraintExpr_print (term->value.constrExpr) );
257 s = message (" %s ( %s ) ", constraintType_print (term->constrType), s);
263 bool constraintTerm_hasTerm (constraintTerm term, constraintTerm searchTerm)
265 if (term->kind == CONSTRAINTEXPR)
266 return (constraintExpr_includesTerm (term->value.constrExpr, searchTerm) );
268 if ( (term->kind == EXPRNODE) && (searchTerm->kind == EXPRNODE) )
270 return sRef_same (term->value.expr->sref, searchTerm->value.expr->sref);
276 /* same and similar are similar but not the same*/
278 bool constraintTerm_same (constraintTerm term1, constraintTerm term2)
280 llassert (term1 !=NULL && term2 !=NULL);
282 if (term1->constrType != term2->constrType)
286 if ( (term1->kind != term2->kind) || (term1->kind != EXPRNODE) )
292 ("Comparing srefs for %s and %s ", constraintTerm_print(term1), constraintTerm_print(term2)
297 if (sRef_same (term1->value.expr->sref, term2->value.expr->sref) )
299 DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2) ) ));
304 DPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2) ) ));
310 bool constraintTerm_similar (constraintTerm term1, constraintTerm term2)
312 llassert (term1 !=NULL && term2 !=NULL);
314 // if (term1->constrType != term2->constrType)
318 if ( (term1->kind != term2->kind) || (term1->kind != EXPRNODE) )
324 ("Comparing srefs for %s and %s ", constraintTerm_print(term1), constraintTerm_print(term2)
329 if (sRef_same (term1->value.expr->sref, term2->value.expr->sref) )
331 DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2) ) ));
336 DPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2) ) ));