]> andersk Git - splint.git/blobdiff - src/sRef.c
*** empty log message ***
[splint.git] / src / sRef.c
index ee5fe0d1db9a0493a195d0c0c770684ff2afaf46..b254996cf6ee7d961aaedbbe787218aae8068bab 100644 (file)
@@ -87,7 +87,6 @@ static speckind speckind_fromInt (int p_i);
 static bool sRef_equivalent (sRef p_s1, sRef p_s2);
 static bool sRef_isDeepUnionField (sRef p_s);
 static void sRef_addDeriv (/*@notnull@*/ sRef p_s, /*@notnull@*/ /*@exposed@*/ sRef p_t);
-static /*@dependent@*/ sRef sRef_makeResultType (ctype p_ct) /*@*/ ;
 static bool sRef_checkModify (sRef p_s, sRefSet p_sl) /*@*/ ;
 
 static void sRef_checkMutable (/*@unused@*/ sRef s)
@@ -183,6 +182,7 @@ static /*@only@*/ cstring sRef_unparseWithArgs (sRef p_s, uentryList p_args);
 static /*@only@*/ cstring sRef_unparseNoArgs (sRef p_s);
 
 static /*@exposed@*/ sRef sRef_findDerivedPointer (sRef p_s);
+static /*@exposed@*/ sRef sRef_findDerivedArrayFetch (/*@notnull@*/ sRef, bool, int, bool) ;
 static /*@exposed@*/ sRef sRef_findDerivedField (/*@notnull@*/ sRef p_rec, cstring p_f);
 static /*@exposed@*/ sRef
   sRef_getDeriv (/*@notnull@*/ /*@returned@*/ sRef p_set, sRef p_guide);
@@ -359,6 +359,7 @@ static /*@dependent@*/ /*@notnull@*/ /*@special@*/ sRef
   s->safe = TRUE;
   s->modified = FALSE;
   s->immut = FALSE;
+  s->val = multiVal_undefined;
 
   s->type = ctype_unknown;
   s->defstate = SS_UNKNOWN;
@@ -466,6 +467,16 @@ sRef_addDeriv (/*@notnull@*/ sRef s, /*@notnull@*/ /*@exposed@*/ sRef t)
          return;
        }
 
+      /* This sometimes fails: (evans 2001-07-12)
+      if (sRef_isArrayFetch (t))
+       {
+         DPRINTF (("Derived fetch: %s / %s / %s",
+                   sRef_unparseFull (s), sRef_unparseFull (t),
+                   sRef_unparseFull (t->info->arrayfetch->arr)));
+         llassert (t->info->arrayfetch->arr == s);
+       }
+      */
+
       if (sRef_isFileOrGlobalScope (s))
        {
          if (context_inFunctionLike () 
@@ -686,18 +697,31 @@ void sRef_clearGlobalScope ()
 }
 
 static bool oldInFunction = FALSE;
+static int nestedScope = 0;
 
 void sRef_setGlobalScopeSafe ()
 {
-  oldInFunction = inFunction;
-  DPRINTF (("leave function"));
+  if (nestedScope == 0)
+    {
+      oldInFunction = inFunction;
+    }
+  
+  nestedScope++;
+  DPRINTF (("leave function safe"));
   inFunction = FALSE;
 }
 
 void sRef_clearGlobalScopeSafe ()
 {
-    inFunction = oldInFunction;
-    DPRINTF (("clear function: %s", bool_unparse (inFunction)));
+  nestedScope--;
+  llassert (nestedScope >= 0);
+  
+  if (nestedScope == 0)
+    {
+      inFunction = oldInFunction;
+    }
+
+  DPRINTF (("clear function: %s", bool_unparse (inFunction)));
 }
 
 void sRef_enterFunctionScope ()
@@ -709,8 +733,7 @@ void sRef_enterFunctionScope ()
 }
 
 void sRef_exitFunctionScope ()
