Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/chaoswg/xtc4y/classdesc/code/instructions/ShortCPRefInstruction.java


1   //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/code/instructions/ShortCPRefInstruction.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   * This cpreference instruction has as an operand just a byte representing
29   * a valid index into the cp table
30   * @author Mike Toggweiler
31   **/
32  public class ShortCPRefInstruction extends BinaryInstruction {
33      private ConstantPoolEntry cpEntry;
34  
35      /**
36       * Opcodes of byte binary instructions
37       **/
38      /**
39       * load an int, byte, short, float, string, char from the cp
40       **/
41      public static final byte LDC = (byte)18;
42      
43      /**
44       * Creates an ShortCPRefInstruction and initializes it from a 
45       * DataInputStream. the operand is read from the stream and 
46       * provided to extending classes for a further handling of it
47       * @param the opcode of the command
48       * @param dis the DataInputStream to read from
49       * @param cp the constant pool to resolve indices
50       **/
51      protected ShortCPRefInstruction(byte command, DataInputStream dis, 
52          ConstantPool cp) throws IOException {
53    super(command, dis, cp);
54      }
55  
56      /**
57       * Create a new binary instruction with a command and the byte value 
58       * as operand
59       * @param command
60       * @param operand
61       **/
62      protected ShortCPRefInstruction(byte command, ConstantPoolEntry cpEntry) {
63    super(command);
64    this.cpEntry = cpEntry;
65      }
66  
67      /**
68       * Handle operand. By default, the operands value is stored. Another
69       * behaviour may be implemented in an extending class
70       * @param operand to handle
71       * @param cp the constant pool to resolve indices
72       **/
73      protected void handleOperand(byte operand, ConstantPool cp) {
74    short shortOperand = 0;
75    if (operand < 0) {   
76        shortOperand = (short)(operand+256);      
77    }
78    else {
79        shortOperand = (short)operand;
80    }
81    cpEntry = (ConstantPoolEntry)cp.getCPEntryAt(shortOperand);
82      }
83  
84      /**
85       * @param cp The constant pool to register variables
86       * @return the byte value of the operand, by default, the previously 
87       * stored operands value will be returned. Another behiour may be 
88       * implemented in an extending class.
89       **/
90      protected byte getOperand(ConstantPool cp) {
91    return (byte)cp.addCPEntry(cpEntry);
92      }
93  }