1 2 package org.quilt.cl; 3 4 import org.quilt.graph.*; 5 import org.apache.bcel.generic.GotoInstruction; 6 import org.apache.bcel.generic.Instruction; 7 import org.apache.bcel.generic.InstructionHandle; 8 import org.apache.bcel.generic.InstructionList; 9 10 16 public class CodeVertex extends Vertex { 17 18 protected int pos = -1; 19 20 21 protected InstructionList ilist = new InstructionList(); 22 23 27 protected int startLine_ = -1; 28 29 34 protected int endLine_ = -1; 35 36 37 protected Instruction connInst_ = null; 38 39 45 public CodeVertex (ControlFlowGraph g) { 46 super(g); 47 } 48 53 public CodeVertex (ControlFlowGraph g, int position) { 54 super(g); 55 if (position < 0) { 56 throw new IllegalArgumentException ( 57 "position cannot be negative"); 58 } 59 pos = position; 60 } 61 67 public CodeVertex (ControlFlowGraph g, String l) { 68 super(g); 69 pos = -1; 70 label_ = l; 71 } 72 74 public Instruction getConnInst() { 75 return connInst_; 76 } 77 78 public void setConnInst (Instruction i) { 79 if (i == null) { 80 throw new IllegalArgumentException ("null instruction"); 81 } 82 connInst_ = i; 83 } 84 95 public InstructionList getInstructionList() { 96 return ilist; 97 } 98 104 public int getStartLine () { 105 return startLine_; 106 } 107 111 public void setStartLine(int n) { 112 startLine_ = n; 113 } 114 118 public int getEndLine() { 119 return endLine_; 120 } 121 128 public void setEndLine(int n) { 129 endLine_ = n; 130 } 131 137 public int getPosition () { 138 return pos; 139 } 140 149 public void setPos (int position) { 150 if (position < 0) { 151 throw new IllegalArgumentException ( 152 "position cannot be negative"); 153 } 154 pos = position; 155 } 156 166 public void moveGoto (final CodeVertex target) { 167 if (target == null) { 168 throw new IllegalArgumentException ("null target vertex"); 169 } 170 BinaryConnector biConnector = (BinaryConnector)getConnector(); 172 Edge flowEdge = biConnector.getEdge(); 173 Edge otherEdge = biConnector.getOtherEdge(); 175 if (otherEdge.getTarget() != target) { 176 throw new IllegalArgumentException ("not target of otherEdge"); 177 } 178 if (! (connInst_ instanceof GotoInstruction) ) { 179 throw new IllegalArgumentException ( 180 "connecting instruction not goto"); 181 } 182 UnaryConnector uConnector = (UnaryConnector)target.getConnector(); 184 Edge uEdge = uConnector.getEdge(); 185 Vertex tgtTarget = uEdge.getTarget(); 186 187 197 uEdge.setSource(this); 199 uEdge.setTarget(target); 200 setConnector(uConnector); 201 202 flowEdge.setSource(target); 204 otherEdge.setSource(target); 206 otherEdge.setTarget(tgtTarget); 207 target.setConnector(biConnector); 208 209 target.setConnInst (connInst_); connInst_ = null; 213 } 222 228 public String toString () { 229 StringBuffer sb = new StringBuffer ().append("Code ") 230 .append(super.toString()).append(" pos ") .append(pos); 231 232 if (startLine_ > -1) { 234 sb.append(" line ").append(startLine_); 235 } 236 if (endLine_ > -1) { 237 sb.append("/").append(endLine_); 238 } 239 return sb.toString(); 240 } 241 247 public String toString (boolean b) { 248 249 StringBuffer sb = new StringBuffer ().append(toString()); 250 if (b) { 251 if (label_ != null) { 252 sb.append ("\n label ") .append(label_); 253 } 254 sb.append("\n ilist: "); 255 InstructionHandle ih = ilist.getStart(); 256 while ( ih != null) { 257 sb.append(ih.getInstruction()); 258 } 259 } 260 return sb.toString(); 261 } 262 } 263 | Popular Tags |