java-decompiler - refactoring for last basic type

GitOrigin-RevId: f9cc40839228035946b3fb3c97e4e338f8d41e16
This commit is contained in:
Ilyas Selimov
2022-01-28 15:21:20 +07:00
committed by intellij-monorepo-bot
parent 1c74502734
commit 2cf8098315
10 changed files with 16 additions and 20 deletions

View File

@@ -5,6 +5,7 @@ import org.jetbrains.java.decompiler.modules.decompiler.StatEdge.EdgeDirection;
import org.jetbrains.java.decompiler.modules.decompiler.StatEdge.EdgeType;
import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent;
import org.jetbrains.java.decompiler.modules.decompiler.stats.Statement;
import org.jetbrains.java.decompiler.modules.decompiler.stats.Statement.StatementType;
import java.util.ArrayList;
import java.util.HashSet;
@@ -76,7 +77,7 @@ public final class DecHelper {
setDest.remove(post);
for (Statement stat : setDest) {
if (stat.getLastBasicType() != Statement.LASTBASICTYPE_GENERAL) {
if (stat.getLastBasicType() != StatementType.GENERAL) {
if (post == null) {
post = stat;
repeat = true;

View File

@@ -121,7 +121,7 @@ public class FlattenStatementsHelper {
}
// 'if' statement: record positive branch
if (stat.getLastBasicType() == Statement.LASTBASICTYPE_IF) {
if (stat.getLastBasicType() == StatementType.IF) {
mapPosIfBranch.put(sourcenode.id, lstSuccEdges.get(0).getDestination().id);
}

View File

@@ -27,10 +27,10 @@ public class BasicBlockStatement extends Statement {
Instruction instr = block.getLastInstruction();
if (instr != null) {
if (instr.group == CodeConstants.GROUP_JUMP && instr.opcode != CodeConstants.opc_goto) {
lastBasicType = LASTBASICTYPE_IF;
lastBasicType = StatementType.IF;
}
else if (instr.group == CodeConstants.GROUP_SWITCH) {
lastBasicType = LASTBASICTYPE_SWITCH;
lastBasicType = StatementType.SWITCH;
}
}

View File

@@ -65,7 +65,7 @@ public final class CatchAllStatement extends Statement {
// *****************************************************************************
public static Statement isHead(Statement head) {
if (head.getLastBasicType() != Statement.LASTBASICTYPE_GENERAL) {
if (head.getLastBasicType() != StatementType.GENERAL) {
return null;
}
@@ -77,7 +77,7 @@ public final class CatchAllStatement extends Statement {
for (StatEdge edge : head.getSuccessorEdges(EdgeType.EXCEPTION)) {
Statement exc = edge.getDestination();
if (edge.getExceptions() == null && exc.getLastBasicType() == LASTBASICTYPE_GENERAL && setHandlers.contains(exc)) {
if (edge.getExceptions() == null && exc.getLastBasicType() == StatementType.GENERAL && setHandlers.contains(exc)) {
List<StatEdge> lstSuccs = exc.getSuccessorEdges(EdgeType.DIRECT_ALL);
if (lstSuccs.isEmpty() || lstSuccs.get(0).getType() != EdgeType.REGULAR) {

View File

@@ -61,7 +61,7 @@ public final class CatchStatement extends Statement {
// *****************************************************************************
public static Statement isHead(Statement head) {
if (head.getLastBasicType() != LASTBASICTYPE_GENERAL) {
if (head.getLastBasicType() != StatementType.GENERAL) {
return null;
}
@@ -82,7 +82,7 @@ public final class CatchStatement extends Statement {
boolean handlerok = true;
if (edge.getExceptions() != null && setHandlers.contains(stat)) {
if (stat.getLastBasicType() != LASTBASICTYPE_GENERAL) {
if (stat.getLastBasicType() != StatementType.GENERAL) {
handlerok = false;
}
else {

View File

@@ -37,7 +37,7 @@ public final class DoStatement extends Statement {
}
public static @Nullable Statement isHead(Statement head) {
if (head.getLastBasicType() == LASTBASICTYPE_GENERAL && !head.isMonitorEnter()) {
if (head.getLastBasicType() == StatementType.GENERAL && !head.isMonitorEnter()) {
// at most one outgoing edge
StatEdge edge = null;
List<StatEdge> successorEdges = head.getSuccessorEdges(EdgeType.DIRECT_ALL);

View File

@@ -159,7 +159,7 @@ public final class IfStatement extends Statement {
public static Statement isHead(Statement head) {
if (head.type == StatementType.BASIC_BLOCK && head.getLastBasicType() == LASTBASICTYPE_IF) {
if (head.type == StatementType.BASIC_BLOCK && head.getLastBasicType() == StatementType.IF) {
int regsize = head.getSuccessorEdges(EdgeType.REGULAR).size();
Statement p = null;

View File

@@ -57,7 +57,7 @@ public class SequenceStatement extends Statement {
public static Statement isHead2Block(Statement head) {
if (head.getLastBasicType() != Statement.LASTBASICTYPE_GENERAL) {
if (head.getLastBasicType() != StatementType.GENERAL) {
return null;
}
@@ -74,7 +74,7 @@ public class SequenceStatement extends Statement {
if (stat != head && stat.getPredecessorEdges(EdgeType.REGULAR).size() == 1
&& !stat.isMonitorEnter()) {
if (stat.getLastBasicType() == Statement.LASTBASICTYPE_GENERAL) {
if (stat.getLastBasicType() == StatementType.GENERAL) {
if (DecHelper.checkStatementExceptions(Arrays.asList(head, stat))) {
return new SequenceStatement(head, stat);
}

View File

@@ -26,11 +26,6 @@ import java.util.*;
import java.util.Map.Entry;
public abstract class Statement implements IMatchable {
public static final int LASTBASICTYPE_IF = 0;
public static final int LASTBASICTYPE_SWITCH = 1;
public static final int LASTBASICTYPE_GENERAL = 2;
// *****************************************************************************
// public fields
// *****************************************************************************
@@ -70,7 +65,7 @@ public abstract class Statement implements IMatchable {
protected Statement post;
protected int lastBasicType = LASTBASICTYPE_GENERAL;
protected StatementType lastBasicType = StatementType.GENERAL;
protected boolean isMonitorEnter;
@@ -736,7 +731,7 @@ public abstract class Statement implements IMatchable {
return stats;
}
public int getLastBasicType() {
public StatementType getLastBasicType() {
return lastBasicType;
}

View File

@@ -53,7 +53,7 @@ public final class SwitchStatement extends Statement {
@Nullable
public static Statement isHead(@NotNull Statement head) {
if (head.type == StatementType.BASIC_BLOCK && head.getLastBasicType() == Statement.LASTBASICTYPE_SWITCH) {
if (head.type == StatementType.BASIC_BLOCK && head.getLastBasicType() == StatementType.SWITCH) {
List<Statement> statements = new ArrayList<>();
if (DecHelper.isChoiceStatement(head, statements)) {
Statement post = statements.remove(0);