From 89c65d2fff0fa66d3f51f0110d5f6128f00ba9ca Mon Sep 17 00:00:00 2001 From: jjenista Date: Wed, 9 Jul 2008 21:07:04 +0000 Subject: [PATCH] Added reachability classes, all of which are extensions of Canonical such that after makeCanonical() two equivalent reachability classes are actually the same class. This was the bug that kept the orginial analysis tests from terminating and now they run fine. --- .../Analysis/OwnershipAnalysis/Canonical.java | 20 ++++ .../OwnershipAnalysis/ChangeTuple.java | 6 +- .../OwnershipAnalysis/ChangeTupleSet.java | 21 +++- .../OwnershipAnalysis/HeapRegionNode.java | 6 ++ .../OwnershipAnalysis/OwnershipAnalysis.java | 19 ++++ .../OwnershipAnalysis/OwnershipGraph.java | 101 +++++++----------- .../OwnershipAnalysis/ReachabilitySet.java | 33 ++++-- .../ReferenceEdgeProperties.java | 23 ++++ .../OwnershipAnalysis/TokenTuple.java | 10 +- .../OwnershipAnalysis/TokenTupleSet.java | 21 +++- Robust/src/Makefile | 1 + .../OwnershipAnalysisTest/test01/makefile | 3 + .../OwnershipAnalysisTest/test01/test01.java | 7 +- .../testTokens/Main.java | 80 +++++++++++++- 14 files changed, 269 insertions(+), 82 deletions(-) create mode 100644 Robust/src/Analysis/OwnershipAnalysis/Canonical.java diff --git a/Robust/src/Analysis/OwnershipAnalysis/Canonical.java b/Robust/src/Analysis/OwnershipAnalysis/Canonical.java new file mode 100644 index 00000000..f2d5901e --- /dev/null +++ b/Robust/src/Analysis/OwnershipAnalysis/Canonical.java @@ -0,0 +1,20 @@ +package Analysis.OwnershipAnalysis; + +import IR.*; +import IR.Flat.*; +import java.util.*; +import java.io.*; + +public class Canonical { + + private static Hashtable canon = new Hashtable(); + + public static Canonical makeCanonical( Canonical c ) { + if( canon.containsKey( c ) ) { + return canon.get( c ); + } + + canon.put( c, c ); + return c; + } +} diff --git a/Robust/src/Analysis/OwnershipAnalysis/ChangeTuple.java b/Robust/src/Analysis/OwnershipAnalysis/ChangeTuple.java index 9a1f8bdf..296e578d 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/ChangeTuple.java +++ b/Robust/src/Analysis/OwnershipAnalysis/ChangeTuple.java @@ -12,7 +12,7 @@ import java.io.*; // THIS CLASS IS IMMUTABLE! -public class ChangeTuple +public class ChangeTuple extends Canonical { private TokenTupleSet toMatch; private TokenTupleSet toAdd; @@ -23,6 +23,10 @@ public class ChangeTuple this.toAdd = toAdd; } + public ChangeTuple makeCanonical() { + return (ChangeTuple) Canonical.makeCanonical( this ); + } + public TokenTupleSet getSetToMatch() { return toMatch; } public TokenTupleSet getSetToAdd() { return toAdd; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/ChangeTupleSet.java b/Robust/src/Analysis/OwnershipAnalysis/ChangeTupleSet.java index 5593285b..afbd0405 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/ChangeTupleSet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/ChangeTupleSet.java @@ -6,7 +6,7 @@ import java.util.*; import java.io.*; -public class ChangeTupleSet { +public class ChangeTupleSet extends Canonical { private HashSet changeTuples; @@ -23,6 +23,10 @@ public class ChangeTupleSet { changeTuples = (HashSet) cts.changeTuples.clone(); //COPY?! } + public ChangeTupleSet makeCanonical() { + return (ChangeTupleSet) Canonical.makeCanonical( this ); + } + public Iterator iterator() { return changeTuples.iterator(); } @@ -30,13 +34,26 @@ public class ChangeTupleSet { public ChangeTupleSet union( ChangeTupleSet ctsIn ) { ChangeTupleSet ctsOut = new ChangeTupleSet( this ); ctsOut.changeTuples.addAll( ctsIn.changeTuples ); - return ctsOut; + return ctsOut.makeCanonical(); } public boolean isSubset( ChangeTupleSet ctsIn ) { return ctsIn.changeTuples.containsAll( this.changeTuples ); } + public boolean equals( Object o ) { + if( !(o instanceof ChangeTupleSet) ) { + return false; + } + + ChangeTupleSet cts = (ChangeTupleSet) o; + return changeTuples.equals( cts.changeTuples ); + } + + public int hashCode() { + return changeTuples.hashCode(); + } + public String toString() { String s = "["; diff --git a/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java b/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java index 1e28f904..08502304 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java +++ b/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java @@ -57,6 +57,7 @@ public class HeapRegionNode extends OwnershipNode { return id; } + public boolean equals( HeapRegionNode hrn ) { assert hrn != null; @@ -64,6 +65,7 @@ public class HeapRegionNode extends OwnershipNode { isSingleObject == hrn.isSingleObject() && isFlagged == hrn.isFlagged() && isNewSummary == hrn.isNewSummary() && + alpha.equals( hrn.getAlpha() ) && description.equals( hrn.getDescription() ); } @@ -116,6 +118,10 @@ public class HeapRegionNode extends OwnershipNode { } + public void setAlpha( ReachabilitySet alpha ) { + this.alpha = alpha; + } + public ReachabilitySet getAlpha() { return alpha; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java index 991bd02b..23d9af6f 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java @@ -318,6 +318,11 @@ public class OwnershipAnalysis { // the final ownership graph result to return as an empty set returnNodesToCombineForCompleteOwnershipGraph = new HashSet(); + + // DEBUG + //int x = 0; + + while( !flatNodesToVisit.isEmpty() ) { FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next(); flatNodesToVisit.remove( fn ); @@ -351,6 +356,20 @@ public class OwnershipAnalysis { if( !og.equals( ogPrev ) ) { setGraphForFlatNode( fn, og ); + // DEBUG + /* + ++x; + + if( x > 5000 ) { + String s = String.format( "%04d", x ); + og.writeGraph( "debug"+s, false, false ); + } + + if( x == 5020 ) { + System.exit( -1 ); + } + */ + for( int i = 0; i < fn.numNext(); i++ ) { FlatNode nn = fn.getNext( i ); flatNodesToVisit.add( nn ); diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index 39fa29d8..0eb63db7 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -24,10 +24,6 @@ public class OwnershipGraph { public HashSet allocationSites; - // CHANGE! Map HRN ID's to token sets (sets of IDs!) - //public Hashtable< HeapRegionNode, HashSet< HashSet > > alpha; - //public Hashtable< touple< HRN, HRN >, HashSet< HashSet > > beta; - public OwnershipGraph( int allocationDepth ) { this.allocationDepth = allocationDepth; @@ -38,8 +34,6 @@ public class OwnershipGraph { paramIndex2id = new Hashtable(); allocationSites = new HashSet (); - - //alpha = new Hashtable< HeapRegionNode, HashSet< HashSet > >(); } @@ -658,6 +652,9 @@ public class OwnershipGraph { // in merge() and equals() methods the suffix A // represents the passed in graph and the suffix // B refers to the graph in this object + // Merging means to take the incoming graph A and + // merge it into B, so after the operation graph B + // is the final result. //////////////////////////////////////////////////// public void merge( OwnershipGraph og ) { @@ -669,9 +666,9 @@ public class OwnershipGraph { mergeReferenceEdges ( og ); mergeId2paramIndex ( og ); mergeAllocationSites( og ); - //mergeTokenSets ( og ); } + protected void mergeOwnershipNodes( OwnershipGraph og ) { Set sA = og.id2hrn.entrySet(); Iterator iA = sA.iterator(); @@ -685,6 +682,12 @@ public class OwnershipGraph { if( !id2hrn.containsKey( idA ) ) { HeapRegionNode hrnB = hrnA.copy(); id2hrn.put( idA, hrnB ); + } else { + // otherwise this is a node present in both graphs + // so make the new reachability set a union of the + // nodes' reachability sets + HeapRegionNode hrnB = id2hrn.get( idA ); + hrnB.setAlpha( hrnB.getAlpha().union( hrnA.getAlpha() ) ); } } @@ -708,7 +711,8 @@ public class OwnershipGraph { // for stroing heap region nodes retrieved by integer // ids. Because finding edges requires interacting // with these disparate data structures frequently the - // process is nearly duplicated, one for each + // process is nearly duplicated, one for each structure + // that stores edges // heap regions Set sA = og.id2hrn.entrySet(); @@ -733,14 +737,17 @@ public class OwnershipGraph { assert id2hrn.containsKey( idA ); HeapRegionNode hrnB = id2hrn.get( idA ); - HeapRegionNode hrnChildB = null; + HeapRegionNode hrnChildB = null; + ReferenceEdgeProperties repB = null; Iterator heapRegionsItrB = hrnB.setIteratorToReferencedRegions(); while( heapRegionsItrB.hasNext() ) { - Map.Entry meC = (Map.Entry) heapRegionsItrB.next(); - hrnChildB = (HeapRegionNode) meC.getKey(); + Map.Entry meC = (Map.Entry) heapRegionsItrB.next(); + hrnChildB = (HeapRegionNode) meC.getKey(); + ReferenceEdgeProperties rep = (ReferenceEdgeProperties) meC.getValue(); if( hrnChildB.equals( idChildA ) ) { edgeFound = true; + repB = rep; } } @@ -749,15 +756,15 @@ public class OwnershipGraph { if( !edgeFound ) { assert id2hrn.containsKey( idChildA ); hrnChildB = id2hrn.get( idChildA ); - ReferenceEdgeProperties repB = repA.copy(); + repB = repA.copy(); addReferenceEdge( hrnB, hrnChildB, repB ); } - // otherwise, the edge already existed in both graphs. - // if this is the case, check to see whether the isUnique - // predicate of the edges might change - else - { - + // otherwise, the edge already existed in both graphs + // so merge their reachability sets + else { + // just replace this beta set with the union + assert repB != null; + repB.setBeta( repB.getBeta().union( repA.getBeta() ) ); } } } @@ -785,14 +792,17 @@ public class OwnershipGraph { assert td2ln.containsKey( tdA ); LabelNode lnB = td2ln.get( tdA ); - HeapRegionNode hrnChildB = null; + HeapRegionNode hrnChildB = null; + ReferenceEdgeProperties repB = null; Iterator heapRegionsItrB = lnB.setIteratorToReferencedRegions(); while( heapRegionsItrB.hasNext() ) { - Map.Entry meC = (Map.Entry) heapRegionsItrB.next(); - hrnChildB = (HeapRegionNode) meC.getKey(); + Map.Entry meC = (Map.Entry) heapRegionsItrB.next(); + hrnChildB = (HeapRegionNode) meC.getKey(); + ReferenceEdgeProperties rep = (ReferenceEdgeProperties) meC.getValue(); if( hrnChildB.equals( idChildA ) ) { edgeFound = true; + repB = rep; } } @@ -801,15 +811,15 @@ public class OwnershipGraph { if( !edgeFound ) { assert id2hrn.containsKey( idChildA ); hrnChildB = id2hrn.get( idChildA ); - ReferenceEdgeProperties repB = repA.copy(); + repB = repA.copy(); addReferenceEdge( lnB, hrnChildB, repB ); } - // otherwise, the edge already existed in both graphs. - // if this is the case, check to see whether the isUnique - // predicate of the edges might change - else - { - + // otherwise, the edge already existed in both graphs + // so merge the reachability sets + else { + // just replace this beta set with the union + assert repB != null; + repB.setBeta( repB.getBeta().union( repA.getBeta() ) ); } } } @@ -837,38 +847,6 @@ public class OwnershipGraph { } - - //protected void mergeTokenSets( OwnershipGraph og ) { - // alpha = new Hashtable< HeapRegionNode, HashSet< HashSet > >(); - - // if a key is in one or the other token set, - // add it to the merged token set. - // if a key is in both graphs, the merged - // token set should have that key and the union - // of values as the merged value. - - /* - Set alphaB = og.alpha.entrySet(); - Iterator iB = alphaB.iterator(); - while( iB.hasNext() ) { - Map.Entry meB = (Map.Entry) iB.next(); - HeapRegionNode hrnKeyB = (HeapRegionNode) meB.getKey(); - HashSet< HashSet > > tokenSetsB = - (HashSet< HashSet > >) meB.getValue(); - - if( !alpha.containsKey( hrnKeyB ) ) { - alpha.put( hrnKeyB, tokenSetsB ); - } else { - - } - } - */ - //} - - - - - // it is necessary in the equals() member functions // to "check both ways" when comparing the data @@ -927,7 +905,8 @@ public class OwnershipGraph { return false; } - HeapRegionNode hrnB = og.id2hrn.get( idA ); + //HeapRegionNode hrnB = og.id2hrn.get( idA ); + HeapRegionNode hrnB = id2hrn.get( idA ); if( !hrnA.equals( hrnB ) ) { return false; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java b/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java index 972e3d5b..d333f2c8 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java @@ -6,7 +6,7 @@ import java.util.*; import java.io.*; -public class ReachabilitySet { +public class ReachabilitySet extends Canonical { private HashSet possibleReachabilities; @@ -27,6 +27,10 @@ public class ReachabilitySet { possibleReachabilities = (HashSet) rs.possibleReachabilities.clone(); // again, DEEP COPY?! } + public ReachabilitySet makeCanonical() { + return (ReachabilitySet) Canonical.makeCanonical( this ); + } + public Iterator iterator() { return possibleReachabilities.iterator(); } @@ -34,7 +38,7 @@ public class ReachabilitySet { public ReachabilitySet union( ReachabilitySet rsIn ) { ReachabilitySet rsOut = new ReachabilitySet( this ); rsOut.possibleReachabilities.addAll( rsIn.possibleReachabilities ); - return rsOut; + return rsOut.makeCanonical(); } public ReachabilitySet intersection( ReachabilitySet rsIn ) { @@ -48,7 +52,7 @@ public class ReachabilitySet { } } - return rsOut; + return rsOut.makeCanonical(); } public ChangeTupleSet unionUpArity( ReachabilitySet rsIn ) { @@ -69,9 +73,9 @@ public class ReachabilitySet { TokenTuple e = (TokenTuple) itrRelement.next(); if( o.containsToken( e.getToken() ) ) { - theUnion = theUnion.union( new TokenTupleSet( e.increaseArity() ) ); + theUnion = theUnion.union( new TokenTupleSet( e.increaseArity() ) ).makeCanonical(); } else { - theUnion = theUnion.union( new TokenTupleSet( e ) ); + theUnion = theUnion.union( new TokenTupleSet( e ) ).makeCanonical(); } } @@ -80,7 +84,7 @@ public class ReachabilitySet { TokenTuple e = (TokenTuple) itrOelement.next(); if( !theUnion.containsToken( e.getToken() ) ) { - theUnion = theUnion.union( new TokenTupleSet( e ) ); + theUnion = theUnion.union( new TokenTupleSet( e ) ).makeCanonical(); } } @@ -92,7 +96,21 @@ public class ReachabilitySet { } } - return ctsOut; + return ctsOut.makeCanonical(); + } + + + public boolean equals( Object o ) { + if( !(o instanceof ReachabilitySet) ) { + return false; + } + + ReachabilitySet rs = (ReachabilitySet) o; + return possibleReachabilities.equals( rs.possibleReachabilities ); + } + + public int hashCode() { + return possibleReachabilities.hashCode(); } @@ -109,7 +127,6 @@ public class ReachabilitySet { return s; } - public String toString() { String s = "["; diff --git a/Robust/src/Analysis/OwnershipAnalysis/ReferenceEdgeProperties.java b/Robust/src/Analysis/OwnershipAnalysis/ReferenceEdgeProperties.java index eee52986..72b4457b 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/ReferenceEdgeProperties.java +++ b/Robust/src/Analysis/OwnershipAnalysis/ReferenceEdgeProperties.java @@ -5,17 +5,28 @@ public class ReferenceEdgeProperties { public ReferenceEdgeProperties() { this.isUnique = false; this.isInitialParamReflexive = false; + this.beta = new ReachabilitySet(); } public ReferenceEdgeProperties( boolean isUnique ) { this.isUnique = isUnique; this.isInitialParamReflexive = false; + this.beta = new ReachabilitySet(); } public ReferenceEdgeProperties( boolean isUnique, boolean isInitialParamReflexive ) { this.isUnique = isUnique; this.isInitialParamReflexive = isInitialParamReflexive; + this.beta = new ReachabilitySet(); + } + + public ReferenceEdgeProperties( boolean isUnique, + boolean isInitialParamReflexive, + ReachabilitySet beta) { + this.isUnique = isUnique; + this.isInitialParamReflexive = isInitialParamReflexive; + this.beta = beta; } @@ -43,6 +54,18 @@ public class ReferenceEdgeProperties { } + protected ReachabilitySet beta; + public ReachabilitySet getBeta() { + return beta; + } + public void setBeta( ReachabilitySet beta ) { + this.beta = beta; + } + public String getBetaString() { + return beta.toStringEscapeNewline(); + } + + public boolean equals( ReferenceEdgeProperties rep ) { return isUnique == rep.isUnique() && isInitialParamReflexive == rep.isInitialParamReflexive(); diff --git a/Robust/src/Analysis/OwnershipAnalysis/TokenTuple.java b/Robust/src/Analysis/OwnershipAnalysis/TokenTuple.java index e135a680..f198a0a0 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/TokenTuple.java +++ b/Robust/src/Analysis/OwnershipAnalysis/TokenTuple.java @@ -11,7 +11,7 @@ import java.io.*; // THIS CLASS IS IMMUTABLE! -public class TokenTuple +public class TokenTuple extends Canonical { private Integer token; private boolean isNewSummary; @@ -35,12 +35,18 @@ public class TokenTuple this.arity = arity; } + public TokenTuple makeCanonical() { + return (TokenTuple) Canonical.makeCanonical( this ); + } + public Integer getToken() { return token; } public int getArity() { return arity; } public TokenTuple increaseArity() { if( isNewSummary ) { - return new TokenTuple( token, isNewSummary, ARITY_MANY ); + return (TokenTuple) Canonical.makeCanonical( + new TokenTuple( token, isNewSummary, ARITY_MANY ) + ); } return this; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java b/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java index 9a81a658..d8532901 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java @@ -6,7 +6,7 @@ import java.util.*; import java.io.*; -public class TokenTupleSet { +public class TokenTupleSet extends Canonical { private HashSet tokenTuples; @@ -23,6 +23,10 @@ public class TokenTupleSet { tokenTuples = (HashSet) tts.tokenTuples.clone(); //COPY?! } + public TokenTupleSet makeCanonical() { + return (TokenTupleSet) Canonical.makeCanonical( this ); + } + public Iterator iterator() { return tokenTuples.iterator(); } @@ -30,7 +34,7 @@ public class TokenTupleSet { public TokenTupleSet union( TokenTupleSet ttsIn ) { TokenTupleSet ttsOut = new TokenTupleSet( this ); ttsOut.tokenTuples.addAll( ttsIn.tokenTuples ); - return ttsOut; + return ttsOut.makeCanonical(); } public boolean isEmpty() { @@ -41,6 +45,19 @@ public class TokenTupleSet { return tokenTuples.contains( tt ); } + public boolean equals( Object o ) { + if( !(o instanceof TokenTupleSet) ) { + return false; + } + + TokenTupleSet tts = (TokenTupleSet) o; + return tokenTuples.equals( tts.tokenTuples ); + } + + public int hashCode() { + return tokenTuples.hashCode(); + } + // this should be a hash table so we can do this by key public boolean containsToken( Integer token ) { Iterator itr = tokenTuples.iterator(); diff --git a/Robust/src/Makefile b/Robust/src/Makefile index e51d4717..2ec41852 100644 --- a/Robust/src/Makefile +++ b/Robust/src/Makefile @@ -85,6 +85,7 @@ Analysis/OwnershipAnalysis/TokenTupleSet.class \ Analysis/OwnershipAnalysis/ReachabilitySet.class \ Analysis/OwnershipAnalysis/ChangeTuple.class \ Analysis/OwnershipAnalysis/ChangeTupleSet.class \ +Analysis/OwnershipAnalysis/Canonical.class \ Util/GraphNode.class Util/Namer.class Util/Relation.class \ Interface/HTTPHeader.class Interface/HTTPResponse.class \ Interface/HTTPServices.class Interface/HashStrings.class \ diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile b/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile index 37e72086..3d08d27a 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile @@ -13,6 +13,7 @@ view: PNGs #eog *FN*.png & #eog *Ownership*.png & eog *COMPLETE*.png & + #eog *debug*.png & printable: rm -f *Startup*.dot @@ -30,6 +31,8 @@ printable: PNGs: DOTs #rm -f *Startup*.dot + #rm -f *COMPLETE*.dot + rm -f *FlatIR*.dot rm -f *FlatMethod*.dot rm -f *FlatOpNode*.dot rm -f *FlatFieldNode*.dot diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java index 9349ccca..dc458915 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java @@ -61,7 +61,7 @@ task Startup( StartupObject s{ initialstate } ) { } - +/* // this task allocates a new object, so there should // be a heap region for the parameter, and several // heap regions for the allocation site, but the label @@ -74,6 +74,7 @@ task NewObject( Voo v{ f } ) { taskexit( v{ !f } ); } + // this task task Branch( Voo v{ f } ) { Voo w = new Voo(); @@ -88,7 +89,7 @@ task Branch( Voo v{ f } ) { taskexit( v{ !f } ); } - +*/ task NoAliasNewInLoop( Voo v{ f } ) { @@ -101,6 +102,7 @@ task NoAliasNewInLoop( Voo v{ f } ) { taskexit( v{ !f } ); } +/* task NoAliasNewInLoopAnotherWay( Voo v{ f } ) { for( int i = 0; i < 10; ++i ) { @@ -121,3 +123,4 @@ task ClobberInitParamReflex( Voo v{ f }, Voo w{ f } ) { taskexit( v{ !f }, w{ !f } ); } +*/ \ No newline at end of file diff --git a/Robust/src/Tests/OwnershipAnalysisTest/testTokens/Main.java b/Robust/src/Tests/OwnershipAnalysisTest/testTokens/Main.java index 603ce6c9..ac115555 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/testTokens/Main.java +++ b/Robust/src/Tests/OwnershipAnalysisTest/testTokens/Main.java @@ -21,6 +21,7 @@ public class Main { public static void main(String args[]) throws Exception { + // example test to know the testing routine is correct! test( "4 == 5?", false, 4 == 5 ); test( "3 == 3?", true, 3 == 3 ); @@ -85,10 +86,10 @@ public class Main { true, TokenTuple.ARITY_ONE ); - /* TokenTuple tt5 = new TokenTuple( new Integer( 4 ), - true, + TokenTuple tt5 = new TokenTuple( new Integer( 4 ), + true, TokenTuple.ARITY_ONE ); - */ + TokenTuple tt6 = new TokenTuple( new Integer( 6 ), false, TokenTuple.ARITY_ONE ); @@ -107,5 +108,76 @@ public class Main { ChangeTupleSet cts0 = rs0.unionUpArity( rs1 ); System.out.println( "cts0 is "+cts0 ); + + + + TokenTuple tt00 = new TokenTuple( new Integer( 9 ), + true, + TokenTuple.ARITY_ONE ); + + TokenTuple tt01 = new TokenTuple( new Integer( 9 ), + true, + TokenTuple.ARITY_ONE ); + + test( "tt00 equals tt01?", true, tt00.equals( tt01 ) ); + test( "tt00 == tt01?", false, tt00 == tt01 ); + + tt00 = (TokenTuple) Canonical.makeCanonical( tt00 ); + tt01 = (TokenTuple) Canonical.makeCanonical( tt01 ); + + test( "tt00 equals tt01?", true, tt00.equals( tt01 ) ); + test( "tt00 == tt01?", true, tt00 == tt01 ); + + + TokenTuple tt02 = + (TokenTuple) Canonical.makeCanonical( + new TokenTuple( new Integer( 10 ), + true, + TokenTuple.ARITY_ONE ) + ); + + TokenTuple tt03 = + (TokenTuple) Canonical.makeCanonical( + new TokenTuple( new Integer( 11 ), + true, + TokenTuple.ARITY_ONE ) + ); + + TokenTuple tt04 = + (TokenTuple) Canonical.makeCanonical( + new TokenTuple( new Integer( 12 ), + true, + TokenTuple.ARITY_ONE ) + ); + + TokenTupleSet ttsT00 = + (TokenTupleSet) Canonical.makeCanonical( new TokenTupleSet( tt00 ) ); + + TokenTupleSet ttsT01 = + (TokenTupleSet) Canonical.makeCanonical( new TokenTupleSet( tt01 ) ); + + TokenTupleSet ttsT02 = + (TokenTupleSet) Canonical.makeCanonical( new TokenTupleSet( tt02 ) ); + + TokenTupleSet ttsT03 = + (TokenTupleSet) Canonical.makeCanonical( new TokenTupleSet( tt03 ) ); + + TokenTupleSet ttsT04 = + (TokenTupleSet) Canonical.makeCanonical( new TokenTupleSet( tt04 ) ); + + TokenTupleSet tts00 = ttsT00.union( ttsT02.union( ttsT03.union( ttsT04 ) ) ); + TokenTupleSet tts01 = ttsT01.union( ttsT02.union( ttsT03.union( ttsT04 ) ) ); + + test( "tts00 equals tts01?", true, tts00.equals( tts01 ) ); + + // It's OK that this one turns out true--I changed the union operator + // to automatically canonicalize stuff! + test( "tts00 == tts01?", false, tts00 == tts01 ); + + tts00 = (TokenTupleSet) Canonical.makeCanonical( tts00 ); + tts01 = (TokenTupleSet) Canonical.makeCanonical( tts01 ); + + test( "tts00 equals tts01?", true, tts00.equals( tts01 ) ); + test( "tts00 == tts01?", true, tts00 == tts01 ); } -} \ No newline at end of file +} -- 2.34.1