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

Quick Search    Search Deep

Source code: com/techtrader/modules/tools/bytecode/StoreInstruction.java


1   package com.techtrader.modules.tools.bytecode;
2   
3   
4   import java.io.IOException;
5   import java.io.DataInput;
6   import java.io.DataOutput;
7   
8   import com.techtrader.modules.tools.bytecode.visitor.BCVisitor;
9   
10  
11  /**
12   *  Represents an instruction to store a value in a local variable from 
13   *  the stack; can be any of astore*, istore*, etc.
14   *
15   *  @author    Abe White
16   */
17  public class StoreInstruction
18    extends TypedLocalVariableInstruction
19  {
20    protected StoreInstruction (Code owner)
21    {
22      super (owner);
23    }
24  
25  
26    protected StoreInstruction (Code owner, int opcode, Class type, int index)
27    {
28      super (owner);
29      _opcode = opcode;
30      _type = type;
31      _index = index;
32    }
33  
34  
35    public boolean equals (Object other)
36    {
37      if (this == other)
38        return true;
39      if (!(other instanceof StoreInstruction))
40        return false;
41      return super.equals (other);
42    }
43  
44  
45    public int getLength ()
46    {
47      switch (_opcode)
48      {
49      case ISTORE:
50      case LSTORE:
51      case FSTORE:
52      case DSTORE:
53      case ASTORE:
54        return super.getLength () + 1;
55      default:
56        return super.getLength ();
57      }
58    }
59  
60  
61    public int getStackChange ()
62    {
63      if (_type.equals (long.class) || _type.equals (double.class))
64        return -2;
65  
66  
67      return -1;
68    }
69  
70  
71    protected void readData (DataInput in)
72      throws IOException
73    {
74      switch (_opcode)
75      {
76      case ISTORE:
77      case LSTORE:
78      case FSTORE:
79      case DSTORE:
80      case ASTORE:
81        _index = in.readUnsignedByte ();
82      }
83    }
84  
85  
86    protected void writeData (DataOutput out)
87      throws IOException
88    {
89      switch (_opcode)
90      {
91      case ISTORE:
92      case LSTORE:
93      case FSTORE:
94      case DSTORE:
95      case ASTORE:
96        out.writeByte (_index);
97      }
98    }
99  
100 
101   protected void calculateOpCode ()
102   {
103     // take advantage of the arrangement of the opcode values --
104     // see Constants.java for details
105     int marker = _opcodeTypes.indexOf (_type);
106     if (_index < 4)
107       _opcode = ISTORE_0 + (4 * marker) + _index;
108     else
109       _opcode = ISTORE + marker;
110   }
111 
112 
113   public void acceptVisit (BCVisitor visit)
114   {
115     visit.enterStoreInstruction (this);
116     visit.exitStoreInstruction (this);
117   }
118 }