-{
-  
+{  
   if (inFunction)
     {
       DPRINTF (("Exit function scope."));
@@ -2133,6 +2156,7 @@ sRef_closeEnough (sRef s1, sRef s2)
   s is an sRef of a formal paramenter in a function call constraint
   we trys to return a constraint expression derived from the actual parementer of a function call.
 */
+
 /*@only@*/ constraintExpr sRef_fixConstraintParam (/*@observer@*/  sRef s, /*@observer@*/ /*@temp@*/ exprNodeList args)
 {
   constraintExpr ce;
@@ -2144,7 +2168,7 @@ sRef_closeEnough (sRef s1, sRef s2)
     {
     case SK_RESULT:
       {
-       //      s = sRef_saveCopy(s);
+       /* s = sRef_saveCopy(s); */ /*@i523@*/
        ce = constraintExpr_makeTermsRef (s);
        return ce;
       }
@@ -2161,7 +2185,7 @@ sRef_closeEnough (sRef s1, sRef s2)
       {
        sRef temp;
        temp = (sRef_makePointer (sRef_fixBaseParam (s->info->ref, args)));
-       //temp = sRef_saveCopy(temp);
+       /* temp = sRef_saveCopy(temp); */ /*@i523@*/
        ce = constraintExpr_makeTermsRef (temp);
        return ce;
       }
@@ -2197,7 +2221,8 @@ sRef_closeEnough (sRef s1, sRef s2)
     default:
       {
        sRef temp;
-      llcontbug ((message("Trying to do fixConstraintParam on nonparam, nonglobal: %q for function with arguments %q", sRef_unparse (s), exprNodeList_unparse(args) ) ));
+       llcontbug (message ("Trying to do fixConstraintParam on nonparam, nonglobal: %q for function with arguments %q",
+                           sRef_unparse (s), exprNodeList_unparse(args)));
       temp = sRef_saveCopy(s);
       ce = constraintExpr_makeTermsRef (temp);
 
@@ -2300,7 +2325,7 @@ sRef_undumpGlobal (char **c)
        reader_checkChar (c, '@');
        nullstate = nstate_fromInt (reader_getInt (c));
 
-       ret = sRef_makeGlobal (uid, ctype_unknown);
+       ret = sRef_makeGlobal (uid, ctype_unknown, stateInfo_currentLoc ());
        sRef_setNullStateN (ret, nullstate);
        ret->defstate = defstate;
        return ret;
@@ -2333,8 +2358,7 @@ sRef_undumpGlobal (char **c)
   BADEXIT;
 }
 
-/*@exposed@*/ sRef
-sRef_undump (char **c)
+static /*@exposed@*/ sRef sRef_undumpBody (char **c)
 {
   char p = **c;
 
@@ -2343,11 +2367,11 @@ sRef_undump (char **c)
   switch (p)
     {
     case 'g':
-      return (sRef_makeGlobal (usymId_fromInt (reader_getInt (c)), ctype_unknown));
+      return (sRef_makeGlobal (usymId_fromInt (reader_getInt (c)), ctype_unknown, stateInfo_currentLoc ()));
     case 'p':
-      return (sRef_makeParam (reader_getInt (c), ctype_unknown));
+      return (sRef_makeParam (reader_getInt (c), ctype_unknown, stateInfo_makeLoc (g_currentloc)));
     case 'r':
-      return (sRef_makeResultType (ctype_undump (c)));
+      return (sRef_makeResult (ctype_undump (c)));
     case 'a':
       {
        if ((**c >= '0' && **c <= '9') || **c == '-')
@@ -2435,8 +2459,21 @@ sRef_undump (char **c)
   BADEXIT;
 }
 
-/*@only@*/ cstring
-sRef_dump (sRef s)
+/*@exposed@*/ sRef sRef_undump (char **c)
+{
+  sRef res = sRef_undumpBody (c);
+
+  if (reader_optCheckChar (c, '='))
+    {
+      multiVal mv = multiVal_undump (c);
+      sRef_setValue (res, mv);
+      reader_checkChar (c, '=');
+    }
+
+  return res;
+}
+
+static /*@only@*/ cstring sRef_dumpBody (sRef s)
 {
   if (sRef_isInvalid (s))
     {
@@ -2504,8 +2541,22 @@ sRef_dump (sRef s)
   BADEXIT;
 }
 
+/*@only@*/ cstring sRef_dump (sRef s)
+{
+  cstring res = sRef_dumpBody (s);
+
+  if (sRef_hasValue (s))
+    {
+      res = message ("%q=%q=", res, multiVal_dump (sRef_getValue (s)));
+    }
+
+  return res;
+}
+
 cstring sRef_dumpGlobal (sRef s)
 {
+  llassert (!sRef_hasValue (s));
+
   if (sRef_isInvalid (s))
     {
       return (cstring_makeLiteral ("-"));
@@ -2747,9 +2798,7 @@ sRef_unparseWithArgs (sRef s, uentryList args)
              return uentry_getName (ue);
          }
 
-       return (message ("<bad param: %q / args %q",
-                        sRef_unparseDebug (s),
-                        uentryList_unparse (args)));
+       return (message ("parameter %d", s->info->paramno + 1));
       }
     case SK_ARRAYFETCH:
       if (s->info->arrayfetch->indknown)
@@ -2919,7 +2968,14 @@ sRef_unparseDebug (sRef s)
     case SK_TYPE:
       return (message ("<type %s>", ctype_unparse (s->type)));
     case SK_CONST:
-      return (message ("<const %s>", ctype_unparse (s->type)));
+      if (sRef_hasValue (s))
+       {
+         return (message ("<const %s=%q>", ctype_unparse (s->type), multiVal_unparse (sRef_getValue (s))));
+       }
+      else
+       {
+         return (message ("<const %s>", ctype_unparse (s->type)));
+       }
     case SK_RESULT:
       return (message ("<result %s>", ctype_unparse (s->type)));
     case SK_SPECIAL:
@@ -3048,7 +3104,7 @@ bool sRef_isUnconstrained (sRef s)
 }
 
 static /*@dependent@*/ /*@notnull@*/ sRef 
-  sRef_makeCvarAux (int level, usymId index, ctype ct)
+  sRef_makeCvarAux (int level, usymId index, ctype ct, /*@only@*/ stateInfo stinfo)
 {
   sRef s = sRef_newRef ();
   
@@ -3089,13 +3145,13 @@ static /*@dependent@*/ /*@notnull@*/ sRef
 
   DPRINTF (("Made cvar: [%p] %s", s, sRef_unparseDebug (s)));
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s);
+  s->state = context_createValueTable (s, stinfo); 
   return s;
 }
 
-/*@dependent@*/ sRef sRef_makeCvar (int level, usymId index, ctype ct)
+/*@dependent@*/ sRef sRef_makeCvar (int level, usymId index, ctype ct, /*@only@*/ stateInfo stinfo)
 {
-  return (sRef_makeCvarAux (level, index, ct));
+  return (sRef_makeCvarAux (level, index, ct, stinfo));
 }
 
 int sRef_lexLevel (sRef s)
@@ -3117,9 +3173,9 @@ int sRef_lexLevel (sRef s)
 }
 
 sRef
-sRef_makeGlobal (usymId l, ctype ct)
+sRef_makeGlobal (usymId l, ctype ct, /*@only@*/ stateInfo stinfo)
 {
-  return (sRef_makeCvar (globScope, l, ct));
+  return (sRef_makeCvar (globScope, l, ct, stinfo));
 }
 
 void
@@ -3131,7 +3187,7 @@ sRef_setParamNo (sRef s, int l)
 }
 
 /*@dependent@*/ sRef
-sRef_makeParam (int l, ctype ct)
+sRef_makeParam (int l, ctype ct, stateInfo stinfo)
 {
   sRef s = sRef_new ();
 
@@ -3145,7 +3201,7 @@ sRef_makeParam (int l, ctype ct)
   /* (probably defined, unless its an out parameter) */
 
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s);
+  s->state = context_createValueTable (s, stinfo);
   return s;
 }
 
@@ -3233,7 +3289,7 @@ static bool sRef_isZerothArrayFetch (/*@notnull@*/ sRef s)
        }
 
       llassert (valueTable_isUndefined (s->state));
-      s->state = context_createValueTable (s);
+      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
       return s;
     }
 }
