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

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

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