]> andersk Git - splint.git/blobdiff - src/ctbase.i
Merged this branch with the one in the splint.sf.net repository.
[splint.git] / src / ctbase.i
index 3eaa78060d6a81aaeae388895c1e47941f8b9b6c..56d31aae37054e245a398329a56b0e465102b092 100644 (file)
@@ -69,8 +69,10 @@ static void cttable_grow (void);
 static ctype cttable_addDerived (ctkind p_ctk, /*@keep@*/ ctbase p_cnew, ctype p_base);
 static ctype cttable_addFull (/*@keep@*/ ctentry p_cnew);
 static bool ctentry_isInteresting (ctentry p_c) /*@*/;
-static /*@notnull@*/ /*@only@*/ ctbase ctbase_makeFixedArray (ctype p_b, long p_size) /*@*/ ;
+static /*@notnull@*/ /*@only@*/ ctbase ctbase_makeFixedArray (ctype p_b, size_t p_size) /*@*/ ;
+static bool ctbase_isAnytype (/*@notnull@*/ ctbase p_b) /*@*/ ;
 
+cstring ctbase_unparseFunctionPointer (ctbase c, /*@only@*/ cstring name) /*@*/ ;
 /* 
 ** These are file-static macros (used in ctype.c).  No way to
 ** declare them as static in C.
@@ -89,6 +91,9 @@ static /*@notnull@*/ /*@only@*/ ctbase ctbase_makeFixedArray (ctype p_b, long p_
 # define ctentry_setPtr(c,b)      ((c)->ptr = (b))
 
 # define ctbase_fixUser(c)        (c = ctbase_realType(c))
+
+/*drl added 04/14/2002 */
+# define ctentry_getCtbase(c)       ((c)->ctbase)
 /*@=allmacros@*/ /*@=macrospec@*/ /*@=namechecks@*/
 
 static ctype cttable_addComplex (/*@notnull@*/ /*@only@*/ ctbase p_cnew);
@@ -168,7 +173,7 @@ typedef struct
 typedef struct
 {
   ctype base;
-  long size;
+  size_t size;
 } *tfixed;
  
 typedef union 
@@ -492,8 +497,29 @@ ctbase_unparse (ctbase c)
          return (message ("%t *", c->contents.base));
        }
     case CT_FIXEDARRAY:
-      return (message ("%t [%d]", c->contents.farray->base, 
-                      (int) c->contents.farray->size));
+      if (ctype_isFixedArray ( c->contents.farray->base ) &&(willOutputCode) )
+       
+       {
+         cstring tmp, tmp2, ret;
+         
+         tmp = ctype_unparse( c->contents.farray->base);
+         tmp2 = cstring_beforeChar(tmp, '[');
+         
+         ret = message("%q [%d] %s ",
+                       tmp2,
+                       c->contents.farray->size,
+                       cstring_afterChar(tmp, '[')
+                       );
+         return ret;
+       }
+      
+      else
+       {
+         return (message ("%t [%d]", 
+                  c->contents.farray->base, 
+                  (int) c->contents.farray->size));
+       }
+      
     case CT_ARRAY:
       return (message ("%t []", c->contents.base));
     case CT_FCN:
@@ -510,7 +536,7 @@ ctbase_unparse (ctbase c)
       else
        {
          return (message ("struct { %q }", 
-                          uentryList_unparseAbbrev (c->contents.su->fields))); 
+                          uentryList_unparse (c->contents.su->fields)));       
        }
     case CT_UNION:
       if (cstring_isDefined (c->contents.su->name) &&
@@ -537,7 +563,11 @@ ctbase_unparse (ctbase c)
                           enumNameList_unparseBrief (c->contents.cenum->members)));
        }
     case CT_CONJ:
-      if (c->contents.conj->isExplicit || context_getFlag (FLG_SHOWALLCONJS))
+      if (ctbase_isAnytype (c))
+       {
+         return (cstring_makeLiteral ("<any>"));
+       }
+      else if (c->contents.conj->isExplicit || context_getFlag (FLG_SHOWALLCONJS))
        {
          if (!ctype_isSimple (c->contents.conj->a) ||
              !ctype_isSimple (c->contents.conj->b))
@@ -604,11 +634,22 @@ static /*@only@*/ cstring
                       uentryList_unparse (c->contents.fcn->params),
                       c->contents.fcn->rval));
     case CT_STRUCT:
+      if (context_getFlag(FLG_GENERATECODE) )
+       {
+         DPRINTF( (message("struct %s { %s }",  c->contents.su->name, uentryList_unparse(c->contents.su->fields) ) ));
+       }
       return (message ("struct %s { ... } ", c->contents.su->name));
     case CT_UNION:
       return (message ("union %s { ... }", c->contents.su->name));
     case CT_CONJ:
-      return (message ("%t", c->contents.conj->a));
+      if (ctbase_isAnytype (c))
+       {
+         return (cstring_makeLiteral ("<any>"));
+       }
+      else
+       {
+         return (message ("%t", c->contents.conj->a));
+       }
     BADDEFAULT;
     }
   BADEXIT;
@@ -656,9 +697,16 @@ ctbase_unparseNotypes (ctbase c)
     case CT_ENUMLIST:
       return (message ("[enumlist]"));
     case CT_CONJ:
-      return (message ("%q/%q", 
-                      ctbase_unparseNotypes (ctype_getCtbase (c->contents.conj->a)),
-                      ctbase_unparseNotypes (ctype_getCtbase (c->contents.conj->b))));
+      if (ctbase_isAnytype (c))
+       {
+         return (cstring_makeLiteral ("<any>"));
+       }
+      else
+       {
+         return (message ("%q/%q", 
+                          ctbase_unparseNotypes (ctype_getCtbase (c->contents.conj->a)),
+                          ctbase_unparseNotypes (ctype_getCtbase (c->contents.conj->b))));
+       }
     BADDEFAULT;
     }
   BADEXIT;
@@ -689,7 +737,7 @@ ctbase_unparseDeclaration (ctbase c, /*@only@*/ cstring name) /*@*/
     case CT_PTR:
       if (ctype_isFunction (c->contents.base))
        {
-         return ctbase_unparseDeclaration (ctype_getCtbase (c->contents.base), name);
+         return ctbase_unparseFunctionPointer (ctype_getCtbase (c->contents.base), name);
        }
       else
        {
@@ -753,8 +801,12 @@ ctbase_unparseDeclaration (ctbase c, /*@only@*/ cstring name) /*@*/
                           enumNameList_unparseBrief (c->contents.cenum->members),
                           name));
        }
-    case CT_CONJ:      
-      if (c->contents.conj->isExplicit || context_getFlag (FLG_SHOWALLCONJS))
+    case CT_CONJ:
+      if (ctbase_isAnytype (c))
+       {
+         return (message ("<any> %q", name));
+       }
+      else if (c->contents.conj->isExplicit || context_getFlag (FLG_SHOWALLCONJS))
        {
          if (!ctype_isSimple (c->contents.conj->a) ||
              !ctype_isSimple (c->contents.conj->b))
@@ -789,6 +841,105 @@ ctbase_unparseDeclaration (ctbase c, /*@only@*/ cstring name) /*@*/
   BADEXIT;
 }
 