@@ -3406,7 +3462,7 @@ sRef_makeObject (ctype o)
   s->info = (sinfo) dmalloc (sizeof (*s->info));
   s->info->object = o;
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s);
+  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
   return s;
 }
 
@@ -3425,7 +3481,7 @@ sRef sRef_makeExternal (sRef t)
   s->type = t->type;
   s->info->ref = t; /* sRef_copy (t); */ /*@i32 was exposed@*/
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s);
+  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
   return s;
 }
 
@@ -3441,7 +3497,7 @@ sRef sRef_makeExternal (sRef t)
       
       s->type = t->type;
       llassert (valueTable_isUndefined (s->state));
-      s->state = context_createValueTable (s);
+      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
       return s;
     }
   else
@@ -3888,6 +3944,13 @@ sRef_mergeStateAux (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other,
   ** Merge value table states
   */
 
+
+  /*@i3245@*/
+# if 0
+  /*
+  ** This doesn't do anything.  And its broken too...
+  */
+
   valueTable_elements (res->state, key, sv) 
     {
       stateValue os = valueTable_lookup (other->state, key);
@@ -3907,6 +3970,8 @@ sRef_mergeStateAux (/*@notnull@*/ sRef res, /*@notnull@*/ sRef other,
        DPRINTF (("Val: %d / %s", val, msg));
       */
   } end_valueTable_elements ; 
+# endif
+
 }
 
 static sRefSet
@@ -4105,7 +4170,6 @@ static bool checkDeadState (/*@notnull@*/ sRef el, bool tbranch, fileloc loc)
                                         ? "kept" : "released")),
           loc))
        {
-                 
          if (sRef_isKept (el))
            {
              sRef_showAliasInfo (el);      
@@ -4243,7 +4307,7 @@ sRef sRef_makeConj (/*@exposed@*/ /*@returned@*/ sRef a, /*@exposed@*/ sRef b)
       s->aliaskind = alkind_resolve (a->aliaskind, b->aliaskind);
 
       llassert (valueTable_isUndefined (s->state));
-      s->state = context_createValueTable (s);
+      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
       return s;
     }
   else
@@ -4328,31 +4392,22 @@ sRef_makeGlobalMarker (void)
 {
   sRef s = sRef_makeSpecial (SR_GLOBALMARKER);
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createGlobalMarkerValueTable ();
+  s->state = context_createGlobalMarkerValueTable (stateInfo_undefined);
   return s;
 }
 
-static sRef
-sRef_makeResultType (ctype ct)
-{
-  sRef res = sRef_makeResult ();
-
-  res->type = ct;
-  return res;
-}
-
 sRef
-sRef_makeResult ()
+sRef_makeResult (ctype c)
 {
   sRef s = sRef_newRef ();
   
   s->kind = SK_RESULT;
-  s->type = ctype_unknown;
+  s->type = c;
   s->defstate = SS_UNKNOWN; 
   s->aliaskind = AK_UNKNOWN;
   sRef_setNullStateN (s, NS_UNKNOWN);
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s);
+  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
 
   DPRINTF (("Result: [%p] %s", s, sRef_unparseFull (s)));
   return s;
@@ -4969,6 +5024,8 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear)
   sRef_checkMutable (s);
   if (sRef_isInvalid (s)) return;
 
