x.f = y now prunes new edge's beta by alpha at x
[IRC.git] / Robust / src / Analysis / OwnershipAnalysis / ReachabilitySet.java
index 842098d10d09d1fdd401090a3a0c8c731c4e8ea1..f7a5721ac255b1b980618a8a273ee16641b9c4ff 100644 (file)
@@ -12,16 +12,22 @@ public class ReachabilitySet extends Canonical {
 
     public ReachabilitySet() {
        possibleReachabilities = new HashSet<TokenTupleSet>();
+       //TokenTupleSet ttsEmpty = new TokenTupleSet().makeCanonical();
+       //possibleReachabilities.add( ttsEmpty );       
     }
 
     public ReachabilitySet( TokenTupleSet tts ) {
+       this();
        assert tts != null;
-       possibleReachabilities = new HashSet<TokenTupleSet>();
        possibleReachabilities.add( tts );
     }
 
     public ReachabilitySet( TokenTuple tt ) {
-       this( new TokenTupleSet( tt ) );
+       this( new TokenTupleSet( tt ).makeCanonical() );
+    }
+
+    public ReachabilitySet( HashSet<TokenTupleSet> possibleReachabilities ) {
+       this.possibleReachabilities = possibleReachabilities;
     }
 
     public ReachabilitySet( ReachabilitySet rs ) {
@@ -38,6 +44,25 @@ public class ReachabilitySet extends Canonical {
        return possibleReachabilities.contains( tts );
     }
 
+    public ReachabilitySet add( TokenTupleSet tts ) {
+       ReachabilitySet rsOut = new ReachabilitySet( tts );
+       return this.union( rsOut );
+    }
+
+    public ReachabilitySet increaseArity( Integer token ) {
+       assert token != null;
+
+       HashSet<TokenTupleSet> possibleReachabilitiesNew = new HashSet<TokenTupleSet>();
+
+       Iterator itr = iterator();
+       while( itr.hasNext() ) {
+           TokenTupleSet tts = (TokenTupleSet) itr.next();
+           possibleReachabilitiesNew.add( tts.increaseArity( token ) );
+       }
+
+       return new ReachabilitySet( possibleReachabilitiesNew ).makeCanonical(); 
+    }
+
     public Iterator iterator() {
        return possibleReachabilities.iterator();
     }
@@ -73,8 +98,63 @@ public class ReachabilitySet extends Canonical {
 
        return rsOut.makeCanonical();
     }
+    
+    /*
+    public ReachabilitySet unionUpArity( ReachabilitySet rsIn ) {
+       assert rsIn != null;
+
+       ReachabilitySet rsOut = new ReachabilitySet();
+       Iterator itrIn;
+       Iterator itrThis;       
+
+       itrIn = rsIn.iterator();
+       while( itrIn.hasNext() ) {
+           TokenTupleSet ttsIn = (TokenTupleSet) itrIn.next();
+
+           boolean foundEqual = false;
+
+           itrThis = this.iterator();
+           while( itrThis.hasNext() ) {
+               TokenTupleSet ttsThis = (TokenTupleSet) itrThis.next();
+
+               if( ttsIn.equalWithoutArity( ttsThis ) ) {
+                   rsOut.possibleReachabilities.add( ttsIn.unionUpArity( ttsThis ) );
+                   foundEqual = true;
+                   continue;
+               }
+           }
+
+           if( !foundEqual ) {
+               rsOut.possibleReachabilities.add( ttsIn );
+           }
+       }
+
+       itrThis = this.iterator();
+       while( itrThis.hasNext() ) {
+           TokenTupleSet ttsThis = (TokenTupleSet) itrThis.next();
+
+           boolean foundEqual = false;
+
+           itrIn = rsIn.iterator();
+           while( itrIn.hasNext() ) {
+               TokenTupleSet ttsIn = (TokenTupleSet) itrIn.next();
+
+               if( ttsThis.equalWithoutArity( ttsIn ) ) {
+                   foundEqual = true;
+                   continue;
+               }
+           }
+
+           if( !foundEqual ) {
+               rsOut.possibleReachabilities.add( ttsThis );
+           }
+       }
+
+       return rsOut.makeCanonical();
+    }  
+    */
 
-    public ChangeTupleSet unionUpArity( ReachabilitySet rsIn ) {
+    public ChangeTupleSet unionUpArityToChangeSet( ReachabilitySet rsIn ) {
        assert rsIn != null;
 
        ChangeTupleSet ctsOut = new ChangeTupleSet();
@@ -121,6 +201,47 @@ public class ReachabilitySet extends Canonical {
     }
 
 
+    public ReachabilitySet ageTokens( AllocationSite as ) {    
+       assert as != null;
+       
+       ReachabilitySet rsOut = new ReachabilitySet();
+
+       Iterator itrS = this.iterator();
+       while( itrS.hasNext() ) {
+           TokenTupleSet tts = (TokenTupleSet) itrS.next();
+           rsOut.possibleReachabilities.add( tts.ageTokens( as ) );
+       }
+
+       return rsOut.makeCanonical();
+    }
+
+
+    public ReachabilitySet pruneBy( ReachabilitySet rsIn ) {
+       assert rsIn != null;
+
+       ReachabilitySet rsOut = new ReachabilitySet();
+
+       Iterator itrB = this.iterator();
+       while( itrB.hasNext() ) {
+           TokenTupleSet ttsB = (TokenTupleSet) itrB.next();
+
+           boolean subsetExists = false;
+
+           Iterator itrA = rsIn.iterator();
+           while( itrA.hasNext() && !subsetExists ) {
+               TokenTupleSet ttsA = (TokenTupleSet) itrA.next();
+           
+               if( ttsA.isSubset( ttsB ) ) {
+                   subsetExists = true;
+                   rsOut.possibleReachabilities.add( ttsB );               
+               }
+           }
+       }
+
+       return rsOut.makeCanonical();   
+    }
+
+
     public boolean equals( Object o ) {
        if( !(o instanceof ReachabilitySet) ) {
            return false;
@@ -140,11 +261,13 @@ public class ReachabilitySet extends Canonical {
 
        Iterator i = this.iterator();
        while( i.hasNext() ) {
-           s += "\\n  "+i.next();
+           s += i.next();
+           if( i.hasNext() ) {
+               s += "\\n";
+           }
        }
 
        s += "]";
-
        return s;       
     }
 
@@ -153,11 +276,13 @@ public class ReachabilitySet extends Canonical {
 
        Iterator i = this.iterator();
        while( i.hasNext() ) {
-           s += "\n  "+i.next();
+           s += i.next();
+           if( i.hasNext() ) {
+               s += "\n";
+           }
        }
 
-       s += "\n]";
-
+       s += "]";
        return s;       
     }
 }