]> andersk Git - splint.git/blobdiff - src/ctype.c
Added llgrammar_gen2.h
[splint.git] / src / ctype.c
index 757a4c1d1d68526ce2d8acb23d65b18ff30d194c..1227234bf28fe2a1b1330e4d3384aeaf735c15b8 100644 (file)
@@ -17,8 +17,8 @@
 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 ** MA 02111-1307, USA.
 **
-** For information on splint: splint@cs.virginia.edu
-** To report a bug: splint-bug@cs.virginia.edu
+** For information on splint: info@splint.org
+** To report a bug: splint-bug@splint.org
 ** For more information: http://www.splint.org
 */
 /*
@@ -80,7 +80,7 @@ ctkind
 ctkind_fromInt (int i)
 {
   /*@+enumint@*/
-  if (i < CTK_UNKNOWN || i > CTK_COMPLEX)
+  if (i < CTK_ANYTYPE || i > CTK_COMPLEX)
     {
       llcontbug (message ("ctkind_fromInt: out of range: %d", i));
       return CTK_INVALID;
@@ -315,9 +315,59 @@ ctype_makePointer (ctype c)
     }
 }
 
-ctype ctype_makeFixedArray (ctype c, long size)
+ctype ctype_makeFixedArray (ctype c, size_t size)
 {
-  return (cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c));
+  ctype res;
+  res = cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c);
+  return res;
+}
+
+ctype ctype_makeInnerFixedArray (ctype c, size_t size)
+{
+  ctype res;
+
+  if (ctype_isFixedArray (c))
+    {
+      ctype cb = ctype_baseArrayPtr (c);
+      size_t osize = ctype_getArraySize (c);
+      
+      res = ctype_makeFixedArray (ctype_makeInnerFixedArray (cb, size), osize);
+    }
+  else if (ctype_isArray (c))
+    {
+      ctype cb = ctype_baseArrayPtr (c);
+
+      res = ctype_makeArray (ctype_makeInnerFixedArray (cb, size));
+    }
+  else
+    {
+      res = ctype_makeFixedArray (c, size);
+    }
+
+  DPRINTF (("Make inner fixed array: %s", ctype_unparse (res)));
+  return res;
+}
+
+ctype ctype_makeInnerArray (ctype c)
+{
+  ctype res;
+
+  DPRINTF (("Make inner array: %s", ctype_unparse (c)));
+
+  if (ctype_isFixedArray (c))
+    {
+      ctype cb = ctype_baseArrayPtr (c);
+      size_t osize = ctype_getArraySize (c);
+      
+      res = ctype_makeFixedArray (ctype_makeInnerArray (cb), osize);
+    }
+  else
+    {
+      res = ctype_makeArray (c);
+    }
+
+  DPRINTF (("Make inner array: %s", ctype_unparse (res)));
+  return res;
 }
 
 ctype
@@ -326,6 +376,8 @@ ctype_makeArray (ctype c)
   ctentry cte = ctype_getCtentry (c);
   ctype clp = ctentry_getArray (cte);
 
+  DPRINTF (("Make array: %s", ctype_unparse (c)));
+
   if /*@+enumint@*/ (clp == CTK_DNE) /*@=enumint@*/
     {
       ctype cnew = cttable_addDerived (CTK_ARRAY, ctbase_makeArray (c), c);
@@ -333,7 +385,9 @@ ctype_makeArray (ctype c)
       return (cnew);
     }
   else
-    return clp;
+    {
+      return clp;
+    }
 }
 
 /*
@@ -626,6 +680,20 @@ ctype ctype_expectFunction (ctype c)
   return (cttable_addComplex (ctbase_expectFunction (c)));
 }
 
+ctype ctype_dontExpectFunction (ctype c)
+{
+  ctbase ctb = ctype_getCtbase (c);
+
+  /* what about this?
+  if (!ctype_isAP (c))
+    {
+      c = ctype_makePointer (c);
+    }
+  */
+
+  return (ctbase_getExpectFunction (ctb));
+}
+
 /*
 ** makeRealFunction: function returning base
 */
