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/LocalVariableInstruction.java


1   package com.techtrader.modules.tools.bytecode;
2   
3   
4   import com.techtrader.modules.tools.bytecode.visitor.BCVisitor;
5   
6   
7   /**
8    *  Represents an instruction that has an argument of an index into the
9    *  local variable array of the current frame.  This includes most of the 
10   *  LOAD and STORE instructions.
11   *  <p>
12   *  The local variable array size is fixed by the 'maxLocals' property of 
13   *  the code block.  Long and double types take up 2 local variable indexes.
14   *  <p>  
15   *  Parameter values to methods are loaded into the local variable array 
16   *  prior to the execution of the first instruction.  The 0th-index of the 
17   *  array is set to the instance of the class the method is being invoked on.  
18   *
19   *  @author    Abe White
20   */
21  public abstract class LocalVariableInstruction
22    extends Instruction
23  {
24    protected int _index = -1;
25  
26  
27    protected LocalVariableInstruction (Code owner)
28    {
29      super (owner);
30    }
31  
32  
33    /**
34      *  Set the index of the local variable that this instruction should 
35     *  operate on.
36      *  
37     *  @return    this Instruction, for method chaining
38     */
39    public LocalVariableInstruction setIndex (int index)
40    {
41      _index = index;
42      calculateOpCode ();
43  
44      return this;
45    }
46  
47  
48    /**
49      *  Get the index of the local variable that this instruction should 
50     *  operate on.
51     */
52    public int getIndex ()
53    {
54      return _index;
55    }
56  
57  
58    /**
59     *  Two local variable instructions are equal if the local index they
60     *  reference is equal or if either index is 0/unset.
61     */
62    public boolean equals (Object other)
63    {
64      if (this == other)
65        return true;
66      if (!(other instanceof LocalVariableInstruction))
67        return false;
68  
69      LocalVariableInstruction ins = (LocalVariableInstruction) other;
70      int index = getIndex ();
71      int insIndex = ins.getIndex ();
72  
73      return index == -1 || insIndex == -1 || index == insIndex;
74    }
75  
76  
77    /**
78     *  Subclasses with variable opcodes can use this method to be
79     *  notified that information possibly affecting the opcode has been
80     *  changed.
81     */
82    protected void calculateOpCode ()
83    {
84    }
85  
86  
87    protected void copy (Instruction orig)
88    {
89      super.copy (orig);
90      _index = ((LocalVariableInstruction) orig)._index;
91    }
92  }