1 package serp.bytecode;
2
3 import serp.bytecode.visitor.*;
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public abstract class LocalVariableInstruction extends TypedInstruction {
21 private int _index = -1;
22
23 LocalVariableInstruction(Code owner) {
24 super(owner);
25 }
26
27 LocalVariableInstruction(Code owner, int opcode) {
28 super(owner, opcode);
29 calculateLocal();
30 }
31
32 public String getTypeName() {
33 return null;
34 }
35
36 public TypedInstruction setType(String type) {
37 throw new UnsupportedOperationException();
38 }
39
40
41
42
43 public int getLocal() {
44 return _index;
45 }
46
47
48
49
50
51
52 public LocalVariableInstruction setLocal(int index) {
53 _index = index;
54 calculateOpcode();
55 return this;
56 }
57
58
59
60
61 public int getParam() {
62 return getCode().getParamsIndex(getLocal());
63 }
64
65
66
67
68
69
70 public LocalVariableInstruction setParam(int param) {
71 int local = getCode().getLocalsIndex(param);
72 if (local != -1) {
73 BCMethod method = getCode().getMethod();
74 setType(method.getParamNames()[param]);
75 }
76 return setLocal(local);
77 }
78
79
80
81
82
83
84
85 public LocalVariable getLocalVariable() {
86 LocalVariableTable table = getCode().getLocalVariableTable(false);
87 if (table == null)
88 return null;
89 return table.getLocalVariable(getLocal());
90 }
91
92
93
94
95
96
97
98
99 public LocalVariableInstruction setLocalVariable(LocalVariable local) {
100 if (local == null)
101 return setLocal(-1);
102 String type = local.getTypeName();
103 if (type != null)
104 setType(type);
105 return setLocal(local.getLocal());
106 }
107
108
109
110
111
112 public boolean equalsInstruction(Instruction other) {
113 if (this == other)
114 return true;
115 if (!getClass().equals(other.getClass()))
116 return false;
117
118 LocalVariableInstruction ins = (LocalVariableInstruction) other;
119 int index = getLocal();
120 int insIndex = ins.getLocal();
121 return index == -1 || insIndex == -1 || index == insIndex;
122 }
123
124 void read(Instruction orig) {
125 super.read(orig);
126 setLocal(((LocalVariableInstruction) orig).getLocal());
127 }
128
129
130
131
132
133 void calculateOpcode() {
134 }
135
136
137
138
139
140 void calculateLocal() {
141 }
142 }