]> andersk Git - splint.git/blobdiff - src/ctype.c
Fixed fatal errors in constraint checking.
[splint.git] / src / ctype.c
index 6a309aca62cb8c131e0b41133bd005cc4ccf0f94..7fc16c481bef2841d0c72adcb6db297c3b9fac9f 100644 (file)
@@ -154,8 +154,9 @@ ctype_createUser (typeId u)
 ctype
 ctype_createAbstract (typeId u)
 {
- /* requires: ctype_createAbstract (u) is never called more than once for any u. */
- /*           [ tested by cttable_addFullSafe, not really required ]            */
+  /* requires: ctype_createAbstract (u) is never called more than once for any u. */
+  /*           [ tested by cttable_addFullSafe, not really required ]            */
+
   return (cttable_addFullSafe (ctentry_makeNew (CTK_PLAIN, ctbase_createAbstract (u))));
 }
 
@@ -235,7 +236,8 @@ ctype_realishType (ctype c)
 bool
 ctype_isUA (ctype c)
 {
-  return (!ctype_isUnknown (c) && ctbase_isUA (ctype_getCtbase (c)));
+  return (!ctype_isUnknown (c) 
+         && ctbase_isUA (ctype_getCtbase (c)));
 }
 
 bool
@@ -315,24 +317,23 @@ ctype_makePointer (ctype c)
     }
 }
 
-ctype ctype_makeFixedArray (ctype c, long size)
+ctype ctype_makeFixedArray (ctype c, size_t size)
 {
   ctype res;
   res = cttable_addDerived (CTK_ARRAY, ctbase_makeFixedArray (c, size), c);
   return res;
 }
 
