1 salcianu 1.1.2.1 // PAEdge.java, created Wed Feb 16 15:02:44 2000 by salcianu 2 cananian 1.1.2.10 // Copyright (C) 2000 Alexandru SALCIANU <salcianu@retezat.lcs.mit.edu> 3 salcianu 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 salcianu 1.1.2.1 package harpoon.Analysis.PointerAnalysis; 5 salcianu 1.1.2.1 6 salcianu 1.1.2.2 import java.util.Set; 7 salcianu 1.1.2.7 import java.util.Map; 8 salcianu 1.1.2.6 import java.util.HashSet; 9 salcianu 1.1.2.6 import java.util.Iterator; 10 salcianu 1.1.2.2 11 salcianu 1.1.2.8 import harpoon.Util.DataStructs.Relation; 12 salcianu 1.1.2.8 import harpoon.Util.DataStructs.LightRelation; 13 salcianu 1.1.2.8 14 salcianu 1.1.2.1 /** 15 salcianu 1.1.2.1 * <code>PAEdge</code> 16 salcianu 1.1.2.1 * 17 cananian 1.1.2.10 * @author Alexandru SALCIANU <salcianu@retezat.lcs.mit.edu> 18 cananian 1.3 * @version $Id: PAEdge.java,v 1.3 2004/02/08 03:20:03 cananian Exp $ 19 salcianu 1.1.2.1 */ 20 salcianu 1.1.2.9 public class PAEdge implements java.io.Serializable { 21 salcianu 1.1.2.1 22 salcianu 1.1.2.1 PANode n1; 23 salcianu 1.1.2.1 String f; 24 salcianu 1.1.2.1 PANode n2; 25 salcianu 1.1.2.1 26 salcianu 1.1.2.1 /** Creates a <code>PAEdge</code>. */ 27 salcianu 1.1.2.1 public PAEdge(PANode n1, String f, PANode n2) { 28 salcianu 1.1.2.1 this.n1 = n1; 29 salcianu 1.1.2.1 this.f = f; 30 salcianu 1.1.2.1 this.n2 = n2; 31 salcianu 1.1.2.6 } 32 salcianu 1.1.2.6 33 salcianu 1.1.2.7 /* Project this edge through the relation <code>mu</code>. */ 34 salcianu 1.1.2.6 public Set project(Relation mu){ 35 salcianu 1.1.2.6 Set edges = new HashSet(); 36 cananian 1.3 for(Object new_n1O : mu.getValues(n1)) { 37 cananian 1.3 PANode new_n1 = (PANode) new_n1O; 38 cananian 1.3 for(Object new_n2O : mu.getValues(n2)) { 39 cananian 1.3 PANode new_n2 = (PANode) new_n2O; 40 salcianu 1.1.2.6 edges.add(new PAEdge(new_n1, f, new_n2)); 41 salcianu 1.1.2.6 } 42 salcianu 1.1.2.6 } 43 salcianu 1.1.2.6 return edges; 44 salcianu 1.1.2.7 } 45 salcianu 1.1.2.7 46 salcianu 1.1.2.7 /* Specialize <code>this</code> edge by using the mapping 47 salcianu 1.1.2.7 <code>map</code>. <code>map</code> should be a mappig from 48 salcianu 1.1.2.7 <code>PANode</code> to <code>PANode</code>. 49 salcianu 1.1.2.7 Returns an edge obtained from <code>this</code> 50 salcianu 1.1.2.7 one by translating the two ends of it according to the mapping 51 salcianu 1.1.2.7 <code>map</code>. Each node that don't appear in <code>map</code> 52 salcianu 1.1.2.7 is implicitly assumed to be mapped to itself. 53 salcianu 1.1.2.7 This method is smart enough not to reallocated a new object if 54 salcianu 1.1.2.7 none of its ends is mapped to something else; in this case, it returns 55 salcianu 1.1.2.7 <code>this</code> object. */ 56 salcianu 1.1.2.7 public PAEdge specialize(Map map){ 57 salcianu 1.1.2.7 PANode n1p = (PANode) map.get(n1); 58 salcianu 1.1.2.7 PANode n2p = (PANode) map.get(n2); 59 salcianu 1.1.2.7 if(n1p == null){ 60 salcianu 1.1.2.7 // hack to avoid regenerating the same edge 61 salcianu 1.1.2.7 if(n2p == null) return this; 62 salcianu 1.1.2.7 // an unmaped nodes is implicitly maped to itself 63 salcianu 1.1.2.7 n1p = n1; 64 salcianu 1.1.2.7 } 65 salcianu 1.1.2.7 // an unmaped nodes is implicitly maped to itself 66 salcianu 1.1.2.7 if(n2p == null) n2p = n2; 67 salcianu 1.1.2.7 return new PAEdge(n1p,f,n2p); 68 salcianu 1.1.2.1 } 69 salcianu 1.1.2.1 70 salcianu 1.1.2.1 /** Checks the equality of two edges. */ 71 salcianu 1.1.2.1 public boolean equals(Object o){ 72 salcianu 1.1.2.1 PAEdge edge2 = (PAEdge) o; 73 salcianu 1.1.2.1 return (n1==edge2.n1) && (n2==edge2.n2) && (f.equals(edge2.f)); 74 salcianu 1.1.2.1 } 75 salcianu 1.1.2.1 76 salcianu 1.1.2.1 /** Computes the hash code of <code>this</code> object. */ 77 salcianu 1.1.2.1 public int hashCode(){ 78 salcianu 1.1.2.1 return n1.hashCode(); 79 salcianu 1.1.2.1 } 80 salcianu 1.1.2.1 81 salcianu 1.1.2.1 /** String representation for debug purposes. */ 82 salcianu 1.1.2.1 public String toString(){ 83 salcianu 1.1.2.1 return "<" + n1.toString() + "," + f + "," + n2.toString() + ">"; 84 salcianu 1.1.2.2 } 85 salcianu 1.1.2.2 86 salcianu 1.1.2.3 /** Checks whether <code>this</code> edge refers only to remaining nodes. 87 salcianu 1.1.2.3 This is supposed to be used by <code>keepTheEssential</code> methods. 88 salcianu 1.1.2.5 Warning: <code>isGood</code> is NOT the negation of 89 salcianu 1.1.2.5 <code>isBad</code>. */ 90 salcianu 1.1.2.5 boolean isGood(Set remaining_nodes){ 91 salcianu 1.1.2.3 return remaining_nodes.contains(n1) && remaining_nodes.contains(n2); 92 salcianu 1.1.2.3 } 93 salcianu 1.1.2.3 94 salcianu 1.1.2.2 /** Checks whether <code>this</code> edge refers to at least one 95 salcianu 1.1.2.2 node from the set <code>bad_nodes</code>. This is supposed to 96 salcianu 1.1.2.2 help us to determine which edges must go when we remove some nodes. */ 97 salcianu 1.1.2.5 boolean isBad(Set bad_nodes){ 98 salcianu 1.1.2.2 return bad_nodes.contains(n1) || bad_nodes.contains(n2); 99 salcianu 1.1.2.1 } 100 salcianu 1.1.2.1 } 101 salcianu 1.1.2.4 102 salcianu 1.1.2.4 103 salcianu 1.1.2.4 104 salcianu 1.1.2.4 105 cananian 1.2