** constraintExpr.c
*/
-//#define DEBUGPRINT 1
+/* #define DEBUGPRINT 1 */
# include <ctype.h> /* for isdigit */
# include "lclintMacros.nf"
/*@-czechfcns@*/
-//#include "constraintExpr.h"
-
/*@access exprNode @*/
-/*@unused@*/ static bool constraintTerm_same (constraintTerm p_term1, constraintTerm p_term2) ;
+bool constraintTerm_isDefined (constraintTerm t)
+{
+ return t != NULL;
+}
void constraintTerm_free (/*@only@*/ constraintTerm term)
{
- llassert(constraintTerm_isDefined(term) );
+ llassert (constraintTerm_isDefined (term));
+
fileloc_free (term->loc);
switch (term->kind)
break;
case SREF:
/* sref */
- //sRef_free (term->value.sref);
+ sRef_free (term->value.sref);
break;
case INTLITERAL:
/* don't free an int */
/* type was set incorrectly */
llcontbug (message("constraintTerm_free type was set incorrectly"));
}
+
+ term->kind = ERRORBADCONSTRAINTTERMTYPE;
free (term);
}
return FALSE;
}
+
+bool constraintTerm_isInitBlock (/*@observer@*/ /*@temp@*/ constraintTerm c) /*@*/
+{
+ llassert (c != NULL);
+ if (c->kind == EXPRNODE)
+ {
+
+ if (exprNode_isInitBlock(c->value.expr) )
+ {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+
+bool constraintTerm_isExprNode (/*@observer@*/ /*@temp@*/ constraintTerm c) /*@*/
+{
+ llassert (c != NULL);
+ if (c->kind == EXPRNODE)
+ {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
+int constraintTerm_getInitBlockLength (/*@observer@*/ /*@temp@*/ constraintTerm c) /*@*/
+{
+
+ exprNodeList list;
+ int ret;
+ llassert (c != NULL);
+ llassert (constraintTerm_isInitBlock (c) );
+ llassert (c->kind == EXPRNODE);
+
+ llassert(exprNode_isDefined(c->value.expr) );
+
+ if (exprNode_isUndefined(c->value.expr) )
+ {
+ return 1;
+ }
+
+ if (c->value.expr->edata == exprData_undefined)
+ {
+ return 1;
+ }
+ list = exprData_getArgs(c->value.expr->edata);
+
+ ret = exprNodeList_size(list);
+
+ return ret;
+}
+
+
+
bool constraintTerm_isStringLiteral (constraintTerm c) /*@*/
{
llassert (c != NULL);
return FALSE;
}
+
+
cstring constraintTerm_getStringLiteral (constraintTerm c)
{
llassert (c != NULL);
fileloc constraintTerm_getFileloc (constraintTerm t)
{
+ llassert (constraintTerm_isDefined (t));
return (fileloc_copy (t->loc) );
}
return (t->value.sref);
}
-/*@only@*/ constraintTerm constraintTerm_makeExprNode (/*@depenedent@*/ exprNode e)
+/*@only@*/ constraintTerm constraintTerm_makeExprNode (/*@dependent@*/ exprNode e)
{
constraintTerm ret = new_constraintTermExpr();
ret->loc = fileloc_copy(exprNode_getfileloc(e));
return ret;
}
+
+
constraintTerm constraintTerm_copy (constraintTerm term)
{
constraintTerm ret;
ret = new_constraintTermExpr();
ret->loc = fileloc_copy (term->loc);
- constraintTermValue_copy (ret->value, term->value);
+
+ switch (term->kind)
+ {
+ case EXPRNODE:
+ ret->value.expr = term->value.expr;
+ break;
+ case INTLITERAL:
+ ret->value.intlit = term->value.intlit;
+ break;
+
+ case SREF:
+ ret->value.sref = sRef_saveCopy(term->value.sref);
+ break;
+ default:
+ BADEXIT;
+ }
ret->kind = term->kind;
return ret;
}
switch (term->kind)
{
case EXPRNODE:
- /*@i334*/ //wtf
+ /*@i334*/ /*wtf*/
s = message ("%s", exprNode_unparse (term->value.expr) );
break;
case INTLITERAL:
- s = message (" %d ", term->value.intlit);
+ s = message (" %d ", (int) term->value.intlit);
break;
case SREF:
switch (term->kind)
{
case EXPRNODE:
- /*@i334*/ //wtf
- // s = message ("%s @ %s ", exprNode_unparse (term->value.expr),
- // fileloc_unparse (term->loc) );
+ /*@i334*/ /*wtf*/
break;
case INTLITERAL:
- // s = message (" %d ", term->value.intlit);
- break;
+ break;
case SREF:
term->value.sref = sRef_fixBaseParam (term->value.sref, arglist);
- // s = message ("%s ", sRef_unparse (term->value.sref) );
-
break;
default:
BADEXIT;
switch (term->kind)
{
case EXPRNODE:
- /*@i334*/ //wtf
- s = message ("%s @ %q ", exprNode_unparse (term->value.expr),
+ /*@i334*/ /*wtf*/
+ s = message ("%s @ %q", exprNode_unparse (term->value.expr),
fileloc_unparse (term->loc) );
break;
case INTLITERAL:
- s = message (" %d ", term->value.intlit);
+ s = message ("%d", (int)term->value.intlit);
break;
case SREF:
- s = message ("%q ", sRef_unparseDebug (term->value.sref) );
+ s = message ("%q", sRef_unparseDebug (term->value.sref) );
break;
default:
}
-constraintTerm constraintTerm_makeIntLiteral (int i)
+constraintTerm constraintTerm_makeIntLiteral (long i)
{
constraintTerm ret = new_constraintTermExpr();
ret->value.intlit = i;
bool constraintTerm_canGetValue (constraintTerm term)
{
if (term->kind == INTLITERAL)
- return TRUE;
+ {
+ return TRUE;
+ }
+ else if (term->kind == SREF)
+ {
+ if (sRef_hasValue (term->value.sref))
+ {
+ multiVal mval = sRef_getValue (term->value.sref);
+
+ return multiVal_isInt (mval); /* for now, only try to deal with int values */
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+ else if (term->kind == EXPRNODE)
+ {
+ return FALSE;
+ }
else
- return FALSE;
+ {
+ return FALSE;
+ }
}
-int constraintTerm_getValue (constraintTerm term)
+long constraintTerm_getValue (constraintTerm term)
{
- llassert (term->kind == INTLITERAL);
- return term->value.intlit;
-}
+ llassert (constraintTerm_canGetValue (term));
-/* same and similar are similar but not the same*/
-static bool constraintTerm_same (constraintTerm term1, constraintTerm term2)
-{
- llassert (term1 !=NULL && term2 !=NULL);
+ if (term->kind == INTLITERAL)
+ {
+ return term->value.intlit;
+ }
+ else if (term->kind == SREF)
+ {
+ if (sRef_hasValue (term->value.sref))
+ {
+ multiVal mval = sRef_getValue (term->value.sref);
- if ( (term1->kind != term2->kind) || (term1->kind != EXPRNODE) )
+ return multiVal_forceInt (mval); /* for now, only try to deal with int values */
+ }
+ else
+ {
+ BADBRANCH;
+ }
+ }
+ else if (term->kind == EXPRNODE)
{
- return FALSE;
+ BADBRANCH;
}
-
- 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) )
- {
- DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2) ) ));
- return TRUE;
- }
- else
- {
- DPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2) ) ));
- return FALSE;
- }
-
+ else
+ {
+ BADBRANCH;
+ }
+
+ BADEXIT;
}
static /*@exposed@*/ sRef constraintTerm_getsRef (constraintTerm t)
llassert (term1 !=NULL && term2 !=NULL);
- if ( (term1->kind == INTLITERAL) && (term2->kind == INTLITERAL) )
+ if (constraintTerm_canGetValue (term1) && constraintTerm_canGetValue (term2))
+ /* evans 2001-07-24: was (term1->kind == INTLITERAL) && (term2->kind == INTLITERAL) ) */
{
- int t1, t2;
- llassert (constraintTerm_canGetValue(term1) );
- t1 = constraintTerm_getValue (term1);
+ long t1, t2;
- llassert (constraintTerm_canGetValue(term2) );
+ t1 = constraintTerm_getValue (term1);
t2 = constraintTerm_getValue (term2);
- if (t1 == t2)
- return TRUE;
-
- return FALSE;
+
+ return (t1 == t2);
}
-
+
+ if (constraintTerm_canGetValue (term1) || constraintTerm_canGetValue (term2))
+ {
+ /* evans 2001-07-24: is this right? */ /*@i534@*/
+ return FALSE;
+ }
+
s1 = constraintTerm_getsRef (term1);
s2 = constraintTerm_getsRef (term2);
- if ( ! (sRef_isValid(s1) && sRef_isValid(s2) ) )
+ if (!(sRef_isValid(s1) && sRef_isValid(s2)))
{
return FALSE;
}
- DPRINTF( (message
+ DPRINTF( (message
("Comparing srefs for %s and %s ", constraintTerm_print(term1), constraintTerm_print(term2)
)
)
);
-
- if (sRef_similarRelaxed(s1, s2) || sRef_sameName (s1, s2) )
- {
- DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2) ) ));
- return TRUE;
- }
- else
- {
- DPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2) ) ));
- return FALSE;
- }
-
+
+ if (sRef_similarRelaxed(s1, s2) || sRef_sameName (s1, s2) )
+ {
+ DPRINTF ((message (" %s and %s are same", constraintTerm_print(term1), constraintTerm_print(term2) ) ));
+ return TRUE;
+ }
+ else
+ {
+ DPRINTF ((message (" %s and %s are not same", constraintTerm_print(term1), constraintTerm_print(term2) ) ));
+ return FALSE;
+ }
}
void constraintTerm_dump ( /*@observer@*/ constraintTerm t, FILE *f)
break;
case INTLITERAL:
- fprintf (f, "%d\n", t->value.intlit);
+ fprintf (f, "%ld\n", t->value.intlit);
break;
default:
uentry ue;
- char * str;
- char * os;
+ char *str;
+ char *os;
str = mstring_create (MAX_DUMP_LINE_LENGTH);
os = str;
- str = fgets(os, MAX_DUMP_LINE_LENGTH, f);
+ str = fgets (os, MAX_DUMP_LINE_LENGTH, f);
kind = (constraintTermType) reader_getInt(&str);
str = fgets(os, MAX_DUMP_LINE_LENGTH, f);
if (strcmp (term, "Result") == 0 )
{
- s = sRef_makeResult();
+ s = sRef_makeResult (ctype_unknown);
}
else if (strcmp (term, "Param" ) == 0 )
{
ostr2 = str2;
t = ctype_undump(&str2) ;
- s = sRef_makeParam (param, t );
+ s = sRef_makeParam (param, t, stateInfo_makeLoc (g_currentloc));
free (ostr2);
}
- else //This must be an identified that we can search for
- // in usymTab
+ else /* This must be an identified that we can search for in usymTab */
{
cstring termStr = cstring_makeLiteralTemp(term);
cstring termStr;
term = reader_getWord(&str);
- //This must be an identifier that we can search for
- // in usymTab
+ /* This must be an identifier that we can search for in usymTab */
termStr = cstring_makeLiteralTemp(term);
ue = usymtab_lookup (termStr);