1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.generic;
18
19 /***
20 * LDC2_W - Push long or double from constant pool
21 *
22 * <PRE>Stack: ... -> ..., item.word1, item.word2</PRE>
23 *
24 * @version $Id: LDC2_W.java 386056 2006-03-15 11:31:56Z tcurdt $
25 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26 */
27 public class LDC2_W extends CPInstruction implements PushInstruction, TypedInstruction {
28
29 /***
30 * Empty constructor needed for the Class.newInstance() statement in
31 * Instruction.readInstruction(). Not to be used otherwise.
32 */
33 LDC2_W() {
34 }
35
36
37 public LDC2_W(int index) {
38 super(org.apache.bcel.Constants.LDC2_W, index);
39 }
40
41
42 public Type getType( ConstantPoolGen cpg ) {
43 switch (cpg.getConstantPool().getConstant(index).getTag()) {
44 case org.apache.bcel.Constants.CONSTANT_Long:
45 return Type.LONG;
46 case org.apache.bcel.Constants.CONSTANT_Double:
47 return Type.DOUBLE;
48 default:
49 throw new RuntimeException("Unknown constant type " + opcode);
50 }
51 }
52
53
54 public Number getValue( ConstantPoolGen cpg ) {
55 org.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(index);
56 switch (c.getTag()) {
57 case org.apache.bcel.Constants.CONSTANT_Long:
58 return new Long(((org.apache.bcel.classfile.ConstantLong) c).getBytes());
59 case org.apache.bcel.Constants.CONSTANT_Double:
60 return new Double(((org.apache.bcel.classfile.ConstantDouble) c).getBytes());
61 default:
62 throw new RuntimeException("Unknown or invalid constant type at " + index);
63 }
64 }
65
66
67 /***
68 * Call corresponding visitor method(s). The order is:
69 * Call visitor methods of implemented interfaces first, then
70 * call methods according to the class hierarchy in descending order,
71 * i.e., the most specific visitXXX() call comes last.
72 *
73 * @param v Visitor object
74 */
75 public void accept( Visitor v ) {
76 v.visitStackProducer(this);
77 v.visitPushInstruction(this);
78 v.visitTypedInstruction(this);
79 v.visitCPInstruction(this);
80 v.visitLDC2_W(this);
81 }
82 }