1 19 20 package soot.dava.internal.AST; 21 22 import java.util.*; 23 import soot.*; 24 import soot.jimple.*; 25 import soot.dava.internal.SET.*; 26 import soot.dava.internal.asg.*; 27 import soot.dava.toolkits.base.AST.*; 28 import soot.dava.toolkits.base.AST.analysis.*; 29 30 56 public class ASTForLoopNode extends ASTControlFlowNode 57 { 58 private List init; private List update; 62 private List body; 63 64 public ASTForLoopNode( SETNodeLabel label, List init, ASTCondition condition, List update, List body) 65 { 66 super( label, condition); 67 this.body = body; 68 this.init=init; 69 this.update=update; 70 71 subBodies.add( body); 72 } 73 74 public List getInit(){ 75 return init; 76 } 77 78 public List getUpdate(){ 79 return update; 80 } 81 82 public void replaceBody(List body){ 83 this.body=body; 84 subBodies=new ArrayList(); 85 subBodies.add(body); 86 } 87 88 public Object clone() 89 { 90 return new ASTForLoopNode( get_Label(), init,get_Condition(),update, body); 91 } 92 93 public void toString( UnitPrinter up ){ 94 label_toString( up ); 95 96 up.literal( "for" ); 97 up.literal( " " ); 98 up.literal( "(" ); 99 100 Iterator it = init.iterator(); 101 while(it.hasNext()){ 102 AugmentedStmt as = (AugmentedStmt)it.next(); 103 Unit u = as.get_Stmt(); 104 u.toString( up ); 105 if(it.hasNext()){ 106 up.literal(" , "); 107 } 108 } 109 110 up.literal("; "); 111 112 113 condition.toString( up ); 114 up.literal("; "); 115 116 it = update.iterator(); 117 while(it.hasNext()){ 118 AugmentedStmt as = (AugmentedStmt)it.next(); 119 Unit u = as.get_Stmt(); 120 u.toString( up ); 121 if(it.hasNext()){ 122 up.literal(" , "); 123 } 124 } 125 126 up.literal( ")" ); 127 up.newline(); 128 129 up.literal( "{" ); 130 up.newline(); 131 132 up.incIndent(); 133 body_toString( up, body ); 134 up.decIndent(); 135 136 up.literal( "}" ); 137 up.newline(); 138 139 } 140 141 public String toString( ) 142 { 143 StringBuffer b = new StringBuffer (); 144 145 b.append( label_toString( )); 146 b.append( "for ("); 147 148 Iterator it = init.iterator(); 149 while(it.hasNext()){ 150 b.append( ((Unit) ((AugmentedStmt) it.next()).get_Stmt()).toString()); 151 if(it.hasNext()){ 152 b.append(" , "); 153 } 154 } 155 b.append("; "); 156 157 158 b.append( get_Condition().toString()); 159 b.append( "; "); 160 161 162 it = update.iterator(); 163 while(it.hasNext()){ 164 b.append( ((Unit) ((AugmentedStmt) it.next()).get_Stmt()).toString()); 165 if(it.hasNext()){ 166 b.append(" , "); 167 } 168 } 169 170 b.append(")"); 171 b.append( NEWLINE); 172 173 b.append( "{"); 174 b.append( NEWLINE); 175 176 b.append( body_toString( body)); 177 178 b.append( "}"); 179 b.append( NEWLINE); 180 181 return b.toString(); 182 } 183 184 185 public void apply(Analysis a){ 186 a.caseASTForLoopNode(this); 187 } 188 189 } 190 | Popular Tags |