Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

PredicateSliceInterestCollector.java

00001 package edu.ksu.cis.bandera.specification.predicate;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 2000   Robby (robby@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 import edu.ksu.cis.bandera.jjjc.symboltable.*;
00036 import edu.ksu.cis.bandera.pdgslicer.datastructure.*;
00037 import edu.ksu.cis.bandera.annotation.*;
00038 import edu.ksu.cis.bandera.jjjc.*;
00039 import ca.mcgill.sable.soot.*;
00040 import ca.mcgill.sable.soot.jimple.*;
00041 import java.util.*;
00042 import edu.ksu.cis.bandera.specification.predicate.datastructure.*;
00043 
00044 public class PredicateSliceInterestCollector {
00045     private static HashSet sliceInterests;
00046 /**
00047  * 
00048  * @return java.util.Collection
00049  * @param predicates java.util.Collection
00050  */
00051 public static Collection collect(Collection predicates) {
00052     Jimple jimple = Jimple.v();
00053     sliceInterests = new HashSet();
00054     for (Iterator i = predicates.iterator(); i.hasNext();) {
00055         Predicate p = (Predicate) i.next();
00056 
00057         try {
00058             Annotation a = p.getAnnotation();
00059             if (a instanceof LabeledStmtAnnotation) {
00060                 a = CompilationManager.getAnnotationManager().getMethodAnnotationContainingAnnotation(a);
00061             }
00062             SootClass sc = CompilationManager.getSootClassManager().getClass(p.getType().getName().toString());
00063             SootMethod sm = null;
00064             if (a != null) {
00065                 Stmt[] stmts = p.getAnnotation().getStatements();
00066                 sm = (a instanceof MethodDeclarationAnnotation) ?
00067                         ((MethodDeclarationAnnotation) a).getSootMethod() :
00068                         ((ConstructorDeclarationAnnotation) a).getSootMethod();
00069                 if (p instanceof ReturnPredicate) {
00070                     for (int k = 0; k < stmts.length; k++) {
00071                         if ((stmts[k] instanceof ReturnStmt) || ((stmts[k] instanceof ReturnVoidStmt))) {
00072                             int sind = SlicePoint.getStmtIndex(sm,(Stmt) stmts[k]);
00073                             sliceInterests.add(new SlicePoint(sc, sm, stmts[k],sind));
00074                             if (((ReturnPredicate) p).hasRet()) {
00075                                 sliceInterests.add(new SliceLocal(sc, sm, (Local) ((ReturnStmt) stmts[k]).getReturnValue()));
00076                             }
00077                         }
00078                     }
00079                 } else {
00080                     int sind = SlicePoint.getStmtIndex(sm,(Stmt) stmts[0]);
00081                     sliceInterests.add(new SlicePoint(sc, sm, stmts[0],sind));
00082                 }
00083             }
00084             if (p.getConstraint() != null) {
00085                 for (Enumeration e = p.getVariablesUsed().elements(); e.hasMoreElements();) {
00086                     Object o = e.nextElement();
00087                     if (o instanceof Local) {
00088                         sliceInterests.add(new SliceLocal(sc, sm, (Local) o));
00089                     } else if (o instanceof Field) {
00090                         try {
00091                             SootClass sootClass = CompilationManager.getSootClassManager().getClass(((Field) o).getDeclaringClassOrInterface().getName().toString());
00092                             SootField sf = sootClass.getField(((Field) o).getName().toString());
00093                             sliceInterests.add(new SliceField(sootClass, sf));
00094                         } catch (Exception ex) {}
00095                     } else if ("this".equals(o)) {
00096                         if (sm != null) {
00097                             try {
00098                                 Local l = ((JimpleBody) sm.getBody(jimple)).getLocal("JJJCTEMP$0");
00099                                 sliceInterests.add(new SliceLocal(sc, sm, l));
00100                             } catch (Exception ex) {}
00101                         }
00102                     }
00103                 }
00104             }
00105         } catch (Exception exc) {}
00106     }
00107     return sliceInterests;
00108 }
00109 }

Generated at Thu Feb 7 06:52:40 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001