+  DPRINTF (("Set defined: %s", sRef_unparseFull (s)));
+
   if (s->defstate != SS_DEFINED && fileloc_isDefined (loc))
     {
       s->definfo = stateInfo_updateLoc (s->definfo, loc);
@@ -4976,16 +5033,31 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear)
   
   s->defstate = SS_DEFINED;
   
+  DPRINTF (("Set defined: %s", sRef_unparseFull (s)));
+
   /* e.g., if x is allocated, *x = 3 defines x */
   
   if (s->kind == SK_PTR)
     {
       sRef p = s->info->ref;
-      
-      if (p->defstate == SS_ALLOCATED)
+      sRef arr;
+
+      if (p->defstate == SS_ALLOCATED
+         || p->defstate == SS_SPECIAL) /* evans 2001-07-12: shouldn't need this */
        {
          sRef_setDefinedAux (p, loc, clear);
        }
+
+      /* 
+      ** Defines a[0] also:
+      */
+
+      arr = sRef_findDerivedArrayFetch (p, FALSE, 0, FALSE);
+
+      if (sRef_isValid (arr))
+       {
+         sRef_setDefinedAux (arr, loc, clear);
+       }
     }
   else if (s->kind == SK_ARRAYFETCH) 
     {
@@ -4994,11 +5066,12 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear)
        {
          sRef p = s->info->arrayfetch->arr;
          sRef ptr = sRef_constructPointer (p);
-         
+
          if (sRef_isValid (ptr))
            {
              if (ptr->defstate == SS_ALLOCATED 
-                 || ptr->defstate == SS_UNDEFINED)
+                 || ptr->defstate == SS_UNDEFINED
+                 || ptr->defstate == SS_SPECIAL) /* evans 2001-07-12: shouldn't need this */
                {
                  sRef_setDefinedAux (ptr, loc, clear);
                }
@@ -5008,7 +5081,8 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear)
            {
              ;
            }
