]> andersk Git - splint.git/blobdiff - src/ctbase.i
Made allocations involving sizeof work correctly (test/malloc.c).
[splint.git] / src / ctbase.i
index 2b30048475725b4dc7c0ad79dd039b3478e340c6..c59eb7628313015a9b5de658abda9405dca3db3c 100644 (file)
 abst_typedef /*@null@*/ struct s_ctbase *ctbase;
 
 /*@function static bool ctuid_isAnyUserType (sef ctuid p_cid) @*/
-/*@i888@*/
+
 /*@-macrofcndecl@*/ /*@-macroparams@*/
 # define ctuid_isAnyUserType(cid) \
    ((cid) == CT_ABST || (cid) == CT_USER || (cid) == CT_NUMABST)
 /*@=macrofcndecl@*/ /*@=macroparams@*/
 
-/*@private@*/ typedef struct {
+/*:private:*/ typedef struct {
   ctkind kind;
   ctbase ctbase; 
   ctype base;     /* type I point to (or element of array) */
@@ -1024,12 +1024,11 @@ ctbase_dump (ctbase c)
     case CT_PRIM:
       return (message ("p%d|", c->contents.prim));
     case CT_USER:
-      return (message ("s%d|", 
-                      usymtab_convertId (c->contents.tid)));
+      return (message ("s%d|", usymtab_convertTypeId (c->contents.tid)));
     case CT_ABST:
-      return (message ("a%d|", usymtab_convertId (c->contents.tid)));
+      return (message ("a%d|", usymtab_convertTypeId (c->contents.tid)));
     case CT_NUMABST:
-      return (message ("n%d|", usymtab_convertId (c->contents.tid)));
+      return (message ("n%d|", usymtab_convertTypeId (c->contents.tid)));
     case CT_PTR:
       return (message ("t%q|", ctype_dump (c->contents.base)));
     case CT_ARRAY:
@@ -1173,7 +1172,8 @@ ctbase_free (/*@only@*/ ctbase c)
          sfree (c);
          break;
        case CT_FCN:
-         /*@i32@*/ /* uentryList_free (c->contents.fcn->params); */
+         /* Cannot free params: uentryList_free (c->contents.fcn->params);  */ 
+         uentryList_freeShallow (c->contents.fcn->params);
          sfree (c);
          break;
        case CT_STRUCT:
@@ -2382,13 +2382,13 @@ ctbase_compare (ctbase c1, ctbase c2, bool strict)
     case CT_BOOL:
       return 0;
     case CT_USER:
-      return (int_compare (c1->contents.tid, c2->contents.tid));
+      return (typeId_compare (c1->contents.tid, c2->contents.tid));
     case CT_ENUMLIST:       
       return 1;
     case CT_ENUM:              /* for now, keep like abstract */
     case CT_ABST:
     case CT_NUMABST:
-      return (int_compare (c1->contents.tid, c2->contents.tid));
+      return (typeId_compare (c1->contents.tid, c2->contents.tid));
     case CT_PTR:
       return (ctype_compare (c1->contents.base, c2->contents.base));
     case CT_FIXEDARRAY:
@@ -2627,3 +2627,54 @@ bool ctbase_isBigger (ctbase ct1, ctbase ct2)
       return FALSE;
     }
 }
+
+int ctbase_getSize (ctbase ct)
+{
+  if (ct == NULL) 
+    {
+      return 0;
+    }
+  
+  switch (ct->type) 
+    {
+    case CT_UNKNOWN:
+    case CT_BOOL:
+    case CT_PRIM:
+      {
+       cprim cp = ct->contents.prim;
+       int nbits = cprim_getExpectedBits (cp);
+       return nbits;
+      }
+    case CT_USER:
+    case CT_ABST:
+    case CT_NUMABST:
+    case CT_EXPFCN:
+      {
+       return 0;
+      }
+    case CT_PTR:
+      {
+       /* Malloc returns void *, but they are bytes.  Normal void * is pointer size. */
+       if (ctype_isVoid (ct->contents.base)) 
+         {
+           return 8;
+         }
+       else
+         {
+           return ctype_getSize (ct->contents.base);
+         }
+      }
+    case CT_FIXEDARRAY: 
+    case CT_ARRAY:
+    case CT_FCN:
+    case CT_STRUCT:
+    case CT_UNION:
+    case CT_ENUM:
+    case CT_CONJ:
+      break;
+      BADDEFAULT;
+    }
+
+  return 0;
+      
+}
This page took 0.091261 seconds and 4 git commands to generate.