00001 package edu.ksu.cis.bandera.pdgslicer; 00002 00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00004 * Bandera, a Java(TM) analysis and transformation toolkit * 00005 * Copyright (C) 1998, 1999 Hongjun Zheng (zheng@cis.ksu.edu) * 00006 * All rights reserved. * 00007 * * 00008 * This work was done as a project in the SAnToS Laboratory, * 00009 * Department of Computing and Information Sciences, Kansas State * 00010 * University, USA (http://www.cis.ksu.edu/santos). * 00011 * It is understood that any modification not identified as such is * 00012 * not covered by the preceding statement. * 00013 * * 00014 * This work is free software; you can redistribute it and/or * 00015 * modify it under the terms of the GNU Library General Public * 00016 * License as published by the Free Software Foundation; either * 00017 * version 2 of the License, or (at your option) any later version. * 00018 * * 00019 * This work is distributed in the hope that it will be useful, * 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00022 * Library General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU Library General Public * 00025 * License along with this toolkit; if not, write to the * 00026 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * 00027 * Boston, MA 02111-1307, USA. * 00028 * * 00029 * Java is a trademark of Sun Microsystems, Inc. * 00030 * * 00031 * To submit a bug report, send a comment, or get the latest news on * 00032 * this project and other SAnToS projects, please visit the web-site * 00033 * http://www.cis.ksu.edu/santos * 00034 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00035 00036 import ca.mcgill.sable.soot.jimple.*; 00037 import ca.mcgill.sable.soot.*; 00038 import edu.ksu.cis.bandera.jjjc.*; 00039 import edu.ksu.cis.bandera.annotation.*; 00040 import java.util.*; 00041 00042 /** 00043 * This class is for PDG browser. Each object of this class will record 00044 * one node in CFG which is included in the slice of one method. All the 00045 * slice trace nodes are linked by dependencies. 00046 * <br> For example, suppose we have 00047 * <br> n1 cd--> n2, n1 dd--> n3, n1 synd--> n4 00048 * <br> n5 dd--> n2, n6 cd--> n4 00049 * <br> where --> can be read as "on", and 00050 * cd, dd, synd are saying control dependent, data dependent, synchronization dependent 00051 * repectively. 00052 * In this case, we say 00053 * <br> (1) n1 has 3 slice children: n2(cd), n3(dd), n4(synd), if n1 00054 * is included in the slice. 00055 * <br> (2) n2 has 2 slice parents: n5(dd), n1(cd), if both n1 and n5 are in the slice. 00056 * In other words, how many slice parents n2 can have depends on how many parents 00057 * of n2 are in the slice. 00058 * <br> Finally, all objects of SliceTraceNode for a method could construct a net 00059 * (bidirectional link) linked by all kinds of dependency(cd, dd, synd etc.). 00060 */ 00061 00062 public class SliceTraceNode 00063 { 00064 /** 00065 * Method where the node is. 00066 */ 00067 public MethodInfo methodInfo; 00068 /** 00069 * The annotation of the node (statement). 00070 */ 00071 public Annotation stmtAnnotation = null; 00072 /** 00073 * Slice parents of current node. 00074 * <br> A map from {@link SliceTraceNode SliceTraceNode} to 00075 * {@link Kind Kind}. 00076 */ 00077 public Map parents ; //map from parent (SliceTraceNode) to kind (data, control etc.) 00078 /** 00079 * Slice children of current node. 00080 * <br> A map from {@link SliceTraceNode SliceTraceNode} to 00081 * {@link Kind Kind} 00082 */ 00083 public Map children ; 00084 00085 /** 00086 * Initial constructor. 00087 */ 00088 public SliceTraceNode() { 00089 methodInfo = null; 00090 parents = new HashMap(); 00091 children = new HashMap(); 00092 } 00093 /** 00094 * Constructor for method and annotation. 00095 * <p> 00096 * @param sm sootmethod where the annotation <code>sa</code> is. 00097 * @param sa annotation for current node (statement). 00098 */ 00099 public SliceTraceNode(SootMethod sm, Annotation sa) 00100 { 00101 methodInfo = (MethodInfo) Slicer.sootMethodInfoMap.get(sm); 00102 stmtAnnotation = sa; 00103 parents = new HashMap(); 00104 children = new HashMap(); 00105 } 00106 /** 00107 * Constructor for method and statement. 00108 * <p> 00109 * @param mi method where the statement <code>s</code> is. 00110 * @param s statement for current node. 00111 */ 00112 public SliceTraceNode(MethodInfo mi, Stmt s) { 00113 00114 methodInfo = mi; 00115 parents = new HashMap(); 00116 children = new HashMap(); 00117 Annotation mda = null; 00118 AnnotationManager annotationManager = CompilationManager.getAnnotationManager(); 00119 try { 00120 mda = (Annotation) annotationManager.getAnnotation(methodInfo.sootClass, methodInfo.sootMethod); 00121 } catch (Exception ex) { 00122 System.out.println("There is an exception in geting Annotation in SliceTraceNode"); 00123 //System.exit(0); 00124 } 00125 try { 00126 stmtAnnotation = mda.getContainingAnnotation(s); 00127 } catch (AnnotationException ae) { 00128 System.out.println("there is an AnnotationException! And stmtAnnotation may be null in SliceTraceNode"); 00129 } 00130 /* 00131 if (stmtAnnotation.toString().equals("")) 00132 System.out.println(methodInfo.sootMethod+"--stmt : " + s +" 's annotation is blank"); 00133 */ 00134 } 00135 /** 00136 * Add a slice trace node into current node list. 00137 * <br> Set the parent as child for current node. 00138 * <p> 00139 * @param stn node being added. 00140 * @param kind the dependency kind of the node <code>stn</code>. 00141 */ 00142 public void add(SliceTraceNode stn, Integer kind) { 00143 this.children.put(stn, kind); 00144 stn.parents.put(this, kind); 00145 } 00146 public boolean equals(Object o) { 00147 if (!(o instanceof SliceTraceNode)) 00148 return false; 00149 SliceTraceNode stn = (SliceTraceNode) o; 00150 return (methodInfo == stn.methodInfo) && (stmtAnnotation == stn.stmtAnnotation); 00151 // &&(nodeKind==stn.nodeKind)&&(sourceNode==stn.sourceNode); 00152 } 00153 /** 00154 * See if a slice trace node <code>stn</code> is a child of 00155 * current slice trace node. 00156 * <p> 00157 * @param stn query slice trace node. 00158 */ 00159 public boolean isChild(SliceTraceNode stn) 00160 { 00161 Set childrenSet = children.keySet(); 00162 if (childrenSet.contains(stn)) return true; 00163 return false; 00164 } 00165 public String toString() { 00166 if (stmtAnnotation.toString().equals("")) 00167 return "BLANK :: " + methodInfo.sootMethod; 00168 else 00169 return stmtAnnotation+" :: " + methodInfo.sootMethod; 00170 } 00171 }