+
+
+/*drl added 04/22/2002*/
+ /*@only@*/ cstring
+ctbase_doUnparseFunctionPointer (ctbase c, /*@only@*/ cstring name, cstring quals) /*@*/ 
+{
+  cstring s;
+  
+  if (ctbase_isUndefined (c))
+    {
+      return name;
+    }
+
+  if (c->type == CT_FCN)
+    {
+      s = message ("%s (*%q)(%q)", quals, name, 
+                  uentryList_unparseParamsComplete (c->contents.fcn->params));
+      
+         return (ctbase_unparseDeclaration 
+                 (ctype_getCtbase (c->contents.fcn->rval), s));
+    }
+  else
+    {
+      llassert (c->type == CT_PTR);
+      llassert(FALSE);
+      //  s = message("%q", ctype_unparseFunction ( c->contents.base, name)  );
+         
+     s = message("%q", ctbase_unparse /*Declaration*/ (c) /* name)*/ );
+      return s;
+
+    }
+}
+
+
+/*drl added 04/22/2002*/
+ /*@only@*/ cstring
+ctbase_unparseFunctionPointer (ctbase c, /*@only@*/ cstring name) /*@*/ 
+{
+  cstring s;
+  
+  if (ctbase_isUndefined (c))
+    {
+      return name;
+    }
+
+  if (c->type == CT_FCN)
+    {
+      //      llassert(FALSE);
+      s = message ("(*%q)(%q)", name, 
+                  uentryList_unparseParamsComplete (c->contents.fcn->params));
+      
+         return (ctbase_unparseDeclaration 
+                 (ctype_getCtbase (c->contents.fcn->rval), s));
+    }
+  else
+    {
+      llassert (c->type == CT_PTR);
+      s = message("%q", ctype_unparseFunction ( c->contents.base, name)  );
+         
+   //    s = message("%q", ctbase_unparse /*Declaration*/ (c) /* name)*/ );
+      return s;
+
+    }
+}
+
+
+/*drl added 3/10/2002*/
+
+ /*@only@*/ cstring
+ctbase_unparseFunction (ctbase c, /*@only@*/ cstring name) /*@*/ 
+{
+  cstring s;
+  
+  if (ctbase_isUndefined (c))
+    {
+      return name;
+    }
+
+  if (c->type == CT_FCN)
+    {
+      s = message ("%q(%q)", name, 
+                  uentryList_unparseParamsComplete (c->contents.fcn->params));
+      
+         return (ctbase_unparseDeclaration 
+                 (ctype_getCtbase (c->contents.fcn->rval), s));
+    }
+  else
+    {
+      
+      llassert (c->type == CT_PTR);
+
+      
+      s = message("%q", ctbase_unparse /*Declaration*/ (c) /* name)*/ );
+      return s;
+
+    }
+}
+
+
 static ctbase ctbase_undump (d_char *c) /*@requires maxRead(*c) >= 2 @*/
 {
   ctbase res;
@@ -827,10 +978,10 @@ static ctbase ctbase_undump (d_char *c) /*@requires maxRead(*c) >= 2 @*/
     case 'F':
       {
        ctype ct = ctype_undump (c);
-       int size;
+       size_t size;
 
        reader_checkChar (c, '/');
-       size = reader_getInt (c);
+       size = size_fromInt (reader_getInt (c));
        reader_checkChar (c, '|');
        return (ctbase_makeFixedArray (ct, size));
       }
@@ -1165,6 +1316,19 @@ ctbase_expectFunction (ctype c)
   return (f);
 }
 
+static bool
+ctbase_isExpectFunction (/*@notnull@*/ ctbase ct) /*@*/
+{
+  return (ct->type == CT_EXPFCN);
+}
+
+static ctype
+ctbase_getExpectFunction (/*@notnull@*/ ctbase ct)
+{
+  llassert (ctbase_isExpectFunction (ct));
+  return ct->contents.base;
+}
+
 static bool
 ctbase_genMatch (ctbase c1, ctbase c2, bool force, bool arg, bool def, bool deep)
 {
@@ -1654,7 +1818,7 @@ ctbase_makeArray (ctype b)
 }
 
 static /*@notnull@*/ /*@only@*/ ctbase
-ctbase_makeFixedArray (ctype b, long size)
+ctbase_makeFixedArray (ctype b, size_t size)
 {
   ctbase c = ctbase_new ();
 
@@ -1825,6 +1989,23 @@ static /*@only@*/ ctbase
   return (c);
 }
 
+static bool ctbase_isAnytype (/*@notnull@*/ ctbase b)
+{
+  /*
+  ** A unknown|dne conj is a special representation for an anytype.
+  */
+
+  if (b->type == CT_CONJ)
+    {
+      /*@access ctype@*/
+      return (b->contents.conj->a == ctype_unknown
+             && b->contents.conj->b == ctype_dne);
+      /*@noaccess ctype@*/ 
+    }
+  
+  return FALSE;
+}
+
 static ctype
 ctbase_getConjA (/*@notnull@*/ ctbase c)
 {
@@ -2499,12 +2680,14 @@ ctbase_almostEqual (ctbase c1, ctbase c2)
   called by ctype_getArraySize
 */
 
-long int ctbase_getArraySize (ctbase ctb)
+size_t ctbase_getArraySize (ctbase ctb)
 {
-  llassert (ctbase_isDefined (ctb) );
-  
-  llassert (ctbase_isFixedArray(ctb) );
+  /*drl 1/25/2002 fixed discovered by Jim Francis */
+  ctbase r;
   
-  return (ctb->contents.farray->size);
+  llassert (ctbase_isDefined (ctb) );
+  r = ctbase_realType (ctb);
+  llassert (ctbase_isFixedArray(r) );
 
+  return (r->contents.farray->size);
 }
This page took 0.053318 seconds and 4 git commands to generate.