]> andersk Git - splint.git/blobdiff - src/constraintTerm.c
Fixed library dump support so that buffer constraint annotations are read and written...
[splint.git] / src / constraintTerm.c
index d094a1dc6089833dcd3d2952979d7e881b4fec5d..eded0598b7afd20d246f5679770e33aff7e7b334 100644 (file)
 # include "aliasChecks.h"
 # include "exprNodeSList.h"
 
-//# include "exprData.i"
-
 /*@-czechfcns@*/
 
 //#include "constraintExpr.h"
 
 /*@access exprNode, constraintTermValue @*/
 
+/*@unused@*/ static bool constraintTerm_same (constraintTerm term1, constraintTerm term2) ;
 
-static/*@out@*/ constraintTerm new_constraintTermExpr (void)
+void constraintTerm_free (/*@only@*/ constraintTerm term)
+{
+  llassert(constraintTerm_isDefined(term) );
+  fileloc_free (term->loc);
+  
+  switch (term->kind) 
+    {
+    case EXPRNODE:
+      /* we don't free an exprNode*/
+      break;
+    case SREF:
+      /* sref */
+      //sRef_free (term->value.sref);
+      break;
+    case INTLITERAL:
+      /* don't free an int */
+      break;
+    case  ERRORBADCONSTRAINTTERMTYPE:
+    default:
+      /* type was set incorrectly */
+      llcontbug (message("constraintTerm_free type was set incorrectly"));
+    }
+  free (term);
+}
+
+/*@only@*/ static/*@out@*/ constraintTerm new_constraintTermExpr (void)
 {
   constraintTerm ret;
   ret = dmalloc (sizeof (* ret ) );
+  ret->value.intlit = 0;
   return ret;
 }
 
@@ -70,6 +95,7 @@ constraintTerm constraintTerm_simplify (/*@returned@*/ constraintTerm term) /*@m
       if ( exprNode_knownIntValue (term->value.expr ) )
        {
          long int temp;
+         #warning is this a leak?
          temp  = exprNode_getLongValue (term->value.expr);
          term->value.intlit = (int)temp;
          term->kind = INTLITERAL;
@@ -98,21 +124,21 @@ constraintTermType constraintTerm_getKind (constraintTerm t)
   return (t->value.sref);
 }
 
-constraintTerm constraintTerm_makeExprNode (/*@only@*/ exprNode e)
+/*@only@*/ constraintTerm constraintTerm_makeExprNode (/*@dependent@*/ exprNode e)
 {
   constraintTerm ret = new_constraintTermExpr();
-  ret->loc =  exprNode_getfileloc(e);
+  ret->loc =  fileloc_copy(exprNode_getfileloc(e));
   ret->value.expr = e;
   ret->kind = EXPRNODE;
   ret = constraintTerm_simplify(ret);
   return ret;
 }
 
-/*@only@*/ constraintTerm constraintTerm_makesRef  (/*@only@*/ sRef s)
+/*@only@*/ constraintTerm constraintTerm_makesRef  (/*@exposed@*/ sRef s)
 {
   constraintTerm ret = new_constraintTermExpr();
   ret->loc =  fileloc_undefined;
-  ret->value.sref = s;
+  ret->value.sref = sRef_saveCopy(s);
   ret->kind = SREF;
   ret = constraintTerm_simplify(ret);
   return ret;
@@ -128,15 +154,19 @@ constraintTerm constraintTerm_copy (constraintTerm term)
   return ret;
 }
 
-constraintTerm constraintTerm_setFileloc (/*@returned@*/ constraintTerm term, fileloc loc)
+constraintTerm constraintTerm_setFileloc (/*@returned@*/ constraintTerm term, fileloc loc) 
 {
   llassert(term != NULL);
+
+  if (term->loc != fileloc_undefined)
+    fileloc_free(term->loc);
+
   term->loc = fileloc_copy(loc);
   return term;
 }
 
 
-cstring constraintTerm_getName (constraintTerm term)
+static cstring constraintTerm_getName (constraintTerm term)
 {
   cstring s;
   s = cstring_undefined;
@@ -154,7 +184,7 @@ cstring constraintTerm_getName (constraintTerm term)
       break;
       
     case SREF:
-      s = message ("%s", sRef_unparse (term->value.sref) );
+      s = message ("%q", sRef_unparse (term->value.sref) );
 
       break;
     default:
@@ -167,7 +197,7 @@ cstring constraintTerm_getName (constraintTerm term)
 }
 
 constraintTerm 
