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

WhileStmtAnnotation.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 
00041 public class WhileStmtAnnotation extends ControlFlowAnnotation {
00042     private Annotation initAnnotation = null;
00043 /**
00044  * WhileStmtAnnotation constructor comment.
00045  * @param node edu.ksu.cis.bandera.jjjc.node.Node
00046  */
00047 public WhileStmtAnnotation(Node node) {
00048     super(node);
00049 }
00050     public void apply(Switch sw)
00051     {
00052         ((AnnotationSwitch) sw).caseWhileStmtAnnotation(this);
00053     }
00054 /**
00055  * 
00056  * @return java.lang.Object
00057  */
00058 public Object clone() {
00059     WhileStmtAnnotation result = new WhileStmtAnnotation((Node) node.clone());
00060     /*
00061     Stmt[] stmts = getTestStatements();
00062 
00063     for (int i = 0; i < stmts.length; i++) {
00064         result.addStmt(JimpleStmtCloner.clone(stmts[i]));
00065     }
00066     */
00067     if (blockAnnotation != null) result.setBlockAnnotation((Annotation) blockAnnotation.clone());
00068     if (initAnnotation != null) result.setInitAnnotation((Annotation) blockAnnotation.clone());
00069     result.setIndefinite(indefinite);
00070     
00071     return result;
00072 }
00073 /**
00074  * 
00075  * @return java.util.Vector
00076  * @param includeSequential boolean
00077  */
00078 public Vector getAllAnnotations(boolean includeSequential) {
00079     Vector result = new Vector();
00080     result.addElement(this);
00081     for (Enumeration e = blockAnnotation.getAllAnnotations(includeSequential).elements(); e.hasMoreElements();) {
00082         result.addElement(e.nextElement());
00083     }
00084     return result;
00085 }
00086 /**
00087  * 
00088  * @return ca.mcgill.sable.soot.jimple.Stmt
00089  */
00090 public Stmt getBackpointStmt() {
00091     int size = getNumOfStatements();
00092     if (size > 0)
00093         return getStmtAt(size - 1);
00094     else
00095         return null;
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 (initAnnotation != null) {
00109         a = initAnnotation.getContainingAnnotation(stmt);
00110         if (a != null) result.addElement(a);
00111     }
00112 
00113     int size = result.size();
00114     if (size == 0) return null;
00115     else if (size == 1) return (Annotation) result.elementAt(0);
00116     throw new AnnotationException("Statement " + stmt + " is contained in two or more annotations");
00117 }
00118 /**
00119  * 
00120  * @return edu.ksu.cis.bandera.annotation.Annotation
00121  */
00122 public Annotation getInitAnnotation() {
00123     return initAnnotation;
00124 }
00125 /**
00126  * 
00127  * @return ca.mcgill.sable.soot.jimple.Stmt[]
00128  */
00129 public Stmt[] getStatements() {
00130     Stmt[] initStmts = (initAnnotation != null) ? initAnnotation.getStatements() : new Stmt[0];
00131     
00132     Stmt[] stmts = (blockAnnotation != null) ? blockAnnotation.getStatements() : new Stmt[0];
00133 
00134     Stmt[] testStmts = super.toArray();
00135     
00136     Stmt[] result = new Stmt[initStmts.length + stmts.length + testStmts.length];
00137 
00138     for (int i = 0; i < initStmts.length; i++) {
00139         result[i] = initStmts[i];
00140     }
00141 
00142     int index = initStmts.length;
00143     
00144     for (int i = 0; i < stmts.length; i++) {
00145         result[index + i] = stmts[i];
00146     }
00147 
00148     index += stmts.length;
00149 
00150     for (int i = 0; i < testStmts.length; i++) {
00151         result[index + i] = testStmts[i];
00152     }
00153     
00154     return result;
00155 }
00156 /**
00157  * 
00158  * @param annotation edu.ksu.cis.bandera.annotation.Annotation
00159  */
00160 public void setInitAnnotation(Annotation annotation) {
00161     initAnnotation = annotation;
00162     initAnnotation.setParent(this);
00163 }
00164 /**
00165  * 
00166  * @return java.lang.String
00167  */
00168 public String toString() {
00169     return "while (" + ((AWhileStmt) node).getExp().toString().trim() + ")";
00170 }
00171 /**
00172  * 
00173  * @param body ca.mcgill.sable.soot.jimple.JimpleBody
00174  */
00175 public void validate(JimpleBody body) {
00176     super.validate(body);
00177 
00178     if (initAnnotation != null) initAnnotation.validate(body);
00179 }
00180 }

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