/*
-** constraintTerm.c
+** constraintExpr.c
*/
+//#define DEBUGPRINT 1
+
# include <ctype.h> /* for isdigit */
# include "lclintMacros.nf"
# include "basic.h"
# include "exprChecks.h"
# include "aliasChecks.h"
# include "exprNodeSList.h"
-# include "exprData.i"
-int constraintTerm_getValue (constraintTerm term)
-{
- if (term->kind == EXPRNODE)
- {
- return (multiVal_forceInt (term->value.expr->val) );
- }
- if (term->kind == INTLITERAL )
- {
- return (term->value.intlit);
- }
- llassert(FALSE);
- return 0;
-}
+//# include "exprData.i"
+
+/*@-czechfcns@*/
+
+//#include "constraintExpr.h"
+
-/*@out@*/ static constraintTerm new_constraintTermExpr (void)
+
+
+bool constraintTerm_isIntLiteral (constraintTerm term)
{
- constraintTerm ret;
- ret = dmalloc (sizeof (* ret ) );
- return ret;
+ llassert(term);
+
+ if (term->kind == INTLITERAL)
+ return TRUE;
+
+ return FALSE;
}
constraintTerm constraintTerm_simplify (constraintTerm term)
{
- if (term->constrType == VALUE)
- {
- if (term->kind == EXPRNODE)
- {
- if ( exprNode_knownIntValue (term->value.expr ) )
- {
- int temp;
- temp = exprNode_getLongValue (term->value.expr);
- term->value.intlit = temp;
- term->kind = INTLITERAL;
- }
-
- }
-
- }
-
- if (term->kind == CONSTRAINTEXPR )
+ if (term->kind == EXPRNODE)
{
- if ( (term->constrType == MAXREAD) || (term->constrType == MAXSET) )
+ if ( exprNode_knownIntValue (term->value.expr ) )
{
- // ms(var + intlit) = ms (var) - intlit
- if (term->value.constrExpr->expr == NULL)
- return term;
-
- if (term->value.constrExpr->expr->term->kind == INTLITERAL)
- {
- if (term->constrType == MAXREAD)
- term->value.constrExpr->term->constrType = MAXREAD;
- else if (term->constrType == MAXSET)
- term->value.constrExpr->term->constrType = MAXSET;
- else
- llassert(FALSE);
-
- term->constrType = VALUE;
-
- if (term->value.constrExpr->op == PLUS)
- term->value.constrExpr->op = MINUS;
- else
- term->value.constrExpr->op = PLUS;
- }
-
+ int temp;
+ temp = exprNode_getLongValue (term->value.expr);
+ term->value.intlit = temp;
+ term->kind = INTLITERAL;
}
-
}
-
-
return term;
-
}
-constraintTerm constraintTerm_copy (constraintTerm term)
+fileloc constraintTerm_getFileloc (constraintTerm t)
{
- constraintTerm ret;
- ret = new_constraintTermExpr();
- ret->constrType = term->constrType;
- ret->loc = fileloc_copy (term->loc);
- ret->value= term->value;
- ret->kind = term->kind;
- return ret;
+ return (fileloc_copy (t->loc) );
}
-constraintTerm exprNode_makeConstraintTerm (/*@only@*/ exprNode e)
+constraintTerm constraintTerm_makeExprNode (/*@only@*/ exprNode e)
{
constraintTerm ret = new_constraintTermExpr();
ret->loc = exprNode_getfileloc(e);
ret->value.expr = e;
ret->kind = EXPRNODE;
+ ret = constraintTerm_simplify(ret);
return ret;
}
-
-constraintTerm constraintTerm_makeMaxSetexpr (exprNode e)
+constraintTerm constraintTerm_makesRef (/*@only@*/ sRef s)
{
- constraintTerm ret;
- ret = exprNode_makeConstraintTerm (e);
- ret->constrType = MAXSET;
+ constraintTerm ret = new_constraintTermExpr();
+ ret->loc = fileloc_undefined;
+ ret->value.sref = s;
+ ret->kind = SREF;
+ ret = constraintTerm_simplify(ret);
return ret;
}
-constraintTerm constraintTerm_makeMinSetexpr (exprNode e)
+constraintTerm constraintTerm_copy (constraintTerm term)
{
constraintTerm ret;
- ret = exprNode_makeConstraintTerm (e);
- ret->constrType = MINSET;
+ ret = new_constraintTermExpr();
+ ret->loc = fileloc_copy (term->loc);
+ ret->value= term->value;
+ ret->kind = term->kind;
return ret;
}
-constraintTerm constraintTerm_makeMaxReadexpr (exprNode e)
+constraintTerm constraintTerm_setFileloc (constraintTerm term, fileloc loc)
{
- constraintTerm ret;
- ret = exprNode_makeConstraintTerm (e);
- ret->constrType = MAXREAD;
- return ret;
+ llassert(term);
+ term->loc = fileloc_copy(loc);
+ return term;
}
-constraintTerm constraintTerm_makeMinReadexpr (exprNode e)
-{
- constraintTerm ret;
- ret = exprNode_makeConstraintTerm (e);
- ret->constrType = MINREAD;
- return ret;
-}
-constraintTerm constraintTerm_makeValueexpr (exprNode e)
+cstring constraintTerm_getName (constraintTerm term)
{
- constraintTerm ret;
- ret = exprNode_makeConstraintTerm (e);
- ret->constrType = VALUE;
- ret = constraintTerm_simplify (ret);
- return ret;
-}
+ cstring s;
+ s = cstring_undefined;
+
+ llassert (term != NULL);
+ switch (term->kind)
+ {
+ case EXPRNODE:
+ /*@i334*/ //wtf
+ s = message ("%s", exprNode_unparse (term->value.expr) );
+ break;
+ case INTLITERAL:
+ s = message (" %d ", term->value.intlit);
+ break;
+
+ case SREF:
+ s = message ("%s", sRef_unparse (term->value.sref) );
-constraintTerm intLit_makeConstraintTerm (int i)
-{
- constraintTerm ret = new_constraintTermExpr();
- ret->value.intlit = i;
- ret->kind = INTLITERAL;
- ret->loc = fileloc_undefined;
- return ret;
+ break;
+ }
+
+ return s;
}
-constraintTerm constraintTerm_makeIntLitValue (int i)
+constraintTerm constraintTerm_doSRefFixBaseParam (constraintTerm term, exprNodeList arglist)
{
- constraintTerm ret;
- ret = intLit_makeConstraintTerm (i);
- ret->constrType = VALUE;
- return ret;
-
-}
-
-/* constraintTerm constraintTerm_makeMinSetexpr (int i) */
-/* { */
-/* constraintTerm ret; */
-/* ret = intLit_makeConstraintTerm (i); */
-/* ret->constrType = MINSET; */
-/* } */
-
-/* constraintTerm constraintTerm_makeMaxReadexpr (int i) */
-/* { */
-/* constraintTerm ret; */
-/* ret = intLit_makeConstraintTerm (i); */
-/* ret->constrType = MAXREAD; */
-/* } */
-/* constraintTerm constraintTerm_makeMinReadexpr (int i) */
-/* { */
-/* constraintTerm ret; */
-/* ret = exprNode_makeConstraintTerm (i); */
-/* ret->constrType = MINREAD; */
-/* } */
-
-
-
+ llassert (term != NULL);
-cstring constraintType_print (constraintType constrType)
-{
- cstring st = cstring_undefined;
-
- switch (constrType)
+ switch (term->kind)
{
- case VALUE:
- st = cstring_makeLiteral("VALUE");
- break;
- case CALLSAFE:
- st = cstring_makeLiteral("CALLSAFE");
- break;
- case MAXSET:
- st = cstring_makeLiteral ("MAXSET");
- break;
- case MINSET:
- st = cstring_makeLiteral ("MINSET");
- break;
- case MAXREAD:
- st = cstring_makeLiteral ("MAXREAD");
- break;
- case MINREAD:
- st = cstring_makeLiteral ("MINREAD");
- break;
- case NULLTERMINATED:
- st = cstring_makeLiteral ("NULLTERMINATED");
+ case EXPRNODE:
+ /*@i334*/ //wtf
+ // s = message ("%s @ %s ", exprNode_unparse (term->value.expr),
+ // fileloc_unparse (term->loc) );
break;
- case UNDEFINED:
- st = cstring_makeLiteral (("Unhandled value for constraintType"));
- llassert(FALSE);
+ case INTLITERAL:
+ // s = message (" %d ", term->value.intlit);
+ break;
+
+ case SREF:
+ term->value.sref = sRef_fixBaseParam (term->value.sref, arglist);
+ // s = message ("%s ", sRef_unparse (term->value.sref) );
+
break;
- default:
- st = cstring_makeLiteral (("Unhandled value for constraintType"));
- llassert(FALSE);
}
- return st;
+ return term;
+
}
-cstring constraintTerm_print (constraintTerm term)
+
+cstring constraintTerm_print (constraintTerm term) /*@*/
{
cstring s;
s = cstring_undefined;
fileloc_unparse (term->loc) );
break;
case INTLITERAL:
- {
s = message (" %d ", term->value.intlit);
break;
- }
+
case SREF:
- s = cstring_makeLiteral("Not Implemented\n");
- llassert(FALSE);
+ s = message ("%s ", sRef_unparseDebug (term->value.sref) );
+
break;
- case CONSTRAINTEXPR:
- s = message ("%s ", constraintExpr_print (term->value.constrExpr) );
}
- s = message (" %s ( %s ) ", constraintType_print (term->constrType), s);
- return s;
+ return s;
}
-bool constraintTerm_hasTerm (constraintTerm term, constraintTerm searchTerm)
+constraintTerm constraintTerm_makeIntLiteral (int i)
{
- if (term->kind == CONSTRAINTEXPR)
- return (constraintExpr_includesTerm (term->value.constrExpr, searchTerm) );
+ constraintTerm ret = new_constraintTermExpr();
+ ret->value.intlit = i;
+ ret->kind = INTLITERAL;
+ ret->loc = fileloc_undefined;
+ return ret;
+}
- if ( (term->kind == EXPRNODE) && (searchTerm->kind == EXPRNODE) )
- {
- return sRef_same (term->value.expr->sref, searchTerm->value.expr->sref);
- }
- return FALSE;
-
+bool constraintTerm_canGetValue (constraintTerm term)
+{
+ if (term->kind == INTLITERAL)
+ return TRUE;
+ else
+ return FALSE;
}
+int constraintTerm_getValue (constraintTerm term)
+{
+ llassert (term->kind == INTLITERAL);
+ return term->value.intlit;
+}
+
+
+
/* same and similar are similar but not the same*/
bool constraintTerm_same (constraintTerm term1, constraintTerm term2)
{
llassert (term1 !=NULL && term2 !=NULL);
- if (term1->constrType != term2->constrType)
- {
- return FALSE;
- }
if ( (term1->kind != term2->kind) || (term1->kind != EXPRNODE) )
{
return FALSE;
}
+sRef constraintTerm_getsRef (constraintTerm t)
+{
+ llassert (t);
+ if (t->kind == EXPRNODE)
+ {
+ return t->value.expr->sref;
+ }
+
+ if (t->kind == SREF)
+ {
+ return t->value.sref;
+ }
+
+ return sRef_undefined;
+}
+
+bool constraintTerm_probSame (constraintTerm term1, constraintTerm term2)
+{
+ cstring s1, s2;
+
+ llassert (term1 !=NULL && term2 !=NULL);
+
+ DPRINTF ( (message
+ ("Comparing srefs for %s and %s ", constraintTerm_print(term1), constraintTerm_print(term2)
+ )
+ )
+ );
+
+ s1 = constraintTerm_getName (term1);
+ s2 = constraintTerm_getName (term2);
+
+ if (cstring_equal (s1, s2) )
+ {
+ DPRINTF ((message (" %s and %s are same", s1, s2 ) ) );
+ return TRUE;
+ }
+ else
+ {
+ DPRINTF ((message (" %s and %s are not same", s1, s2 ) ) );
+ return FALSE;
+ }
+}
+
bool constraintTerm_similar (constraintTerm term1, constraintTerm term2)
{
+ sRef s1, s2;
+
llassert (term1 !=NULL && term2 !=NULL);
- // if (term1->constrType != term2->constrType)
- // {
- // return FALSE;
- // }
- if ( (term1->kind != term2->kind) || (term1->kind != EXPRNODE) )
+ s1 = constraintTerm_getsRef (term1);
+ s2 = constraintTerm_getsRef (term2);
+
+ if ( ! (s1 && s2) )
{
return FALSE;
}
-
+
DPRINTF ( (message
("Comparing srefs for %s and %s ", constraintTerm_print(term1), constraintTerm_print(term2)
)
)
);
- if (sRef_same (term1->value.expr->sref, term2->value.expr->sref) )
+ if (sRef_sameName (s1, s2) )
{
DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2) ) ));
return TRUE;
}
+
+