-ctype ctype_makeInnerFixedArray (ctype c, long size)
+ctype ctype_makeInnerFixedArray (ctype c, size_t size)
 {
   ctype res;
 
   if (ctype_isFixedArray (c))
     {
       ctype cb = ctype_baseArrayPtr (c);
-      long osize = ctype_getArraySize (c);
-
-      res = ctype_makeFixedArray (ctype_makeInnerFixedArray (cb, size),
-                                 osize);
+      size_t osize = ctype_getArraySize (c);
+      
+      res = ctype_makeFixedArray (ctype_makeInnerFixedArray (cb, size), osize);
     }
   else if (ctype_isArray (c))
     {
@@ -358,10 +359,9 @@ ctype ctype_makeInnerArray (ctype c)
   if (ctype_isFixedArray (c))
     {
       ctype cb = ctype_baseArrayPtr (c);
-      long osize = ctype_getArraySize (c);
-
-      res = ctype_makeFixedArray (ctype_makeInnerArray (cb),
-                                 osize);
+      size_t osize = ctype_getArraySize (c);
+      
+      res = ctype_makeFixedArray (ctype_makeInnerArray (cb), osize);
     }
   else
     {
@@ -1139,7 +1139,11 @@ ctype_makeConjAux (ctype c1, ctype c2, bool isExplicit)
 ctype
 ctype_makeExplicitConj (ctype c1, ctype c2)
 {
-  if (ctype_isFunction (c1) && !ctype_isFunction (c2))
+  if (ctype_isAnytype (c1) || ctype_isAnytype (c2))
+    {
+      return ctype_makeAnytype ();
+    }
+  else if (ctype_isFunction (c1) && !ctype_isFunction (c2))
     {
       ctype ret = ctype_makeExplicitConj (ctype_getReturnType (c1), c2);
 
@@ -1168,6 +1172,27 @@ static ctype ivb = ctype_unknown;  /* int | void * | bool */
 static ctype ivbf = ctype_unknown; /* int | void * | bool | float */
 static ctype cuc = ctype_unknown;  /* char | unsigned char */
 
+static ctype cany = ctype_unknown;
+
+ctype 
+ctype_makeAnytype ()
+{
+  if (cany == ctype_unknown)
+    {
+      cany = ctype_makeConj (ctype_unknown, ctype_dne);
+      llassert (ctype_isAnytype (cany));
+    }
+
+  DPRINTF (("make anytype: %s", ctype_unparse (cany)));
+  return cany;
+}
+
+bool 
+ctype_isAnytype (ctype c)
+{
+  return (c == cany);
+} 
+
 static void
 ctype_recordConj (ctype c)
 {
@@ -1288,7 +1313,15 @@ ctype_makeConj (ctype c1, ctype c2)
 
   DPRINTF (("Make conj: %s / %s", ctype_unparse (c1), ctype_unparse (c2)));
 
-  if (ctype_isUnknown (c1)) 
+  if (ctype_isAnytype (c1))
+    {
+      return c1;
+    }
+  else if (ctype_isAnytype (c2))
+    {
+      return c2;
+    }
+  else if (ctype_isUnknown (c1)) 
     {
       return c2;
     }
@@ -1479,7 +1512,6 @@ ctype_makeConj (ctype c1, ctype c2)
        {
          ;
        }
-
       
       return (cttable_addComplex (ctbase_makeConj (c1, c2, FALSE)));
     }
@@ -1788,7 +1820,7 @@ ctype_typeId (ctype c)
 cstring
 ctype_unparseDeclaration (ctype c, /*@only@*/ cstring name)
 {
-  llassert (! (ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
+  llassert (!(ctype_isElips (c) || ctype_isMissingParamsMarker (c)));
 
   if (ctype_isUnknown (c))
     {
@@ -1811,14 +1843,14 @@ ctype_unparse (ctype c)
     {
       return cstring_makeLiteralTemp ("-");
     }
-  else if (ctype_isUnknown (c))
-    {
-      return cstring_makeLiteralTemp ("?");
-    }
   else if (ctype_isAnytype (c))
     {
       return cstring_makeLiteralTemp ("<any>");
     }
+  else if (ctype_isUnknown (c))
+    {
+      return cstring_makeLiteralTemp ("?");
+    }
   else
     {
       /*@-modobserver@*/
@@ -1915,7 +1947,6 @@ ctype_getBaseType (ctype c)
 
   switch (ctentry_getKind (cte))
     {
-    case CTK_ANYTYPE:
     case CTK_UNKNOWN:
     case CTK_INVALID:
     case CTK_PLAIN:
@@ -1967,13 +1998,14 @@ ctype_getBaseType (ctype c)
 }
 
 ctype
-ctype_adjustPointers (int np, ctype c)
+ctype_adjustPointers (pointers p, ctype c)
 {
-  
+  int np = pointers_depth (p);
+
   if (ctype_isFunction (c))
     {
       c = ctype_makeParamsFunction
-        (ctype_adjustPointers (np, ctype_getReturnType (c)),
+        (ctype_adjustPointers (p, ctype_getReturnType (c)),
         uentryList_copy (ctype_argsFunction (c)));
     }
   else
@@ -2181,6 +2213,16 @@ ctype_createForwardUnion (cstring n)
   return (ct);
 }
 
+ctype
+ctype_createForwardEnum (cstring n)
+{
+  uentry ue  = uentry_makeEnumTag (n, ctype_unknown, fileloc_undefined);
+  ctype ct = usymtab_supForwardTypeEntry (ue);
+
+  cstring_free (n);
+  return (ct);
+}
+
 ctype
 ctype_removePointers (ctype c)
 {
@@ -2538,18 +2580,13 @@ ctype ctype_combine (ctype dominant, ctype modifier)
   
 ctype ctype_resolve (ctype c)
 {
-  if (ctype_isUnknown (c)
+  if (ctype_isUnknown (c) && !ctype_isAnytype (c))
     {
+      DPRINTF (("Resolving to int: %s", ctype_unparse (c)));
       return ctype_int;
     }
-  else if (c == ctype_anytype)
-    {
-      return ctype_unknown;
-    }
-  else
-    {
-      return c;
-    }
+
+  return c;
 }
 
 ctype ctype_fromQual (qual q)
@@ -2742,9 +2779,9 @@ bool ctype_isFixedArray (ctype c)
 /* 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;
+  size_t size;
 
   ctbase ctb;
 
This page took 0.0554559999999999 seconds and 4 git commands to generate.