-         else if (p->defstate == SS_ALLOCATED || p->defstate == SS_PDEFINED)
+         else if (p->defstate == SS_ALLOCATED || p->defstate == SS_PDEFINED
+                  || p->defstate == SS_SPECIAL) /* evans 2001-07-12: shouldn't need this */
            {
              p->defstate = SS_DEFINED;
            }
@@ -5046,7 +5120,17 @@ static void sRef_setDefinedAux (sRef s, fileloc loc, bool clear)
   if (clear)
     {
       sRef_clearDerived (s);
-    }  
+    } 
+  else
+    {
+      /* evans 2001-07-12: need to define the derived references */
+      sRefSet_elements (s->deriv, el)
+       {
+         el->defstate = SS_DEFINED;
+       } end_sRefSet_elements ;
+    }
+
+  DPRINTF (("Set defined: %s", sRef_unparseFull (s)));
 }
 
 static void sRef_setPartialDefined (sRef s, fileloc loc)
@@ -5066,6 +5150,7 @@ void sRef_setPartialDefinedComplete (sRef s, fileloc loc)
 
 void sRef_setDefinedComplete (sRef s, fileloc loc)
 {
+  DPRINTF (("Set defined complete: %s", sRef_unparseFull (s)));
   sRef_innerAliasSetComplete (sRef_setDefined, s, loc);
 }
 
@@ -5641,6 +5726,7 @@ sRef sRef_copy (sRef s)
       t->modified = s->modified;
       t->immut = FALSE; /* Note mutability is not copied. */
       t->type = s->type;
+      t->val = multiVal_copy (s->val);
 
       t->info = sinfo_copy (s);
       t->defstate = s->defstate;
@@ -6375,6 +6461,16 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
   
   if (sRef_isValid (s))
     {
+      /* evans 2001-07-12: this is bogus, clean-up hack */
+      if (s->info->arrayfetch->arr != arr)
+       {
+         sRef res;
+         check (sRefSet_delete (arr->deriv, s));
+         res = sRef_buildArrayFetch (arr);
+         sRef_copyState (res, s);
+         return res;
+       }
+
       sRef_setExKind (s, sRef_getExKind (arr), g_currentloc);
       return s;
     }
@@ -6397,8 +6493,10 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
          sRef_addDeriv (arr, s);
        }
       
-      llassert (valueTable_isUndefined (s->state));
-      s->state = context_createValueTable (s);
+      if (valueTable_isUndefined (s->state))
+       {
+         s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+       }
 
       return (s);
     }
@@ -6422,7 +6520,19 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
       
   if (sRef_isValid (s))
     {
+      /* evans 2001-07-12: this is bogus, clean-up hack */
+      if (s->info->arrayfetch->arr != arr)
+       {
+         sRef res;
+         check (sRefSet_delete (arr->deriv, s));
+         res = sRef_buildArrayFetchKnown (arr, i);
+         sRef_copyState (res, s);
+         return res;
+       }
+
       sRef_setExKind (s, sRef_getExKind (arr), g_currentloc);      
+
+      llassert (s->info->arrayfetch->arr == arr);
       return s;
     }
   else
