1 package gov.nasa.jpf.jvm; 20 21 import gov.nasa.jpf.*; 22 import gov.nasa.jpf.jvm.bytecode.Instruction; 23 import gov.nasa.jpf.util.Left; 24 25 import java.io.PrintWriter ; 26 import java.io.StringWriter ; 27 import gov.nasa.jpf.util.SourceRef; 28 import gov.nasa.jpf.util.Source; 29 30 31 36 public class Step extends SourceRef implements TransitionStep { 37 38 Instruction insn; 39 String comment; 40 Step next; 41 42 static boolean showBytecode; 45 static boolean showMissingLines; 46 47 public String description; 49 public Step (String f, int l) { 50 super(f, l); 51 } 52 53 public Step (String file, int line, Instruction insn) { 54 this(file, line); 55 this.insn = insn; 56 } 57 58 static boolean init (Config config) { 59 showBytecode = config.getBoolean("vm.report.show_bytecode"); 60 showMissingLines = config.getBoolean("vm.report.show_missing_lines"); 61 return true; 62 } 63 64 public Step getNext() { 65 return next; 66 } 67 68 public SourceRef getSourceRef () { 69 return this; 70 } 71 72 public String getDescription () { 73 if (description != null) { 74 StringWriter sw = new StringWriter (); 75 PrintWriter pw = new PrintWriter (sw); 76 77 printStepOn(pw, null, null); 78 description = sw.toString(); 79 } 80 81 return description; 82 } 83 84 public void setComment (String s) { 85 comment = s; 86 } 87 88 public String getComment () { 89 return comment; 90 } 91 92 public void printStepOn (PrintWriter pw, SourceRef lastPrinted, String prefix) { 93 Source source = Source.getSource(fileName); 94 boolean isLineMissing = source.isLineMissing(line); 95 96 if (!this.equals(lastPrinted)) { 97 if (!isLineMissing) { 98 pw.print( (prefix != null) ? prefix : " "); 99 pw.print(Left.format(fileName + ":" + line, 20)); 100 pw.print(' '); 101 pw.println(source.getLine(line)); 102 } else { 103 if (!fileName.equals(lastPrinted.getFileName()) && !showMissingLines) { 104 pw.print( (prefix != null) ? prefix : " "); 105 pw.print("[no source for: "); 106 pw.print(fileName); 107 pw.println(']'); 108 } 109 } 110 111 lastPrinted.set(this); 112 } 113 114 if (showBytecode || (showMissingLines && isLineMissing) ) { 115 if (insn != null) { 116 MethodInfo mi = insn.getMethod(); 117 pw.print('\t'); 118 pw.print(Left.format(mi.getClassInfo().getName() + "." + 119 mi.getUniqueName() + "." + insn.getPosition() + ":", 40)); 120 pw.println(insn); 121 } 122 } 123 124 if (comment != null) { 125 pw.print(" // "); 126 pw.println(comment); 127 } 128 } 129 130 public void toXML (PrintWriter pw) { 131 pw.print("\t<Instruction File=\""); 132 pw.print( fileName); 133 pw.print("\" Line=\""); 134 pw.print(line); 135 pw.println("\"/>"); 136 137 if (comment != null) { 138 pw.print("\t<Comment>"); 139 pw.print( comment); 140 pw.println("</Comment>"); 141 } 142 } 143 } 144 | Popular Tags |