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

IfStmtAnnotation.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 IfStmtAnnotation extends ConditionalAnnotation {
00041     private Annotation thenAnnotation = null;
00042     private Annotation annotation = null;
00043     private Annotation elseAnnotation = null;
00044 /**
00045  * IfStmtAnnotation constructor comment.
00046  * @param node edu.ksu.cis.bandera.jjjc.node.Node
00047  */
00048 public IfStmtAnnotation(edu.ksu.cis.bandera.jjjc.node.Node node) {
00049     super(node);
00050 }
00051     public void apply(Switch sw)
00052     {
00053         ((AnnotationSwitch) sw).caseIfStmtAnnotation(this);
00054     }
00055 /**
00056  * 
00057  * @return java.lang.Object
00058  */
00059 public Object clone() {
00060     IfStmtAnnotation result = new IfStmtAnnotation((Node) node.clone());
00061     /*
00062     Stmt[] stmts = getTestStatements();
00063 
00064     for (int i = 0; i < stmts.length; i++) {
00065         result.addStmt(JimpleStmtCloner.clone(stmts[i]));
00066     }
00067     */
00068     if (thenAnnotation != null) result.setThenAnnotation((Annotation) thenAnnotation.clone());
00069     if (annotation != null) result.setAnnotation((Annotation) annotation.clone());
00070     if (elseAnnotation != null) result.setElseAnnotation((Annotation) elseAnnotation.clone());
00071     
00072     return result;
00073 }
00074 /**
00075  * 
00076  * @return java.util.Vector
00077  * @param includeSequential boolean
00078  */
00079 public Vector getAllAnnotations(boolean includeSequential) {
00080     Vector result = new Vector();
00081     result.addElement(this);
00082     for (Enumeration e = thenAnnotation.getAllAnnotations(includeSequential).elements(); e.hasMoreElements();) {
00083         result.addElement(e.nextElement());
00084     }
00085     for (Enumeration e = elseAnnotation.getAllAnnotations(includeSequential).elements(); e.hasMoreElements();) {
00086         result.addElement(e.nextElement());
00087     }
00088     return result;
00089 }
00090 /**
00091  * 
00092  * @return edu.ksu.cis.bandera.annotation.Annotation
00093  */
00094 public Annotation getAnnotation() {
00095     return annotation;
00096 }
00097 /**
00098  * 
00099  * @return edu.ksu.cis.bandera.annotations.Annotation
00100  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00101  */
00102 public Annotation getContainingAnnotation(Stmt stmt) throws AnnotationException {
00103     Vector result = new Vector();
00104 
00105     Annotation a = super.getContainingAnnotation(stmt);
00106     if (a != null) result.addElement(a);
00107 
00108     if (thenAnnotation != null) {
00109         a = thenAnnotation.getContainingAnnotation(stmt);
00110         if (a != null) result.addElement(a);
00111     }
00112     
00113     if (annotation != null) {
00114         a = annotation.getContainingAnnotation(stmt);
00115         if (a != null) result.addElement(a);
00116     }
00117     
00118     if (elseAnnotation != null) {
00119         a = elseAnnotation.getContainingAnnotation(stmt);
00120         if (a != null) result.addElement(a);
00121     }
00122         
00123     int size = result.size();
00124     if (size == 0) return null;
00125     else if (size == 1) return (Annotation) result.elementAt(0);
00126     throw new AnnotationException("Statement " + stmt + " is contained in two or more annotations");
00127 }
00128 /**
00129  * 
00130  * @return edu.ksu.cis.bandera.annotations.Annotation
00131  */
00132 public Annotation getElseAnnotation() {
00133     return elseAnnotation;
00134 }
00135 /**
00136  * 
00137  * @return ca.mcgill.sable.soot.jimple.Stmt[]
00138  */
00139 public Stmt[] getStatements() {
00140     Stmt[] testStmts = toArray();
00141     Stmt[] thenStmts = (thenAnnotation != null) ? thenAnnotation.getStatements() : new Stmt[0];
00142     Stmt[] stmts = (annotation != null) ? annotation.getStatements() : new Stmt[0];
00143     Stmt[] elseStmts = (elseAnnotation != null) ? elseAnnotation.getStatements() : new Stmt[0];
00144 
00145     Stmt[] result = new Stmt[testStmts.length + thenStmts.length + stmts.length + elseStmts.length];
00146 
00147     for (int i = 0; i < testStmts.length; i++) {
00148         result[i] = testStmts[i];       
00149     }
00150 
00151     int index = testStmts.length;
00152 
00153     for (int i = 0; i < thenStmts.length; i++) {
00154         result[index + i] = thenStmts[i];
00155     }
00156 
00157     index += thenStmts.length;
00158 
00159     for (int i = 0; i < stmts.length; i++) {
00160         result[index + i] = stmts[i];
00161     }
00162 
00163     index += stmts.length;
00164     
00165     for (int i = 0; i < elseStmts.length; i++) {
00166         result[index + i] = elseStmts[i];
00167     }
00168     
00169     return result;
00170 }
00171 /**
00172  * 
00173  * @return edu.ksu.cis.bandera.annotations.Annotation
00174  */
00175 public Annotation getThenAnnotation() {
00176     return thenAnnotation;
00177 }
00178 /**
00179  * 
00180  * @return boolean
00181  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00182  */
00183 public boolean removeStmt(Stmt stmt) throws AnnotationException {
00184     Annotation a = getContainingAnnotation(stmt);
00185     if (a == null) return false;
00186     else if (a == this) return remove(stmt);
00187     else return a.removeStmt(stmt);
00188 }
00189 /**
00190  * 
00191  * @return boolean
00192  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00193  */
00194 public boolean removeStmtByMark(Stmt stmt) throws AnnotationException {
00195     Annotation a = getContainingAnnotation(stmt);
00196     if (a == null) return false;
00197     else if (a == this) return removeByMark(stmt);
00198     else return a.removeStmtByMark(stmt);
00199 }
00200 /**
00201  * 
00202  * @return boolean
00203  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00204  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00205  */
00206 public boolean replaceStmt(Stmt oldStmt, Stmt newStmt) throws AnnotationException {
00207     Annotation a = getContainingAnnotation(oldStmt);
00208     if (a == null) return false;
00209     else if (a == this) return replace(oldStmt, newStmt);
00210     else return a.replaceStmt(oldStmt, newStmt);
00211 }
00212 /**
00213  * 
00214  * @return boolean
00215  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00216  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00217  */
00218 public boolean replaceStmtByMark(Stmt oldStmt, Stmt newStmt) throws AnnotationException {
00219     Annotation a = getContainingAnnotation(oldStmt);
00220     if (a == null) return false;
00221     else if (a == this) return replaceByMark(oldStmt, newStmt);
00222     else return a.replaceStmtByMark(oldStmt, newStmt);
00223 }
00224 /**
00225  * 
00226  * @param annotation edu.ksu.cis.bandera.annotation.Annotation
00227  */
00228 public void setAnnotation(Annotation annotation) {
00229     this.annotation = annotation;
00230     annotation.setParent(this);
00231 }
00232 /**
00233  * 
00234  * @param annotation edu.ksu.cis.bandera.annotations.Annotation
00235  */
00236 public void setElseAnnotation(Annotation annotation) {
00237     elseAnnotation = annotation;
00238     elseAnnotation.setParent(this);
00239 }
00240 /**
00241  * 
00242  * @param annotation edu.ksu.cis.bandera.annotations.Annotation
00243  */
00244 public void setThenAnnotation(Annotation annotation) {
00245     thenAnnotation = annotation;
00246     thenAnnotation.setParent(this);
00247 }
00248 /**
00249  * 
00250  * @return java.lang.String
00251  */
00252 public String toString() {
00253     return "if (" + ((AIfStmt) node).getExp().toString().trim() + ")";
00254 }
00255 /**
00256  * 
00257  * @param body ca.mcgill.sable.soot.jimple.JimpleBody
00258  */
00259 public void validate(JimpleBody body) {
00260     super.validate(body);
00261     if (thenAnnotation != null) thenAnnotation.validate(body);
00262     if (annotation != null) annotation.validate(body);
00263     if (elseAnnotation != null) elseAnnotation.validate(body);
00264 }
00265 }

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