Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

aliasTable.c File Reference

#include "lclintMacros.nf"
#include "basic.h"

Go to the source code of this file.

Defines

#define ATINVALID   -1

Functions

aliasTable aliasTable_new ()
aliasTable aliasTable_addMustAlias ( aliasTable s, sRef sr, sRef al)
void aliasTable_clearAliases (aliasTable s, sRef sr)
sRefSet aliasTable_aliasedBy (aliasTable s, sRef sr)
sRefSet aliasTable_canAlias (aliasTable s, sRef sr)
aliasTable aliasTable_copy (aliasTable s)
aliasTable aliasTable_levelUnionSeq ( aliasTable t1, aliasTable t2, int level)
aliasTable aliasTable_levelUnion ( aliasTable t1, aliasTable t2, int level)
aliasTable aliasTable_levelUnionNew (aliasTable t1, aliasTable t2, int level)
cstring aliasTable_unparse (aliasTable s)
void aliasTable_fixSrefs (aliasTable s)
void aliasTable_free ( aliasTable s)
void aliasTable_checkGlobs (aliasTable t)


Define Documentation

#define ATINVALID   -1
 

Definition at line 32 of file aliasTable.c.


Function Documentation

aliasTable aliasTable_addMustAlias ( aliasTable s,
sRef sr,
sRef al )
 

Definition at line 109 of file aliasTable.c.

Referenced by usymtab_addForceMustAlias(), and usymtab_addMustAlias().

00112 {
00113   int ind;
00114   sRefSet ss;
00115   
00116   llassert (NOALIAS (sr, al));
00117 
00118   if (aliasTable_isUndefined (s))
00119     {
00120       s = aliasTable_newEmpty ();
00121       ind = ATINVALID;
00122     }
00123   else
00124     {
00125       ind = aliasTable_lookupRefs (s, sr);
00126     }
00127   
00128   ss = aliasTable_canAlias (s, al); 
00129   
00130   
00131   if (ind == ATINVALID)
00132     {
00133       if (s->nspace <= 0) {
00134         aliasTable_grow (s);
00135       }
00136 
00137       s->nspace--;
00138       s->keys[s->nelements] = sr;
00139       s->values[s->nelements] = sRefSet_single (al); 
00140       ind = s->nelements;
00141       s->nelements++;      
00142     }
00143   else
00144     {
00145       s->values[ind] = sRefSet_insert (s->values[ind], al); 
00146     }
00147   
00148   s->values[ind] = sRefSet_unionExcept (s->values[ind], ss, s->keys[ind]); 
00149 
00150   sRefSet_free (ss);
00151   return s;
00152 }

sRefSet aliasTable_aliasedBy ( aliasTable s,
sRef sr )
 

Definition at line 368 of file aliasTable.c.

Referenced by usymtab_aliasedBy().

00369 { 
00370   if (sRef_isConj (sr))
00371     {
00372       return (sRefSet_unionFree (aliasTable_aliasedBy (s, sRef_getConjA (sr)),
00373                                  aliasTable_aliasedBy (s, sRef_getConjB (sr))));
00374     }
00375 
00376   return (aliasTable_aliasedByAux (s, sr, 0));
00377 }

sRefSet aliasTable_canAlias ( aliasTable s,
sRef sr )
 

Definition at line 379 of file aliasTable.c.

Referenced by aliasTable_addMustAlias(), usymtab_allAliases(), and usymtab_canAlias().

00380 {
00381   sRefSet res;
00382 
00383     
00384   if (sRef_isConj (sr))
00385     {
00386       res = sRefSet_unionFree (aliasTable_canAlias (s, sRef_getConjA (sr)),
00387                                aliasTable_canAlias (s, sRef_getConjB (sr)));
00388     }
00389   else
00390     {
00391       res = aliasTable_canAliasAux (s, sr, 0);
00392           }
00393 
00394     return res;
00395 }

void aliasTable_checkGlobs ( aliasTable t )
 

Definition at line 755 of file aliasTable.c.

Referenced by usymtab_checkFinalScope().

