[java decompiler] cleanup (dead code; optimizations; warnings)

This commit is contained in:
Roman Shevchenko
2017-12-01 18:23:42 +01:00
parent 71d8f4d689
commit 29de7ad72e
140 changed files with 761 additions and 5054 deletions

View File

@@ -1,83 +1,61 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.java.decompiler.code;
/*
* opc_tableswitch, lookupswitch
*/
public class SwitchInstruction extends Instruction {
private int[] destinations;
private int[] values;
private int defaultDestination;
private int defaultdest;
public SwitchInstruction() {
public SwitchInstruction(int opcode, int group, boolean wide, int bytecodeVersion, int[] operands) {
super(opcode, group, wide, bytecodeVersion, operands);
}
@Override
public void initInstruction(InstructionSequence seq) {
defaultDestination = seq.getPointerByRelOffset(operands[0]);
int pref = (opcode == CodeConstants.opc_tableswitch ? 3 : 2);
int len = this.getOperands().length - pref;
defaultdest = seq.getPointerByRelOffset(this.getOperand(0));
int prefix = opcode == CodeConstants.opc_tableswitch ? 3 : 2;
int len = operands.length - prefix;
int low = 0;
if (opcode == CodeConstants.opc_lookupswitch) {
len /= 2;
}
else {
low = this.getOperand(1);
low = operands[1];
}
destinations = new int[len];
values = new int[len];
for (int i = 0, k = 0; i < len; i++, k++) {
if (opcode == CodeConstants.opc_lookupswitch) {
values[i] = this.getOperand(pref + k);
values[i] = operands[prefix + k];
k++;
}
else {
values[i] = low + k;
}
destinations[i] = seq.getPointerByRelOffset(this.getOperand(pref + k));
destinations[i] = seq.getPointerByRelOffset(operands[prefix + k]);
}
}
public SwitchInstruction clone() {
SwitchInstruction newinstr = (SwitchInstruction)super.clone();
newinstr.defaultdest = defaultdest;
newinstr.destinations = destinations.clone();
newinstr.values = values.clone();
return newinstr;
}
public int[] getDestinations() {
return destinations;
}
public void setDestinations(int[] destinations) {
this.destinations = destinations;
}
public int getDefaultdest() {
return defaultdest;
}
public void setDefaultdest(int defaultdest) {
this.defaultdest = defaultdest;
}
public int[] getValues() {
return values;
}
public void setValues(int[] values) {
this.values = values;
public int getDefaultDestination() {
return defaultDestination;
}
}
@Override
public SwitchInstruction clone() {
SwitchInstruction copy = (SwitchInstruction)super.clone();
copy.defaultDestination = defaultDestination;
copy.destinations = destinations.clone();
copy.values = values.clone();
return copy;
}
}