[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,19 +1,10 @@
// 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;
import org.jetbrains.java.decompiler.code.interpreter.Util;
import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.struct.StructContext;
import org.jetbrains.java.decompiler.util.TextUtil;
import org.jetbrains.java.decompiler.util.VBStyleCollection;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public abstract class InstructionSequence {
// *****************************************************************************
@@ -73,10 +64,6 @@ public abstract class InstructionSequence {
}
}
public Instruction getCurrentInstr() {
return collinstr.get(pointer);
}
public Instruction getInstr(int index) {
return collinstr.get(index);
}
@@ -85,16 +72,12 @@ public abstract class InstructionSequence {
return collinstr.getLast();
}
public int getCurrentOffset() {
return collinstr.getKey(pointer).intValue();
}
public int getOffset(int index) {
return collinstr.getKey(index).intValue();
public int getOffset(int index) {
return collinstr.getKey(index);
}
public int getPointerByAbsOffset(int offset) {
Integer absoffset = new Integer(offset);
Integer absoffset = offset;
if (collinstr.containsKey(absoffset)) {
return collinstr.getIndexByKey(absoffset);
}
@@ -104,7 +87,7 @@ public int getOffset(int index) {
}
public int getPointerByRelOffset(int offset) {
Integer absoffset = new Integer(collinstr.getKey(pointer).intValue() + offset);
Integer absoffset = collinstr.getKey(pointer) + offset;
if (collinstr.containsKey(absoffset)) {
return collinstr.getIndexByKey(absoffset);
}
@@ -113,13 +96,6 @@ public int getOffset(int index) {
}
}
public void setPointerByAbsOffset(int offset) {
Integer absoffset = new Integer(collinstr.getKey(pointer).intValue() + offset);
if (collinstr.containsKey(absoffset)) {
pointer = collinstr.getIndexByKey(absoffset);
}
}
public int length() {
return collinstr.size();
}
@@ -153,55 +129,6 @@ public int getOffset(int index) {
return buf.toString();
}
public void writeCodeToStream(DataOutputStream out) throws IOException {
for (int i = 0; i < collinstr.size(); i++) {
collinstr.get(i).writeToStream(out, collinstr.getKey(i).intValue());
}
}
public void writeExceptionsToStream(DataOutputStream out) throws IOException {
List<ExceptionHandler> handlers = exceptionTable.getHandlers();
out.writeShort(handlers.size());
for (int i = 0; i < handlers.size(); i++) {
handlers.get(i).writeToStream(out);
}
}
public void sortHandlers(final StructContext context) {
Collections.sort(exceptionTable.getHandlers(), (handler0, handler1) -> {
if (handler0.to == handler1.to) {
if (handler0.exceptionClass == null) {
return 1;
}
else {
if (handler1.exceptionClass == null) {
return -1;
}
else if (handler0.exceptionClass.equals(handler1.exceptionClass)) {
return (handler0.from > handler1.from) ? -1 : 1; // invalid code
}
else {
if (Util.instanceOf(context, handler0.exceptionClass, handler1.exceptionClass)) {
return -1;
}
else {
return 1;
}
}
}
}
else {
return (handler0.to > handler1.to) ? 1 : -1;
}
});
}
// *****************************************************************************
// getter and setter methods
// *****************************************************************************
@@ -217,8 +144,4 @@ public int getOffset(int index) {
public ExceptionTable getExceptionTable() {
return exceptionTable;
}
public void setExceptionTable(ExceptionTable exceptionTable) {
this.exceptionTable = exceptionTable;
}
}
}