00756 {
00757   aliasTable_elements (t, key, value)
00758     {
00759       sRef root = sRef_getRootBase (key);
00760 
00761       if (sRef_isAliasCheckedGlobal (root))
00762         {
00763           sRefSet_realElements (value, sr)
00764             {
00765               root = sRef_getRootBase (sr);
00766 
00767               if (((sRef_isAliasCheckedGlobal (root) 
00768                     && !(sRef_similar (root, key)))
00769                    || sRef_isAnyParam (root))
00770                   && !sRef_isExposed (root))
00771                 {
00772                   if (sRef_isAliasCheckedGlobal (key))
00773                     {
00774                       if (!(sRef_isShared (key) 
00775                             && sRef_isShared (root)))
00776                         {
00777                           voptgenerror 
00778                             (FLG_GLOBALIAS,
00779                              message 
00780                              ("Function returns with %q variable %q aliasing %q %q",
00781                               cstring_makeLiteral (sRef_isRealGlobal (key) 
00782                                                    ? "global" : "file static"),
00783                               sRef_unparse (key),
00784                               cstring_makeLiteral (sRef_isAnyParam (root) 
00785                                                    ? "parameter" : "global"),
00786                               sRef_unparse (sr)),
00787                              g_currentloc);
00788                         }
00789                     }
00790 
00791                 }
00792             } end_sRefSet_realElements;
00793         }
00794       else if (sRef_isAnyParam (key) || sRef_isAnyParam (root))
00795         {
00796           sRefSet_realElements (value, sr)
00797             {
00798               root = sRef_getRootBase (sr);
00799               
00800               if (sRef_isAliasCheckedGlobal (root) 
00801                   && !sRef_isExposed (root)
00802                   && !sRef_isDead (key)
00803                   && !sRef_isShared (root))
00804                 {
00805                   voptgenerror 
00806                     (FLG_GLOBALIAS,
00807                      message ("Function returns with parameter %q aliasing %q %q",
00808                               sRef_unparse (key),
00809                               cstring_makeLiteral (sRef_isRealGlobal (root) 
00810                                                    ? "global" : "file static"),
00811                               sRef_unparse (sr)),
00812                      g_currentloc);
00813                 }
00814             } end_sRefSet_realElements;
00815         }
00816       else
00817         {
00818           ;
00819         }
00820     } end_aliasTable_elements;
00821 }

void aliasTable_clearAliases ( aliasTable s,
sRef sr )
 

Definition at line 197 of file aliasTable.c.

Referenced by usymtab_clearAlias().

00198 {
00199   if (aliasTable_isUndefined (s))
00200     {
00201       return;
00202     }
00203   else
00204     {
00205       sRef rb = sRef_getRootBase (sr);
00206 
00207             
00208       if (!sRef_isCvar (sr) && sRef_isLocalVar (rb))
00209         {
00210           int ind = aliasTable_lookupRefs (s, rb);
00211           
00212           if (ind != ATINVALID)
00213             {
00214               sRefSet al = s->values[ind];
00215               
00216                       
00217               sRefSet_realElements (al, el)
00218                 {
00219                                   
00220                   if (sRef_isParam (el))
00221                     {
00222                       if (sRef_sameName (el, rb))
00223                         {
00224                           sRef fb = sRef_fixBase (sr, el); 
00225 
00226                           aliasTable_clearAliasesAux (s, fb); 
00227                         }
00228                     }
00229                 } end_sRefSet_realElements ;
00230             }
00231         }
00232       
00233       aliasTable_clearAliasesAux (s, sr); 
00234     }  
00235 }

aliasTable aliasTable_copy ( aliasTable s )
 

Definition at line 497 of file aliasTable.c.

Referenced by usymtab_altBranch(), usymtab_enterScope(), usymtab_newCase(), usymtab_switchBranch(), and usymtab_trueBranch().

00498 {
00499   if (aliasTable_isEmpty (s))
00500     {
00501       return aliasTable_undefined;
00502     }
00503   else
00504     {
00505       aliasTable t = (aliasTable) dmalloc (sizeof (*s));
00506       int i;
00507 
00508       t->nelements = s->nelements;
00509       t->nspace = 0;
00510       t->keys = (sRef *) dmalloc (sizeof (*s->keys) * s->nelements);
00511       t->values = (sRefSet *) dmalloc (sizeof (*s->values) * t->nelements);
00512         
00513       for (i = 0; i < s->nelements; i++)
00514         {
00515           t->keys[i] = s->keys[i];
00516           t->values[i] = sRefSet_newCopy (s->values[i]);
00517         }
00518 
00519       return t;
00520     }
00521 }

void aliasTable_fixSrefs ( aliasTable s )
 

Definition at line 718 of file aliasTable.c.

Referenced by usymtab_popBranches().

00719 {
00720   int i;
00721 
00722   if (aliasTable_isUndefined (s)) return;
00723 
00724   for (i = 0; i < s->nelements; i++)
00725     {
00726       sRef old = s->keys[i];
00727 
00728       if (sRef_isLocalVar (old))
00729         {
00730           s->keys[i] = uentry_getSref (sRef_getUentry (old));
00731         }
00732 
00733       sRefSet_fixSrefs (s->values[i]);
00734     }
00735 }

void aliasTable_free ( aliasTable s )
 

Definition at line 738 of file aliasTable.c.

Referenced by usymtab_altBranch(), usymtab_popBranches(), and usymtab_trueBranch().

00739 {
00740   int i;
00741   
00742   if (aliasTable_isUndefined (s)) return;
00743   
00744   for (i = 0; i < s->nelements; i++)
00745     {
00746       sRefSet_free (s->values[i]); 
00747     }
00748   
00749   sfree (s->values);
00750   sfree (s->keys);
00751   sfree (s);
00752 }