@@ -1703,13 +1771,6 @@ bool ctype_isIncompleteArray (ctype c)
   return (ctype_isArray (c) && !ctype_isFixedArray (c));
 }
 
-bool ctype_isFixedArray (ctype c)
-{
-  if (ctype_isElips (c)) return FALSE;
-
-  return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
-}
-
 bool
 ctype_isArrayPtr (ctype c)
 {
@@ -1752,6 +1813,10 @@ ctype_unparse (ctype c)
     {
       return cstring_makeLiteralTemp ("?");
     }
+  else if (ctype_isAnytype (c))
+    {
+      return cstring_makeLiteralTemp ("<any>");
+    }
   else
     {
       /*@-modobserver@*/
@@ -1848,6 +1913,7 @@ ctype_getBaseType (ctype c)
 
   switch (ctentry_getKind (cte))
     {
+    case CTK_ANYTYPE:
     case CTK_UNKNOWN:
     case CTK_INVALID:
     case CTK_PLAIN:
@@ -2470,8 +2536,18 @@ ctype ctype_combine (ctype dominant, ctype modifier)
   
 ctype ctype_resolve (ctype c)
 {
-  if (ctype_isUnknown (c)) return ctype_int;
-  return c;
+  if (ctype_isUnknown (c)) 
+    {
+      return ctype_int;
+    }
+  else if (c == ctype_anytype)
+    {
+      return ctype_unknown;
+    }
+  else
+    {
+      return c;
+    }
 }
 
 ctype ctype_fromQual (qual q)
@@ -2593,7 +2669,9 @@ static /*@observer@*/ ctbase ctype_getCtbase (ctype c)
        llbuglit ("ctype_getCtbase: ctype dne");
       if (c == ctype_elipsMarker)
        llbuglit ("ctype_getCtbase: elips marker");
-      
+      if (c == ctype_anytype)
+       llbuglit ("ctype_getCtbase: ctype anytype");
+
       llfatalbug (message ("ctype_getCtbase: ctype out of range: %d", c));
       BADEXIT;
     }
@@ -2636,6 +2714,8 @@ ctype_getCtentry (ctype c)
     }
   else if (c == CTK_UNKNOWN) 
     llcontbuglit ("ctype_getCtentry: ctype unknown");
+  else if (c == CTK_ANYTYPE) 
+    llcontbuglit ("ctype_getCtentry: ctype unknown");
   else if (c == CTK_INVALID)
     llcontbuglit ("ctype_getCtentry: ctype invalid (ctype_undefined)");
   else if (c == CTK_DNE)
@@ -2651,20 +2731,28 @@ ctype_getCtentry (ctype c)
   /*@=enumint@*/
 }
 
+
+bool ctype_isFixedArray (ctype c)
+{
+  if (ctype_isElips (c)) return FALSE;
+
+  return (ctbase_isFixedArray (ctype_getCtbaseSafe (c)));
+}
+
+
 /*drl 11/28/2000 */
 /* requires that the type is an fixed array */
 /* return the size of the array */
 
-long int ctype_getArraySize (ctype c)
+size_t ctype_getArraySize (ctype c)
 {
-  long int size;
-  ctentry cte = ctype_getCtentry (c);
+  size_t size;
+
   ctbase ctb;
 
   llassert (ctype_isFixedArray (c));
-  llassert ((ctentry_getKind (cte) ==  CTK_COMPLEX) || (ctentry_getKind (cte) == CTK_ARRAY));
 
-  ctb = cte->ctbase;
+  ctb = ctype_getCtbaseSafe(c);
   size = ctbase_getArraySize (ctb);
 
   DPRINTF ((message ("ctype_getArraySize: got fixed array size of %s / %d ",
This page took 0.043467 seconds and 4 git commands to generate.