@@ -6443,7 +6553,7 @@ void sRef_setArrayFetchState (/*@notnull@*/ /*@exposed@*/ sRef s,
       sRef_addDeriv (arr, s);
 
       llassert (valueTable_isUndefined (s->state));
-      s->state = context_createValueTable (s);
+      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
 
       return (s);
     }
@@ -6601,26 +6711,16 @@ static /*@exposed@*/ sRef sRef_constructDerefAux (sRef t, bool isdead)
       
       if (sRef_isValid (s))
        {
+         DPRINTF (("Found array fetch: %s", sRef_unparseFull (s)));
          return s;
        }
       else
        {
          sRef ret = sRef_constructPointer (t);
 
-         /*
-         ** This is necessary to prevent infinite depth
-         ** in checking complete destruction.  
-         */
+         DPRINTF (("Constructed pointer: %s", sRef_unparseFull (ret)));
 
-         if (isdead)
-           {
-             /* ret->defstate = SS_UNKNOWN;  */
-             return ret; 
-           }
-         else
-           {
-             return ret;
-           }
+         return ret;
        }
     }
   else
@@ -6646,6 +6746,8 @@ sRef_constructPointerAux (/*@notnull@*/ /*@exposed@*/ sRef t)
   ctype rt = t->type;
   ctype st;
   
+  llassert (valueTable_isUndefined (s->state));
+
   s->kind = SK_PTR;
   s->info = (sinfo) dmalloc (sizeof (*s->info));
   s->info->ref = t; /* sRef_copy (t); */ /*@i32*/
@@ -6656,7 +6758,7 @@ sRef_constructPointerAux (/*@notnull@*/ /*@exposed@*/ sRef t)
     }
   
   st = ctype_realType (s->type);  
-    
+
   if (t->defstate == SS_UNDEFINED)
     {
       s->defstate = SS_UNUSEABLE;
@@ -6678,15 +6780,18 @@ sRef_constructPointerAux (/*@notnull@*/ /*@exposed@*/ sRef t)
     {
       s->aliaskind = AK_UNKNOWN;
     }
-  
+
   sRef_setExKind (s, sRef_getExKind (t), fileloc_undefined);
   sRef_setTypeState (s);
-  
+
   s->oaliaskind = s->aliaskind;
   s->oexpkind = s->expkind;
 
-  llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s);
+  if (valueTable_isUndefined (s->state))
+    {
+      s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
+    }
+
   return s;
 }
 
@@ -7035,7 +7140,7 @@ sRef_makeType (ctype ct)
   s->oaliaskind = s->aliaskind;
   s->oexpkind = s->expkind;
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s);
+  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
 
   DPRINTF (("Create: %s", sRef_unparseFull (s)));
   return s;
@@ -7056,8 +7161,6 @@ sRef_makeConst (ctype ct)
   /* start modification */
   s->bufinfo.bufstate = BB_NULLTERMINATED;
   /* end modification */
-
-  
   if (ctype_isUA (ct))
     {
       typeId uid = ctype_typeId (ct);
@@ -7074,7 +7177,7 @@ sRef_makeConst (ctype ct)
   s->oexpkind = s->expkind;
 
   llassert (valueTable_isUndefined (s->state));
-  s->state = context_createValueTable (s);
+  s->state = context_createValueTable (s, stateInfo_makeLoc (g_currentloc));
 
   return s;
 }
@@ -7571,8 +7674,8 @@ sRef_showMetaStateInfo (sRef s, cstring key)
   if (stateValue_hasLoc (val))
     {
       llgenindentmsg 
-       (message ("Meta state %qbecomes %s", sRef_unparseOpt (s), 
-                 metaStateInfo_unparseValue (minfo, stateValue_getValue (val))),
+       (message ("%qbecomes %q", sRef_unparseOpt (s), 
+                 stateValue_unparseValue (val, minfo)),
         stateValue_getLoc (val));
     }
 }
@@ -8228,7 +8331,6 @@ sRef_innerAliasSetComplete (void (predf) (sRef, fileloc), sRef s, fileloc loc)
       inner = s->info->ref;
       aliases = usymtab_allAliases (inner);
       ct = sRef_getType (inner);
