special union of reachability sets works correctly now
authorjjenista <jjenista>
Tue, 1 Jul 2008 21:49:10 +0000 (21:49 +0000)
committerjjenista <jjenista>
Tue, 1 Jul 2008 21:49:10 +0000 (21:49 +0000)
Robust/src/Analysis/OwnershipAnalysis/ChangeTupleSet.java
Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java
Robust/src/Analysis/OwnershipAnalysis/TokenTuple.java
Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java
Robust/src/Tests/OwnershipAnalysisTest/testTokens/Main.java

index c0d90104aa4f0131b1b8a730beadd1ae0f0c5356..5593285b1ce5a2be9785e6850e5f54cc2d12736f 100644 (file)
@@ -8,7 +8,7 @@ import java.io.*;
 
 public class ChangeTupleSet {
 
-    public HashSet<ChangeTuple> changeTuples;
+    private HashSet<ChangeTuple> changeTuples;
 
     public ChangeTupleSet() {
        changeTuples = new HashSet<ChangeTuple>();
@@ -38,6 +38,15 @@ public class ChangeTupleSet {
     }
 
     public String toString() {
-       return changeTuples.toString();
+       String s = "[";
+
+       Iterator i = this.iterator();
+       while( i.hasNext() ) {
+           s += "\n  "+i.next();
+       }
+
+       s += "\n]";
+
+       return s;
     }
 }
index 6f612414bada4286e7a23e04ec364cf6a5270065..83d6bfce40b5de2ba81e5c8c6de80ec5653456ad 100644 (file)
@@ -8,12 +8,17 @@ import java.io.*;
 
 public class ReachabilitySet {
 
-    public HashSet<TokenTupleSet> possibleReachabilities;
+    private HashSet<TokenTupleSet> possibleReachabilities;
 
     public ReachabilitySet() {
        possibleReachabilities = new HashSet<TokenTupleSet>();
     }
 
+    public ReachabilitySet( TokenTupleSet tts ) {
+       possibleReachabilities = new HashSet<TokenTupleSet>();
+       possibleReachabilities.add( tts );
+    }
+
     public ReachabilitySet( ReachabilitySet rs ) {
        possibleReachabilities = (HashSet<TokenTupleSet>) rs.possibleReachabilities.clone(); // again, DEEP COPY?!
     }
@@ -59,49 +64,45 @@ public class ReachabilitySet {
                while( itrRelement.hasNext() ) {
                    TokenTuple e = (TokenTuple) itrRelement.next();
 
-                   if( o.contains( e ) ) {
-                       theUnion.union( new TokenTupleSet( e.increaseArity() ) );
+                   if( o.containsToken( e.getToken() ) ) {
+                       theUnion = theUnion.union( new TokenTupleSet( e.increaseArity() ) );
+                   } else {
+                       theUnion = theUnion.union( new TokenTupleSet( e ) );
                    }
                }
+
+               Iterator itrOelement = o.iterator();
+               while( itrOelement.hasNext() ) {
+                   TokenTuple e = (TokenTuple) itrOelement.next();
+
+                   if( !theUnion.containsToken( e.getToken() ) ) {
+                       theUnion = theUnion.union( new TokenTupleSet( e ) );
+                   }
+               }
+
+               if( !theUnion.isEmpty() ) {
+                   ctsOut = ctsOut.union( 
+                              new ChangeTupleSet( 
+                                new ChangeTuple( o, theUnion )
+                                                 )
+                                         );
+               }
            }
        }
 
        return ctsOut;
     }
-}
-
-/*
-Set specialUnion( Set O, Set R ) {
-  Set C = {}
-
-  foreach o in O {
-    foreach r in R {
-
-      Set theUnion = {}
 
-      foreach e in r {
-        if o.contains( e ) {
-          if e.isSummaryToken() { // wait, stronger condition?
-            theUnion.add( e.copy().increaseArity() )
-          } else {
-            theUnion.add( e.copy() )
-          }
-        }
-      }
+    public String toString() {
+       String s = "[";
 
-      foreach e in o {
-        if !theUnion.contains( e ) {
-           theUnion.add( e.copy() )
-        }
-      }
+       Iterator i = this.iterator();
+       while( i.hasNext() ) {
+           s += "\n  "+i.next();
+       }
 
-      if !theUnion.isEmpty() {
-        C.add( <o, theUnion> )
-      }
+       s += "\n]";
 
+       return s;       
     }
-  }
-
-  return C
 }
-*/
index 4d496987d89acb22ca0d30981395893a6bd851ac..e135a68060bc2e32a25b9e8dc268973b9f1c0579 100644 (file)
@@ -63,14 +63,14 @@ public class TokenTuple
     public String toString() {
        String s = "";
        if( isNewSummary ) {
-           s = "sum";
+           s = "S";
        }
 
        String t = "1";
        if( arity == ARITY_MANY ) {
-           t = "many";
+           t = "M";
        }
 
-       return new String( "<"+token+s+", "+t+">" );
+       return new String( "<"+token+s+","+t+">" );
     }
 }
