Source code: com/chaoswg/xtc4y/classdesc/code/instructions/CPRefInstruction.java
1 //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/code/instructions/CPRefInstruction.java,v 1.2 2003/08/26 12:35:25 toggm Exp $
2 /******************************************************************************
3 * XTC4y - eXtreme Testing Collection 4 you *
4 * -------------------------------------------------------------------------- *
5 * URL: http://www.chaoswg.com/xtc4y *
6 * Author: Mike Toggweiler (2.dog@gmx.ch) *
7 * *
8 * Last Updated: $Date: 2003/08/26 12:35:25 $, by $Author: toggm $ *
9 * Version: $Revision: 1.2 $ *
10 * -------------------------------------------------------------------------- *
11 * COPYRIGHT: (c) 2003 by Mike Toggweiler *
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 *****************************************************************************/
18 package com.chaoswg.xtc4y.classdesc.code.instructions;
19
20 import java.io.DataInputStream;
21 import java.io.DataOutputStream;
22 import java.io.IOException;
23
24 import com.chaoswg.xtc4y.classdesc.ConstantPool;
25 import com.chaoswg.xtc4y.classdesc.ConstantPoolEntry;
26
27 /**
28 * a constant pool refernece instruction is an instruction composite of
29 * the command and a short refering into the cp table.
30 * @author Mike Toggweiler
31 **/
32 public class CPRefInstruction extends WideBinaryInstruction {
33 private ConstantPoolEntry cpEntry;
34
35 /**
36 * Opcodes of short binary instructions
37 **/
38 /**
39 * load an int, byte, short, float, string, char from the cp
40 **/
41 public static final byte LDC_W = (byte)19;
42 /**
43 * load a float or double from the cp
44 **/
45 public static final byte LDC2_W = (byte)20;
46 /**
47 * get a static field value
48 **/
49 public static final byte GETSTATIC = (byte)178;
50 /**
51 * gput a static field value
52 **/
53 public static final byte PUTSTATIC = (byte)179;
54 /**
55 * get an instance field value
56 **/
57 public static final byte GETFIELD = (byte)180;
58 /**
59 * put an instance field value
60 **/
61 public static final byte PUTFIELD = (byte)181;
62 /**
63 * invoke a method on an object
64 **/
65 public static final byte INVOKEVIRTUAL = (byte)182;
66 /**
67 * invoke the instance initialisation method
68 **/
69 public static final byte INVOKESPECIAL = (byte)183;
70 /**
71 * invoke a static method
72 **/
73 public static final byte INVOKESTATIC = (byte)184;
74 /**
75 * instantiate a new object
76 **/
77 public static final byte NEW = (byte)187;
78 /**
79 * instantiation of an array
80 **/
81 public static final byte ANEWARRAY = (byte)189;
82 /**
83 * check a cast
84 **/
85 public static final byte CHECKCAST = (byte)192;
86 /**
87 * check the object instance
88 **/
89 public static final byte INSTANCEOF = (byte)193;
90
91
92 /**
93 * Creates an CPRefInstruction and initializes it from a
94 * DataInputStream
95 * @param the opcode of the command
96 * @param dis the DataInputStream to read from
97 * @param cp the constant pool to resolve indices
98 **/
99 protected CPRefInstruction(byte command, DataInputStream dis,
100 ConstantPool cp) throws IOException {
101 super(command, dis, cp);
102 }
103
104 /**
105 * Create a new binary instruction with a command and a cp entry
106 * as operand
107 * @param command
108 * @param operand
109 **/
110 protected CPRefInstruction(byte command, ConstantPoolEntry cpEntry) {
111 super(command);
112 this.cpEntry = cpEntry;
113 }
114
115 /**
116 * Resolve the operand as index from the cp
117 * @param operand to handle
118 * @param cp the constant pool to resolve indices
119 **/
120 protected final void handleOperand(short operand, ConstantPool cp) {
121 cpEntry = (ConstantPoolEntry)cp.getCPEntryAt(operand);
122 }
123
124 /**
125 * Register cp entry on constant pool and return index
126 * @param cp The constant pool to register variables
127 * @return the index of the stored cp entry
128 **/
129 protected final short getOperand(ConstantPool cp) {
130 return cp.addCPEntry(cpEntry);
131 }
132
133 /**
134 * Write code in a readable way
135 **/
136 public String toString() {
137 return super.toString() + " " + cpEntry;
138 }
139 }