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

SynchronizedStmtAnnotation.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 edu.ksu.cis.bandera.jjjc.node.*;
00036 import edu.ksu.cis.bandera.jjjc.util.*;
00037 import ca.mcgill.sable.soot.jimple.*;
00038 import ca.mcgill.sable.util.*;
00039 import java.util.*;
00040 public class SynchronizedStmtAnnotation extends SpecializedAnnotation {
00041     private Annotation blockAnnotation = null;
00042     private Annotation catchAnnotation = null;
00043     private Vector exitMonitors = new Vector();
00044     private Value lockValue = null;
00045     private Stmt enterMonitor = null;
00046 /**
00047  * SynchronizedStmtAnnotation constructor comment.
00048  * @param node edu.ksu.cis.bandera.jjjc.node.Node
00049  */
00050 public SynchronizedStmtAnnotation(edu.ksu.cis.bandera.jjjc.node.Node node) {
00051     super(node);
00052 }
00053 /**
00054  * 
00055  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00056  */
00057 public void addExitMonitor(Stmt stmt) {
00058     exitMonitors.addElement(stmt);
00059 }
00060     public void apply(Switch sw)
00061     {
00062         ((AnnotationSwitch) sw).caseSynchronizedStmtAnnotation(this);
00063     }
00064 /**
00065  * 
00066  * @return java.lang.Object
00067  */
00068 public Object clone() {
00069     SynchronizedStmtAnnotation result = new SynchronizedStmtAnnotation((Node) node.clone());
00070     /*
00071     Stmt[] stmts = toArray();
00072 
00073     for (int i = 0; i < stmts.length; i++) {
00074         result.addStmt(JimpleStmtCloner.clone(stmts[i]));
00075     }
00076     */
00077     if (blockAnnotation != null) result.setBlockAnnotation((Annotation) blockAnnotation.clone());
00078     if (catchAnnotation != null) result.setCatchAnnotation((Annotation) catchAnnotation.clone());
00079     /*
00080     result.setExitMonitors(exitMonitors);
00081     result.setLockValue(lockValue);
00082     result.setEnterMonitor(enterMonitor);
00083     */
00084     return result;
00085 }
00086 /**
00087  * 
00088  * @return java.util.Vector
00089  * @param includeSequential boolean
00090  */
00091 public Vector getAllAnnotations(boolean includeSequential) {
00092     Vector result = new Vector();
00093     result.addElement(this);
00094     for (Enumeration e = blockAnnotation.getAllAnnotations(includeSequential).elements(); e.hasMoreElements();) {
00095         result.addElement(e.nextElement());
00096     }
00097     return result;
00098 }
00099 /**
00100  * 
00101  * @return edu.ksu.cis.bandera.annotations.Annotation
00102  */
00103 public Annotation getBlockAnnotation() {
00104     return blockAnnotation;
00105 }
00106 /**
00107  * 
00108  * @return annotation edu.ksu.cis.bandera.annotations.Annotation
00109  */
00110 public Annotation getCatchAnnotation() {
00111     return catchAnnotation;
00112 }
00113 /**
00114  * 
00115  * @return edu.ksu.cis.bandera.annotations.Annotation
00116  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00117  */
00118 public Annotation getContainingAnnotation(Stmt stmt) throws AnnotationException {
00119     Vector result = new Vector();
00120 
00121     Annotation a = super.getContainingAnnotation(stmt);
00122     if (a != null) result.addElement(this);
00123 
00124     a = blockAnnotation.getContainingAnnotation(stmt);
00125     if (a != null) result.addElement(a);
00126 
00127     if ((catchAnnotation != null) && (catchAnnotation.getContainingAnnotation(stmt) != null))
00128         result.addElement(this);
00129 
00130     int size = result.size();
00131     if (size == 0) return null;
00132     else if (size == 1) return (Annotation) result.elementAt(0);
00133     throw new AnnotationException("Statement " + stmt + " is contained in two or more annotations");
00134 }
00135 /**
00136  * 
00137  * @return ca.mcgill.sable.soot.jimple.Stmt
00138  */
00139 public Stmt getEnterMonitor() {
00140     return enterMonitor;
00141 }
00142 /**
00143  * 
00144  * @return java.util.Vector
00145  */
00146 public Vector getExitMonitors() {
00147     return exitMonitors;
00148 }
00149 /**
00150  * 
00151  * @return ca.mcgill.sable.soot.jimple.Stmt[]
00152  */
00153 public Stmt[] getLockStatements() {
00154     return toArray();
00155 }
00156 /**
00157  * 
00158  * @return ca.mcgill.sable.soot.jimple.Value
00159  */
00160 public Value getLockValue() {
00161     return lockValue;
00162 }
00163 /**
00164  * 
00165  * @return ca.mcgill.sable.soot.jimple.Stmt[]
00166  */
00167 public Stmt[] getStatements() {
00168     Stmt[] stmts = super.toArray();
00169     Stmt[] blockStmts = (blockAnnotation != null) ? blockAnnotation.getStatements() : new Stmt[0];
00170     Stmt[] catchStmts = (catchAnnotation != null) ? catchAnnotation.getStatements() : new Stmt[0];
00171 
00172     Stmt[] result = new Stmt[stmts.length + blockStmts.length + catchStmts.length];
00173 
00174     for (int i = 0; i < stmts.length; i++) {
00175         result[i] = stmts[i];
00176     }
00177 
00178     int index = stmts.length;
00179 
00180     for (int i = 0; i < blockStmts.length; i++) {
00181         result[index + i] = blockStmts[i];
00182     }
00183 
00184     index += blockStmts.length;
00185 
00186     for (int i = 0; i < catchStmts.length; i++) {
00187         result[index + i] = catchStmts[i];
00188     }
00189         
00190     return result;
00191 }
00192 /**
00193  * 
00194  * @return boolean
00195  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00196  */
00197 public boolean removeStmt(Stmt stmt) throws AnnotationException {
00198     Annotation a = getContainingAnnotation(stmt);
00199     if (a == null) return false;
00200     else if (a == this) {
00201         boolean r = false;
00202         if (catchAnnotation != null) {
00203             r = catchAnnotation.removeStmt(stmt);
00204         }
00205         return remove(stmt) || r; 
00206     } else return a.removeStmt(stmt);
00207 }
00208 /**
00209  * 
00210  * @return boolean
00211  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00212  */
00213 public boolean removeStmtByMark(Stmt stmt) throws AnnotationException {
00214     Annotation a = getContainingAnnotation(stmt);
00215     if (a == null) return false;
00216     else if (a == this) {
00217         boolean r = false;
00218         if (catchAnnotation != null) {
00219             r = catchAnnotation.removeStmtByMark(stmt);
00220         }
00221         return removeByMark(stmt) || r; 
00222     } else return a.removeStmtByMark(stmt);
00223 }
00224 /**
00225  * 
00226  * @return boolean
00227  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00228  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00229  */
00230 public boolean replaceStmt(Stmt oldStmt, Stmt newStmt) throws AnnotationException {
00231     Annotation a = getContainingAnnotation(oldStmt);
00232     if (a == null) return false;
00233     else if (a == this) {
00234         boolean r = false;
00235         if (catchAnnotation != null) {
00236             r = catchAnnotation.replaceStmt(oldStmt, newStmt);
00237         }
00238         return replace(oldStmt, newStmt) || r; 
00239     } else return a.replaceStmt(oldStmt, newStmt);
00240 }
00241 /**
00242  * 
00243  * @return boolean
00244  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00245  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00246  */
00247 public boolean replaceStmtByMark(Stmt oldStmt, Stmt newStmt) throws AnnotationException {
00248     Annotation a = getContainingAnnotation(oldStmt);
00249     if (a == null) return false;
00250     else if (a == this) {
00251         boolean r = false;
00252         if (catchAnnotation != null) {
00253             r = catchAnnotation.replaceStmtByMark(oldStmt, newStmt);
00254         }
00255         return replaceByMark(oldStmt, newStmt) || r; 
00256     } else return a.replaceStmtByMark(oldStmt, newStmt);
00257 }
00258 /**
00259  * 
00260  * @param annotation edu.ksu.cis.bandera.annotations.Annotation
00261  */
00262 public void setBlockAnnotation(Annotation annotation) {
00263     blockAnnotation = annotation;
00264     blockAnnotation.setParent(this);
00265 }
00266 /**
00267  * 
00268  * @param annotation edu.ksu.cis.bandera.annotations.Annotation
00269  */
00270 public void setCatchAnnotation(Annotation annotation) {
00271     catchAnnotation = annotation;
00272     catchAnnotation.setParent(this);
00273 }
00274 /**
00275  * 
00276  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00277  */
00278 public void setEnterMonitor(Stmt stmt) {
00279     enterMonitor = stmt;
00280 }
00281 /**
00282  * 
00283  * @param exitMonitors java.util.Vector
00284  */
00285 public void setExitMonitors(Vector exitMonitors) {
00286 }
00287 /**
00288  * 
00289  * @param value ca.mcgill.sable.soot.jimple.Value
00290  */
00291 public void setLockValue(Value value) {
00292     lockValue = value;
00293 }
00294 /**
00295  * 
00296  * @return java.lang.String
00297  */
00298 public String toString() {
00299     return "synchronized (" + ((ASynchronizedStmt) node).getExp().toString().trim() + ")";
00300 }
00301 /**
00302  * 
00303  * @param body ca.mcgill.sable.soot.jimple.JimpleBody
00304  */
00305 public void validate(JimpleBody body) {
00306     StmtList stmts = body.getStmtList();
00307     
00308     super.validate(body);
00309 
00310     if (blockAnnotation != null) blockAnnotation.validate(body);
00311 
00312     if (catchAnnotation != null) catchAnnotation.validate(body);
00313 
00314     Vector newExitMonitors = new Vector();
00315 
00316     for (Enumeration e = exitMonitors.elements(); e.hasMoreElements();) {
00317         Stmt stmt = (Stmt) e.nextElement();
00318         if (stmts.contains(stmt)) {
00319             newExitMonitors.addElement(stmt);
00320         }
00321     }
00322 
00323     exitMonitors = newExitMonitors;
00324 
00325     if (!stmts.contains(enterMonitor)) enterMonitor = null;
00326 }
00327 }

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