01: /* CounterVertex.java */
02: package org.quilt.cover.stmt;
03:
04: import org.apache.bcel.generic.*;
05: import org.quilt.cl.*;
06: import org.quilt.graph.*;
07:
08: /**
09: * <p>A CodeVertex which carries counter instrumentation and a label.
10: * The counter has an index. Whenever the flow of execution passes
11: * through this vertex, the counter code adds 1 to the hit count table,
12: * to <code>q$$q[n]</code>, where <code>n</code> is the counter index.</p>
13: *
14: * <p>Counter indexes are unique and assigned consecutively. They are
15: * not the same as vertex indexes. In the current revision of the
16: * software, counter vertices are also labeled with the counter index.</p>
17: *
18: * @author <a href="mailto:jddixon@users.sourceforge.net">Jim Dixon</a>
19: */
20: public class CounterVertex extends CodeVertex {
21:
22: /**
23: * Create a code vertex with default bytecode offset, line number,
24: * empty instruction list, and no label.
25: *
26: * @param g Graph which the vertex belongs to.
27: */
28: public CounterVertex(ControlFlowGraph g) {
29: super (g);
30: }
31:
32: /**
33: * Create a counter vertex, specifying a label
34: *
35: * @param g Graph which the vertex belongs to.
36: * @param l The String label applied to the vertex.
37: */
38: public CounterVertex(ControlFlowGraph g, String lbl) {
39: this (g);
40: label_ = lbl;
41: }
42:
43: // OTHER METHODS ////////////////////////////////////////////////
44: /**
45: * @return Graph index and Vertex index in a neatly formatted String,
46: * including the label if there is one, *not* newline-terminated.
47: */
48: public String toString() {
49: StringBuffer sb = new StringBuffer().append("Counter ").append(
50: getGraph().getIndex()).append(":").append(getIndex());
51: if (label_ != null) {
52: sb.append(" {").append(label_).append("}");
53: }
54: return sb.toString();
55: }
56:
57: /**
58: * @param b If true, add label (if any) and instruction list.
59: * @return A neatly formatted String ending with a newline.
60: */
61: public String toString(boolean b) {
62:
63: StringBuffer sb = new StringBuffer().append(toString());
64: if (b) {
65: sb.append("\n ilist: ");
66: InstructionHandle ih = ilist.getStart();
67: while (ih != null) {
68: sb.append(ih.getInstruction());
69: }
70: }
71: return sb.toString();
72: }
73: }
|