-
       
       sRefSet_realElements (aliases, current)
        {
@@ -8251,28 +8353,38 @@ sRef_innerAliasSetComplete (void (predf) (sRef, fileloc), sRef s, fileloc loc)
       aliases = usymtab_allAliases (inner);
       ct = sRef_getType (inner);
 
+      DPRINTF (("Array fetch: %s", sRefSet_unparse (aliases)));
+
       sRefSet_realElements (aliases, current)
        {
          if (sRef_isValid (current))
            {
              current = sRef_updateSref (current);
-             
+             DPRINTF (("Current: %s", sRef_unparseFull (current)));
+
              if (ctype_equal (ct, sRef_getType (current)))
                {
-                                 
                  if (s->info->arrayfetch->indknown)
                    {
                      sRef af = sRef_makeArrayFetchKnown (current, s->info->arrayfetch->ind);
-                     
+                     DPRINTF (("Defining: %s", sRef_unparseFull (af)));
+                     llassert (af->info->arrayfetch->arr == current);
                      ((*predf)(af, loc));
                    }
                  else
                    {
                      sRef af = sRef_makeArrayFetch (current);
-                     
+                     llassert (af->info->arrayfetch->arr == current);
+                     DPRINTF (("Defining: %s", sRef_unparseFull (af)));
                      ((*predf)(af, loc));
                    }
                }
+             else
+               {
+                 DPRINTF (("Type mismatch: %s / %s",
+                           ctype_unparse (ct),
+                           ctype_unparse (sRef_getType (current))));
+               }
            }
        } end_sRefSet_realElements;
 
@@ -9581,8 +9693,17 @@ void sRef_setMetaStateValue (sRef s, cstring key, int value, fileloc loc)
        {
          DPRINTF (("Updating state: %s: %s %d / %s", sRef_unparse (s), key, value,
                    fileloc_unparse (loc)));
-         valueTable_update 
-           (s->state, key, stateValue_create (value, stateInfo_makeLoc (loc)));
+         if (valueTable_contains (s->state, key))
+           {
+             valueTable_update 
+               (s->state, key, stateValue_create (value, stateInfo_makeLoc (loc)));
+           }
+         else
+           {
+             valueTable_insert 
+               (s->state, cstring_copy (key), stateValue_create (value, stateInfo_makeLoc (loc)));
+           }
+
          DPRINTF (("After: %s", sRef_unparseFull (s)));
        }
     }
@@ -9623,7 +9744,7 @@ bool sRef_checkMetaStateValue (sRef s, cstring key, int value)
          stateValue val;
          
          val = valueTable_lookup (s->state, key);
-         llassert (stateValue_isDefined (val));
+         /* Okay if its not defined, just returns stateValue_undefined */
          return val;
        }
       else
@@ -9664,14 +9785,14 @@ bool sRef_makeStateSpecial (sRef s)
 
   if (s->defstate == SS_UNKNOWN || s->defstate == SS_DEFINED || s->defstate == SS_SPECIAL)
     {
-      s->aliaskind = AK_IMPTEMP;
+      /* s->aliaskind = AK_IMPTEMP; */ /* evans 2001-07-23 shouldn't effect alias state */
       s->defstate = SS_SPECIAL;
       DPRINTF (("Made special: %s", sRef_unparseFull (s)));
       return TRUE;
     }
   else
     {
-      s->aliaskind = AK_IMPTEMP;
+      /* s->aliaskind = AK_IMPTEMP; */
       s->defstate = SS_SPECIAL;
       return FALSE;
     }
@@ -9779,11 +9900,25 @@ long int sRef_getArraySize (sRef p_s) /*@*/ {
   return (ctype_getArraySize (c) );
 }
 
+void sRef_setValue (sRef s, multiVal val)
+{
+  llassert (sRef_isValid (s));
+  multiVal_free (s->val);
+  s->val = val;
+}
 
+bool sRef_hasValue (sRef s)
+{
+  return (sRef_isValid (s)
+         && multiVal_isDefined (s->val));
+}
 
+multiVal sRef_getValue (sRef s)
+{
+  if (sRef_isValid (s))
+    {
+      return s->val;
+    }
 
-
-
-
-
-
+  return multiVal_undefined;
+}
This page took 0.089649 seconds and 4 git commands to generate.