00001 package edu.ksu.cis.bandera.annotation;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00045
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
00057
00058 public Object clone() {
00059 WhileStmtAnnotation result = new WhileStmtAnnotation((Node) node.clone());
00060
00061
00062
00063
00064
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
00076
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
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
00100
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
00121
00122 public Annotation getInitAnnotation() {
00123 return initAnnotation;
00124 }
00125
00126
00127
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
00159
00160 public void setInitAnnotation(Annotation annotation) {
00161 initAnnotation = annotation;
00162 initAnnotation.setParent(this);
00163 }
00164
00165
00166
00167
00168 public String toString() {
00169 return "while (" + ((AWhileStmt) node).getExp().toString().trim() + ")";
00170 }
00171
00172
00173
00174
00175 public void validate(JimpleBody body) {
00176 super.validate(body);
00177
00178 if (initAnnotation != null) initAnnotation.validate(body);
00179 }
00180 }