KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > bcel > generic > JSR


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.bcel.generic;
18
19 import java.io.DataOutputStream JavaDoc;
20 import java.io.IOException JavaDoc;
21
22 /**
23  * JSR - Jump to subroutine
24  *
25  * @version $Id: JSR.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 JSR extends JsrInstruction implements VariableLengthInstruction {
29
30     /**
31      * Empty constructor needed for the Class.newInstance() statement in
32      * Instruction.readInstruction(). Not to be used otherwise.
33      */

34     JSR() {
35     }
36
37
38     public JSR(InstructionHandle target) {
39         super(org.apache.bcel.Constants.JSR, 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 JavaDoc out ) throws IOException JavaDoc {
48         index = getTargetOffset();
49         if (opcode == org.apache.bcel.Constants.JSR) {
50             super.dump(out);
51         } else { // JSR_W
52
index = getTargetOffset();
53             out.writeByte(opcode);
54             out.writeInt(index);
55         }
56     }
57
58
59     protected int updatePosition( int offset, int max_offset ) {
60         int i = getTargetOffset(); // Depending on old position value
61
position += offset; // Position may be shifted by preceding expansions
62
if (Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate)
63
opcode = org.apache.bcel.Constants.JSR_W;
64             length = 5;
65             return 2; // 5 - 3
66
}
67         return 0;
68     }
69
70
71     /**
72      * Call corresponding visitor method(s). The order is:
73      * Call visitor methods of implemented interfaces first, then
74      * call methods according to the class hierarchy in descending order,
75      * i.e., the most specific visitXXX() call comes last.
76      *
77      * @param v Visitor object
78      */

79     public void accept( Visitor v ) {
80         v.visitStackProducer(this);
81         v.visitVariableLengthInstruction(this);
82         v.visitBranchInstruction(this);
83         v.visitJsrInstruction(this);
84         v.visitJSR(this);
85     }
86 }
87
Popular Tags