1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.generic;
18
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21
22 /***
23 * GOTO - Branch always (to relative offset, not absolute address)
24 *
25 * @version $Id: GOTO.java 386056 2006-03-15 11:31:56Z tcurdt $
26 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27 */
28 public class GOTO extends GotoInstruction implements VariableLengthInstruction {
29
30 /***
31 * Empty constructor needed for the Class.newInstance() statement in
32 * Instruction.readInstruction(). Not to be used otherwise.
33 */
34 GOTO() {
35 }
36
37
38 public GOTO(InstructionHandle target) {
39 super(org.apache.bcel.Constants.GOTO, target);
40 }
41
42
43 /***
44 * Dump instruction as byte code to stream out.
45 * @param out Output stream
46 */
47 public void dump( DataOutputStream out ) throws IOException {
48 index = getTargetOffset();
49 if (opcode == org.apache.bcel.Constants.GOTO) {
50 super.dump(out);
51 } else {
52 index = getTargetOffset();
53 out.writeByte(opcode);
54 out.writeInt(index);
55 }
56 }
57
58
59 /*** Called in pass 2 of InstructionList.setPositions() in order to update
60 * the branch target, that may shift due to variable length instructions.
61 */
62 protected int updatePosition( int offset, int max_offset ) {
63 int i = getTargetOffset();
64 position += offset;
65 if (Math.abs(i) >= (32767 - max_offset)) {
66 opcode = org.apache.bcel.Constants.GOTO_W;
67 length = 5;
68 return 2;
69 }
70 return 0;
71 }
72
73
74 /***
75 * Call corresponding visitor method(s). The order is:
76 * Call visitor methods of implemented interfaces first, then
77 * call methods according to the class hierarchy in descending order,
78 * i.e., the most specific visitXXX() call comes last.
79 *
80 * @param v Visitor object
81 */
82 public void accept( Visitor v ) {
83 v.visitVariableLengthInstruction(this);
84 v.visitUnconditionalBranch(this);
85 v.visitBranchInstruction(this);
86 v.visitGotoInstruction(this);
87 v.visitGOTO(this);
88 }
89 }