author | joehw |
Wed, 26 Jun 2019 05:49:59 +0000 | |
changeset 55496 | 8e0ae3830fca |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
6 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
5 |
/* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
12 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
14 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
15 |
* Unless required by applicable law or agreed to in writing, software |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
18 |
* See the License for the specific language governing permissions and |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
19 |
* limitations under the License. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
20 |
*/ |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
21 |
|
6 | 22 |
package com.sun.org.apache.bcel.internal.generic; |
23 |
||
46174 | 24 |
import java.io.DataOutputStream; |
25 |
import java.io.IOException; |
|
26 |
||
6 | 27 |
import com.sun.org.apache.bcel.internal.util.ByteSequence; |
28 |
||
29 |
/** |
|
30 |
* RET - Return from subroutine |
|
31 |
* |
|
46174 | 32 |
* <PRE>Stack: ... -> ...</PRE> |
6 | 33 |
* |
55496 | 34 |
* @version $Id$ |
6 | 35 |
*/ |
36 |
public class RET extends Instruction implements IndexedInstruction, TypedInstruction { |
|
37 |
||
46174 | 38 |
private boolean wide; |
39 |
private int index; // index to local variable containg the return address |
|
40 |
||
6 | 41 |
|
46174 | 42 |
/** |
55496 | 43 |
* Empty constructor needed for Instruction.readInstruction. |
44 |
* Not to be used otherwise. |
|
46174 | 45 |
*/ |
46 |
RET() { |
|
47 |
} |
|
6 | 48 |
|
46174 | 49 |
|
50 |
public RET(final int index) { |
|
51 |
super(com.sun.org.apache.bcel.internal.Const.RET, (short) 2); |
|
52 |
setIndex(index); // May set wide as side effect |
|
53 |
} |
|
54 |
||
6 | 55 |
|
46174 | 56 |
/** |
57 |
* Dump instruction as byte code to stream out. |
|
58 |
* @param out Output stream |
|
59 |
*/ |
|
60 |
@Override |
|
61 |
public void dump( final DataOutputStream out ) throws IOException { |
|
62 |
if (wide) { |
|
63 |
out.writeByte(com.sun.org.apache.bcel.internal.Const.WIDE); |
|
64 |
} |
|
65 |
out.writeByte(super.getOpcode()); |
|
66 |
if (wide) { |
|
67 |
out.writeShort(index); |
|
68 |
} else { |
|
69 |
out.writeByte(index); |
|
70 |
} |
|
71 |
} |
|
6 | 72 |
|
73 |
||
46174 | 74 |
private void setWide() { |
75 |
wide = index > com.sun.org.apache.bcel.internal.Const.MAX_BYTE; |
|
76 |
if (wide) { |
|
77 |
super.setLength(4); // Including the wide byte |
|
78 |
} else { |
|
79 |
super.setLength(2); |
|
80 |
} |
|
81 |
} |
|
82 |
||
6 | 83 |
|
46174 | 84 |
/** |
85 |
* Read needed data (e.g. index) from file. |
|
86 |
*/ |
|
87 |
@Override |
|
88 |
protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException { |
|
89 |
this.wide = wide; |
|
90 |
if (wide) { |
|
91 |
index = bytes.readUnsignedShort(); |
|
92 |
super.setLength(4); |
|
93 |
} else { |
|
94 |
index = bytes.readUnsignedByte(); |
|
95 |
super.setLength(2); |
|
96 |
} |
|
6 | 97 |
} |
98 |
||
99 |
||
46174 | 100 |
/** |
101 |
* @return index of local variable containg the return address |
|
102 |
*/ |
|
103 |
@Override |
|
104 |
public final int getIndex() { |
|
105 |
return index; |
|
106 |
} |
|
6 | 107 |
|
108 |
||
46174 | 109 |
/** |
110 |
* Set index of local variable containg the return address |
|
111 |
*/ |
|
112 |
@Override |
|
113 |
public final void setIndex( final int n ) { |
|
114 |
if (n < 0) { |
|
115 |
throw new ClassGenException("Negative index value: " + n); |
|
116 |
} |
|
117 |
index = n; |
|
118 |
setWide(); |
|
119 |
} |
|
6 | 120 |
|
46174 | 121 |
|
122 |
/** |
|
123 |
* @return mnemonic for instruction |
|
124 |
*/ |
|
125 |
@Override |
|
126 |
public String toString( final boolean verbose ) { |
|
127 |
return super.toString(verbose) + " " + index; |
|
128 |
} |
|
129 |
||
6 | 130 |
|
46174 | 131 |
/** @return return address type |
132 |
*/ |
|
133 |
@Override |
|
134 |
public Type getType( final ConstantPoolGen cp ) { |
|
135 |
return ReturnaddressType.NO_TARGET; |
|
136 |
} |
|
137 |
||
138 |
||
139 |
/** |
|
140 |
* Call corresponding visitor method(s). The order is: |
|
141 |
* Call visitor methods of implemented interfaces first, then |
|
142 |
* call methods according to the class hierarchy in descending order, |
|
143 |
* i.e., the most specific visitXXX() call comes last. |
|
144 |
* |
|
145 |
* @param v Visitor object |
|
146 |
*/ |
|
147 |
@Override |
|
148 |
public void accept( final Visitor v ) { |
|
149 |
v.visitRET(this); |
|
150 |
} |
|
6 | 151 |
} |