KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > uka > ipd > coverage > recording > BlockDelimiter


1 /*
2  * Created on 24.08.2004
3  *
4  * written by Matthias Kempka
5  */

6 package de.uka.ipd.coverage.recording;
7
8 import org.apache.bcel.generic.NOP;
9
10 /**
11  * Created on 24.08.2004
12  *
13  * This class is used by <code>de.uka.ipd.coverage.BasicBlockIdentifyer</code>
14  * to signal the boundaries of an
15  * <code>org.apache.bcel.generic.InstructionList</code>.
16  * @author Matthias Kempka
17  */

18 class BlockDelimiter extends NOP {
19
20     public final static int BLOCK_START = 0;
21     public final static int BLOCK_END = 4;
22     
23     private int boundary;
24     private int position;
25     private int[] targets = new int[2];
26     private int targetsMaxIndex = -1;
27     
28     
29     /**
30      * The standard constructor initializes this InstructionHandle with
31      * a NOP Instruction
32      * @param boundary indicates whether this BlockDelimiter represents the
33      * start or the end of a block.
34      */

35     public BlockDelimiter(int boundary, int position) {
36         if (boundary != BLOCK_START && boundary != BLOCK_END) {
37             throw new IllegalArgumentException JavaDoc(
38                     "Boundary must be one of BLOCK_START or BLOCK_END"); //$NON-NLS-1$
39
}
40         this.boundary = boundary;
41         this.position = position;
42     }
43     
44     /**
45      * @return returns true if this instance represents the start of a BasicBlock
46      */

47     public boolean isEndBlock() {
48         return boundary == BLOCK_END;
49     }
50
51     /**
52      * @return returns true if this instance represents the end of a BasicBlock
53      */

54     public boolean isStartBlock() {
55         return boundary == BLOCK_START;
56     }
57     
58     /**
59      * @return returns the position this block references to in the unmodified byte code
60      */

61     public int getPosition() {
62         return position;
63     }
64     
65     public void addTarget(int targetPosition) {
66         
67         for (int i = 0; i <= targetsMaxIndex; i++)
68             if (targets[i] == targetPosition) return;
69             
70         targetsMaxIndex++;
71         if (targetsMaxIndex >= targets.length) {
72             int[] newTargets = new int[targetsMaxIndex * 4];
73             System.arraycopy(targets, 0, newTargets, 0, targets.length);
74             targets = newTargets;
75         }
76         targets[targetsMaxIndex] = targetPosition;
77     }
78     
79     public int[] getTargets() {
80         if (targetsMaxIndex < targets.length) {
81             int[] newTargets = new int[targetsMaxIndex + 1];
82             System.arraycopy(targets, 0, newTargets, 0, newTargets.length);
83             return newTargets;
84         }
85         return targets;
86     }
87 }
88
Popular Tags