]> andersk Git - splint.git/blobdiff - src/constraintTerm.c
Merged code tree with Dave Evans's version. Many changes to numberous to list....
[splint.git] / src / constraintTerm.c
index 535d4e6cf338bf99c810d12712faa329ca67be82..55b2d8b31dd5341fad5a83f8c392e9de7f28d7f5 100644 (file)
 # include "cgrammar_tokens.h"
 
 # include "exprChecks.h"
-# include "aliasChecks.h"
 # include "exprNodeSList.h"
 
 /*@-czechfcns@*/
 
 //#include "constraintExpr.h"
 
-/*@access exprNode, constraintTermValue @*/
+/*@access exprNode @*/
 
-static bool constraintTerm_same (constraintTerm term1, constraintTerm term2) ;
+/*@unused@*/ static bool constraintTerm_same (constraintTerm p_term1, constraintTerm p_term2) ;
 
 void constraintTerm_free (/*@only@*/ constraintTerm term)
 {
@@ -95,7 +94,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;
@@ -124,7 +123,7 @@ constraintTermType constraintTerm_getKind (constraintTerm t)
   return (t->value.sref);
 }
 
-/*@only@*/ constraintTerm constraintTerm_makeExprNode (/*@dependent@*/ exprNode e)
+/*@only@*/ constraintTerm constraintTerm_makeExprNode (/*@depenedent@*/  exprNode e)
 {
   constraintTerm ret = new_constraintTermExpr();
   ret->loc =  fileloc_copy(exprNode_getfileloc(e));
@@ -134,7 +133,7 @@ constraintTermType constraintTerm_getKind (constraintTerm t)
   return ret;
 }
 
-/*@only@*/ constraintTerm constraintTerm_makesRef  (/*@exposed@*/ sRef s)
+/*@only@*/ constraintTerm constraintTerm_makesRef  (/*@temp@*/ /*@observer@*/ sRef s)
 {
   constraintTerm ret = new_constraintTermExpr();
   ret->loc =  fileloc_undefined;
@@ -158,7 +157,7 @@ constraintTerm constraintTerm_setFileloc (/*@returned@*/ constraintTerm term, fi
 {
   llassert(term != NULL);
 
-  if (term->loc != fileloc_undefined)
+  if ( fileloc_isDefined(  term->loc ) )
     fileloc_free(term->loc);
 
   term->loc = fileloc_copy(loc);
@@ -372,12 +371,12 @@ bool constraintTerm_similar (constraintTerm term1, constraintTerm term2)
   s1 = constraintTerm_getsRef (term1);
   s2 = constraintTerm_getsRef (term2);
 
-  if ( ! (s1 && 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)
             )
            )
@@ -395,3 +394,174 @@ 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", cstring_toCharsSafe( 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", cstring_toCharsSafe(ctString), (int) param );
+           cstring_free(ctString);
+         }
+       else
+         {
+           u = sRef_getUentry(s);
+           fprintf(f, "%s\n", cstring_toCharsSafe(uentry_rawName (u) ) );
+         }
+       
+      }
+      break;
+      
+    case INTLITERAL:
+      fprintf (f, "%d\n", t->value.intlit);
+      break;
+      
+    default:
+      BADEXIT;
+    }
+  
+}
+
+
+/*@only@*/ constraintTerm constraintTerm_undump ( FILE *f)
+{
+  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) reader_getInt(&str);
+  str = fgets(os, MAX_DUMP_LINE_LENGTH, f);
+
+  switch (kind)
+    {
+      
+    case SREF:
+      {
+       sRef s;
+       char * term;
+       term = reader_getWord(&str);
+       
+       if (strcmp (term, "Result") == 0 )
+         {
+           s = sRef_makeResult();
+         }
+       else if (strcmp (term, "Param" ) == 0 )
+         {
+           int param;
+           char *str2, *ostr2;
+           
+           ctype t;
+
+           reader_checkChar(&str, ' ');
+           str2  = reader_getWord(&str);
+           param = reader_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
+         {
+           cstring termStr = cstring_makeLiteralTemp(term);
+
+           ue = usymtab_lookup (termStr);
+           s = uentry_getSref(ue);
+         }
+       
+       ret = constraintTerm_makesRef(s);
+
+       free(term);
+      }
+      break;
+
+    case EXPRNODE:
+      {
+       sRef s;
+       char * term;
+       cstring termStr;
+               
+       term = reader_getWord(&str);
+       //This must be an identifier that we can search for
+         // in usymTab
+       termStr = cstring_makeLiteralTemp(term);
+       
+       ue = usymtab_lookup (termStr);
+       s = uentry_getSref(ue);
+       ret = constraintTerm_makesRef(s);
+
+       free (term);
+      }
+      break;
+      
+      
+    case INTLITERAL:
+      {
+       int i;
+
+       i = reader_getInt(&str);
+       ret = constraintTerm_makeIntLiteral (i);
+      }
+      break;
+      
+    default:
+      BADEXIT;
+    }
+  free (os);
+
+  return ret;
+}
+
+
+
+
This page took 0.045279 seconds and 4 git commands to generate.