index 626e5327fd9e679957b70373979e73d7c094a626..9a81a6583d1fb99f79ceec2e66f8ea949acc823e 100644 (file)
@@ -8,7 +8,7 @@ import java.io.*;
 
 public class TokenTupleSet {
 
-    public HashSet<TokenTuple> tokenTuples;
+    private HashSet<TokenTuple> tokenTuples;
 
     public TokenTupleSet() {
        tokenTuples = new HashSet<TokenTuple>();
@@ -33,10 +33,26 @@ public class TokenTupleSet {
        return ttsOut;
     }
 
-    public boolean contains( TokenTuple tt ) {
+    public boolean isEmpty() {
+       return tokenTuples.isEmpty();
+    }
+
+    public boolean containsTuple( TokenTuple tt ) {
        return tokenTuples.contains( tt );
     }
 
+    // this should be a hash table so we can do this by key
+    public boolean containsToken( Integer token ) {
+       Iterator itr = tokenTuples.iterator();
+       while( itr.hasNext() ) {
+           TokenTuple tt = (TokenTuple) itr.next();
+           if( token.equals( tt.getToken() ) ) {
+               return true;
+           }
+       }
+       return false;
+    }
+
     public String toString() {
        return tokenTuples.toString();
     }
index b6a0508938bc96e9e108c9d95fe66c33908992d3..603ce6c94e6b341ee267de581debf4b6b8e89c30 100644 (file)
@@ -30,7 +30,9 @@ public class Main {
                                         true,
                                         TokenTuple.ARITY_ONE );
 
-       TokenTuple tt1 = tt0.copy();
+       TokenTuple tt1 = new TokenTuple( new Integer( 1 ),
+                                        true,
+                                        TokenTuple.ARITY_ONE );
 
        TokenTuple tt2 = new TokenTuple( new Integer( 2 ),
                                         true,
@@ -52,7 +54,7 @@ public class Main {
        test( "tt2 equals tt3?", false, tt2.equals( tt3 ) );
        test( "tt3 equals tt2?", false, tt3.equals( tt2 ) );
 
-       tt1.increaseArity();
+       tt1 = tt1.increaseArity();
 
        test( "tt1 equals tt2?", false, tt1.equals( tt2 ) );
        test( "tt2 equals tt1?", false, tt2.equals( tt1 ) );
@@ -72,5 +74,38 @@ public class Main {
        System.out.println( "tts4 is "+tts4 );
        System.out.println( "tts5 is "+tts5 );
        System.out.println( "tts6 is "+tts6 );
+
+       ReachabilitySet rs0 = new ReachabilitySet( tts0 );
+       rs0 = rs0.union( new ReachabilitySet( tts2 ) );
+       rs0 = rs0.union( new ReachabilitySet( tts5 ) );
+
+       System.out.println( "rs0 is "+rs0 );
+
+       TokenTuple tt4 = new TokenTuple( new Integer( 4 ),
+                                        true,
+                                        TokenTuple.ARITY_ONE );
+
+       /*      TokenTuple tt5 = new TokenTuple( new Integer( 4 ),
+                                        true,
+                                        TokenTuple.ARITY_ONE );
+       */
+       TokenTuple tt6 = new TokenTuple( new Integer( 6 ),
+                                        false,
+                                        TokenTuple.ARITY_ONE );
+
+       TokenTupleSet tts7 = new TokenTupleSet( tt4 );
+       //TokenTupleSet tts8 = new TokenTupleSet( tt5 );
+       TokenTupleSet tts9 = new TokenTupleSet( tt1 );
+       tts9 = tts9.union( tts2 );
+
+       ReachabilitySet rs1 = new ReachabilitySet( tts7 );
+       //rs1 = rs1.union( new ReachabilitySet( tts8 ) );
+       rs1 = rs1.union( new ReachabilitySet( tts9 ) );
+
+       System.out.println( "rs1 is "+rs1 );
+
+
+       ChangeTupleSet cts0 = rs0.unionUpArity( rs1 );
+       System.out.println( "cts0 is "+cts0 );
     }
 }
\ No newline at end of file