aliasTable aliasTable_levelUnion ( aliasTable t1,
aliasTable t2,
int level )
 

Definition at line 636 of file aliasTable.c.

Referenced by aliasTable_levelUnionNew(), usymtab_newCase(), usymtab_popAndBranch(), and usymtab_popOrBranch().

00637 {
00638   if (aliasTable_isUndefined (t1))
00639     {
00640       if (aliasTable_isUndefined (t2)) 
00641         {
00642           return t1;
00643         }
00644       else
00645         {
00646           t1 = aliasTable_newEmpty ();
00647         }
00648     }
00649   else
00650     {
00651       aliasTable_levelPrune (t1, level);
00652     }
00653 
00654   aliasTable_elements (t2, key, cvalue)
00655     {
00656       sRefSet value = sRefSet_newCopy (cvalue);
00657 
00658       if (sRef_lexLevel (key) <= level)
00659         {
00660           sRefSet_levelPrune (value, level);
00661 
00662           if (sRefSet_size (value) > 0)
00663             {
00664               int ind = aliasTable_lookupRefs (t1, key);
00665               
00666               if (ind == ATINVALID)
00667                 {
00668                   t1 = aliasTable_addSet (t1, key, value);
00669                 }
00670               else
00671                 {
00672                   t1->values[ind] = sRefSet_union (t1->values[ind], value);
00673                   sRefSet_free (value);
00674                 }
00675             }
00676           else
00677             {
00678               sRefSet_free (value); 
00679             }
00680         }
00681       else
00682         {
00683           sRefSet_free (value); 
00684         }
00685     } end_aliasTable_elements;
00686 
00687     return t1;
00688 }

aliasTable aliasTable_levelUnionNew ( aliasTable t1,
aliasTable t2,
int level )
 

Definition at line 690 of file aliasTable.c.

Referenced by usymtab_popBranches().

00691 {
00692   aliasTable ret = aliasTable_levelUnion (aliasTable_copy (t1), t2, level);
00693 
00694   return ret;
00695 }

aliasTable aliasTable_levelUnionSeq ( aliasTable t1,
aliasTable t2,
int level )
 

Definition at line 578 of file aliasTable.c.

Referenced by usymtab_quietExitScope().

00580 {
00581   if (aliasTable_isUndefined (t2))
00582     {
00583       return t1;
00584     }
00585 
00586   if (aliasTable_isUndefined (t1))
00587     {
00588       t1 = aliasTable_newEmpty ();
00589     }
00590   else
00591     {
00592       aliasTable_levelPrune (t1, level);
00593     }
00594 
00595   aliasTable_elements (t2, key, value)
00596     {
00597       if (sRef_lexLevel (key) <= level)
00598         {
00599           int ind = aliasTable_lookupRefs (t1, key);
00600 
00601           sRefSet_levelPrune (value, level);
00602               
00603           if (ind == ATINVALID)
00604             {
00605               /* okay, t2 is killed */
00606               /*@-exposetrans@*/ /*@-dependenttrans@*/ 
00607               t1 = aliasTable_addSet (t1, key, value);
00608               /*@=exposetrans@*/ /*@=dependenttrans@*/ 
00609             }
00610           else
00611             {
00612               sRefSet_free (t1->values[ind]);
00613 
00614               /*@-dependenttrans@*/ /* okay, t2 is killed */
00615               t1->values[ind] = value;
00616               /*@=dependenttrans@*/
00617             } 
00618         }
00619       else
00620         {
00621           /*@-exposetrans@*/ /*@-dependenttrans@*/ 
00622           sRefSet_free (value);
00623           /*@=exposetrans@*/ /*@=dependenttrans@*/ 
00624         }
00625 
00626     } end_aliasTable_elements;
00627   
00628   sfree (t2->keys);
00629   sfree (t2->values);
00630   sfree (t2);
00631 
00632     return t1;
00633 }

aliasTable aliasTable_new ( )
 

Definition at line 42 of file aliasTable.c.

00043 {
00044   return (aliasTable_undefined);
00045 }

cstring aliasTable_unparse ( aliasTable s )
 

Definition at line 698 of file aliasTable.c.

Referenced by usymtab_unparseAliases().

00699 {
00700    cstring st = cstring_undefined;
00701 
00702    if (aliasTable_isUndefined (s)) return (cstring_makeLiteral ("<NULL>"));
00703 
00704    aliasTable_elements (s, key, value)
00705      {
00706        st = message ("%q\t%q -> %q\n", st, sRef_unparse (key), 
00707                      sRefSet_unparse (value));
00708      } end_aliasTable_elements;
00709 
00710    return st;
00711 }


Generated at Fri Nov 3 18:57:49 2000 for LCLint by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000