-constraintTerm_doSRefFixBaseParam (constraintTerm term, exprNodeList arglist) /*@modifies term@*/
+constraintTerm_doSRefFixBaseParam (/*@returned@*/constraintTerm term, exprNodeList arglist) /*@modifies term@*/
 {
   llassert (term != NULL);
   
@@ -205,7 +235,7 @@ cstring constraintTerm_print (constraintTerm term)  /*@*/
     {
     case EXPRNODE:
       /*@i334*/  //wtf
-      s = message ("%s @ %s ", exprNode_unparse (term->value.expr),
+      s = message ("%s @ %q ", exprNode_unparse (term->value.expr),
                   fileloc_unparse (term->loc) );
       break;
     case INTLITERAL:
@@ -213,7 +243,7 @@ cstring constraintTerm_print (constraintTerm term)  /*@*/
       break;
       
     case SREF:
-      s = message ("%s ", sRef_unparseDebug (term->value.sref) );
+      s = message ("%q ", sRef_unparseDebug (term->value.sref) );
 
       break;
     default:
@@ -247,11 +277,8 @@ int constraintTerm_getValue (constraintTerm term)
   return term->value.intlit;
 }
 
-
-
 /* same and similar are similar but not the same*/
-
-bool constraintTerm_same (constraintTerm term1, constraintTerm term2)
+static bool constraintTerm_same (constraintTerm term1, constraintTerm term2)
 {
   llassert (term1 !=NULL && term2 !=NULL);
 
@@ -279,7 +306,7 @@ bool constraintTerm_same (constraintTerm term1, constraintTerm term2)
     
 }
 
-/*@exposed@*/ sRef constraintTerm_getsRef (constraintTerm t)
+static /*@exposed@*/ sRef constraintTerm_getsRef (constraintTerm t)
 {
   llassert (t != NULL);
   if (t->kind == EXPRNODE)
@@ -312,12 +339,12 @@ bool constraintTerm_probSame (constraintTerm term1, constraintTerm term2)
 
   if (cstring_equal (s1, s2) )
     {
-      DPRINTF ((message (" %s and %s are same", s1, s2 ) ) );
+      DPRINTF ((message (" %q and %q are same", s1, s2 ) ) );
      return TRUE;
    }
   else
      {
-     DPRINTF ((message (" %s and %s are not same", s1, s2 ) ) );
+     DPRINTF ((message (" %q and %q are not same", s1, s2 ) ) );
      return FALSE;
    }   
 }
@@ -368,3 +395,171 @@ bool constraintTerm_similar (constraintTerm term1, constraintTerm term2)
    }     
     
 }
+
+void constraintTerm_dump ( /*@observer@*/ constraintTerm t,  FILE *f)
+{
+  fileloc loc;
+  constraintTermValue value;
+  constraintTermType kind;
+  uentry u;
+  
+  loc = t->loc;
+
+  value = t->value;
+
+  kind  = t->kind;
+
+  fprintf(f, "%d\n", (int) kind);
+  
+  switch (kind)
+    {
+      
+    case EXPRNODE:
+      u = exprNode_getUentry(t->value.expr);
+      fprintf(f, "%s\n", uentry_rawName (u) );
+      break;
+      
+    case SREF:
+      {
+       sRef s;
+
+       s =  t->value.sref;
+       
+       if (sRef_isResult (s ) )
+         {
+           fprintf(f, "Result\n");
+         }
+       else if (sRef_isParam (s ) )
+         {
+           int param;
+           ctype ct;
+           cstring ctString;
+
+           
+           ct =  sRef_getType (s); 
+           param = sRef_getParam(s);
+
+           ctString =  ctype_dump(ct);
+           
+           fprintf(f, "Param %s %d\n", ctString, (int) param );
+           cstring_free(ctString);
+         }
+       else
+         {
+           u = sRef_getUentry(s);
+           fprintf(f, "%s\n", uentry_rawName (u) );
+         }
+       
+      }
+      break;
+      
+    case INTLITERAL:
+      fprintf (f, "%d\n", t->value.intlit);
+      break;
+      
+    default:
+      BADEXIT;
+    }
+  
+}
+
+
+/*@only@*/ constraintTerm constraintTerm_undump ( FILE *f)
+{
+  fileloc loc;
+  constraintTermType kind;
+  constraintTerm ret;
+  
+  uentry ue;
+  
+  char * str;
+  char * os;
+
+  str = mstring_create (MAX_DUMP_LINE_LENGTH);
+  os = str;
+  str = fgets(os, MAX_DUMP_LINE_LENGTH, f);
+
+  kind = (constraintTermType) getInt(&str);
+  str = fgets(os, MAX_DUMP_LINE_LENGTH, f);
+
+  switch (kind)
+    {
+      
+    case SREF:
+      {
+       sRef s;
+       char * term;
+       term = getWord(&str);
+       
+       if (strcmp (term, "Result") == 0 )
+         {
+           s = sRef_makeResult();
+         }
+       else if (strcmp (term, "Param" ) == 0 )
+         {
+           int param;
+           char *str2, *ostr2;
+           
+           ctype t;
+
+           checkChar(&str, ' ');
+           str2  = getWord(&str);
+           param = getInt(&str);
+
+           ostr2 = str2;
+           t = ctype_undump(&str2) ;
+           s = sRef_makeParam (param, t );
+           free (ostr2);
+         }
+       else  //This must be an identified that we can search for
+         // in usymTab
+         {
+           
+           ue = usymtab_lookup (term);
+           s = uentry_getSref(ue);
+         }
+       
+       ret = constraintTerm_makesRef(s);
+
+       free(term);
+      }
+      break;
+
+    case EXPRNODE:
+      {
+       sRef s;
+       char * term;
+               
+       term = getWord(&str);
+       //This must be an identifier that we can search for
+         // in usymTab
+       
+       ue = usymtab_lookup (term);
+       s = uentry_getSref(ue);
+       ret = constraintTerm_makesRef(s);
+
+       free (term);
+      }
+      break;
+      
+      
+    case INTLITERAL:
+      {
+       int i;
+
+       i = getInt(&str);
+       ret = constraintTerm_makeIntLiteral (i);
+      }
+      break;
+      
+    default:
+      BADEXIT;
+    }
+  free (os);
+
+  return ret;
+}
+
+
+
+
This page took 0.101668 seconds and 4 git commands to generate.