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

Statements.java

00001 package edu.ksu.cis.bandera.annotation;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1999, 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 ca.mcgill.sable.soot.jimple.*;
00036 import java.util.*;
00037 public class Statements {
00038     public final static int REMAINED = 0;
00039     public final static int SLICED = 1;
00040     public final static int MODIFIED = 2;
00041     private Vector statements = new Vector();
00042     private BitSet removedStatements = null;
00043     private BitSet modifiedStatements = null;
00044 /**
00045  * 
00046  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00047  */
00048 public void add(Stmt stmt) {
00049     statements.addElement(stmt);
00050 }
00051 /**
00052  * 
00053  * @return boolean
00054  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00055  */
00056 public boolean contains(Stmt stmt) {
00057     return statements.contains(stmt);
00058 }
00059 /**
00060  * 
00061  * @return java.util.Enumeration
00062  */
00063 public Enumeration elements() {
00064     return statements.elements();
00065 }
00066 /**
00067  * Insert the method's description here.
00068  * Creation date: (00-12-6 11:14:08)
00069  * @return int
00070  */
00071 public int getAnnotationState() {
00072     if (removedStatements != null) {
00073         if (edu.ksu.cis.bandera.pdgslicer.SetUtil.emptyBitSetWithLength(removedStatements, getNumOfStatements()))
00074             return SLICED;
00075         else
00076             return MODIFIED;
00077     } else
00078         if (modifiedStatements != null)
00079             return MODIFIED;
00080     return REMAINED;
00081 }
00082 /**
00083  * 
00084  * @return int
00085  */
00086 public int getNumOfStatements() {
00087     return statements.size();
00088 }
00089 /**
00090  * 
00091  * @return ca.mcgill.sable.soot.jimple.Stmt
00092  * @param index int
00093  */
00094 public Stmt getStmtAt(int index) {
00095     return (Stmt) statements.elementAt(index);
00096 }
00097 /**
00098  * 
00099  * @return int
00100  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00101  */
00102 public int indexOf(Stmt stmt) {
00103     return statements.indexOf(stmt);
00104 }
00105 /**
00106  * Insert the method's description here.
00107  * Creation date: (00-12-7 17:57:40)
00108  */
00109 public void initializeState() {
00110     removedStatements = null;
00111     modifiedStatements = null;
00112 }
00113 /**
00114  * 
00115  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00116  * @param index int
00117  */
00118 public  void insertStmtAt(Stmt stmt, int index) {
00119     statements.insertElementAt(stmt, index);
00120 }
00121 /**
00122  * 
00123  * @return boolean
00124  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00125  */
00126 public boolean remove(Stmt stmt) {
00127     return statements.removeElement(stmt);
00128 }
00129 /**
00130  * 
00131  * @return boolean
00132  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00133  */
00134 public boolean removeByMark(Stmt stmt) {
00135     if (statements.contains(stmt)) {
00136         if (removedStatements == null) {
00137             removedStatements = new BitSet(getNumOfStatements());
00138             edu.ksu.cis.bandera.pdgslicer.SetUtil.initializeBitSetToAllTrue(removedStatements);
00139         }
00140         removedStatements.clear(indexOf(stmt));
00141         return true;
00142     }
00143     return false;
00144 }
00145 /**
00146  * 
00147  * @return boolean
00148  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00149  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00150  */
00151 public boolean replace(Stmt oldStmt, Stmt newStmt) {
00152     int i = statements.indexOf(oldStmt);
00153     if (i >= 0) {
00154         statements.setElementAt(newStmt, i);
00155         return true;
00156     } else return false;
00157 }
00158 /**
00159  * 
00160  * @return boolean
00161  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00162  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00163  */
00164 public boolean replaceByMark(Stmt oldStmt, Stmt newStmt) {
00165     int i = statements.indexOf(oldStmt);
00166     if (i >= 0) {
00167         if (modifiedStatements == null) {
00168             modifiedStatements = new BitSet(getNumOfStatements());
00169             edu.ksu.cis.bandera.pdgslicer.SetUtil.initializeBitSetToAllFalse(modifiedStatements);
00170         }
00171         modifiedStatements.set(i);
00172         return true;
00173     } else
00174         return false;
00175 }
00176 /**
00177  * 
00178  * @return ca.mcgill.sable.soot.jimple.Stmt[]
00179  */
00180 public Stmt[] toArray() {
00181     Stmt[] result = new Stmt[statements.size()];
00182 
00183     for (int i = 0; i < result.length; i++) result[i] = (Stmt) statements.elementAt(i);
00184     
00185     return result;
00186 }
00187 /**
00188  * 
00189  * @return java.lang.String
00190  */
00191 public String toString() {
00192     return statements.toString();
00193 }
00194 /**
00195  * 
00196  * @param body ca.mcgill.sable.soot.jimple.JimpleBody
00197  */
00198 public void validate(JimpleBody body) {
00199     StmtList stmtList = body.getStmtList();
00200 
00201     Vector newStatements = new Vector();
00202     
00203     for (Enumeration e = elements(); e.hasMoreElements();) {
00204         Stmt stmt = (Stmt) e.nextElement();
00205         if (stmtList.contains(stmt)) newStatements.addElement(stmt);
00206     }
00207 
00208     statements = newStatements;
00209 }
00210 }

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